A11: Chart, minimap and tide forecast

The island as a hand-drawn nautical chart: paper land with ink contours
every 5 m (heavier every 25 m) and a coastline, the sea in the sea's
ink, place names drawn from the seed, the barge's route, and the
player's mark. The land the coming tide will flood is hatched, and land
the sea has already taken is washed with the sea, so the forecast isn't
told by colour alone.

- Flood.forecast(level, structures): a copy of the flood spread to a
  level as update() would, with today's breakwaters. Changes nothing.
- ChartMap: FULL (opened and closed with the new "map" binding, M) and
  MINI (240 m around the player, top left, during the drop and play).
  The paper is drawn once per world (about 270 ms) and shared; the
  forecast overlay is redrawn at most once a second, and only when the
  forecast level, the flood or the pieces changed.
- PlaceNames: names from original coastal words and a word for each
  kind of place, the same for every player of a match.
- make chart-captures renders the chart before and after the first tide.

Solo matches have no teammates; ChartMap draws `mates` when duos (M7)
give it some.

Closes #51

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:46:35 -05:00
co-authored by Claude Opus 5.5
parent c504551b28
commit 8505216568
18 changed files with 638 additions and 2 deletions
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/chart_scene.gd" id="1"]
[node name="CaptureChart" type="Control"]
script = ExtResource("1")
stage = "first"
+7
View File
@@ -0,0 +1,7 @@
[gd_scene load_steps=2 format=3]
[ext_resource type="Script" path="res://test/capture/chart_scene.gd" id="1"]
[node name="CaptureChart" type="Control"]
script = ExtResource("1")
stage = "later"
+38
View File
@@ -0,0 +1,38 @@
## Capture scenario for the chart (A11): an island's full chart and minimap over the
## menu backdrop, with a player marked. Stages: "first" (the first tide is forecast) and
## "later" (the first tide has risen and the second is forecast, so taken land shows
## washed with the sea and the next is hatched).
extends Control
@export var stage: String = "first"
@export var match_seed: int = 2
func _ready() -> void:
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
var backdrop: ColorRect = ColorRect.new()
backdrop.color = Palette.SEA_INK.darkened(0.4)
backdrop.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
add_child(backdrop)
var sim: Simulation = Simulation.new(match_seed)
sim.start_tide()
if stage == "later":
var first: Dictionary = Tuning.TIDE_PHASES[0]
var into: int = roundi((float(first["hold"]) + float(first["rise"])) * Tuning.TICK_RATE_HZ) + 5 * Tuning.TICK_RATE_HZ
sim.tide = Tide.new(sim.tick - into, sim.tide.levels)
sim.set_sea_level(sim.tide.level_at(sim.tick))
var drop: Drop = Drop.plan(sim.ground, SimRng.new(match_seed), 0)
var top: Vector3 = sim.island.summits[0]
var me: Vector3 = top + Vector3(-30.0, 0.0, 40.0)
var chart: ChartMap = ChartMap.new(ChartMap.Mode.FULL)
chart.position = Vector2(560.0, 50.0)
chart.size = Vector2(620.0, 620.0)
add_child(chart)
chart.setup(sim, match_seed, drop)
chart.refresh(me, deg_to_rad(40.0), true, 10.0)
var mini: ChartMap = ChartMap.new(ChartMap.Mode.MINI)
mini.position = Vector2(60.0, 60.0)
mini.size = Vector2(170.0, 170.0)
add_child(mini)
mini.setup(sim, match_seed, drop, chart)
mini.refresh(me, deg_to_rad(40.0), true, 10.0)
+1
View File
@@ -0,0 +1 @@
uid://exbrsuso4xy
+102
View File
@@ -0,0 +1,102 @@
extends TestCase
## A11: the chart, its place names and its tide forecast, during the drop and in play.
func test_place_names_follow_the_seed_and_the_kind() -> void:
var kinds: Array[String] = ["hamlet", "dock", "lighthouse", "quarry", "hamlet"]
var names: Array[String] = PlaceNames.names_for(7, kinds)
assert_eq(names, PlaceNames.names_for(7, kinds), "the same seed, the same names")
assert_ne(names, PlaceNames.names_for(8, kinds), "another seed, other names")
assert_eq(names.size(), kinds.size())
var firsts: Dictionary = {}
for index: int in names.size():
var words: Array = PlaceNames.KIND_WORDS[kinds[index]]
var ends_right: bool = false
for word: String in words:
ends_right = ends_right or names[index].ends_with(" " + word)
assert_true(ends_right, "%s is named as a %s" % [names[index], kinds[index]])
firsts[names[index].trim_suffix(names[index].get_slice(" ", names[index].get_slice_count(" ") - 1))] = true
assert_eq(firsts.size(), names.size(), "no first word twice")
func test_the_chart_draws_sea_land_and_coast() -> void:
var sim: Simulation = Simulation.new(5)
var began: int = Time.get_ticks_msec()
var image: Image = ChartMap.base_image(sim.ground)
var took: int = Time.get_ticks_msec() - began
print("chart base image: %d ms" % took)
assert_eq(image.get_size(), Vector2i(ChartMap.PIXELS, ChartMap.PIXELS))
# The corner is open sea; the island's highest summit is paper or ink, not sea.
var corner: Color = image.get_pixel(2, 2)
assert_true(corner.b > corner.r, "the corner is sea")
var top: Vector3 = sim.island.summits[0]
var pixel: Vector2i = Vector2i(top.x / Tuning.WORLD_SIZE_METRES * ChartMap.PIXELS, top.z / Tuning.WORLD_SIZE_METRES * ChartMap.PIXELS)
var land: Color = image.get_pixel(pixel.x, pixel.y)
assert_true(land.r >= land.b, "a summit is land")
var ink: int = 0
for py: int in ChartMap.PIXELS:
for px: int in ChartMap.PIXELS:
var colour: Color = image.get_pixel(px, py)
if absf(colour.r - Palette.INK.r) < 0.01 and absf(colour.g - Palette.INK.g) < 0.01 and absf(colour.b - Palette.INK.b) < 0.01:
ink += 1
assert_true(ink > 50, "there is a coastline (%d ink pixels)" % ink)
func test_the_forecast_overlay_marks_what_the_next_tide_takes() -> void:
var sim: Simulation = Simulation.new(5)
assert_eq(ChartMap.coming_flood(sim).size(), 0, "no tide yet, no forecast")
sim.start_tide()
var coming: PackedByteArray = ChartMap.coming_flood(sim)
var expected: PackedByteArray = sim.flood.forecast(sim.tide.forecast_at(sim.tick), sim.structures)
var count: int = 0
for index: int in coming.size():
if coming[index] != 0:
count += 1
assert_eq(expected[index], 1)
assert_eq(sim.flood.flooded[index], 0, "only land not yet taken")
assert_true(count > 100, "the first tide takes a good piece of shore (%d cells)" % count)
var chart: ChartMap = ChartMap.new()
chart.setup(sim, 5)
chart.refresh(Vector3(500.0, 10.0, 500.0), 0.0, true, 1.0)
assert_eq(chart.forecast_cells, count, "the chart drew them all")
assert_near(chart.forecast_level, sim.tide.forecast_at(sim.tick), 0.001)
assert_eq(chart.places.size(), sim.pois.pois.size(), "every place is named")
var mini: ChartMap = ChartMap.new(ChartMap.Mode.MINI)
mini.setup(sim, 5, null, chart)
assert_eq(mini._base, chart._base, "the minimap shares the chart's paper")
chart.free()
mini.free()
func test_the_session_shows_the_minimap_in_play_and_the_chart_on_the_map_key() -> void:
var tree: SceneTree = Engine.get_main_loop() as SceneTree
var rules: MatchRules = MatchRules.new()
rules.max_players = 2
rules.min_players = 1
rules.lobby_ticks = 2
rules.countdown_ticks = 2
var session: ClientSession = ClientSession.new()
session.input.autoplay = true
session.play_offline(6, 1, rules)
tree.root.add_child(session)
var frames: int = 0
while not session.game.playing() and frames < 600:
session._process(1.0 / 30.0)
frames += 1
assert_true(session.game.playing())
session._process(1.0 / 30.0)
assert_true(session.minimap.visible, "the minimap during the drop")
assert_false(session.chart.visible)
assert_eq(session.chart.route.size(), 2, "the drop route is on the chart")
assert_true(session.game.prediction.player.drop_state != Drop.NONE, "still on the drop")
session.input.press(KEY_M)
session._process(1.0 / 30.0)
assert_true(session.chart.visible, "M opens the chart")
assert_false(session.minimap.visible, "and the minimap gives way")
assert_true(session.chart.show_me)
assert_near(session.chart.me.x, session.game.prediction.player.position.x, 0.01, "the player is marked where they are")
session.input.press(KEY_M)
session._process(1.0 / 30.0)
assert_false(session.chart.visible)
session.free()
+1
View File
@@ -0,0 +1 @@
uid://cnm6ise52xj7h
+95
View File
@@ -0,0 +1,95 @@
extends TestCase
## A11: the chart's flood forecast (Flood.forecast) shows exactly the cells each phase's
## rise will flood, on a real island through every phase, and behind a breakwater ring
## that holds or doesn't.
const SIDE: int = 513
const SPACING: float = 2.0
## Skips the rest of the current hold, so the rise starts on the next step.
func _skip_hold(sim: Simulation) -> void:
var wait: int = sim.tide.ticks_until_rise(sim.tick)
if wait > 1:
sim.tide = Tide.new(sim.tide.started_tick - wait + 1, sim.tide.levels)
## Steps through the current rise and a second after, so every pour has happened.
func _ride_out_rise(sim: Simulation) -> void:
var phase: int = sim.tide.phase_at(sim.tick)
var guard: int = 0
while sim.tide.stage_at(sim.tick) != Tide.HOLD or sim.tide.phase_at(sim.tick) == phase:
sim.step()
guard += 1
if sim.tide.stage_at(sim.tick) >= Tide.SUDDEN_DEATH or guard > 200 * Tuning.TICK_RATE_HZ:
break
for _index: int in Tuning.TICK_RATE_HZ + 1:
sim.step()
func _differing(a: PackedByteArray, b: PackedByteArray) -> int:
var count: int = 0
for index: int in a.size():
if a[index] != b[index]:
count += 1
return count
func test_the_forecast_matches_every_phase_on_a_real_island() -> void:
var sim: Simulation = Simulation.new(11)
assert_not_null(sim.flood)
sim.start_tide()
var phases_checked: int = 0
for phase: int in Tide.phase_count():
var before: PackedByteArray = sim.flood.flooded.duplicate()
var level: float = sim.tide.forecast_at(sim.tick)
var forecast: PackedByteArray = sim.flood.forecast(level, sim.structures)
assert_eq(sim.flood.flooded, before, "forecasting changes nothing")
_skip_hold(sim)
_ride_out_rise(sim)
assert_near(sim.sea_level, level, 0.001, "phase %d reached its forecast level" % phase)
assert_eq(_differing(forecast, sim.flood.flooded), 0, "phase %d floods what was forecast" % phase)
assert_true(_differing(before, forecast) > 0 or phase == 0, "phase %d floods something new" % phase)
phases_checked += 1
if sim.tide.stage_at(sim.tick) >= Tide.SUDDEN_DEATH:
break
assert_eq(phases_checked, Tide.phase_count())
func test_the_forecast_respects_a_breakwater_ring() -> void:
var values: PackedFloat32Array = PackedFloat32Array()
values.resize(SIDE * SIDE)
for gz: int in SIDE:
for gx: int in SIDE:
var x: float = gx * SPACING
var z: float = gz * SPACING
values[gz * SIDE + gx] = 1.0 if x >= 400.0 and x <= 600.0 and z >= 400.0 and z <= 600.0 else -Tuning.ISLAND_SEA_DEPTH
var ground: SimGround = SimGround.from_heights(values, SIDE, SPACING)
var sim: Simulation = Simulation.new(3, ground)
sim.flood = Flood.create(ground)
var stone: int = Materials.code_of("stone")
var ids: Array[int] = []
for along: int in range(120, 123):
for slot: Vector4i in [Vector4i(120, 0, along, StructureSet.SLOT_WALL_X), Vector4i(123, 0, along, StructureSet.SLOT_WALL_X),
Vector4i(along, 0, 120, StructureSet.SLOT_WALL_Z), Vector4i(along, 0, 123, StructureSet.SLOT_WALL_Z)]:
ids.append(sim.structures.add(StructureSet.BREAKWATER, stone, slot, 0, 0, sim.tick, sim.ground).id)
for _index: int in 200:
sim.structures.advance_building()
var inside: int = sim.flood.cell_of(486.0, 486.0)
var outside: int = sim.flood.cell_of(450.0, 450.0)
var forecast: PackedByteArray = sim.flood.forecast(3.0, sim.structures)
assert_eq(forecast[outside], 1, "the land outside will flood")
assert_eq(forecast[inside], 0, "the ring will hold")
sim.set_sea_level(3.0)
assert_eq(_differing(forecast, sim.flood.flooded), 0, "and so it did")
# Too high for the ring: the forecast says it spills over.
forecast = sim.flood.forecast(9.0, sim.structures)
assert_eq(forecast[inside], 1, "over the top")
# With the ring gone, the forecast changes with it.
for piece_id: int in ids:
sim.structures.remove(piece_id, sim.ground)
forecast = sim.flood.forecast(3.0, sim.structures)
assert_eq(forecast[inside], 1, "nothing holds it back now")
sim.set_sea_level(3.0)
assert_eq(_differing(forecast, sim.flood.flooded), 0)
+1
View File
@@ -0,0 +1 @@
uid://ddoxk48b3guk1