diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-14 15:49:49 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-14 15:49:49 +0300 |
| commit | d7d51ac4bdedad7c9d611c343877b54468c9ea4d (patch) | |
| tree | ce63e45ceb4bef988d097bac3f261db60d8fe20a /crates/fparkan-runtime/src/unit_patrol.rs | |
| parent | 406d17ca79a0b29e062c60ad87c1dbe44f844444 (diff) | |
| download | fparkan-d7d51ac4bdedad7c9d611c343877b54468c9ea4d.tar.xz fparkan-d7d51ac4bdedad7c9d611c343877b54468c9ea4d.zip | |
feat(combat): damage the building part struck by a projectile
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index 6c30e566..cfbee245 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -27,6 +27,7 @@ struct PatrollingUnit { points: VecDeque<[f32; 2]>, retry_ms: u32, attack: Option<ObjectHandle>, + raid_factory: Option<(ObjectHandle, usize)>, } pub(super) struct PreparedPatrol { @@ -68,7 +69,7 @@ impl UnitPatrol { } let clan = &mission.clans[bundle.clan_index]; - let factories = drafts.iter().filter(|draft| { + let factories = drafts.iter().enumerate().filter(|(_, draft)| { draft.unit_dat_header_flags == Some(PLANT_CLASS) && mission .clans @@ -91,9 +92,9 @@ impl UnitPatrol { (draft.position[0] - target.position[0]) .hypot(draft.position[1] - target.position[1]) }; - if let Some(factory) = factories + if let Some((index, factory)) = factories .clone() - .min_by(|a, b| distance(a).total_cmp(&distance(b))) + .min_by(|(_, a), (_, b)| distance(a).total_cmp(&distance(b))) { ordered |= self.order( world, @@ -101,6 +102,9 @@ impl UnitPatrol { [factory.position[0], factory.position[1]], 60.0, ); + if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) { + unit.raid_factory = Some((handles[index], index)); + } } } self.factory_raid_clans += usize::from(ordered); @@ -126,6 +130,7 @@ impl UnitPatrol { self.units .retain(|unit| transform_state(world, unit.handle).is_ok()); if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) { + unit.raid_factory = None; if unit.center != center || unit.radius != radius { unit.center = center; unit.radius = radius; @@ -142,6 +147,7 @@ impl UnitPatrol { points: VecDeque::new(), retry_ms: 0, attack: None, + raid_factory: None, }); true } @@ -150,6 +156,13 @@ impl UnitPatrol { self.units.iter().any(|unit| unit.handle == handle) } + pub(super) fn raid_factory(&self, handle: ObjectHandle) -> Option<(ObjectHandle, usize)> { + self.units + .iter() + .find(|unit| unit.handle == handle)? + .raid_factory + } + pub(super) fn activate(&mut self, world: &World, handle: ObjectHandle) { if let Some(center) = self.center { self.order(world, handle, center, 150.0); @@ -180,6 +193,7 @@ impl UnitPatrol { points: VecDeque::new(), retry_ms: 0, attack: None, + raid_factory: None, }) .collect(); Some(Self { |
