diff options
Diffstat (limited to 'crates/fparkan-assets/src')
| -rw-r--r-- | crates/fparkan-assets/src/lib.rs | 74 |
1 files changed, 73 insertions, 1 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"), |
