载入中...
搜索中...
未找到
RTSSystemMovementInternal.h
浏览该文件的文档.
1#pragma once
2
3// Private shared movement helpers; no independent state or provider lookup.
4#include <algorithm>
5#include <cmath>
6#include <optional>
7#include "rts/RTSSystems.h"
8
10
12float visibleHostileThreatAt(Faction& viewer, WorldPosition point);
13
14// Conservative swept-radius query against the canonical navigation grid.
15// Oversized/invalid queries return false and retain ordinary path steering.
16EVENGINE_API_DOMAINS bool isFormationSegmentClear(const map::Pathfinder& pathfinder, const NavigationGrid& grid,
17 WorldPosition from, WorldPosition to, float radius);
18
19inline bool isFinitePosition(WorldPosition position) { return std::isfinite(position.x) && std::isfinite(position.y); }
20
21inline bool isSameHandle(const ecs::EntityHandle& left, const ecs::EntityHandle& right) {
22 return left.table == right.table && left.type == right.type && left.id == right.id &&
23 left.generation == right.generation;
24}
25
26
27inline float distanceSquared(float ax, float ay, float bx, float by) {
28 const float dx = ax - bx;
29 const float dy = ay - by;
30 return dx * dx + dy * dy;
31}
32
35 return unit.crowd()->link.isBound() &&
37 order.kind == OrderKind::Escort || order.kind == OrderKind::Patrol) &&
38 !unit.navigation()->trafficRecoveryTarget;
39}
40
43 return isSharedFlowNavigationOrder(unit, order) && !unit.navigation()->formationTarget &&
44 !unit.navigation()->combatSlotTarget;
45}
46
48 switch (kind) {
49 case OrderKind::Move:
62 case OrderKind::SupplyRelay: return true;
63 default: return false;
64 }
65}
66
71
72// Service contact is based on occupied geometry, not exact overlap of agent centers.
73// The radius is derived from canonical node membership/building footprint and is
74// recomputed synchronously; no second range state or persistent format is created.
76 float radius = unit.motion()->arrivalRadius;
77 if (order.kind == OrderKind::Gather) {
78 if (auto* node = dynamic_cast<ResourceNode*>(ecs::try_get(order.targetEntity))) {
79 const float workers = static_cast<float>(std::max<std::size_t>(1, node->harvest()->workers.size()));
80 radius = std::max(radius, unit.crowd()->radius * 2.0f * std::sqrt(workers));
81 }
82 } else if (isInteractionOrder(order.kind)) {
83 if (auto* building = dynamic_cast<Building*>(ecs::try_get(order.targetEntity)))
84 radius = std::max(radius, building->dropoff()->radius + unit.crowd()->radius);
85 }
86 return radius;
87}
88
89inline std::optional<WorldPosition> entityPosition(const ecs::EntityHandle& handle) {
90 if (auto* unit = dynamic_cast<Unit*>(ecs::try_get(handle)))
91 return WorldPosition{unit->motion()->x, unit->motion()->y};
92 if (auto* building = dynamic_cast<Building*>(ecs::try_get(handle)))
93 return WorldPosition{building->placement()->worldX, building->placement()->worldY};
94 return std::nullopt;
95}
96
101 WorldPosition goal = order.target;
103 if (auto target = entityPosition(order.targetEntity)) goal = *target;
104 if (order.kind == OrderKind::SupplyRelay && unit.supply()->rendezvousActive)
105 goal = unit.supply()->rendezvousPoint;
106 } else if (order.kind == OrderKind::Escort && unit.tactics()->guardSet) {
107 goal = {unit.tactics()->guardX, unit.tactics()->guardY};
108 } else if (order.kind == OrderKind::Patrol && unit.navigation()->patrolInitialized &&
109 !unit.navigation()->patrolTowardTarget) {
110 goal = unit.navigation()->patrolOrigin;
111 }
112 return goal;
113}
114
116 auto current = orders.current();
117 if (current) return Result<std::optional<OrderRecord>>::success(std::move(current).takeValue());
118 if (current.code() == StatusCode::NotFound) {
119 current.ignore("RTS entity has no active order");
121 }
122 return Result<std::optional<OrderRecord>>::failure(current.status());
123}
124
125} // namespace eve::rts::systems_internal
LogicalId target
#define EVENGINE_API_DOMAINS
Definition Export.h:110
HexVec3 left
HexVec3 right
std::array< float, 3 > position
std::string to
std::string from
double radius
Definition MeleeHit.cpp:42
std::vector< std::int32_t > order
glm::dvec3 dx
PrimitiveHandle handle
Deterministic phase-one RTS systems and their ECS contracts.
const RoadNode * node
std::string kind
double current
float dy
Definition Shadow.cpp:151
TacticalUnit * unit
glm::vec3 point
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.cpp:19
RTS building domain root with placement and production composition.
Definition RTSTypes.h:852
Generic orders component adapter; the queue remains the sole order owner.
Definition RTSTypes.h:390
Result< OrderRecord > current() const
Project the active order or return NotFound when idle.
Definition RTSTypes.cpp:420
Harvestable RTS resource node; deposited balances are owned by an external resource account.
Definition RTSTypes.h:1085
RTS unit domain root.
Definition RTSTypes.h:501
WorldPosition movementGoal(Unit &unit, const OrderRecord &order)
Resolve the current canonical movement goal without retaining entity pointers. @ownership Returns a w...
float visibleHostileThreatAt(Faction &viewer, WorldPosition point)
Observe visible hostile weapon threat at a world point using canonical faction intelligence.
float interactionArrivalRadius(Unit &unit, const OrderRecord &order)
float distanceSquared(float ax, float ay, float bx, float by)
Result< std::optional< OrderRecord > > readCurrent(OrderComponent &orders)
bool isSameHandle(const ecs::EntityHandle &left, const ecs::EntityHandle &right)
std::optional< WorldPosition > entityPosition(const ecs::EntityHandle &handle)
bool isSharedFlowOrder(Unit &unit, const OrderRecord &order)
Whether motion uses a shared field instead of a radius-clear moving slot.
bool isFinitePosition(WorldPosition position)
EVENGINE_API_DOMAINS bool isFormationSegmentClear(const map::Pathfinder &pathfinder, const NavigationGrid &grid, WorldPosition from, WorldPosition to, float radius)
bool isSharedFlowNavigationOrder(Unit &unit, const OrderRecord &order)
Whether planning uses the shared policy, before the current group projection exists.
OrderKind
Commands shared by movement, combat, construction and gathering.
Definition RTSTypes.h:69
Owning projection of the active generic order used by RTS systems.
Definition RTSTypes.h:122
Two-dimensional deterministic RTS world position.
Definition RTSTypes.h:53