-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathNextBotIntentionInterface.cpp
More file actions
91 lines (73 loc) · 2.74 KB
/
NextBotIntentionInterface.cpp
File metadata and controls
91 lines (73 loc) · 2.74 KB
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
// NextBotIntentionInterface.cpp
// Interface for intentional thinking
// Author: Michael Booth, November 2007
//========= Copyright Valve Corporation, All rights reserved. ============//
#include "cbase.h"
#include "NextBotInterface.h"
#include "NextBotIntentionInterface.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//------------------------------------------------------------------------------------------------------------------------
/**
* Given a subject, return the world space position we should aim at
*/
Vector IIntention::SelectTargetPoint( const INextBot *me, const CBaseCombatCharacter *subject ) const
{
for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
{
const IContextualQuery *query = dynamic_cast< const IContextualQuery * >( sub );
if ( query )
{
// return the response of the first responder that gives a definitive answer
Vector result = query->SelectTargetPoint( me, subject );
if ( result != vec3_origin )
{
return result;
}
}
}
// no answer, use a reasonable position
Vector threatMins, threatMaxs;
subject->CollisionProp()->WorldSpaceAABB( &threatMins, &threatMaxs );
Vector targetPoint = subject->GetAbsOrigin();
targetPoint.z += 0.7f * ( threatMaxs.z - threatMins.z );
return targetPoint;
}
//------------------------------------------------------------------------------------------------------------------------
/**
* Given two threats, decide which one is more dangerous
*/
const CKnownEntity *IIntention::SelectMoreDangerousThreat( const INextBot *me, const CBaseCombatCharacter *subject, const CKnownEntity *threat1, const CKnownEntity *threat2 ) const
{
if ( !threat1 || threat1->IsObsolete() )
{
if ( threat2 && !threat2->IsObsolete() )
return threat2;
return NULL;
}
else if ( !threat2 || threat2->IsObsolete() )
{
return threat1;
}
for ( INextBotEventResponder *sub = FirstContainedResponder(); sub; sub = NextContainedResponder( sub ) )
{
const IContextualQuery *query = dynamic_cast< const IContextualQuery * >( sub );
if ( query )
{
// return the response of the first responder that gives a definitive answer
const CKnownEntity *result = query->SelectMoreDangerousThreat( me, subject, threat1, threat2 );
if ( result )
{
return result;
}
}
}
// no specific decision was made - return closest threat as most dangerous
float range1 = ( subject->GetAbsOrigin() - threat1->GetLastKnownPosition() ).LengthSqr();
float range2 = ( subject->GetAbsOrigin() - threat2->GetLastKnownPosition() ).LengthSqr();
if ( range1 < range2 )
{
return threat1;
}
return threat2;
}