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/clan_factory_schemes.rs | 98 +++++++++++++++------- 1 file changed, 68 insertions(+), 30 deletions(-) (limited to 'crates/fparkan-runtime/src/clan_factory_schemes.rs') diff --git a/crates/fparkan-runtime/src/clan_factory_schemes.rs b/crates/fparkan-runtime/src/clan_factory_schemes.rs index 8d6d9f47..4cf78352 100644 --- a/crates/fparkan-runtime/src/clan_factory_schemes.rs +++ b/crates/fparkan-runtime/src/clan_factory_schemes.rs @@ -17,12 +17,25 @@ pub(super) const SELECT_STRONGEST: u32 = 5; pub(super) const AUXILIARY_CLASSES: [u32; 2] = [TRANSPORT_CLASS, crate::construction::BUILDER_CLASS]; +pub(super) struct ScriptDesign { + pub owner: OwnerId, + pub class: u32, + pub selection: u32, + pub path: NormalizedPath, +} + +#[derive(Clone, Copy)] +struct DesignRatings { + combat: Option, + speed: Option, +} + pub(super) fn available( assets: &AssetManager, vfs: &dyn Vfs, mission: &MissionDocument, bundles: &[MissionScriptBundle], -) -> Vec<(OwnerId, u32, NormalizedPath)> { +) -> Vec { let clans = bundles.iter().filter(|bundle| { mission.clans[bundle.clan_index].mode == 2 && bundle.package.events.iter().any(|event| { @@ -75,23 +88,43 @@ pub(super) fn available( .entries .into_iter() .filter(|entry| entry.status != 0); - let design = if class == WARBOT_CLASS { - let candidates = available.filter_map(|entry| { - let score = *ratings - .entry(entry.path.clone()) - .or_insert_with(|| combat_rating(assets, vfs, &entry.path)); - Some((entry.path, score?)) - }); - best_design(candidates) + if class == WARBOT_CLASS { + let candidates: Vec<_> = available + .filter_map(|entry| { + let scores = (*ratings + .entry(entry.path.clone()) + .or_insert_with(|| design_ratings(assets, vfs, &entry.path)))?; + Some((entry.path, scores)) + }) + .collect(); + for selection in [SELECT_STRONGEST, SELECT_FASTEST] { + let ranked = candidates.iter().filter_map(|(path, scores)| { + let score = if selection == SELECT_STRONGEST { + scores.combat + } else { + scores.speed + }?; + Some((path.clone(), score)) + }); + if let Some(path) = best_design(ranked) { + selected.push(ScriptDesign { + owner, + class, + selection, + path, + }); + } + } } else { // shortcut: select the sole qualified auxiliary until those ranks are wired. - available - .next() - .filter(|_| available.next().is_none()) - .map(|entry| entry.path) - }; - if let Some(path) = design { - selected.push((owner, class, path)); + if let Some(entry) = available.next().filter(|_| available.next().is_none()) { + selected.push(ScriptDesign { + owner, + class, + selection: SELECT_FASTEST, + path: entry.path, + }); + } } } } @@ -105,11 +138,11 @@ fn best_design(candidates: impl Iterator) -> Optio .map(|(path, _)| path) } -fn combat_rating( +fn design_ratings( assets: &AssetManager, vfs: &dyn Vfs, path: &NormalizedPath, -) -> Option { +) -> Option { let root = crate::resource_name(path.as_bytes()); let (graph, prototypes, report) = build_prototype_graph_report(assets.repository(), vfs, &[root]); @@ -149,18 +182,23 @@ fn combat_rating( }, ) .ok()?; - let volume = f32::from_bits(crate::initial_node_provider_amount( - &projection.node_provider_status, - )?); - let resistance = projection - .projectile_resistance_bits - .map_or(1.0, |[factor, _]| f32::from_bits(factor)); - // shortcut: selector 0x36 adds a shield term and selector 0x204 reads native bank totals. - let score = rating( - volume / resistance, - weapon_power(&projection.devices, &projection.node_provider_status), - ); - score.is_finite().then_some(score) + let combat = crate::initial_node_provider_amount(&projection.node_provider_status) + .map(|bits| { + let resistance = projection + .projectile_resistance_bits + .map_or(1.0, |[factor, _]| f32::from_bits(factor)); + // shortcut: selector 0x36 adds a shield term and selector 0x204 reads native bank totals. + rating( + f32::from_bits(bits) / resistance, + weapon_power(&projection.devices, &projection.node_provider_status), + ) + }) + .filter(|score| score.is_finite()); + let speed = projection + .owner_profile + .map(|profile| f32::from_bits(profile.current_words[7])) + .filter(|speed| speed.is_finite() && *speed > 0.0); + Some(DesignRatings { combat, speed }) } #[cfg(test)] -- cgit v1.2.3