DDNet documentation
Loading...
Searching...
No Matches
gamecore.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_GAMECORE_H
4#define GAME_GAMECORE_H
5
6#include "prng.h"
7
8#include <base/vmath.h>
9
11
12#include <generated/protocol.h>
16#include <limits>
17#include <set>
18#include <vector>
26
27public:
28 int Get() const { return m_Value; }
30 {
31 const float Fixed = v * 100.0f;
32 if(Fixed >= static_cast<float>(std::numeric_limits<int>::min()) && Fixed < static_cast<float>(std::numeric_limits<int>::max()))
33 m_Value = static_cast<int>(Fixed);
34 else
35 m_Value = std::numeric_limits<int>::min();
36 return *this;
37 }
38 operator float() const { return m_Value / 100.0f; }
39};
40
43 static const char *ms_apNames[];
44
45public:
47 {
48#define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) m_##Name = (Value);
49#include "tuning.h"
50#undef MACRO_TUNING_PARAM
51 }
53#define MACRO_TUNING_PARAM(Name, ScriptName, Value, Description) CTuneParam m_##Name;
54#include "tuning.h"
55#undef MACRO_TUNING_PARAM
57 static int Num()
58 {
59 return sizeof(CTuningParams) / sizeof(int);
60 }
61 int *NetworkArray() { return (int *)this; }
62 const int *NetworkArray() const { return (const int *)this; }
63 bool Set(int Index, float Value);
64 bool Set(const char *pName, float Value);
65 bool Get(int Index, float *pValue) const;
66 bool Get(const char *pName, float *pValue) const;
67 static const char *Name(int Index) { return ms_apNames[Index]; }
68 float GetWeaponFireDelay(int Weapon) const;
70 static const CTuningParams DEFAULT;
71};
72
73// Do not use these function unless for legacy code!
74void StrToInts(int *pInts, size_t NumInts, const char *pStr);
75bool IntsToStr(const int *pInts, size_t NumInts, char *pStr, size_t StrSize);
76
77inline vec2 CalcPos(vec2 Pos, vec2 Velocity, float Curvature, float Speed, float Time)
78{
79 vec2 n;
80 Time *= Speed;
81 n.x = Pos.x + Velocity.x * Time;
82 n.y = Pos.y + Velocity.y * Time + Curvature / 10000 * (Time * Time);
83 return n;
84}
85
86template<typename T>
87inline T SaturatedAdd(T Min, T Max, T Current, T Modifier)
88{
89 if(Modifier < 0)
90 {
91 if(Current < Min)
92 return Current;
93 Current += Modifier;
94 if(Current < Min)
95 Current = Min;
96 return Current;
97 }
98 else
99 {
100 if(Current > Max)
101 return Current;
102 Current += Modifier;
103 if(Current > Max)
104 Current = Max;
105 return Current;
106 }
107}
108
109float VelocityRamp(float Value, float Start, float Range, float Curvature);
110
111// hooking stuff
112enum
113{
120
128};
129
130// show others values - do not change them
131enum
132{
133 SHOW_OTHERS_NOT_SET = -1, // show others value before it is set
134 SHOW_OTHERS_OFF = 0, // show no other players in solo or other teams
135 SHOW_OTHERS_ON = 1, // show all other players in solo and other teams
136 SHOW_OTHERS_ONLY_TEAM = 2 // show players that are in solo and are in the same team
137};
138
147
149{
150public:
152 {
153 for(auto &pCharacter : m_apCharacters)
154 {
155 pCharacter = nullptr;
156 }
157 m_pPrng = nullptr;
158 }
159
160 int RandomOr0(int BelowThis) // NOLINT(readability-make-member-function-const)
161 {
162 if(BelowThis <= 1 || !m_pPrng)
163 {
164 return 0;
165 }
166 // This makes the random number slightly biased if `BelowThis`
167 // is not a power of two, but we have decided that this is not
168 // significant for DDNet and favored the simple implementation.
169 return m_pPrng->RandomBits() % BelowThis;
170 }
171
174
175 void InitSwitchers(int HighestSwitchNumber);
176 std::vector<SSwitchers> m_vSwitchers;
177};
178
179typedef std::function<void(int ClientId, bool DisallowReset)> FAntiPingInterfereCallback;
180
182{
185
186public:
187 static constexpr float PhysicalSize() { return 28.0f; }
188 static constexpr vec2 PhysicalSizeVec2() { return vec2(28.0f, 28.0f); }
191
197 std::set<int> m_AttachedPlayers;
198 int HookedPlayer() const { return m_HookedPlayer; }
200
203 {
204 public:
208 bool m_Got;
209 } m_aWeapons[NUM_WEAPONS];
210
211 // ninja
212 struct
213 {
217 int m_OldVelAmount;
219
221
223 // m_JumpedTotal counts the jumps performed in the air
226
229 CNetObj_PlayerInput m_Input;
230
232
233 void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr);
234 void SetCoreWorld(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams);
235 void Reset();
236 void TickDeferred();
237 void Tick(bool UseInput, bool DoDeferredTick = true);
238 void Move();
239
240 void Read(const CNetObj_CharacterCore *pObjCore);
241 void Write(CNetObj_CharacterCore *pObjCore) const;
242 void Quantize();
243
244 // DDRace
245 int m_Id;
248
251
252 // DDNet Character
253 void SetTeamsCore(CTeamsCore *pTeams);
254 void ReadDDNet(const CNetObj_DDNetCharacter *pObjDDNet);
255 bool m_Solo;
276
277 // clientside only: antiping
279
280private:
284 static bool IsSwitchActiveCb(unsigned char Number, void *pUser);
285
286 FAntiPingInterfereCallback m_AntiPingInterfereCallback = [](int ClientId, bool DisallowReset) {};
287};
288
289// input count
291{
294};
295
296inline CInputCount CountInput(int Prev, int Cur)
297{
298 CInputCount c = {0, 0};
299 Prev &= INPUT_STATE_MASK;
300 Cur &= INPUT_STATE_MASK;
301 int i = Prev;
302
303 while(i != Cur)
304 {
305 i = (i + 1) & INPUT_STATE_MASK;
306 if(i & 1)
307 c.m_Presses++;
308 else
309 c.m_Releases++;
310 }
311
312 return c;
313}
314
315#endif
Definition gamecore.h:203
int m_AmmoRegenStart
Definition gamecore.h:205
int m_Ammocost
Definition gamecore.h:207
int m_Ammo
Definition gamecore.h:206
bool m_Got
Definition gamecore.h:208
Definition gamecore.h:182
int m_FreezeEnd
Definition gamecore.h:271
int m_Colliding
Definition gamecore.h:249
vec2 m_Vel
Definition gamecore.h:190
bool m_EndlessHook
Definition gamecore.h:258
std::set< int > m_AttachedPlayers
Definition gamecore.h:197
void TickDeferred()
Definition gamecore.cpp:465
bool m_Jetpack
Definition gamecore.h:256
bool m_LeftWall
Definition gamecore.h:250
static bool IsSwitchActiveCb(unsigned char Number, void *pUser)
Definition gamecore.cpp:740
vec2 m_HookPos
Definition gamecore.h:192
void Move()
Definition gamecore.cpp:538
bool m_Reset
Definition gamecore.h:246
CWorldCore * m_pWorld
Definition gamecore.h:183
int m_FreezeStart
Definition gamecore.h:270
int m_Direction
Definition gamecore.h:227
bool m_DeepFrozen
Definition gamecore.h:273
bool m_LiveFrozen
Definition gamecore.h:274
int m_Id
Definition gamecore.h:245
vec2 m_HookDir
Definition gamecore.h:193
static constexpr vec2 PhysicalSizeVec2()
Definition gamecore.h:188
bool m_HammerHitDisabled
Definition gamecore.h:260
int m_HookTick
Definition gamecore.h:195
void SetTeamsCore(CTeamsCore *pTeams)
Definition gamecore.cpp:735
bool m_Super
Definition gamecore.h:265
CCollision * Collision()
Definition gamecore.h:247
bool m_HasTelegunGun
Definition gamecore.h:267
bool m_IsInFreeze
Definition gamecore.h:272
bool m_LaserHitDisabled
Definition gamecore.h:262
void Quantize()
Definition gamecore.cpp:702
void SetHookedPlayer(int HookedPlayer)
Definition gamecore.cpp:709
class CCharacterCore::CWeaponStat m_aWeapons[NUM_WEAPONS]
bool m_HasTelegunLaser
Definition gamecore.h:269
int m_JumpedTotal
Definition gamecore.h:224
bool m_GrenadeHitDisabled
Definition gamecore.h:261
void Tick(bool UseInput, bool DoDeferredTick=true)
Definition gamecore.cpp:195
bool m_CollisionDisabled
Definition gamecore.h:257
bool m_HasTelegunGrenade
Definition gamecore.h:268
bool m_ShotgunHitDisabled
Definition gamecore.h:263
vec2 m_HookTeleBase
Definition gamecore.h:194
void SetCoreWorld(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams)
Definition gamecore.cpp:139
void ReadDDNet(const CNetObj_DDNetCharacter *pObjDDNet)
Definition gamecore.cpp:646
int m_Angle
Definition gamecore.h:228
bool m_Invincible
Definition gamecore.h:266
int m_TriggeredEvents
Definition gamecore.h:231
int HookedPlayer() const
Definition gamecore.h:198
static constexpr float PhysicalSize()
Definition gamecore.h:187
vec2 m_Pos
Definition gamecore.h:189
void Reset()
Definition gamecore.cpp:151
FAntiPingInterfereCallback m_AntiPingInterfereCallback
Definition gamecore.h:286
int m_ActiveWeapon
Definition gamecore.h:201
bool m_HookHitDisabled
Definition gamecore.h:264
bool m_NewHook
Definition gamecore.h:220
CTuningParams m_Tuning
Definition gamecore.h:275
void SetAntiPingInterfereCallback(FAntiPingInterfereCallback Callback)
Definition gamecore.cpp:146
int m_MoveRestrictions
Definition gamecore.h:282
void Write(CNetObj_CharacterCore *pObjCore) const
Definition gamecore.cpp:609
int m_HookState
Definition gamecore.h:196
void Read(const CNetObj_CharacterCore *pObjCore)
Definition gamecore.cpp:628
CNetObj_PlayerInput m_Input
Definition gamecore.h:229
bool m_Solo
Definition gamecore.h:255
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams=nullptr)
Definition gamecore.cpp:130
CCollision * m_pCollision
Definition gamecore.h:184
CTeamsCore * m_pTeams
Definition gamecore.h:281
int m_Jumps
Definition gamecore.h:225
struct CCharacterCore::@317352214054337255361032065311054004157320177367 m_Ninja
int m_Jumped
Definition gamecore.h:222
int m_HookedPlayer
Definition gamecore.h:283
bool m_EndlessJump
Definition gamecore.h:259
Definition collision.h:35
Definition prng.h:7
unsigned int RandomBits()
Definition prng.cpp:44
Definition teamscore.h:26
Definition gamecore.h:24
int Get() const
Definition gamecore.h:28
CTuneParam & operator=(float v)
Definition gamecore.h:29
int m_Value
Definition gamecore.h:25
Definition gamecore.h:42
bool Set(int Index, float Value)
Definition gamecore.cpp:23
static const char * Name(int Index)
Definition gamecore.h:67
static const char * ms_apNames[]
Definition gamecore.h:16
float GetWeaponFireDelay(int Weapon) const
Definition gamecore.cpp:56
static int Num()
Definition gamecore.h:57
CTuningParams()
Definition gamecore.h:46
static const CTuningParams DEFAULT
Definition gamecore.h:70
int * NetworkArray()
Definition gamecore.h:61
bool Get(int Index, float *pValue) const
Definition gamecore.cpp:31
Definition gamecore.h:149
class CCharacterCore * m_apCharacters[MAX_CLIENTS]
Definition gamecore.h:172
void InitSwitchers(int HighestSwitchNumber)
Definition gamecore.cpp:749
CPrng * m_pPrng
Definition gamecore.h:173
std::vector< SSwitchers > m_vSwitchers
Definition gamecore.h:176
CWorldCore()
Definition gamecore.h:151
int RandomOr0(int BelowThis)
Definition gamecore.h:160
float VelocityRamp(float Value, float Start, float Range, float Curvature)
Definition gamecore.cpp:123
bool IntsToStr(const int *pInts, size_t NumInts, char *pStr, size_t StrSize)
Definition gamecore.cpp:92
void StrToInts(int *pInts, size_t NumInts, const char *pStr)
Definition gamecore.cpp:72
vec2 CalcPos(vec2 Pos, vec2 Velocity, float Curvature, float Speed, float Time)
Definition gamecore.h:77
@ SHOW_OTHERS_NOT_SET
Definition gamecore.h:133
@ SHOW_OTHERS_ONLY_TEAM
Definition gamecore.h:136
@ SHOW_OTHERS_OFF
Definition gamecore.h:134
@ SHOW_OTHERS_ON
Definition gamecore.h:135
T SaturatedAdd(T Min, T Max, T Current, T Modifier)
Definition gamecore.h:87
@ HOOK_IDLE
Definition gamecore.h:115
@ HOOK_RETRACT_END
Definition gamecore.h:117
@ COREEVENT_HOOK_HIT_NOHOOK
Definition gamecore.h:126
@ HOOK_FLYING
Definition gamecore.h:118
@ HOOK_RETRACT_START
Definition gamecore.h:116
@ COREEVENT_GROUND_JUMP
Definition gamecore.h:121
@ COREEVENT_AIR_JUMP
Definition gamecore.h:122
@ COREEVENT_HOOK_ATTACH_GROUND
Definition gamecore.h:125
@ COREEVENT_HOOK_LAUNCH
Definition gamecore.h:123
@ HOOK_RETRACTED
Definition gamecore.h:114
@ HOOK_GRABBED
Definition gamecore.h:119
@ COREEVENT_HOOK_RETRACT
Definition gamecore.h:127
@ COREEVENT_HOOK_ATTACH_PLAYER
Definition gamecore.h:124
std::function< void(int ClientId, bool DisallowReset)> FAntiPingInterfereCallback
Definition gamecore.h:179
CInputCount CountInput(int Prev, int Cur)
Definition gamecore.h:296
@ MAX_CLIENTS
Definition protocol.h:89
Definition gamecore.h:291
int m_Presses
Definition gamecore.h:292
int m_Releases
Definition gamecore.h:293
Definition gamecore.h:140
int m_aType[NUM_DDRACE_TEAMS]
Definition gamecore.h:144
bool m_aStatus[NUM_DDRACE_TEAMS]
Definition gamecore.h:141
int m_aLastUpdateTick[NUM_DDRACE_TEAMS]
Definition gamecore.h:145
bool m_Initial
Definition gamecore.h:142
int m_aEndTick[NUM_DDRACE_TEAMS]
Definition gamecore.h:143
@ NUM_DDRACE_TEAMS
Definition teamscore.h:11
vector2_base< float > vec2
Definition vmath.h:168