diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 12:36:08 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 12:36:08 +0300 |
| commit | 0da658fa6dfc7b2a052066561d904353532220ce (patch) | |
| tree | 2641d1897f45258e3db9d546a32a3489a145694d /crates/fparkan-runtime/src/production.rs | |
| parent | fac74ba2d2487cb500d24de4223a0ffec50fa580 (diff) | |
| download | fparkan-0da658fa6dfc7b2a052066561d904353532220ce.tar.xz fparkan-0da658fa6dfc7b2a052066561d904353532220ce.zip | |
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.
Diffstat (limited to 'crates/fparkan-runtime/src/production.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/production.rs | 73 |
1 files changed, 56 insertions, 17 deletions
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<NormalizedPath>, player_scheme_count: usize, customized: bool, - ai_schemes: Vec<(OwnerId, u32, NormalizedPath)>, + ai_schemes: Vec<crate::clan_factory_schemes::ScriptDesign>, controls: Vec<MissionControlDeviceTableState>, plants: Vec<(usize, u32)>, pending: VecDeque<Order>, @@ -170,7 +170,7 @@ impl Production { schemes: Vec<NormalizedPath>, player_scheme_count: usize, customized: bool, - ai_schemes: Vec<(OwnerId, u32, NormalizedPath)>, + ai_schemes: Vec<crate::clan_factory_schemes::ScriptDesign>, controls: Vec<MissionControlDeviceTableState>, drafts: &[MissionObjectDraft], ) -> Result<Self, EngineError> { @@ -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 { @@ -826,6 +818,52 @@ mod tests { #[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() { 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(); @@ -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 |
