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