From 7962aa90e3a3b70d6ed5bd5c6a4ad991b3bc0199 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 14:21:31 +0400 Subject: 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. --- crates/fparkan-runtime/src/script_host.rs | 115 ++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 crates/fparkan-runtime/src/script_host.rs (limited to 'crates/fparkan-runtime/src/script_host.rs') 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, +) -> 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)]); + } +} -- cgit v1.2.3