refactor(generation): ♻️ Refactor procedural generation algorithms for hydrology, map placement, and start positions to enhance efficiency and variety
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
002c64eb50
commit
84ba7e8217
4 changed files with 21 additions and 10 deletions
|
|
@ -24,9 +24,13 @@ static func generate_drainage(
|
|||
var fill: Dictionary = _depression_fill(game_map, elevation, params)
|
||||
var acc: Dictionary = _accumulate_flow(game_map, rainfall, fill.flow_dir, fill.topo_order)
|
||||
HydrologyRiversScript.detect_lakes(game_map, elevation, fill.filled_elev, params)
|
||||
HydrologyRiversScript.mark_rivers(game_map, acc, temperature, fill.flow_dir, fill.topo_order, params)
|
||||
HydrologyRiversScript.mark_rivers(
|
||||
game_map, acc, temperature, fill.flow_dir, fill.topo_order, params
|
||||
)
|
||||
HydrologyRiversScript.mark_deltas(game_map, acc, fill.flow_dir, params)
|
||||
HydrologyRiversScript.classify_sources(game_map, elevation, moisture, temperature, fill.flow_dir, params)
|
||||
HydrologyRiversScript.classify_sources(
|
||||
game_map, elevation, moisture, temperature, fill.flow_dir, params
|
||||
)
|
||||
for axial: Vector2i in acc:
|
||||
var t: Variant = game_map.tiles.get(axial)
|
||||
if t != null:
|
||||
|
|
|
|||
|
|
@ -91,7 +91,10 @@ func _get_wonder_candidates(game_map: RefCounted) -> Array[Vector2i]:
|
|||
var margin: int = 3
|
||||
for axial: Vector2i in game_map.tiles:
|
||||
var tile: Variant = game_map.tiles[axial]
|
||||
if BiomeRegistry.has_tag(tile.biome_id, "is_water") or BiomeRegistry.has_tag(tile.biome_id, "is_elevated"):
|
||||
if (
|
||||
BiomeRegistry.has_tag(tile.biome_id, "is_water")
|
||||
or BiomeRegistry.has_tag(tile.biome_id, "is_elevated")
|
||||
):
|
||||
continue
|
||||
var offset: Vector2i = HexUtilsScript.axial_to_offset(axial)
|
||||
if (
|
||||
|
|
@ -152,7 +155,8 @@ func place_resources(game_map: RefCounted, multiplier: float) -> void:
|
|||
var placed: int = 0
|
||||
var min_resource_distance: int = 2
|
||||
|
||||
# Build per-resource selection weights from quality: Q1->1.0, Q2->0.25, Q3->0.06, Q4->0.015, Q5->0.004
|
||||
# Build per-resource selection weights from quality:
|
||||
# Q1->1.0, Q2->0.25, Q3->0.06, Q4->0.015, Q5->0.004
|
||||
var res_weights: Array[float] = []
|
||||
for res: Dictionary in all_resources:
|
||||
var q: int = res.get("quality", 1)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ extends RefCounted
|
|||
|
||||
const HexUtilsScript = preload("res://engine/src/map/hex_utils.gd")
|
||||
|
||||
static var _classify_rules: Array = []
|
||||
static var _classify_rules_loaded: bool = false
|
||||
|
||||
|
||||
# -- Shape seed placement --
|
||||
|
||||
|
|
@ -147,10 +150,6 @@ static func _place_seeds_plus(
|
|||
# -- Public utility: climate-driven terrain classification --
|
||||
|
||||
|
||||
static var _classify_rules: Array = []
|
||||
static var _classify_rules_loaded: bool = false
|
||||
|
||||
|
||||
static func classify_terrain(temp: float, moisture: float, elevation: float) -> String:
|
||||
## Classify terrain from continuous climate values. Reads rules from climate_spec.json.
|
||||
## Called by climate system each turn. Returns a biome_id matching terrain.json entries.
|
||||
|
|
@ -163,7 +162,8 @@ static func classify_terrain(temp: float, moisture: float, elevation: float) ->
|
|||
for rule: Variant in _classify_rules:
|
||||
if not rule is Dictionary:
|
||||
continue
|
||||
# Simple single-field rule: { "field": "temperature", "op": "<", "value": 0.10, "terrain": "snow" }
|
||||
# Simple single-field rule: { "field": "temperature", "op": "<", "value": 0.10,
|
||||
# "terrain": "snow" }
|
||||
if rule.has("field"):
|
||||
var val: float = _classify_field_value(rule["field"], temp, moisture, elevation)
|
||||
if _classify_check_op(val, rule.get("op", ""), rule.get("value", 0.0)):
|
||||
|
|
|
|||
|
|
@ -278,7 +278,10 @@ func _score_all_start_candidates(
|
|||
continue
|
||||
if tile.is_natural_wonder():
|
||||
continue
|
||||
if BiomeRegistry.has_tag(tile.biome_id, "is_elevated") or BiomeRegistry.has_tag(tile.biome_id, "is_water"):
|
||||
if (
|
||||
BiomeRegistry.has_tag(tile.biome_id, "is_elevated")
|
||||
or BiomeRegistry.has_tag(tile.biome_id, "is_water")
|
||||
):
|
||||
continue
|
||||
var score: float = _score_start_position(game_map, axial, prefer_coast)
|
||||
if score > 0:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue