aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_patrol.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 18:34:08 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 18:34:08 +0300
commit2d01cd35b069d0d1aa78a064593b54f51b23540d (patch)
tree07fe0aa111c41cadc6b14548881731886dc8f0d1 /crates/fparkan-runtime/src/unit_patrol.rs
parent72ae7666d428c783a03b5378658890947f205de0 (diff)
downloadfparkan-2d01cd35b069d0d1aa78a064593b54f51b23540d.tar.xz
fparkan-2d01cd35b069d0d1aa78a064593b54f51b23540d.zip
fix(ai): resume building capture after losing its assignee
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index 59965b4c..44e83986 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -57,6 +57,7 @@ struct PatrollingUnit {
attack_target: Option<(ObjectHandle, usize)>,
raid_factory: Option<(ObjectHandle, usize)>,
ground_support: Option<Option<GroundSupport>>,
+ capture_target: Option<ObjectHandle>,
capture_passage: Option<CapturePassage>,
animal_clearance: Option<f32>,
}
@@ -192,6 +193,8 @@ impl UnitPatrol {
.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;
+ unit.capture_target = None;
+ unit.capture_passage = None;
let was_attacking = unit.attack_target.take().is_some();
let was_moving = unit.destinations.take().is_some();
if unit.center_object.take().is_some()
@@ -222,6 +225,7 @@ impl UnitPatrol {
attack_target: None,
raid_factory: None,
ground_support: None,
+ capture_target: None,
capture_passage: None,
animal_clearance: None,
});
@@ -258,11 +262,13 @@ impl UnitPatrol {
&mut self,
world: &World,
handle: ObjectHandle,
+ building: ObjectHandle,
destination: [f32; 2],
passage: Option<CapturePassage>,
) {
self.move_to(world, handle, destination, false);
if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) {
+ unit.capture_target = Some(building);
unit.capture_passage = passage;
}
}
@@ -311,14 +317,10 @@ impl UnitPatrol {
.filter_map(|route| route.opening)
}
- pub(super) fn clear_capture_passage(&mut self, unit: ObjectHandle, building: ObjectHandle) {
- self.units.retain(|patrol| {
- patrol.handle != unit
- || patrol
- .capture_passage
- .as_ref()
- .is_none_or(|route| route.building != building)
- });
+ pub(super) fn has_capture_order(&self, unit: ObjectHandle, building: ObjectHandle) -> bool {
+ self.units
+ .iter()
+ .any(|order| order.handle == unit && order.capture_target == Some(building))
}
pub(super) fn order_around_object(
@@ -484,6 +486,7 @@ impl UnitPatrol {
attack_target: None,
raid_factory: None,
ground_support: None,
+ capture_target: None,
capture_passage: None,
animal_clearance: None,
})