aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_combat.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/unit_combat.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_combat.rs45
1 files changed, 32 insertions, 13 deletions
diff --git a/crates/fparkan-runtime/src/unit_combat.rs b/crates/fparkan-runtime/src/unit_combat.rs
index 799f0009..cd90c924 100644
--- a/crates/fparkan-runtime/src/unit_combat.rs
+++ b/crates/fparkan-runtime/src/unit_combat.rs
@@ -25,6 +25,7 @@ const ATTACK_RANGE: f32 = 400.0;
const ATTACK_STOP_RANGE: f32 = 200.0;
/// An autonomous projectile type, in render-pool order.
+#[derive(Clone)]
pub struct AutoDemoProjectileType {
/// Prototype archive.
pub archive: String,
@@ -112,6 +113,7 @@ pub enum AutoDemoCombatEvent {
},
}
+#[derive(Default)]
pub(super) struct AutoDemoCombat {
units: Vec<Unit>,
reserve: Vec<Unit>,
@@ -202,25 +204,41 @@ impl AutoDemoCombat {
})
.collect();
let mut battle = Self {
- units: Vec::new(),
- reserve: Vec::new(),
hostile,
guard_clans,
- projectiles: Vec::new(),
- weapon_effects: Vec::new(),
- flights: Vec::new(),
- next_flight_id: 0,
- finished_segments: Vec::new(),
- pose_failures: super::WeaponPoseReport::default(),
- report: CombatReport::default(),
- unavailable: 0,
+ ..Self::default()
};
for (index, (draft, &handle)) in drafts.iter().zip(handles).enumerate() {
- battle.add_unit(vfs, index, draft, handle, assets, index >= reserve_start);
+ battle.add_unit(
+ vfs,
+ index,
+ draft,
+ handle,
+ assets,
+ index,
+ index >= reserve_start,
+ );
}
battle
}
+ pub(super) fn prepare_reserve(&self) -> Self {
+ Self {
+ projectiles: self.projectiles.clone(),
+ weapon_effects: self.weapon_effects.clone(),
+ ..Self::default()
+ }
+ }
+
+ pub(super) fn install_reserve(&mut self, prepared: Self) {
+ self.projectiles = prepared.projectiles;
+ self.weapon_effects = prepared.weapon_effects;
+ self.reserve.extend(prepared.reserve);
+ self.unavailable += prepared.unavailable;
+ self.report.unavailable.extend(prepared.report.unavailable);
+ }
+
+ #[allow(clippy::too_many_arguments)]
pub(super) fn add_unit(
&mut self,
vfs: &Arc<dyn Vfs>,
@@ -228,6 +246,7 @@ impl AutoDemoCombat {
draft: &MissionObjectDraft,
handle: ObjectHandle,
assets: &MissionAssets,
+ asset_row: usize,
reserve: bool,
) {
let class = draft.unit_dat_header_flags.unwrap_or(0);
@@ -242,7 +261,7 @@ impl AutoDemoCombat {
let weapons = prepare_unit_weapons(
assets
.object_component_controls
- .get(index)
+ .get(asset_row)
.map_or(&[], Vec::as_slice),
);
if class == ANIMAL_UNIT_CLASS && weapons.weapons().is_empty() {
@@ -322,7 +341,7 @@ impl AutoDemoCombat {
weapons,
slots,
effects,
- poses: WeaponPoses::new(draft, assets, index),
+ poses: WeaponPoses::new(draft, assets, asset_row),
idle_target: DefaultWeaponTarget::default(),
original_id: draft.original_id.map_or(handle.slot, |id| id.0),
});