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
+41
View File
@@ -26,6 +26,10 @@ var frames: int = 0
## The in-game HUD, once the session is in a scene tree.
var hud: Hud = null
## The chart (A11): the minimap in the corner while playing, and the full chart when
## the map key opens it. Children of the HUD.
var minimap: ChartMap = null
var chart: ChartMap = null
## The player's settings (see use_settings()).
var settings: GameSettings = GameSettings.new()
## Escape asks for the pause menu: whoever runs the session shows it (AppShell). With
@@ -122,6 +126,17 @@ func _ready() -> void:
add_child(_status)
hud = Hud.new()
add_child(hud)
minimap = ChartMap.new(ChartMap.Mode.MINI)
minimap.position = Vector2(18.0, 18.0)
minimap.size = Vector2(170.0, 170.0)
minimap.visible = false
hud.add_child(minimap)
chart = ChartMap.new(ChartMap.Mode.FULL)
chart.set_anchors_and_offsets_preset(Control.PRESET_CENTER)
chart.size = Vector2(600.0, 600.0)
chart.position = Vector2(-300.0, -300.0)
chart.visible = false
hud.add_child(chart)
if DisplayServer.get_name() != "headless" and not input.autoplay:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@@ -132,6 +147,7 @@ func _process(delta: float) -> void:
_status.text = status_text()
if hud != null:
hud.show_state(hud_state())
_show_charts(delta)
## What the HUD should show now.
@@ -198,6 +214,31 @@ func _show(delta: float) -> void:
view.overview()
## The minimap while this client plays (the drop included), and the full chart while
## the map key has it open and there's a world.
func _show_charts(delta: float) -> void:
if minimap == null:
return
var world: Simulation = game.world
if world == null:
minimap.visible = false
chart.visible = false
return
if minimap.world != world:
var drop: Drop = Drop.plan(world.ground, SimRng.new(game.world_seed), 0) if world.island != null else null
minimap.setup(world, game.world_seed, drop)
chart.setup(world, game.world_seed, drop, minimap)
var playing: bool = game.playing()
var me: SimEntity = game.prediction.player
var at: Vector3 = me.position if playing else Vector3(Tuning.WORLD_SIZE_METRES * 0.5, 0.0, Tuning.WORLD_SIZE_METRES * 0.5)
minimap.visible = playing and not input.map_open
chart.visible = input.map_open
if minimap.visible:
minimap.refresh(at, input.yaw, true, delta)
if chart.visible:
chart.refresh(at, input.yaw, playing, delta)
## The build ghost, in build mode while this client plays: the piece the next build
## would place, asked of the client's own world and predicted player, as the server
## will ask its own. Its look is the newest the mouse has given.
+5 -1
View File
@@ -5,7 +5,7 @@
## right mouse aim · R reload · E pick up or open · G drop the held item ·
## 1 the boathook, 2 to 6 the five slots · B build mode on and off ·
## in build mode 1 to 5 pick wall, floor, ramp, roof or breakwater, Tab the material,
## and left mouse places.
## and left mouse places · M the chart.
## Gamepads come with A13.
##
## With `autoplay` on, a simple script plays instead: it leaps from the barge over
@@ -25,6 +25,8 @@ var buttons: int = 0
## The held selection outside build mode: 0 the boathook, 1 to 5 a slot.
var slot: int = 0
var build_mode: bool = false
## The full chart is open (the map key toggles it).
var map_open: bool = false
## The piece kind and material placed in build mode.
var build_kind: int = StructureSet.WALL
var material: int = Materials.DRIFTWOOD
@@ -89,6 +91,8 @@ func press(keycode: Key) -> void:
func act(action: String) -> void:
if action == "build":
build_mode = not build_mode
elif action == "map":
map_open = not map_open
elif action == "material" and build_mode:
material = (material + 1) % Materials.NAMES.size()
elif action.begins_with("slot_"):
+268
View File
@@ -0,0 +1,268 @@
## The island as a hand-drawn nautical chart (A11): paper land with ink contours every
## CONTOUR_METRES, a heavier coastline, the sea in the sea's ink, place names, the
## barge's route, the player's own mark, and the tide forecast: land the coming tide
## will flood is hatched, and land the sea has already taken is washed with the sea.
##
## The forecast comes from the client's own Flood (Flood.forecast), the same spreading
## the simulation does, so it accounts for the breakwaters standing now.
##
## One ChartMap draws either the full chart (FULL, opened with the map key) or the
## minimap (MINI: a square of the chart around the player, north up). setup() once per
## world; refresh() each frame with where the player is.
class_name ChartMap
extends Control
enum Mode { FULL, MINI }
## Chart pixels per side: 2 m each over the 1024 m world.
const PIXELS: int = 512
const CONTOUR_METRES: float = 5.0
const MAJOR_CONTOUR_METRES: float = 25.0
## The minimap shows this many metres across.
const MINI_METRES: float = 240.0
## How often the forecast overlay may be redrawn, in seconds.
const OVERLAY_SECONDS: float = 1.0
const FONT_SIZE: int = 13
var mode: Mode = Mode.FULL
var world: Simulation = null
## Place names and where they are, in world metres (x, z).
var places: Array[Dictionary] = []
## The barge's route ends, in world metres (x, z), or empty when there's no drop.
var route: PackedVector2Array = PackedVector2Array()
## The player: position (x, z) in metres, facing (radians, the simulation's yaw), and
## whether to draw them.
var me: Vector2 = Vector2.ZERO
var facing: float = 0.0
var show_me: bool = false
## Teammates' positions (x, z), drawn as hollow marks. Solo matches have none.
var mates: PackedVector2Array = PackedVector2Array()
## The forecast as last drawn: the level, and the cells that will newly flood.
var forecast_level: float = NAN
var forecast_cells: int = 0
var _base: ImageTexture = null
var _overlay: ImageTexture = null
var _overlay_image: Image = null
var _overlay_key: Array = []
var _overlay_age: float = INF
func _init(chart_mode: Mode = Mode.FULL) -> void:
mode = chart_mode
mouse_filter = Control.MOUSE_FILTER_IGNORE
## Draws the chart of `simulation`'s island and names its places from `match_seed`.
## `drop` is the match's barge route, or null. `share` is another ChartMap already set
## up for the same world, whose paper and contours are used rather than drawn again.
func setup(simulation: Simulation, match_seed: int, drop: Drop = null, share: ChartMap = null) -> void:
world = simulation
if share != null and share.world == simulation and share._base != null:
_base = share._base
else:
_base = ImageTexture.create_from_image(base_image(simulation.ground))
_overlay_image = Image.create(PIXELS, PIXELS, false, Image.FORMAT_RGBA8)
_overlay = ImageTexture.create_from_image(_overlay_image)
_overlay_key = []
_overlay_age = INF
places.clear()
var kinds: Array[String] = []
for poi: Poi in simulation.pois.pois:
kinds.append(poi.kind)
var names: Array[String] = PlaceNames.names_for(match_seed, kinds)
for index: int in kinds.size():
var poi: Poi = simulation.pois.pois[index]
places.append({"name": names[index], "at": Vector2(poi.origin.x, poi.origin.z), "kind": poi.kind})
route = PackedVector2Array()
if drop != null:
route = PackedVector2Array([Vector2(drop.start.x, drop.start.z), Vector2(drop.finish.x, drop.finish.z)])
queue_redraw()
## Where the player is now; redraws the forecast when the tide or the flood moved on.
func refresh(position: Vector3, yaw: float, visible_me: bool, delta: float) -> void:
me = Vector2(position.x, position.z)
facing = yaw
show_me = visible_me
_overlay_age += delta
if world != null and _overlay_age >= OVERLAY_SECONDS:
var key: Array = overlay_key(world)
if key != _overlay_key:
_overlay_key = key
_draw_overlay()
_overlay_age = 0.0
queue_redraw()
## What the overlay depends on: when none of it changed, the overlay can't have.
static func overlay_key(sim: Simulation) -> Array:
var level: float = sim.tide.forecast_at(sim.tick) if sim.tide != null else NAN
var pours: int = sim.flood.pours if sim.flood != null else -1
return [level, pours, sim.structures.count()]
## The cells the coming tide will newly flood: the forecast less what's flooded now.
## Empty with no tide or no flood grid.
static func coming_flood(sim: Simulation) -> PackedByteArray:
if sim.tide == null or sim.flood == null:
return PackedByteArray()
var forecast: PackedByteArray = sim.flood.forecast(sim.tide.forecast_at(sim.tick), sim.structures)
for index: int in forecast.size():
if sim.flood.flooded[index] != 0:
forecast[index] = 0
return forecast
## The chart's paper, sea and contours for `ground`, PIXELS square.
static func base_image(ground: SimGround) -> Image:
var image: Image = Image.create(PIXELS, PIXELS, false, Image.FORMAT_RGB8)
var metres: float = Tuning.WORLD_SIZE_METRES / PIXELS
var heights: PackedFloat32Array = PackedFloat32Array()
heights.resize((PIXELS + 1) * (PIXELS + 1))
for py: int in PIXELS + 1:
for px: int in PIXELS + 1:
heights[py * (PIXELS + 1) + px] = ground.terrain_height(minf(px * metres, Tuning.WORLD_SIZE_METRES - 0.01), minf(py * metres, Tuning.WORLD_SIZE_METRES - 0.01))
var sea_shallow: Color = Palette.SEA_INK.lightened(0.45)
var sea_deep: Color = Palette.SEA_INK.lightened(0.15)
for py: int in PIXELS:
for px: int in PIXELS:
var h: float = heights[py * (PIXELS + 1) + px]
var right: float = heights[py * (PIXELS + 1) + px + 1]
var down: float = heights[(py + 1) * (PIXELS + 1) + px]
var colour: Color
if h < Tuning.SEA_LEVEL_START:
colour = sea_shallow.lerp(sea_deep, clampf(-h / Tuning.ISLAND_SEA_DEPTH, 0.0, 1.0))
else:
# Paper, faintly shaded where the ground faces away from a north-west light.
var shade: float = clampf((right - h) * 0.06 + (down - h) * 0.06, -0.12, 0.12)
colour = Palette.PAPER.darkened(maxf(shade, 0.0)).lightened(maxf(-shade, 0.0) * 0.3)
var crossed: int = _crossing(h, right, down)
if crossed == 3:
colour = Palette.INK
elif crossed == 2:
colour = colour.lerp(Palette.INK, 0.65)
elif crossed == 1:
colour = colour.lerp(Palette.INK, 0.3)
image.set_pixel(px, py, colour)
return image
## 3 for the coastline, 2 for a major contour, 1 for a minor one, 0 for none, between a
## height and its right and lower neighbours.
static func _crossing(h: float, right: float, down: float) -> int:
var sea: float = Tuning.SEA_LEVEL_START
if (h < sea) != (right < sea) or (h < sea) != (down < sea):
return 3
if h < sea:
return 0
if floori(h / MAJOR_CONTOUR_METRES) != floori(right / MAJOR_CONTOUR_METRES) or floori(h / MAJOR_CONTOUR_METRES) != floori(down / MAJOR_CONTOUR_METRES):
return 2
if floori(h / CONTOUR_METRES) != floori(right / CONTOUR_METRES) or floori(h / CONTOUR_METRES) != floori(down / CONTOUR_METRES):
return 1
return 0
func _draw_overlay() -> void:
_overlay_image.fill(Color.TRANSPARENT)
var flood: Flood = world.flood
forecast_level = world.tide.forecast_at(world.tick) if world.tide != null else NAN
forecast_cells = 0
if flood == null:
_overlay.update(_overlay_image)
return
var coming: PackedByteArray = coming_flood(world)
var per_cell: int = maxi(roundi(PIXELS / float(flood.side)), 1)
var taken: Color = Color(Palette.SEA_INK.lightened(0.3), 0.7)
var hatch: Color = Color(Palette.WARNING, 0.95)
var wash: Color = Color(Palette.WARNING, 0.16)
for cz: int in flood.side:
for cx: int in flood.side:
var index: int = cz * flood.side + cx
var flooded_land: bool = flood.flooded[index] != 0 and flood.floors[index] >= Tuning.SEA_LEVEL_START - 0.5
var will_flood: bool = not coming.is_empty() and coming[index] != 0
if not flooded_land and not will_flood:
continue
if will_flood:
forecast_cells += 1
for oy: int in per_cell:
for ox: int in per_cell:
var px: int = cx * per_cell + ox
var py: int = cz * per_cell + oy
if px >= PIXELS or py >= PIXELS:
continue
if will_flood:
# Diagonal hatching, so the warning isn't colour alone.
_overlay_image.set_pixel(px, py, hatch if (px + py) % 4 < 1 else wash)
else:
_overlay_image.set_pixel(px, py, taken)
_overlay.update(_overlay_image)
## World metres (x, z) to a point in `rect` showing `view` (a world rectangle).
static func to_chart(at: Vector2, view: Rect2, rect: Rect2) -> Vector2:
return rect.position + (at - view.position) / view.size * rect.size
func _draw() -> void:
if _base == null:
return
var rect: Rect2 = Rect2(Vector2.ZERO, size)
var view: Rect2 = Rect2(0.0, 0.0, Tuning.WORLD_SIZE_METRES, Tuning.WORLD_SIZE_METRES)
if mode == Mode.MINI:
view = Rect2(me - Vector2(MINI_METRES, MINI_METRES) * 0.5, Vector2(MINI_METRES, MINI_METRES))
var scale: float = PIXELS / Tuning.WORLD_SIZE_METRES
var source: Rect2 = Rect2(view.position * scale, view.size * scale)
# Paper margin, then the chart.
draw_rect(rect.grow(6.0), Palette.PAPER)
draw_texture_rect_region(_base, rect, source)
draw_texture_rect_region(_overlay, rect, source)
var font: Font = ThemeDB.fallback_font
if route.size() == 2 and mode == Mode.FULL:
_dashed(to_chart(route[0], view, rect), to_chart(route[1], view, rect), Palette.INK, 2.0)
for place: Dictionary in places:
var at: Vector2 = to_chart(place["at"], view, rect)
if not rect.has_point(at):
continue
draw_circle(at, 3.5, Palette.INK)
if mode == Mode.FULL:
var text: String = String(place["name"])
var width: float = font.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE).x
var spot: Vector2 = at + Vector2(-width * 0.5, -7.0)
spot.x = clampf(spot.x, rect.position.x + 2.0, rect.end.x - width - 2.0)
draw_string_outline(font, spot, text, HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE, 4, Palette.PAPER)
draw_string(font, spot, text, HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE, Palette.INK)
for mate: Vector2 in mates:
var at: Vector2 = to_chart(mate, view, rect)
if rect.has_point(at):
draw_arc(at, 6.0, 0.0, TAU, 16, Palette.INK, 2.0)
if show_me:
var at: Vector2 = to_chart(me, view, rect)
var ahead: Vector2 = Vector2(sin(facing), cos(facing))
var side: Vector2 = Vector2(ahead.y, -ahead.x)
var arrow: PackedVector2Array = PackedVector2Array([at + ahead * 11.0, at - ahead * 7.0 + side * 7.0, at - ahead * 3.0, at - ahead * 7.0 - side * 7.0])
draw_colored_polygon(arrow, Palette.OILSKIN)
arrow.append(arrow[0])
draw_polyline(arrow, Palette.INK, 2.0)
# North, and the frame's ink edge.
var north: Vector2 = rect.position + Vector2(rect.size.x - 18.0, 22.0)
draw_string_outline(font, north + Vector2(-5.0, 0.0), "N", HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE + 2, 4, Palette.PAPER)
draw_string(font, north + Vector2(-5.0, 0.0), "N", HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE + 2, Palette.INK)
draw_line(north + Vector2(0.0, 4.0), north + Vector2(0.0, 18.0), Palette.INK, 2.0)
draw_rect(rect, Palette.INK, false, 3.0)
if mode == Mode.FULL:
var legend: String = "Hatched: floods at the next tide (to %.0f m)" % forecast_level if forecast_cells > 0 else "Nothing more floods at the next tide"
if is_nan(forecast_level):
legend = "The tide hasn't turned yet"
var spot: Vector2 = rect.position + Vector2(10.0, rect.size.y - 10.0)
draw_string_outline(font, spot, legend, HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE, 4, Palette.PAPER)
draw_string(font, spot, legend, HORIZONTAL_ALIGNMENT_LEFT, -1, FONT_SIZE, Palette.INK)
func _dashed(from: Vector2, to: Vector2, colour: Color, width: float) -> void:
var length: float = from.distance_to(to)
var step: float = 12.0
var along: float = 0.0
while along < length:
draw_line(from.lerp(to, along / length), from.lerp(to, minf(along + step * 0.6, length) / length), colour, width)
along += step
+1
View File
@@ -0,0 +1 @@
uid://bn80hlfqxya7
+43
View File
@@ -0,0 +1,43 @@
## Names for an island's places, for the chart: drawn from the island's seed, so every
## player of a match sees the same names. The words are Tidewall's own: shore birds,
## weed and rock, boat gear and weather, with a word for what kind of place it is.
class_name PlaceNames
extends RefCounted
const FIRST: Array[String] = [
"Gannet", "Wrack", "Skerry", "Kelp", "Tern", "Brine", "Shingle", "Heron", "Cormorant",
"Driftwood", "Lantern", "Oyster", "Spindle", "Mussel", "Cockle", "Thole", "Bladder",
"Curlew", "Plover", "Saltcote", "Tarred", "Netmender's", "Grey Seal", "Sculpin",
"Barnacle", "Squall", "Low Water", "Fogbell", "Sandeel", "Limpet", "Whelk", "Gull",
]
## What each kind of place is called on the chart.
const KIND_WORDS: Dictionary = {
"hamlet": ["Row", "Cottages", "End", "Huddle"],
"dock": ["Quay", "Staithe", "Landing", "Hard"],
"lighthouse": ["Light", "Head", "Beacon"],
"shrine": ["Cairn", "Chapel", "Rest"],
"salt_works": ["Salt Pans", "Saltings", "Brine Works"],
"quarry": ["Delph", "Cut", "Quarry"],
}
## One name for each of `kinds`, in order, from `match_seed`. No first word repeats
## while there are words left.
static func names_for(match_seed: int, kinds: Array[String]) -> Array[String]:
var rng: RandomNumberGenerator = RandomNumberGenerator.new()
rng.seed = hash([match_seed, "place-names"])
var order: Array[int] = []
for index: int in FIRST.size():
order.append(index)
# Fisher-Yates with the seeded generator, so the order is the same everywhere.
for index: int in range(order.size() - 1, 0, -1):
var other: int = rng.randi_range(0, index)
var held: int = order[index]
order[index] = order[other]
order[other] = held
var names: Array[String] = []
for index: int in kinds.size():
var words: Array = KIND_WORDS.get(kinds[index], ["Point"])
var first: String = FIRST[order[index % order.size()]]
names.append("%s %s" % [first, words[rng.randi_range(0, words.size() - 1)]])
return names
+1
View File
@@ -0,0 +1 @@
uid://b55xw4hlb313n
+1
View File
@@ -26,6 +26,7 @@ const ACTIONS: Array[Dictionary] = [
{"id": "drop", "label": "Drop held item", "default": KEY_G},
{"id": "build", "label": "Build mode", "default": KEY_B},
{"id": "material", "label": "Next material", "default": KEY_TAB},
{"id": "map", "label": "Chart", "default": KEY_M},
{"id": "slot_0", "label": "Boathook / wall", "default": KEY_1},
{"id": "slot_1", "label": "Slot 1 / floor", "default": KEY_2},
{"id": "slot_2", "label": "Slot 2 / ramp", "default": KEY_3},
+19
View File
@@ -202,6 +202,25 @@ func update(level: float, structures: StructureSet, seconds: float) -> int:
return reached
## The cells the sea will have reached once it stands at `level`, if the breakwaters in
## `structures` (null: the ones last read) hold as they are now: a copy of this flood
## spread to that level, as update() would spread it. Changes nothing here. For the
## chart's tide forecast (A11).
func forecast(level: float, structures: StructureSet = null) -> PackedByteArray:
var copy: Flood = Flood.new()
copy.side = side
copy.cell = cell
copy.floors = floors
copy.flooded = flooded.duplicate()
copy.fill_group = fill_group.duplicate()
copy.sea_level = sea_level
copy._blocked = _blocked.duplicate()
copy._barriers = _barriers.duplicate()
copy._structures_seen = _structures_seen
copy.update(maxf(level, sea_level), structures, 0.0)
return copy.flooded
## Follows the sea level and advances filling basins, without re-spreading. Cheap
## enough for every tick.
func flow(level: float, seconds: float) -> void: