aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 06:57:23 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 06:57:23 +0300
commit31dd73cbf59f5c8fe58b77b373a75033dc5a037a (patch)
tree7a20ada1d75679b61a6c6716ffe91a10faba4592 /crates
parent364f8a0984e5cd3b65e81f24e95fcf8cd92aec2d (diff)
downloadfparkan-31dd73cbf59f5c8fe58b77b373a75033dc5a037a.tar.xz
fparkan-31dd73cbf59f5c8fe58b77b373a75033dc5a037a.zip
fix(fx): switch warbot smoke with the damage alarm
Resolve the matching enable and disable selectors from authored CTL alarm groups. Render node-attached smoke and light only while the live Control alarm is active. Verify the native selector against both DLLs and inspect two Vulkan frames around an ordinary AutoDemo alarm. Independent mode-14 triggers and the damage stage cascade remain open.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-assets/src/lib.rs74
-rw-r--r--crates/fparkan-runtime/src/control_profile.rs2
-rw-r--r--crates/fparkan-runtime/src/control_resources.rs6
-rw-r--r--crates/fparkan-runtime/src/lib.rs12
4 files changed, 92 insertions, 2 deletions
diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs
index d98bff3d..4738f175 100644
--- a/crates/fparkan-assets/src/lib.rs
+++ b/crates/fparkan-assets/src/lib.rs
@@ -45,7 +45,7 @@ pub use research::{
calc_full_research_cost, research_project_rows, ResearchCandidate, ResearchCandidateSet,
ResearchCompletion, ResearchCost, ResearchError, ResearchTrfDocument,
};
-use std::collections::{hash_map::Entry, HashMap};
+use std::collections::{hash_map::Entry, BTreeMap, HashMap};
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
@@ -1055,6 +1055,8 @@ pub struct PreparedComponentControl {
/// Validated group selected by native Control's first effect-group
/// header word; `None` is the native no-group sentinel or an invalid index.
pub initial_effect_group: Option<usize>,
+ /// Rows in the initial group enabled by the alarm and disabled on recovery.
+ pub alarm_effect_rows: Vec<usize>,
/// Node-to-effect links from Control opcode 14, resolved within each group.
pub node_effect_links: Vec<(usize, u32, u32)>,
/// Changes to the clocks of existing effect instances, from opcode 10.
@@ -3903,6 +3905,7 @@ const CONTROL_EFFECT_ROW_BYTES: usize = 100;
struct DecodedComponentEffectSection {
section: PreparedControlEffectSection,
initial_effect_group: Option<usize>,
+ alarm_effect_rows: Vec<usize>,
initial_group_opcodes: Option<Vec<u32>>,
typed_records: Vec<PreparedControlTypedRecord>,
node_effect_links: Vec<(usize, u32, u32)>,
@@ -3930,6 +3933,7 @@ where
}
},
initial_effect_group: None,
+ alarm_effect_rows: Vec::new(),
initial_group_opcodes: (cursor == payload.len()).then(Vec::new),
typed_records: Vec::new(),
node_effect_links: Vec::new(),
@@ -3954,6 +3958,7 @@ where
typed_record_tag: Some(tag),
},
initial_effect_group: None,
+ alarm_effect_rows: Vec::new(),
initial_group_opcodes: None,
typed_records,
node_effect_links: Vec::new(),
@@ -4057,6 +4062,7 @@ where
}
},
initial_effect_group: None,
+ alarm_effect_rows: Vec::new(),
initial_group_opcodes: complete.then(Vec::new),
typed_records,
node_effect_links: Vec::new(),
@@ -4076,6 +4082,11 @@ where
)
.ok()
.filter(|group| *group < effect_group_count);
+ // The native group table copies these two references to owner +0x4f4/+0x4f8.
+ let alarm_groups = [0x18, 0x1c].map(|offset| {
+ control_u32_at(payload, cursor + offset).expect("validated effect group header") as usize
+ });
+ let mut alarm_switches = [BTreeMap::new(), BTreeMap::new()];
cursor = group_header_end;
let mut initial_group_opcodes = Some(Vec::new());
@@ -4119,6 +4130,16 @@ where
.expect("valid initial group has an opcode list")
.push(opcode);
}
+ if matches!(opcode, 0x12 | 0x13)
+ && control_u32_at(row, 0).expect("fixed effect condition") & 0xf000_0000 == 0
+ {
+ let selector = control_u32_at(row, 0x10).expect("fixed effect selector");
+ for (&group, switches) in alarm_groups.iter().zip(&mut alarm_switches) {
+ if group == table_index {
+ switches.insert(selector, opcode == 0x12);
+ }
+ }
+ }
if !matches!(opcode, 3 | 4 | 10) {
continue;
}
@@ -4168,15 +4189,26 @@ where
typed_record_tag: None,
},
initial_effect_group: None,
+ alarm_effect_rows: Vec::new(),
initial_group_opcodes: None,
typed_records,
node_effect_links: Vec::new(),
effect_modes: Vec::new(),
});
}
+ let alarm_effect_rows = effect_rows
+ .iter()
+ .filter(|row| {
+ Some(row.table_index) == initial_effect_group
+ && alarm_switches[0].get(&row.selector) == Some(&true)
+ && alarm_switches[1].get(&row.selector) == Some(&false)
+ })
+ .map(|row| row.row_index)
+ .collect();
Ok(DecodedComponentEffectSection {
section: PreparedControlEffectSection::Parsed(effect_rows),
initial_effect_group,
+ alarm_effect_rows,
initial_group_opcodes,
typed_records,
node_effect_links,
@@ -4360,6 +4392,7 @@ fn decode_component_control_payload_with_opcodes(
node_data: None,
effect_section: decoded_effect.section,
initial_effect_group: decoded_effect.initial_effect_group,
+ alarm_effect_rows: decoded_effect.alarm_effect_rows,
node_effect_links: decoded_effect.node_effect_links,
effect_modes: decoded_effect.effect_modes,
point_list: None,
@@ -6971,6 +7004,45 @@ mod tests {
}
#[test]
+ fn component_control_pairs_alarm_switches_by_selector() {
+ let source = ResourceKey {
+ archive: parse_path("bases.rlb").unwrap(),
+ name: resource_name(b"warbot.ctl"),
+ type_id: None,
+ };
+ let mut payload = component_control_payload(&[]);
+ payload[16..20].copy_from_slice(&3_u32.to_le_bytes());
+ let header = payload.len();
+ payload.resize(header + CONTROL_EFFECT_GROUP_HEADER_BYTES, 0);
+ payload[header + 0x18..header + 0x1c].copy_from_slice(&1_u32.to_le_bytes());
+ payload[header + 0x1c..header + 0x20].copy_from_slice(&2_u32.to_le_bytes());
+ append_effect_table(
+ &mut payload,
+ &[1, 2, 3].map(|selector| {
+ effect_row(3, [0; 3], [0; 3], selector, "effects.rlb", "smoke_fr_01")
+ }),
+ );
+ let switch = |opcode, selector, condition| {
+ effect_row(opcode, [condition, 0, 0], [selector, 0, 0], 0, "", "")
+ };
+ append_effect_table(
+ &mut payload,
+ &[
+ switch(0x12, 1, 0),
+ switch(0x12, 2, 0),
+ switch(0x13, 2, 0),
+ switch(0x12, 3, 0x8000_0000),
+ ],
+ );
+ append_effect_table(
+ &mut payload,
+ &[1, 2, 3].map(|selector| switch(0x13, selector, 0)),
+ );
+ let control = decode_component_control_payload(&payload, source, 1, 0).unwrap();
+ assert_eq!(control.alarm_effect_rows, [0]);
+ }
+
+ #[test]
fn initial_control_effect_opcodes_keep_raw_selected_rows_in_order() {
let source = ResourceKey {
archive: parse_path("controls.rlb").expect("archive"),
diff --git a/crates/fparkan-runtime/src/control_profile.rs b/crates/fparkan-runtime/src/control_profile.rs
index 236d523b..21c54607 100644
--- a/crates/fparkan-runtime/src/control_profile.rs
+++ b/crates/fparkan-runtime/src/control_profile.rs
@@ -63,7 +63,7 @@ pub(super) fn project_initial(
#[derive(Default)]
pub(super) struct DamageAlarm {
threshold: Option<f32>,
- active: bool,
+ pub(super) active: bool,
}
#[derive(Default)]
diff --git a/crates/fparkan-runtime/src/control_resources.rs b/crates/fparkan-runtime/src/control_resources.rs
index b9958229..e34a3dfc 100644
--- a/crates/fparkan-runtime/src/control_resources.rs
+++ b/crates/fparkan-runtime/src/control_resources.rs
@@ -34,6 +34,12 @@ impl Default for Resources {
}
impl Resources {
+ pub(super) fn alarm_active(&self, handle: ObjectHandle) -> bool {
+ self.clocks
+ .iter()
+ .any(|(owner, clock)| *owner == handle && clock.alarm.active)
+ }
+
pub(super) fn energy_available(&self, handle: ObjectHandle) -> bool {
!self.blocked_budgets.contains(&handle)
}
diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs
index 3b097acd..e6fe77af 100644
--- a/crates/fparkan-runtime/src/lib.rs
+++ b/crates/fparkan-runtime/src/lib.rs
@@ -3875,6 +3875,16 @@ pub fn loaded_mission_control_device_tables(
.map(|state| state.control_device_tables.as_slice())
}
+/// Whether Control has switched this live object into its damage alarm.
+#[must_use]
+pub fn control_damage_alarm_active(engine: &Engine, handle: ObjectHandle) -> bool {
+ transform_state(&engine.world, handle).is_ok()
+ && engine
+ .loaded
+ .as_ref()
+ .is_some_and(|mission| mission.control_resources.alarm_active(handle))
+}
+
/// Returns the initial prepared Control grouping for full-load mission objects.
#[must_use]
pub fn loaded_mission_behavior_control_groupings(
@@ -8606,6 +8616,7 @@ mod tests {
node_data: None,
effect_section: PreparedControlEffectSection::Parsed(rows),
initial_effect_group,
+ alarm_effect_rows: Vec::new(),
node_effect_links: Vec::new(),
effect_modes: Vec::new(),
point_list: point_count.map(|count| PreparedControlPointList {
@@ -9112,6 +9123,7 @@ mod tests {
node_data: None,
effect_section,
initial_effect_group: None,
+ alarm_effect_rows: Vec::new(),
node_effect_links: Vec::new(),
effect_modes: Vec::new(),
point_list: None,