diff --git a/packages/engine-ts/src/ClimatePhysics.generated.ts b/packages/engine-ts/src/ClimatePhysics.generated.ts index 69c77a8f..a9049ecb 100644 --- a/packages/engine-ts/src/ClimatePhysics.generated.ts +++ b/packages/engine-ts/src/ClimatePhysics.generated.ts @@ -600,63 +600,71 @@ export class ClimatePhysics { } private stepTerrainEvolution(grid: GridState): void { - const { tiles } = grid - const up_thresh = this.p('quality_up_threshold', 10) - const down_thresh = this.p('quality_down_threshold', 5) + const { tiles, width: w, height: h } = grid + let up_thresh = Math.floor((this.params as any)["quality_up_threshold"] ?? 10) + let down_thresh = Math.floor((this.params as any)["quality_down_threshold"] ?? 5) - for (let i = 0; i < tiles.length; i++) { - const tile = tiles[i] - const tid = tile.biome_id + for (let i = 0; i < tiles.length; i++) { + const tile = tiles[i] + const { col, row } = tile + let tid = tile.biome_id - if (tile.is_natural_wonder) continue + if (tile.is_natural_wonder) { + continue - // Water freezing/thawing — ice forms below freeze threshold, thaws above - const freezeTemp = this.p('water_freeze_threshold', 0.12) - const thawTemp = freezeTemp + 0.03 // hysteresis prevents oscillation - const isWater = tid === 'ocean' || tid === 'coast' || tid === 'lake' || tid === 'inland_sea' - if (isWater) { - if (tile.temperature < freezeTemp) { - tile.original_biome_id = tid - tile.biome_id = 'ice' + } + // Water freezing/thawing + let freeze_temp = (this.params as any)["water_freeze_threshold"] ?? 0.12 + let thaw_temp = freeze_temp + 0.03 + let is_water = ( tid === "ocean" || tid === "coast" || tid === "lake" || tid === "inland_sea" ) + if (is_water) { + if (tile.temperature < freeze_temp) { + tile.original_biome_id = tid + tile.biome_id = "ice" + tile.quality = 1 + tile.quality_progress = 0 + } + continue + } + if (tid === "ice") { + if (tile.temperature > thaw_temp && tile.original_biome_id !== "") { + tile.biome_id = tile.original_biome_id + tile.original_biome_id = "" + tile.quality = 1 + tile.quality_progress = 0 + } + continue + + } + if (tid === "volcano") { + continue + + } + let ideal = idealTerrain(tile, this.spec) + + if (ideal === tid) { + tile.quality_progress += 1 + if (tile.quality_progress >= up_thresh) { + tile.quality_progress = 0 + if (tile.quality < 5) { + tile.quality += 1 + } else { + tile.quality_progress -= 1 + if (tile.quality_progress <= -down_thresh) { + tile.quality_progress = 0 + if (tile.quality > 1) { + tile.quality -= 1 + } else { + tile.biome_id = ideal tile.quality = 1 tile.quality_progress = 0 - } - continue - } - if (tid === 'ice') { - if (tile.temperature > thawTemp && tile.original_biome_id) { - tile.biome_id = tile.original_biome_id - tile.original_biome_id = '' - tile.quality = 1 - tile.quality_progress = 0 - } - continue - } - if (tid === 'volcano') continue - - const ideal = idealTerrain(tile, this.spec) - - if (ideal === tid) { - tile.quality_progress += 1 - if (tile.quality_progress >= up_thresh) { - tile.quality_progress = 0 - if (tile.quality < 5) tile.quality += 1 - } - } else { - tile.quality_progress -= 1 - if (tile.quality_progress <= -down_thresh) { - tile.quality_progress = 0 - if (tile.quality > 1) { - tile.quality -= 1 - } else { - tile.biome_id = ideal - tile.quality = 1 - tile.quality_progress = 0 - } } } } + } + } + } } private stepGlobalStats(grid: GridState): void { diff --git a/tools/sprite-generation/sprites.db-shm b/tools/sprite-generation/sprites.db-shm index c843a1c1..34566726 100644 Binary files a/tools/sprite-generation/sprites.db-shm and b/tools/sprite-generation/sprites.db-shm differ diff --git a/tools/sprite-generation/sprites.db-wal b/tools/sprite-generation/sprites.db-wal index 3c1902a8..a129d0c7 100644 Binary files a/tools/sprite-generation/sprites.db-wal and b/tools/sprite-generation/sprites.db-wal differ diff --git a/tools/transpile-engine/transpile.py b/tools/transpile-engine/transpile.py index 11da0be9..7a892daf 100644 --- a/tools/transpile-engine/transpile.py +++ b/tools/transpile-engine/transpile.py @@ -183,7 +183,7 @@ METHOD_MAP = [ ("_update_lake_evaporation", "stepLakeEvaporation", "private"), ("_update_deep_earth_water", "stepDeepEarthWater", "private"), ("_update_precipitation", "stepPrecipitation", "private"), - ("_check_terrain_evolution", "stepTerrainEvolution", "HAND_WRITTEN"), + ("_check_terrain_evolution", "stepTerrainEvolution", "private"), ("_compute_global_stats", "stepGlobalStats", "private"), ("_clear_magic_deltas", "stepClearDeltas", "private"), ] @@ -918,9 +918,6 @@ def assemble(fns: dict[str, dict[str, str]]) -> str: if gd_name == "_apply_aerosol_forcing": parts.append(_emit_aerosol_forcing()) # hand-written — too complex for generic transpilation continue - if gd_name == "_check_terrain_evolution": - parts.append(_emit_terrain_evolution()) # hand-written — transpiler mishandles nested if/else - continue if gd_name in climate_fns: body = climate_fns[gd_name] ts_body = transform_method_body(body, gd_name, defaults=CLIMATE_DEFAULTS, extra_removals=EXTRA_REMOVALS)