From 0da658fa6dfc7b2a052066561d904353532220ce Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 13:36:08 +0400 Subject: fix(ai): choose fast combat designs for factory orders Prepare a combat catalog entry for SELECT_FASTEST alongside SELECT_STRONGEST. Rank the fast choice using the projected Control forward limit and preserve catalog order on ties. The GOG selector picks 12hel1.dat from the initial scream catalog. Both newly built small factories in Third Part now complete that design from a stock start. --- crates/fparkan-runtime/src/production.rs | 73 ++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 17 deletions(-) (limited to 'crates/fparkan-runtime/src/production.rs') diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs index 957a9c5e..b33fbf1e 100644 --- a/crates/fparkan-runtime/src/production.rs +++ b/crates/fparkan-runtime/src/production.rs @@ -72,7 +72,7 @@ pub(super) struct Production { schemes: Vec, player_scheme_count: usize, customized: bool, - ai_schemes: Vec<(OwnerId, u32, NormalizedPath)>, + ai_schemes: Vec, controls: Vec, plants: Vec<(usize, u32)>, pending: VecDeque, @@ -170,7 +170,7 @@ impl Production { schemes: Vec, player_scheme_count: usize, customized: bool, - ai_schemes: Vec<(OwnerId, u32, NormalizedPath)>, + ai_schemes: Vec, controls: Vec, drafts: &[MissionObjectDraft], ) -> Result { @@ -577,21 +577,13 @@ pub(super) fn order_script_factory( .find(|&(_, handle, _)| handle == plant) .ok_or_else(|| production_error("script factory is unavailable"))?; let auxiliary = crate::clan_factory_schemes::AUXILIARY_CLASSES.contains(&class); - let use_catalog = (auxiliary && selection == crate::clan_factory_schemes::SELECT_FASTEST) - || (class == crate::boarding::WARBOT_CLASS - && selection == crate::clan_factory_schemes::SELECT_STRONGEST); - let ai_scheme = if use_catalog { - production - .ai_schemes - .iter() - .find_map(|(clan, kind, path)| (*clan == owner && *kind == class).then_some(path)) - } else { - None - }; + let ai_scheme = production.ai_schemes.iter().find(|design| { + design.owner == owner && design.class == class && design.selection == selection + }); let scheme = ai_scheme .and_then(|selected| { schemes_for_plant(mission, production, index) - .find(|&(_, path)| selected.as_str() == path) + .find(|&(_, path)| selected.path.as_str() == path) }) .or_else(|| { if auxiliary { @@ -824,6 +816,52 @@ mod tests { use fparkan_world::{set_transform, InputSnapshot, OriginalObjectId}; use std::sync::Arc; + #[test] + #[ignore = "requires licensed corpus"] + fn licensed_new_small_factories_build_the_fast_combat_design() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/Single.02/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + + let production = engine.production.as_ref().unwrap(); + for owner in [OwnerId(1), OwnerId(2)] { + let design = production + .ai_schemes + .iter() + .find(|design| { + design.owner == owner + && design.class == crate::boarding::WARBOT_CLASS + && design.selection == crate::clan_factory_schemes::SELECT_FASTEST + }) + .expect("eligible fast combat design"); + assert!( + design.path.as_str().ends_with("/12hel1.dat"), + "{}", + design.path.as_str() + ); + } + + let report = crate::simulate_mission_report(&mut engine, 180_000).unwrap(); + for clan in [1, 2] { + assert!( + report.first_factory_completion_ms.contains_key(&clan), + "clan {clan} did not build a warbot" + ); + } + } + #[test] #[ignore = "requires licensed corpus"] fn licensed_enemy_designs_leave_a_player_factory_slot_available() { @@ -1026,12 +1064,13 @@ mod tests { let cockpit = super::super::starting_cockpit(&engine).unwrap(); let factory = handle_by_original_id(&engine.world, OriginalObjectId(5)).unwrap(); let production = engine.production.as_ref().unwrap(); - let (owner, _, transport) = production + let design = production .ai_schemes .iter() - .find(|(_, class, _)| *class == crate::clan_factory_schemes::TRANSPORT_CLASS) + .find(|design| design.class == crate::clan_factory_schemes::TRANSPORT_CLASS) .expect("eligible AI transport"); - assert_eq!(*owner, OwnerId(1)); + assert_eq!(design.owner, OwnerId(1)); + let transport = &design.path; assert!(transport.as_str().ends_with("/sml_cargo.dat")); let transport_index = production .schemes -- cgit v1.2.3