From 0a4aada114bdcce5dba69bdbb88fa0ed44cf6733 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 03:53:21 +0400 Subject: fix(movement): use profile requests for scripted Go speed Scripted Go used a fixed speed of 9. Feed the temporary movement controller with the current Control forward limit multiplied by the loaded Behavior Go_SpeedPercent. Missing coefficients retain the native constructor default of 1; present VAR records use the first matching row's applied value. Rebind a produced unit's Behavior profile to its new full handle so the request remains available after spawning. Share Go and PatrolPlace speed sampling in unit_speed.rs while retaining the patrol coefficient of 0.8, and move profile-loading mechanics out of lib.rs into behavior_profile.rs. Reports distinguish Go and patrol samples and keep explicit fallbacks for unresolved inputs. An unmodified GOG Behavior.dll oracle executes the native profile constructor, current-profile getter and both Go start/update paths under x87 0x007f. A hardware breakpoint records the request before the MWalker call. It confirms default, fractional and zero vectors, including the stock request 0x41e52e74 (28.647682). This is requested-speed evidence; MWalker caching, acceleration, routing and physical integration remain explicit approximations. The licensed stock mission-19 test first failed because Go never requested its Control speed, then passed with the original robot at the stock start. Existing patrol and newly produced-unit profile tests also pass. In the stock game window the raid fires at 190671 ms instead of the preceding build's roughly 327 seconds, depletes the bunker root at 193620 ms, and completes both queued retreat Go orders before ShutDown. The hero stays at the starting position. Validation: cargo fmt --all -- --check; cargo check --workspace; cargo test --workspace; release build; six focused/ignored runtime speed tests; native start/update vectors; all 29 stock --sim-report 900 runs with zero Go speed fallbacks or damage errors. World summaries remain unchanged. Full original movement and mission chronology are not accepted by this change. --- .../fparkan-assets/src/behavior_profile_values.rs | 57 ++++++++++++++++++---- crates/fparkan-assets/src/lib.rs | 6 ++- 2 files changed, 52 insertions(+), 11 deletions(-) (limited to 'crates/fparkan-assets') diff --git a/crates/fparkan-assets/src/behavior_profile_values.rs b/crates/fparkan-assets/src/behavior_profile_values.rs index 9600b581..1d07ed91 100644 --- a/crates/fparkan-assets/src/behavior_profile_values.rs +++ b/crates/fparkan-assets/src/behavior_profile_values.rs @@ -24,14 +24,34 @@ pub fn decode_behavior_work_rates( }) } +/// Reads the applied Go coefficient, retaining the native default when absent. +/// +/// # Errors +/// Rejects malformed framing and a selected record that is not a float. +pub fn decode_behavior_go_speed_percent(bytes: &[u8]) -> Result { + let [value] = decode_values(bytes, ["Go_SpeedPercent"])?; + Ok(value.unwrap_or(1.0_f32.to_bits())) +} + pub(super) fn decode_pair( bytes: &[u8], names: [&'static str; 2], ) -> Result<[u32; 2], BehaviorProfileVarError> { + let [first, second] = decode_values(bytes, names)?; + Ok([ + first.ok_or(BehaviorProfileVarError::MissingField { name: names[0] })?, + second.ok_or(BehaviorProfileVarError::MissingField { name: names[1] })?, + ]) +} + +fn decode_values( + bytes: &[u8], + names: [&'static str; N], +) -> Result<[Option; N], BehaviorProfileVarError> { let mut cursor = Cursor::new(bytes); let count = cursor.read_u32_le()?; checked_count_bytes(u64::from(count), 28, cursor.remaining() as u64)?; - let mut found = [None, None]; + let mut found = [None; N]; for _ in 0..count { let size = cursor.read_u32_le()?; let type_index = cursor.read_u32_le()?; @@ -61,19 +81,16 @@ pub(super) fn decode_pair( cursor.read_exact(8)?; } cursor.require_eof()?; - Ok([ - found[0].ok_or(BehaviorProfileVarError::MissingField { name: names[0] })?, - found[1].ok_or(BehaviorProfileVarError::MissingField { name: names[1] })?, - ]) + Ok(found) } #[cfg(test)] mod tests { use super::*; - #[test] - fn work_rates_use_the_applied_second_blob() { - let mut bytes = 2_u32.to_le_bytes().to_vec(); - for (name, first, second) in [("Use_Power", 7.0_f32, 3.0_f32), ("Use_Ore", 9.0, 1.0)] { + + fn profile(fields: &[(&str, f32, f32)]) -> Vec { + let mut bytes = (fields.len() as u32).to_le_bytes().to_vec(); + for &(name, first, second) in fields { for word in [4_u32, 3, 0] { bytes.extend(word.to_le_bytes()); } @@ -86,6 +103,12 @@ mod tests { bytes.extend(second.to_le_bytes()); bytes.extend([0; 8]); } + bytes + } + + #[test] + fn work_rates_use_the_applied_second_blob() { + let bytes = profile(&[("Use_Power", 7.0, 3.0), ("Use_Ore", 9.0, 1.0)]); assert_eq!( decode_behavior_work_rates(&bytes).unwrap(), BehaviorWorkRates { @@ -94,4 +117,20 @@ mod tests { } ); } + + #[test] + fn go_speed_keeps_native_default_or_uses_the_first_rows_applied_value() { + assert_eq!( + decode_behavior_go_speed_percent(&profile(&[])), + Ok(1.0_f32.to_bits()) + ); + let bytes = profile(&[ + ("Go_SpeedPercent", 0.8, 0.5), + ("Go_SpeedPercent", 1.0, 0.25), + ]); + assert_eq!( + decode_behavior_go_speed_percent(&bytes), + Ok(0.5_f32.to_bits()) + ); + } } diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs index f9dbebe4..016eec41 100644 --- a/crates/fparkan-assets/src/lib.rs +++ b/crates/fparkan-assets/src/lib.rs @@ -32,7 +32,9 @@ pub use fparkan_texm::{PageRect, RgbaImage}; use fparkan_vfs::DirectoryVfs; mod behavior_profile_values; mod chassis_profile; -pub use behavior_profile_values::{decode_behavior_work_rates, BehaviorWorkRates}; +pub use behavior_profile_values::{ + decode_behavior_go_speed_percent, decode_behavior_work_rates, BehaviorWorkRates, +}; pub use chassis_profile::decode_chassis_can_fly; mod research; pub use research::{ @@ -88,7 +90,7 @@ pub struct BehaviorProfileRates { pub enum BehaviorProfileVarError { /// The binary record framing is malformed. Decode(DecodeError), - /// A bound for one of the two fields used here is not a 32-bit float. + /// A selected registered field is not a 32-bit float. InvalidFloatField { name: &'static str, size: u32, -- cgit v1.2.3