aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 09:56:17 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 09:56:17 +0300
commitb21189c3089acc1cf24e530db40707aae292813d (patch)
treed53629295bb034fddf36f4b1a5e57ec2aa0eb4d1 /crates/fparkan-runtime
parent350df52410d4ae731834c56a9f8eb628e24592fd (diff)
downloadfparkan-b21189c3089acc1cf24e530db40707aae292813d.tar.xz
fparkan-b21189c3089acc1cf24e530db40707aae292813d.zip
fix(gameplay): keep selected suit weapons deployed
Diffstat (limited to 'crates/fparkan-runtime')
-rw-r--r--crates/fparkan-runtime/src/player_weapon.rs44
-rw-r--r--crates/fparkan-runtime/src/weapon_deployment.rs4
2 files changed, 37 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs
index 0fe233ac..421f0e7a 100644
--- a/crates/fparkan-runtime/src/player_weapon.rs
+++ b/crates/fparkan-runtime/src/player_weapon.rs
@@ -8,11 +8,19 @@ use fparkan_assets::{
#[derive(Clone, Default)]
pub struct PlayerWeapons {
weapons: Vec<PlayerWeapon>,
- selected: Option<usize>,
+ selection: WeaponSelection,
last_sample_ms: Option<u32>,
clock_ms: f64,
}
+#[derive(Clone, Copy, Default)]
+enum WeaponSelection {
+ #[default]
+ All,
+ StandardSuit,
+ Slot(usize),
+}
+
/// A manual-fire device prepared from its CTLD record and effect rows.
#[derive(Clone)]
pub struct PlayerWeapon {
@@ -141,8 +149,8 @@ impl PlayerWeapons {
/// Selects all weapons with zero, or one weapon by its one-based slot.
pub fn select(&mut self, slot: usize) {
match slot {
- 0 => self.selected = None,
- n if n <= self.weapons.len() => self.selected = Some(n - 1),
+ 0 => self.selection = WeaponSelection::All,
+ n if n <= self.weapons.len() => self.selection = WeaponSelection::Slot(n - 1),
_ => {}
}
}
@@ -168,7 +176,7 @@ impl PlayerWeapons {
.map_or(0, |last| clock_ms.wrapping_sub(last));
self.clock_ms += f64::from(elapsed_ms);
let now = self.clock_ms;
- let selected = self.selected;
+ let selection = self.selection;
self.weapons
.iter_mut()
.enumerate()
@@ -178,7 +186,11 @@ impl PlayerWeapons {
weapon.windup_started = false;
return None;
}
- let selected = selected.is_none_or(|selected| selected == index);
+ let selected = match selection {
+ WeaponSelection::All => true,
+ WeaponSelection::StandardSuit => matches!(index, 0 | 2),
+ WeaponSelection::Slot(slot) => slot == index,
+ };
let mut start =
selected && trigger(index, weapon, &weapon.barrels[weapon.barrel_index].muzzle);
if let Some(deployment) = &mut weapon.deployment {
@@ -367,8 +379,19 @@ pub fn starting_player_weapons(engine: &Engine, cockpit: StartingCockpit) -> Pla
);
}
}
+ let selection = if control
+ .source
+ .name
+ .0
+ .eq_ignore_ascii_case(b"o_tur_ht_02.ctl")
+ {
+ WeaponSelection::StandardSuit
+ } else {
+ WeaponSelection::All
+ };
PlayerWeapons {
weapons,
+ selection,
..PlayerWeapons::default()
}
}
@@ -674,7 +697,7 @@ mod tests {
.into_iter()
.map(|time| time.map(|time| time.0))
.collect();
- assert!(weapons.fire(true, 0).next().is_none());
+ assert!(weapons.fire(false, 0).next().is_none());
assert!(weapons.fire(false, 225).next().is_none());
weapons.apply_firing_pose(hero.component_index, &mut times);
assert_eq!(times[11], Some(44.7));
@@ -694,7 +717,7 @@ mod tests {
(752, 0.0),
] {
let shot = weapons
- .fire(false, now)
+ .fire(now == 500, now)
.next()
.map(|(slot, _, muzzle)| (slot, muzzle.clone()));
assert_eq!(shot.is_some(), now == 626);
@@ -730,8 +753,13 @@ mod tests {
assert!(weapons.fire(false, 753).next().is_none());
assert!(weapons.fire(false, 978).next().is_none());
weapons.apply_firing_pose(hero.component_index, &mut times);
+ assert_eq!(times[11], Some(48.0));
+ weapons.select(2);
+ assert!(weapons.fire(false, 978).next().is_none());
+ assert!(weapons.fire(false, 1203).next().is_none());
+ weapons.apply_firing_pose(hero.component_index, &mut times);
assert_eq!(times[11], Some(45.3));
- assert!(weapons.fire(false, 1253).next().is_none());
+ assert!(weapons.fire(false, 1478).next().is_none());
weapons.apply_firing_pose(hero.component_index, &mut times);
assert_eq!(times[11], Some(42.0));
}
diff --git a/crates/fparkan-runtime/src/weapon_deployment.rs b/crates/fparkan-runtime/src/weapon_deployment.rs
index 0dec287b..4be6f6e8 100644
--- a/crates/fparkan-runtime/src/weapon_deployment.rs
+++ b/crates/fparkan-runtime/src/weapon_deployment.rs
@@ -88,10 +88,8 @@ impl WeaponDeployment {
(track.position_ms - step).max(0.0)
};
}
- // shortcut: use the manual trigger to deploy. Native CTL 24 activation
- // rules beyond the authored tracks and clock still need a live comparison.
self.pending_shot = selected && (self.pending_shot || trigger);
- self.extending = self.pending_shot || cycling;
+ self.extending = selected || cycling;
let start = self.pending_shot
&& self
.tracks