diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 19:20:27 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 19:20:27 +0300 |
| commit | 71ae57fb95805e6262aa70fc4890dcad91ab3ea1 (patch) | |
| tree | 754c2e7d3d2a4fa3bb6518534f4a98a0c636d507 /crates/fparkan-runtime/src/clan_script_init.rs | |
| parent | f61cc5fd7dda6a76b843b36013795f52b03fae7e (diff) | |
| download | fparkan-71ae57fb95805e6262aa70fc4890dcad91ab3ea1.tar.xz fparkan-71ae57fb95805e6262aa70fc4890dcad91ab3ea1.zip | |
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.
Diffstat (limited to 'crates/fparkan-runtime/src/clan_script_init.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/clan_script_init.rs | 52 |
1 files changed, 52 insertions, 0 deletions
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 + ); + } } |
