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:
@@ -40,6 +40,7 @@ continuity.
|
||||
| `make client-captures` | Renders what a network client sees on the barge, gliding and landed, the build ghost allowed and refused, and a breakwater basin kept dry by the tide (`captures/client_<stage>.png`, about 4 min). Needs Docker. Look at them. |
|
||||
| `make hud-captures` | Renders the HUD over a staged moment of play (three bots out, carried items, a wound) at 1280x720, in build mode, and at 3840x2160 (`captures/hud_*.png`, about 5 min). Needs Docker. Look at them. |
|
||||
| `make menu-captures` | Renders every menu screen: main, practice, join (with a made-up server list), settings (controls and mouse tabs), pause and results over a match (`captures/menu_*.png`, about 5 min). Needs Docker. Look at them. |
|
||||
| `make chart-captures` | Renders the chart and minimap of seed 2 with the first tide forecast, and again once it has risen (`captures/chart_*.png`, about 2 min). Needs Docker. Look at them. |
|
||||
| `make style-captures` | Renders a hamlet and a dock with and without the woodcut print pass (`captures/style_*.png`). Needs Docker. |
|
||||
| `make soak` | The 24-client network soak (N8): a real server and 24 headless `SoakPlayer` clients in three processes, each behind a `UdpRelay` adding 60 ms, +/-20 ms jitter and 2% loss each way, for two whole matches in real time (about 30 min, under `nice`). Fails on a world-hash mismatch, errors, unreadable packets, a client that didn't play every match, memory growth between matches, or a p99 tick over budget. `SOAK_MATCHES`, `SOAK_CLIENTS`, `SOAK_PROCS`, `SOAK_LATENCY`, `SOAK_JITTER`, `SOAK_LOSS` scale it. Results in `build/soak/report.txt`. |
|
||||
| `make soak-selfcheck` | About a minute: tampers with one client's world and checks the soak's comparison catches it and only it. |
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Tidewall build entry points. Everything runs headless with the repo-local engine.
|
||||
GODOT := tools/godot.sh
|
||||
|
||||
.PHONY: check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures discovery-check fuzz soak soak-selfcheck server-package-check
|
||||
.PHONY: check import parse test test-selfcheck smoke capture-test terrain-capture binaries verify-engine bot-matches match match-captures client-check client-captures hud-captures style-captures menu-captures chart-captures discovery-check fuzz soak soak-selfcheck server-package-check
|
||||
|
||||
## Everything that must pass before a push.
|
||||
check: verify-engine binaries parse test test-selfcheck smoke
|
||||
@@ -75,6 +75,11 @@ hud-captures: import
|
||||
menu-captures: import
|
||||
@for scene in menu_main menu_practice menu_join menu_settings menu_settings_mouse menu_pause menu_results; do tools/capture.sh $$scene captures/$$scene.png; done
|
||||
|
||||
## A11: the chart and minimap with the first tide forecast, and after it has risen
|
||||
## (captures/chart_*.png, about 2 min). Needs Docker. Look at them.
|
||||
chart-captures: import
|
||||
@for scene in chart_first chart_later; do tools/capture.sh $$scene captures/$$scene.png; done
|
||||
|
||||
## A1: the woodcut print pass on and off, side by side scenes (captures/style_*.png). Needs Docker.
|
||||
style-captures: import
|
||||
@for scene in style_hamlet style_hamlet_plain style_dock style_dock_plain; do tools/capture.sh $$scene captures/$$scene.png; done
|
||||
|
||||
@@ -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,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_"):
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://bn80hlfqxya7
|
||||
@@ -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
|
||||
@@ -0,0 +1 @@
|
||||
uid://b55xw4hlb313n
|
||||
@@ -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},
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://exbrsuso4xy
|
||||
@@ -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()
|
||||
@@ -0,0 +1 @@
|
||||
uid://cnm6ise52xj7h
|
||||
@@ -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)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ddoxk48b3guk1
|
||||
Reference in New Issue
Block a user