ReGameDLL_CS/regamedll/dlls/tutor_cs_states.cpp

222 lines
5.9 KiB
C++
Raw Normal View History

2015-06-30 12:46:07 +03:00
#include "precompiled.h"
2015-08-20 13:35:01 +03:00
/*
* Globals initialization
*/
#ifndef HOOK_GAMEDLL
2017-10-12 17:50:56 +03:00
const char *g_TutorStateStrings[] =
{
"#Cstrike_TutorState_Undefined", // TUTORSTATE_UNDEFINED
"#Cstrike_TutorState_Looking_For_Hostage", // TUTORSTATE_LOOKING_FOR_HOSTAGE
"#Cstrike_TutorState_Escorting_Hostage", // TUTORSTATE_ESCORTING_HOSTAGE
"#Cstrike_TutorState_Following_Hostage_Escort", // TUTORSTATE_FOLLOWING_HOSTAGE_ESCORT
"#Cstrike_TutorState_Moving_To_Bombsite", // TUTORSTATE_MOVING_TO_BOMBSITE,
"#Cstrike_TutorState_Looking_For_Bomb_Carrier", // TUTORSTATE_LOOKING_FOR_BOMB_CARRIER
"#Cstrike_TutorState_Guarding_Loose_Bomb", // TUTORSTATE_GUARDING_LOOSE_BOMB
"#Cstrike_TutorState_Defusing_Bomb", // TUTORSTATE_DEFUSING_BOMB
"#Cstrike_TutorState_Guarding_Hostage", // TUTORSTATE_GUARDING_HOSTAGE
"#Cstrike_TutorState_Moving_To_Intercept_Enemy", // TUTORSTATE_MOVING_TO_INTERCEPT_ENEMY
"#Cstrike_TutorState_Looking_For_Hostage_Escort", // TUTORSTATE_LOOKING_FOR_HOSTAGE_ESCORT
"#Cstrike_TutorState_Attacking_Hostage_Escort", // TUTORSTATE_ATTACKING_HOSTAGE_ESCORT
"#Cstrike_TutorState_Escorting_Bomb_Carrier", // TUTORSTATE_ESCORTING_BOMB_CARRIER
"#Cstrike_TutorState_Moving_To_Bomb_Site", // TUTORSTATE_MOVING_TO_BOMB_SITE
"#Cstrike_TutorState_Planting_Bomb", // TUTORSTATE_PLANTING_BOMB
"#Cstrike_TutorState_Guarding_Bomb", // TUTORSTATE_GUARDING_BOMB
"#Cstrike_TutorState_Looking_For_Loose_Bomb", // TUTORSTATE_LOOKING_FOR_LOOSE_BOMB
"#Cstrike_TutorState_Running_Away_From_Ticking_Bomb", // TUTORSTATE_RUNNING_AWAY_FROM_TICKING_BOMB
"#Cstrike_TutorState_Buy_Time", // TUTORSTATE_BUYTIME
"#Cstrike_TutorState_Waiting_For_Start" // TUTORSTATE_WAITING_FOR_START
2015-06-30 12:46:07 +03:00
};
2015-08-20 13:35:01 +03:00
#endif
2015-06-30 12:46:07 +03:00
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
}
bool CCSTutorStateSystem::UpdateState(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
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-10-12 17:50:56 +03:00
TutorStateType nextStateType = m_currentState->CheckForStateTransition(event, entity, other);
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-10-12 17:50:56 +03:00
TutorStateType CCSTutorUndefinedState::CheckForStateTransition(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (event == EVENT_PLAYER_SPAWNED)
{
return HandlePlayerSpawned(entity, other);
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
TutorStateType CCSTutorUndefinedState::HandlePlayerSpawned(CBaseEntity *entity, CBaseEntity *other)
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-10-12 17:50:56 +03:00
CBasePlayer *pPlayer = static_cast<CBasePlayer *>(entity);
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-10-12 17:50:56 +03:00
TutorStateType CCSTutorWaitingForStartState::CheckForStateTransition(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
switch (event)
{
case EVENT_PLAYER_SPAWNED:
return HandlePlayerSpawned(entity, other);
2015-08-20 13:35:01 +03:00
case EVENT_BUY_TIME_START:
return HandleBuyTimeStart(entity, other);
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
2015-08-20 13:35:01 +03:00
return g_TutorStateStrings[m_type];
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
TutorStateType CCSTutorWaitingForStartState::HandlePlayerSpawned(CBaseEntity *entity, CBaseEntity *other)
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-10-12 17:50:56 +03:00
CBasePlayer *pPlayer = static_cast<CBasePlayer *>(entity);
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
TutorStateType CCSTutorWaitingForStartState::HandleBuyTimeStart(CBaseEntity *entity, CBaseEntity *other)
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-10-12 17:50:56 +03:00
TutorStateType CCSTutorBuyMenuState::CheckForStateTransition(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
if (event == EVENT_ROUND_START)
{
return HandleRoundStart(entity, other);
}
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
2015-08-20 13:35:01 +03:00
return g_TutorStateStrings[m_type];
2015-06-30 12:46:07 +03:00
}
2017-10-12 17:50:56 +03:00
TutorStateType CCSTutorBuyMenuState::HandleRoundStart(CBaseEntity *entity, CBaseEntity *other)
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
}