Skip to content

kelindar backend

The golem.nav/kelindar backend exposes several features that go beyond basic pathfinding. They are available when you hold the concrete *navkelindar.Backend reference—the same value you passed to SetNavBackend.

var nav *navkelindar.Backend
nav, err = navkelindar.NewFromTiledLayer(...)
srv.SetNavBackend(nav)

Find every cell reachable within a movement budget. Useful for spawn-point searches, highlighting tiles a unit can reach in one turn, or NPC line-of-sight approximations:

nav.Around(npc.X, npc.Y, 5, nil, func(p golem.NavPoint) {
// p is the world-space centre of each reachable cell within 5 cells
})

The third argument is the radius in cells. Passing nil for costOf reuses the same cost function as FindPath. Pass a custom function to apply a different cost model for the scan without affecting normal pathfinding:

nav.Around(npc.X, npc.Y, 3, func(col, row int) uint16 {
// treat water as unreachable for this scan only
if myMap.IsWater(col, row) {
return 0
}
return 1
}, func(p golem.NavPoint) {
spawnCandidates = append(spawnCandidates, p)
})

WriteValue and ReadValue — runtime terrain changes

Section titled “WriteValue and ReadValue — runtime terrain changes”

Change a cell’s terrain kind at any time; the next FindPath or Around call picks it up automatically:

// Turn a road tile into rubble (higher cost) after an explosion.
nav.WriteValue(explosionX, explosionY, 8)
// Restore it.
nav.WriteValue(explosionX, explosionY, 1)
// Read the current value.
v, ok := nav.ReadValue(x, y)

Value 0 is always impassable. Any other value is the traversal cost used by A* and Around. This complements srv.SetNavWalkable—use SetNavWalkable for simple on/off doors and WriteValue when you need graduated costs (e.g. rubble, mud, fire).

Grid() returns the underlying *tile.Grid for features not individually wrapped by the backend:

  • Within — iterate all tiles inside a bounding box
  • NewView — reactive observer: get notified whenever tiles change (useful for clients that need a live minimap or fog-of-war updates)
  • WriteTo / ReadFrom — save and restore the full grid state for persistence or hot-reload
  • MaskAt / MergeAt — atomic bit-level tile updates when multiple systems share the same grid
grid := nav.Grid()
grid.Within(tile.At(x0, y0), tile.At(x1, y1), func(p tile.Point, t tile.Tile) {
// inspect every tile in the bounding box
})

See the kelindar/tile README for the full API.

See also: Backends & wiring, NavAgent.