aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/designer_chassis.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/designer_chassis.rs')
-rw-r--r--crates/fparkan-runtime/src/designer_chassis.rs32
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"),