From e50b53e7a08d8b5e3393e477b890da95c4c8ef2a Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 08:50:33 +0400 Subject: feat(ui): install turrets and weapons in designer sockets Read the chassis and turret mount families from MSH Res10 and the attached devices from CTLD. Preserve the parent and mount node in Unit DAT, including separate ammunition subtrees for matching weapons. Verified from the stock Field Camp start: install a turret, mount two identical guns, remove one with its ammunition, and order the edited project through the factory panel. --- crates/fparkan-runtime/src/designer_chassis.rs | 32 ++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'crates/fparkan-runtime/src/designer_chassis.rs') diff --git a/crates/fparkan-runtime/src/designer_chassis.rs b/crates/fparkan-runtime/src/designer_chassis.rs index fe290d33..bd6858f2 100644 --- a/crates/fparkan-runtime/src/designer_chassis.rs +++ b/crates/fparkan-runtime/src/designer_chassis.rs @@ -80,26 +80,34 @@ pub fn prepare_factory_chassis( .and_then(|controls| controls.first()) .and_then(Option::as_ref) .ok_or_else(|| invalid("chassis has no Control data"))?; + let defaults = factory_default_devices(engine, cockpit, &control.typed_records)?; + project.records[0].immediate_child_count = defaults.len() as u32; + project.records.extend(defaults); + Ok(project) +} + +pub(super) fn factory_default_devices( + engine: &Engine, + cockpit: StartingCockpit, + records: &[PreparedControlTypedRecord], +) -> Result, EngineError> { let mission = engine .loaded .as_ref() .ok_or_else(|| invalid("no mission"))?; let owner = player_owner(&engine.world, cockpit)?; - let defaults = with_clan_research(&engine.services.vfs, mission, owner, |research| { - Ok(default_devices(&control.typed_records, |name| { + with_clan_research(&engine.services.vfs, mission, owner, |research| { + Ok(default_devices(records, |name| { research.find_key(name).ok().flatten().is_some_and(|row| { researched(research, row, |row| { mission.free_research.learned.contains(&(owner, row)) }) }) })) - })?; - project.records[0].immediate_child_count = defaults.len() as u32; - project.records.extend(defaults); - Ok(project) + }) } -fn researched( +pub(super) fn researched( research: &ResearchTrfDocument, row: usize, learned: impl FnOnce(usize) -> bool, @@ -124,13 +132,19 @@ fn default_devices( if !available(&name) { return None; } - let role = if family.starts_with(b"i_arm_") { 2 } else { 3 }; + let role = if family.starts_with(b"i_arm_") { + 2 + } else if record.tag == 2 { + 5 + } else { + 3 + }; component(&name, index as i32, role) }) .collect() } -fn component(name: &[u8], link: i32, role: u32) -> Option { +pub(super) fn component(name: &[u8], link: i32, role: u32) -> Option { let resource_raw = project_field(name)?; Some(UnitComponentRecord { archive_raw: project_field(b"objects.rlb").expect("static archive name"), -- cgit v1.2.3