Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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:
ICmpUnitMotion IComponent

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_FOLLOWING_REQUESTING_SHORT_APPEND, PATHSTATE_MAX
}
 

Public Member Functions

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)
 
virtual bool IsMoving ()
 Get whether the unit is moving. More...
 
virtual fixed GetWalkSpeed ()
 Get the default speed that this unit will have when walking, in metres per second. More...
 
virtual fixed GetRunSpeed ()
 Get the default speed that this unit will have when running, in metres per second. More...
 
virtual
ICmpPathfinder::pass_class_t 
GetPassabilityClass ()
 Get the unit's passability class. More...
 
virtual fixed GetCurrentSpeed ()
 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)
 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)
 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 void SetUnitRadius (fixed radius)
 Override the default obstruction radius, used for planning paths and checking for collisions. 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 JSClass * GetJSClass () const
 
virtual jsval GetJSInstance () const
 

Static Public Member Functions

static void ClassInit (CComponentManager &componentManager)
 
static IComponentAllocate (ScriptInterface &, jsval)
 
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_RunSpeed
 
ICmpPathfinder::pass_class_t m_PassClass
 
ICmpPathfinder::cost_class_t m_CostClass
 
entity_pos_t m_Radius
 
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
 
ICmpPathfinder::Path m_LongPath
 
ICmpPathfinder::Path m_ShortPath
 
ICmpPathfinder::Goal m_FinalGoal
 

Private Member Functions

bool ShouldAvoidMovingUnits ()
 
bool IsFormationMember ()
 
void StartFailed ()
 
void MoveFailed ()
 
void StartSucceeded ()
 
void MoveSucceeded ()
 
void PathResult (u32 ticket, const ICmpPathfinder::Path &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 hw, entity_pos_t hh, entity_pos_t circleRadius)
 Decide whether to approximate the given range from a square target as a circle, rather than as a square. More...
 
bool ComputeTargetPosition (CFixedVector2D &out)
 Computes the current location of our target entity (plus offset). More...
 
bool TryGoingStraightToTargetEntity (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 (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...
 
bool PathIsShort (const ICmpPathfinder::Path &path, CFixedVector2D from, entity_pos_t minDistance)
 Returns whether the length of the given path, plus the distance from 'from' to the first waypoints, it shorter than minDistance. More...
 
void FaceTowardsPointFromPos (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 forceAvoidMovingUnits=false)
 Returns an appropriate obstruction filter for use with path requests. More...
 
void BeginPathing (CFixedVector2D from, const ICmpPathfinder::Goal &goal)
 Start moving to the given goal, from our current position 'from'. More...
 
void RequestLongPath (CFixedVector2D from, const ICmpPathfinder::Goal &goal)
 Start an asynchronous long path query. More...
 
void RequestShortPath (CFixedVector2D from, const ICmpPathfinder::Goal &goal, bool avoidMovingUnits)
 Start an asynchronous short path query. More...
 
bool PickNextLongWaypoint (const CFixedVector2D &pos, bool avoidMovingUnits)
 Select a next long waypoint, given the current unit position. More...
 
void RenderPath (const ICmpPathfinder::Path &path, std::vector< SOverlayLine > &lines, CColor color)
 Convert a path into a renderable list of lines. More...
 
void RenderSubmit (SceneCollector &collector)
 

Detailed Description

Definition at line 103 of file CCmpUnitMotion.cpp.

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_FOLLOWING_REQUESTING_SHORT_APPEND 
PATHSTATE_MAX 

Definition at line 166 of file CCmpUnitMotion.cpp.

Enumerator
STATE_IDLE 
STATE_STOPPING 
STATE_FORMATIONMEMBER_PATH 
STATE_INDIVIDUAL_PATH 
STATE_MAX 

Definition at line 134 of file CCmpUnitMotion.cpp.

Member Function Documentation

static IComponent* CCmpUnitMotion::Allocate ( ScriptInterface ,
jsval   
)
inlinestatic

Definition at line 114 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::BeginPathing ( CFixedVector2D  from,
const ICmpPathfinder::Goal 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.

Definition at line 1161 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::CheckTargetMovement ( 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.

Definition at line 1062 of file CCmpUnitMotion.cpp.

static void CCmpUnitMotion::ClassInit ( CComponentManager componentManager)
inlinestatic

Definition at line 106 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::ComputeTargetPosition ( CFixedVector2D out)
private

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

Returns false if no target entity or no valid position.

Definition at line 1000 of file CCmpUnitMotion.cpp.

static void CCmpUnitMotion::Deallocate ( IComponent cmp)
inlinestatic

Definition at line 114 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::Deinit ( )
inlinevirtual

Implements IComponent.

Definition at line 323 of file CCmpUnitMotion.cpp.

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

Implements IComponent.

Definition at line 361 of file CCmpUnitMotion.cpp.

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

Turn to look towards the given point.

Implements ICmpUnitMotion.

Definition at line 1123 of file CCmpUnitMotion.cpp.

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

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

Definition at line 1133 of file CCmpUnitMotion.cpp.

virtual fixed CCmpUnitMotion::GetCurrentSpeed ( )
inlinevirtual

Get the current movement speed.

Implements ICmpUnitMotion.

Definition at line 425 of file CCmpUnitMotion.cpp.

ControlGroupMovementObstructionFilter CCmpUnitMotion::GetObstructionFilter ( bool  forceAvoidMovingUnits = false)
private

Returns an appropriate obstruction filter for use with path requests.

Definition at line 1148 of file CCmpUnitMotion.cpp.

virtual ICmpPathfinder::pass_class_t CCmpUnitMotion::GetPassabilityClass ( )
inlinevirtual

Get the unit's passability class.

Implements ICmpUnitMotion.

Definition at line 420 of file CCmpUnitMotion.cpp.

virtual fixed CCmpUnitMotion::GetRunSpeed ( )
inlinevirtual

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

Implements ICmpUnitMotion.

Definition at line 415 of file CCmpUnitMotion.cpp.

static std::string CCmpUnitMotion::GetSchema ( )
inlinestatic

Definition at line 242 of file CCmpUnitMotion.cpp.

virtual fixed CCmpUnitMotion::GetWalkSpeed ( )
inlinevirtual

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

Implements ICmpUnitMotion.

Definition at line 410 of file CCmpUnitMotion.cpp.

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

Reimplemented from IComponent.

Definition at line 368 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::Init ( const CParamNode paramNode)
inlinevirtual

Implements IComponent.

Definition at line 280 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::IsFormationMember ( )
inlineprivate

Definition at line 474 of file CCmpUnitMotion.cpp.

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

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

Implements ICmpUnitMotion.

Definition at line 1353 of file CCmpUnitMotion.cpp.

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

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

Implements ICmpUnitMotion.

Definition at line 1563 of file CCmpUnitMotion.cpp.

virtual bool CCmpUnitMotion::IsMoving ( )
inlinevirtual

Get whether the unit is moving.

Implements ICmpUnitMotion.

Definition at line 405 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::Move ( fixed  dt)
private

Do the per-turn movement and other updates.

Definition at line 765 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::MoveFailed ( )
inlineprivate

Definition at line 492 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::MoveSucceeded ( )
inlineprivate

Definition at line 510 of file CCmpUnitMotion.cpp.

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.

Definition at line 1629 of file CCmpUnitMotion.cpp.

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.

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.

Definition at line 1266 of file CCmpUnitMotion.cpp.

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.

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.

Definition at line 1417 of file CCmpUnitMotion.cpp.

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

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

Definition at line 1101 of file CCmpUnitMotion.cpp.

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

Handle the result of an asynchronous path query.

Definition at line 609 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::PickNextLongWaypoint ( const CFixedVector2D pos,
bool  avoidMovingUnits 
)
private

Select a next long waypoint, given the current unit position.

Also recomputes the short path to use that waypoint. Returns false on error, or if there is no waypoint to pick.

Definition at line 1215 of file CCmpUnitMotion.cpp.

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

Convert a path into a renderable list of lines.

Definition at line 1656 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::RenderSubmit ( SceneCollector collector)
private

Definition at line 1681 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::RequestLongPath ( CFixedVector2D  from,
const ICmpPathfinder::Goal goal 
)
private

Start an asynchronous long path query.

Definition at line 1195 of file CCmpUnitMotion.cpp.

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

Start an asynchronous short path query.

Definition at line 1206 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::Serialize ( ISerializer serialize)
inlinevirtual

Implements IComponent.

Definition at line 356 of file CCmpUnitMotion.cpp.

template<typename S >
void CCmpUnitMotion::SerializeCommon ( S &  serialize)
inline

Definition at line 328 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::SetDebugOverlay ( bool  enabled)
inlinevirtual

Toggle the rendering of debug info.

Implements ICmpUnitMotion.

Definition at line 440 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::SetFacePointAfterMove ( bool  facePointAfterMove)
inlinevirtual

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

Implements ICmpUnitMotion.

Definition at line 435 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::SetSpeed ( fixed  speed)
inlinevirtual

Set the current movement speed.

Implements ICmpUnitMotion.

Definition at line 430 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::SetUnitRadius ( fixed  radius)
inlinevirtual

Override the default obstruction radius, used for planning paths and checking for collisions.

Bad things may happen if this entity has an active Obstruction component with a larger radius. (This is intended primarily for formation controllers.)

Implements ICmpUnitMotion.

Definition at line 463 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::ShouldAvoidMovingUnits ( )
inlineprivate

Definition at line 469 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::ShouldTreatTargetAsCircle ( entity_pos_t  range,
entity_pos_t  hw,
entity_pos_t  hh,
entity_pos_t  circleRadius 
)
private

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

Definition at line 1402 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::StartFailed ( )
inlineprivate

Definition at line 479 of file CCmpUnitMotion.cpp.

void CCmpUnitMotion::StartSucceeded ( )
inlineprivate

Definition at line 504 of file CCmpUnitMotion.cpp.

virtual void CCmpUnitMotion::StopMoving ( )
inlinevirtual

Stop moving immediately.

Implements ICmpUnitMotion.

Definition at line 453 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::TryGoingStraightToTargetEntity ( 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.

Definition at line 1024 of file CCmpUnitMotion.cpp.

Member Data Documentation

ICmpPathfinder::cost_class_t CCmpUnitMotion::m_CostClass

Definition at line 126 of file CCmpUnitMotion.cpp.

fixed CCmpUnitMotion::m_CurSpeed

Definition at line 233 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::m_DebugOverlayEnabled

Definition at line 116 of file CCmpUnitMotion.cpp.

std::vector<SOverlayLine> CCmpUnitMotion::m_DebugOverlayLongPathLines

Definition at line 117 of file CCmpUnitMotion.cpp.

std::vector<SOverlayLine> CCmpUnitMotion::m_DebugOverlayShortPathLines

Definition at line 118 of file CCmpUnitMotion.cpp.

u32 CCmpUnitMotion::m_ExpectedPathTicket

Definition at line 222 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::m_FacePointAfterMove

Definition at line 132 of file CCmpUnitMotion.cpp.

ICmpPathfinder::Goal CCmpUnitMotion::m_FinalGoal

Definition at line 240 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::m_FormationController

Definition at line 122 of file CCmpUnitMotion.cpp.

ICmpPathfinder::Path CCmpUnitMotion::m_LongPath

Definition at line 237 of file CCmpUnitMotion.cpp.

bool CCmpUnitMotion::m_Moving

Definition at line 131 of file CCmpUnitMotion.cpp.

ICmpPathfinder::pass_class_t CCmpUnitMotion::m_PassClass

Definition at line 125 of file CCmpUnitMotion.cpp.

u8 CCmpUnitMotion::m_PathState

Definition at line 220 of file CCmpUnitMotion.cpp.

entity_pos_t CCmpUnitMotion::m_Radius

Definition at line 130 of file CCmpUnitMotion.cpp.

fixed CCmpUnitMotion::m_RunSpeed

Definition at line 124 of file CCmpUnitMotion.cpp.

ICmpPathfinder::Path CCmpUnitMotion::m_ShortPath

Definition at line 238 of file CCmpUnitMotion.cpp.

fixed CCmpUnitMotion::m_Speed

Definition at line 230 of file CCmpUnitMotion.cpp.

u8 CCmpUnitMotion::m_State

Definition at line 164 of file CCmpUnitMotion.cpp.

entity_id_t CCmpUnitMotion::m_TargetEntity

Definition at line 224 of file CCmpUnitMotion.cpp.

entity_pos_t CCmpUnitMotion::m_TargetMaxRange

Definition at line 228 of file CCmpUnitMotion.cpp.

entity_pos_t CCmpUnitMotion::m_TargetMinRange

Definition at line 227 of file CCmpUnitMotion.cpp.

CFixedVector2D CCmpUnitMotion::m_TargetOffset

Definition at line 226 of file CCmpUnitMotion.cpp.

CFixedVector2D CCmpUnitMotion::m_TargetPos

Definition at line 225 of file CCmpUnitMotion.cpp.

fixed CCmpUnitMotion::m_WalkSpeed

Definition at line 123 of file CCmpUnitMotion.cpp.


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