aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/clan_ai_events.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 12:11:27 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 12:11:27 +0300
commitfac74ba2d2487cb500d24de4223a0ffec50fa580 (patch)
treefcc13a4bb05b1a9a4fa7ea29f0fae5477e469f8c /crates/fparkan-runtime/src/clan_ai_events.rs
parent21b13ca1493d6f4d2da2add874f3fcd29b3cf5fe (diff)
downloadfparkan-fac74ba2d2487cb500d24de4223a0ffec50fa580.tar.xz
fparkan-fac74ba2d2487cb500d24de4223a0ffec50fa580.zip
fix(ai): preserve clan job priorities through factory dispatch
Match GOG ai.dll when refreshing the same request and starting equally weighted jobs. Resolve generated factory IDs when dispatching or awaiting production. Verified from stock starts in Two Fortresses and Third Part. Two Fortresses uses a newly built factory for a combat robot. The small factory in Third Part still lacks a compatible prepared design. The armed stock replay reached late cleanup and left a transport to pursue.
Diffstat (limited to 'crates/fparkan-runtime/src/clan_ai_events.rs')
-rw-r--r--crates/fparkan-runtime/src/clan_ai_events.rs62
1 files changed, 18 insertions, 44 deletions
diff --git a/crates/fparkan-runtime/src/clan_ai_events.rs b/crates/fparkan-runtime/src/clan_ai_events.rs
index f5dad22f..65e602a6 100644
--- a/crates/fparkan-runtime/src/clan_ai_events.rs
+++ b/crates/fparkan-runtime/src/clan_ai_events.rs
@@ -330,6 +330,7 @@ impl LoadedMissionState {
continue;
};
let mut problems_event = Some((event_index, event, None::<Handler2Record>));
+ let mut start_pass = crate::clan_problem_priority::StartPass::default();
// shortcut: task continuations still share the clan cycle rather than per-task scheduling.
let mut pending = self
.clan_ai_events
@@ -412,7 +413,16 @@ impl LoadedMissionState {
let Some((event_index, _event, mut problem)) =
next.or_else(|| problems_event.take())
else {
- break;
+ let Some(queue) = self.clan_ai_events.problems.get(&clan) else {
+ break;
+ };
+ pending = start_pass.next_batch(queue.records(), |key| {
+ self.clan_ai_events.problem_in_progress(clan, key)
+ });
+ if pending.is_empty() {
+ break;
+ }
+ continue;
};
let mut solved = false;
let mut transport_factory_busy = false;
@@ -892,12 +902,9 @@ impl LoadedMissionState {
);
}
let owner = OwnerId(clan as u16);
- let plant = crate::mission_events::placed_logic_objects(
- &self.mission,
- world,
- order.word_0,
- )
- .find(|&handle| {
+ let plant = self.mission_events.logic_objects(
+ &self.mission, world, order.word_0,
+ ).find(|&handle| {
identity_metadata(world, handle)
.is_ok_and(|identity| identity.owner_id == Some(owner))
});
@@ -1020,7 +1027,7 @@ impl LoadedMissionState {
})
.ok_or("Handler(27) requires an active construction order")?;
if assignment != Some(order.plant)
- || !crate::mission_events::placed_logic_objects(
+ || !self.mission_events.logic_objects(
&self.mission,
world,
id,
@@ -1359,6 +1366,9 @@ impl LoadedMissionState {
}
}
if let Some(problem) = problem {
+ if problems_event.is_none() && !solved && !solving {
+ start_pass.stop_after_batch();
+ }
// shortcut: keep transport demand queued until the factory can accept it.
if solved && !transport_factory_busy {
self.clan_ai_events
@@ -1386,8 +1396,6 @@ impl LoadedMissionState {
.waits
.insert((clan, problem.key), conditions);
}
- } else if let Some(queue) = self.clan_ai_events.problems.get(&clan) {
- pending = ranked_problems(queue.records());
}
}
}
@@ -1395,17 +1403,6 @@ impl LoadedMissionState {
}
}
-fn ranked_problems(problems: &[Handler2Record]) -> Vec<Handler2Record> {
- let mut pending: Vec<_> = problems
- .iter()
- .filter(|record| record.scalar_1 > 0.0)
- .cloned()
- .collect();
- pending.sort_by(|a, b| b.scalar_1.total_cmp(&a.scalar_1));
- pending.reverse();
- pending
-}
-
fn single_dword(references: &[u32], values: &[VarSetDefault]) -> Option<u32> {
let &[index] = references else {
return None;
@@ -2153,29 +2150,6 @@ mod tests {
}
#[test]
- fn problem_selection_requires_a_positive_priority_and_preserves_order_on_ties() {
- let mut queue = Handler2RecordScheduler::default();
- for (word_0, scalar_1) in [(1, 0.0), (2, -3.0), (3, 0.5), (4, 0.5)] {
- queue.submit(Handler2RecordInput {
- word_0,
- scalar_1,
- word_2: 0,
- word_3: 0,
- argument_0: 0,
- argument_1: 0,
- argument_2: 0,
- });
- }
- let first = ranked_problems(queue.records()).pop().unwrap().key;
- assert_eq!(first.word_0, 3);
- queue.remove(first);
- assert_eq!(
- ranked_problems(queue.records()).pop().unwrap().key.word_0,
- 4
- );
- }
-
- #[test]
fn free_ore_space_follows_storage_ownership_and_lifecycle() {
use fparkan_world::{
construct_object, new, register_object, request_delete, set_owner, step, InputSnapshot,