From 5cc5602b3fa42e5864d205a1c42c895504038b10 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 20:14:25 +0400 Subject: fix(ai): start player and clan cycles on the first update Fresh AI contexts enter their first cycle immediately, including the player context with an empty Problems0. Share their logical clock with Mission timeouts and registration notifications. The stock original confirms the first Mission callback sees zero before the first AI cycle. Run the player Problems0 path and support TAKE_ALL_BATTLE_UNITS: preserve reserved and same-kind assignments, take warbots from other combat tasks. Native ai.dll calls verify recruitment and the initial shared RNG draws. Validation: workspace fmt/check/tests, release build, licensed stock-clock test, all 29 stock missions at --sim-report 900 without script stops, and stock mission windows 28 and 20. Full AI chronology, native occupancy and remaining RNG consumers are still approximate. --- crates/fparkan-runtime/src/clan_combat_groups.rs | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'crates/fparkan-runtime/src/clan_combat_groups.rs') diff --git a/crates/fparkan-runtime/src/clan_combat_groups.rs b/crates/fparkan-runtime/src/clan_combat_groups.rs index b1476df0..71d8a2a5 100644 --- a/crates/fparkan-runtime/src/clan_combat_groups.rs +++ b/crates/fparkan-runtime/src/clan_combat_groups.rs @@ -85,6 +85,11 @@ pub(super) fn recruit_all(units: impl Iterator) -> Option, current_kind: u32) -> bool { + // ai.dll+0xac36: TAKE_ALL_BATTLE_UNITS keeps units already assigned to this problem kind. + assigned_kind != Some(current_kind) +} + pub(super) fn recruit( world: &World, units: impl Iterator, @@ -207,6 +212,34 @@ impl CombatGroup { mod tests { use super::*; + #[test] + fn battle_group_takes_other_problem_kinds_but_keeps_matching_assignments() { + // ai.dll+0xab85 oracle: roster classes [warbot, transport, building, warbot]. + // Reserved 0xfffe is excluded before recruitment, as in MissionEvents::clan_units. + for (jobs, expected) in [ + ([None, None], vec![0, 3]), + ([Some(12), Some(12)], vec![]), + ([Some(8), Some(8)], vec![0, 3]), + ] { + let recruited = recruit_all([0, 3].into_iter().zip(jobs).filter_map(|(slot, job)| { + battle_assignment_available(job, 12).then_some(ObjectHandle { + slot, + generation: 1, + }) + })); + assert_eq!( + recruited + .map(|group| group + .members + .into_iter() + .map(|unit| unit.slot) + .collect::>()) + .unwrap_or_default(), + expected + ); + } + } + #[test] fn recruits_by_distance_until_the_threshold_and_keeps_partial_groups() { let [a, b, c] = [1, 2, 3].map(|slot| ObjectHandle { -- cgit v1.2.3