DDraceNetwork Docs
character.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_ENTITIES_CHARACTER_H
4#define GAME_SERVER_ENTITIES_CHARACTER_H
5
7#include <game/server/save.h>
8
9class CGameTeams;
10class CGameWorld;
11class IAntibot;
13
14enum
15{
23};
24
25class CCharacter : public CEntity
26{
28
29 friend class CSaveTee; // need to use core
30
31public:
32 CCharacter(CGameWorld *pWorld, CNetObj_PlayerInput LastInput);
33
34 void Reset() override;
35 void Destroy() override;
36 void PreTick();
37 void Tick() override;
38 void TickDeferred() override;
39 void TickPaused() override;
40 void Snap(int SnappingClient) override;
41 void PostSnap() override;
42 void SwapClients(int Client1, int Client2) override;
43
44 bool CanSnapCharacter(int SnappingClient);
45 bool IsSnappingCharacterInView(int SnappingClientId);
46
47 bool IsGrounded();
48
49 void SetWeapon(int W);
50 void SetJetpack(bool Active);
51 void SetEndlessJump(bool Active);
52 void SetJumps(int Jumps);
53 void SetSolo(bool Solo);
54 void SetSuper(bool Super);
55 void SetInvincible(bool Invincible);
56 void SetLiveFrozen(bool Active);
57 void SetDeepFrozen(bool Active);
60
64
68 void ResetHook();
69 void ResetInput();
70 void FireWeapon();
71
72 void Die(int Killer, int Weapon, bool SendKillMsg = true);
73 bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon);
74
75 bool Spawn(class CPlayer *pPlayer, vec2 Pos);
76 bool Remove();
77
78 bool IncreaseHealth(int Amount);
79 bool IncreaseArmor(int Amount);
80
81 void GiveWeapon(int Weapon, bool Remove = false);
82 void GiveNinja();
84 void SetEndlessHook(bool Enable);
85
86 void SetEmote(int Emote, int Tick);
87
88 void Rescue();
89
90 int NeededFaketuning() const { return m_NeededFaketuning; }
91 bool IsAlive() const { return m_Alive; }
92 bool IsPaused() const { return m_Paused; }
93 class CPlayer *GetPlayer() { return m_pPlayer; }
95
96 void SetPosition(const vec2 &Position);
97 void Move(vec2 RelPos);
98
100 void SetVelocity(vec2 NewVelocity);
101 void SetRawVelocity(vec2 NewVelocity);
102 void AddVelocity(vec2 Addition);
104
105private:
106 // player controlling this character
108
113
114 // weapon info
116 int m_NumObjectsHit;
117
118 int m_LastWeapon;
119 int m_QueuedWeapon;
120
121 int m_ReloadTimer;
122 int m_AttackTick;
123
125
127
130
131 // last tick that the player took any action ie some input
134
135 // these are non-heldback inputs
139
140 // input
144 int m_NumInputs;
145
147
150
152
153 // the player core for the physics
156
157 // info for dead reckoning
158 int m_ReckoningTick; // tick that we are performing dead reckoning From
159 CCharacterCore m_SendCore; // core that we should send
160 CCharacterCore m_ReckoningCore; // the dead reckoning core
161
162 // DDRace
163
164 void SnapCharacter(int SnappingClient, int Id);
165 static bool IsSwitchActiveCb(int Number, void *pUser);
166 void SetTimeCheckpoint(int TimeCheckpoint);
167 void HandleTiles(int Index);
168 float m_Time;
170 void DDRaceInit();
171 void HandleSkippableTiles(int Index);
172 void ForceSetRescue(int RescueMode);
175 void HandleBroadcast();
177 void SendZoneMsgs();
178 IAntibot *Antibot();
179
182
183public:
184 CGameTeams *Teams() { return m_pTeams; }
185 void SetTeams(CGameTeams *pTeams);
186 bool TrySetRescue(int RescueMode);
187
189 void Pause(bool Pause);
190 bool Freeze(int Seconds);
191 bool Freeze();
192 bool UnFreeze();
194 void ResetPickups();
195 void ResetJumps();
197 int Team();
198 bool CanCollide(int ClientId);
199 bool SameTeam(int ClientId);
200 void StopRecording();
201 bool m_NinjaJetpack;
203 int m_FreezeTime;
204 bool m_FrozenLastTick;
206 int m_TuneZone;
213
218
219 int m_TileIndex;
220 int m_TileFIndex;
221
230 int m_StrongWeakId;
231
234
235 // Setters/Getters because i don't want to modify vanilla vars access modifiers
236 int GetLastWeapon() const { return m_LastWeapon; }
237 void SetLastWeapon(int LastWeap) { m_LastWeapon = LastWeap; }
238 int GetActiveWeapon() const { return m_Core.m_ActiveWeapon; }
239 void SetActiveWeapon(int ActiveWeap) { m_Core.m_ActiveWeapon = ActiveWeap; }
240 void SetLastAction(int LastAction) { m_LastAction = LastAction; }
241 int GetArmor() const { return m_Armor; }
242 void SetArmor(int Armor) { m_Armor = Armor; }
245 const CCharacterCore *Core() const { return &m_Core; }
246 bool GetWeaponGot(int Type) { return m_Core.m_aWeapons[Type].m_Got; }
247 void SetWeaponGot(int Type, bool Value) { m_Core.m_aWeapons[Type].m_Got = Value; }
248 int GetWeaponAmmo(int Type) { return m_Core.m_aWeapons[Type].m_Ammo; }
249 void SetWeaponAmmo(int Type, int Value) { m_Core.m_aWeapons[Type].m_Ammo = Value; }
250 void SetNinjaActivationDir(vec2 ActivationDir) { m_Core.m_Ninja.m_ActivationDir = ActivationDir; }
251 void SetNinjaActivationTick(int ActivationTick) { m_Core.m_Ninja.m_ActivationTick = ActivationTick; }
252 void SetNinjaCurrentMoveTime(int CurrentMoveTime) { m_Core.m_Ninja.m_CurrentMoveTime = CurrentMoveTime; }
253
254 int GetLastAction() const { return m_LastAction; }
255
256 bool HasTelegunGun() const { return m_Core.m_HasTelegunGun; }
258 bool HasTelegunLaser() const { return m_Core.m_HasTelegunLaser; }
259
264
265 bool IsSuper() const { return m_Core.m_Super; }
266
268 CTuningParams *GetTuning(int Zone) { return Zone ? &TuningList()[Zone] : Tuning(); }
269};
270
271enum
272{
275 DDRACE_CHEAT, // no time and won't start again unless ordered by a mod or death
278
279#endif
#define MACRO_ALLOC_POOL_ID()
Definition: alloc.h:36
Definition: gamecore.h:176
int m_ActivationTick
Definition: gamecore.h:208
bool m_HammerHitDisabled
Definition: gamecore.h:253
bool m_Super
Definition: gamecore.h:258
bool m_HasTelegunGun
Definition: gamecore.h:260
bool m_LaserHitDisabled
Definition: gamecore.h:255
bool m_HasTelegunLaser
Definition: gamecore.h:262
bool m_GrenadeHitDisabled
Definition: gamecore.h:254
bool m_HasTelegunGrenade
Definition: gamecore.h:261
bool m_ShotgunHitDisabled
Definition: gamecore.h:256
int m_CurrentMoveTime
Definition: gamecore.h:209
int m_ActiveWeapon
Definition: gamecore.h:195
vec2 m_ActivationDir
Definition: gamecore.h:207
struct CCharacterCore::@220 m_Ninja
struct CCharacterCore::WeaponStat m_aWeapons[NUM_WEAPONS]
Definition: character.h:30
bool m_LastBonus
Definition: character.h:226
void FireWeapon()
Definition: character.cpp:251
int m_NumInputs
Definition: character.h:166
bool IsPaused() const
Definition: character.h:92
void SetLastWeapon(int LastWeap)
Definition: character.h:237
void Rescue()
Definition: character.cpp:2390
bool Freeze(int Seconds)
bool GetWeaponGot(int Type)
Definition: character.h:246
int m_ReloadTimer
Definition: character.h:152
CNetObj_PlayerInput m_LatestPrevInput
Definition: character.h:158
int GetArmor() const
Definition: character.h:241
void TickPaused() override
Definition: character.cpp:926
void SetArmor(int Armor)
Definition: character.h:242
void ApplyMoveRestrictions()
CSaveTee m_RescueTee[NUM_RESCUEMODES]
Definition: character.h:181
bool m_SetSavePos[NUM_RESCUEMODES]
Definition: character.h:180
void RemoveNinja()
Definition: character.cpp:96
void DDRaceTick()
int m_WeaponChangeTick
Definition: character.h:233
void SetActiveWeapon(int ActiveWeap)
Definition: character.h:239
void HandleTiles(int Index)
bool HasTelegunGun() const
Definition: character.h:256
int m_Armor
Definition: character.h:149
void SetEndlessHook(bool Enable)
Definition: character.cpp:2298
bool HasTelegunGrenade() const
Definition: character.h:257
int m_LastAction
Definition: character.h:132
bool Spawn(class CPlayer *pPlayer, vec2 Pos)
Definition: character.cpp:55
class CPlayer * GetPlayer()
Definition: character.h:93
bool m_LastRefillJumps
Definition: character.h:92
const CCharacterCore * Core() const
Definition: character.h:101
void SetLastAction(int LastAction)
Definition: character.h:240
int m_SpawnTick
Definition: character.h:232
void Pause(bool Pause)
Definition: character.cpp:2309
void SetNinjaActivationTick(int ActivationTick)
Definition: character.h:251
int GetLastWeapon() const
Definition: character.h:236
int m_LastWeapon
Definition: character.h:149
int GetLastAction() const
Definition: character.h:254
void ResetInput()
Definition: character.cpp:562
int m_TriggeredEvents7
Definition: character.h:151
int m_EmoteStop
Definition: character.h:129
void ResetHook()
Definition: character.cpp:556
void SetEmote(int Emote, int Tick)
Definition: character.cpp:681
void HandleSkippableTiles(int Index)
int m_NumObjectsHit
Definition: character.h:147
int m_TuneZoneOld
Definition: character.h:207
void OnPredictedInput(CNetObj_PlayerInput *pNewInput)
Definition: character.cpp:499
CCharacterCore m_ReckoningCore
Definition: character.h:160
int m_LastTimeCp
Definition: character.h:215
bool m_FreezeHammer
Definition: character.h:205
bool m_FrozenLastTick
Definition: character.h:83
void Tick() override
Definition: character.cpp:582
CNetObj_PlayerInput m_SavedInput
Definition: character.h:164
void HandleNinja()
Definition: character.cpp:105
int GetWeaponAmmo(int Type)
Definition: character.h:248
CEntity * m_apHitObjects[10]
Definition: character.h:115
void AddVelocity(vec2 Addition)
void OnDirectInput(CNetObj_PlayerInput *pNewInput)
Definition: character.cpp:520
bool Freeze()
void SwapClients(int Client1, int Client2) override
Definition: character.cpp:2462
void ReleaseHook()
Definition: character.cpp:549
CCharacterCore m_Core
Definition: character.h:169
int m_ReckoningTick
Definition: character.h:158
void SetCore(CCharacterCore Core)
Definition: character.h:244
void Snap(int SnappingClient) override
Definition: character.cpp:1217
int m_PausedTick
Definition: character.h:111
CNetObj_PlayerInput m_PrevInput
Definition: character.h:162
bool m_Alive
Definition: character.h:109
int m_TuneZone
Definition: character.h:84
void ForceSetRescue(int RescueMode)
Definition: character.cpp:2079
bool IncreaseArmor(int Amount)
Definition: character.cpp:948
vec2 m_TeleGunPos
Definition: character.h:227
void SetNinjaCurrentMoveTime(int CurrentMoveTime)
Definition: character.h:252
int m_StartTime
Definition: character.h:210
bool IncreaseHealth(int Amount)
Definition: character.cpp:940
void DoWeaponSwitch()
Definition: character.cpp:191
void SetWeapon(int W)
Definition: character.cpp:14
CGameTeams * m_pTeams
Definition: character.h:155
void SetTimeCheckpoint(int TimeCheckpoint)
Definition: character.cpp:1469
bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
Definition: character.cpp:612
CSaveTee & GetLastRescueTeeRef(int Mode=RESCUEMODE_AUTO)
Definition: character.h:267
void SetDeepFrozen(bool Active)
Definition: character.cpp:216
int m_FreezeTime
Definition: character.h:82
bool IsSnappingCharacterInView(int SnappingClientId)
Definition: character.cpp:1188
int m_PainSoundTimer
Definition: character.h:208
void SetSolo(bool Solo)
Definition: character.cpp:27
bool CanSnapCharacter(int SnappingClient)
Definition: character.cpp:1167
void SendZoneMsgs()
Definition: character.cpp:1997
void SetSuper(bool Super)
Definition: character.cpp:33
bool HammerHitDisabled() const
Definition: character.h:260
bool CanCollide(int ClientId)
void SetWeaponAmmo(int Type, int Value)
Definition: character.h:249
void HandleWeaponSwitch()
Definition: character.cpp:201
void HandleTuneLayer()
void SetEndlessJump(bool Active)
Definition: character.cpp:164
int m_LastTimeCpBroadcasted
Definition: character.h:216
vec2 m_PrevPos
Definition: character.h:85
void Reset() override
Definition: character.cpp:49
CGameTeams * Teams()
Definition: character.h:184
void PreTick() override
Definition: character.cpp:574
void Destroy() override
Definition: character.cpp:138
bool IsGrounded()
Definition: character.cpp:40
bool m_IsBlueTeleGunTeleport
Definition: character.h:229
float m_aCurrentTimeCp[MAX_CHECKPOINTS]
Definition: character.h:217
IAntibot * Antibot()
Definition: character.cpp:2032
void SetVelocity(vec2 NewVelocity)
static bool IsSwitchActiveCb(int Number, void *pUser)
int m_LastNoAmmoSound
Definition: character.h:133
CCharacterCore m_SendCore
Definition: character.h:159
bool SameTeam(int ClientId)
bool Remove()
void PostSnap() override
Definition: character.cpp:1313
CCharacterCore GetCore()
Definition: character.h:243
bool UnFreeze()
CClientMask TeamMask()
Definition: character.cpp:2420
void FillAntibot(CAntibotCharacterData *pData)
Definition: character.cpp:1334
int m_QueuedWeapon
Definition: character.h:150
void SetLiveFrozen(bool Active)
Definition: character.cpp:211
void DDRacePostCoreTick()
void HandleJetpack()
Definition: character.cpp:51
bool TrySetRescue(int RescueMode)
Definition: character.cpp:2043
void SetRawVelocity(vec2 NewVelocity)
CTuningParams * GetTuning(int Zone)
Definition: character.h:268
bool IsAlive() const
Definition: character.h:91
CNetObj_PlayerInput m_LatestPrevPrevInput
Definition: character.h:136
void HandleBroadcast()
Definition: character.cpp:1350
int m_LastMove
Definition: character.h:209
int m_EmoteType
Definition: character.h:128
bool IsSuper() const
Definition: character.h:265
int m_DamageTaken
Definition: character.h:126
int m_LastBroadcast
Definition: character.h:169
void SetNinjaActivationDir(vec2 ActivationDir)
Definition: character.h:250
int m_DamageTakenTick
Definition: character.h:146
int m_Health
Definition: character.h:148
void SetTeams(CGameTeams *pTeams)
Definition: character.cpp:2037
void GiveWeapon(int Weapon, bool Remove=false)
Definition: character.cpp:1089
void ResetJumps()
Definition: character.cpp:2250
int64_t m_LastStartWarning
Definition: character.h:222
int NeededFaketuning() const
Definition: character.h:90
void TickDeferred() override
Definition: character.cpp:605
int GetActiveWeapon() const
Definition: character.h:238
void DDRaceInit()
Definition: character.cpp:2336
void SetJumps(int Jumps)
Definition: character.cpp:169
CNetObj_PlayerInput m_Input
Definition: character.h:163
bool m_NinjaJetpack
Definition: character.h:81
int m_TeleCheckpoint
Definition: character.h:87
void GiveAllWeapons()
int m_TileFIndex
Definition: character.h:90
CNetObj_PlayerInput m_LatestInput
Definition: character.h:159
bool HasTelegunLaser() const
Definition: character.h:258
bool GrenadeHitDisabled() const
Definition: character.h:263
int m_NeededFaketuning
Definition: character.h:112
void HandleWeapons()
Definition: character.cpp:471
int m_TimeCpBroadcastEndTick
Definition: character.h:214
int m_MoveRestrictions
Definition: character.h:155
void ResetPickups()
Definition: character.cpp:2288
bool ShotgunHitDisabled() const
Definition: character.h:261
void StopRecording()
Definition: character.cpp:956
bool LaserHitDisabled() const
Definition: character.h:262
class CPlayer * m_pPlayer
Definition: character.h:107
void SetInvincible(bool Invincible)
Definition: character.cpp:200
void ResetVelocity()
int m_TeamBeforeSuper
Definition: character.h:202
void SetPosition(const vec2 &Position)
Definition: character.cpp:2425
int64_t m_LastRescue
Definition: character.h:223
int m_StrongWeakId
Definition: character.h:182
void Move(vec2 RelPos)
Definition: character.cpp:2430
bool m_TeleGunTeleport
Definition: character.h:228
int m_TileIndex
Definition: character.h:89
void Die(int Killer, int Weapon, bool SendKillMsg=true)
Definition: character.cpp:971
float m_Time
Definition: character.h:168
void SetJetpack(bool Active)
Definition: character.cpp:159
bool m_Paused
Definition: character.h:110
int m_DDRaceState
Definition: character.h:196
void SetWeaponGot(int Type, bool Value)
Definition: character.h:247
void GiveNinja()
Definition: character.cpp:488
void SnapCharacter(int SnappingClient, int Id)
Definition: character.cpp:1023
bool m_LastPenalty
Definition: character.h:225
int m_AttackTick
Definition: character.h:153
Definition: entity.h:13
CTuningParams * TuningList()
Definition: entity.h:36
CTuningParams * Tuning()
Definition: entity.h:35
Definition: teams.h:14
Definition: gameworld.h:17
Definition: player.h:33
Definition: save.h:34
Definition: gamecore.h:41
Definition: antibot.h:7
@ FAKETUNE_SOLO
Definition: character.h:20
@ FAKETUNE_NOCOLL
Definition: character.h:22
@ FAKETUNE_FREEZE
Definition: character.h:19
@ FAKETUNE_NOJUMP
Definition: character.h:21
@ FAKETUNE_JETPACK
Definition: character.h:24
@ FAKETUNE_NOHOOK
Definition: character.h:23
@ FAKETUNE_NOHAMMER
Definition: character.h:25
@ DDRACE_STARTED
Definition: character.h:191
@ DDRACE_FINISHED
Definition: character.h:193
@ DDRACE_CHEAT
Definition: character.h:192
@ DDRACE_NONE
Definition: character.h:190
std::bitset< MAX_CLIENTS > CClientMask
Definition: protocol.h:132
@ MAX_CHECKPOINTS
Definition: protocol.h:90
@ NUM_RESCUEMODES
Definition: save.h:19
@ RESCUEMODE_AUTO
Definition: save.h:17
Definition: antibot_data.h:43
bool m_Got
Definition: gamecore.h:201
int m_Ammo
Definition: gamecore.h:199
Definition: protocol.h:360