From 68b1043749b58e39d671e3937eef73430cbc0ab8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 16:14:57 +0400 Subject: feat(ai): execute scripted mine construction Mission 29 stopped before choosing a deposit. Implement Handler(40)'s vacant deposit and weakest enemy mine policy, preserve its partial output writes and reserve the chosen site. Follow the script's tail transfer into BUILD_MINE with the original problem context and cells. Move event execution out of the large script module and report stops at the actual destination event. Use the existing prepared deposit slot for the builder's mine order. Completion registers its controls, ore buffer and logical ID with the regular resource loop. Track mine queries by clan, target and coordinates in --sim-report. Validation: fmt, workspace check/tests; licensed stock-start tests construct a working mine, collect ore and subsequently construct a working factory. Calls to GOG ai.dll confirm mine choices/output writes and VM event transfer behavior. The 900-second stock mission now stops only at the research transition 8. Window validation reaches mine creation from the stock start; construction animation was outside the player's view and has not been accepted visually. Native ArealMap deposit binding, builder resupply and live BAS cuts remain open. --- crates/fparkan-script/src/lib.rs | 86 +--------------------------------------- 1 file changed, 2 insertions(+), 84 deletions(-) (limited to 'crates/fparkan-script/src/lib.rs') diff --git a/crates/fparkan-script/src/lib.rs b/crates/fparkan-script/src/lib.rs index 311334ef..60b3a9d7 100644 --- a/crates/fparkan-script/src/lib.rs +++ b/crates/fparkan-script/src/lib.rs @@ -5,6 +5,8 @@ //! deliberately does not implement a general bytecode VM. It contains a //! narrow executor for confirmed event instructions and bounded FML expressions. +mod event_execution; + use fparkan_binary::{checked_allocation_len, Cursor, DecodeError, Limits}; use std::sync::Arc; @@ -1133,90 +1135,6 @@ impl VarSet { }) } - /// Executes an event whose host can return DWORD and float values and update - /// variables passed as output operands. - /// - /// # Errors - /// - /// Returns the first unsupported instruction, including a result type mismatch. - pub fn execute_event_prefix( - &self, - event: &ScriptEvent, - formulas: Option<&FormulaTable>, - values: &mut [VarSetDefault], - mut host: impl FnMut( - &ScriptInstruction, - &mut [VarSetDefault], - ) -> Result, String>, - ) -> Result<(), (usize, String)> { - let mut conditions = Vec::new(); - let mut pc = 0; - while let Some(instruction) = event.instructions.get(pc) { - let index = pc; - pc += 1; - match advance_condition(&mut conditions, instruction, values) - .map_err(|()| (index, "unsupported comparison operands".into()))? - { - EventInstruction::Skip => continue, - EventInstruction::Return => break, - EventInstruction::Execute => {} - } - let control = instruction.header_words[3]; - if control == 3 && instruction.dispatch_selector() == ScriptDispatchSelector::Sentinel { - let &[target] = instruction.references.as_slice() else { - return Err((index, "jump requires one instruction index".into())); - }; - pc = target as usize; - if pc <= index || pc >= event.instructions.len() { - return Err((index, format!("unsupported jump to instruction {target}"))); - } - conditions.clear(); - continue; - } - if instruction.dispatch_selector() != ScriptDispatchSelector::Sentinel { - if control != u32::MAX { - return Err((index, format!("unsupported handler control {control}"))); - } - let target = instruction.header_words[1]; - if target != u32::MAX && values.get(target as usize).is_none() { - return Err((index, format!("unsupported result target {target}"))); - } - let result = host(instruction, values).map_err(|reason| (index, reason))?; - if let Some(cell) = values.get_mut(target as usize) { - *cell = match (*cell, result) { - (VarSetDefault::Dword(_), Some(result @ VarSetDefault::Dword(_))) - | ( - VarSetDefault::FloatBits(_), - Some(result @ VarSetDefault::FloatBits(_)), - ) => result, - (VarSetDefault::Dword(_), None) => VarSetDefault::Dword(0), - _ => return Err((index, format!("unsupported result target {target}"))), - }; - } - continue; - } - match self - .resolve_assignment(instruction, formulas, values) - .map_err(|error| (index, error.to_string()))? - { - InitInstructionResolution::Executed(writes) => { - for write in writes { - *values.get_mut(write.index as usize).ok_or_else(|| { - ( - index, - format!("varset index {} is out of bounds", write.index), - ) - })? = write.value; - } - } - InitInstructionResolution::Unsupported(error) => { - return Err((index, error.to_string())) - } - } - } - Ok(()) - } - /// Resolves the fixed-width, corpus-proven operands of GOG `Handler(15)`. /// /// Static analysis of `ai.dll` at `0x10008054` shows four DWORD slots, -- cgit v1.2.3