diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 10:26:10 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 10:26:10 +0300 |
| commit | b9eebd22cde510bea9553470e7384fe61a41b5c0 (patch) | |
| tree | dd7e2579208e7f1831c6b256065ac58a9578a93b /crates/fparkan-runtime/src/player_weapon.rs | |
| parent | ec513e13e598964e8139bf3518bb35ebee176b7a (diff) | |
| download | fparkan-b9eebd22cde510bea9553470e7384fe61a41b5c0.tar.xz fparkan-b9eebd22cde510bea9553470e7384fe61a41b5c0.zip | |
fix(combat): use authored range for autonomous weapons
Diffstat (limited to 'crates/fparkan-runtime/src/player_weapon.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/player_weapon.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/player_weapon.rs b/crates/fparkan-runtime/src/player_weapon.rs index ffc488b1..cfec0524 100644 --- a/crates/fparkan-runtime/src/player_weapon.rs +++ b/crates/fparkan-runtime/src/player_weapon.rs @@ -21,6 +21,7 @@ pub struct PlayerWeapon { pub(super) control_record_index: usize, pub(super) charge: Option<crate::mobile_budget::Charge>, pub(super) energy_waits: u64, + pub(super) autonomous_fire_distance: f32, /// Name of the projectile prototype. pub projectile: String, /// Archive named by the weapon's projectile descriptor. @@ -126,13 +127,13 @@ impl PlayerWeapons { trigger: bool, clock_ms: u32, ) -> impl Iterator<Item = (usize, &PlayerWeapon, &PreparedControlPoint)> { - self.fire_where(clock_ms, move |_, _| trigger) + self.fire_where(clock_ms, move |_, _, _| trigger) } pub(super) fn fire_where( &mut self, clock_ms: u32, - mut trigger: impl FnMut(&PlayerWeapon, &PreparedControlPoint) -> bool, + mut trigger: impl FnMut(usize, &PlayerWeapon, &PreparedControlPoint) -> bool, ) -> impl Iterator<Item = (usize, &PlayerWeapon, &PreparedControlPoint)> { if let Some(last) = self.last_sample_ms.replace(clock_ms) { self.clock_ms += f64::from(clock_ms.wrapping_sub(last)); @@ -144,7 +145,7 @@ impl PlayerWeapons { .enumerate() .filter_map(move |(index, weapon)| { let start = selected.is_none_or(|selected| selected == index) - && trigger(weapon, &weapon.barrels[weapon.barrel_index].muzzle); + && trigger(index, weapon, &weapon.barrels[weapon.barrel_index].muzzle); let barrel = weapon.sample_fire(start, now)?; Some((index, &*weapon, &weapon.barrels[barrel].muzzle)) }) @@ -354,6 +355,7 @@ fn prepare_weapons( control_record_index, charge: None, energy_waits: 0, + autonomous_fire_distance: f32::from_bits(record.fixed_words[19]), projectile, projectile_archive, effect, @@ -436,6 +438,7 @@ mod tests { control_record_index: 0, charge: None, energy_waits: 0, + autonomous_fire_distance: 0.0, projectile: String::from("test"), projectile_archive: String::from("test.rlb"), effect: None, |
