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_CLIENT_PREDICTION_ENTITIES_CHARACTER_H
4#define GAME_CLIENT_PREDICTION_ENTITIES_CHARACTER_H
5
7
8#include <game/gamecore.h>
9
10enum
11{
12 WEAPON_GAME = -3, // team switching etc
13 WEAPON_SELF = -2, // console kill command
14 WEAPON_WORLD = -1, // death tiles etc
15};
16
17enum
18{
26
27};
28
29class CCharacter : public CEntity
30{
31 friend class CGameWorld;
32
33public:
35
36 void PreTick() override;
37 void Tick() override;
38 void TickDeferred() override;
39
40 bool IsGrounded();
41
42 void SetWeapon(int W);
43 void SetSolo(bool Solo);
44 void SetSuper(bool Super);
45 void HandleWeaponSwitch();
46 void DoWeaponSwitch();
47
48 void HandleWeapons();
49 void HandleNinja();
50 void HandleJetpack();
51
53 void OnDirectInput(CNetObj_PlayerInput *pNewInput);
54 void ReleaseHook();
55 void ResetHook();
56 void ResetInput();
57 void FireWeapon();
58
59 bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon);
60
61 void GiveWeapon(int Weapon, bool Remove = false);
62 void GiveNinja();
63 void RemoveNinja();
64
65 void ResetVelocity();
66 void SetVelocity(vec2 NewVelocity);
67 void SetRawVelocity(vec2 NewVelocity);
68 void AddVelocity(vec2 Addition);
70
72
74 bool Freeze(int Seconds);
75 bool Freeze();
76 bool UnFreeze();
77 void GiveAllWeapons();
78 int Team();
79 bool CanCollide(int ClientId);
80 bool SameTeam(int ClientId);
88
91
93
94 // Setters/Getters because i don't want to modify vanilla vars access modifiers
95 int GetLastWeapon() { return m_LastWeapon; }
96 void SetLastWeapon(int LastWeap) { m_LastWeapon = LastWeap; }
98 void SetActiveWeapon(int ActiveWeap);
101 const CCharacterCore *Core() const { return &m_Core; }
102 bool GetWeaponGot(int Type) { return m_Core.m_aWeapons[Type].m_Got; }
103 void SetWeaponGot(int Type, bool Value) { m_Core.m_aWeapons[Type].m_Got = Value; }
104 int GetWeaponAmmo(int Type) { return m_Core.m_aWeapons[Type].m_Ammo; }
105 void SetWeaponAmmo(int Type, int Value) { m_Core.m_aWeapons[Type].m_Ammo = Value; }
106 void SetNinjaActivationDir(vec2 ActivationDir) { m_Core.m_Ninja.m_ActivationDir = ActivationDir; }
107 void SetNinjaActivationTick(int ActivationTick) { m_Core.m_Ninja.m_ActivationTick = ActivationTick; }
108 void SetNinjaCurrentMoveTime(int CurrentMoveTime) { m_Core.m_Ninja.m_CurrentMoveTime = CurrentMoveTime; }
109 int GetCid() { return m_Id; }
110 void SetInput(const CNetObj_PlayerInput *pNewInput)
111 {
112 m_LatestInput = m_Input = *pNewInput;
113 // it is not allowed to aim in the center
114 if(m_Input.m_TargetX == 0 && m_Input.m_TargetY == 0)
115 {
117 }
118 };
119 int GetJumped() { return m_Core.m_Jumped; }
120 int GetAttackTick() { return m_AttackTick; }
122
123 CCharacter(CGameWorld *pGameWorld, int Id, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended = 0);
124 void Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, bool IsLocal);
125 void SetCoreWorld(CGameWorld *pGameWorld);
126
132
133 bool Match(CCharacter *pChar) const;
134 void ResetPrediction();
135 void SetTuneZone(int Zone);
136
141
142 bool IsSuper() { return m_Core.m_Super; }
143
144private:
145 // weapon info
148
151
154
156
157 // these are non-heldback inputs
160
161 // input
165
167
168 // the player core for the physics
170
171 // DDRace
172
173 static bool IsSwitchActiveCb(int Number, void *pUser);
174 void HandleTiles(int Index);
175 void HandleSkippableTiles(int Index);
176 void DDRaceTick();
177 void DDRacePostCoreTick();
178 void HandleTuneLayer();
179
181
183
186};
187
188enum
189{
192 DDRACE_CHEAT, // no time and won't start again unless ordered by a mod or death
195
196#endif
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_LaserHitDisabled
Definition: gamecore.h:255
bool m_GrenadeHitDisabled
Definition: gamecore.h:254
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
int m_Jumped
Definition: gamecore.h:215
struct CCharacterCore::WeaponStat m_aWeapons[NUM_WEAPONS]
Definition: character.h:30
void FireWeapon()
Definition: character.cpp:251
int m_NumInputs
Definition: character.h:166
void SetLastWeapon(int LastWeap)
Definition: character.h:96
vec2 m_PrevPrevPos
Definition: character.h:86
bool GetWeaponGot(int Type)
Definition: character.h:102
int m_ReloadTimer
Definition: character.h:152
CNetObj_PlayerInput m_LatestPrevInput
Definition: character.h:158
void ApplyMoveRestrictions()
Definition: character.cpp:1143
void RemoveNinja()
Definition: character.cpp:96
void DDRaceTick()
Definition: character.cpp:959
void SetActiveWeapon(int ActiveWeap)
Definition: character.cpp:1406
void HandleTiles(int Index)
Definition: character.cpp:707
void SetCoreWorld(CGameWorld *pGameWorld)
Definition: character.cpp:1396
bool m_LastRefillJumps
Definition: character.h:92
const CCharacterCore * Core() const
Definition: character.h:101
void SetNinjaActivationTick(int ActivationTick)
Definition: character.h:107
int m_LastWeapon
Definition: character.h:149
void ResetInput()
Definition: character.cpp:562
void ResetHook()
Definition: character.cpp:556
void HandleSkippableTiles(int Index)
Definition: character.cpp:636
int m_NumObjectsHit
Definition: character.h:147
void OnPredictedInput(CNetObj_PlayerInput *pNewInput)
Definition: character.cpp:499
bool m_FrozenLastTick
Definition: character.h:83
void Tick() override
Definition: character.cpp:582
CNetObj_PlayerInput m_SavedInput
Definition: character.h:164
int m_LastSnapWeapon
Definition: character.h:127
void HandleNinja()
Definition: character.cpp:105
int GetWeaponAmmo(int Type)
Definition: character.h:104
void AddVelocity(vec2 Addition)
Definition: character.cpp:1138
void OnDirectInput(CNetObj_PlayerInput *pNewInput)
Definition: character.cpp:520
bool Freeze()
Definition: character.cpp:1070
void ReleaseHook()
Definition: character.cpp:549
bool ShotgunHitDisabled()
Definition: character.h:138
CCharacterCore m_Core
Definition: character.h:169
bool Match(CCharacter *pChar) const
Definition: character.cpp:1401
void SetCore(CCharacterCore Core)
Definition: character.h:100
bool m_KeepHooked
Definition: character.h:129
CNetObj_PlayerInput m_PrevInput
Definition: character.h:162
int GetActiveWeapon()
Definition: character.h:97
int m_TuneZone
Definition: character.h:84
int Team()
Definition: character.cpp:631
int m_GameTeam
Definition: character.h:130
void SetNinjaCurrentMoveTime(int CurrentMoveTime)
Definition: character.h:108
bool m_IsLocal
Definition: character.h:71
void DoWeaponSwitch()
Definition: character.cpp:191
static bool IsSwitchActiveCb(int Number, void *pUser)
Definition: character.cpp:700
void SetWeapon(int W)
Definition: character.cpp:14
bool TakeDamage(vec2 Force, int Dmg, int From, int Weapon)
Definition: character.cpp:612
int m_FreezeTime
Definition: character.h:82
void SetSolo(bool Solo)
Definition: character.cpp:27
void SetSuper(bool Super)
Definition: character.cpp:33
bool CanCollide(int ClientId)
Definition: character.cpp:621
void SetWeaponAmmo(int Type, int Value)
Definition: character.h:105
void HandleWeaponSwitch()
Definition: character.cpp:201
void HandleTuneLayer()
Definition: character.cpp:949
vec2 m_PrevPos
Definition: character.h:85
CTeamsCore * TeamsCore()
Definition: character.cpp:1148
int m_aHitObjects[10]
Definition: character.h:146
void PreTick() override
Definition: character.cpp:574
bool IsGrounded()
Definition: character.cpp:40
bool LaserHitDisabled()
Definition: character.h:139
void SetVelocity(vec2 NewVelocity)
Definition: character.cpp:1128
bool HammerHitDisabled()
Definition: character.h:137
~CCharacter()
Definition: character.cpp:1420
bool SameTeam(int ClientId)
Definition: character.cpp:626
CTuningParams * CharacterTuning()
bool Remove()
bool m_CanMoveInFreeze
Definition: character.h:131
int GetStrongWeakId()
Definition: character.h:121
CCharacterCore GetCore()
Definition: character.h:99
bool UnFreeze()
Definition: character.cpp:1075
int m_QueuedWeapon
Definition: character.h:150
void DDRacePostCoreTick()
Definition: character.cpp:1000
void HandleJetpack()
Definition: character.cpp:51
int GetJumped()
Definition: character.h:119
void SetRawVelocity(vec2 NewVelocity)
Definition: character.cpp:1133
bool IsSuper()
Definition: character.h:142
int GetAttackTick()
Definition: character.h:120
int m_LastTuneZoneTick
Definition: character.h:185
int GetCid()
Definition: character.h:109
int GetLastWeapon()
Definition: character.h:95
void SetNinjaActivationDir(vec2 ActivationDir)
Definition: character.h:106
void GiveWeapon(int Weapon, bool Remove=false)
Definition: character.cpp:1089
void SetInput(const CNetObj_PlayerInput *pNewInput)
Definition: character.h:110
void TickDeferred() override
Definition: character.cpp:605
CNetObj_PlayerInput m_Input
Definition: character.h:163
int m_LastJetpackStrength
Definition: character.h:128
bool m_NinjaJetpack
Definition: character.h:81
int m_TeleCheckpoint
Definition: character.h:87
void GiveAllWeapons()
Definition: character.cpp:1113
int m_TileFIndex
Definition: character.h:90
CNetObj_PlayerInput m_LatestInput
Definition: character.h:159
void HandleWeapons()
Definition: character.cpp:471
void ResetPrediction()
Definition: character.cpp:1187
int m_MoveRestrictions
Definition: character.h:155
void ResetVelocity()
Definition: character.cpp:1121
int m_StrongWeakId
Definition: character.h:182
bool GrenadeHitDisabled()
Definition: character.h:140
int m_LastWeaponSwitchTick
Definition: character.h:184
int m_TileIndex
Definition: character.h:89
CCharacter(CGameWorld *pGameWorld, int Id, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended=0)
Definition: character.cpp:1153
void Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, bool IsLocal)
Definition: character.cpp:1223
void SetTuneZone(int Zone)
Definition: character.cpp:1412
void SetWeaponGot(int Type, bool Value)
Definition: character.h:103
void GiveNinja()
Definition: character.cpp:488
int m_AttackTick
Definition: character.h:153
Definition: entity.h:13
int m_Id
Definition: entity.h:24
Definition: gameworld.h:17
Definition: teamscore.h:25
Definition: gamecore.h:41
@ 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
@ WEAPON_SELF
Definition: character.h:13
@ WEAPON_GAME
Definition: character.h:12
@ WEAPON_WORLD
Definition: character.h:14
bool m_Got
Definition: gamecore.h:201
int m_Ammo
Definition: gamecore.h:199
Definition: protocol.h:455
Definition: protocol.h:513
Definition: protocol.h:360
int m_TargetY
Definition: protocol.h:364
int m_TargetX
Definition: protocol.h:363