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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
//========= Copyright Valve Corporation, All rights reserved. ============//
// tf_bot_retreat.cpp
// Retreat towards our spawn to find another patient
// Michael Booth, May 2009
#include "cbase.h"
#include "tf_player.h"
#include "tf_gamerules.h"
#include "tf_weapon_medigun.h"
#include "bot/tf_bot.h"
#include "bot/behavior/medic/tf_bot_medic_retreat.h"
#include "nav_mesh.h"
extern ConVar tf_bot_path_lookahead_range;
extern ConVar tf_bot_medic_follow_range;
extern ConVar tf_bot_force_class;
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotMedicRetreat::OnStart( CTFBot *me, Action< CTFBot > *priorAction )
{
CTFNavArea *homeArea = me->GetSpawnArea();
if ( homeArea == NULL )
{
return Done( "No home area!" );
}
m_path.SetMinLookAheadDistance( tf_bot_path_lookahead_range.GetFloat() );
CTFBotPathCost cost( me, FASTEST_ROUTE );
m_path.Compute( me, homeArea->GetCenter(), cost );
return Continue();
}
//---------------------------------------------------------------------------------------------
class CUsefulHealTargetFilter : public INextBotEntityFilter
{
public:
CUsefulHealTargetFilter( int team )
{
m_team = team;
}
virtual bool IsAllowed( CBaseEntity *entity ) const
{
if ( entity && entity->IsPlayer() && entity->GetTeamNumber() == m_team )
{
return !ToTFPlayer( entity )->IsPlayerClass( TF_CLASS_MEDIC ) && !ToTFPlayer( entity )->IsPlayerClass( TF_CLASS_SNIPER );
}
return false;
}
int m_team;
};
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotMedicRetreat::Update( CTFBot *me, float interval )
{
// equip the syringegun and defend ourselves!
CTFWeaponBase *myWeapon = me->m_Shared.GetActiveTFWeapon();
if ( myWeapon )
{
if ( myWeapon->GetWeaponID() != TF_WEAPON_SYRINGEGUN_MEDIC )
{
CBaseCombatWeapon *syringeGun = me->Weapon_GetSlot( TF_WPN_TYPE_PRIMARY );
if ( syringeGun )
{
me->Weapon_Switch( syringeGun );
}
}
}
m_path.Update( me );
// look around to try to spot a friend to heal
if ( m_lookAroundTimer.IsElapsed() )
{
m_lookAroundTimer.Start( RandomFloat( 0.33f, 1.0f ) );
QAngle angle;
angle.x = 0.0f;
angle.y = RandomFloat( -180.0f, 180.0f );
angle.z = 0.0f;
Vector forward;
AngleVectors( angle, &forward );
me->GetBodyInterface()->AimHeadTowards( me->EyePosition() + forward, IBody::IMPORTANT, 0.1f, NULL, "Looking for someone to heal" );
}
// if we see a friend, heal them
CUsefulHealTargetFilter filter( me->GetTeamNumber() );
const CKnownEntity *known = me->GetVisionInterface()->GetClosestKnown( filter );
if ( known )
{
return Done( "I know of a teammate" );
}
return Continue();
}
//---------------------------------------------------------------------------------------------
ActionResult< CTFBot > CTFBotMedicRetreat::OnResume( CTFBot *me, Action< CTFBot > *interruptingAction )
{
CTFBotPathCost cost( me, FASTEST_ROUTE );
m_path.Compute( me, me->GetSpawnArea()->GetCenter(), cost );
return Continue();
}
//---------------------------------------------------------------------------------------------
EventDesiredResult< CTFBot > CTFBotMedicRetreat::OnStuck( CTFBot *me )
{
CTFBotPathCost cost( me, FASTEST_ROUTE );
m_path.Compute( me, me->GetSpawnArea()->GetCenter(), cost );
return TryContinue();
}
//---------------------------------------------------------------------------------------------
EventDesiredResult< CTFBot > CTFBotMedicRetreat::OnMoveToFailure( CTFBot *me, const Path *path, MoveToFailureType reason )
{
CTFBotPathCost cost( me, FASTEST_ROUTE );
m_path.Compute( me, me->GetSpawnArea()->GetCenter(), cost );
return TryContinue();
}
//---------------------------------------------------------------------------------------------
QueryResultType CTFBotMedicRetreat::ShouldAttack( const INextBot *me, const CKnownEntity *them ) const
{
// defend ourselves!
return ANSWER_YES;
}
|