summaryrefslogtreecommitdiff
path: root/game/server/tf/bot/behavior/tf_bot_use_item.cpp
blob: ee8e9ec271c9d4e2ed6b990df6e3edc1c6e48f69 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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();
}