1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_SERVER_GAMEWORLD_H
4#define GAME_SERVER_GAMEWORLD_H
5
6#include <game/gamecore.h>
7
8#include <vector>
9
10class CEntity;
11class CCharacter;
12
13/*
14 Class: Game World
15 Tracks all entities in the game. Propagates tick and
16 snap calls to all entities.
17*/
18class CGameWorld
19{
20public:
21 enum
22 {
23 ENTTYPE_PROJECTILE = 0,
24 ENTTYPE_LASER,
25 ENTTYPE_PICKUP,
26 ENTTYPE_FLAG,
27 ENTTYPE_CHARACTER,
28 NUM_ENTTYPES
29 };
30
31private:
32 void Reset();
33 void RemoveEntities();
34
35 CEntity *m_pNextTraverseEntity = nullptr;
36 CEntity *m_apFirstEntityTypes[NUM_ENTTYPES];
37
38 class CGameContext *m_pGameServer;
39 class CConfig *m_pConfig;
40 class IServer *m_pServer;
41
42public:
43 class CGameContext *GameServer() { return m_pGameServer; }
44 class CConfig *Config() { return m_pConfig; }
45 class IServer *Server() { return m_pServer; }
46
47 bool m_ResetRequested;
48 bool m_Paused;
49 CWorldCore m_Core;
50
51 CGameWorld();
52 ~CGameWorld();
53
54 void SetGameServer(CGameContext *pGameServer);
55
56 CEntity *FindFirst(int Type);
57
58 /*
59 Function: FindEntities
60 Finds entities close to a position and returns them in a list.
61
62 Arguments:
63 Pos - Position.
64 Radius - How close the entities have to be.
65 ppEnts - Pointer to a list that should be filled with the pointers
66 to the entities.
67 Max - Number of entities that fits into the ents array.
68 Type - Type of the entities to find.
69
70 Returns:
71 Number of entities found and added to the ents array.
72 */
73 int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type);
74
75 /*
76 Function: InterserctCharacters
77 Finds the CCharacters that intersects the line. // made for types lasers=1 and doors=0
78
79 Arguments:
80 Pos0 - Start position
81 Pos1 - End position
82 Radius - How for from the line the CCharacter is allowed to be.
83 NewPos - Intersection position
84 pNotThis - Entity to ignore intersecting with
85
86 Returns:
87 Returns a pointer to the closest hit or NULL of there is no intersection.
88 */
89 CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis = nullptr, int CollideWith = -1, const CCharacter *pThisOnly = nullptr);
90 /*
91 Function: ClosestCharacter
92 Finds the closest CCharacter to a specific point.
93
94 Arguments:
95 Pos - The center position.
96 Radius - How far off the CCharacter is allowed to be
97 pNotThis - Entity to ignore
98
99 Returns:
100 Returns a pointer to the closest CCharacter or NULL if no CCharacter is close enough.
101 */
102 CCharacter *ClosestCharacter(vec2 Pos, float Radius, const CEntity *pNotThis);
103
104 /*
105 Function: InsertEntity
106 Adds an entity to the world.
107
108 Arguments:
109 pEntity - Entity to add
110 */
111 void InsertEntity(CEntity *pEntity);
112
113 /*
114 Function: RemoveEntity
115 Removes an entity from the world.
116
117 Arguments:
118 pEntity - Entity to remove
119 */
120 void RemoveEntity(CEntity *pEntity);
121
122 void RemoveEntitiesFromPlayer(int PlayerId);
123 void RemoveEntitiesFromPlayers(int PlayerIds[], int NumPlayers);
124
125 /*
126 Function: Snap
127 Calls Snap on all the entities in the world to create
128 the snapshot.
129
130 Arguments:
131 SnappingClient - ID of the client which snapshot
132 is being created.
133 */
134 void Snap(int SnappingClient);
135
136 /*
137 Function: PostSnap
138 Called after all clients received their snapshot.
139 */
140 void PostSnap();
141
142 /*
143 Function: Tick
144 Calls Tick on all the entities in the world to progress
145 the world to the next tick.
146 */
147 void Tick();
148
149 /*
150 Function: SwapClients
151 Calls SwapClients on all the entities in the world to ensure that /swap
152 command is handled safely.
153 */
154 void SwapClients(int Client1, int Client2);
155
156 // DDRace
157 void ReleaseHooked(int ClientId);
158
159 /*
160 Function: IntersectedCharacters
161 Finds all CCharacters that intersect the line.
162
163 Arguments:
164 Pos0 - Start position
165 Pos1 - End position
166 Radius - How for from the line the CCharacter is allowed to be.
167 pNotThis - Entity to ignore intersecting with
168
169 Returns:
170 Returns list with all Characters on line.
171 */
172 std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
173
174 CTuningParams *Tuning();
175
176 CTuningParams *m_pTuningList;
177 CTuningParams *TuningList() { return m_pTuningList; }
178 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
179};
180
181#endif
182