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