Skip to content

Instantly share code, notes, and snippets.

@Learath2
Created February 9, 2020 17:37
Show Gist options
  • Save Learath2/cfe46b3bbd59b27092a29cb664e8578c to your computer and use it in GitHub Desktop.
Save Learath2/cfe46b3bbd59b27092a29cb664e8578c to your computer and use it in GitHub Desktop.
Abstract GV
#include <game/server/gamecontext.h>
/*
Interface: IGameController
Abstract base class for gamecontrollers
*/
class IGameController
{
class CGameContext *m_pGameContext;
class CConfig *m_pConfig;
class IServer *m_pServer;
protected:
class CGameContext *GameServer() const { return m_pGameContext; }
class CConfig *Config() const { return m_pConfig; }
class IServer *Server() const { return m_pServer; }
public:
IGameController(CGameContext *pGameContext) : m_pGameContext(pGameContext)
{
m_pConfig = pGameContext->Config();
m_pServer = pGameContext->Server();
}
virtual const char *GetGameType() const = 0;
// World events
/*
Event: OnCharacterDeath
Called when a CCharacter in the world dies.
Arguments:
pVictim - The CCharacter that died.
pKiller - The CPlayer that killed it.
Weapon - The Weapon that killed it. Can be -1 for undefined
weapon when switching team or suicide.
*/
virtual int OnCharacterDeath(class CCharacter *pVictim, class CPlayer *pKiller, int Weapon) = 0;
/*
Event: OnCharacterSpawn
Called when a CCharacter spawns into the game world.
Arguments:
pCharacter - The CCharacter that was spawned.
*/
virtual void OnCharacterSpawn(class CCharacter *pCharacter) = 0;
/*
Event: OnFlagReturn
Called when a CFlag is returned.
Arguments:
pFlag - The CFlag that was returned.
*/
virtual void OnFlagReturn(class CFlag *pFlag) = 0;
/*
Event: OnEntity
Called during map loads to process an entity.
Arguments:
Index - Entity index.
Pos - Where the entity is located in the world
*/
virtual bool OnEntity(int Index, vec2 Pos) = 0;
/*
Event: PostWorldReset
Called after the game world is reset.
Arguments:
pWorld - World that was reset.
*/
virtual void PostWorldReset(class CGameWorld *pWorld) = 0;
// Server events
/*
Event: OnPlayerConnect
Called when a player enters the game.
Arguments:
pPlayer - The CPlayer that entered the game.
*/
virtual void OnPlayerConnect(class CPlayer *pPlayer) = 0;
/*
Event: OnPlayerDisconnect
Called when a player leaves the game.
Arguments:
pPlayer - The CPlayer that left the game.
*/
virtual void OnPlayerDisconnect(class CPlayer *pPlayer) = 0;
/*
Event: OnPlayerDisconnect
Called when a player changes their info.
Arguments:
pPlayer - The CPlayer that changed info.
*/
virtual void OnPlayerInfoChange(class CPlayer *pPlayer) = 0;
/*
Event: OnPlayerReadyChange
Called when a player changes their ready state.
Arguments:
pPlayer - The CPlayer that changed it's ready state.
*/
virtual void OnPlayerReadyChange(class CPlayer *pPlayer) = 0;
/* TODO: Check whether this can be reworked with OnConsoleInit
Event: SwapTeamScore > PostTeamSwap
Called after a team swap.
*/
virtual void SwapTeamscore() = 0;
virtual void Snap(int SnappingClient) = 0;
virtual void Tick() = 0;
//
/*
Function: DoPause
Called when a pause is requested.
Arguments:
Seconds - Pause duration
*/
virtual void DoPause(int Seconds) = 0;
/*
Function: DoWarmup
Called when a warmup is requested.
Arguments:
Seconds - Warmup duration
*/
virtual void DoWarmup(int Seconds) = 0;
// TODO: Refactor this with OnConsoleInit
virtual void CheckGameInfo() = 0;
// TODO: Handle PLAYER_TEAM_BLUE/RED here
virtual bool IsFriendlyFire(int ClientID1, int ClientID2) const = 0;
// TODO: Drop this
virtual bool IsFriendlyTeamFire(int Team1, int Team2) const = 0;
virtual bool IsGamePaused() const = 0;
virtual bool IsGameRunning() const = 0;
virtual bool IsPlayerReadyMode() const = 0;
virtual bool IsTeamChangeAllowed() const = 0;
// TODO: Investigate these
virtual bool IsTeamplay() const = 0;
virtual bool IsSurvival() const = 0;
// Does this really belong here?
// EndMatch from CGameContext + CycleMap/sv_map
virtual void ChangeMap(const char *pMap) = 0;
virtual bool CanSpawn(int Team, vec2 *pPos) const = 0;
// TODO: Investigate
virtual bool GetStartRespawnState() const = 0;
virtual bool CanJoinTeam(int Team, int NotThisID) const = 0;
virtual bool CanChangeTeam(CPlayer *pPlayer, int JoinTeam) const = 0;
// TODO: Check if DoChatMsg belongs here
virtual void DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg = false) = 0;
virtual void ForceTeamBalance() = 0;
virtual int GetRealPlayerNum() const = 0;
// TODO: Why isn't this fnc pure?
virtual int GetStartTeam() = 0;
virtual void RegisterChatCommands(CCommandManager *pManager) = 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment