DDraceNetwork Documentation
Loading...
Searching...
No Matches
entity.h
Go to the documentation of this file.
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_ENTITY_H
4#define GAME_SERVER_ENTITY_H
5
6#include <base/vmath.h>
7
8#include <game/alloc.h>
9
10#include "gameworld.h"
11#include "save.h"
12
13class CCollision;
14class CGameContext;
15
16/*
17 Class: Entity
18 Basic entity class.
19*/
20class CEntity
21{
23
25 friend CGameWorld; // entity list handling
28
29 /* Identity */
32
33 int m_Id;
34 int m_ObjType;
35
36 /*
37 Variable: m_ProximityRadius
38 Contains the physical size of the entity.
39 */
41
43 /* State */
45
46public: // TODO: Maybe make protected
47 /*
48 Variable: m_Pos
49 Contains the current posititon of the entity.
50 */
51 vec2 m_Pos;
52
53 /* Getters */
54 int GetId() const { return m_Id; }
55
56 /* Constructor */
58
59 /* Destructor */
60 virtual ~CEntity();
61
62 /* Objects */
63 std::vector<SSwitchers> &Switchers() { return m_pGameWorld->m_Core.m_vSwitchers; }
67 CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); }
68 class CConfig *Config() { return m_pGameWorld->Config(); }
70 class IServer *Server() { return m_pGameWorld->Server(); }
72
73 /* Getters */
76 const vec2 &GetPos() const { return m_Pos; }
77 float GetProximityRadius() const { return m_ProximityRadius; }
78
79 /* Other functions */
80
81 /*
82 Function: Destroy
83 Destroys the entity.
84 */
85 virtual void Destroy() { delete this; }
86
87 /*
88 Function: Reset
89 Called when the game resets the map. Puts the entity
90 back to its starting state or perhaps destroys it.
91 */
92 virtual void Reset() {}
93
94 /*
95 Function: Tick
96 Called to progress the entity to the next tick. Updates
97 and moves the entity to its new state and position.
98 */
99 virtual void Tick() {}
100
101 /*
102 Function: TickDeferred
103 Called after all entities Tick() function has been called.
104 */
105 virtual void TickDeferred() {}
106
107 /*
108 Function: TickPaused
109 Called when the game is paused, to freeze the state and position of the entity.
110 */
111 virtual void TickPaused() {}
112
113 /*
114 Function: Snap
115 Called when a new snapshot is being generated for a specific
116 client.
117
118 Arguments:
119 SnappingClient - ID of the client which snapshot is
120 being generated. Could be -1 to create a complete
121 snapshot of everything in the game for demo
122 recording.
123 */
124 virtual void Snap(int SnappingClient) {}
125
126 /*
127 Function: SwapClients
128 Called when two players have swapped their client ids.
129
130 Arguments:
131 Client1 - First client ID
132 Client2 - Second client ID
133 */
134 virtual void SwapClients(int Client1, int Client2) {}
135
136 /*
137 Function: BlocksSave
138 Called to check if a team can be saved
139
140 Arguments:
141 ClientId - Client ID
142 */
143 virtual ESaveResult BlocksSave(int ClientId) { return ESaveResult::SUCCESS; }
144
145 /*
146 Function GetOwnerId
147 Returns:
148 ClientId of the initiator from this entity. -1 created by map.
149 This is used by save/load to remove related entities to the tee.
150 CCharacter should not return the PlayerId, because they get
151 handled separately in save/load code.
152 */
153 virtual int GetOwnerId() const { return -1; }
154
155 /*
156 Function: NetworkClipped
157 Performs a series of test to see if a client can see the
158 entity.
159
160 Arguments:
161 SnappingClient - ID of the client which snapshot is
162 being generated. Could be -1 to create a complete
163 snapshot of everything in the game for demo
164 recording.
165
166 Returns:
167 True if the entity doesn't have to be in the snapshot.
168 */
169 bool NetworkClipped(int SnappingClient) const;
172
174 virtual bool CanCollide(int ClientId) { return true; };
175
176 // DDRace
177
180
181 int m_Number;
182 int m_Layer;
183};
184
187
188#endif
#define MACRO_ALLOC_HEAP()
Definition alloc.h:21
Definition collision.h:34
Definition config.h:25
Definition entity.h:13
float m_ProximityRadius
Definition entity.h:51
CGameWorld * GameWorld()
Definition entity.h:64
virtual ESaveResult BlocksSave(int ClientId)
Definition entity.h:143
bool NetworkClippedLine(int SnappingClient, vec2 StartPos, vec2 EndPos) const
Definition entity.cpp:43
class CGameContext * GameServer()
Definition entity.h:69
int GetId() const
Definition entity.h:28
virtual ~CEntity()
class IServer * Server()
Definition entity.h:70
bool m_MarkedForDestroy
Definition entity.h:23
std::vector< SSwitchers > & Switchers()
Definition entity.h:63
const vec2 & GetPos() const
Definition entity.h:76
CEntity * m_pNextTypeEntity
Definition entity.h:19
bool NetworkClipped(int SnappingClient) const
Definition entity.cpp:33
CGameWorld * m_pGameWorld
Definition entity.h:22
CCollision * Collision()
Definition entity.h:71
CCollision * m_pCCollision
Definition entity.h:31
class CConfig * Config()
Definition entity.h:68
vec2 m_Pos
Definition entity.h:52
CTuningParams * GetTuning(int i)
Definition entity.h:67
virtual void TickDeferred()
Definition entity.h:105
float GetProximityRadius() const
Definition entity.h:77
int m_Layer
Definition entity.h:54
CTuningParams * TuningList()
Definition entity.h:66
CEntity * m_pPrevTypeEntity
Definition entity.h:18
CEntity * TypeNext()
Definition entity.h:74
virtual void Tick()
Definition entity.h:99
CEntity(CGameWorld *pGameWorld, int Objtype, vec2 Pos=vec2(0, 0), int ProximityRadius=0)
CEntity * TypePrev()
Definition entity.h:75
virtual void Snap(int SnappingClient)
Definition entity.h:124
CTuningParams * Tuning()
Definition entity.h:65
virtual void SwapClients(int Client1, int Client2)
Definition entity.h:134
virtual bool CanCollide(int ClientId)
Definition entity.h:174
virtual void Destroy()
Definition entity.h:85
bool GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *pOutPos)
Definition entity.cpp:77
virtual int GetOwnerId() const
Definition entity.h:153
bool GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2 *pOutPos)
Definition entity.cpp:54
int m_Number
Definition entity.h:53
int m_ObjType
Definition entity.h:25
virtual void Reset()
Definition entity.h:92
bool GameLayerClipped(vec2 CheckPos)
virtual void TickPaused()
Definition entity.h:111
int m_Id
Definition entity.h:24
Definition gamecontext.h:106
Definition gameworld.h:18
CTuningParams * TuningList()
Definition gameworld.h:105
CTuningParams * Tuning()
Definition gameworld.cpp:326
class IServer * Server()
Definition gameworld.h:47
class CConfig * Config()
Definition gameworld.h:46
class CGameContext * GameServer()
Definition gameworld.h:45
CWorldCore m_Core
Definition gameworld.h:35
CTuningParams * GetTuning(int i)
Definition gameworld.h:106
Definition gamecore.h:43
std::vector< SSwitchers > m_vSwitchers
Definition gamecore.h:176
Definition server.h:31
Definition vmath.h:15
ESaveResult
Definition save.h:27
bool NetworkClipped(const CGameContext *pGameServer, int SnappingClient, vec2 CheckPos)
Definition entity.cpp:90
bool NetworkClippedLine(const CGameContext *pGameServer, int SnappingClient, vec2 StartPos, vec2 EndPos)
Definition entity.cpp:103
vector2_base< float > vec2
Definition vmath.h:161