## Capture scenario for the sea, sky and weather (A6), on seed 2's island in the real ## MatchView, with the tide set as the server would have it: ## ## - tide_0: the first tide holding, a clear afternoon. tide_1 to tide_7: just after ## each phase's rise, the storm building and the light lowering. All from one camera ## out at sea, looking up one slope, so the climbing waterline is compared directly. ## - shore_calm and shore_gale: standing on the beach at the first tide, and on the ## last land after the fifth rise, looking along the waterline: foam, chop, rain and ## the lowering light. (Seed 2's highest summit goes under at the sixth rise, so ## tide_6 and tide_7 show only sea over where the island was.) ## - underwater: below the surface just off that beach, looking up the slope. extends Node3D @export var stage: String = "tide_0" @export var match_seed: int = 2 var sim: Simulation var view: MatchView func _ready() -> void: sim = Simulation.new(match_seed) sim.start_tide() var levels: PackedFloat32Array = sim.tide.levels var after_rise: int = 0 if stage.begins_with("tide_"): after_rise = stage.trim_prefix("tide_").to_int() elif stage == "shore_gale": # The last land: on most islands the next rise covers the highest summit. after_rise = Tide.phase_count() - 2 var elapsed: int = _elapsed_after(after_rise) sim.tide = Tide.new(sim.tick - elapsed, levels) sim.set_sea_level(sim.tide.level_at(sim.tick)) var shore: Array = _shore(sim.sea_level) var edge: Vector3 = shore[0] var inland: Vector3 = shore[1] view = MatchView.new() view.setup(sim, 0) add_child(view) view.sync() if stage.begins_with("tide_"): # Out at sea, looking in at this tide's waterline and the land above it. var eye: Vector3 = edge - inland * 150.0 + Vector3(0.0, 55.0, 0.0) var target: Vector3 = edge + inland * 70.0 target.y = sim.ground.terrain_height(target.x, target.z) view.look_from(eye, target) elif stage == "underwater": # Out from the waterline until the water is a few metres deep. var under: Vector3 = edge for _step: int in 200: if sim.ground.terrain_height(under.x, under.z) < sim.sea_level - 4.0: break under -= inland * 2.0 under.y = sim.sea_level - 1.8 var look: Vector3 = edge + inland * 20.0 look.y = sim.ground.terrain_height(look.x, look.z) + 1.0 view.look_from(under, look) else: # On the beach, looking along the waterline and out a little. var along: Vector3 = inland.cross(Vector3.UP).normalized() var stand: Vector3 = edge + inland * 5.0 stand.y = sim.ground.terrain_height(stand.x, stand.z) + 1.7 var look: Vector3 = edge + along * 45.0 - inland * 30.0 look.y = sim.sea_level view.look_from(stand, look) view.sync() view.settle() ## Ticks from the tide's start to two seconds after phase `rises` - 1's rise ends, or ## into the first hold for 0. func _elapsed_after(rises: int) -> int: var at: float = 0.0 if rises == 0: return roundi(20.0 * Tuning.TICK_RATE_HZ) for index: int in rises: var phase: Dictionary = Tuning.TIDE_PHASES[index] at += float(phase["hold"]) + float(phase["rise"]) return roundi((at + 2.0) * Tuning.TICK_RATE_HZ) ## [where the sea at `level` meets the land, the unit direction inland from there], ## on the bearing from the highest summit whose shore rises most gently. func _shore(level: float) -> Array: var summit: Vector3 = sim.island.summits[0] var best: Array = [] var best_run: float = 0.0 for bearing: int in 24: var out: Vector3 = Vector3(cos(TAU * bearing / 24.0), 0.0, sin(TAU * bearing / 24.0)) var at: Vector3 = summit var step: int = 0 # Down to the sea itself, not a dry hollow below its level. while step < 500 and (sim.ground.terrain_height(at.x, at.z) > level or (sim.flood != null and not sim.flood.is_flooded(at.x, at.z))): at += out * 2.0 step += 1 if step >= 500 or step == 0: continue # How far inland before the land is 12 m above the water: longer is gentler. var run: float = 0.0 while run < 300.0 and sim.ground.terrain_height(at.x - out.x * run, at.z - out.z * run) < level + 12.0: run += 2.0 if run > best_run: best_run = run best = [Vector3(at.x, level, at.z), -out] return best if not best.is_empty() else [Vector3(summit.x, level, summit.z), Vector3.FORWARD]