summaryrefslogtreecommitdiff
path: root/game/server/tf/bot/behavior/tf_bot_melee_attack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'game/server/tf/bot/behavior/tf_bot_melee_attack.cpp')
-rw-r--r--game/server/tf/bot/behavior/tf_bot_melee_attack.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/game/server/tf/bot/behavior/tf_bot_melee_attack.cpp b/game/server/tf/bot/behavior/tf_bot_melee_attack.cpp
new file mode 100644
index 0000000..c914a8c
--- /dev/null
+++ b/game/server/tf/bot/behavior/tf_bot_melee_attack.cpp
@@ -0,0 +1,67 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+// tf_bot_melee_attack.h
+// Attack a threat with out melee weapon
+// Michael Booth, February 2009
+
+#include "cbase.h"
+#include "bot/tf_bot.h"
+#include "bot/behavior/tf_bot_melee_attack.h"
+
+#include "nav_mesh.h"
+
+extern ConVar tf_bot_path_lookahead_range;
+
+ConVar tf_bot_melee_attack_abandon_range( "tf_bot_melee_attack_abandon_range", "500", FCVAR_CHEAT, "If threat is farther away than this, bot will switch back to its primary weapon and attack" );
+
+
+//---------------------------------------------------------------------------------------------
+CTFBotMeleeAttack::CTFBotMeleeAttack( float giveUpRange )
+{
+ m_giveUpRange = giveUpRange < 0.0f ? tf_bot_melee_attack_abandon_range.GetFloat() : giveUpRange;
+}
+
+
+//---------------------------------------------------------------------------------------------
+ActionResult< CTFBot > CTFBotMeleeAttack::OnStart( CTFBot *me, Action< CTFBot > *priorAction )
+{
+ m_path.SetMinLookAheadDistance( me->GetDesiredPathLookAheadRange() );
+
+ return Continue();
+}
+
+
+//---------------------------------------------------------------------------------------------
+ActionResult< CTFBot > CTFBotMeleeAttack::Update( CTFBot *me, float interval )
+{
+ // bash the bad guys
+ const CKnownEntity *threat = me->GetVisionInterface()->GetPrimaryKnownThreat();
+
+ if ( threat == NULL )
+ {
+ return Done( "No threat" );
+ }
+
+ if ( me->IsDistanceBetweenGreaterThan( threat->GetLastKnownPosition(), m_giveUpRange ) )
+ {
+ // threat is too far away for melee
+ return Done( "Threat is too far away for a melee attack" );
+ }
+
+ // switch to our melee weapon
+ CBaseCombatWeapon *meleeWeapon = me->Weapon_GetSlot( TF_WPN_TYPE_MELEE );
+ if ( meleeWeapon )
+ {
+ me->Weapon_Switch( meleeWeapon );
+ }
+
+ // actual head aiming is handled elsewhere
+
+ // just keep swinging
+ me->PressFireButton();
+
+ // chase them down
+ CTFBotPathCost cost( me, FASTEST_ROUTE );
+ m_path.Update( me, threat->GetEntity(), cost );
+
+ return Continue();
+}