W2: Procedural island generator
Island.generate(seed) builds a 513 x 513 heightfield (2 m spacing, the whole 1,024 m world) from the match seed's "worldgen" stream: a warped coastline, a coastal shelf and interior dome, two to four summits joined by ridges, rolling and rocky detail, and flattened marsh in wet lowland. Land is scaled so the tallest summit lands between ISLAND_PEAK_MIN and ISLAND_PEAK_MAX, under the last tide. Each sample gets an elevation band (sea, beach, marsh, forest, highland, summit) for terrain materials. - Simulation generates the island unless a test supplies its own ground, and spawns players on dry land until the drop arrives. - The headless server logs world_hash in its start line. - Island.heightmap_hash() is SHA-256 over millimetre heights and bands. - tools/island_map.gd draws a top-down map with tide contours. - New island constants in tuning.gd; GDD gains an island section. Tests: a 100-seed sweep checks generation time (slowest 617 ms against 5 s), land area, at least two distinct high points, walkable land, bands, and that no more than 3% of dry land is cut off at sea levels 0 and 8 m (worst seen 0.87%). A separate server process given only the seed must log the same heightmap hash. Closes #9 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+18
-3
@@ -6,12 +6,15 @@ class_name Simulation
|
||||
extends RefCounted
|
||||
|
||||
const SECONDS_PER_TICK: float = 1.0 / Tuning.TICK_RATE_HZ
|
||||
const SPAWN_ATTEMPTS: int = 64
|
||||
|
||||
var tick: int = 0
|
||||
var entities: EntityRegistry = EntityRegistry.new()
|
||||
var rng: SimRng
|
||||
## Terrain and solids. Flat until the island generator provides a heightfield.
|
||||
var ground: SimGround = SimGround.flat(0.0)
|
||||
## Terrain and solids. The island's heightfield unless a test supplied its own ground.
|
||||
var ground: SimGround
|
||||
## The generated island, or null when a test supplied its own ground.
|
||||
var island: Island
|
||||
|
||||
## Player entity ID -> { command tick -> PlayerCommand }
|
||||
var _pending: Dictionary = {}
|
||||
@@ -19,8 +22,14 @@ var _pending: Dictionary = {}
|
||||
var _players: Array[int] = []
|
||||
|
||||
|
||||
func _init(match_seed: int) -> void:
|
||||
## Generates the island from the seed, unless `world` is given. Tests that don't care
|
||||
## about terrain pass `SimGround.flat()` to skip worldgen.
|
||||
func _init(match_seed: int, world: SimGround = null) -> void:
|
||||
rng = SimRng.new(match_seed)
|
||||
if world == null:
|
||||
island = Island.generate(match_seed)
|
||||
world = island.ground
|
||||
ground = world
|
||||
|
||||
|
||||
## Adds a player at a seeded spawn position and returns its entity ID.
|
||||
@@ -30,6 +39,12 @@ func add_player() -> int:
|
||||
var size: float = Tuning.WORLD_SIZE_METRES
|
||||
var x: float = spawn.randf() * size
|
||||
var z: float = spawn.randf() * size
|
||||
# Until the drop arrives (W7), spawn on dry land above the beach when there is any.
|
||||
for _attempt: int in SPAWN_ATTEMPTS:
|
||||
if ground.terrain_height(x, z) > Tuning.ISLAND_BEACH_TOP:
|
||||
break
|
||||
x = spawn.randf() * size
|
||||
z = spawn.randf() * size
|
||||
player.position = Vector3(x, ground.terrain_height(x, z), z)
|
||||
player.on_ground = true
|
||||
player.health = Tuning.PLAYER_MAX_HEALTH
|
||||
|
||||
Reference in New Issue
Block a user