diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-25 13:21:31 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-25 13:21:31 +0300 |
| commit | 7962aa90e3a3b70d6ed5bd5c6a4ad991b3bc0199 (patch) | |
| tree | 4d8e2c37409cb25f654a1db8b956ca6c83fc2260 /crates/fparkan-runtime/src/script_host.rs | |
| parent | 2656cca01b65745e9e6aa7b11d80414039e4cc67 (diff) | |
| download | fparkan-7962aa90e3a3b70d6ed5bd5c6a4ad991b3bc0199.tar.xz fparkan-7962aa90e3a3b70d6ed5bd5c6a4ad991b3bc0199.zip | |
feat(ai): deliver clan script notifications to the player
Handle clan Handler(30) through the same host command and first-message
state as the Mission event. Carry clan notices in FrameResult and pass
them to the existing text and voice queues without changing the Mission
tick counter. Extract shared host dispatch and app presentation modules.
Execute ai.dll RVA 0xc266 with the original hash guard: clan contexts 0
and 2 call the global host as (0, MESSAGE_INFO, index), reading live
varset cells. Extend the licensed stock Convoy test to require message 0
after the delayed attack, and test shared first-message and AutoDemo
behavior. Repeated native message UI branches remain explicit debt.
Validate fmt, workspace check/tests, licensed stock-start test, release
simulation and the mission window. Clock replay checks message delivery,
not full mission completion.
Diffstat (limited to 'crates/fparkan-runtime/src/script_host.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/script_host.rs | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/script_host.rs b/crates/fparkan-runtime/src/script_host.rs new file mode 100644 index 00000000..d87f6348 --- /dev/null +++ b/crates/fparkan-runtime/src/script_host.rs @@ -0,0 +1,115 @@ +use crate::{ + apply_recovered_script_host_callback, mission_events::MissionEvents, MissionMode, + MissionNotice, MissionScriptHostEffect, MissionScriptOutcome, +}; +use fparkan_script::VmHostCallbackCommand; + +pub(super) fn apply( + mode: MissionMode, + status: &mut u32, + outcome: &mut MissionScriptOutcome, + events: &mut MissionEvents, + command: VmHostCallbackCommand, + notices: &mut Vec<MissionNotice>, +) -> Result<(), String> { + if mode == MissionMode::AutoDemo { + return Ok(()); + } + let outcome_command = match command.first { + 0 => Some(command), + 1 => { + // shortcut: present the first message until the native repeated-message UI is wired. + if events.voiced_messages.insert(command.second) { + notices.push(MissionNotice::Information(command.second)); + } + None + } + 3..=5 => events + .objectives + .apply(command.first, command.second, notices)? + .then_some(VmHostCallbackCommand { + mode: 0, + first: 0, + second: 1, + }), + _ => return Err(format!("Handler(30) command {}", command.first)), + }; + if let Some(command) = outcome_command { + match apply_recovered_script_host_callback(mode, status, outcome, command) { + MissionScriptHostEffect::MissionCompleted => notices.push(MissionNotice::Completed), + MissionScriptHostEffect::MissionFailed => notices.push(MissionNotice::Failed), + MissionScriptHostEffect::NoChange => {} + MissionScriptHostEffect::Unhandled => { + return Err(format!("Handler(30) outcome {}", command.second)); + } + } + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn information_is_presented_once_across_script_callers() { + let mut events = MissionEvents::default(); + let mut status = 5; + let mut outcome = MissionScriptOutcome::Active; + let mut notices = Vec::new(); + for index in [0, 0, 1, 0, 1] { + apply( + MissionMode::SingleMission, + &mut status, + &mut outcome, + &mut events, + VmHostCallbackCommand { + mode: 0, + first: 1, + second: index, + }, + &mut notices, + ) + .unwrap(); + } + assert_eq!( + notices, + [MissionNotice::Information(0), MissionNotice::Information(1)] + ); + assert_eq!(outcome, MissionScriptOutcome::Active); + assert_eq!(status, 5); + } + + #[test] + fn autodemo_does_not_consume_an_information_message() { + let mut events = MissionEvents::default(); + let mut status = 5; + let mut outcome = MissionScriptOutcome::Active; + let mut notices = Vec::new(); + let command = VmHostCallbackCommand { + mode: 0, + first: 1, + second: 0, + }; + apply( + MissionMode::AutoDemo, + &mut status, + &mut outcome, + &mut events, + command, + &mut notices, + ) + .unwrap(); + assert!(notices.is_empty()); + apply( + MissionMode::SingleMission, + &mut status, + &mut outcome, + &mut events, + command, + &mut notices, + ) + .unwrap(); + assert_eq!(notices, [MissionNotice::Information(0)]); + } +} |
