aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-script/src
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-script/src
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-script/src')
-rw-r--r--crates/fparkan-script/src/lib.rs49
1 files changed, 19 insertions, 30 deletions
diff --git a/crates/fparkan-script/src/lib.rs b/crates/fparkan-script/src/lib.rs
index 4dd73efd..e9e10722 100644
--- a/crates/fparkan-script/src/lib.rs
+++ b/crates/fparkan-script/src/lib.rs
@@ -1967,9 +1967,10 @@ impl Handler2RecordScheduler {
/// Inserts or refreshes one resolved handler input.
///
/// The original compares the three identity words bit-for-bit. On an
- /// existing key, it refreshes only when `scalar_1` compares unequal; that
- /// update replaces `scalar_1` and `argument_2`, then adds the slot-2 word
- /// captured when that record was created, with x86 wrapping arithmetic.
+ /// existing key, it accepts a weight at least as high as the stored
+ /// weight. An unordered comparison leaves the record unchanged.
+ /// Refresh updates `scalar_1` and `argument_2`, then adds the initial
+ /// slot-2 word with x86 wrapping arithmetic.
pub fn submit(&mut self, input: Handler2RecordInput) -> Handler2RecordUpdate {
let key = Handler2RecordKey::from(input);
if let Some((index, record)) = self
@@ -1978,7 +1979,7 @@ impl Handler2RecordScheduler {
.enumerate()
.find(|(_, record)| record.key == key)
{
- if !handler_two_scalar_equal(record.scalar_1, input.scalar_1) {
+ if record.scalar_1 <= input.scalar_1 {
record.scalar_1 = input.scalar_1;
record.argument_2 = input.argument_2;
record.counter = record.counter.wrapping_add(record.increment);
@@ -2011,19 +2012,6 @@ impl Handler2RecordScheduler {
}
}
-fn handler_two_scalar_equal(left: f32, right: f32) -> bool {
- if left.is_nan() || right.is_nan() {
- return false;
- }
- let left_bits = left.to_bits();
- let right_bits = right.to_bits();
- left_bits == right_bits || (is_f32_zero_bits(left_bits) && is_f32_zero_bits(right_bits))
-}
-
-fn is_f32_zero_bits(bits: u32) -> bool {
- matches!(bits, 0 | 0x8000_0000)
-}
-
/// Parses the numeric `VAR(...)` declarations from a legacy `varset.var` file.
///
/// Parsing is line-oriented and byte-safe: non-UTF-8 comments remain opaque,
@@ -2489,7 +2477,7 @@ mod tests {
assert_eq!(scheduler.records().len(), 1);
assert_eq!(scheduler.records()[0].counter, 4);
- let unchanged = handler_two_input(1.5, -0.0, 3.0, 12.0, 99);
+ let unchanged = handler_two_input(1.0, -0.0, 3.0, 12.0, 99);
assert_eq!(
scheduler.submit(unchanged),
super::Handler2RecordUpdate {
@@ -2501,7 +2489,7 @@ mod tests {
assert_eq!(scheduler.records()[0].counter, 4);
assert_eq!(scheduler.records()[0].argument_2, 9.0_f32.to_bits());
- let refreshed = handler_two_input(2.5, -0.0, 3.0, 12.0, 99);
+ let refreshed = handler_two_input(1.5, -0.0, 3.0, 12.0, 99);
assert_eq!(
scheduler.submit(refreshed),
super::Handler2RecordUpdate {
@@ -2536,30 +2524,31 @@ mod tests {
}
#[test]
- fn handler_two_scheduler_refreshes_nan_and_wraps_counter() {
+ fn handler_two_scheduler_skips_unordered_weights_and_wraps_on_refresh() {
let mut scheduler = Handler2RecordScheduler::default();
- scheduler.submit(handler_two_input(f32::NAN, 1.0, 2.0, 3.0, u32::MAX));
+ scheduler.submit(handler_two_input(0.5, 1.0, 2.0, 3.0, u32::MAX));
let update = scheduler.submit(handler_two_input(f32::NAN, 1.0, 2.0, 4.0, 2));
assert_eq!(update.index, 0);
- assert!(update.refreshed);
- assert_eq!(scheduler.records()[0].counter, u32::MAX - 1);
- assert_eq!(scheduler.records()[0].argument_2, 4.0_f32.to_bits());
+ assert!(!update.refreshed);
+ assert_eq!(scheduler.records()[0].counter, u32::MAX);
+ assert_eq!(scheduler.records()[0].argument_2, 3.0_f32.to_bits());
- let update = scheduler.submit(handler_two_input(f32::NAN, 1.0, 2.0, 5.0, 17));
+ let update = scheduler.submit(handler_two_input(0.5, 1.0, 2.0, 5.0, 17));
assert!(update.refreshed);
- assert_eq!(scheduler.records()[0].counter, u32::MAX - 2);
+ assert_eq!(scheduler.records()[0].counter, u32::MAX - 1);
assert_eq!(scheduler.records()[0].argument_2, 5.0_f32.to_bits());
}
#[test]
- fn handler_two_scheduler_treats_signed_zero_value_as_unchanged() {
+ fn handler_two_scheduler_refreshes_equal_weights_across_signed_zero() {
let mut scheduler = Handler2RecordScheduler::default();
scheduler.submit(handler_two_input(-0.0, 1.0, 2.0, 3.0, 5));
let update = scheduler.submit(handler_two_input(0.0, 1.0, 2.0, 4.0, 9));
assert!(!update.created);
- assert!(!update.refreshed);
- assert_eq!(scheduler.records()[0].counter, 5);
- assert_eq!(scheduler.records()[0].argument_2, 3.0_f32.to_bits());
+ assert!(update.refreshed);
+ assert_eq!(scheduler.records()[0].counter, 10);
+ assert_eq!(scheduler.records()[0].scalar_1.to_bits(), 0);
+ assert_eq!(scheduler.records()[0].argument_2, 4.0_f32.to_bits());
}
#[test]