summaryrefslogtreecommitdiff
path: root/game/server/cstrike/bot/states/cs_bot_use_entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/server/cstrike/bot/states/cs_bot_use_entity.cpp')
-rw-r--r--game/server/cstrike/bot/states/cs_bot_use_entity.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/game/server/cstrike/bot/states/cs_bot_use_entity.cpp b/game/server/cstrike/bot/states/cs_bot_use_entity.cpp
new file mode 100644
index 0000000..591b364
--- /dev/null
+++ b/game/server/cstrike/bot/states/cs_bot_use_entity.cpp
@@ -0,0 +1,63 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+
+// Author: Michael S. Booth ([email protected]), 2003
+
+#include "cbase.h"
+#include "cs_bot.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+
+/**
+ * Face the entity and "use" it
+ * NOTE: This state assumes we are standing in range of the entity to be used, with no obstructions.
+ */
+void UseEntityState::OnEnter( CCSBot *me )
+{
+}
+
+void UseEntityState::OnUpdate( CCSBot *me )
+{
+ // in the very rare situation where two or more bots "used" a hostage at the same time,
+ // one bot will fail and needs to time out of this state
+ const float useTimeout = 5.0f;
+ if (me->GetStateTimestamp() - gpGlobals->curtime > useTimeout)
+ {
+ me->Idle();
+ return;
+ }
+
+ // look at the entity
+ Vector pos = m_entity->EyePosition();
+ me->SetLookAt( "Use entity", pos, PRIORITY_HIGH );
+
+ // if we are looking at the entity, "use" it and exit
+ if (me->IsLookingAtPosition( pos ))
+ {
+ if (TheCSBots()->GetScenario() == CCSBotManager::SCENARIO_RESCUE_HOSTAGES &&
+ me->GetTeamNumber() == TEAM_CT &&
+ me->GetTask() == CCSBot::COLLECT_HOSTAGES)
+ {
+ // we are collecting a hostage, assume we were successful - the update check will correct us if we weren't
+ me->IncreaseHostageEscortCount();
+ }
+
+ me->UseEnvironment();
+ me->Idle();
+ }
+}
+
+void UseEntityState::OnExit( CCSBot *me )
+{
+ me->ClearLookAt();
+ me->ResetStuckMonitor();
+}
+
+
+