ddnet/src/game/server/gamecontroller.h

153 lines
3.3 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_SERVER_GAMECONTROLLER_H
#define GAME_SERVER_GAMECONTROLLER_H
#include <base/vmath.h>
2020-06-18 16:29:27 +00:00
#include <engine/map.h>
2010-05-29 07:25:38 +00:00
/*
Class: Game Controller
Controls the main game logic. Keeping track of team and player score,
winning conditions and specific game logic.
*/
class IGameController
{
2018-02-04 15:00:47 +00:00
friend class CSaveTeam; // need access to GameServer() and Server()
2015-07-09 00:08:14 +00:00
2010-05-29 07:25:38 +00:00
vec2 m_aaSpawnPoints[3][64];
int m_aNumSpawnPoints[3];
2010-05-29 07:25:38 +00:00
class CGameContext *m_pGameServer;
class CConfig *m_pConfig;
2010-05-29 07:25:38 +00:00
class IServer *m_pServer;
2010-05-29 07:25:38 +00:00
protected:
CGameContext *GameServer() const { return m_pGameServer; }
CConfig *Config() { return m_pConfig; }
2010-05-29 07:25:38 +00:00
IServer *Server() const { return m_pServer; }
void DoActivityCheck();
2010-05-29 07:25:38 +00:00
struct CSpawnEval
{
CSpawnEval()
{
m_Got = false;
m_FriendlyTeam = -1;
m_Pos = vec2(100, 100);
2010-05-29 07:25:38 +00:00
}
2010-05-29 07:25:38 +00:00
vec2 m_Pos;
bool m_Got;
int m_FriendlyTeam;
float m_Score;
};
float EvaluateSpawnPos(CSpawnEval *pEval, vec2 Pos);
void EvaluateSpawnType(CSpawnEval *pEval, int Type);
void ResetGame();
2020-06-18 16:29:27 +00:00
char m_aMapWish[MAX_MAP_LENGTH];
2010-05-29 07:25:38 +00:00
int m_RoundStartTick;
int m_GameOverTick;
int m_SuddenDeath;
2010-05-29 07:25:38 +00:00
int m_Warmup;
int m_RoundCount;
2010-05-29 07:25:38 +00:00
int m_GameFlags;
int m_UnbalancedTick;
bool m_ForceBalanced;
2010-05-29 07:25:38 +00:00
public:
const char *m_pGameType;
IGameController(class CGameContext *pGameServer);
virtual ~IGameController();
// event
2010-05-29 07:25:38 +00:00
/*
Function: OnCharacterDeath
Called when a CCharacter in the world dies.
Arguments:
victim - The CCharacter that died.
killer - The player that killed it.
weapon - What weapon that killed it. Can be -1 for undefined
weapon when switching team or player suicides.
*/
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon);
/*
Function: OnCharacterSpawn
Called when a CCharacter spawns into the game world.
Arguments:
chr - The CCharacter that was spawned.
*/
virtual void OnCharacterSpawn(class CCharacter *pChr);
virtual void HandleCharacterTiles(class CCharacter *pChr, int MapIndex);
2010-05-29 07:25:38 +00:00
/*
Function: OnEntity
2010-05-29 07:25:38 +00:00
Called when the map is loaded to process an entity
in the map.
2010-05-29 07:25:38 +00:00
Arguments:
index - Entity index.
pos - Where the entity is located in the world.
2010-05-29 07:25:38 +00:00
Returns:
bool?
*/
virtual bool OnEntity(int Index, vec2 Pos, int Layer, int Flags, int Number = 0);
virtual void OnPlayerConnect(class CPlayer *pPlayer);
virtual void OnPlayerDisconnect(class CPlayer *pPlayer, const char *pReason);
void OnReset();
// game
void DoWarmup(int Seconds);
void StartRound();
void EndRound();
void ChangeMap(const char *pToMap);
bool IsFriendlyFire(int ClientID1, int ClientID2);
bool IsForceBalanced();
2010-05-29 07:25:38 +00:00
/*
2010-05-29 07:25:38 +00:00
*/
virtual bool CanBeMovedOnBalance(int ClientID);
virtual void Tick();
2010-05-29 07:25:38 +00:00
virtual void Snap(int SnappingClient);
//spawn
2011-02-14 07:43:44 +00:00
virtual bool CanSpawn(int Team, vec2 *pPos);
2010-05-29 07:25:38 +00:00
virtual void DoTeamChange(class CPlayer *pPlayer, int Team, bool DoChatMsg = true);
2010-05-29 07:25:38 +00:00
/*
*/
2010-05-29 07:25:38 +00:00
virtual const char *GetTeamName(int Team);
virtual int GetAutoTeam(int NotThisID);
virtual bool CanJoinTeam(int Team, int NotThisID);
2010-05-29 07:25:38 +00:00
int ClampTeam(int Team);
2021-06-23 05:05:49 +00:00
virtual int64_t GetMaskForPlayerWorldEvent(int Asker, int ExceptID = -1);
// DDRace
2011-01-29 00:59:50 +00:00
float m_CurrentRecord;
2010-05-29 07:25:38 +00:00
};
2011-02-14 07:43:44 +00:00
#endif