Skip to content

Commit cb60077

Browse files
authored
Code push
1 parent a0a8045 commit cb60077

46 files changed

Lines changed: 19038 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Behavior/BehaviorBackUp.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// BehaviorBackUp.h
2+
// Back up for a short duration
3+
// Author: Michael Booth, March 2007
4+
//========= Copyright Valve Corporation, All rights reserved. ============//
5+
6+
#ifndef _BEHAVIOR_BACK_UP_H_
7+
#define _BEHAVIOR_BACK_UP_H_
8+
9+
10+
//----------------------------------------------------------------------------------------------
11+
/**
12+
* Move backwards for a short duration away from a given position.
13+
* Useful to dislodge ourselves if we get stuck while following our path.
14+
*/
15+
template < typename Actor >
16+
class BehaviorBackUp : public Action< Actor >
17+
{
18+
public:
19+
BehaviorBackUp( const Vector &avoidPos );
20+
21+
virtual ActionResult< Actor > OnStart( Actor *me, Action< Actor > *priorAction );
22+
virtual ActionResult< Actor > Update( Actor *me, float interval );
23+
24+
virtual EventDesiredResult< Actor > OnStuck( Actor *me );
25+
26+
virtual const char *GetName( void ) const { return "BehaviorBackUp"; }
27+
28+
private:
29+
CountdownTimer m_giveUpTimer;
30+
CountdownTimer m_backupTimer;
31+
CountdownTimer m_jumpTimer;
32+
Vector m_way;
33+
Vector m_avoidPos;
34+
};
35+
36+
37+
//----------------------------------------------------------------------------------------------
38+
template < typename Actor >
39+
inline BehaviorBackUp< Actor >::BehaviorBackUp( const Vector &avoidPos )
40+
{
41+
m_avoidPos = avoidPos;
42+
}
43+
44+
45+
//----------------------------------------------------------------------------------------------
46+
template < typename Actor >
47+
inline ActionResult< Actor > BehaviorBackUp< Actor >::OnStart( Actor *me, Action< Actor > *priorAction )
48+
{
49+
ILocomotion *mover = me->GetLocomotionInterface();
50+
51+
// don't back off if we're on a ladder
52+
if ( mover && mover->IsUsingLadder() )
53+
{
54+
return Done();
55+
}
56+
57+
float backupTime = RandomFloat( 0.3f, 0.5f );
58+
59+
m_backupTimer.Start( backupTime );
60+
m_jumpTimer.Start( 1.5f * backupTime );
61+
m_giveUpTimer.Start( 2.5f * backupTime );
62+
63+
m_way = me->GetPosition() - m_avoidPos;
64+
m_way.NormalizeInPlace();
65+
66+
return Continue();
67+
}
68+
69+
70+
//----------------------------------------------------------------------------------------------
71+
template < typename Actor >
72+
inline ActionResult< Actor > BehaviorBackUp< Actor >::Update( Actor *me, float interval )
73+
{
74+
if ( m_giveUpTimer.IsElapsed() )
75+
{
76+
return Done();
77+
}
78+
79+
// if ( m_jumpTimer.HasStarted() && m_jumpTimer.IsElapsed() )
80+
// {
81+
// me->GetLocomotionInterface()->Jump();
82+
// m_jumpTimer.Invalidate();
83+
// }
84+
85+
ILocomotion *mover = me->GetLocomotionInterface();
86+
if ( mover )
87+
{
88+
Vector goal;
89+
90+
if ( m_backupTimer.IsElapsed() )
91+
{
92+
// move towards bad spot
93+
goal = m_avoidPos; // me->GetPosition() - 100.0f * m_way;
94+
}
95+
else
96+
{
97+
// move away from bad spot
98+
goal = me->GetPosition() + 100.0f * m_way;
99+
}
100+
101+
mover->Approach( goal );
102+
}
103+
104+
return Continue();
105+
}
106+
107+
108+
//----------------------------------------------------------------------------------------------
109+
template < typename Actor >
110+
inline EventDesiredResult< Actor > BehaviorBackUp< Actor >::OnStuck( Actor *me )
111+
{
112+
return TryToSustain( RESULT_IMPORTANT, "Stuck while trying to back up" );
113+
}
114+
115+
116+
117+
#endif // _BEHAVIOR_BACK_UP_H_
118+

