DDraceNetwork Docs
gamecontroller.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_GAMECONTROLLER_H
4#define GAME_SERVER_GAMECONTROLLER_H
5
6#include <base/vmath.h>
7#include <engine/map.h>
9#include <game/server/teams.h>
10
12
13/*
14 Class: Game Controller
15 Controls the main game logic. Keeping track of team and player score,
16 winning conditions and specific game logic.
17*/
19{
20 friend class CSaveTeam; // need access to GameServer() and Server()
21
22 std::vector<vec2> m_avSpawnPoints[3];
23
27
29
30protected:
32 CConfig *Config() { return m_pConfig; }
33 IServer *Server() const { return m_pServer; }
34
35 void DoActivityCheck();
36
38 {
40 {
41 m_Got = false;
42 m_FriendlyTeam = -1;
43 m_Pos = vec2(100, 100);
44 }
45
47 bool m_Got;
49 float m_Score;
50 };
51
52 float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos, int DDTeam);
53 void EvaluateSpawnType(CSpawnEval *pEval, int Type, int DDTeam);
54
55 void ResetGame();
56
58
62
65
69
70public:
71 const char *m_pGameType;
72
73 IGameController(class CGameContext *pGameServer);
75
76 // event
77 /*
78 Function: OnCharacterDeath
79 Called when a CCharacter in the world dies.
80
81 Arguments:
82 victim - The CCharacter that died.
83 killer - The player that killed it.
84 weapon - What weapon that killed it. Can be -1 for undefined
85 weapon when switching team or player suicides.
86 */
87 virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
88 /*
89 Function: OnCharacterSpawn
90 Called when a CCharacter spawns into the game world.
91
92 Arguments:
93 chr - The CCharacter that was spawned.
94 */
95 virtual void OnCharacterSpawn(class CCharacter *pChr);
96
97 virtual void HandleCharacterTiles(class CCharacter *pChr, int MapIndex);
98 virtual void SetArmorProgress(CCharacter *pCharacer, int Progress){};
99
100 /*
101 Function: OnEntity
102 Called when the map is loaded to process an entity
103 in the map.
104
105 Arguments:
106 index - Entity index.
107 pos - Where the entity is located in the world.
108
109 Returns:
110 bool?
111 */
112 virtual bool OnEntity(int Index, int x, int y, int Layer, int Flags, bool Initial, int Number = 0);
113
114 virtual void OnPlayerConnect(class CPlayer *pPlayer);
115 virtual void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason);
116
117 virtual void OnReset();
118
119 // game
120 void DoWarmup(int Seconds);
121
122 void StartRound();
123 void EndRound();
124 void ChangeMap(const char *pToMap);
125
126 bool IsForceBalanced();
127
128 /*
129
130 */
131 virtual bool CanBeMovedOnBalance(int ClientId);
132
133 virtual void Tick();
134
135 virtual void Snap(int SnappingClient);
136
137 //spawn
138 virtual bool CanSpawn(int Team, vec2 *pOutPos, int DDTeam);
139
140 virtual void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg = true);
141 /*
142
143 */
144 virtual const char *GetTeamName(int Team);
145 virtual int GetAutoTeam(int NotThisId);
146 virtual bool CanJoinTeam(int Team, int NotThisId, char *pErrorReason, int ErrorReasonSize);
147 int ClampTeam(int Team);
148
149 CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptID = -1);
150
152 // DDRace
153
155 CGameTeams &Teams() { return m_Teams; }
156 std::shared_ptr<CScoreLoadBestTimeResult> m_pLoadBestTimeResult;
157};
158
159#endif
Definition: character.h:30
Definition: config.h:23
Definition: gamecontext.h:79
Definition: teams.h:14
Definition: player.h:33
Definition: save.h:152
Definition: gamecontroller.h:19
virtual void Snap(int SnappingClient)
Definition: gamecontroller.cpp:571
void EndRound()
Definition: gamecontroller.cpp:441
virtual void OnPlayerConnect(class CPlayer *pPlayer)
Definition: gamecontroller.cpp:390
CGameTeams m_Teams
Definition: gamecontroller.h:28
virtual void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason)
Definition: gamecontroller.cpp:423
virtual const char * GetTeamName(int Team)
Definition: gamecontroller.cpp:456
CClientMask GetMaskForPlayerWorldEvent(int Asker, int ExceptID=-1)
Definition: gamecontroller.cpp:724
virtual void OnReset()
Definition: gamecontroller.cpp:483
class CConfig * m_pConfig
Definition: gamecontroller.h:25
virtual bool CanJoinTeam(int Team, int NotThisId, char *pErrorReason, int ErrorReasonSize)
Definition: gamecontroller.cpp:687
virtual void SetArmorProgress(CCharacter *pCharacer, int Progress)
Definition: gamecontroller.h:98
virtual bool CanSpawn(int Team, vec2 *pOutPos, int DDTeam)
Definition: gamecontroller.cpp:157
std::shared_ptr< CScoreLoadBestTimeResult > m_pLoadBestTimeResult
Definition: gamecontroller.h:156
int m_Warmup
Definition: gamecontroller.h:63
virtual void Tick()
Definition: gamecontroller.cpp:531
virtual void HandleCharacterTiles(class CCharacter *pChr, int MapIndex)
Definition: gamecontroller.cpp:508
void ResetGame()
Definition: gamecontroller.cpp:451
bool m_ForceBalanced
Definition: gamecontroller.h:68
const char * m_pGameType
Definition: gamecontroller.h:71
int m_GameOverTick
Definition: gamecontroller.h:60
bool IsForceBalanced()
Definition: gamecontroller.cpp:521
char m_aMapWish[MAX_MAP_LENGTH]
Definition: gamecontroller.h:57
CConfig * Config()
Definition: gamecontroller.h:32
virtual void OnCharacterSpawn(class CCharacter *pChr)
Definition: gamecontroller.cpp:495
int m_UnbalancedTick
Definition: gamecontroller.h:67
CGameTeams & Teams()
Definition: gamecontroller.h:155
virtual ~IGameController()
virtual bool CanBeMovedOnBalance(int ClientId)
Definition: gamecontroller.cpp:526
virtual void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg=true)
Definition: gamecontroller.cpp:732
CGameContext * GameServer() const
Definition: gamecontroller.h:31
void EvaluateSpawnType(CSpawnEval *pEval, int Type, int DDTeam)
Definition: gamecontroller.cpp:108
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon)
Definition: gamecontroller.cpp:490
std::vector< vec2 > m_avSpawnPoints[3]
Definition: gamecontroller.h:22
void DoWarmup(int Seconds)
Definition: gamecontroller.cpp:513
IServer * Server() const
Definition: gamecontroller.h:33
void ChangeMap(const char *pToMap)
Definition: gamecontroller.cpp:478
float m_CurrentRecord
Definition: gamecontroller.h:154
class IServer * m_pServer
Definition: gamecontroller.h:26
float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos, int DDTeam)
Definition: gamecontroller.cpp:91
virtual bool OnEntity(int Index, int x, int y, int Layer, int Flags, bool Initial, int Number=0)
Definition: gamecontroller.cpp:172
void StartRound()
Definition: gamecontroller.cpp:463
int m_SuddenDeath
Definition: gamecontroller.h:61
class CGameContext * m_pGameServer
Definition: gamecontroller.h:24
int m_RoundCount
Definition: gamecontroller.h:64
int m_RoundStartTick
Definition: gamecontroller.h:59
virtual int GetAutoTeam(int NotThisId)
Definition: gamecontroller.cpp:668
int ClampTeam(int Team)
Definition: gamecontroller.cpp:717
void DoActivityCheck()
Definition: gamecontroller.cpp:48
IGameController(class CGameContext *pGameServer)
Definition: gamecontroller.cpp:23
int m_GameFlags
Definition: gamecontroller.h:66
bool IsTeamPlay()
Definition: gamecontroller.h:151
Definition: server.h:30
std::bitset< MAX_CLIENTS > CClientMask
Definition: protocol.h:132
@ GAMEFLAG_TEAMS
Definition: protocol.h:145
@ MAX_MAP_LENGTH
Definition: map.h:12
Definition: scoreworker.h:67
Definition: gamecontroller.h:38
bool m_Got
Definition: gamecontroller.h:47
int m_FriendlyTeam
Definition: gamecontroller.h:48
float m_Score
Definition: gamecontroller.h:49
vec2 m_Pos
Definition: gamecontroller.h:46
CSpawnEval()
Definition: gamecontroller.h:39
vector2_base< float > vec2
Definition: vmath.h:158