#include "precompiled.h" CCSTutorStateSystem::CCSTutorStateSystem() { m_currentState = new CCSTutorUndefinedState; } CCSTutorStateSystem::~CCSTutorStateSystem() { if (m_currentState) { delete m_currentState; m_currentState = nullptr; } } bool CCSTutorStateSystem::UpdateState(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { if (!m_currentState) { m_currentState = new CCSTutorUndefinedState; } if (m_currentState) { TutorStateType nextStateType = m_currentState->CheckForStateTransition(event, entity, other); if (nextStateType != TUTORSTATE_UNDEFINED) { delete m_currentState; m_currentState = ConstructNewState(nextStateType); return true; } } return false; } const char *CCSTutorStateSystem::GetCurrentStateString() { if (m_currentState) { return m_currentState->GetStateString(); } return nullptr; } CBaseTutorState *CCSTutorStateSystem::ConstructNewState(TutorStateType stateType) { switch (stateType) { case TUTORSTATE_BUYTIME: return new CCSTutorBuyMenuState; case TUTORSTATE_WAITING_FOR_START: return new CCSTutorWaitingForStartState; case TUTORSTATE_UNDEFINED: return new CCSTutorUndefinedState; } return nullptr; } CCSTutorUndefinedState::CCSTutorUndefinedState() { m_type = TUTORSTATE_UNDEFINED; } CCSTutorUndefinedState::~CCSTutorUndefinedState() { ; } TutorStateType CCSTutorUndefinedState::CheckForStateTransition(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { if (event == EVENT_PLAYER_SPAWNED) { return HandlePlayerSpawned(entity, other); } return TUTORSTATE_UNDEFINED; } TutorStateType CCSTutorUndefinedState::HandlePlayerSpawned(CBaseEntity *entity, CBaseEntity *other) { CBasePlayer *pLocalPlayer = UTIL_GetLocalPlayer(); if (pLocalPlayer) { CBasePlayer *pPlayer = static_cast(entity); if (pPlayer && pPlayer->IsPlayer() && pPlayer == pLocalPlayer) { return TUTORSTATE_WAITING_FOR_START; } } return TUTORSTATE_UNDEFINED; } const char *CCSTutorUndefinedState::GetStateString() { return nullptr; } CCSTutorWaitingForStartState::CCSTutorWaitingForStartState() { m_type = TUTORSTATE_WAITING_FOR_START; } CCSTutorWaitingForStartState::~CCSTutorWaitingForStartState() { ; } TutorStateType CCSTutorWaitingForStartState::CheckForStateTransition(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { switch (event) { case EVENT_PLAYER_SPAWNED: return HandlePlayerSpawned(entity, other); case EVENT_BUY_TIME_START: return HandleBuyTimeStart(entity, other); } return TUTORSTATE_UNDEFINED; } const char *CCSTutorWaitingForStartState::GetStateString() { #ifdef REGAMEDLL_FIXES if (m_type < TUTORSTATE_UNDEFINED || m_type > TUTORSTATE_WAITING_FOR_START) { return nullptr; } #endif return m_TutorStateStrings[m_type]; } TutorStateType CCSTutorWaitingForStartState::HandlePlayerSpawned(CBaseEntity *entity, CBaseEntity *other) { CBasePlayer *pLocalPlayer = UTIL_GetLocalPlayer(); if (pLocalPlayer) { CBasePlayer *pPlayer = static_cast(entity); if (pPlayer && pPlayer->IsPlayer() && pPlayer == pLocalPlayer) { return TUTORSTATE_WAITING_FOR_START; } } return TUTORSTATE_UNDEFINED; } TutorStateType CCSTutorWaitingForStartState::HandleBuyTimeStart(CBaseEntity *entity, CBaseEntity *other) { return TUTORSTATE_BUYTIME; } CCSTutorBuyMenuState::CCSTutorBuyMenuState() { m_type = TUTORSTATE_BUYTIME; } CCSTutorBuyMenuState::~CCSTutorBuyMenuState() { ; } TutorStateType CCSTutorBuyMenuState::CheckForStateTransition(GameEventType event, CBaseEntity *entity, CBaseEntity *other) { if (event == EVENT_ROUND_START) { return HandleRoundStart(entity, other); } return TUTORSTATE_UNDEFINED; } const char *CCSTutorBuyMenuState::GetStateString() { #ifdef REGAMEDLL_FIXES if (m_type < TUTORSTATE_UNDEFINED || m_type > TUTORSTATE_WAITING_FOR_START) { return nullptr; } #endif return m_TutorStateStrings[m_type]; } TutorStateType CCSTutorBuyMenuState::HandleRoundStart(CBaseEntity *entity, CBaseEntity *other) { return TUTORSTATE_WAITING_FOR_START; }