diff options
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol.rs | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index 5e083403..48e4924a 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -22,6 +22,7 @@ use fparkan_world::{set_transform, transform_state}; use std::collections::{BTreeMap, HashSet, VecDeque}; mod orders; +mod search_and_destroy; pub(super) use orders::supports_order; pub(super) use orders::UnitOrder; @@ -56,6 +57,7 @@ pub(super) struct PatrollingUnit { place_points: PatrolPoints, retry_ms: u32, attack: Option<ObjectHandle>, + search: Option<search_and_destroy::Search>, attack_target: Option<(ObjectHandle, usize)>, raid_factory: Option<(ObjectHandle, usize)>, ground_support: Option<Option<GroundSupport>>, @@ -201,9 +203,11 @@ impl UnitPatrol { unit.capture_passage = None; let was_attacking = unit.attack_target.take().is_some(); let was_moving = unit.destinations.take().is_some(); + let was_searching = unit.search.take().is_some(); if unit.center_object.take().is_some() || was_moving || was_attacking + || was_searching || unit.center != center || unit.radius != radius { @@ -226,6 +230,7 @@ impl UnitPatrol { place_points: PatrolPoints::default(), retry_ms: 0, attack: None, + search: None, attack_target: None, raid_factory: None, ground_support: None, @@ -444,10 +449,9 @@ impl UnitPatrol { handle: ObjectHandle, ) -> Option<PatrolAttackLimit> { // A raid starts with an explicit attack order. It never receives PatrolPlace limits. - let unit = self - .units - .iter() - .find(|unit| unit.handle == handle && unit.raid_factory.is_none())?; + let unit = self.units.iter().find(|unit| { + unit.handle == handle && unit.raid_factory.is_none() && unit.search.is_none() + })?; Some(PatrolAttackLimit { center: unit.center(world)?, radius: unit.radius, @@ -488,6 +492,7 @@ impl UnitPatrol { place_points: PatrolPoints::default(), retry_ms: 0, attack: None, + search: None, attack_target: None, raid_factory: None, ground_support: None, @@ -627,16 +632,31 @@ impl UnitPatrol { let enemy = targets .iter() .find(|(handle, _)| *handle == unit.handle) - .map(|(_, target)| *target); + .map(|(_, target)| *target) + .filter(|target| { + unit.search.is_none() + || !super::attack_target::complete( + world, + &mission.control_device_tables, + target.handle, + ) + }); if unit.attack != enemy.map(|target| target.handle) { unit.points.clear(); unit.retry_ms = 0; unit.attack = enemy.map(|target| target.handle); } + if let Some(search) = &mut unit.search { + if search.forget_depleted(world, &mission.control_device_tables) { + unit.points.clear(); + unit.retry_ms = 0; + } + } let place_patrol = unit.center_object.is_none() && unit.destinations.is_none() && unit.attack_target.is_none() - && unit.raid_factory.is_none(); + && unit.raid_factory.is_none() + && unit.search.is_none(); if place_patrol && (enemy.is_none() || unit.place_points.current().is_none()) { if let Some(bounds) = terrain.surface_bounds() { let mut checks = 0; @@ -769,6 +789,8 @@ impl UnitPatrol { .unwrap_or_default() } else if unit.attack_target.is_some() { VecDeque::new() + } else if let Some(search) = &mut unit.search { + search.route(world, mission, unit.handle, from, crt)? } else if let Some([x, y]) = unit.place_points.current().filter(|_| place_patrol) { let route = terrain .height_at([x, y]) @@ -886,6 +908,7 @@ impl PatrollingUnit { self.center_object.is_none() && self.attack_target.is_none() && self.destinations.is_none() + && self.search.is_none() && self.center == point } |
