Pyrogenesis  trunk
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Private Member Functions | List of all members
CCmpUnitMotion Class Reference
Inheritance diagram for CCmpUnitMotion:
Inheritance graph
[legend]
Collaboration diagram for CCmpUnitMotion:
Collaboration graph
[legend]

Public Types

enum  State {
  STATE_IDLE, STATE_STOPPING, STATE_FORMATIONMEMBER_PATH, STATE_INDIVIDUAL_PATH,
  STATE_MAX
}
 
enum  PathState {
  PATHSTATE_NONE, PATHSTATE_WAITING_REQUESTING_LONG, PATHSTATE_WAITING_REQUESTING_SHORT, PATHSTATE_FOLLOWING,
  PATHSTATE_FOLLOWING_REQUESTING_LONG, PATHSTATE_FOLLOWING_REQUESTING_SHORT, PATHSTATE_MAX
}
 

Public Member Functions

virtual int GetComponentTypeId () const
 
virtual void Init (const CParamNode &paramNode)
 
virtual void Deinit ()
 
template<typename S >
void SerializeCommon (S &serialize)
 
virtual void Serialize (ISerializer &serialize)
 
virtual void Deserialize (const CParamNode &paramNode, IDeserializer &deserialize)
 
virtual void HandleMessage (const CMessage &msg, bool global)
 
void UpdateMessageSubscriptions ()
 
virtual bool IsMoving () const
 Get whether the unit is moving. More...
 
virtual fixed GetWalkSpeed () const
 Get the default speed that this unit will have when walking, in metres per second. More...
 
virtual fixed GetRunSpeed () const
 Get the default speed that this unit will have when running, in metres per second. More...
 
virtual pass_class_t GetPassabilityClass () const
 Get the unit's passability class. More...
 
virtual std::string GetPassabilityClassName () const
 Get the passability class name (as defined in pathfinder.xml) More...
 
virtual void SetPassabilityClassName (const std::string &passClassName)
 
virtual fixed GetCurrentSpeed () const
 Get the current movement speed. More...
 
virtual void SetSpeed (fixed speed)
 Set the current movement speed. More...
 
virtual void SetFacePointAfterMove (bool facePointAfterMove)
 Set whether the unit will turn to face the target point after finishing moving. More...
 
virtual void SetDebugOverlay (bool enabled)
 Toggle the rendering of debug info. More...
 
virtual bool MoveToPointRange (entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)
 Attempt to walk into range of a to a given point, or as close as possible. More...
 
virtual bool IsInPointRange (entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) const
 Determine wether the givven point is within the given range, using the same measurement as MoveToPointRange. More...
 
