diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 22:23:04 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 22:23:04 +0300 |
| commit | 7848a77aef2995d855a5b07de138c8b9d3f6fdc8 (patch) | |
| tree | a7dbc7c1f5cda441b65aad7875c11dcf5e51d176 /crates/fparkan-runtime/src/unit_patrol/orders.rs | |
| parent | 90ea3afec48e2bac7016db08987e5c94878b1993 (diff) | |
| download | fparkan-7848a77aef2995d855a5b07de138c8b9d3f6fdc8.tar.xz fparkan-7848a77aef2995d855a5b07de138c8b9d3f6fdc8.zip | |
feat(ui): draw selected warbot routes on the satellite map
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol/orders.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol/orders.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol/orders.rs b/crates/fparkan-runtime/src/unit_patrol/orders.rs index cde2bd09..560f2142 100644 --- a/crates/fparkan-runtime/src/unit_patrol/orders.rs +++ b/crates/fparkan-runtime/src/unit_patrol/orders.rs @@ -50,6 +50,32 @@ pub(crate) fn supports_order(order: &Handler15Invocation) -> bool { } 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()) { + return unit.points.iter().copied().collect(); + } + let mut points = Vec::new(); + if let Some(unit) = active { + unit.append_point_orders(&mut points); + } + if let Some((_, queue)) = self + .script_orders + .iter() + .find(|(handle, _)| *handle == actor) + { + for order in queue { + match order { + UnitOrder::Move(point) | UnitOrder::Patrol(point, _) => points.push(*point), + UnitOrder::Resume(unit) => unit.append_point_orders(&mut points), + UnitOrder::Attack(..) | UnitOrder::Shutdown => {} + } + } + } + points + } + pub(crate) fn clear_capture_order(&mut self, unit: ObjectHandle, building: ObjectHandle) { self.units .retain(|order| order.handle != unit || order.capture_target != Some(building)); @@ -314,6 +340,16 @@ impl UnitPatrol { } } +impl PatrollingUnit { + fn append_point_orders(&self, points: &mut Vec<[f32; 2]>) { + if let Some(destinations) = &self.destinations { + points.extend(destinations); + } else if self.patrols_point(self.center) && self.raid_factory.is_none() { + points.push(self.center); + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -334,6 +370,24 @@ mod tests { } #[test] + fn satellite_route_prefers_remaining_waypoints_to_coordinate_orders() { + let mut world = fparkan_world::new(Default::default()); + let actor = object(&mut world); + let enemy = object(&mut world); + let mut patrol = UnitPatrol::scripted(); + patrol.enqueue_script_order(&world, actor, UnitOrder::Move([20.0, 30.0]), false); + patrol.enqueue_script_order(&world, actor, UnitOrder::Attack(enemy, 1), true); + patrol.enqueue_script_order(&world, actor, UnitOrder::Patrol([40.0, 50.0], 60.0), true); + assert_eq!(patrol.satellite_route(actor), [[20.0, 30.0], [40.0, 50.0]]); + + patrol.units[0].points = VecDeque::from([[10.0, 18.0], [20.0, 30.0]]); + assert_eq!(patrol.satellite_route(actor), [[10.0, 18.0], [20.0, 30.0]]); + patrol.units[0].points.pop_front(); + assert_eq!(patrol.satellite_route(actor), [[20.0, 30.0]]); + assert!(patrol.satellite_route(enemy).is_empty()); + } + + #[test] fn move_attack_and_shutdown_wait_for_the_preceding_task() { let mut world = fparkan_world::new(Default::default()); let actor = object(&mut world); |
