ReGameDLL_CS/regamedll/dlls/tutor_cs_states.cpp

213 lines
4.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
2015-09-16 23:19:21 +03:00
char *const g_TutorStateStrings[20] =
2015-08-20 13:35:01 +03:00
{
"#Cstrike_TutorState_Undefined",
"#Cstrike_TutorState_Looking_For_Hostage",
"#Cstrike_TutorState_Escorting_Hostage",
"#Cstrike_TutorState_Following_Hostage_Escort",
"#Cstrike_TutorState_Moving_To_Bombsite",
"#Cstrike_TutorState_Looking_For_Bomb_Carrier",
"#Cstrike_TutorState_Guarding_Loose_Bomb",
"#Cstrike_TutorState_Defusing_Bomb",
"#Cstrike_TutorState_Guarding_Hostage",
"#Cstrike_TutorState_Moving_To_Intercept_Enemy",
"#Cstrike_TutorState_Looking_For_Hostage_Escort",
"#Cstrike_TutorState_Attacking_Hostage_Escort",
"#Cstrike_TutorState_Escorting_Bomb_Carrier",
"#Cstrike_TutorState_Moving_To_Bomb_Site",
"#Cstrike_TutorState_Planting_Bomb",
"#Cstrike_TutorState_Guarding_Bomb",
"#Cstrike_TutorState_Looking_For_Loose_Bomb",
"#Cstrike_TutorState_Running_Away_From_Ticking_Bomb",
"#Cstrike_TutorState_Buy_Time",
"#Cstrike_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
}
2015-08-20 13:35:01 +03:00
bool CCSTutorStateSystem::__MAKE_VHOOK(UpdateState)(GameEventType event, CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
if (m_currentState == nullptr)
2015-08-20 13:35:01 +03:00
{
m_currentState = new CCSTutorUndefinedState;
}
if (m_currentState)
2015-08-20 13:35:01 +03:00
{
TutorStateType nextStateType = static_cast<TutorStateType>(m_currentState->CheckForStateTransition(event, entity, other));
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
}
char *CCSTutorStateSystem::__MAKE_VHOOK(GetCurrentStateString)()
2015-06-30 12:46:07 +03:00
{
if (m_currentState)
2015-08-20 13:35:01 +03:00
{
return m_currentState->GetStateString();
}
return NULL;
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
CBaseTutorState *CCSTutorStateSystem::__MAKE_VHOOK(ConstructNewState)(int stateType)
2015-06-30 12:46:07 +03:00
{
switch (stateType)
2015-08-20 13:35:01 +03:00
{
case TUTORSTATE_BUYTIME: return new CCSTutorBuyMenuState;
case TUTORSTATE_WAITING_FOR_START: return new CCSTutorWaitingForStartState;
case TUTORSTATE_UNDEFINED: return new CCSTutorUndefinedState;
2015-08-20 13:35:01 +03:00
}
return NULL;
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
m_type = 0;
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
}
2015-08-20 13:35:01 +03:00
int CCSTutorUndefinedState::__MAKE_VHOOK(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
}
return 0;
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
int CCSTutorUndefinedState::HandlePlayerSpawned(CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
CBasePlayer *localPlayer = UTIL_GetLocalPlayer();
if (localPlayer)
2015-08-20 13:35:01 +03:00
{
CBasePlayer *player = static_cast<CBasePlayer *>(entity);
if (player && player->IsPlayer() && player == localPlayer)
2015-08-20 13:35:01 +03:00
{
// flags
return TUTOR_STATE_FLAG_1;
}
}
return 0;
2015-06-30 12:46:07 +03:00
}
char *CCSTutorUndefinedState::__MAKE_VHOOK(GetStateString)()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
return NULL;
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
m_type = (TUTORMESSAGETYPE_ENEMY_DEATH | TUTORMESSAGETYPE_BUY);
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
}
2015-08-20 13:35:01 +03:00
int CCSTutorWaitingForStartState::__MAKE_VHOOK(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
}
return 0;
2015-06-30 12:46:07 +03:00
}
char *CCSTutorWaitingForStartState::__MAKE_VHOOK(GetStateString)()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
return g_TutorStateStrings[m_type];
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
int CCSTutorWaitingForStartState::HandlePlayerSpawned(CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
CBasePlayer *localPlayer = UTIL_GetLocalPlayer();
if (localPlayer)
2015-08-20 13:35:01 +03:00
{
CBasePlayer *player = static_cast<CBasePlayer *>(entity);
if (player && player->IsPlayer() && player == localPlayer)
2015-08-20 13:35:01 +03:00
{
// flags
return TUTOR_STATE_FLAG_1;
}
}
return 0;
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
int CCSTutorWaitingForStartState::HandleBuyTimeStart(CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
return TUTOR_STATE_FLAG_2;
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
m_type = (TUTORMESSAGETYPE_DEFAULT | TUTORMESSAGETYPE_FRIEND_DEATH | TUTORMESSAGETYPE_BUY);
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
}
2015-08-20 13:35:01 +03:00
int CCSTutorBuyMenuState::__MAKE_VHOOK(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);
}
return 0;
2015-06-30 12:46:07 +03:00
}
char *CCSTutorBuyMenuState::__MAKE_VHOOK(GetStateString)()
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
return g_TutorStateStrings[m_type];
2015-06-30 12:46:07 +03:00
}
2015-08-20 13:35:01 +03:00
int CCSTutorBuyMenuState::HandleRoundStart(CBaseEntity *entity, CBaseEntity *other)
2015-06-30 12:46:07 +03:00
{
2015-08-20 13:35:01 +03:00
return TUTOR_STATE_FLAG_1;
2015-06-30 12:46:07 +03:00
}