载入中...
搜索中...
未找到
HexSearch.cpp
浏览该文件的文档.
17 return Result<HexPath>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, message, "hexmap"));
121bool isValidDestination(const HexMap& map, HexCoordinates coordinates, const HexOccupancyQuery& occupied) {
131std::int32_t moveCost(const HexMap& map, HexCoordinates from, HexCoordinates to, HexDirection direction,
147Result<HexPath> findPath(const HexMap& map, HexSearchContext& scratch, HexCoordinates from, HexCoordinates to,
153 return pathInvalidArgument("search scratch must be resized to map.cellCount() before findPath");
154 if (!isValidDestination(map, to, occupied)) return unreachable("path goal is not a valid destination");
250Result<void> collectVisibleCells(const HexMap& map, HexSearchContext& scratch, HexCoordinates from,
253 if (map.empty()) return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "cannot collect visibility from an empty hex map", "hexmap"));
254 if (!map.contains(from)) return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "view origin is outside the hex map", "hexmap"));
256 return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument, "search scratch must be resized to map.cellCount() before collectVisibleCells", "hexmap"));
Stable, structured diagnostics shared by engine modules.
Cell-graph search used by pathfinding and visibility.
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
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
HexCoordinates coordinatesAt(std::int32_t index) const noexcept
Coordinates of a linear cell index; out-of-range indices return (0, 0).
Definition HexMap.cpp:69
std::int32_t indexOf(HexCoordinates coordinates) const noexcept
Linear cell index of coordinates (offset order), or -1 when outside the grid.
Definition HexMap.cpp:64
HexValues values(HexCoordinates c) const noexcept
Full packed value record of a cell (zero when outside the grid).
Definition HexMap.cpp:356
bool contains(HexCoordinates coordinates) const noexcept
Whether coordinates address a cell inside the grid.
Definition HexMap.h:122
bool getNeighbor(HexCoordinates coordinates, HexDirection direction, HexCoordinates &out) const noexcept
Neighbour of coordinates in direction; false when it is off-grid.
Definition HexMap.cpp:87
bool isExplorable(HexCoordinates c) const noexcept
Whether a cell may ever be revealed by a viewer.
Definition HexMap.cpp:352
bool isWalled(HexCoordinates c) const noexcept
Definition HexMap.cpp:344
HexFlags flags(HexCoordinates c) const noexcept
Full packed flag record of a cell (zero when outside the grid).
Definition HexMap.cpp:360
std::int32_t elevation(HexCoordinates c) const noexcept
Definition HexMap.cpp:300
const HexCellData * cell(HexCoordinates coordinates) const noexcept
Cell record, or null when outside the grid. @ownership Borrowed; the map owns the record....
Definition HexMap.cpp:79
std::int32_t urbanLevel(HexCoordinates c) const noexcept
Definition HexMap.cpp:312
std::int32_t plantLevel(HexCoordinates c) const noexcept
Definition HexMap.cpp:320
std::int32_t farmLevel(HexCoordinates c) const noexcept
Definition HexMap.cpp:316
Reusable search scratch: one record per cell plus a priority bucket queue.
Definition HexSearch.h:68
void resize(std::int32_t cellCount)
Sizes the scratch for cellCount cells, preserving nothing.
Definition HexSearch.cpp:40
HexSearchPop dequeue(std::int32_t &outCellIndex) noexcept
Removes the lowest-priority cell.
Definition HexSearch.cpp:83
void change(std::int32_t cellIndex, std::int32_t oldPriority) noexcept
Re-queues a cell whose priority changed after it was enqueued.
Definition HexSearch.cpp:114
std::int32_t beginPhase() noexcept
Starts a new search: clears the frontier and advances the phase.
Definition HexSearch.cpp:60
HexSearchData & data(std::int32_t cellIndex) noexcept
Mutable record of one cell.
Definition HexSearch.cpp:50
void enqueue(std::int32_t cellIndex) noexcept
Adds a cell at its current priority.
Definition HexSearch.cpp:70
std::int32_t cellCount() const noexcept
Number of cells this context can hold.
Definition HexSearch.h:80
constexpr std::int32_t viewElevation() const noexcept
Elevation used for line of sight: the higher of land and water.
Definition HexCell.h:70
Definition HexCell.h:9
constexpr bool canHoldUnit(const HexCellData &cell) noexcept
Whether a cell record is in a state that can hold a unit.
Definition HexCell.h:261
std::int32_t moveCost(const HexMap &map, HexCoordinates from, HexCoordinates to, HexDirection direction, const HexOccupancyQuery &occupied)
Cost of moving between two adjacent cells.
Definition HexSearch.cpp:131
constexpr std::int32_t kHexDirectionCount
Number of hex edges / facing directions.
Definition HexMetrics.h:62
constexpr HexEdgeType edgeType(int elevation1, int elevation2) noexcept
The relationship between two elevations (single-step changes are slopes).
Definition HexMetrics.h:96
HexEdgeType
Relationship between two neighbouring cells of different elevation.
Definition HexMetrics.h:93
std::function< bool(HexCoordinates)> HexOccupancyQuery
Predicate answering whether a cell is already occupied by another actor.
Definition HexSearch.h:143
bool isValidDestination(const HexMap &map, HexCoordinates coordinates, const HexOccupancyQuery &occupied)
Whether an actor may occupy a cell.
Definition HexSearch.cpp:121
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
Result< HexPath > findPath(const HexMap &map, HexSearchContext &scratch, HexCoordinates from, HexCoordinates to, const HexMoveRules &rules, const HexOccupancyQuery &occupied)
Finds the cheapest path between two cells.
Definition HexSearch.cpp:147
Result< void > collectVisibleCells(const HexMap &map, HexSearchContext &scratch, HexCoordinates from, std::int32_t range, std::vector< std::int32_t > &out)
Collects every cell visible from from within range.
Definition HexSearch.cpp:250
@ InvalidArgument
@ NotFound
One cell of the hex map: packed values plus packed flags.
Definition HexCell.h:244
Movement tuning of one actor; cells per turn and vision radius in cells.
Definition HexSearch.h:130
One found path: the cells from origin to goal, with the turn each one is reached on.
Definition HexSearch.h:178
std::int32_t priority() const noexcept
Ordering key of the priority queue (distance + heuristic).
Definition HexSearch.h:36
std::int32_t distance
Shortest distance from the search origin found so far.
Definition HexSearch.h:25
std::int32_t searchPhase
Phase this record was written in; a record from an older phase is unvisited.
Definition HexSearch.h:31
std::int32_t heuristic
Remaining-distance estimate towards the search goal (0 for blind searches).
Definition HexSearch.h:29