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-runtime/src/construction.rs | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'crates/fparkan-runtime/src/construction.rs') diff --git a/crates/fparkan-runtime/src/construction.rs b/crates/fparkan-runtime/src/construction.rs index 3f347d9f..571617b3 100644 --- a/crates/fparkan-runtime/src/construction.rs +++ b/crates/fparkan-runtime/src/construction.rs @@ -124,6 +124,7 @@ pub(super) fn order( terrain: &fparkan_terrain::TerrainWorld, mission: &crate::MissionDocument, drafts: &[crate::MissionObjectDraft], + mine_sites: &[crate::mining::MineSite], ores: &[crate::BehaviorOreState], research: &crate::research::FreeResearch, vfs: Option<&dyn fparkan_vfs::Vfs>, @@ -146,9 +147,17 @@ pub(super) fn order( .iter() .find(|ore| ore.handle == builder && ore.class_flags == BUILDER_CLASS) .ok_or("unit has no builder ore state")?; - let slot = construction - .available_slot(world, drafts, class) - .ok_or("no free prepared building slot")?; + let slot = if class == crate::mining::MINE_CLASS { + mine_sites.iter().find_map(|site| { + let point = [site.position[0], site.position[1]].map(|axis| axis.trunc() as i64 as u32); + let id = site.control.as_ref()?.original_id?; + (point == xy && site.live_mine(world).is_none()).then_some(id.0 as usize) + }) + } else { + construction.available_slot(world, drafts, class) + } + .filter(|&slot| !construction.tasks.iter().any(|task| task.slot == slot)) + .ok_or("no free prepared building slot")?; let table = crate::research::load_technology_table( vfs.ok_or("no clan technology provider")?, mission, @@ -263,8 +272,17 @@ fn complete( .behavior_profiles .iter() .position(|profile| profile.original_id == id); - let control = - mission.construction.controls[task.slot - mission.construction.first_slot].clone(); + let control = if class == crate::mining::MINE_CLASS { + mission + .mine_sites + .iter() + .filter_map(|site| site.control.as_ref()) + .find(|control| control.original_id == Some(id)) + .cloned() + .ok_or_else(|| crate::EngineError::Production("mine control is unavailable".into()))? + } else { + mission.construction.controls[task.slot - mission.construction.first_slot].clone() + }; let handle = spawn_prepared_unit( world, mission, @@ -461,6 +479,7 @@ mod tests { &mission.terrain, &mission.mission, &mission.object_drafts, + &mission.mine_sites, &mission.behavior_ore_states, &mission.free_research, Some(vfs.as_ref()), -- cgit v1.2.3