From 71ae57fb95805e6262aa70fc4890dcad91ab3ea1 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 14 Nov 2026 20:20:27 +0400 Subject: feat(ai): reserve placed units for scenario orders Handler(51) changes availability in the owning clan, matching a direct ai.dll call. Reserved units stay out of the free capturer query. Campaign mission 7 now finishes Init and mission 13 reserves the addressed unit. --- crates/fparkan-runtime/src/clan_script_init.rs | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'crates/fparkan-runtime/src/clan_script_init.rs') diff --git a/crates/fparkan-runtime/src/clan_script_init.rs b/crates/fparkan-runtime/src/clan_script_init.rs index f9c23498..98d899c2 100644 --- a/crates/fparkan-runtime/src/clan_script_init.rs +++ b/crates/fparkan-runtime/src/clan_script_init.rs @@ -1,6 +1,29 @@ use crate::script_patrol::ScriptPatrol; use fparkan_script::{ScriptDispatchSelector, ScriptInstruction, VarSet, VarSetDefault}; +pub(super) enum InitOrder { + Patrol(ScriptPatrol), + Reserve { + clan: usize, + id: u32, + reserved: bool, + }, +} + +pub(super) fn reservation( + instruction: &ScriptInstruction, + values: &[VarSetDefault], +) -> Option<(u32, bool)> { + if instruction.dispatch_selector() != ScriptDispatchSelector::Handler(51) + || instruction.header_words[1] != u32::MAX + || instruction.header_words[3] != u32::MAX + { + return None; + } + let (id, flag) = instruction.dword_pair(values)?; + Some((id, flag != 0)) +} + pub(super) fn patrol_order( declarations: &VarSet, instruction: &ScriptInstruction, @@ -40,4 +63,33 @@ mod tests { instruction.header_words[1] = 0; assert_eq!(stubbed_handler(&instruction), None); } + + #[test] + fn reservation_reads_logical_id_and_treats_every_nonzero_flag_as_set() { + let instruction = ScriptInstruction { + header_words: [51, u32::MAX, u32::MAX, u32::MAX, 6, 2, u32::MAX], + references: vec![1, 0], + }; + assert_eq!( + reservation( + &instruction, + &[VarSetDefault::Dword(2), VarSetDefault::Dword(12)] + ), + Some((12, true)) + ); + assert_eq!( + reservation( + &instruction, + &[VarSetDefault::Dword(0), VarSetDefault::Dword(13)] + ), + Some((13, false)) + ); + assert_eq!( + reservation( + &instruction, + &[VarSetDefault::FloatBits(0), VarSetDefault::Dword(13)] + ), + None + ); + } } -- cgit v1.2.3