initial
This commit is contained in:
118
game/server/NextBot/Behavior/BehaviorBackUp.h
Normal file
118
game/server/NextBot/Behavior/BehaviorBackUp.h
Normal file
@@ -0,0 +1,118 @@
|
||||
// BehaviorBackUp.h
|
||||
// Back up for a short duration
|
||||
// Author: Michael Booth, March 2007
|
||||
// Copyright (c) 2007 Turtle Rock Studios, Inc. - All Rights Reserved
|
||||
|
||||
#ifndef _BEHAVIOR_BACK_UP_H_
|
||||
#define _BEHAVIOR_BACK_UP_H_
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* Move backwards for a short duration away from a given position.
|
||||
* Useful to dislodge ourselves if we get stuck while following our path.
|
||||
*/
|
||||
template < typename Actor >
|
||||
class BehaviorBackUp : public Action< Actor >
|
||||
{
|
||||
public:
|
||||
BehaviorBackUp( const Vector &avoidPos );
|
||||
|
||||
virtual ActionResult< Actor > OnStart( Actor *me, Action< Actor > *priorAction );
|
||||
virtual ActionResult< Actor > Update( Actor *me, float interval );
|
||||
|
||||
virtual EventDesiredResult< Actor > OnStuck( Actor *me );
|
||||
|
||||
virtual const char *GetName( void ) const { return "BehaviorBackUp"; }
|
||||
|
||||
private:
|
||||
CountdownTimer m_giveUpTimer;
|
||||
CountdownTimer m_backupTimer;
|
||||
CountdownTimer m_jumpTimer;
|
||||
Vector m_way;
|
||||
Vector m_avoidPos;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor >
|
||||
inline BehaviorBackUp< Actor >::BehaviorBackUp( const Vector &avoidPos )
|
||||
{
|
||||
m_avoidPos = avoidPos;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor >
|
||||
inline ActionResult< Actor > BehaviorBackUp< Actor >::OnStart( Actor *me, Action< Actor > *priorAction )
|
||||
{
|
||||
ILocomotion *mover = me->GetLocomotionInterface();
|
||||
|
||||
// don't back off if we're on a ladder
|
||||
if ( mover && mover->IsUsingLadder() )
|
||||
{
|
||||
return Done();
|
||||
}
|
||||
|
||||
float backupTime = RandomFloat( 0.3f, 0.5f );
|
||||
|
||||
m_backupTimer.Start( backupTime );
|
||||
m_jumpTimer.Start( 1.5f * backupTime );
|
||||
m_giveUpTimer.Start( 2.5f * backupTime );
|
||||
|
||||
m_way = me->GetPosition() - m_avoidPos;
|
||||
m_way.NormalizeInPlace();
|
||||
|
||||
return Continue();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor >
|
||||
inline ActionResult< Actor > BehaviorBackUp< Actor >::Update( Actor *me, float interval )
|
||||
{
|
||||
if ( m_giveUpTimer.IsElapsed() )
|
||||
{
|
||||
return Done();
|
||||
}
|
||||
|
||||
// if ( m_jumpTimer.HasStarted() && m_jumpTimer.IsElapsed() )
|
||||
// {
|
||||
// me->GetLocomotionInterface()->Jump();
|
||||
// m_jumpTimer.Invalidate();
|
||||
// }
|
||||
|
||||
ILocomotion *mover = me->GetLocomotionInterface();
|
||||
if ( mover )
|
||||
{
|
||||
Vector goal;
|
||||
|
||||
if ( m_backupTimer.IsElapsed() )
|
||||
{
|
||||
// move towards bad spot
|
||||
goal = m_avoidPos; // me->GetPosition() - 100.0f * m_way;
|
||||
}
|
||||
else
|
||||
{
|
||||
// move away from bad spot
|
||||
goal = me->GetPosition() + 100.0f * m_way;
|
||||
}
|
||||
|
||||
mover->Approach( goal );
|
||||
}
|
||||
|
||||
return Continue();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor >
|
||||
inline EventDesiredResult< Actor > BehaviorBackUp< Actor >::OnStuck( Actor *me )
|
||||
{
|
||||
return TryToSustain( RESULT_IMPORTANT, "Stuck while trying to back up" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // _BEHAVIOR_BACK_UP_H_
|
||||
|
||||
82
game/server/NextBot/Behavior/BehaviorMoveTo.h
Normal file
82
game/server/NextBot/Behavior/BehaviorMoveTo.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// BehaviorMoveTo.h
|
||||
// Move to a potentially far away position
|
||||
// Author: Michael Booth, June 2007
|
||||
// Copyright (c) 2007 Turtle Rock Studios, Inc. - All Rights Reserved
|
||||
|
||||
#ifndef _BEHAVIOR_MOVE_TO_H_
|
||||
#define _BEHAVIOR_MOVE_TO_H_
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
/**
|
||||
* Move to a potentially far away position, using path planning.
|
||||
*/
|
||||
template < typename Actor, typename PathCost >
|
||||
class BehaviorMoveTo : public Action< Actor >
|
||||
{
|
||||
public:
|
||||
BehaviorMoveTo( const Vector &goal );
|
||||
|
||||
virtual ActionResult< Actor > OnStart( Actor *me, Action< Actor > *priorAction );
|
||||
virtual ActionResult< Actor > Update( Actor *me, float interval );
|
||||
|
||||
// derive to supply specific cost functor - default uses simple shortest path
|
||||
virtual bool ComputePath( Actor *me, const Vector &goal, PathFollower *path );
|
||||
|
||||
virtual const char *GetName( void ) const { return "BehaviorMoveTo"; }
|
||||
|
||||
private:
|
||||
Vector m_goal;
|
||||
PathFollower m_path;
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor, typename PathCost >
|
||||
inline BehaviorMoveTo< Actor, PathCost >::BehaviorMoveTo( const Vector &goal )
|
||||
{
|
||||
m_goal = goal;
|
||||
m_path.Invalidate();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor, typename PathCost >
|
||||
inline bool BehaviorMoveTo< Actor, PathCost >::ComputePath( Actor *me, const Vector &goal, PathFollower *path )
|
||||
{
|
||||
PathCost cost( me );
|
||||
return path->Compute( me, goal, cost );
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor, typename PathCost >
|
||||
inline ActionResult< Actor > BehaviorMoveTo< Actor, PathCost >::OnStart( Actor *me, Action< Actor > *priorAction )
|
||||
{
|
||||
if ( !ComputePath( me, m_goal, &m_path ) )
|
||||
{
|
||||
return Done( "No path to goal" );
|
||||
}
|
||||
|
||||
return Continue();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
template < typename Actor, typename PathCost >
|
||||
inline ActionResult< Actor > BehaviorMoveTo< Actor, PathCost >::Update( Actor *me, float interval )
|
||||
{
|
||||
// move along path
|
||||
m_path.Update( me );
|
||||
|
||||
if ( m_path.IsValid() )
|
||||
{
|
||||
return Continue();
|
||||
}
|
||||
|
||||
return Done();
|
||||
}
|
||||
|
||||
|
||||
#endif // _BEHAVIOR_MOVE_TO_H_
|
||||
|
||||
Reference in New Issue
Block a user