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: Tick
138 Calls Tick on all the entities in the world to progress
139 the world to the next tick.
140 */
141 void Tick();
142
143 /*
144 Function: SwapClients
145 Calls SwapClients on all the entities in the world to ensure that /swap
146 command is handled safely.
147 */
148 void SwapClients(int Client1, int Client2);
149
150 // DDRace
151 void ReleaseHooked(int ClientId);
152
153 /*
154 Function: IntersectedCharacters
155 Finds all CCharacters that intersect the line.
156
157 Arguments:
158 Pos0 - Start position
159 Pos1 - End position
160 Radius - How for from the line the CCharacter is allowed to be.
161 pNotThis - Entity to ignore intersecting with
162
163 Returns:
164 Returns list with all Characters on line.
165 */
166 std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
167
168 CTuningParams *Tuning();
169
170 CTuningParams *m_pTuningList;
171 CTuningParams *TuningList() { return m_pTuningList; }
172 CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
173};
174
175#endif
176