diff options
Diffstat (limited to 'crates/fparkan-runtime/src/lib.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 7170b78f..2ac3f856 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -50,6 +50,7 @@ mod basement_geometry; mod boarding; mod builder_supply; mod building_door; +mod camouflage; pub use basement_geometry::{ mission_basement_footprint, mission_basement_footprints, place_constructed_basement, MissionBasementFootprint, @@ -196,6 +197,7 @@ pub use boarding::{ select_boarding_target, RemoteWarbotControl, VehicleEntry, }; pub use building_door::{has_proximity_doors, sample_capture_doors, sample_proximity_doors}; +pub use camouflage::toggle_camouflage; pub use capture_barrier::sample_capture_barrier; pub use designer_attachments::{edit_factory_socket, factory_socket_choices}; pub use designer_chassis::{factory_chassis_choices, prepare_factory_chassis}; @@ -4933,7 +4935,7 @@ fn control_device_resource_rate( match device.factory_tag { 5 => Ok(mobile_budget::unmodeled_motion_rate()), - 10 => mobile_budget::passive_device_rate(device, delta_time_seconds), + 10 => camouflage::resource_rate(device, delta_time_seconds, descriptor_rate), 9 => { let coefficient_0 = control_device_budget_coefficient(device, 0)?; let coefficient_1 = control_device_budget_coefficient(device, 1)?; @@ -5413,7 +5415,8 @@ fn control_device_resource_update( )?; } } - 5 | 10 | 26 => set_control_device_multiplier(table, device_index, allocation)?, + 10 => camouflage::update_resource(table, device_index, delta_time_seconds, allocation)?, + 5 | 26 => set_control_device_multiplier(table, device_index, allocation)?, factory_tag if control_factory_uses_generic_budget_callbacks(factory_tag) => { set_control_device_multiplier(table, device_index, allocation)?; } @@ -6721,7 +6724,7 @@ fn native_control_factory_defaults(factory_tag: u32) -> (Option<u32>, Option<u32 match factory_tag { 1 | 4 => (Some(0x3f80_0000), Some(0x200)), 3 | 5 | 8 | 21 | 25 | 26 => (Some(0x3f80_0000), Some(0x5)), - 10 => (Some(0x3f80_0000), Some(0x2000)), + 10 => (Some(0x3f80_0000), Some(camouflage::OFF)), 17 | 19 => (Some(0x3f80_0000), Some(0x20)), 2 | 27 | 30 => (Some(0x3f80_0000), Some(0)), 9 => (Some(0x3f80_0000), Some(0x20)), @@ -9878,6 +9881,40 @@ mod tests { } #[test] + fn control_budget_camouflage_matches_native_demand_and_shutdown_threshold() { + let mut device = synthetic_effective_control_device( + 10, + 10, + 1.0_f32.to_bits(), + Some(1.0_f32.to_bits()), + None, + ); + device.key = 0; + device.native_word_50_bits = Some(0x1000); + let provider = synthetic_node_provider_row(0, 0, 1.0_f32.to_bits()); + for (seconds, base, extra, allocation_bits, demand, expected_enabled) in [ + (1.0_f32, 3.0_f32, 9.0_f32, 0x3e80_0000, 0xc140_0000, true), + (1.0, 3.0, 9.0, 0x3e7f_ffff, 0xc140_0000, false), + (0.375491, 17.258, 19.81, 0x3e6f_e3b0, 0xc15e_b2fe, false), + ] { + device.coefficient_bits.as_mut().unwrap()[4] = extra.to_bits(); + device.descriptor.fixed_words[8] = base.to_bits(); + let mut table = synthetic_control_device_table_with_providers( + MissionControlDeviceTableStatus::Available(vec![device.clone()]), + MissionControlNodeProviderTableStatus::Available(vec![provider.clone()]), + ); + let active = control_budget_device(&table, 0).unwrap(); + let rate = control_device_resource_rate(&table, active, seconds).unwrap(); + assert_eq!(rate.to_bits(), demand); + control_device_resource_update(&mut table, 0, seconds, f32::from_bits(allocation_bits)) + .unwrap(); + let updated = control_budget_device(&table, 0).unwrap(); + assert_eq!(updated.multiplier_bits, Some(allocation_bits)); + assert_eq!(camouflage::is_enabled(updated), expected_enabled); + } + } + + #[test] fn control_budget_tag26_rate_matches_native_additive_cost() { let mut device = synthetic_effective_control_device( 26, |
