diff options
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol/orders.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol/orders.rs | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol/orders.rs b/crates/fparkan-runtime/src/unit_patrol/orders.rs index 48a849f3..b956c599 100644 --- a/crates/fparkan-runtime/src/unit_patrol/orders.rs +++ b/crates/fparkan-runtime/src/unit_patrol/orders.rs @@ -15,6 +15,7 @@ pub(crate) enum UnitOrder { Stand, Route(Vec<[f32; 2]>), StrategicPatrol(PatrolTarget), + SearchAndDestroy, Shutdown, Resume(Box<PatrollingUnit>), } @@ -25,6 +26,7 @@ impl UnitOrder { Self::Move(_) | Self::Route(_) => 2, Self::Attack(..) => 3, Self::Patrol(..) | Self::StrategicPatrol(_) => 4, + Self::SearchAndDestroy => 5, Self::Shutdown => 0x13, Self::Stand => 0x15, Self::Resume(_) => unreachable!("a suspended order has already started"), @@ -82,6 +84,8 @@ impl UnitPatrol { }; if unit.capture_target.is_some() { 0x11 + } else if unit.search.is_some() { + UnitOrder::SearchAndDestroy.opcode() } else if unit.attack_target.is_some() || unit.raid_factory.is_some() { 3 } else if unit @@ -99,8 +103,9 @@ impl UnitPatrol { pub(crate) fn satellite_route(&self, actor: ObjectHandle) -> Vec<[f32; 2]> { let active = self.units.iter().find(|unit| unit.handle == actor); - // iron3d+0x77ae0 prefers the path whenever there are unvisited points. - if let Some(unit) = active.filter(|unit| !unit.points.is_empty()) { + // iron3d+0x77ae0 draws published waypoints. Search does not publish its + // internal navigation path to the satellite map. + if let Some(unit) = active.filter(|unit| unit.search.is_none() && !unit.points.is_empty()) { return unit.points.iter().copied().collect(); } let mut points = Vec::new(); @@ -119,7 +124,10 @@ impl UnitPatrol { UnitOrder::Route(route) => points.extend(route), UnitOrder::StrategicPatrol(PatrolTarget::Point(point)) => points.push(*point), UnitOrder::StrategicPatrol(PatrolTarget::Object(_)) => {} - UnitOrder::Attack(..) | UnitOrder::Shutdown | UnitOrder::Stand => {} + UnitOrder::Attack(..) + | UnitOrder::Shutdown + | UnitOrder::Stand + | UnitOrder::SearchAndDestroy => {} } } } @@ -299,6 +307,7 @@ impl UnitPatrol { self.standing.insert(actor); return true; } + UnitOrder::SearchAndDestroy => return self.start_search(world, actor), UnitOrder::Route(route) => { for (index, &point) in route.iter().enumerate() { self.move_to(world, actor, point, index != 0); @@ -494,6 +503,26 @@ mod tests { } #[test] + fn command_panel_search_replaces_the_route_without_a_target_click() { + let mut world = fparkan_world::new(Default::default()); + let actor = object(&mut world); + let mut patrol = UnitPatrol::scripted(); + patrol.command_order(&world, actor, UnitOrder::Route(vec![[45.0, 60.0]])); + + patrol.command_order(&world, actor, UnitOrder::SearchAndDestroy); + assert_eq!(patrol.active_order_code(actor), 5); + assert!(patrol.satellite_route(actor).is_empty()); + patrol.units[0].points = VecDeque::from([[25.0, 35.0]]); + assert!(patrol.satellite_route(actor).is_empty()); + assert_eq!(patrol.search_target(actor), Some(None)); + assert!(patrol.attack_limit(&world, actor).is_none()); + + patrol.command_order(&world, actor, UnitOrder::Stand); + assert_eq!(patrol.active_order_code(actor), 0x15); + assert_eq!(patrol.search_target(actor), None); + } + + #[test] fn command_panel_patrol_replaces_the_route_and_tracks_an_object_center() { let mut world = fparkan_world::new(Default::default()); let actor = object(&mut world); |
