aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/radar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/radar.rs')
-rw-r--r--crates/fparkan-runtime/src/radar.rs64
1 files changed, 63 insertions, 1 deletions
diff --git a/crates/fparkan-runtime/src/radar.rs b/crates/fparkan-runtime/src/radar.rs
index 9bb0dfde..e114790d 100644
--- a/crates/fparkan-runtime/src/radar.rs
+++ b/crates/fparkan-runtime/src/radar.rs
@@ -493,7 +493,7 @@ fn signature(table: &MissionControlDeviceTableState) -> Option<[f32; 3]> {
}
// Control+0x2bb40 attenuates each channel with the tag-10 getter.
let mut factor = (1.0 - f64::from(gain) * state * multiplier).max(0.0) as f32;
- if device.native_word_50_bits == Some(0x1000) {
+ if crate::camouflage::is_enabled(device) {
factor *= (1.0 - coefficients[3]).max(0.0);
}
*value *= factor;
@@ -545,6 +545,68 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
+ fn stock_camouflage_attenuates_radar_and_shuts_off_without_power() {
+ use super::signature;
+ use crate::{
+ camouflage, cockpit_indicators::cockpit_indicators, create, load_gameplay_mission,
+ loaded_mission_control_device_tables, starting_cockpit, toggle_camouflage,
+ EngineServices, MissionControlDeviceTableStatus, MissionMode, MissionRequest,
+ MissionStartupInput,
+ };
+ use fparkan_vfs::DirectoryVfs;
+ use std::sync::Arc;
+
+ let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus");
+ let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap();
+ load_gameplay_mission(
+ &mut engine,
+ MissionRequest {
+ key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.02/data.tma".into(),
+ mode: MissionMode::SingleMission,
+ },
+ MissionStartupInput {
+ queue_time_ms: 0,
+ research_creation_gate: false,
+ },
+ None,
+ )
+ .unwrap();
+ let hero = starting_cockpit(&engine).unwrap();
+ let table_index = loaded_mission_control_device_tables(&engine)
+ .unwrap()
+ .iter()
+ .position(|table| table.handle == hero.handle)
+ .unwrap();
+ let table = &loaded_mission_control_device_tables(&engine).unwrap()[table_index];
+ let MissionControlDeviceTableStatus::Available(devices) = &table.status else {
+ panic!("the hero requires a prepared Control device table");
+ };
+ let index = devices
+ .iter()
+ .position(camouflage::is_controlled_device)
+ .unwrap();
+ let before = signature(table).unwrap();
+ let attenuation = f32::from_bits(devices[index].coefficient_bits.unwrap()[3]);
+ assert!(attenuation > 0.0);
+ assert!(!cockpit_indicators(&engine, hero).unwrap().camouflage);
+ assert_eq!(toggle_camouflage(&mut engine, hero), Some(true));
+ assert!(cockpit_indicators(&engine, hero).unwrap().camouflage);
+ let table = &mut engine.loaded.as_mut().unwrap().control_device_tables[table_index];
+ let after = signature(table).unwrap();
+ assert!(before.iter().zip(after).any(|(&off, on)| off > on));
+ assert_eq!(
+ after,
+ before.map(|value| value * (1.0 - attenuation).max(0.0))
+ );
+ crate::control_device_resource_update(table, index, 1.0, 1.0).unwrap();
+ assert!(cockpit_indicators(&engine, hero).unwrap().camouflage);
+ let table = &mut engine.loaded.as_mut().unwrap().control_device_tables[table_index];
+ crate::control_device_resource_update(table, index, 1.0, 0.0).unwrap();
+ assert!(!cockpit_indicators(&engine, hero).unwrap().camouflage);
+ }
+
+ #[test]
+ #[ignore = "requires licensed corpus"]
fn stock_neutral_warbot_appears_and_expires_on_the_hero_radar_clock() {
use crate::{
create, frame, load_gameplay_mission, loaded_mission_control_device_tables,