Skip to content

183 mod tool 5 tiles and maps

Alex Diakovsky edited this page Nov 22, 2026 · 1 revision

183. Mod tool 5: tiles and maps (stage S7.3)

Question: the S7 test game needs its own tiles and its own maps, made by the user in the toolset. What must the engine stop assuming about tile numbers, and what does the mod tool need to define tile types and paint a playable two-player map from nothing (issues #135 and #3; tracking issue #143)?

The mod tool series: stage S7 builds the mod tool into a toolset that makes a whole game by hand. It began as the last stage of the deterministic simulation plan (whose stages S0 to S6 are documents 156 to 178), because netplay is tested on a game made with the tool, but the work is the mod tool's. S7 began with the audit (document 179) and the plan for the rest of S7 (document 180). Document 181 is S7.1 and document 182 is S7.2. This document is S7.3, maps.

The tile rules move Return Fire's traced tile behaviour out of the engine into its pack, so this document cites the documents that traced it. The mod tool itself is the port's own; there is no decompiled code to quote, only the port's.

Glossary

Term Meaning
art id A level cell's tile number, 0-127 (the cell's top bit is not part of it). It indexes terrain/tileset.json "tiles".
tile type One tileset.json entry: the sprite a tile is drawn with, a terrain class, and its tile rules.
tile rules What a tile is to the simulation: water, road, pavement, mines, side, hole (below).
coastal id A cell's decoration number: a building, tree, gate, bridge. It indexes decorations.json, coastal_damage.json and coastal_shapes.json.
home A side's spawn point. Its vehicles rise from the home pad tile under it.
flag place A cell of a side's target pool (pool A for side 1, pool B for side 2). One is the live target; the side's flag appears where the pool's last target is destroyed (PORTING_PLAN 1.5).
mod map A level in the mod's own levels/<id>/ (level.json and art.bin). The map editor paints only these.
engine tick One step of the simulation, 1/62.5 s.