virtual bool MoveToTargetRange (entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
 Attempt to walk into range of a given target entity, or as close as possible. More...
 
virtual bool IsInTargetRange (entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) const
 Determine whether the target is within the given range, using the same measurement as MoveToTargetRange. More...
 
virtual void MoveToFormationOffset (entity_id_t target, entity_pos_t x, entity_pos_t z)
 Join a formation, and move towards a given offset relative to the formation controller entity. More...
 
virtual void FaceTowardsPoint (entity_pos_t x, entity_pos_t z)
 Turn to look towards the given point. More...
 
virtual void StopMoving ()
 Stop moving immediately. More...
 
virtual entity_pos_t GetUnitClearance () const
 Get the unit clearance (used by the Obstruction component) More...
 
- Public Member Functions inherited from IComponent
virtual ~IComponent ()
 
CEntityHandle GetEntityHandle () const
 
void SetEntityHandle (CEntityHandle ent)
 
entity_id_t GetEntityId () const
 
CEntityHandle GetSystemEntity () const
 
const CSimContextGetSimContext () const
 
void SetSimContext (const CSimContext &context)
 
virtual bool NewJSObject (ScriptInterface &scriptInterface, JS::MutableHandleObject out) const
 Returns false by default, indicating that a scripted wrapper of this IComponent is not supported. More...
 
virtual JS::Value GetJSInstance () const
 

Static Public Member Functions

static void ClassInit (CComponentManager &componentManager)
 
static IComponentAllocate (ScriptInterface &, JS::HandleValue)
 
static void Deallocate (IComponent *cmp)
 
static std::string GetSchema ()
 
- Static Public Member Functions inherited from IComponent
static std::string GetSchema ()
 
static u8 GetSerializationVersion ()
 

Public Attributes

bool m_DebugOverlayEnabled
 
std::vector< SOverlayLinem_DebugOverlayLongPathLines
 
std::vector< SOverlayLinem_DebugOverlayShortPathLines
 
bool m_FormationController
 
fixed m_WalkSpeed
 
fixed m_OriginalWalkSpeed
 
fixed m_RunSpeed
 
fixed m_OriginalRunSpeed
 
pass_class_t m_PassClass
 
std::string m_PassClassName
 
entity_pos_t m_Clearance
 
bool m_Moving
 
bool m_FacePointAfterMove
 
u8 m_State
 
u8 m_PathState
 
u32 m_ExpectedPathTicket
 
entity_id_t m_TargetEntity
 
CFixedVector2D m_TargetPos
 
CFixedVector2D m_TargetOffset
 
entity_pos_t m_TargetMinRange
 
entity_pos_t m_TargetMaxRange
 
fixed m_Speed
 
fixed m_CurSpeed
 
WaypointPath m_LongPath
 
WaypointPath m_ShortPath
 
u8 m_Tries
 
PathGoal m_FinalGoal
 

Private Member Functions

bool ShouldAvoidMovingUnits () const
 
bool IsFormationMember () const
 
entity_id_t GetGroup () const
 
bool HasValidPath () const
 
void StartFailed ()
 
void MoveFailed ()
 
void StartSucceeded ()
 
void MoveSucceeded ()
 
bool MoveToPointRange (entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange, entity_id_t target)
 
void PathResult (u32 ticket, const WaypointPath &path)
 Handle the result of an asynchronous path query. More...
 
void Move (fixed dt)
 Do the per-turn movement and other updates. More...
 
bool ShouldTreatTargetAsCircle (entity_pos_t range, entity_pos_t circleRadius) const
 Decide whether to approximate the given range from a square target as a circle, rather than as a square. More...
 
bool ComputeTargetPosition (CFixedVector2D &out) const
 Computes the current location of our target entity (plus offset). More...
 
bool TryGoingStraightToGoalPoint (const CFixedVector2D &from)
 Attempts to replace the current path with a straight line to the goal, if this goal is a point, is close enough and the route is not obstructed. More...
 
bool TryGoingStraightToTargetEntity (const CFixedVector2D &from)
 Attempts to replace the current path with a straight line to the target entity, if it's close enough and the route is not obstructed. More...
 
bool CheckTargetMovement (const CFixedVector2D &from, entity_pos_t minDelta)
 Returns whether the target entity has moved more than minDelta since our last path computations, and we're close enough to it to care. More...
 
void UpdateFinalGoal ()
 Update goal position if moving target. More...
 
bool ShouldConsiderOurselvesAtDestination (const CFixedVector2D &from)
 Returns whether we are close enough to the target to assume it's a good enough position to stop. More...
 
bool PathIsShort (const WaypointPath &path, const CFixedVector2D &from, entity_pos_t minDistance) const
 Returns whether the length of the given path, plus the distance from 'from' to the first waypoints, it shorter than minDistance. More...
 
void FaceTowardsPointFromPos (const CFixedVector2D &pos, entity_pos_t x, entity_pos_t z)
 Rotate to face towards the target point, given the current pos. More...
 
ControlGroupMovementObstructionFilter GetObstructionFilter (bool noTarget=false) const
 Returns an appropriate obstruction filter for use with path requests. More...
 
void BeginPathing (const CFixedVector2D &from, const PathGoal &goal)
 Start moving to the given goal, from our current position 'from'. More...
 
void RequestLongPath (const CFixedVector2D &from, const PathGoal &goal)
 Start an asynchronous long path query. More...
 
void RequestShortPath (const CFixedVector2D &from, const PathGoal &goal, bool avoidMovingUnits)
 Start an asynchronous short path query. More...
 
void RenderPath (const WaypointPath &path, std::vector< SOverlayLine > &lines, CColor color)
 Convert a path into a renderable list of lines. More...
 
void RenderSubmit (SceneCollector &collector)
 

Member Enumeration Documentation

Enumerator
PATHSTATE_NONE 
PATHSTATE_WAITING_REQUESTING_LONG 
PATHSTATE_WAITING_REQUESTING_SHORT 
PATHSTATE_FOLLOWING 
PATHSTATE_FOLLOWING_REQUESTING_LONG 
PATHSTATE_FOLLOWING_REQUESTING_SHORT 
PATHSTATE_MAX 
Enumerator
STATE_IDLE 
STATE_STOPPING 
STATE_FORMATIONMEMBER_PATH 
STATE_INDIVIDUAL_PATH 
STATE_MAX 

Member Function Documentation

static IComponent* CCmpUnitMotion::Allocate ( ScriptInterface ,
JS::HandleValue   
)
inlinestatic
void CCmpUnitMotion::BeginPathing ( const CFixedVector2D from,
const PathGoal goal 
)
private

Start moving to the given goal, from our current position 'from'.

Might go in a straight line immediately, or might start an asynchronous path request.

bool CCmpUnitMotion::CheckTargetMovement ( const CFixedVector2D from,
entity_pos_t  minDelta 
)
private

Returns whether the target entity has moved more than minDelta since our last path computations, and we're close enough to it to care.

static void CCmpUnitMotion::ClassInit ( CComponentManager componentManager)
inlinestatic
bool CCmpUnitMotion::ComputeTargetPosition ( CFixedVector2D out) const
private

Computes the current location of our target entity (plus offset).

Returns false if no target entity or no valid position.

static void CCmpUnitMotion::Deallocate ( IComponent cmp)
inlinestatic
virtual void CCmpUnitMotion::Deinit ( )
inlinevirtual

Implements IComponent.

virtual void CCmpUnitMotion::Deserialize ( const CParamNode paramNode,
IDeserializer deserialize 
)
inlinevirtual

Implements IComponent.

void CCmpUnitMotion::FaceTowardsPoint ( entity_pos_t  x,
entity_pos_t  z 
)
virtual

Turn to look towards the given point.

Implements ICmpUnitMotion.

void CCmpUnitMotion::FaceTowardsPointFromPos ( const CFixedVector2D pos,
entity_pos_t  x,
entity_pos_t  z 
)
private

Rotate to face towards the target point, given the current pos.

virtual int CCmpUnitMotion::GetComponentTypeId ( ) const
inlinevirtual

Implements IComponent.

virtual fixed CCmpUnitMotion::GetCurrentSpeed ( ) const
inlinevirtual

Get the current movement speed.

Implements ICmpUnitMotion.

entity_id_t CCmpUnitMotion::GetGroup ( ) const
inlineprivate
ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter ( bool  noTarget = false) const
private

Returns an appropriate obstruction filter for use with path requests.

noTarget is true only when used inside tryGoingStraightToTargetEntity, in which case we do not want the target obstruction otherwise it would always fail

virtual pass_class_t CCmpUnitMotion::GetPassabilityClass ( ) const
inlinevirtual

Get the unit's passability class.

Implements ICmpUnitMotion.

virtual std::string CCmpUnitMotion::GetPassabilityClassName ( ) const
inlinevirtual

Get the passability class name (as defined in pathfinder.xml)

Implements ICmpUnitMotion.

virtual fixed CCmpUnitMotion::GetRunSpeed ( ) const
inlinevirtual

Get the default speed that this unit will have when running, in metres per second.

Implements ICmpUnitMotion.

static std::string CCmpUnitMotion::GetSchema ( )
inlinestatic
virtual entity_pos_t CCmpUnitMotion::GetUnitClearance ( ) const
inlinevirtual

Get the unit clearance (used by the Obstruction component)

Implements ICmpUnitMotion.

virtual fixed CCmpUnitMotion::GetWalkSpeed ( ) const
inlinevirtual

Get the default speed that this unit will have when walking, in metres per second.

Implements ICmpUnitMotion.

virtual void CCmpUnitMotion::HandleMessage ( const CMessage msg,
bool  global 
)
inlinevirtual

Reimplemented from IComponent.

bool CCmpUnitMotion::HasValidPath ( ) const
inlineprivate
virtual void CCmpUnitMotion::Init ( const CParamNode paramNode)
inlinevirtual

Implements IComponent.

bool CCmpUnitMotion::IsFormationMember ( ) const
inlineprivate
bool CCmpUnitMotion::IsInPointRange ( entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  minRange,
entity_pos_t  maxRange 
) const
virtual

Determine wether the givven point is within the given range, using the same measurement as MoveToPointRange.

Implements ICmpUnitMotion.

bool CCmpUnitMotion::IsInTargetRange ( entity_id_t  target,
entity_pos_t  minRange,
entity_pos_t  maxRange 
) const
virtual

Determine whether the target is within the given range, using the same measurement as MoveToTargetRange.

Implements ICmpUnitMotion.

virtual bool CCmpUnitMotion::IsMoving ( ) const
inlinevirtual

Get whether the unit is moving.

Implements ICmpUnitMotion.

void CCmpUnitMotion::Move ( fixed  dt)
private

Do the per-turn movement and other updates.

void CCmpUnitMotion::MoveFailed ( )
inlineprivate
void CCmpUnitMotion::MoveSucceeded ( )
inlineprivate
void CCmpUnitMotion::MoveToFormationOffset ( entity_id_t  target,
entity_pos_t  x,
entity_pos_t  z 
)
virtual

Join a formation, and move towards a given offset relative to the formation controller entity.

Continues following the formation until given a different command.

Implements ICmpUnitMotion.

bool CCmpUnitMotion::MoveToPointRange ( entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  minRange,
entity_pos_t  maxRange 
)
virtual

Attempt to walk into range of a to a given point, or as close as possible.

The range is measured from the center of the unit. If the unit is already in range, or cannot move anywhere at all, or if there is some other error, then returns false. Otherwise, returns true and sends a MotionChanged message after starting to move, and sends another MotionChanged after finishing moving. If maxRange is negative, then the maximum range is treated as infinity.

Implements ICmpUnitMotion.

bool CCmpUnitMotion::MoveToPointRange ( entity_pos_t  x,
entity_pos_t  z,
entity_pos_t  minRange,
entity_pos_t  maxRange,
entity_id_t  target 
)
private
bool CCmpUnitMotion::MoveToTargetRange ( entity_id_t  target,
entity_pos_t  minRange,
entity_pos_t  maxRange 
)
virtual

Attempt to walk into range of a given target entity, or as close as possible.

The range is measured between approximately the edges of the unit and the target, so that maxRange=0 is not unreachably close to the target. If the unit is already in range, or cannot move anywhere at all, or if there is some other error, then returns false. Otherwise, returns true and sends a MotionChanged message after starting to move, and sends another MotionChanged after finishing moving. If maxRange is negative, then the maximum range is treated as infinity.

Implements ICmpUnitMotion.

bool CCmpUnitMotion::PathIsShort ( const WaypointPath path,
const CFixedVector2D from,
entity_pos_t  minDistance 
) const
private

Returns whether the length of the given path, plus the distance from 'from' to the first waypoints, it shorter than minDistance.

void CCmpUnitMotion::PathResult ( u32  ticket,
const WaypointPath path 
)
private

Handle the result of an asynchronous path query.

void CCmpUnitMotion::RenderPath ( const WaypointPath path,
std::vector< SOverlayLine > &  lines,
CColor  color 
)
private

Convert a path into a renderable list of lines.

void CCmpUnitMotion::RenderSubmit ( SceneCollector collector)
private
void CCmpUnitMotion::RequestLongPath ( const CFixedVector2D from,
const PathGoal goal 
)
private

Start an asynchronous long path query.

void CCmpUnitMotion::RequestShortPath ( const CFixedVector2D from,
const PathGoal goal,
bool  avoidMovingUnits 
)
private

Start an asynchronous short path query.

virtual void CCmpUnitMotion::Serialize ( ISerializer serialize)
inlinevirtual

Implements IComponent.

template<typename S >
void CCmpUnitMotion::SerializeCommon ( S &  serialize)
inline
virtual void CCmpUnitMotion::SetDebugOverlay ( bool  enabled)
inlinevirtual

Toggle the rendering of debug info.

Implements ICmpUnitMotion.

virtual void CCmpUnitMotion::SetFacePointAfterMove ( bool  facePointAfterMove)
inlinevirtual

Set whether the unit will turn to face the target point after finishing moving.

Implements ICmpUnitMotion.

virtual void CCmpUnitMotion::SetPassabilityClassName ( const std::string &  passClassName)
inlinevirtual
virtual void CCmpUnitMotion::SetSpeed ( fixed  speed)
inlinevirtual

Set the current movement speed.

Implements ICmpUnitMotion.

bool CCmpUnitMotion::ShouldAvoidMovingUnits ( ) const
inlineprivate
bool CCmpUnitMotion::ShouldConsiderOurselvesAtDestination ( const CFixedVector2D from)
private

Returns whether we are close enough to the target to assume it's a good enough position to stop.

bool CCmpUnitMotion::ShouldTreatTargetAsCircle ( entity_pos_t  range,
entity_pos_t  circleRadius 
) const
private

Decide whether to approximate the given range from a square target as a circle, rather than as a square.

void CCmpUnitMotion::StartFailed ( )
inlineprivate
void CCmpUnitMotion::StartSucceeded ( )
inlineprivate
virtual void CCmpUnitMotion::StopMoving ( )
inlinevirtual

Stop moving immediately.

Implements ICmpUnitMotion.

bool CCmpUnitMotion::TryGoingStraightToGoalPoint ( const CFixedVector2D from)
private

Attempts to replace the current path with a straight line to the goal, if this goal is a point, is close enough and the route is not obstructed.

bool CCmpUnitMotion::TryGoingStraightToTargetEntity ( const CFixedVector2D from)
private

Attempts to replace the current path with a straight line to the target entity, if it's close enough and the route is not obstructed.

void CCmpUnitMotion::UpdateFinalGoal ( )
private

Update goal position if moving target.

void CCmpUnitMotion::UpdateMessageSubscriptions ( )
inline

Member Data Documentation

entity_pos_t CCmpUnitMotion::m_Clearance
fixed CCmpUnitMotion::m_CurSpeed
bool CCmpUnitMotion::m_DebugOverlayEnabled
std::vector<SOverlayLine> CCmpUnitMotion::m_DebugOverlayLongPathLines
std::vector<SOverlayLine> CCmpUnitMotion::m_DebugOverlayShortPathLines
u32 CCmpUnitMotion::m_ExpectedPathTicket
bool CCmpUnitMotion::m_FacePointAfterMove
PathGoal CCmpUnitMotion::m_FinalGoal
bool CCmpUnitMotion::m_FormationController
WaypointPath CCmpUnitMotion::m_LongPath
bool CCmpUnitMotion::m_Moving
fixed CCmpUnitMotion::m_OriginalRunSpeed
fixed CCmpUnitMotion::m_OriginalWalkSpeed
pass_class_t CCmpUnitMotion::m_PassClass
std::string CCmpUnitMotion::m_PassClassName
u8 CCmpUnitMotion::m_PathState
fixed CCmpUnitMotion::m_RunSpeed
WaypointPath CCmpUnitMotion::m_ShortPath
fixed CCmpUnitMotion::m_Speed
u8 CCmpUnitMotion::m_State
entity_id_t CCmpUnitMotion::m_TargetEntity
entity_pos_t CCmpUnitMotion::m_TargetMaxRange
entity_pos_t CCmpUnitMotion::m_TargetMinRange
CFixedVector2D CCmpUnitMotion::m_TargetOffset
CFixedVector2D CCmpUnitMotion::m_TargetPos
u8 CCmpUnitMotion::m_Tries
fixed CCmpUnitMotion::m_WalkSpeed

The documentation for this class was generated from the following file: