ReGameDLL_CS/regamedll/dlls/tutor_cs_states.cpp

191 lines
4.2 KiB
C++
Raw Normal View History

2015-06-30 12:46:07 +03:00
#include "precompiled.h"
CCSTutorStateSystem::CCSTutorStateSystem()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
m_currentState = new CCSTutorUndefinedState;
2015-06-30 12:46:07 +03:00
}
CCSTutorStateSystem::~CCSTutorStateSystem()
2015-06-30 12:46:07 +03:00
{
if (m_currentState)
2015-08-20 13:35:01 +03:00
{
delete m_currentState;
m_currentState = nullptr;
2015-08-20 13:35:01 +03:00
}
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
bool CCSTutorStateSystem::UpdateState(GameEventType event, CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
if (!m_currentState)
2015-08-20 13:35:01 +03:00
{
m_currentState = new CCSTutorUndefinedState;
}
if (m_currentState)
2015-08-20 13:35:01 +03:00
{
2017-11-22 20:27:55 +03:00
TutorStateType nextStateType = m_currentState->CheckForStateTransition(event, pEntity, pOther);
2015-08-20 13:35:01 +03:00
if (nextStateType != TUTORSTATE_UNDEFINED)
{
delete m_currentState;
2015-08-20 13:35:01 +03:00
m_currentState = ConstructNewState(nextStateType);
return true;
}
}
return false;
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
const char *CCSTutorStateSystem::GetCurrentStateString()
2015-06-30 12:46:07 +03:00
{
if (m_currentState)
2015-08-20 13:35:01 +03:00
{
return m_currentState->GetStateString();
}
2017-10-12 17:50:56 +03:00
return nullptr;
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
CBaseTutorState *CCSTutorStateSystem::ConstructNewState(TutorStateType stateType)
2015-06-30 12:46:07 +03:00
{
switch (stateType)
2015-08-20 13:35:01 +03:00
{
2017-10-12 17:50:56 +03:00
case TUTORSTATE_BUYTIME: return new CCSTutorBuyMenuState;
case TUTORSTATE_WAITING_FOR_START: return new CCSTutorWaitingForStartState;
2017-10-12 17:50:56 +03:00
case TUTORSTATE_UNDEFINED: return new CCSTutorUndefinedState;
2015-08-20 13:35:01 +03:00
}
2017-10-12 17:50:56 +03:00
return nullptr;
2015-06-30 12:46:07 +03:00
}
CCSTutorUndefinedState::CCSTutorUndefinedState()
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
m_type = TUTORSTATE_UNDEFINED;
2015-06-30 12:46:07 +03:00
}
CCSTutorUndefinedState::~CCSTutorUndefinedState()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
;
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorUndefinedState::CheckForStateTransition(GameEventType event, CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (event == EVENT_PLAYER_SPAWNED)
{
2017-11-22 20:27:55 +03:00
return HandlePlayerSpawned(pEntity, pOther);
2015-08-20 13:35:01 +03:00
}
2017-10-12 17:50:56 +03:00
return TUTORSTATE_UNDEFINED;
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorUndefinedState::HandlePlayerSpawned(CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
CBasePlayer *pLocalPlayer = UTIL_GetLocalPlayer();
if (pLocalPlayer)
2015-08-20 13:35:01 +03:00
{
2017-11-22 20:27:55 +03:00
CBasePlayer *pPlayer = static_cast<CBasePlayer *>(pEntity);
2017-10-12 17:50:56 +03:00
if (pPlayer && pPlayer->IsPlayer() && pPlayer == pLocalPlayer)
2015-08-20 13:35:01 +03:00
{
2017-10-12 17:50:56 +03:00
return TUTORSTATE_WAITING_FOR_START;
2015-08-20 13:35:01 +03:00
}
}
2017-10-12 17:50:56 +03:00
return TUTORSTATE_UNDEFINED;
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
const char *CCSTutorUndefinedState::GetStateString()
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
return nullptr;
2015-06-30 12:46:07 +03:00
}
CCSTutorWaitingForStartState::CCSTutorWaitingForStartState()
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
m_type = TUTORSTATE_WAITING_FOR_START;
2015-06-30 12:46:07 +03:00
}
CCSTutorWaitingForStartState::~CCSTutorWaitingForStartState()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
;
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorWaitingForStartState::CheckForStateTransition(GameEventType event, CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
switch (event)
{
case EVENT_PLAYER_SPAWNED:
2017-11-22 20:27:55 +03:00
return HandlePlayerSpawned(pEntity, pOther);
2015-08-20 13:35:01 +03:00
case EVENT_BUY_TIME_START:
2017-11-22 20:27:55 +03:00
return HandleBuyTimeStart(pEntity, pOther);
2015-08-20 13:35:01 +03:00
}
2017-10-12 17:50:56 +03:00
return TUTORSTATE_UNDEFINED;
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
const char *CCSTutorWaitingForStartState::GetStateString()
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
#ifdef REGAMEDLL_FIXES
if (m_type < TUTORSTATE_UNDEFINED || m_type > TUTORSTATE_WAITING_FOR_START)
{
return nullptr;
}
#endif
return m_TutorStateStrings[m_type];
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorWaitingForStartState::HandlePlayerSpawned(CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
CBasePlayer *pLocalPlayer = UTIL_GetLocalPlayer();
if (pLocalPlayer)
2015-08-20 13:35:01 +03:00
{
2017-11-22 20:27:55 +03:00
CBasePlayer *pPlayer = static_cast<CBasePlayer *>(pEntity);
2017-10-12 17:50:56 +03:00
if (pPlayer && pPlayer->IsPlayer() && pPlayer == pLocalPlayer)
2015-08-20 13:35:01 +03:00
{
2017-10-12 17:50:56 +03:00
return TUTORSTATE_WAITING_FOR_START;
2015-08-20 13:35:01 +03:00
}
}
2017-10-12 17:50:56 +03:00
return TUTORSTATE_UNDEFINED;
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorWaitingForStartState::HandleBuyTimeStart(CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
return TUTORSTATE_BUYTIME;
2015-06-30 12:46:07 +03:00
}
CCSTutorBuyMenuState::CCSTutorBuyMenuState()
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
m_type = TUTORSTATE_BUYTIME;
2015-06-30 12:46:07 +03:00
}
CCSTutorBuyMenuState::~CCSTutorBuyMenuState()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
;
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorBuyMenuState::CheckForStateTransition(GameEventType event, CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (event == EVENT_ROUND_START)
{
2017-11-22 20:27:55 +03:00
return HandleRoundStart(pEntity, pOther);
2015-08-20 13:35:01 +03:00
}
2017-10-12 17:50:56 +03:00
return TUTORSTATE_UNDEFINED;
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
const char *CCSTutorBuyMenuState::GetStateString()
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
#ifdef REGAMEDLL_FIXES
if (m_type < TUTORSTATE_UNDEFINED || m_type > TUTORSTATE_WAITING_FOR_START)
{
return nullptr;
}
#endif
return m_TutorStateStrings[m_type];
2015-06-30 12:46:07 +03:00
}
2017-11-22 20:27:55 +03:00
TutorStateType CCSTutorBuyMenuState::HandleRoundStart(CBaseEntity *pEntity, CBaseEntity *pOther)
2015-06-30 12:46:07 +03:00
{
2017-10-12 17:50:56 +03:00
return TUTORSTATE_WAITING_FOR_START;
2015-06-30 12:46:07 +03:00
}