Log inGet started
World

High Ground: Tactics Battle Maps with Cover, Ramps and Chokepoints

README.md

battleMapsKit — tactics battle maps with high ground, cover and chokepoints

Battle maps for turn-based grid tactics games. Eight hand-designed, fair (point-mirrored) boards with raised ground reached by ramps or stairs, half and full cover, and chokepoints — bridges over rivers, a one-plank-wide bridge with slow flank fords, gates in walls, knife-edge ridges, rope bridges over a chasm, a hilltop monastery — each dressable as seven different places, plus a seeded map generator that makes as many more fair boards as you want. One call gives you the map data; one more draws it as a painted diorama on every peer.

Version 1.1.0 (require("battleMapsKit.api").VERSION). This package was called battleMaps up to 1.0.3; it is the same published asset under a new name (see Upgrading from battleMaps).

  • Map data stays tacticsKit-compatible (cols, rows, cellSize, cover with kind/q/r/rot/prop, spawns, objective), plus heights, blocked, bridges, fords, chokepoints.
  • Switching place or layout is one change: BM.get(layout, setting).
  • Seeded generator: BM.generate({ seed, setting, cols, rows, levels, chokepoint }) — same seed, same map on every peer; every answer passes BM.check and BM.isMirrored.
  • Runtime builder: draws the board from a module or component in play, deterministic, so every peer sees the same board. quality = "low" for phones and tablets.
  • Helpers: the movement rule, reach, path (optionally weighted: fords cost 2), check (validation), lighting suggestions.
  • No dependencies.

Quick start

local BM = require("battleMapsKit.api")

local map = BM.get("bridge", "snowPass")          -- a fresh map table
assert(BM.check(map))                              -- valid: walkable, fair, cover placed legally

local holder = entity.spawn("board", { temporary = true })
local board = BM.build(holder, map, { quality = "high" })   -- draw it here
BM.applyLighting(holder, "snowPass")              -- optional: the setting's sky, sun and fog

print(map.name, #map.cover, board.cellTop(6, 5))  -- "Old Bridge (Snowy Mountain Pass)" 20 0
board.setCoverAlive(3, false)                      -- piece 3 is blown up: hidden, rubble shown

-- a generated board: same options, same map on every peer
local gen = BM.generate({ seed = 42, setting = "monastery", chokepoint = "bridge", rows = 13 })
print(gen.name)                                    -- "Narrow Bridge Crossing #42 (Ruined Hill Monastery)"

Or with no code: add the BattleMap component (battleMapsKit.BattleMap) to an entity and pick layout and setting in its fields (layout = "generated" with seed, chokepoint, levels, cols, rows for a generated board; picker = true shows buttons to cycle them; defines = "myMaps" for a layout or setting of your own; ref:board() and ref:map() read back what it drew).

Layouts x settings

Every layout works in every setting (56 maps, all checked by the test suite).

layoutnamesizelevelschokepoints
bridgeOld Bridge14 x 120-2Old Bridge (2 wide, objective), North and South Footbridges
gateBroken Gate14 x 120-2West Gate, East Gate, North Breach, South Breach into a walled courtyard
terracesTerraced Hill14 x 140-3West and East Summit Stairs to the summit objective
twinHillsTwin Hills14 x 120-2North and South Ridge (1-wide), West and East Saddle Ramps
crossroadsMarket Crossroads16 x 120-2four 1-cell stall gaps into the market square, two canal bridges
canyonSpire Canyon16 x 120-2West and East Rope Bridges to the spire, North and South Pass
monasteryHill Monastery14 x 140-3a central hill: garden stairs to the cloister terrace, stairs to the bell tower ring, one stair a side to the summit objective
narrowBridgeNarrow Bridge14 x 130-2Narrow Bridge: a 4-long, 1-wide bridge over a deep river, the only quick crossing (objective); North and South Fords at the far flanks are slow (cost 2) and open

All have 6 spawns a side (west and east), an objective zone, ramps or stairs to every raised area, and 20-26 cover pieces mixing half and full cover. On narrowBridge the shortest walk between the armies goes over the bridge, one cell wide: BM.path crosses on its deck cells and the test suite checks it.

settingplacerampspropscover props (half / full)light
ruinsJungle Ruinsstone stairs11broken column, rubble heap, offering urns, fallen column, altar slab, crouching jaguar statue / crumbling temple wall, standing column, toppled idol head, serpent stele, vine-choked archwaywarm afternoon
snowPassSnowy Mountain Passpacked-snow ramps12ice boulder, spruce stump, broken sled, frozen supply sled, snowy log pile, frozen ore cart, avalanche debris / snowbank wall, stone cairn, ice spire, frozen icefall, prayer-flag windbreakpink dawn
riverVillageRiver Villagetimber stairs11haystack, village well, cider barrels, hand cart, woodpile lean-to, pump and water trough / dry-stone wall, market crate stack, thatched cottage, awning market stall, stone dovecotebright noon
forestMisty Forestdirt ramps11mossy boulder, mushroom stump, bramble thicket, fallen log, fern bank, woodcutter's stack / log palisade, split giant trunk, mossy outcrop, upturned root wall, hunters' blindmisty morning
desertDesert Oasissandstone stairs11clay pots, draped trade crates, half-buried rock, caravan wagon, camel saddle packs, sandstone cistern / mudbrick wall, sandstone hoodoo, layered mesa rock, broken obelisk, nomad tentgolden sunset
outpostFrontier Outpost (sci-fi)hazard-striped metal ramps11cargo crates, fuel drums, jersey barriers, supply lockers, knocked-out sentry turret / barrier panels, antenna pylon, coolant tank, fusion generator, crashed drop pod, hard-light shield emitternight, floodlamps
monasteryRuined Hill Monasterylimestone stairs11leaning headstones, fallen bronze bell, cloister wellhead, monks' beehives, terraced herb bed, abbot's sarcophagus / cloister wall, broken cloister arch, bell tower stump, wayside shrine, cypress planterlilac storm-light, mid-afternoon

Every prop of every setting is placed somewhere by the shipped layouts (the prop rotation continues from one layout to the next; the test suite checks it). The monastery surround has cypresses, olive trees, lavender and roofless chapel ruins; its raised ground is paved in limestone flags.

The seeded generator

local map = BM.generate({
	seed = 42,              -- number or string; same options = same map on every peer
	setting = "forest",     -- any setting id (default "ruins")
	cols = 14, rows = 13,   -- 12-20 (even) x 10-16 (default 14 x 12)
	levels = 2,             -- highest ground, 1-3 (default 2)
	chokepoint = "bridge",  -- "bridge" | "gate" | "pass" | "random" (default: picked from the seed)
	cover = 12,             -- optional: west-side cover pieces to place (default 10-13)
	fords = true,           -- bridge only: flank fords on an odd row count (default true)
	chasm = nil,            -- bridge only: true = a chasm, false = a river, nil = seed decides (30% chasm)
})
  • bridge: a river (or chasm) down the middle. On an odd row count one central bridge, one cell wide, is the only quick crossing, with slow fords at the far flanks; on an even count two 1-wide bridges. Terraced hills on each bank.
  • gate: a walled courtyard on a mound; a stair gate in each side wall (and sometimes a breach), a dais on top when levels >= 2.
  • pass: a rock ridge down the middle cut by a narrow pass (one cell on an odd row count); the ridge tops are reached by ramps from shoulders.

The answer is a map in the same format as BM.get, plus seed, chokepoint and generated (the options used); its id is gen_<chokepoint>_<seed>_<cols>x<rows>_<setting> and layout is "generated". It is point-mirrored, has raised ground reached by ramps or stairs, half and full cover (more of it near the chokepoints), six spawns a side and an objective at the chokepoint; it always passes BM.check and BM.isMirrored (a candidate that fails is thrown away and the next attempt tried; the suite checks 600 seeds across sizes, levels and chokepoints). Only a seeded generator decides it, so peers that pass the same options draw the same board.

The map data format

BM.get(layoutId, settingId) returns a new table each call:

fieldmeaning
id"<layout>_<setting>"
name, blurbdisplay name and an evocative one-liner
layout, setting, layoutName, settingNamewhere it came from
cols, rowsgrid size; cells are q = 0..cols-1, r = 0..rows-1
cellSize2 (metres)
levelHeight1.0 (metres per level)
holdTurns3
maxLevelhighest level on the map
heightsheights[r+1][q+1]: an integer is flat ground at that level; X.5 is a ramp / stairs cell between level X and X+1
blocked{ {q=,r=}, ... } impassable but see-through cells (water or chasm); their height reads 0
water, chasmthe blocked cells split by what they are
bridges{ {q=,r=}, ... } walkable deck cells drawn over water or a chasm
fords{ {q=,r=}, ... } walkable shallow water at level 0 with stepping stones; BM.moveCost answers 2 for them
cover{ kind, q, r, rot, prop, variant, scale, yaw }; kind is tacticsKit's: wall (1 cell, full), wall2/wall3 (2/3 cells along +q, full), block (2x2, full), low (1 cell, half), low2 (2 cells along +q, half). rot n turns the footprint 90° n times, (dq,dr) -> (-dr,dq) per step (the same as tacticsKit Maps.cells). prop is the setting's prop id. Full cover is about 1.6 m, half about 0.8 m.
spawns{ west = 6 x {q,r}, east = 6 x {q,r} } as a two-entry list; entry i of each side are mirror twins
objective{ cells = { {q,r}, ... } }
chokepoints{ {q=, r=, name="Old Bridge", kind=?}, ... } (kind is "bridge", "ford", "gate" or "pass" where the layout says)

The movement rule

Two orthogonally adjacent cells connect when neither is blocked and |h1 − h2| ≤ 0.5. So a ramp cell (X.5) links level X and level X+1, and a step of 1 or more is a cliff. Cover is not part of the rule (your game decides whether units pass through it); reach and path treat cover cells as solid unless ignoreCover = true. Entering a ford costs 2 movement points (BM.moveCost); reach and path count steps unless weighted = true, when they count movement points.

API (require("battleMapsKit.api"))

calldoes
BM.SETTINGS, BM.LAYOUTSid lists
BM.get(layout, setting)a fresh map definition
BM.generate(opts)a seeded, generated map (above)
BM.all()every { layout, setting } pair
BM.check(map) -> ok, erron the board, no cover on cover / spawns / ramps / blocked / objective cells, every ramp joins its two levels, every spawn walks to the objective and the enemy spawns, every open cell (every raised area) reachable
BM.isMirrored(map) -> ok, errpoint-mirror fairness check (heights, blocked cells, fords, cover heights, spawn counts)
BM.heightAt(map,q,r), BM.isRamp, BM.isBlocked, BM.isBridge, BM.isFord, BM.onBoard, BM.surfaceYqueries
BM.canStep(map,q1,r1,q2,r2)the movement rule
BM.moveCost(map,q,r)movement points to enter a cell: 2 for a ford, else 1
BM.reach(map,q,r,{maxSteps,ignoreCover,occupied,weighted}) -> {["q,r"]=cost}flood fill
BM.path(map,aq,ar,bq,br,{ignoreCover,weighted}) -> {{q,r},...}?shortest (or cheapest) walk
BM.rampDir(map,q,r) -> dq,drwhich way a ramp climbs
BM.cells(cover), BM.FOOTPRINTS, BM.FULLcover footprints
BM.propsFor(setting, kind), BM.setting(id), BM.layout(id)catalogue
BM.defineLayout(id, def), BM.defineSetting(id, def, base?)add your own (see the layouts module README for the half-grid format)
BM.expand(def, id, setting, propSeed?)expand a half-grid layout table into a map without registering it
BM.lightingFor(setting){ timeOfDay, sunColor, sunIntensity, fogColor, fogDensity, ambient, sunDirection, zenith, horizon, lamps }
BM.applyLighting(parent, setting, opts) -> { root, destroy }spawns that sky, sun, ambient and fog (opts fog = false, ambientScale)
BM.build(parent, map, opts) -> handledraws the board (below)

BM.build(parent, map, opts)

opts: cellToLocal = function(q, r) -> (x, z) (default x = (q-(cols-1)/2)*cellSize, z = (r-(rows-1)/2)*cellSize, any affine grid works), quality = "high" | "low", drawCover = true | false, temporary = true (default) , y (base height), name.

The handle: root (entity), cover = { [coverIndex] = entity } (each piece its own entity standing on its cell top), setCoverAlive(i, alive) (hides a destroyed piece and shows rubble), isCoverAlive(i), cellTop(q, r) -> local y, cellCenter(q, r) -> x, y, z, stats (triangles, terrainDraws, lights), destroy().

What it draws: cell tops at heights * levelHeight (grass, snow, sand, flagstones or deck plates per setting, with a faint checker so the grid reads), cliff faces with strata and a ground lip, ramps or stairs climbing toward the higher neighbour, water with lily pads / ice floes or a deep chasm under blocked cells (rivers and rifts run on off the board), fords as shallow water over a pebble bed with stepping stones, bridges (stone, timber, metal, or rope over a chasm), the cover props, and a surround of the setting's land (trees, ruins, cottages, palms, domes, lamps, cypresses and chapel ruins...) cut out as a diorama plinth. Terrain is a few merged, vertex-coloured meshes (about 2-6 draws); a high-quality board is about 17-30k triangles and builds in under 0.2 s; low drops ground detail, most scenery and extra lights.

Multiplayer: build is deterministic from the map data, so give every peer the same layout/setting (or the same generator options) — the BattleMap component's fields sync; for a layout or setting of your own set its defines field to the module that defines it, so every peer requires it — and each draws the same board locally with temporary entities.

What is in the package

partwhat
battleMapsKit.apithe API above
battleMapsKit.layoutsthe eight layouts as data
battleMapsKit.settingsthe seven settings: palettes, materials, props, scatter, lighting
battleMapsKit.propsevery cover prop and scenery piece, modelled in code
battleMapsKit.generatethe seeded map generator behind BM.generate
battleMapsKit.boardthe runtime builder and the lighting helper
battleMapsKit.geoflat-shaded vertex-coloured mesh builder
battleMapsKit.BattleMap componenta board on an entity, with an optional layout/setting picker and generated boards
battleMapsKit test suite17 tests: all 56 maps valid and fair, every prop used, the narrow bridge, the monastery, 600 generated maps valid, fair and deterministic, rule, helpers, component, runtime build
guides"How to add battle maps with high ground, cover and chokepoints to a tactics game" (with the map generator), "Example: build a snowy mountain pass skirmish map with a bridge chokepoint"

Using it with tacticsKit

The map tables carry every field tacticsKit's Maps.define reads. Cover prop ids name battleMapsKit props, so draw the board with BM.build(..., { cellToLocal = <your grid's cell centre> }) and keep tacticsKit's own cover drawing off, or pass drawCover = false and let your game draw cover. When a blast destroys half cover, call board.setCoverAlive(i, false). Fords are ordinary walkable level-0 cells to tacticsKit; charge BM.moveCost if your game counts movement points.

Upgrading from battleMaps

1.1.0 renames the package from battleMaps to battleMapsKit. It is the same ZeroMind asset (same guid), so updating the install brings the new name. Change your requires and component names:

before (1.0.x)now (1.1.0)
require("battleMaps.api")require("battleMapsKit.api")
require("battleMaps.layouts") / .settings / .props / .board / .georequire("battleMapsKit.layouts") / .settings / .props / .board / .geo
component battleMaps.BattleMapbattleMapsKit.BattleMap ("BattleMap" still works where the name is unambiguous)

The API, the map data format and every existing layout and setting are unchanged; existing maps keep their shape, spawns and cover cells (some pieces are now dressed with one of the new props).

Changelog

  • 1.1.0 — renamed battleMaps -> battleMapsKit (same asset). New monastery setting (Ruined Hill Monastery: limestone cloister ruins, cypresses, lilac storm-light) and monastery layout (Hill Monastery: a central hill reached by stairs). New narrowBridge layout: a one-cell-wide bridge as the main crossing with slow flank fords. Fords (f in the half-grid, map.fords, BM.isFord, BM.moveCost, weighted reach/path). Seeded generator BM.generate (bridge / gate / pass chokepoints) and layout = "generated" on the BattleMap component. 27 new cover props: every setting has 10+ props, each placed by the layouts. BM.expand. Test suite 11 -> 17 tests.
  • 1.0.3 — text only: corrects what 1.0.2 said about custom layouts without defines. On a freshly opened engine a require at the top of a scene build runs after the component's first draw, so the board logs unknown layout once and then appears; it is not left empty. defines removes that warning, and is needed when nothing else requires the module.
  • 1.0.2 — BattleMap gets a defines field (the module defining your own layouts or settings, required by the component on every peer before it draws); :board() and :map() are now real methods on the component ref; the example guide makes its scene playerless so Play works, and uses defines.
  • 1.0.1 — first full release: docs, guides, test suite and demo; same API as 1.0.0.
  • 1.0.0 — first release: 6 layouts x 6 settings, movement rule and helpers, check, runtime diorama builder with low quality, per-piece cover entities with destroyed state, lighting suggestions and helper, BattleMap component, test suite, two guides.