From 660332c32fdde77f2d5560a773ecddbf466359ca Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 15 Nov 2026 01:39:41 +0400 Subject: fix(ai): dispatch attacks after a scripted unit dies Match Handler(39) against the live logical-object registry and pass Problems0 attack orders to the existing task. The stock mission 20 regression exercises the branch with the checked warbot present and then removed. The original GOG AI query was called directly for present and missing IDs. Mission 20 completed 900 simulated seconds without a clan-script stop and started in the window with clean Vulkan validation. --- crates/fparkan-runtime/src/clan_ai_events.rs | 16 +++++ crates/fparkan-runtime/src/mission_events.rs | 91 ++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) (limited to 'crates') diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs index 0ecea127..6e844899 100644 --- a/crates/fparkan-runtime/src/clan_ai_events.rs +++ b/crates/fparkan-runtime/src/clan_ai_events.rs @@ -548,6 +548,16 @@ impl LoadedMissionState { .declarations .resolve_handler15_with_values(instruction, values) .map_err(|error| error.to_string())?; + if let (3, 3, Handler15TargetPayload::ByLogicId(target)) = + (order.word_1, order.word_2, order.target) + { + let patrol = self.unit_patrol.get_or_insert_with(crate::unit_patrol::UnitPatrol::scripted); + let accepted = crate::script_patrol::apply_attack_order( + patrol, &self.mission, &self.object_drafts, world, + order.word_0, target, + ).is_some(); + return Ok(Some(VarSetDefault::Dword(u32::from(accepted)))); + } if let (7, 3, Handler15TargetPayload::ByPlace { first, second }) = (order.word_1, order.word_2, order.target) { @@ -968,6 +978,12 @@ impl LoadedMissionState { } Ok(Some(VarSetDefault::Dword(1))) } + ScriptDispatchSelector::Handler(39) => { + let id = single_dword(&instruction.references, values) + .ok_or("Handler(39) requires one DWORD logical ID")?; + let exists = self.mission_events.has_live_logic_object(&self.mission, world, id); + Ok(Some(VarSetDefault::Dword(u32::from(exists)))) + } ScriptDispatchSelector::Handler(49) if instruction.references.is_empty() => { diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs index 67aea865..a00e449c 100644 --- a/crates/fparkan-runtime/src/mission_events.rs +++ b/crates/fparkan-runtime/src/mission_events.rs @@ -227,6 +227,20 @@ impl MissionEvents { )) } + pub(super) fn has_live_logic_object( + &self, + mission: &super::MissionDocument, + world: &World, + id: u32, + ) -> bool { + self.logic_objects(mission, world, id).any(|handle| { + registration_sequence(world, handle) + .ok() + .flatten() + .is_some() + }) + } + pub(super) fn issue_logic_id( &mut self, mission: &super::MissionDocument, @@ -854,6 +868,15 @@ impl LoadedMissionState { ); Ok(Some(count)) } + ScriptDispatchSelector::Handler(39) => { + let id = single_dword(instruction, values) + .ok_or("Handler(39) requires one DWORD logical ID")?; + Ok(Some(u32::from(mission_events.has_live_logic_object( + &self.mission, + world, + id, + )))) + } ScriptDispatchSelector::Handler(52) => { let id = single_dword(instruction, values) .ok_or("Handler(52) requires one DWORD operand")?; @@ -1071,6 +1094,74 @@ mod tests { WorldConfig, }; + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_clan_checks_for_live_unit_in_problems0() { + use crate::{EngineServices, MissionMode, MissionRequest, MissionStartupInput}; + use fparkan_vfs::DirectoryVfs; + use std::sync::Arc; + + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap(); + let mut engine = + crate::create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + crate::load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/CAMPAIGN/CAMPAIGN.05/Mission.01/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + + let loaded = engine.loaded.as_ref().unwrap(); + let unit = super::placed_logic_objects(&loaded.mission, &engine.world, 25) + .next() + .unwrap(); + let attackers = [2, 3, 23, 27, 28, 30].map(|id| { + super::placed_logic_objects(&loaded.mission, &engine.world, id) + .next() + .unwrap() + }); + let hero = super::placed_logic_objects(&loaded.mission, &engine.world, 12) + .next() + .unwrap(); + assert!(loaded + .mission_events + .has_live_logic_object(&loaded.mission, &engine.world, 25)); + crate::clan_ai_events::tick(&mut engine, 7_000); + let patrol = engine + .loaded + .as_ref() + .unwrap() + .unit_patrol + .as_ref() + .unwrap(); + assert_eq!(patrol.attack_target(attackers[0]), None); + request_delete(&mut engine.world, unit).unwrap(); + crate::clan_ai_events::tick(&mut engine, 14_000); + let loaded = engine.loaded.as_ref().unwrap(); + assert!(!loaded + .mission_events + .has_live_logic_object(&loaded.mission, &engine.world, 25)); + assert!(!loaded.mission_events.has_live_logic_object( + &loaded.mission, + &engine.world, + u32::MAX + )); + assert!(loaded.clan_ai_events.stops().next().is_none()); + let patrol = loaded.unit_patrol.as_ref().unwrap(); + assert!(attackers.into_iter().all(|handle| { + patrol + .attack_target(handle) + .is_some_and(|(target, _)| target == hero) + })); + } + #[test] fn exit_cylinder_includes_the_wall_and_caps() { let center = [10., 20., 30.]; -- cgit v1.2.3