The answer, up front

  1. The engine no longer knows Return Fire's tile numbers. Water was art 1, 2 and ranges up to 0x33; roads were 0x49-0x59; pavement 0x49-0x53; the home pads 90 and 91 and the pit 92; the mine rules and the bridges 0x4a / 0x4b were numbers in the code too. Each is now a field of the tile's tileset.json entry (or of the decoration's coastal_damage.json entry), read through new Pack lookups. Return Fire's values live in openfire's tools/data/tile_rules.json, which both importers merge into the pack. This changes the pack format: re-import.
  2. The Tiles tab edits every terrain table: tile types with a form for each rule, decoration types (hit points, what they become, bridge, road, parts and collision as JSON), and the water, home pad, gate and off-map tables as JSON. Every change is one undo step and live in the pack at once.
  3. The Maps tab paints. New map... makes a map of the mod's own (8 to 128 tiles a side, one or two players, filled with a chosen tile), drawn on a Godot TileMapLayer. The tools are brush, rectangle, fill, pick, decoration, clear decoration, home and flag place. A stroke or click is one undo step.
  4. The rules panel sets a mod map's name, players, difficulty, mines, tile seed and roster stock; Show sides as sets its side colours. Play this map runs the game on it.
  5. Map checks in Validate: one home per side, on its pad; a flag place per side with something on it to destroy; markers inside the map; every tile and decoration known; the side colours known.
  6. Sizes other than 128 x 128 work. A check builds a 24 x 16 map through the workspace API, saves it, loads it, and plays two computer players on it: they leave their pads and meet within 276 ticks.

How a tile's number turns into behaviour: the tileset.json entry's rules go into Pack's per-art lookups, which Water, the road assist, the navigation grid, the mines, the impact effects and the home pad read; the mod tool's Tiles tab writes the entry through ModWorkspace.set_entry, which updates the pack and rebuilds the lookups

Mermaid source
flowchart TB
  T["Tiles tab form<br/>(water, road N S E W, pavement,<br/>mines, home pad of, pit)"] -->|"Apply"| S["ModWorkspace.set_entry<br/>one undo step"]
  S --> M["the mod's terrain/tileset.json<br/>(written by Save)"]
  S --> P["Pack.tileset<br/>+ refresh_tile_rules()"]
  I["openfire tools/data/tile_rules.json<br/>(Return Fire's values)"] -->|"importers merge"| B["original pack's<br/>terrain/tileset.json"]
  B --> P
  P --> L["per-art lookups<br/>tile_water, tile_road, tile_pavement,<br/>tile_mines, home_pad_art, pad_hole_art"]
  L --> W["Water.class_at_fx"]
  L --> R["RoadAssist, NavGrid"]
  L --> MC["MatchController:<br/>mines, impacts, debris,<br/>flag land test, pad hatch"]
Loading

Step 1: tile rules from the pack

The audit of S7.3 found the engine still treating some art ids as special. A test game with its own tiles would have got Return Fire's water, roads and pads wherever its tile numbers happened to match. Each tile type now says what it is. From game/pack.gd:

## What a tile art id IS to the simulation, from its terrain/tileset.json entry (a tile's number means nothing to the engine; the
## pack says what each one is -- wiki document 183):
##   "water"    "shallow", "deep", "coast" (part water: the shape is terrain/water.json "coast"[art]) or "box" (shallow inside
##              terrain/water.json "boxes"[art], deep outside); absent = land
##   "road"     the road-assist mask (1 north, 2 south, 4 east, 8 west) that steers a vehicle along it; absent = 0
##   "pavement" true: a shell or a falling piece hitting it plays the pavement effect
##   "mines"    where the level's random mines may go: "yes", or "near_road" (only beside a tile with a road mask, unless the
##              placement is relaxed); absent = never
##   "side"     a home pad of that side (0, 1); "hole" true: the open pad's pit (the art a pad shows while open)
## and per coastal id, in terrain/coastal_damage.json: "dry" true (a decoration that makes its tile land, a bridge) and "road".

refresh_tile_rules() turns the entries into per-art arrays once, after loading and after every edit in the tool, so the simulation's lookups stay as cheap as the old number tests:

func refresh_tile_rules() -> void:
	for arr in [_tile_water, _tile_road, _tile_mines, _tile_pavement]:
		arr.resize(TILE_IDS)
		arr.fill(0)
	_side_art = {}
	_hole_art = -1
	for k in tileset:
		var art := int(k)
		var t: Variant = tileset[k]
		if art < 0 or art >= TILE_IDS or not (t is Dictionary):
			continue
		_tile_water[art] = maxi(0, WATER_KINDS.find(String(t.get("water", "land"))))
		_tile_road[art] = int(t.get("road", 0)) & 0xf
		_tile_mines[art] = maxi(0, MINES_KINDS.find(String(t.get("mines", "never"))))
		_tile_pavement[art] = 1 if t.get("pavement", false) else 0
		...

The water test (document 62's FUN_0042f280) now asks the tile's kind instead of comparing ranges. From game/water.gd:

	var art := level.get_art_id(tx, ty) & 0x7F
	var kind := pack.tile_water(art)
	if kind == Pack.WATER_LAND or pack.coastal_dry(level.get_coastal_id(tx, ty)):
		return 0
	if kind == Pack.WATER_SHALLOW:
		return 1
	if kind == Pack.WATER_DEEP:
		return 2

The coast and box branches are unchanged, keyed by the art in water.json as before. The mine placement (document 75) reads tile_mines and, for near_road, any neighbour with a road mask; the road assist (document 175) and the navigation grid read tile_road; the impact and debris effects (documents 45 and 50) read tile_pavement; the home pad swap reads home_pad_art(side) and pad_hole_art().

Return Fire's values are a table in openfire, tools/data/tile_rules.json, whose _source names each traced function. Both importers merge it into the tileset (from importer/pack_builder.gd):

	# what each art id is to the simulation: water, road, pavement, mines (tools/data/tile_rules.json, wiki document 183)
	var rules: Variant = data("tile_rules.json")
	if rules is Dictionary:
		for k in rules["tiles"]:
			if tileset.has(k):
				tileset[k].merge(rules["tiles"][k], true)

tools/build_pack.py does the same, and the importer parity check confirms the two give the same pack. The debris table's pavement_first_art and pavement_last_art are gone: the tiles say it now.

Step 2: the terrain tables in the workspace

ModWorkspace gains one generic way to edit any terrain table. TABLES names each table's file, its key in the file, and the Pack property holding the resolved table (from editor/workspace.gd):

const TABLES := {
	"tiles": ["terrain/tileset.json", "tiles", "tileset"],
	"off_map": ["terrain/tileset.json", "off_map", "off_map"],
	"decorations": ["terrain/decorations.json", "decoration_types", "decoration_types"],
	"coastal": ["terrain/coastal_damage.json", "coastal", "coastal_damage"],
	"shapes": ["terrain/coastal_shapes.json", "coastal", "coastal_shapes"],
	"gates": ["terrain/gates.json", "gates", "gates"],
	"water": ["terrain/water.json", "", "water_tables"],
	"home_pad": ["terrain/home_pad.json", "", "home_pad"],
}

set_entry(table, key, value) replaces one whole entry in the mod, as the pack loader overlays it; null means the mod no longer sets it, and remove_entry writes the loader's "remove" null. Applying a change updates the mod's table and the live pack, falling back to the layers below:

func _apply_entries(name: String, states: Dictionary) -> void:
	var t: Array = TABLES[name]
	var mt := mod_table(name)
	var runtime: Dictionary = pack.get(String(t[2]))
	var lower := _lower_table(t[0], t[1])
	for k in states:
		var had: bool = states[k][0]
		var v: Variant = states[k][1]
		if had:
			mt[k] = v.duplicate(true) if v is Dictionary or v is Array else v
		else:
			mt.erase(k)
		var shown: Variant = v if had else lower.get(k)
		...
	pack.refresh_tile_rules()
	tables_changed.emit(name)

The mod's whole documents are kept in mod_docs, so keys the tool does not edit (such as tile_size_px) survive a save. PackWriter.write_docs writes each one sorted and removes a file left with nothing in it.

Step 3: the Tiles tab

editor/tiles_panel.gd lists one table at a time with thumbnails. A tile type has a form: sprite, terrain class, water kind, road N / S / E / W, pavement, mines, home pad of a side, the open pad's pit. For a coast or box tile its water.json shape appears under it. A decoration type has hit points, what it becomes when destroyed, Makes its tile land (a bridge), the road it carries, and its parts and collision shapes as JSON. Gates, water, the home pad's mechanism art and the off-map edge are edited as JSON. New, Duplicate (a decoration's damage and collision come along), Revert and Remove complete it. Each control applies at once, as one undo step per table it changes.

The Tiles tab on the engine's test pack: the tile list with thumbnails, and tile 2's form with its sprite, terrain class, water, the road's E and W ticked, mines, home pad and the other fields as JSON

Step 4: painting a map

A map of the mod's own lives in ModWorkspace.mod_levels as its level.json document and its art.bin bytes, written by Save (PackWriter.write_level). A map from the layers below is shown, never changed: original content is never edited (PORTING_PLAN 2.7.9). LevelData.load_from_doc loads a map from memory the same way load_from loads one from disk.

Painting is paint_cells(id, cells), cell to art, one undo step holding only the cells that changed:

func paint_cells(id: String, cells: Dictionary, action := "Paint tiles") -> bool:
	var change := _art_change(id, cells)
	if change.is_empty():
		return false
	undo.create_action(action)
	undo.add_do_method(_apply_cells.bind(id, change[0], change[2]))
	undo.add_undo_method(_apply_cells.bind(id, change[0], change[1]))
	undo.commit_action()
	return true

fill_rect and flood_fill build their cells and call it. Everything else on a map goes through edit_level(id, action, edit, cells), which runs edit on a copy of the document and can paint cells in the same step. place_home uses that to put the spawn and its side's pad tile down together:

func place_home(id: String, team: int, cell: Vector2i) -> bool:
	var cells := {}
	if pack.home_pad_art(team) >= 0:
		cells[cell] = pack.home_pad_art(team)
	return edit_level(id, "Place home %d" % (team + 1), func(doc: Dictionary) -> void:
		var list: Array = doc.get("spawn_points", []).filter(func(p): return int(p.get("team", 0)) != team)
		list.append({"team": team, "x": cell.x, "y": cell.y})
		list.sort_custom(func(a, b): return int(a["team"]) < int(b["team"]))
		doc["spawn_points"] = list, cells)

set_decoration, set_pool_cell and set_level_value work the same way. Every change emits level_edited(id, cells), so the view redraws only the changed cells.

The Maps tab draws a mod map on a TileMapLayer whose TileSet is one atlas made from the pack's tile types (a home pad in its side's colour on this map, and a magenta check for a number with no type). A brush stroke shows on the layer as it is drawn and becomes one paint_cells step on release; a fast drag fills the gaps between mouse positions:

		"Brush":
			# every cell on the line from the last one, so a fast drag leaves no gaps
			var steps := maxi(absi(c.x - _last_cell.x), absi(c.y - _last_cell.y))
			for k in range(1, steps + 1):
				_brush(Vector2i(Vector2(_last_cell).lerp(Vector2(c), float(k) / steps).round()))
			_last_cell = c

The palette beside the view lists tile types for the tile tools and decoration types for Decoration. Right or middle drag pans with any tool; Look pans with the left button too. A map from the layers below keeps the game's own TerrainTileRenderer and shows no tools.

The Maps tab on the engine's test pack: a 20 x 12 map of the mod's own with a river, a road crossing it on a bridge, the two homes (P1, P2) on their pads and a flag place per side (F1, F2); the tool bar, the tile palette, and the map's rules panel

Step 5: map checks and other sizes

ModValidator.check_maps runs on every mod map. Its rules, as EDITOR_PLAN 5.6 lists them:

  • every side the map's player count names has exactly one home, inside the map;
  • the home is on its side's home pad tile (a warning; an editor check: the vehicles rise from the pad);
  • every side has a flag place (an error: without one the side's flag can never appear, PORTING_PLAN 1.5), and each has a destructible decoration on it (a warning, an editor check);
  • no home for a side the map does not have; every decoration inside the map;
  • every cell's art has a tile type, and every decoration id is a decoration type;
  • both side colours are team colours.

check_tiles checks the mod's tile types: a tile number is 0-127, its sprite exists, its water and mines kinds are known, a coast or box tile has its water.json shape, a road mask is 0-15; more than one pad per side, or more than one pit, is a warning. A finding about a map jumps to it from the Validate tab.

EDITOR_PLAN section 8 listed the 128 x 128 assumptions to check. The simulation already reads level.width and level.height everywhere (the edge guard's overshoot, the cell scan, the navigation grid), and the decoration jitter table repeats every 16 tiles whatever the size. The radar's level preview is drawn at 128 x 128 and shows black past a smaller map; a map is therefore limited to 128 a side (ModWorkspace.MAX_MAP_SIZE). The check below plays a match on a 24 x 16 map.

The checks

Engine, tests/tile_rules_check.gd (23 checks): a test pack whose tiles have made-up numbers (10 deep, 11 shallow, 12 a box, 20 a road with pavement and mines, 30 and 31 the pads, 32 the pit, and a dry decoration 5 with a road). The lookups; Water.class_at_fx on each kind, art 1 being land here, and the dry decoration making deep water land; mines through MatchController._mine_candidate; the flag's land test; the pad opening to the pack's pit and closing to its side's pad; and a pack with no rules being all plain land.

Engine, tests/map_editing_check.gd (45 checks, the workspace API alone on the synthetic test pack): tile types (water, a road, two pads, the pit) with undo and redo, a base tile changed and reverted; a building and a bridge; New map refusing a size over 128 and a taken id; a 24 x 16 map painted with the brush (a river), the rectangle (a road over it), and the fill (a pond, and back); homes with their pad tiles, undone together; decorations and flag places; the map and tile checks; saved, the files the mod sets written and the others not, loaded by a fresh Pack and by LevelData from disk, reopened. Then two computer players play on it: both leave their pads, and they meet (within 96 units) after 276 ticks.

Engine, tests/map_editor_ui_check.gd (34 checks, the editor scene): the tab order; the Tiles tab making four tiles through its form (deep water, an E-W road by its boxes, two pads), a decoration's hit points, Duplicate and Makes its tile land; New map... suggesting a free id and making a 20 x 12 map drawn on the TileMapLayer; brush, rectangle, fill, pick, home, decoration, flag place (a second click removes one) and clear decoration driven by mouse events, each one undo step; undo reaching the canvas; the rules panel and Show sides as writing level.json; the hover reading the bridge's road; and a map finding in Validate jumping to the map.

openfire: road_assist_check reads the masks through the pack; the importer parity check passes with the merged rules.

Suites: the engine's 67 checks and openfire's 78 pass, with no script error; the importer parity check compares 2899 files with no differences.

Try it

The pack format changed: re-import the original first (python tools/import_original.py <game dir> packs/original_pc, or the in-game importer).

Open the mod tool (godot --path . res://addons/openfire_engine/editor/editor_main.tscn) on a new standalone game (New game...) so no original art is in the pickers, and draw a few 32 x 32 tiles in the Assets tab first (S7.2): ground, water, a road, two pads, a building.

  1. Tiles tab: New for each tile. Give it its sprite, and set Water to deep on the water tile, tick E and W on the road, set Home pad of side 1 and side 2 on the pads, and tick Open pad's pit on one more tile.
  2. Pick Decorations, New, and paste a part into the JSON (a sprite and four corners). Give it hit points, so a flag can hide in it. Duplicate it and tick Makes its tile land and E / W for a bridge.
  3. Maps tab: New map..., 2 players, filled with the ground tile (128 x 128, or smaller).
  4. Brush a river with the water tile, Rectangle a road across it, Fill to try a pond. Put the bridge decoration on the road over the river.
  5. Home for side 1, then side 2 (the for box). Put a building near each with Decoration, then mark it with Flag place for its side.
  6. Read Validate: it should have no errors. Then Play this map: walk it in the 3D view.

Changed from the plan

  • Document 180 listed "hit points and what it becomes when destroyed" per art id. In the engine those belong to decorations (coastal_damage.json), not tiles, so the Tiles tab has them on decoration types.
  • The plan's "place ... gates, ... the flag": a gate is a decoration type like any other; a flag is placed by its flag places (target pool cells).
  • The original-compatible painting mode of EDITOR_PLAN 5.1 and the cell patches of 5.6 for original maps are not built: S7's game has no original maps.

Not done here

  • Stamps, select / move / copy of cells, and a line tool (EDITOR_PLAN 5.3). The rectangle and fill cover S7's maps.
  • An auto-coast brush: the coast-to-water rules are not traced (EDITOR_PLAN 8).
  • A roster that adds or removes vehicles per map: the rules panel sets the stock of the pack's roster entries that have a stock key.
  • A radar preview larger than 128 x 128.

Where the code is

  • Engine game/pack.gd: WATER_*, MINES_*, refresh_tile_rules, tile_water, tile_road, coastal_dry, tile_pavement, tile_mines, home_pad_art, pad_hole_art.
  • Engine game/water.gd, game/road_assist.gd, game/ai/nav_grid.gd, game/match_controller.gd (_mine_candidate, _set_pad_open, _land_tile_fx, impacts and debris), game/level_preview.gd, game/vehicle.gd: the rules read through the pack.
  • Engine game/level_data.gd: load_from_doc.
  • Engine editor/workspace.gd: TABLES, mod_docs, set_entry, set_entries, remove_entry, free_key, mod_levels, new_level, delete_level, paint_cells, fill_rect, flood_fill, edit_level, set_decoration, place_home, set_pool_cell, set_level_value.
  • Engine editor/pack_writer.gd: write_docs, write_level. Engine editor/validator.gd: check_tiles, check_maps.
  • Engine editor/tiles_panel.gd (new), editor/map_view_panel.gd (the tools, the TileMapLayer, the rules panel, New map), editor/editor_main.gd (the Tiles tab, RF_EDITOR_TOOL, RF_EDITOR_TILE).
  • Engine tests/tile_rules_check.gd, tests/map_editing_check.gd, tests/map_editor_ui_check.gd.
  • openfire tools/data/tile_rules.json, importer/pack_builder.gd, tools/build_pack.py, tools/data/debris.json, tools/tests/road_assist_check.gd, docs/EDITOR_PLAN.md.

Next: S7.4, vehicle numbers and weapons, after the user's try-out.

Clone this wiki locally