M4: Bot navigation

NavGrid is the map bots plan on: a point per 2 m terrain sample, solid on cliffs and
where solids stand between step and head height, and costlier where the water is
deeper than wading. Path search uses Godot's AStarGrid2D. The grid syncs every tick:
new solids (walls, pieces) block points at once, removed ones are found by a rolling
scan, and points turn wet as the tide and flood reach them. Each change is stamped
with its tick.

NavBot follows a path with ordinary PlayerCommands: it steers at waypoints, sprints
on long dry stretches, jumps when stalled, and marks a point blocked after repeated
stalls. Every half second it checks its remaining path against the change stamps and
plans again if water or a wall now crosses it. One path is planned per server tick
across all bots.

The server builds the grid while the lobby waits and its bots now roam between
random reachable places, replacing the placeholder wander bot.

Tests: 150 of 150 random reachable targets reached on 50 islands in the sweep; the
test runs 2 per island and needs 95%. New walls and rising water both cause a new
path around them; a broken wall opens the grid again; with no dry way round, the bot
swims. 23 roaming bots on an island: p99 tick 1.6 ms against the 12 ms budget.

Closes #27

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 23:38:36 -05:00
co-authored by Claude Opus 5.5
parent 6e1c87fe32
commit cc652de46e
14 changed files with 863 additions and 39 deletions
+20
View File
@@ -203,6 +203,26 @@ const TIDE_SUDDEN_DEATH_DPS: int = 5
## line up with cell edges.
const FLOOD_CELL_METRES: float = 4.0
# Bot navigation. Bots path over a grid of terrain samples and steer along it with the
# same commands players send.
## Spacing of the navigation grid, in metres. Matches the terrain heightfield.
const BOT_NAV_CELL_METRES: float = 2.0
## Neighbouring nav points further apart in height than this are a cliff, not a slope.
const BOT_NAV_MAX_RISE: float = 1.9
## Path cost multiplier for water too deep to wade: bots swim only when they must.
const BOT_NAV_WATER_WEIGHT: float = 8.0
## Most paths the shared grid plans in one server tick; other requests wait their turn.
const BOT_NAV_PATHS_PER_TICK: int = 1
## A bot moves on to the next waypoint within this horizontal distance of it.
const BOT_WAYPOINT_RADIUS: float = 1.3
## A bot that gains less than this toward its waypoint in BOT_STUCK_TICKS jumps, and
## after BOT_STUCK_REPATHS tries it marks the waypoint blocked and plans again.
const BOT_STUCK_PROGRESS: float = 0.5
const BOT_STUCK_TICKS: int = 20
const BOT_STUCK_REPATHS: int = 3
## Each bot re-checks its remaining path against grid changes this often, in ticks.
const BOT_PATH_CHECK_TICKS: int = 15
# Building
const GRID_CELL_METRES: float = 4.0
## The most of each material a player can carry.