From 2796bdcc148e39a033b5f389b83dcfbfe0a3e261 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 16:26:49 +0400 Subject: fix(ai): recognize newly built labs in research queries Handler(41) searched only the initial mission objects. A constructed lab has an issued logical ID, so the stub returned missing-object ERROR and sent the script into an unsupported ST_SOLVING transition. Resolve the lab through the live logical roster: an unloaded catalog returns false and the original script finishes the request without inventing a research job. Validation: fmt, workspace check/tests and an ignored stock-start regression build a lab, exercise 41 and confirm no script stop or granted technology. GOG ai.dll calls verify static/dynamic IDs, missing labs, cold catalogs and backend acceptance. A stock window replay reaches the lab and 41 without the old stop; the lab itself is outside the player's view. All 29 stock missions complete 900-second reports with successful exits and no Init, Mission or clan-script hard stops. Explicit research and gameplay stubs remain counted. Research catalog 43 and actual research dispatch remain explicit stubs. This coverage-blocker fix follows the visible scripted-mine construction change. --- crates/fparkan-runtime/src/clan_ai_events.rs | 2 +- crates/fparkan-runtime/src/research.rs | 46 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs index ac45745e..911392f6 100644 --- a/crates/fparkan-runtime/src/clan_ai_events.rs +++ b/crates/fparkan-runtime/src/clan_ai_events.rs @@ -1042,7 +1042,7 @@ impl LoadedMissionState { ScriptDispatchSelector::Handler(41) if problem.is_some() => { let id = single_dword(&instruction.references, values) .ok_or("Handler(41) requires a laboratory logical ID")?; - let exists = crate::mission_events::placed_logic_objects( + let exists = self.mission_events.logic_objects( &self.mission, world, id, diff --git a/crates/fparkan-runtime/src/research.rs b/crates/fparkan-runtime/src/research.rs index 94f5d55a..2ee36abb 100644 --- a/crates/fparkan-runtime/src/research.rs +++ b/crates/fparkan-runtime/src/research.rs @@ -170,6 +170,52 @@ mod tests { use fparkan_vfs::DirectoryVfs; use fparkan_world::{set_transform, OriginalObjectId}; + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_new_lab_rejects_an_unloaded_catalog_without_stopping_the_script() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap(); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/Single.02/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + for now in (0..=900_000).step_by(100) { + frame(&mut engine, now).unwrap(); + } + let loaded = engine.loaded.as_ref().unwrap(); + let lab = loaded + .object_drafts + .iter() + .skip(loaded.mission.objects.len()) + .filter(|draft| draft.unit_dat_header_flags == Some(LAB_CLASS)) + .find_map(|draft| handle_by_original_id(&engine.world, draft.original_id?)) + .unwrap(); + let id = loaded + .mission_events + .logic_id(&loaded.mission, &engine.world, lab) + .unwrap(); + assert!(loaded + .mission_events + .logic_objects(&loaded.mission, &engine.world, id) + .any(|handle| handle == lab)); + assert!(loaded + .clan_ai_events + .research_status_stubs() + .any(|(clan, handler, count)| clan == 1 && handler == 41 && count > 0)); + assert!(loaded.clan_ai_events.stops().next().is_none()); + assert!(loaded.free_research.pending.is_none()); + assert!(loaded.free_research.learned.is_empty()); + } + #[test] #[ignore = "requires licensed corpus"] fn licensed_teleport_lab_researches_the_available_turret() { -- cgit v1.2.3