Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
|
#include <CCmpUnitMotion.h>
Classes | |
struct | MoveRequest |
struct | Ticket |
Public Member Functions | |
int | GetComponentTypeId () const override |
void | Init (const CParamNode ¶mNode) override |
void | Deinit () override |
template<typename S > | |
void | SerializeCommon (S &serialize) |
void | Serialize (ISerializer &serialize) override |
void | Deserialize (const CParamNode ¶mNode, IDeserializer &deserialize) override |
void | HandleMessage (const CMessage &msg, bool global) override |
void | UpdateMessageSubscriptions () |
bool | IsMoveRequested () const override |
fixed | GetSpeedMultiplier () const override |
Returns the ratio of GetSpeed() / GetWalkSpeed(). More... | |
void | SetSpeedMultiplier (fixed multiplier) override |
Set the current movement speed. More... | |
fixed | GetSpeed () const override |
Get the speed at which the unit intends to move. More... | |
fixed | GetWalkSpeed () const override |
Get the unit template walk speed after modifications. More... | |
fixed | GetRunMultiplier () const override |
Get the unit template running (i.e. More... | |
CFixedVector2D | EstimateFuturePosition (const fixed dt) const override |
fixed | GetAcceleration () const override |
Get the current acceleration. More... | |
void | SetAcceleration (fixed acceleration) override |
Set the current acceleration. More... | |
virtual entity_pos_t | GetWeight () const |
pass_class_t | GetPassabilityClass () const override |
Get the unit's passability class. More... | |
std::string | GetPassabilityClassName () const override |
Get the passability class name (as defined in pathfinder.xml) More... | |
void | SetPassabilityClassName (const std::string &passClassName) override |
Sets the passability class name (as defined in pathfinder.xml) More... | |
fixed | GetCurrentSpeed () const override |
Get the speed at the end of the current turn. More... | |
void | SetFacePointAfterMove (bool facePointAfterMove) override |
Set whether the unit will turn to face the target point after finishing moving. More... | |
bool | GetFacePointAfterMove () const override |
void | SetDebugOverlay (bool enabled) override |
Toggle the rendering of debug info. More... | |
bool | MoveToPointRange (entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange) override |
Attempt to walk into range of a to a given point, or as close as possible. More... | |
bool | MoveToTargetRange (entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override |
Attempt to walk into range of a given target entity, or as close as possible. More... | |
void | MoveToFormationOffset (entity_id_t controller, entity_pos_t x, entity_pos_t z) override |
Join a formation, and move towards a given offset relative to the formation controller entity. More... | |
void | SetMemberOfFormation (entity_id_t controller) override |
Set/unset the unit as a formation member. More... | |
bool | IsTargetRangeReachable (entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override |
Check if the target is reachable. More... | |
void | FaceTowardsPoint (entity_pos_t x, entity_pos_t z) override |
Turn to look towards the given point. More... | |
void | StopMoving () override |
Clears the current MoveRequest - the unit will stop and no longer try and move. More... | |
entity_pos_t | GetUnitClearance () const override |
Get the unit clearance (used by the Obstruction component) More... | |
virtual bool | MoveToPointRange (entity_pos_t x, entity_pos_t z, entity_pos_t minRange, entity_pos_t maxRange)=0 |
Attempt to walk into range of a to a given point, or as close as possible. More... | |
virtual bool | MoveToTargetRange (entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)=0 |
Attempt to walk into range of a given target entity, or as close as possible. More... | |
virtual void | MoveToFormationOffset (entity_id_t controller, entity_pos_t x, entity_pos_t z)=0 |
Join a formation, and move towards a given offset relative to the formation controller entity. More... | |
virtual void | SetMemberOfFormation (entity_id_t controller)=0 |
Set/unset the unit as a formation member. More... | |
virtual bool | IsTargetRangeReachable (entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)=0 |
Check if the target is reachable. More... | |
virtual void | FaceTowardsPoint (entity_pos_t x, entity_pos_t z)=0 |
Turn to look towards the given point. More... | |
virtual void | StopMoving ()=0 |
Stop moving immediately. More... | |
virtual fixed | GetCurrentSpeed () const =0 |
Get the speed at the end of the current turn. More... | |
virtual bool | IsMoveRequested () const =0 |
virtual fixed | GetWalkSpeed () const =0 |
Get the unit template walk speed after modifications. More... | |
virtual fixed | GetRunMultiplier () const =0 |
Get the unit template running (i.e. More... | |
virtual fixed | GetSpeedMultiplier () const =0 |
Returns the ratio of GetSpeed() / GetWalkSpeed(). More... | |
virtual void | SetSpeedMultiplier (fixed multiplier)=0 |
Set the current movement speed. More... | |
virtual fixed | GetSpeed () const =0 |
Get the speed at which the unit intends to move. More... | |
virtual CFixedVector2D | EstimateFuturePosition (const fixed dt) const =0 |
virtual fixed | GetAcceleration () const =0 |
Get the current acceleration. More... | |
virtual void | SetAcceleration (fixed acceleration)=0 |
Set the current acceleration. More... | |
virtual void | SetFacePointAfterMove (bool facePointAfterMove)=0 |
Set whether the unit will turn to face the target point after finishing moving. More... | |
virtual bool | GetFacePointAfterMove () const =0 |
virtual pass_class_t | GetPassabilityClass () const =0 |
Get the unit's passability class. More... | |
virtual std::string | GetPassabilityClassName () const =0 |
Get the passability class name (as defined in pathfinder.xml) More... | |
virtual void | SetPassabilityClassName (const std::string &passClassName)=0 |
Sets the passability class name (as defined in pathfinder.xml) More... | |
virtual entity_pos_t | GetUnitClearance () const =0 |
Get the unit clearance (used by the Obstruction component) More... | |
virtual void | SetDebugOverlay (bool enabled)=0 |
Toggle the rendering of debug info. More... | |
Public Member Functions inherited from IComponent | |
virtual | ~IComponent () |
virtual void | Init (const CParamNode ¶mNode)=0 |
virtual void | Deinit ()=0 |
virtual void | HandleMessage (const CMessage &msg, bool global) |
CEntityHandle | GetEntityHandle () const |
void | SetEntityHandle (CEntityHandle ent) |
entity_id_t | GetEntityId () const |
CEntityHandle | GetSystemEntity () const |
const CSimContext & | GetSimContext () const |
void | SetSimContext (const CSimContext &context) |
virtual void | Serialize (ISerializer &serialize)=0 |
virtual void | Deserialize (const CParamNode ¶mNode, IDeserializer &deserialize)=0 |
virtual bool | NewJSObject (const 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 |
virtual int | GetComponentTypeId () const =0 |
Static Public Member Functions | |
static void | ClassInit (CComponentManager &componentManager) |
static IComponent * | Allocate (const ScriptInterface &, JS::HandleValue) |
static void | Deallocate (IComponent *cmp) |
static std::string | GetSchema () |
Static Public Member Functions inherited from IComponent | |
static std::string | GetSchema () |
static void | RegisterComponentType (CComponentManager &mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char *name, const std::string &schema) |
static void | RegisterComponentTypeScriptWrapper (CComponentManager &mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char *name, const std::string &schema) |
static u8 | GetSerializationVersion () |
Public Attributes | |
bool | m_DebugOverlayEnabled |
std::vector< SOverlayLine > | m_DebugOverlayLongPathLines |
std::vector< SOverlayLine > | m_DebugOverlayShortPathLines |
bool | m_IsFormationController |
fixed | m_TemplateWalkSpeed |
fixed | m_TemplateRunMultiplier |
fixed | m_TemplateAcceleration |
fixed | m_TemplateWeight |
pass_class_t | m_PassClass |
std::string | m_PassClassName |
entity_pos_t | m_Clearance |
fixed | m_WalkSpeed |
fixed | m_RunMultiplier |
bool | m_FacePointAfterMove |
bool | m_Pushing = false |
bool | m_BlockMovement = false |
u8 | m_FailedMovements = 0 |
u8 | m_FollowKnownImperfectPathCountdown = 0 |
struct CCmpUnitMotion::Ticket | m_ExpectedPathTicket |
struct CCmpUnitMotion::MoveRequest | m_MoveRequest |
entity_id_t | m_FormationController = INVALID_ENTITY |
fixed | m_SpeedMultiplier |
fixed | m_Speed |
fixed | m_LastTurnSpeed |
fixed | m_CurrentSpeed |
fixed | m_InstantTurnAngle |
fixed | m_Acceleration |
WaypointPath | m_LongPath |
WaypointPath | m_ShortPath |
Private Member Functions | |
bool | IsFormationMember () const |
bool | IsMovingAsFormation () const |
bool | IsFormationControllerMoving () const |
entity_id_t | GetGroup () const |
void | SetParticipateInPushing (bool pushing) |
void | SetPassabilityData (const std::string &passClassName) |
void | MoveFailed () |
Warns other components that our current movement will likely fail (e.g. More... | |
void | MoveSucceeded () |
Warns other components that our current movement is likely over (i.e. More... | |
void | MoveObstructed () |
Warns other components that our current movement was obstructed (i.e. More... | |
bool | IncrementFailedMovementsAndMaybeNotify () |
Increment the number of failed movements and notify other components if required. More... | |
bool | RejectFartherPaths (const PathGoal &goal, const WaypointPath &path, const CFixedVector2D &pos) const |
If path would take us farther away from the goal than pos currently is, return false, else return true. More... | |
bool | ShouldAlternatePathfinder () const |
bool | InShortPathRange (const PathGoal &goal, const CFixedVector2D &pos) const |
entity_pos_t | ShortPathSearchRange () const |
void | PathResult (u32 ticket, const WaypointPath &path) |
Handle the result of an asynchronous path query. More... | |
void | OnValueModification () |
void | OnTurnStart () |
Check if we are at destination early in the turn, this both lets units react faster and ensure that distance comparisons are done while units are not being moved (otherwise they won't be commutative). More... | |
void | PreMove (CCmpUnitMotionManager::MotionState &state) |
void | Move (CCmpUnitMotionManager::MotionState &state, fixed dt) |
void | PostMove (CCmpUnitMotionManager::MotionState &state, fixed dt) |
bool | PossiblyAtDestination () const |
Returns true if we are possibly at our destination. More... | |
bool | PerformMove (fixed dt, const fixed &turnRate, WaypointPath &shortPath, WaypointPath &longPath, CFixedVector2D &pos, fixed &speed, entity_angle_t &angle, uint8_t pushingPressure) const |
Process the move the unit will do this turn. More... | |
void | UpdateMovementState (entity_pos_t speed, entity_pos_t meanSpeed) |
Update other components on our speed. More... | |
bool | HandleObstructedMove (bool moved) |
React if our move was obstructed. More... | |
bool | TargetHasValidPosition (const MoveRequest &moveRequest) const |
Returns true if the target position is valid. More... | |
bool | TargetHasValidPosition () const |
bool | ComputeTargetPosition (CFixedVector2D &out, const MoveRequest &moveRequest) const |
Computes the current location of our target entity (plus offset). More... | |
bool | ComputeTargetPosition (CFixedVector2D &out) const |
bool | TryGoingStraightToTarget (const CFixedVector2D &from, bool updatePaths) |
Attempts to replace the current path with a straight line to the target, if it's close enough and the route is not obstructed. More... | |
bool | PathingUpdateNeeded (const CFixedVector2D &from) const |
Returns whether our we need to recompute a path to reach our target. 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... | |
bool | ShouldCollideWithMovingUnits () const |
Units in 'pushing' mode are marked as 'moving' in the obstruction manager. More... | |
ControlGroupMovementObstructionFilter | GetObstructionFilter () const |
Returns an appropriate obstruction filter for use with path requests. More... | |
SkipTagAndControlGroupObstructionFilter | GetObstructionFilter (const ICmpObstructionManager::tag_t &tag) const |
Filter a specific tag on top of the existing control groups. 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 | ComputeGoal (PathGoal &out, const MoveRequest &moveRequest) const |
Create a PathGoal from a move request. More... | |
void | ComputePathToGoal (const CFixedVector2D &from, const PathGoal &goal) |
Compute a path to the given goal from the given position. 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 extendRange) |
Start an asynchronous short path query. More... | |
bool | MoveTo (MoveRequest request) |
General handler for MoveTo interface functions. 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) |
Friends | |
class | CCmpUnitMotionManager |
Additional Inherited Members | |
Public Types inherited from IComponent | |
using | AllocFunc = IComponent *(*)(const ScriptInterface &scriptInterface, JS::HandleValue ctor) |
using | DeallocFunc = void(*)(IComponent *) |
|
inlinestatic |
|
inlinestatic |
|
private |
Create a PathGoal from a move request.
|
private |
Compute a path to the given goal from the given position.
Might go in a straight line immediately, or might start an asynchronous path request.
|
inlineprivate |
|
private |
Computes the current location of our target entity (plus offset).
Returns false if no target entity or no valid position.
|
inlinestatic |
|
inlineoverridevirtual |
Implements IComponent.
|
inlineoverridevirtual |
Implements IComponent.
|
inlineoverridevirtual |
dt | seconds, following current paths. This is allowed to 'look into the future'. |
Implements ICmpUnitMotion.
|
overridevirtual |
Turn to look towards the given point.
Implements ICmpUnitMotion.
|
private |
Rotate to face towards the target point, given the current pos.
|
inlineoverridevirtual |
Get the current acceleration.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Implements IComponent.
|
inlineoverridevirtual |
Get the speed at the end of the current turn.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Implements ICmpUnitMotion.
|
inlineprivate |
|
inlineprivate |
Returns an appropriate obstruction filter for use with path requests.
|
inlineprivate |
Filter a specific tag on top of the existing control groups.
|
inlineoverridevirtual |
Get the unit's passability class.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Get the passability class name (as defined in pathfinder.xml)
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
|
inlinestatic |
|
inlineoverridevirtual |
Get the speed at which the unit intends to move.
(regardless of whether the unit is moving or not right now).
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Returns the ratio of GetSpeed() / GetWalkSpeed().
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Get the unit clearance (used by the Obstruction component)
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Get the unit template walk speed after modifications.
Implements ICmpUnitMotion.
|
inlinevirtual |
|
inlineoverridevirtual |
Reimplemented from IComponent.
|
private |
React if our move was obstructed.
moved | - true if the unit still managed to move. |
|
inlineprivate |
Increment the number of failed movements and notify other components if required.
|
inlineoverridevirtual |
Implements IComponent.
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
|
inlineoverridevirtual |
Implements ICmpUnitMotion.
|
inlineprivate |
|
overridevirtual |
Check if the target is reachable.
Don't take this as absolute gospel since there are things that the pathfinder may not detect, such as entity obstructions in the way, but in general it should return satisfactory results. The interface is similar to MoveToTargetRange but the move is not attempted.
Implements ICmpUnitMotion.
|
private |
|
inlineprivate |
Warns other components that our current movement will likely fail (e.g.
we won't be able to reach our target) This should only be called before the actual movement in a given turn, or units might both move and try to do things on the same turn, leading to gliding units.
|
inlineprivate |
Warns other components that our current movement was obstructed (i.e.
we failed to move this turn). This should only be called before the actual movement in a given turn, or units might both move and try to do things on the same turn, leading to gliding units.
|
inlineprivate |
Warns other components that our current movement is likely over (i.e.
we probably reached our destination) This should only be called before the actual movement in a given turn, or units might both move and try to do things on the same turn, leading to gliding units.
|
private |
General handler for MoveTo interface functions.
|
inlineoverridevirtual |
Join a formation, and move towards a given offset relative to the formation controller entity.
The unit will remain 'in formation' fromthe perspective of UnitMotion until SetMemberOfFormation(INVALID_ENTITY) is passed.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
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 cannot move anywhere at all, or if there is some other error, then returns false. Otherwise, returns true. If maxRange is negative, then the maximum range is treated as infinity.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
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 cannot move anywhere at all, or if there is some other error, then returns false. Otherwise, returns true. If maxRange is negative, then the maximum range is treated as infinity.
Implements ICmpUnitMotion.
|
private |
Check if we are at destination early in the turn, this both lets units react faster and ensure that distance comparisons are done while units are not being moved (otherwise they won't be commutative).
|
inlineprivate |
|
private |
Returns whether our we need to recompute a path to reach our target.
|
private |
Handle the result of an asynchronous path query.
|
private |
Process the move the unit will do this turn.
This does not send actually change the position.
|
private |
Returns true if we are possibly at our destination.
Since the concept of being at destination is dependent on why the move was requested, UnitMotion can only ever hint about this, hence the conditional tone.
|
private |
|
private |
|
private |
If path would take us farther away from the goal than pos currently is, return false, else return true.
|
private |
Convert a path into a renderable list of lines.
|
private |
|
private |
Start an asynchronous long path query.
|
private |
Start an asynchronous short path query.
extendRange | - if true, extend the search range to at least the distance to the goal. |
|
inlineoverridevirtual |
Implements IComponent.
|
inline |
|
inlineoverridevirtual |
|
inlineoverridevirtual |
Toggle the rendering of debug info.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Set whether the unit will turn to face the target point after finishing moving.
Implements ICmpUnitMotion.
|
inlineoverridevirtual |
Set/unset the unit as a formation member.
controller | - if INVALID_ENTITY, the unit is no longer a formation member. Otherwise it is and this is the controller. |
Implements ICmpUnitMotion.
|
inlineprivate |
|
inlineoverridevirtual |
Sets the passability class name (as defined in pathfinder.xml)
Implements ICmpUnitMotion.
|
inlineprivate |
|
inlineoverridevirtual |
Set the current movement speed.
speed | A multiplier of GetWalkSpeed(). |
Implements ICmpUnitMotion.
|
inlineprivate |
|
inlineprivate |
|
inlineprivate |
Units in 'pushing' mode are marked as 'moving' in the obstruction manager.
Units in 'pushing' mode should skip them in checkMovement (to enable pushing). However, units for which pushing is deactivated should collide against everyone. Units that don't block movement never participate in pushing, but they also shouldn't collide with pushing units.
|
private |
Decide whether to approximate the given range from a square target as a circle, rather than as a square.
|
inlineoverridevirtual |
Clears the current MoveRequest - the unit will stop and no longer try and move.
This should never be called from UnitMotion, since MoveToX orders are given by other components - these components should also decide when to stop.
Implements ICmpUnitMotion.
|
inlineprivate |
|
private |
Returns true if the target position is valid.
False otherwise. (this may indicate that the target is e.g. out of the world/dead). NB: for code-writing convenience, if we have no target, this returns true.
|
private |
Attempts to replace the current path with a straight line to the target, if it's close enough and the route is not obstructed.
|
inline |
|
private |
Update other components on our speed.
(For performance, this should try to avoid sending messages).
|
friend |
fixed CCmpUnitMotion::m_Acceleration |
bool CCmpUnitMotion::m_BlockMovement = false |
entity_pos_t CCmpUnitMotion::m_Clearance |
fixed CCmpUnitMotion::m_CurrentSpeed |
bool CCmpUnitMotion::m_DebugOverlayEnabled |
std::vector<SOverlayLine> CCmpUnitMotion::m_DebugOverlayLongPathLines |
std::vector<SOverlayLine> CCmpUnitMotion::m_DebugOverlayShortPathLines |
struct CCmpUnitMotion::Ticket CCmpUnitMotion::m_ExpectedPathTicket |
bool CCmpUnitMotion::m_FacePointAfterMove |
u8 CCmpUnitMotion::m_FailedMovements = 0 |
u8 CCmpUnitMotion::m_FollowKnownImperfectPathCountdown = 0 |
entity_id_t CCmpUnitMotion::m_FormationController = INVALID_ENTITY |
fixed CCmpUnitMotion::m_InstantTurnAngle |
bool CCmpUnitMotion::m_IsFormationController |
fixed CCmpUnitMotion::m_LastTurnSpeed |
WaypointPath CCmpUnitMotion::m_LongPath |
struct CCmpUnitMotion::MoveRequest CCmpUnitMotion::m_MoveRequest |
pass_class_t CCmpUnitMotion::m_PassClass |
std::string CCmpUnitMotion::m_PassClassName |
bool CCmpUnitMotion::m_Pushing = false |
fixed CCmpUnitMotion::m_RunMultiplier |
WaypointPath CCmpUnitMotion::m_ShortPath |
fixed CCmpUnitMotion::m_Speed |
fixed CCmpUnitMotion::m_SpeedMultiplier |
fixed CCmpUnitMotion::m_TemplateAcceleration |
fixed CCmpUnitMotion::m_TemplateRunMultiplier |
fixed CCmpUnitMotion::m_TemplateWalkSpeed |
fixed CCmpUnitMotion::m_TemplateWeight |
fixed CCmpUnitMotion::m_WalkSpeed |