Skip to content

Commit

Permalink
GameController: Refactor GameType as virtual getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine committed Dec 16, 2024
1 parent 3c6b904 commit 02d95c9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,9 +1090,9 @@ void CGameContext::CheckPureTuning()
if(!m_pController)
return;

if( str_comp(m_pController->m_pGameType, "DM")==0 ||
str_comp(m_pController->m_pGameType, "TDM")==0 ||
str_comp(m_pController->m_pGameType, "CTF")==0)
if( str_comp(m_pController->GameType(), "DM")==0 ||
str_comp(m_pController->GameType(), "TDM")==0 ||
str_comp(m_pController->GameType(), "CTF")==0)
{
CTuningParams p;
if(mem_comp(&p, &m_Tuning, sizeof(p)) != 0)
Expand Down Expand Up @@ -4747,7 +4747,7 @@ int CGameContext::PersistentClientDataSize() const
}

CUuid CGameContext::GameUuid() const { return m_GameUuid; }
const char *CGameContext::GameType() const { return m_pController && m_pController->m_pGameType ? m_pController->m_pGameType : ""; }
const char *CGameContext::GameType() const { return m_pController ? m_pController->GameType() : ""; }
const char *CGameContext::Version() const { return GAME_VERSION; }
const char *CGameContext::NetVersion() const { return GAME_NETVERSION; }

Expand Down
8 changes: 6 additions & 2 deletions src/game/server/gamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ IGameController::IGameController(class CGameContext *pGameServer)
m_pGameServer = pGameServer;
m_pConfig = m_pGameServer->Config();
m_pServer = m_pGameServer->Server();
m_pGameType = "unknown";

//
DoWarmup(g_Config.m_SvWarmup);
Expand Down Expand Up @@ -407,7 +406,7 @@ void IGameController::StartRound()
m_ForceBalanced = false;
Server()->DemoRecorder_HandleAutoStart();
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "start round type='%s' teamplay='%d' id='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS, m_RoundId);
str_format(aBuf, sizeof(aBuf), "start round type='%s' teamplay='%d' id='%d'", GameType(), m_GameFlags&GAMEFLAG_TEAMS, m_RoundId);
GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf);
}

Expand Down Expand Up @@ -1300,6 +1299,11 @@ void IGameController::DoWincheck()
{
}

const char *IGameController::GameType() const
{
return "unknown";
}

int IGameController::ClampTeam(int Team)
{
if(Team < 0)
Expand Down
4 changes: 2 additions & 2 deletions src/game/server/gamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class IGameController
bool m_ForceBalanced;

public:
const char *m_pGameType;

void SkipMap();

bool IsTeamplay() const;
Expand All @@ -102,6 +100,8 @@ class IGameController
IGameController(class CGameContext *pGameServer);
virtual ~IGameController();

virtual const char *GameType() const;

virtual void DoWincheck();

// event
Expand Down
7 changes: 5 additions & 2 deletions src/game/server/infclass/infcgamecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ IGameController *CreateInfclassModController(CGameContext *pGameServer) { return
CInfClassGameController::CInfClassGameController(class CGameContext *pGameServer)
: IGameController(pGameServer), m_Teams(pGameServer)
{
m_pGameType = "InfClassR";

m_Teams.m_Core.m_IsInfclass = true;

for(std::vector<vec2> &vTeamSpawnPoints : m_avSpawnPoints)
Expand Down Expand Up @@ -211,6 +209,11 @@ CInfClassGameController::~CInfClassGameController()
if(m_GrowingMap) delete[] m_GrowingMap;
}

const char *CInfClassGameController::GameType() const
{
return "InfClassR";
}

void CInfClassGameController::IncreaseCurrentRoundCounter()
{
IGameController::IncreaseCurrentRoundCounter();
Expand Down
2 changes: 2 additions & 0 deletions src/game/server/infclass/infcgamecontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class CInfClassGameController : public IGameController
CInfClassGameController(class CGameContext *pGameServer);
~CInfClassGameController() override;

const char *GameType() const override;

void IncreaseCurrentRoundCounter() override;

void DoTeamBalance() override;
Expand Down

0 comments on commit 02d95c9

Please sign in to comment.