fix(@projects/@magic-civilization): 🐛 adjust difficulty loading timing

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-04-18 21:56:13 -07:00
parent 39922d0dab
commit 31facca432
3 changed files with 28 additions and 32 deletions

View file

@ -1,5 +1,5 @@
{
"ai_difficulty": [
"difficulty": [
{
"level": 1,
"id": "easy",

View file

@ -524,11 +524,8 @@ func _process(_delta: float) -> void:
if not diff_env.is_empty():
GameState.game_settings["difficulty"] = diff_env
print("AutoPlay: AI_DIFFICULTY=%s applied" % diff_env)
GameState.apply_ai_difficulty()
# Per-player difficulty overrides for asymmetric matchups (p0-24).
# AI_DIFFICULTY_P0=<tier> and AI_DIFFICULTY_P1=<tier> each override
# that player's production/research multipliers independently.
_apply_per_player_difficulty_overrides()
# apply_ai_difficulty() + per-player overrides are deferred to
# wait_loading (after DataLoader.load_theme runs in loading_screen).
_state = "wait_loading"
_frame = 0
if _frame > 120:
@ -549,6 +546,10 @@ func _process(_delta: float) -> void:
# real clan assignments the Python per-clan aggregator
# (tools/autoplay-report.py) reads.
_write_meta()
# Apply difficulty modifiers NOW — DataLoader.load_theme ran
# during loading_screen so get_data("difficulty") is populated.
GameState.apply_ai_difficulty()
_apply_per_player_difficulty_overrides()
_state = "fix_start"
_frame = 0
if _frame > 600:
@ -799,10 +800,6 @@ func _apply_per_player_difficulty_overrides() -> void:
# DataLoader.get_data("difficulty") returns {"easy": {full entry}, "normal": {...}, ...}
# already keyed by id — no wrapping "ai_difficulty" array at this level.
var diff_data: Dictionary = DataLoader.get_data("difficulty")
print("AutoPlay: per_player_override entry: diff_data.size=%d P0='%s' P1='%s'" % [
diff_data.size(),
EnvConfig.get_var("AI_DIFFICULTY_P0", "__unset__"),
EnvConfig.get_var("AI_DIFFICULTY_P1", "__unset__")])
if diff_data == null or diff_data.is_empty():
return
# Use a fixed upper bound — this runs before loading_screen.gd populates

View file

@ -228,28 +228,27 @@ func apply_ai_difficulty() -> void:
var diff_data: Dictionary = DataLoader.get_data("difficulty") as Dictionary
if diff_data == null or diff_data.is_empty():
return
var levels: Array = diff_data.get("ai_difficulty", []) as Array
for entry: Dictionary in levels:
if entry.get("id", "") == diff_id:
var mods: Dictionary = entry.get("ai_modifiers", {}) as Dictionary
ai_difficulty_modifier = float(mods.get("production_mult", 1.0))
ai_research_modifier = float(mods.get("research_mult", 1.0))
ai_starting_gold_bonus = int(mods.get("starting_gold_bonus", 0))
ai_extra_starting_units = int(mods.get("extra_starting_units", 0))
ai_extra_unit_id = str(mods.get("extra_unit_id", "warrior"))
print(
(
"GameState: difficulty=%s prod=%.2f research=%.2f gold_bonus=%d extra_units=%d"
% [
diff_id,
ai_difficulty_modifier,
ai_research_modifier,
ai_starting_gold_bonus,
ai_extra_starting_units
]
)
)
return
var entry: Dictionary = diff_data.get(diff_id, {}) as Dictionary
if entry.is_empty():
return
var mods: Dictionary = entry.get("ai_modifiers", {}) as Dictionary
if mods.is_empty():
return
ai_difficulty_modifier = float(mods.get("production_mult", 1.0))
ai_research_modifier = float(mods.get("research_mult", 1.0))
ai_starting_gold_bonus = int(mods.get("starting_gold_bonus", 0))
ai_extra_starting_units = int(mods.get("extra_starting_units", 0))
ai_extra_unit_id = str(mods.get("extra_unit_id", "warrior"))
print(
"GameState: difficulty=%s prod=%.2f research=%.2f gold_bonus=%d extra_units=%d"
% [
diff_id,
ai_difficulty_modifier,
ai_research_modifier,
ai_starting_gold_bonus,
ai_extra_starting_units
]
)
func get_max_event_tier() -> int: