From f3f5054641a3542e3154461f39a7a204cfd095ff Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 19:28:40 +0400 Subject: fix(ai): rule out unavailable building upgrades Check the class, initial stage and known research status of the next BuildDat scheme before treating Handler(58) as unresolved. Keep the existing coverage stub for candidates that still need full selection and a builder upgrade order. The native eligibility and research walks confirm both gates. The stock Two Fortresses window and 900-second simulation exercise the no-candidate branch. All 29 missions reach 900 seconds. --- crates/fparkan-runtime/src/clan_ai_events.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'crates/fparkan-runtime/src/clan_ai_events.rs') diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs index 7b663482..ee19f56e 100644 --- a/crates/fparkan-runtime/src/clan_ai_events.rs +++ b/crates/fparkan-runtime/src/clan_ai_events.rs @@ -1223,10 +1223,18 @@ impl LoadedMissionState { ))) } ScriptDispatchSelector::Handler(58) => { - single_dword(&instruction.references, values) + let index = single_dword(&instruction.references, values) .ok_or("Handler(58) requires a DWORD building index")?; - // shortcut: an unavailable upgrade catalog exposes no eligible buildings. - self.clan_ai_events.log_research_stub(clan, 58, &bundle.script_path); + let owner = OwnerId(clan as u16); + let units = self.mission_events.clan_units(world, owner, false); + let research = vfs.zip(self.clan_ai_events.research_catalogs.get(&clan).map(|catalog| &catalog.table)); + if crate::building_upgrade::needs_upgrade_selection( + world, units, &self.object_drafts, &self.build_categories, research, index, + |row| self.free_research.learned.contains(&(owner, row)), + ) { + // shortcut: eligible upgrades still need selection and a builder order. + self.clan_ai_events.log_research_stub(clan, 58, &bundle.script_path); + } Ok(Some(VarSetDefault::Dword(u32::MAX))) } ScriptDispatchSelector::Handler(handler @ (37 | 47 | 67)) => { -- cgit v1.2.3