18 #ifndef INCLUDED_CCMPUNITMOTION 19 #define INCLUDED_CCMPUNITMOTION 52 #define DISABLE_PATHFINDER 0 197 } m_Type = SHORT_PATH;
248 "<a:help>Provides the unit with the ability to move around the world by itself.</a:help>" 250 "<WalkSpeed>7.0</WalkSpeed>" 251 "<PassabilityClass>default</PassabilityClass>" 253 "<element name='FormationController'>" 254 "<data type='boolean'/>" 256 "<element name='WalkSpeed' a:help='Basic movement speed (in metres per second).'>" 257 "<ref name='positiveDecimal'/>" 260 "<element name='RunMultiplier' a:help='How much faster the unit goes when running (as a multiple of walk speed).'>" 261 "<ref name='positiveDecimal'/>" 264 "<element name='InstantTurnAngle' a:help='Angle we can turn instantly. Any value greater than pi will disable turning times. Avoid zero since it stops the entity every turn.'>" 265 "<ref name='positiveDecimal'/>" 267 "<element name='Acceleration' a:help='Acceleration (in metres per second^2).'>" 268 "<ref name='positiveDecimal'/>" 270 "<element name='PassabilityClass' a:help='Identifies the terrain passability class (values are defined in special/pathfinder.xml).'>" 273 "<element name='Weight' a:help='Makes this unit both push harder and harder to push. 10 is considered the base value.'>" 274 "<ref name='positiveDecimal'/>" 277 "<element name='DisablePushing'>" 278 "<data type='boolean'/>" 338 serialize.NumberU32_Unbounded(
"formation controller", m_FormationController);
340 serialize.NumberFixed_Unbounded(
"speed multiplier", m_SpeedMultiplier);
342 serialize.NumberFixed_Unbounded(
"last turn speed", m_LastTurnSpeed);
343 serialize.NumberFixed_Unbounded(
"current speed", m_CurrentSpeed);
345 serialize.NumberFixed_Unbounded(
"instant turn angle", m_InstantTurnAngle);
347 serialize.NumberFixed_Unbounded(
"acceleration", m_Acceleration);
380 PROFILE(
"UnitMotion::RenderSubmit");
470 if (!cmpPosition || !cmpPosition->
IsInWorld())
493 m_Acceleration = acceleration;
515 LOGWARNING(
"Only formation controllers can change their passability class");
560 m_FormationController = controller;
577 if (cmpPosition && cmpPosition->
IsInWorld())
739 if (!cmpValueModificationManager)
899 if (path.m_Waypoints.empty())
903 if (goal.DistanceToPoint(pos) <= goal.DistanceToPoint(
CFixedVector2D(path.m_Waypoints.front().x, path.m_Waypoints.front().z)))
921 if (!cmpPosition || !cmpPosition->
IsInWorld())
929 bool shortPathHack =
false;
933 if (!pathedTowardsGoal)
996 if (!pathedTowardsGoal)
1119 ENSURE(cmpObstructionManager);
1163 if (pushingPressure)
1166 constexpr
int pressureMinThreshold = 10;
1172 static_assert(maxPressure > 0);
1174 uint8_t slowdown = maxPressure - std::min(maxPressure, std::max(0, pushingPressure - pressureMinThreshold));
1185 fixed maxSpeed = basicSpeed;
1187 fixed timeLeft = dt;
1194 if (cmpTargetObstruction)
1198 while (timeLeft > zero)
1212 if (turnRate > zero && !offset.
IsZero())
1233 angle += maxRotation * direction;
1240 timeLeft = std::min(maxRotation, maxRotation - absoluteAngleDiff +
m_InstantTurnAngle) / turnRate;
1255 fixed maxdist = accelDist + maxSpeed.
Multiply(timeLeft - accelTime);
1258 fixed offsetLength = offset.Length();
1259 if (offsetLength <= maxdist)
1269 if (offsetLength <= accelDist)
1272 timeLeft -= requiredTime;
1277 timeLeft -= accelTime + (offsetLength - accelDist) / maxSpeed;
1297 offset.Normalize(maxdist);
1298 target = pos + offset;
1331 if (!cmpPosition || !cmpPosition->
IsInWorld())
1370 next.
x = pos.
X + backUp.
X;
1371 next.
z = pos.
Y + backUp.
Y;
1416 return cmpPosition && cmpPosition->
IsInWorld();
1428 if (!cmpTargetPosition || !cmpTargetPosition->
IsInWorld())
1452 if (needInterpolation)
1482 goal.
x = targetPos.
X;
1483 goal.
z = targetPos.
Y;
1500 if (cmpTargetObstruction)
1505 if (specificIgnore.
valid())
1543 if (cmpTargetObstruction)
1547 estimatedTargetShape.
x = targetPos.
X;
1548 estimatedTargetShape.
z = targetPos.
Y;
1564 shape.
x = lastWaypoint.
x;
1565 shape.
z = lastWaypoint.
z;
1569 ENSURE(cmpObstructionManager);
1579 if (cmpObstructionManager->
AreShapesInRange(shape, estimatedTargetShape, minRange, maxRange,
false))
1588 if (!cmpPosition || !cmpPosition->
IsInWorld())
1606 cmpPosition->
TurnTo(angle);
1620 return (range > circleRadius*3);
1629 if (!cmpPosition || !cmpPosition->
IsInWorld())
1642 if (cmpTargetObstruction)
1645 targetObstruction.
x = targetPosition.
X;
1646 targetObstruction.
z = targetPosition.
Y;
1654 obstruction.
x = pos.
X;
1655 obstruction.
z = pos.
Y;
1659 ENSURE(cmpObstructionManager);
1663 out.
x = targetObstruction.
x;
1664 out.
z = targetObstruction.
z;
1665 out.
hw = targetObstruction.
hw;
1666 out.
hh = targetObstruction.
hh;
1667 out.
u = targetObstruction.
u;
1668 out.
v = targetObstruction.
v;
1698 out.
hw = circleRadius + goalDistance;
1703 out.
hw = targetObstruction.
hw + goalDistance;
1704 out.
hh = targetObstruction.
hh + goalDistance;
1713 circleRadius = std::min(targetObstruction.
hw, targetObstruction.
hh);
1716 out.
hw = circleRadius + goalDistance;
1727 out.
hw = targetObstruction.
hw + delta;
1728 out.
hh = targetObstruction.
hh + delta;
1737 #if DISABLE_PATHFINDER 1772 shortPath = !shortPath;
1830 LOGWARNING(
"MaxRange must be larger than MinRange; See CCmpUnitMotion.cpp for more information");
1833 if (!cmpPosition || !cmpPosition->
IsInWorld())
1851 if (!cmpPosition || !cmpPosition->
IsInWorld())
1867 bool floating =
false;
1870 floating = cmpPosition->
CanFloat();
1873 std::vector<float> waypointCoords;
1874 for (
size_t i = 0; i < path.
m_Waypoints.size(); ++i)
1878 waypointCoords.push_back(x);
1879 waypointCoords.push_back(z);
1881 lines.back().m_Color = color;
1886 waypointCoords.push_back(x);
1887 waypointCoords.push_back(z);
1889 lines.back().m_Color = color;
1909 #endif // INCLUDED_CCMPUNITMOTION bool IsFormationControllerMoving() const
Definition: CCmpUnitMotion.h:607
bool isMoving
Definition: CCmpUnitMotionManager.h:89
An entity initialisation parameter node.
Definition: ParamNode.h:150
void SubscribeToMessageType(MessageTypeId mtid)
Subscribe the current component type to the given message type.
Definition: ComponentManager.cpp:549
constexpr u8 ALTERNATE_PATH_TYPE_EVERY
Definition: CCmpUnitMotion.h:113
MoveRequest(CFixedVector2D pos, entity_pos_t minRange, entity_pos_t maxRange)
Definition: CCmpUnitMotion.h:217
A simple fixed-point number class.
Definition: Fixed.h:119
static constexpr int MAX_PRESSURE
Maximum value for pushing pressure.
Definition: CCmpUnitMotionManager.h:41
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...
Definition: CCmpUnitMotion.h:1462
fixed speed
Definition: CCmpUnitMotionManager.h:64
entity_pos_t x
Definition: ICmpObstructionManager.h:68
pass_class_t GetPassabilityClass() const override
Get the unit's passability class.
Definition: CCmpUnitMotion.h:501
fixed m_SpeedMultiplier
Definition: CCmpUnitMotion.h:226
fixed m_Acceleration
Definition: CCmpUnitMotion.h:238
#define REGISTER_COMPONENT_TYPE(cname)
Definition: Component.h:32
void PathResult(u32 ticket, const WaypointPath &path)
Handle the result of an asynchronous path query.
Definition: CCmpUnitMotion.h:909
virtual void SetDebugPath(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass)=0
If the debug overlay is enabled, render the path that will computed by ComputePath.
const CColor OVERLAY_COLOR_LONG_PATH(1, 1, 1, 1)
Definition: FixedVector2D.h:24
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.
Definition: CCmpUnitMotion.h:547
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
Sent by CCmpUnitMotion during Update if an event happened that might interest other components...
Definition: MessageTypes.h:322
CFixedVector2D EstimateFuturePosition(const fixed dt) const override
Definition: CCmpUnitMotion.h:467
u16 pass_class_t
Definition: Pathfinding.h:27
Line-based overlay, with world-space coordinates, rendered in the world potentially behind other obje...
Definition: Overlay.h:38
entity_id_t m_FormationController
Definition: CCmpUnitMotion.h:223
Definition: Components.h:75
T Clamp(T value, T min, T max)
Definition: MathUtil.h:32
virtual bool CanFloat() const =0
Returns whether the entity can float on water.
bool TargetHasValidPosition() const
Definition: CCmpUnitMotion.h:795
static CFixed Zero()
Definition: Fixed.h:131
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.
Definition: CCmpUnitMotion.h:897
virtual pass_class_t GetPassabilityClass(const std::string &name) const =0
Get the tag for a given passability class name.
virtual bool IsInPointRange(entity_id_t ent, entity_pos_t px, entity_pos_t pz, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0
Check if the given entity is in range of the other point given those parameters.
entity_pos_t GetUnitClearance() const override
Get the unit clearance (used by the Obstruction component)
Definition: CCmpUnitMotion.h:591
virtual CFixedVector2D GetPosition2D() const =0
Returns the current x,z position (no interpolation).
static constexpr CFixed FromFraction(int n, int d)
Definition: Fixed.h:146
Definition: CCmpUnitMotion.h:195
Returned path.
Definition: Pathfinding.h:66
entity_pos_t m_Clearance
Definition: CCmpUnitMotion.h:164
CComponentManager & GetComponentManager() const
Definition: SimContext.cpp:35
bool valid() const
Definition: ICmpObstructionManager.h:81
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...
Definition: CCmpUnitMotion.h:552
void RenderSubmit(SceneCollector &collector)
Definition: CCmpUnitMotion.h:1894
void Init(const CParamNode ¶mNode) override
Definition: CCmpUnitMotion.h:283
CFixedVector2D initialPos
Definition: CCmpUnitMotionManager.h:57
#define ENTITY_IS_LOCAL(id)
Definition: Entity.h:59
bool ignore
Definition: CCmpUnitMotionManager.h:80
void SetPassabilityClassName(const std::string &passClassName) override
Sets the passability class name (as defined in pathfinder.xml)
Definition: CCmpUnitMotion.h:511
bool IsTargetRangeReachable(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange) override
Check if the target is reachable.
Definition: CCmpUnitMotion.h:1848
void Normalize()
Normalize the vector so that length is close to 1.
Definition: FixedVector2D.h:181
const std::string & ToString() const
Returns the content of this node as an UTF8 string.
Definition: ParamNode.cpp:271
virtual bool IsInTargetRange(entity_id_t ent, entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0
Check if the given entity is in range of the target given those parameters.
Serialization interface; see serialization overview.
Definition: ISerializer.h:120
void OnTurnStart()
Check if we are at destination early in the turn, this both lets units react faster and ensure that d...
Definition: CCmpUnitMotion.h:1019
CFixedVector2D Rotate(fixed angle) const
Rotate the vector by the given angle (anticlockwise).
Definition: FixedVector2D.h:241
uint8_t pushingPressure
Definition: CCmpUnitMotionManager.h:76
Obstruction test filter that reject shapes in a given control group, and rejects shapes that don't bl...
Definition: ICmpObstructionManager.h:400
Add renderable objects to the scene collector.
Definition: MessageTypes.h:149
static std::string GetSchema()
Definition: CCmpUnitMotion.h:245
static void out(const wchar_t *fmt,...)
Definition: wdbg_sym.cpp:421
std::vector< SOverlayLine > m_DebugOverlayShortPathLines
Definition: CCmpUnitMotion.h:152
entity_pos_t hw
Definition: PathGoal.h:45
Definition: CCmpUnitMotionManager.h:44
entity_id_t controlGroup
Definition: CCmpUnitMotionManager.h:71
void Serializer(S &serialize, const char *name, Args &&... args)
Definition: SerializeTemplates.h:51
constexpr entity_pos_t DIRECT_PATH_RANGE
If we are this close to our target entity/point, then think about heading for it in a straight line i...
Definition: CCmpUnitMotion.h:80
std::vector< Waypoint > m_Waypoints
Definition: Pathfinding.h:68
Similar to ControlGroupMovementObstructionFilter, but also ignoring a specific tag.
Definition: ICmpObstructionManager.h:541
virtual entity_pos_t GetWeight() const
Definition: CCmpUnitMotion.h:496
fixed m_TemplateWeight
Definition: CCmpUnitMotion.h:158
bool MoveTo(MoveRequest request)
General handler for MoveTo interface functions.
Definition: CCmpUnitMotion.h:1825
Definition: CCmpUnitMotion.h:202
bool IsFormationMember() const
Definition: CCmpUnitMotion.h:597
bool ComputeGoal(PathGoal &out, const MoveRequest &moveRequest) const
Create a PathGoal from a move request.
Definition: CCmpUnitMotion.h:1623
Definition: PathGoal.h:37
Definition: Pathfinding.h:57
void RequestShortPath(const CFixedVector2D &from, const PathGoal &goal, bool extendRange)
Start an asynchronous short path query.
Definition: CCmpUnitMotion.h:1803
entity_pos_t m_MaxRange
Definition: CCmpUnitMotion.h:211
#define LOGWARNING(...)
Definition: CLogger.h:35
Definition: CCmpUnitMotion.h:205
virtual void SelectMovementAnimation(const std::string &name, fixed speed)=0
Start playing the given movement animation unless we are currently playing a non-movement animation...
void Move(CCmpUnitMotionManager::MotionState &state, fixed dt)
Definition: CCmpUnitMotion.h:1061
void RenderPath(const WaypointPath &path, std::vector< SOverlayLine > &lines, CColor color)
Convert a path into a renderable list of lines.
Definition: CCmpUnitMotion.h:1865
Definition: ShaderDefines.cpp:30
fixed Y
Definition: FixedVector3D.h:27
Pathfinder goal.
Definition: PathGoal.h:32
constexpr entity_pos_t LONG_PATH_MIN_DIST
Minimum distance to goal for a long path request.
Definition: CCmpUnitMotion.h:74
virtual void MoveAndTurnTo(entity_pos_t x, entity_pos_t z, entity_angle_t ry)=0
Combines MoveTo and TurnTo to avoid an uncessary "AdvertisePositionChange".
void UpdateMovementState(entity_pos_t speed, entity_pos_t meanSpeed)
Update other components on our speed.
Definition: CCmpUnitMotion.h:1313
virtual CFixedVector3D GetRotation() const =0
Returns the current rotation (relative to the upwards axis), as Euler angles with X=pitch...
entity_pos_t hh
Definition: ICmpObstructionManager.h:70
virtual CFixedVector2D GetPreviousPosition2D() const =0
Returns the previous turn's x,z position (no interpolation).
void SetAcceleration(fixed acceleration) override
Set the current acceleration.
Definition: CCmpUnitMotion.h:491
CEntityHandle GetSystemEntity() const
Definition: IComponent.h:56
static CFixed Pi()
Definition: Fixed.cpp:182
int CompareLength(fixed cmp) const
Returns -1, 0, +1 depending on whether length is less/equal/greater than the argument.
Definition: FixedVector2D.h:122
bool m_DebugOverlayEnabled
Definition: CCmpUnitMotion.h:150
MoveRequest(entity_id_t target, CFixedVector2D offset)
Definition: CCmpUnitMotion.h:219
void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize) override
Definition: CCmpUnitMotion.h:361
std::string m_PassClassName
Definition: CCmpUnitMotion.h:160
uint8_t u8
Definition: types.h:37
virtual u32 ComputeShortPathAsync(entity_pos_t x0, entity_pos_t z0, entity_pos_t clearance, entity_pos_t range, const PathGoal &goal, pass_class_t passClass, bool avoidMovingUnits, entity_id_t controller, entity_id_t notify)=0
Request a short path computation, asynchronously.
enum CCmpUnitMotion::Ticket::Type m_Type
virtual bool IsInWorld() const =0
Returns true if the entity currently exists at a defined position in the world.
bool IsMovingAsFormation() const
Definition: CCmpUnitMotion.h:602
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Definition: Entity.h:43
CFixedVector2D m_Position
Definition: CCmpUnitMotion.h:210
struct CCmpUnitMotion::Ticket m_ExpectedPathTicket
fixed Y
Definition: FixedVector2D.h:27
This interface accepts renderable objects.
Definition: Scene.h:89
constexpr entity_pos_t SHORT_PATH_MIN_SEARCH_RANGE
Min/Max range to restrict short path queries to.
Definition: CCmpUnitMotion.h:61
virtual bool GetBlockMovementFlag(bool templateOnly) const =0
Motion interface for entities with complex movement capabilities.
Definition: ICmpUnitMotion.h:34
void SetPassabilityData(const std::string &passClassName)
Definition: CCmpUnitMotion.h:624
Definition: Components.h:84
entity_pos_t z
Definition: Pathfinding.h:59
virtual fixed ApplyModifications(std::wstring valueName, fixed currentValue, entity_id_t entity) const =0
bool IncrementFailedMovementsAndMaybeNotify()
Increment the number of failed movements and notify other components if required. ...
Definition: CCmpUnitMotion.h:695
virtual u32 ComputePathAsync(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass, entity_id_t notify)=0
Asynchronous version of ComputePath.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition: debug.h:290
fixed m_TemplateAcceleration
Definition: CCmpUnitMotion.h:158
virtual void SetMovingFlag(bool enabled)=0
fixed initialAngle
Definition: CCmpUnitMotionManager.h:66
fixed GetAcceleration() const override
Get the current acceleration.
Definition: CCmpUnitMotion.h:486
fixed m_CurrentSpeed
Definition: CCmpUnitMotion.h:234
Definition: Components.h:70
virtual int GetType() const =0
constexpr fixed NAVCELL_SIZE
The long-range pathfinder operates primarily over a navigation grid (a uniform-cost 2D passability gr...
Definition: Pathfinding.h:143
uint32_t u32
Definition: types.h:39
Type
Definition: CCmpUnitMotion.h:203
Type
Definition: CCmpUnitMotion.h:194
fixed GetRunMultiplier() const override
Get the unit template running (i.e.
Definition: CCmpUnitMotion.h:462
virtual ICmpObstructionManager::tag_t GetObstruction() const =0
entity_pos_t m_MinRange
Definition: CCmpUnitMotion.h:211
fixed DistanceToPoint(CFixedVector2D pos) const
Returns the minimum distance from the point pos to any point on the goal shape.
Definition: PathGoal.cpp:294
constexpr int NAVCELL_SIZE_INT
Definition: Pathfinding.h:144
SkipTagAndControlGroupObstructionFilter GetObstructionFilter(const ICmpObstructionManager::tag_t &tag) const
Filter a specific tag on top of the existing control groups.
Definition: CCmpUnitMotion.h:848
void PostMove(CCmpUnitMotionManager::MotionState &state, fixed dt)
Definition: CCmpUnitMotion.h:1073
entity_pos_t hw
Definition: ICmpObstructionManager.h:70
void ConstructLineOnGround(const CSimContext &context, const std::vector< float > &xz, SOverlayLine &overlay, bool floating, float heightOffset=0.25f)
Constructs overlay line from given points, conforming to terrain.
Definition: Render.cpp:36
Provide specializations for some generic types and containers.
const CColor OVERLAY_COLOR_SHORT_PATH(1, 0, 0, 1)
Definition: ComponentManager.h:39
static void ClassInit(CComponentManager &componentManager)
Definition: CCmpUnitMotion.h:137
virtual bool AreShapesInRange(const ObstructionSquare &source, const ObstructionSquare &target, entity_pos_t minRange, entity_pos_t maxRange, bool opposite) const =0
Check if the given shape is in range of the target shape given those parameters.
bool m_FacePointAfterMove
Definition: CCmpUnitMotion.h:169
std::string GetPassabilityClassName() const override
Get the passability class name (as defined in pathfinder.xml)
Definition: CCmpUnitMotion.h:506
void UpdateMessageSubscriptions()
Definition: CCmpUnitMotion.h:430
bool InShortPathRange(const PathGoal &goal, const CFixedVector2D &pos) const
Definition: CCmpUnitMotion.h:717
virtual void TurnTo(entity_angle_t y)=0
Rotate smoothly to the given angle around the upwards axis.
bool HandleObstructedMove(bool moved)
React if our move was obstructed.
Definition: CCmpUnitMotion.h:1328
void SetDebugOverlay(bool enabled) override
Toggle the rendering of debug info.
Definition: CCmpUnitMotion.h:536
unsigned char uint8_t
Definition: wposix_types.h:51
void StopMoving() override
Clears the current MoveRequest - the unit will stop and no longer try and move.
Definition: CCmpUnitMotion.h:572
struct CCmpUnitMotion::MoveRequest m_MoveRequest
fixed GetSpeed() const override
Get the speed at which the unit intends to move.
Definition: CCmpUnitMotion.h:452
entity_id_t GetEntityId() const
Definition: IComponent.h:54
Definition: MessageTypes.h:328
Definition: MessageTypes.h:329
Sent by aura manager when a value of a certain entity's component is changed.
Definition: MessageTypes.h:496
WaypointPath m_LongPath
Definition: CCmpUnitMotion.h:242
entity_pos_t hh
Definition: PathGoal.h:45
void SerializeCommon(S &serialize)
Definition: CCmpUnitMotion.h:320
void SetParticipateInPushing(bool pushing)
Definition: CCmpUnitMotion.h:618
constexpr u8 ALTERNATE_PATH_TYPE_DELAY
When computing paths but failing to move, we want to occasionally alternate pathfinder systems to avo...
Definition: CCmpUnitMotion.h:112
Definition: Components.h:74
void SetMemberOfFormation(entity_id_t controller) override
Set/unset the unit as a formation member.
Definition: CCmpUnitMotion.h:558
fixed Length() const
Returns the length of the vector.
Definition: FixedVector2D.h:101
entity_pos_t x
Definition: PathGoal.h:43
void PostMessage(entity_id_t ent, const CMessage &msg)
Send a message, targeted at a particular entity.
Definition: ComponentManager.cpp:992
enum CCmpUnitMotion::MoveRequest::Type m_Type
fixed ToFixed() const
Parses the content of this node as a fixed-point number.
Definition: ParamNode.cpp:286
constexpr u8 BACKUP_HACK_DELAY
Units can occasionally get stuck near corners.
Definition: CCmpUnitMotion.h:121
#define PROFILE(name)
Definition: Profile.h:159
void HandleMessage(const CMessage &msg, bool global) override
Definition: CCmpUnitMotion.h:374
#define DEFAULT_COMPONENT_ALLOCATOR(cname)
Definition: Component.h:39
entity_id_t m_Entity
Definition: CCmpUnitMotion.h:209
bool IsOk() const
Returns true if this is a valid CParamNode, false if it represents a non-existent node...
Definition: ParamNode.cpp:261
Definition: Components.h:87
Definition: PathGoal.h:40
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.
Definition: CCmpUnitMotion.h:1142
fixed GetWalkSpeed() const override
Get the unit template walk speed after modifications.
Definition: CCmpUnitMotion.h:457
constexpr bool IsZero() const
Returns true if the number is precisely 0.
Definition: Fixed.h:209
void PreMove(CCmpUnitMotionManager::MotionState &state)
Definition: CCmpUnitMotion.h:1037
Definition: CCmpUnitMotionManager.h:31
Definition: PathGoal.h:39
u8 m_FollowKnownImperfectPathCountdown
Definition: CCmpUnitMotion.h:190
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 squa...
Definition: CCmpUnitMotion.h:1613
CFixedVector2D GetOffset() const
Definition: CCmpUnitMotion.h:214
u32 ticket
Definition: MessageTypes.h:489
fixed m_RunMultiplier
Definition: CCmpUnitMotion.h:167
void ComputePathToGoal(const CFixedVector2D &from, const PathGoal &goal)
Compute a path to the given goal from the given position.
Definition: CCmpUnitMotion.h:1735
A simplified syntax for accessing entity components.
Definition: CmpPtr.h:55
constexpr u8 VERY_OBSTRUCTED_THRESHOLD
After this many failed computations, start sending "VERY_OBSTRUCTED" messages instead.
Definition: CCmpUnitMotion.h:127
WaypointPath path
Definition: MessageTypes.h:490
bool needUpdate
Definition: CCmpUnitMotionManager.h:83
Definition: CCmpUnitMotion.h:196
bool m_IsFormationController
Definition: CCmpUnitMotion.h:156
MoveRequest(entity_id_t target, entity_pos_t minRange, entity_pos_t maxRange)
Definition: CCmpUnitMotion.h:218
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.
Definition: CCmpUnitMotion.h:542
constexpr u8 SHORT_PATH_SEARCH_RANGE_INCREASE_DELAY
Definition: CCmpUnitMotion.h:64
bool ComputeTargetPosition(CFixedVector2D &out, const MoveRequest &moveRequest) const
Computes the current location of our target entity (plus offset).
Definition: CCmpUnitMotion.h:1419
void FaceTowardsPoint(entity_pos_t x, entity_pos_t z) override
Turn to look towards the given point.
Definition: CCmpUnitMotion.h:1585
CFixedVector2D v
Definition: PathGoal.h:47
ControlGroupMovementObstructionFilter GetObstructionFilter() const
Returns an appropriate obstruction filter for use with path requests.
Definition: CCmpUnitMotion.h:841
constexpr CFixed Absolute() const
Definition: Fixed.h:315
fixed GetCurrentSpeed() const override
Get the speed at the end of the current turn.
Definition: CCmpUnitMotion.h:521
fixed m_InstantTurnAngle
Definition: CCmpUnitMotion.h:236
fixed m_TemplateRunMultiplier
Definition: CCmpUnitMotion.h:158
bool m_BlockMovement
Definition: CCmpUnitMotion.h:176
Definition: Components.h:88
fixed GetSpeedMultiplier() const override
Returns the ratio of GetSpeed() / GetWalkSpeed().
Definition: CCmpUnitMotion.h:441
bool GetFacePointAfterMove() const override
Definition: CCmpUnitMotion.h:531
CFixedVector2D NearestPointOnGoal(CFixedVector2D pos) const
Returns the coordinates of the point on the goal that is closest to the point pos.
Definition: PathGoal.cpp:327
CFixedVector2D u
Definition: PathGoal.h:47
u32 m_Ticket
Definition: CCmpUnitMotion.h:193
bool PathingUpdateNeeded(const CFixedVector2D &from) const
Returns whether our we need to recompute a path to reach our target.
Definition: CCmpUnitMotion.h:1523
virtual bool ComputingMotion() const =0
True if entities are currently in the "Move" phase.
CFixed Multiply(CFixed n) const
Multiply by a CFixed.
Definition: Fixed.h:321
pass_class_t m_PassClass
Definition: CCmpUnitMotion.h:159
virtual bool CheckMovement(const IObstructionTestFilter &filter, entity_pos_t x0, entity_pos_t z0, entity_pos_t x1, entity_pos_t z1, entity_pos_t r, pass_class_t passClass) const =0
Check whether the given movement line is valid and doesn't hit any obstructions or impassable terrain...
bool m_Pushing
Definition: CCmpUnitMotion.h:172
Definition: PathGoal.h:38
void clear()
Definition: CCmpUnitMotion.h:199
virtual fixed GetTurnRate() const =0
Returns the turn rate in radians per second.
constexpr u8 MAX_FAILED_MOVEMENTS
When we fail to move this many turns in a row, inform other components that the move will fail...
Definition: CCmpUnitMotion.h:106
constexpr entity_pos_t TARGET_UNCERTAINTY_MULTIPLIER
To avoid recomputing paths too often, have some leeway for target range checks based on our distance ...
Definition: CCmpUnitMotion.h:87
void Serialize(ISerializer &serialize) override
Definition: CCmpUnitMotion.h:356
ICmpPosition * cmpPosition
Definition: CCmpUnitMotionManager.h:53
WaypointPath m_ShortPath
Definition: CCmpUnitMotion.h:243
Definition: PathGoal.h:36
virtual bool IsPushingActivated() const =0
Sent by CCmpPathfinder after async path requests.
Definition: MessageTypes.h:479
SceneCollector & collector
Definition: MessageTypes.h:159
const CSimContext & GetSimContext() const
Definition: IComponent.h:58
fixed m_WalkSpeed
Definition: CCmpUnitMotion.h:167
CEntityHandle GetEntityHandle() const
Definition: IComponent.h:51
void RequestLongPath(const CFixedVector2D &from, const PathGoal &goal)
Start an asynchronous long path query.
Definition: CCmpUnitMotion.h:1786
Definition: MessageTypes.h:331
bool PossiblyAtDestination() const
Returns true if we are possibly at our destination.
Definition: CCmpUnitMotion.h:1113
virtual fixed DistanceBetweenShapes(const ObstructionSquare &source, const ObstructionSquare &target) const =0
Calculate the shortest straight line distance between the source and the target.
bool ShouldAlternatePathfinder() const
Definition: CCmpUnitMotion.h:712
bool ComputeTargetPosition(CFixedVector2D &out) const
Definition: CCmpUnitMotion.h:805
virtual entity_pos_t GetClearance(pass_class_t passClass) const =0
bool ToBool() const
Parses the content of this node as a boolean ("true" == true, anything else == false) ...
Definition: ParamNode.cpp:296
entity_pos_t maxdist
Definition: PathGoal.h:49
virtual bool IsMoveRequested() const =0
void ConstructSquareOnGround(const CSimContext &context, float x, float z, float w, float h, float a, SOverlayLine &overlay, bool floating, float heightOffset=0.25f)
Constructs overlay line as rectangle with given center and dimensions, conforming to terrain...
Definition: Render.cpp:151
entity_id_t GetGroup() const
Definition: CCmpUnitMotion.h:613
void SetSpeedMultiplier(fixed multiplier) override
Set the current movement speed.
Definition: CCmpUnitMotion.h:446
#define FALLTHROUGH
Definition: code_annotation.h:412
void FaceTowardsPointFromPos(const CFixedVector2D &pos, entity_pos_t x, entity_pos_t z)
Rotate to face towards the target point, given the current pos.
Definition: CCmpUnitMotion.h:1595
virtual bool GetObstructionSquare(ICmpObstructionManager::ObstructionSquare &out) const =0
Gets the square corresponding to this obstruction shape.
Definition: MessageTypes.h:330
Definition: CCmpUnitMotion.h:207
entity_pos_t ShortPathSearchRange() const
Definition: CCmpUnitMotion.h:722
Definition: Components.h:72
CFixedVector2D pos
Definition: CCmpUnitMotionManager.h:59
fixed X
Definition: FixedVector2D.h:27
void MoveObstructed()
Warns other components that our current movement was obstructed (i.e.
Definition: CCmpUnitMotion.h:678
entity_pos_t z
Definition: ICmpObstructionManager.h:68
void sincos_approx(CFixed_15_16 a, CFixed_15_16 &sin_out, CFixed_15_16 &cos_out)
Compute sin(a) and cos(a).
Definition: Fixed.cpp:187
void MoveSucceeded()
Warns other components that our current movement is likely over (i.e.
Definition: CCmpUnitMotion.h:661
fixed m_Speed
Definition: CCmpUnitMotion.h:228
bool ShouldCollideWithMovingUnits() const
Units in 'pushing' mode are marked as 'moving' in the obstruction manager.
Definition: CCmpUnitMotion.h:833
Definition: CCmpUnitMotion.h:206
fixed m_LastTurnSpeed
Definition: CCmpUnitMotion.h:231
float ToFloat() const
Convert to float. May be lossy - float can't represent all values.
Definition: Fixed.h:171
void Deinit() override
Definition: CCmpUnitMotion.h:315
u8 m_FailedMovements
Definition: CCmpUnitMotion.h:181
entity_pos_t x
Definition: Pathfinding.h:59
constexpr entity_pos_t SHORT_PATH_SEARCH_RANGE_INCREMENT
Definition: CCmpUnitMotion.h:63
bool IsZero() const
Definition: FixedVector2D.h:172
CFixed_15_16 atan2_approx(CFixed_15_16 y, CFixed_15_16 x)
Inaccurate approximation of atan2 over fixed-point numbers.
Definition: Fixed.cpp:147
fixed angle
Definition: CCmpUnitMotionManager.h:67
constexpr entity_pos_t SHORT_PATH_MAX_SEARCH_RANGE
Definition: CCmpUnitMotion.h:62
void MoveFailed()
Warns other components that our current movement will likely fail (e.g.
Definition: CCmpUnitMotion.h:644
Definition: CCmpUnitMotion.h:192
Definition: Components.h:73
static constexpr CFixed FromInt(int n)
Definition: Fixed.h:140
static float Length(const SVec3 v)
Definition: mikktspace.cpp:109
virtual void SetUnitClearance(const entity_pos_t &clearance)=0
const entity_id_t INVALID_ENTITY
Invalid entity ID.
Definition: Entity.h:35
Definition: CCmpUnitMotion.h:133
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
virtual void Submit(CPatch *patch)=0
Submit a terrain patch that is part of the scene.
fixed m_TemplateWalkSpeed
Definition: CCmpUnitMotion.h:158
constexpr entity_pos_t SHORT_PATH_LONG_WAYPOINT_RANGE
When using the short-pathfinder to rejoin a long-path waypoint, aim for a circle of this radius aroun...
Definition: CCmpUnitMotion.h:69
Definition: CCmpUnitMotion.h:204
constexpr u8 KNOWN_IMPERFECT_PATH_RESET_COUNTDOWN
When following a known imperfect path (i.e.
Definition: CCmpUnitMotion.h:96
virtual bool IsGoalReachable(entity_pos_t x0, entity_pos_t z0, const PathGoal &goal, pass_class_t passClass)=0
void OnValueModification()
Definition: CCmpUnitMotion.h:736
entity_pos_t z
Definition: PathGoal.h:43
CFixedVector2D u
Definition: ICmpObstructionManager.h:69
Standard representation for all types of shapes, for use with geometry processing code...
Definition: ICmpObstructionManager.h:66
constexpr CFixed Square() const
Multiply the value by itself.
Definition: Fixed.h:333
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Definition: ParamNode.cpp:253
std::wstring component
Definition: MessageTypes.h:509
Helper functions related to geometry algorithms.
std::vector< SOverlayLine > m_DebugOverlayLongPathLines
Definition: CCmpUnitMotion.h:151
bool wentStraight
Definition: CCmpUnitMotionManager.h:85
bool wasObstructed
Definition: CCmpUnitMotionManager.h:86
void SetFacePointAfterMove(bool facePointAfterMove) override
Set whether the unit will turn to face the target point after finishing moving.
Definition: CCmpUnitMotion.h:526
Deserialization interface; see serialization overview.
Definition: IDeserializer.h:34
External identifiers for shapes.
Definition: ICmpObstructionManager.h:77
CFixedVector2D v
Definition: ICmpObstructionManager.h:69
void DynamicSubscriptionNonsync(MessageTypeId mtid, IComponent *component, bool enabled)
Subscribe the given component instance to all messages of the given message type. ...
Definition: ComponentManager.cpp:577
bool IsMoveRequested() const override
Definition: CCmpUnitMotion.h:436