OpenBF1942-Plus
Refractor 1, rebuilt from scratch
Loading...
Searching...
No Matches
nav.h
Go to the documentation of this file.
1// AI navigation: level-0 path-finding maps (<Map>/Pathfinding/<name>level0map.raw) and A* on a coarse grid.
2// Spec: docs/formats/pathfinding.md; reference: tools/pathfinding.py
3#pragma once
4#include <cstdint>
5#include <vector>
6
7namespace obf {
8
9struct NavGrid {
10 int n = 0; // cells per side
11 float cell = 1; // metres per cell
12 std::vector<uint8_t> blocked; // n * n, row = z, column = x
13 bool at(int x, int z) const { return x < 0 || z < 0 || x >= n || z >= n || blocked[static_cast<size_t>(z) * n + x]; }
14};
15
16// Level-0 map -> one cell per map cell (world_size / cells metres). Throws std::runtime_error on bad data.
17NavGrid nav_parse(const std::vector<uint8_t>& data, float world_size);
18// Coarser grid: a cell is blocked when more than half of its factor x factor source cells are.
19NavGrid nav_coarse(const NavGrid& g, int factor);
20// Path from a to b (x, z in metres) through free cells: A* with 8 neighbours (no corner cutting), then shortened to
21// the waypoints a straight walk cannot skip. Empty if no path; the start and goal snap to the nearest free cell.
22std::vector<float> nav_path(const NavGrid& g, float ax, float az, float bx, float bz, int max_expand = 200000);
23
24} // namespace obf
Definition anim.cpp:7
NavGrid nav_parse(const std::vector< uint8_t > &d, float world_size)
Definition nav.cpp:11
NavGrid nav_coarse(const NavGrid &g, int f)
Definition nav.cpp:49
std::vector< float > nav_path(const NavGrid &g, float ax, float az, float bx, float bz, int max_expand)
Definition nav.cpp:90
Definition nav.h:9
int n
Definition nav.h:10
std::vector< uint8_t > blocked
Definition nav.h:12
bool at(int x, int z) const
Definition nav.h:13
float cell
Definition nav.h:11