From bef4fbab7701a51945ed93357babe12b416bb9a8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 18:06:07 +0400 Subject: feat(ai): execute laboratory research from clan scripts Clan laboratories accept the selected DAT project, request power and ore, accumulate native research progress, and publish learned technologies to construction and production. Research requests wait for the live laboratory; newly built objects are no longer mistaken for destroyed targets. Behavior.dll task 0x2f730 was called with paid and free work under x87 0x007f. The stock Single.02 regression checks both completed technologies and keeps the request pending while the laboratory is busy. Workspace fmt/check/tests, the 29-mission 900-second corpus, and the Vulkan window check pass. Dependent availability and free child propagation remain explicit script_research_unlock_stub counters; candidate properties 65 and policy 69 remain open. This does not close G7 or establish live AI chronology parity. --- crates/fparkan-runtime/src/clan_ai_events.rs | 38 +++++++++++++++++----------- 1 file changed, 23 insertions(+), 15 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 57de496d..3b3bb708 100644 --- a/crates/fparkan-runtime/src/clan_ai_events.rs +++ b/crates/fparkan-runtime/src/clan_ai_events.rs @@ -20,6 +20,7 @@ const ATTACK_UNIT: u32 = 13; const OPTIMAL_TRANSPORT: u32 = 4; const BUILDING_NEEDED: u32 = 3; const MINE_NEEDED: u32 = 1; +const MAKE_RESEARCH: u32 = 10; pub(super) struct ScriptFactoryOrder { pub owner: OwnerId, @@ -89,6 +90,7 @@ pub(super) fn tick(engine: &mut crate::Engine, now_ms: u32) -> Vec Vec { solving = true @@ -936,14 +941,14 @@ impl LoadedMissionState { }; let key = problem.as_ref().expect("condition requires a problem").key; let condition = match (action, mode) { - (2, 0) if matches!(key.word_0, BUILDING_NEEDED | MINE_NEEDED) || (key.word_0 == OPTIMAL_TRANSPORT && solving) => { + (2, 0) if matches!(key.word_0, BUILDING_NEEDED | MINE_NEEDED | MAKE_RESEARCH) || (key.word_0 == OPTIMAL_TRANSPORT && solving) => { let unit = assignment.filter(|&unit| self.mission_events .logic_objects(&self.mission, world, id).any(|handle| handle == unit)) .ok_or("Handler(27) task wait requires the assigned unit")?; Some(Condition::TaskInactive(unit)) } - (1 | 3, 0) if matches!(key.word_0, 7 | 9) || (action == 1 && matches!(key.word_0, BUILDING_PROTECT | ATTACK_UNIT)) => { - let target = crate::mission_events::placed_logic_objects( + (1 | 3, 0) if matches!(key.word_0, 7 | 9) || (action == 1 && matches!(key.word_0, BUILDING_PROTECT | ATTACK_UNIT | MAKE_RESEARCH)) => { + let target = self.mission_events.logic_objects( &self.mission, world, id ).next(); Some(if action == 1 { Condition::ObjectDestroyed(target) } else { @@ -1043,20 +1048,23 @@ 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 = self.mission_events.logic_objects( + let lab = self.mission_events.logic_objects( &self.mission, world, id, ) - .any(|handle| Some(handle) == assignment); - // shortcut: reject the order until the native laboratory research task is wired. - self.clan_ai_events - .log_research_stub(clan, 41, &bundle.script_path); - Ok(Some(VarSetDefault::Dword(if exists { - 0 - } else { - u32::MAX - }))) + .find(|handle| Some(*handle) == assignment); + let Some(lab) = lab else { return Ok(Some(VarSetDefault::Dword(u32::MAX))); }; + let result = crate::laboratory::order(&mut self.laboratories, &self.clan_ai_events.research_catalogs, + &self.object_drafts, &self.free_research, world, vfs, clan, lab, now_ms); + if let Err(reason) = &result { self.laboratories.rejected(clan, lab, reason); } + Ok(Some(VarSetDefault::Dword(u32::from(result.is_ok())))) + } + ScriptDispatchSelector::Handler(43) if crate::clan_script_init::research_catalog(instruction) => { + let vfs = vfs.ok_or("research VFS is unavailable")?; + let catalog = self.clan_ai_events.research_catalogs.get_mut(&clan).ok_or("research catalog is unavailable")?; + catalog.refresh(vfs)?; + Ok(None) } ScriptDispatchSelector::Handler(2) => { let (name, input) = problem_operands( -- cgit v1.2.3