diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 07:50:33 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 07:50:33 +0300 |
| commit | e50b53e7a08d8b5e3393e477b890da95c4c8ef2a (patch) | |
| tree | 1506b2d9685b562b4b22966c5e16bc574f69fbbc /crates/fparkan-runtime/src/designer_chassis.rs | |
| parent | 20491de7c29f56fda9be16d3b56a9633cb71d386 (diff) | |
| download | fparkan-e50b53e7a08d8b5e3393e477b890da95c4c8ef2a.tar.xz fparkan-e50b53e7a08d8b5e3393e477b890da95c4c8ef2a.zip | |
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.
Diffstat (limited to 'crates/fparkan-runtime/src/designer_chassis.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/designer_chassis.rs | 32 |
1 files changed, 23 insertions, 9 deletions
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<Vec<UnitComponentRecord>, 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<UnitComponentRecord> { +pub(super) fn component(name: &[u8], link: i32, role: u32) -> Option<UnitComponentRecord> { let resource_raw = project_field(name)?; Some(UnitComponentRecord { archive_raw: project_field(b"objects.rlb").expect("static archive name"), |