Behavior/BehaviorMoveTo.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// BehaviorMoveTo.h
2+
// Move to a potentially far away position
3+
// Author: Michael Booth, June 2007
4+
//========= Copyright Valve Corporation, All rights reserved. ============//
5+
6+
#ifndef _BEHAVIOR_MOVE_TO_H_
7+
#define _BEHAVIOR_MOVE_TO_H_
8+
9+
10+
//----------------------------------------------------------------------------------------------
11+
/**
12+
* Move to a potentially far away position, using path planning.
13+
*/
14+
template < typename Actor, typename PathCost >
15+
class BehaviorMoveTo : public Action< Actor >
16+
{
17+
public:
18+
BehaviorMoveTo( const Vector &goal, Action< Actor > *successAction = NULL, Action< Actor > *failAction = NULL );
19+
20+
virtual ActionResult< Actor > OnStart( Actor *me, Action< Actor > *priorAction );
21+
virtual ActionResult< Actor > Update( Actor *me, float interval );
22+
23+
virtual EventDesiredResult< Actor > OnMoveToSuccess( Actor *me, const Path *path );
24+
virtual EventDesiredResult< Actor > OnMoveToFailure( Actor *me, const Path *path, MoveToFailureType reason );
25+
26+
virtual bool ComputePath( Actor *me, const Vector &goal, PathFollower *path );
27+
28+
virtual const char *GetName( void ) const { return "BehaviorMoveTo"; }
29+
30+
private:
31+
Vector m_goal;
32+
PathFollower m_path;
33+
Action< Actor > *m_successAction;
34+
Action< Actor > *m_failAction;
35+
};
36+
37+
38+
//----------------------------------------------------------------------------------------------
39+
template < typename Actor, typename PathCost >
40+
inline BehaviorMoveTo< Actor, PathCost >::BehaviorMoveTo( const Vector &goal, Action< Actor > *successAction, Action< Actor > *failAction )
41+
{
42+
m_goal = goal;
43+
m_path.Invalidate();
44+
m_successAction = successAction;
45+
m_failAction = failAction;
46+
}
47+
48+
49+
//----------------------------------------------------------------------------------------------
50+
template < typename Actor, typename PathCost >
51+
inline bool BehaviorMoveTo< Actor, PathCost >::ComputePath( Actor *me, const Vector &goal, PathFollower *path )
52+
{
53+
PathCost cost( me );
54+
return path->Compute( me, goal, cost );
55+
}
56+
57+
58+
//----------------------------------------------------------------------------------------------
59+
template < typename Actor, typename PathCost >
60+
inline ActionResult< Actor > BehaviorMoveTo< Actor, PathCost >::OnStart( Actor *me, Action< Actor > *priorAction )
61+
{
62+
if ( !this->ComputePath( me, m_goal, &m_path ) )
63+
{
64+
if ( m_failAction )
65+
{
66+
return this->ChangeTo( m_failAction, "No path to goal" );
67+
}
68+
69+
return this->Done( "No path to goal" );
70+
}
71+
72+
return this->Continue();
73+
}
74+
75+
76+
//----------------------------------------------------------------------------------------------
77+
template < typename Actor, typename PathCost >
78+
inline ActionResult< Actor > BehaviorMoveTo< Actor, PathCost >::Update( Actor *me, float interval )
79+
{
80+
// if path became invalid during last tick for any reason, we're done
81+
if ( !m_path.IsValid() )
82+
{
83+
if ( m_failAction )
84+
{
85+
return this->ChangeTo( m_failAction, "Path is invalid" );
86+
}
87+
88+
return this->Done( "Path is invalid" );
89+
}
90+
91+
// move along path - success/fail event handlers will exit behavior when goal is reached
92+
m_path.Update( me );
93+
94+
return this->Continue();
95+
}
96+
97+
98+
//----------------------------------------------------------------------------------------------
99+
template < typename Actor, typename PathCost >
100+
inline EventDesiredResult< Actor > BehaviorMoveTo< Actor, PathCost >::OnMoveToSuccess( Actor *me, const Path *path )
101+
{
102+
if ( m_successAction )
103+
{
104+
return this->TryChangeTo( m_successAction, RESULT_CRITICAL, "OnMoveToSuccess" );
105+
}
106+
107+
return this->TryDone( RESULT_CRITICAL, "OnMoveToSuccess" );
108+
}
109+
110+
111+
//----------------------------------------------------------------------------------------------
112+
template < typename Actor, typename PathCost >
113+
inline EventDesiredResult< Actor > BehaviorMoveTo< Actor, PathCost >::OnMoveToFailure( Actor *me, const Path *path, MoveToFailureType reason )
114+
{
115+
if ( m_failAction )
116+
{
117+
return this->TryChangeTo( m_failAction, RESULT_CRITICAL, "OnMoveToFailure" );
118+
}
119+
120+
return this->TryDone( RESULT_CRITICAL, "OnMoveToFailure" );
121+
}
122+
123+
124+
125+
#endif // _BEHAVIOR_MOVE_TO_H_
126+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//========= Copyright Valve Corporation, All rights reserved. ============//
2+
// NextBot paths that go through this entity must fulfill the given prerequisites to pass
3+
// Michael Booth, August 2009
4+
5+
#include "cbase.h"
6+
#include "func_nav_prerequisite.h"
7+
#include "ndebugoverlay.h"
8+
#include "modelentities.h"
9+
10+
// memdbgon must be the last include file in a .cpp file!!!
11+
#include "tier0/memdbgon.h"
12+
13+
14+
LINK_ENTITY_TO_CLASS( func_nav_prerequisite, CFuncNavPrerequisite );
15+
16+
BEGIN_DATADESC( CFuncNavPrerequisite )
17+
DEFINE_KEYFIELD( m_task, FIELD_INTEGER, "Task" ),
18+
DEFINE_KEYFIELD( m_taskEntityName, FIELD_STRING, "Entity" ),
19+
DEFINE_KEYFIELD( m_taskValue, FIELD_FLOAT, "Value" ),
20+
DEFINE_KEYFIELD( m_isDisabled, FIELD_BOOLEAN, "StartDisabled" ),
21+
DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
22+
DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
23+
END_DATADESC()
24+
25+
IMPLEMENT_AUTO_LIST( IFuncNavPrerequisiteAutoList );
26+
27+
28+
//-----------------------------------------------------------------------------
29+
CFuncNavPrerequisite::CFuncNavPrerequisite()
30+
{
31+
m_task = TASK_NONE;
32+
m_hTaskEntity = NULL;
33+
}
34+
35+
36+
//-----------------------------------------------------------------------------
37+
void CFuncNavPrerequisite::Spawn( void )
38+
{
39+
AddSpawnFlags( SF_TRIGGER_ALLOW_CLIENTS );
40+
41+
BaseClass::Spawn();
42+
InitTrigger();
43+
}
44+
45+
46+
//-----------------------------------------------------------------------------
47+
bool CFuncNavPrerequisite::IsTask( TaskType task ) const
48+
{
49+
return task == m_task ? true : false;
50+
}
51+
52+
53+
//-----------------------------------------------------------------------------
54+
CBaseEntity *CFuncNavPrerequisite::GetTaskEntity( void )
55+
{
56+
if ( m_hTaskEntity == NULL )
57+
{
58+
m_hTaskEntity = gEntList.FindEntityByName( NULL, m_taskEntityName );
59+
}
60+
return m_hTaskEntity;
61+
}
62+
63+
64+
//--------------------------------------------------------------------------------------------------------
65+
void CFuncNavPrerequisite::InputEnable( inputdata_t &inputdata )
66+
{
67+
m_isDisabled = false;
68+
}
69+
70+
71+
//--------------------------------------------------------------------------------------------------------
72+
void CFuncNavPrerequisite::InputDisable( inputdata_t &inputdata )
73+
{
74+
m_isDisabled = true;
75+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//========= Copyright Valve Corporation, All rights reserved. ============//
2+
// NextBot paths that go through this entity must fulfill the given prerequisites to pass
3+
// Michael Booth, August 2009
4+
5+
#ifndef FUNC_NAV_PREREQUISITE_H
6+
#define FUNC_NAV_PREREQUISITE_H
7+
8+
#include "triggers.h"
9+
10+
/**
11+
* NextBot paths that pass through this entity must fulfill the given prerequisites to pass
12+
*/
13+
DECLARE_AUTO_LIST( IFuncNavPrerequisiteAutoList );
14+
15+
class CFuncNavPrerequisite : public CBaseTrigger, public IFuncNavPrerequisiteAutoList
16+
{
17+
DECLARE_CLASS( CFuncNavPrerequisite, CBaseTrigger );
18+
19+
public:
20+
CFuncNavPrerequisite();
21+
22+
DECLARE_DATADESC();
23+
24+
virtual void Spawn( void );
25+
26+
enum TaskType
27+
{
28+
TASK_NONE = 0,
29+
TASK_DESTROY_ENTITY = 1,
30+
TASK_MOVE_TO_ENTITY = 2,
31+
TASK_WAIT = 3,
32+
};
33+
34+
bool IsTask( TaskType type ) const;
35+
CBaseEntity *GetTaskEntity( void );
36+
float GetTaskValue( void ) const;
37+
38+
void InputEnable( inputdata_t &inputdata );
39+
void InputDisable( inputdata_t &inputdata );
40+
bool IsEnabled( void ) const { return !m_isDisabled; }
41+
42+
protected:
43+
int m_task;
44+
string_t m_taskEntityName;
45+
float m_taskValue;
46+
bool m_isDisabled;
47+
EHANDLE m_hTaskEntity;
48+
};
49+
50+
inline float CFuncNavPrerequisite::GetTaskValue( void ) const
51+
{
52+
return m_taskValue;
53+
}
54+
55+
56+
#endif // FUNC_NAV_PREREQUISITE_H

0 commit comments

Comments
 (0)