From 2d01cd35b069d0d1aa78a064593b54f51b23540d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 19:34:08 +0400 Subject: fix(ai): resume building capture after losing its assignee --- crates/fparkan-runtime/src/unit_patrol.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'crates/fparkan-runtime/src/unit_patrol.rs') 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>, + capture_target: Option, capture_passage: Option, animal_clearance: Option, } @@ -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, ) { 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, }) -- cgit v1.2.3