summaryrefslogtreecommitdiff
path: root/game/server/tf/bot/behavior/training
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/server/tf/bot/behavior/training
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/server/tf/bot/behavior/training')
-rw-r--r--game/server/tf/bot/behavior/training/tf_bot_training.cpp133
-rw-r--r--game/server/tf/bot/behavior/training/tf_bot_training.h54
2 files changed, 187 insertions, 0 deletions
diff --git a/game/server/tf/bot/behavior/training/tf_bot_training.cpp b/game/server/tf/bot/behavior/training/tf_bot_training.cpp
new file mode 100644
index 0000000..7db948b
--- /dev/null
+++ b/game/server/tf/bot/behavior/training/tf_bot_training.cpp
@@ -0,0 +1,133 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// tf_bot_training.cpp
+//
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "cbase.h"
+#include "team.h"
+#include "bot/tf_bot.h"
+#include "bot/map_entities/tf_bot_generator.h"
+#include "bot/behavior/training/tf_bot_training.h"
+#include "tf_obj_sentrygun.h"
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ActionResult< CTFBot > CTFDespawn::Update( CTFBot *me, float interval )
+{
+ // players need to be kicked, not deleted
+ if ( me->GetEntity()->IsPlayer() )
+ {
+ CBasePlayer *player = dynamic_cast< CBasePlayer * >( me->GetEntity() );
+ engine->ServerCommand( UTIL_VarArgs( "kickid %d\n", player->GetUserID() ) );
+ }
+ else
+ {
+ UTIL_Remove( me->GetEntity() );
+ }
+ return Continue();
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ActionResult< CTFBot > CTFTrainingAttackSentryActionPoint::Update( CTFBot *me, float interval )
+{
+ CTFBotActionPoint* pActionPoint = me->GetActionPoint();
+ if ( pActionPoint == NULL )
+ {
+ return Done();
+ }
+
+ if ( pActionPoint->IsWithinRange( me ) )
+ {
+ CObjectSentrygun *pSentrygun = me->GetEnemySentry();
+ if ( pSentrygun )
+ {
+ me->GetBodyInterface()->AimHeadTowards( pSentrygun, IBody::MANDATORY, 1.0f, NULL, "Aiming at enemy sentry" );
+
+ // because sentries are stationary, check if XY is on target to allow SelectTargetPoint() to adjust Z for grenades
+ Vector toSentry = pSentrygun->WorldSpaceCenter() - me->EyePosition();
+ toSentry.NormalizeInPlace();
+ Vector forward;
+ me->EyeVectors( &forward );
+
+ if ( ( forward.x * toSentry.x + forward.y * toSentry.y ) > 0.95f )
+ {
+ me->PressFireButton();
+ }
+ }
+ }
+ else
+ {
+ if ( m_repathTimer.IsElapsed() )
+ {
+ m_repathTimer.Start( RandomFloat( 1.0f, 2.0f ) );
+
+ CTFBotPathCost cost( me, FASTEST_ROUTE );
+ m_path.Compute( me, pActionPoint->GetAbsOrigin(), cost );
+ }
+
+ m_path.Update( me );
+ }
+
+ return Continue();
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ActionResult< CTFBot > CTFGotoActionPoint::OnStart( CTFBot *me, Action< CTFBot > *priorAction )
+{
+ m_stayTimer.Invalidate();
+ m_wasTeleported = false;
+
+ return Continue();
+}
+
+ActionResult< CTFBot > CTFGotoActionPoint::Update( CTFBot *me, float interval )
+{
+ CTFBotActionPoint* pActionPoint = me->GetActionPoint();
+ if ( pActionPoint == NULL )
+ {
+ return Done();
+ }
+
+ if ( pActionPoint->IsWithinRange( me ) )
+ {
+ // track if we ever get teleported during this process
+ m_wasTeleported |= me->m_Shared.InCond( TF_COND_SELECTED_TO_TELEPORT );
+
+ // we're at the action point
+ if ( m_stayTimer.HasStarted() == false )
+ {
+ // this method may cause us to become suspended for other actions
+ pActionPoint->ReachedActionPoint( me );
+
+ m_stayTimer.Start( pActionPoint->m_stayTime );
+ }
+ else if ( m_stayTimer.IsElapsed() )
+ {
+ me->SetActionPoint( dynamic_cast< CTFBotActionPoint * >( pActionPoint->m_moveGoal.Get() ) );
+ return ChangeTo( new CTFGotoActionPoint, "Reached point, going to next" );
+ }
+ }
+ else if ( m_wasTeleported )
+ {
+ // we reached our action point, but were teleported far away.
+ // presumably we've resumed, so just go to the next action point.
+ me->SetActionPoint( dynamic_cast< CTFBotActionPoint * >( pActionPoint->m_moveGoal.Get() ) );
+ return ChangeTo( new CTFGotoActionPoint, "Reached point, going to next" );
+ }
+ else
+ {
+ if ( m_repathTimer.IsElapsed() )
+ {
+ m_repathTimer.Start( RandomFloat( 1.0f, 2.0f ) );
+
+ CTFBotPathCost cost( me, FASTEST_ROUTE );
+ m_path.Compute( me, pActionPoint->GetAbsOrigin(), cost );
+ }
+
+ m_path.Update( me );
+ }
+ return Continue();
+}
diff --git a/game/server/tf/bot/behavior/training/tf_bot_training.h b/game/server/tf/bot/behavior/training/tf_bot_training.h
new file mode 100644
index 0000000..d8d6cde
--- /dev/null
+++ b/game/server/tf/bot/behavior/training/tf_bot_training.h
@@ -0,0 +1,54 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// tf_bot_training.h
+//
+// Misc. training actions/behaviors. To be split up into separate files when we deem them "re-usable"
+//
+// Tom Bui, April 2010
+////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#ifndef TF_BOT_TRAINING_H
+#define TF_BOT_TRAINING_H
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Attempts to kick/despawn the bot in the Update()
+
+class CTFDespawn : public Action< CTFBot >
+{
+public:
+ virtual ActionResult< CTFBot > Update( CTFBot *me, float interval );
+ virtual const char *GetName( void ) const { return "Despawn"; };
+};
+
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Simple behavior for training where the bot approaches action point and tries to fire at it (and anything there)
+
+class CTFTrainingAttackSentryActionPoint : public Action< CTFBot >
+{
+public:
+ virtual ActionResult< CTFBot > Update( CTFBot *me, float interval );
+ virtual const char *GetName( void ) const { return "Despawn"; };
+
+private:
+ CountdownTimer m_repathTimer;
+ PathFollower m_path;
+};
+
+////////////////////////////////////////////////////////////////////////////////////////////////////
+// Tells a bot to go an Action Point and run any command it has
+class CTFGotoActionPoint : public Action< CTFBot >
+{
+public:
+ virtual ActionResult< CTFBot > OnStart( CTFBot *me, Action< CTFBot > *priorAction );
+ virtual ActionResult< CTFBot > Update( CTFBot *me, float interval );
+ virtual const char *GetName( void ) const { return "GotoActionPoint"; };
+
+private:
+ CountdownTimer m_stayTimer;
+ CountdownTimer m_repathTimer;
+ PathFollower m_path;
+ bool m_wasTeleported;
+};
+
+#endif // TF_BOT_TRAINING_H