From 1547350d91e6be1cb08be20f98e4aa919f4f5ee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 14 Nov 2026 11:36:01 +0400 Subject: feat(runtime): fire from boarded warbots --- crates/fparkan-runtime/src/player_weapon.rs | 37 +++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'crates/fparkan-runtime/src/player_weapon.rs') diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index f1fcbf7e..ce92b053 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -3,7 +3,7 @@ use fparkan_assets::{ PreparedComponentControl, PreparedControlEffectSection, PreparedControlPoint, }; -/// The starting hero's selectable weapon devices, in resource order. +/// A unit's selectable weapon devices, in resource order. #[derive(Clone, Default)] pub struct PlayerWeapons { weapons: Vec, @@ -15,6 +15,8 @@ pub struct PlayerWeapons { /// A manual-fire device prepared from its CTLD record and effect rows. #[derive(Clone)] pub struct PlayerWeapon { + /// Component containing the barrel's CPT point. + pub component_index: usize, /// Name of the projectile prototype. pub projectile: String, /// Archive named by the weapon's projectile descriptor. @@ -172,12 +174,34 @@ pub fn starting_player_weapons(engine: &Engine, cockpit: StartingCockpit) -> Pla .and_then(|controls| controls.get(cockpit.component_index)) .and_then(Option::as_ref); PlayerWeapons { - weapons: control.map_or_else(Vec::new, prepare_weapons), + weapons: control.map_or_else(Vec::new, |control| { + prepare_weapons(cockpit.component_index, control) + }), ..PlayerWeapons::default() } } -fn prepare_weapons(control: &PreparedComponentControl) -> Vec { +/// Resolves weapon devices for placed and prepared production warbots. +pub fn prepared_warbot_weapons( + engine: &Engine, +) -> impl Iterator + '_ { + engine.loaded.iter().flat_map(|mission| { + mission + .object_drafts + .iter() + .zip(&mission.mission_assets.object_component_controls) + .enumerate() + .filter(|(_, (draft, _))| { + draft.unit_dat_header_flags == Some(crate::boarding::WARBOT_CLASS) + }) + .map(|(index, (_, controls))| (index, prepare_unit_weapons(controls))) + }) +} + +fn prepare_weapons( + component_index: usize, + control: &PreparedComponentControl, +) -> Vec { let Some(points) = &control.point_list else { return Vec::new(); }; @@ -256,6 +280,7 @@ fn prepare_weapons(control: &PreparedComponentControl) -> Vec { _ => None, }; Some(PlayerWeapon { + component_index, projectile, projectile_archive, effect, @@ -276,8 +301,9 @@ pub(super) fn prepare_unit_weapons(controls: &[Option] PlayerWeapons { weapons: controls .iter() - .flatten() - .flat_map(prepare_weapons) + .enumerate() + .filter_map(|(index, control)| Some((index, control.as_ref()?))) + .flat_map(|(index, control)| prepare_weapons(index, control)) .collect(), ..PlayerWeapons::default() } @@ -291,6 +317,7 @@ mod tests { fn shot_finishes_after_trigger_release_and_then_spends_ammo() { let mut weapons = PlayerWeapons { weapons: vec![PlayerWeapon { + component_index: 0, projectile: String::from("test"), projectile_archive: String::from("test.rlb"), effect: None, -- cgit v1.2.3