diff options
Diffstat (limited to 'game/server/tf/bot/behavior/tf_bot_use_item.cpp')
| -rw-r--r-- | game/server/tf/bot/behavior/tf_bot_use_item.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/game/server/tf/bot/behavior/tf_bot_use_item.cpp b/game/server/tf/bot/behavior/tf_bot_use_item.cpp new file mode 100644 index 0000000..ee8e9ec --- /dev/null +++ b/game/server/tf/bot/behavior/tf_bot_use_item.cpp @@ -0,0 +1,73 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// tf_bot_use_item.h +// Equip and consume an item +// Michael Booth, July 2011 + +#include "cbase.h" +#include "tf_weaponbase.h" +#include "bot/tf_bot.h" +#include "bot/behavior/tf_bot_use_item.h" + + +//--------------------------------------------------------------------------------------------- +CTFBotUseItem::CTFBotUseItem( CTFWeaponBase *item ) +{ + m_item = item; +} + + +//--------------------------------------------------------------------------------------------- +ActionResult< CTFBot > CTFBotUseItem::OnStart( CTFBot *me, Action< CTFBot > *priorAction ) +{ + // force-equip the item we're going to use + me->PushRequiredWeapon( m_item ); + + m_cooldownTimer.Start( m_item->m_flNextPrimaryAttack - gpGlobals->curtime + 0.25f ); + + return Continue(); +} + + +//--------------------------------------------------------------------------------------------- +ActionResult< CTFBot > CTFBotUseItem::Update( CTFBot *me, float interval ) +{ + if ( m_item == NULL ) + { + return Done( "NULL item" ); + } + + CTFWeaponBase *myCurrentWeapon = me->m_Shared.GetActiveTFWeapon(); + + if ( !myCurrentWeapon ) + { + return Done( "NULL weapon" ); + } + + if ( m_cooldownTimer.HasStarted() ) + { + if ( m_cooldownTimer.IsElapsed() ) + { + // use it + me->PressFireButton(); + m_cooldownTimer.Invalidate(); + } + } + else // used + { + // some items use the taunt system - wait for the taunt to end + if ( !me->IsTaunting() ) + { + return Done( "Item used" ); + } + } + + return Continue(); +} + + +//--------------------------------------------------------------------------------------------- +void CTFBotUseItem::OnEnd( CTFBot *me, Action< CTFBot > *nextAction ) +{ + me->PopRequiredWeapon(); +} + |