载入中...
搜索中...
未找到
PathfinderCombatNavigation.cpp
浏览该文件的文档.
2
3#include "map/Path.h"
4#include "map/Pathfinder.h"
5
6#include <cmath>
7#include <limits>
8#include <utility>
9
11namespace {
12
13bool finite(CombatVector2 value) { return std::isfinite(value.x) && std::isfinite(value.z); }
14
15double length(CombatVector2 value) { return std::hypot(value.x, value.z); }
16
18 const double magnitude = length(value);
19 return magnitude > 0.0 ? CombatVector2{value.x / magnitude, value.z / magnitude} : CombatVector2{};
20}
21
22Result<int> worldToCell(double coordinate, double origin, double cellSize, std::string path) {
23 const double projected = std::floor((coordinate - origin) / cellSize);
24 if (!std::isfinite(projected) || projected < static_cast<double>(std::numeric_limits<int>::min()) ||
25 projected > static_cast<double>(std::numeric_limits<int>::max()))
27 "navigation coordinate is outside grid range", path));
28 return Result<int>::success(static_cast<int>(projected));
29}
30
31} // namespace
32
34 if (!finite(origin) || !std::isfinite(cellSize) || cellSize <= 0.0)
36 "combat navigation grid projection is invalid", "config"));
37 return Result<void>::success();
38}
39
40PathfinderCombatNavigationProvider::PathfinderCombatNavigationProvider(
41 map::Pathfinder& pathfinder, PathfinderCombatNavigationConfig config) noexcept
42 : pathfinder_(pathfinder), config_(config) {}
43
53
56 (void)tick;
57 if (!finite(state.position) || !finite(goal.position) || !std::isfinite(goal.acceptanceRadius) ||
58 goal.acceptanceRadius < 0.0)
60 Diagnostic::error(DiagnosticCode::InvalidArgument, "combat navigation request is invalid", "navigation"));
61
62 const CombatVector2 goalDelta{goal.position.x - state.position.x,
63 goal.position.z - state.position.z};
64 if (length(goalDelta) <= goal.acceptanceRadius)
67
68 auto startX = worldToCell(state.position.x, config_.origin.x, config_.cellSize, "state.position.x");
69 if (!startX) return Result<CombatNavigationSteering>::failure(startX.status());
70 auto startY = worldToCell(state.position.z, config_.origin.z, config_.cellSize, "state.position.z");
71 if (!startY) return Result<CombatNavigationSteering>::failure(startY.status());
72 auto goalX = worldToCell(goal.position.x, config_.origin.x, config_.cellSize, "goal.position.x");
73 if (!goalX) return Result<CombatNavigationSteering>::failure(goalX.status());
74 auto goalY = worldToCell(goal.position.z, config_.origin.z, config_.cellSize, "goal.position.z");
75 if (!goalY) return Result<CombatNavigationSteering>::failure(goalY.status());
76
77 std::unique_ptr<map::Path> path(pathfinder_.get().findPath(startX.value(), startY.value(),
78 goalX.value(), goalY.value()));
79 if (!path || path->empty())
81 DiagnosticCode::NotFound, "combat navigation goal is unreachable", state.subject.format()));
82
83 CombatVector2 waypoint = goal.position;
84 if (path->getLength() > 1) {
85 waypoint.x = config_.origin.x + (static_cast<double>(path->getX(1)) + 0.5) * config_.cellSize;
86 waypoint.z = config_.origin.z + (static_cast<double>(path->getY(1)) + 0.5) * config_.cellSize;
87 }
90 normalized({waypoint.x - state.position.x, waypoint.z - state.position.z}), 1.0});
91}
92
93} // namespace eve::combat::navigation
double value
Vec3 projected
Definition CaveMesh.cpp:122
float length
Definition CaveMesh.cpp:94
bool valid
bool finite
Map Pathfinder steering adapter for combat locomotion.
std::string path
Definition PlayHost.cpp:110
V3 origin
Definition RoadBake.cpp:138
SimulationTick tick
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Synchronous combat steering provider backed by the canonical map Pathfinder.
Result< CombatNavigationSteering > steer(const CombatLocomotionState &state, const CombatNavigationGoal &goal, SimulationTick tick) override
Resolve steering for one subject without mutating locomotion state.
static Result< std::unique_ptr< PathfinderCombatNavigationProvider > > create(map::Pathfinder &pathfinder, PathfinderCombatNavigationConfig config)
Validate configuration and create an owning adapter.
Pathfinding facade. Single-agent: A*. Group (same goal): Flow Field + follow. Grid/topology internals...
Definition Pathfinder.h:20
Owning read-only projection of one registered combat subject.
Owning navigation goal retained by the locomotion authority.
Finite position or direction in the horizontal combat plane.
World/grid projection used by the map-backed combat navigation provider.
Result< void > validate() const
Reject non-finite coordinates and non-positive cell size.