diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-25 19:14:25 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-25 19:14:25 +0300 |
| commit | 5cc5602b3fa42e5864d205a1c42c895504038b10 (patch) | |
| tree | e6a664fcfd8b4f69b0d0958da661e2e059d53d92 /crates/fparkan-runtime/src/clan_combat_groups.rs | |
| parent | 85474bcd60f66b610985c90a697351837208528b (diff) | |
| download | fparkan-5cc5602b3fa42e5864d205a1c42c895504038b10.tar.xz fparkan-5cc5602b3fa42e5864d205a1c42c895504038b10.zip | |
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.
Diffstat (limited to 'crates/fparkan-runtime/src/clan_combat_groups.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/clan_combat_groups.rs | 33 |
1 files changed, 33 insertions, 0 deletions
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<Item = ObjectHandle>) -> Option<C }) } +pub(super) fn battle_assignment_available(assigned_kind: Option<u32>, 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<Item = ObjectHandle>, @@ -208,6 +213,34 @@ 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::<Vec<_>>()) + .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 { slot, |
