From 0b0764de47a0a1fef30464fb5e4be496e101b083 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 12:28:48 +0400 Subject: feat(ui): assign patrols from the strategic warbot panel Use the installed order string and GUARD cursor. A single valid click assigns a 300-unit patrol around a terrain point or a live object. Checked the terrain and satellite paths, rejected terrain, and cancellation in the stock Two Fortresses window. --- crates/fparkan-runtime/src/strategic_orders.rs | 53 +++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) (limited to 'crates/fparkan-runtime/src/strategic_orders.rs') diff --git a/crates/fparkan-runtime/src/strategic_orders.rs b/crates/fparkan-runtime/src/strategic_orders.rs index 2c40c31f..d49fa963 100644 --- a/crates/fparkan-runtime/src/strategic_orders.rs +++ b/crates/fparkan-runtime/src/strategic_orders.rs @@ -1,8 +1,21 @@ //! Orders issued by the player from the strategic warbot panel. -use crate::{strategic_roster::warbot_rows, unit_patrol::UnitPatrol, Engine, StartingCockpit}; +use crate::{ + strategic_roster::warbot_rows, + unit_patrol::{UnitOrder, UnitPatrol}, + Engine, StartingCockpit, +}; use fparkan_terrain::NavigationQuery; -use fparkan_world::{identity_metadata, ObjectHandle}; +use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle}; + +/// Where the warbot is to patrol. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum PatrolTarget { + /// Fixed world coordinates. + Point([f32; 2]), + /// Live object whose position determines the patrol center. + Object(ObjectHandle), +} /// Tests a route waypoint using the selected warbot's chassis and the native areal flag. pub fn accepts_waypoint(engine: &Engine, actor: ObjectHandle, [x, y]: [f32; 2]) -> bool { @@ -34,7 +47,7 @@ pub fn accepts_waypoint(engine: &Engine, actor: ObjectHandle, [x, y]: [f32; 2]) /// Stops the selected warbot and clears its outstanding movement orders. pub fn stand(engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle) -> bool { - issue(engine, cockpit, actor, None) + issue(engine, cockpit, actor, UnitOrder::Stand) } /// Replaces the selected warbot's order with the confirmed sequence of world points. @@ -51,14 +64,42 @@ pub fn follow_route( { return false; } - issue(engine, cockpit, actor, Some(points.to_vec())) + issue(engine, cockpit, actor, UnitOrder::Route(points.to_vec())) +} + +/// Whether an object may be used as the center of a patrol. +pub fn accepts_patrol_object(engine: &Engine, target: ObjectHandle) -> bool { + registration_sequence(&engine.world, target) + .ok() + .flatten() + .is_some() + && engine.loaded.as_ref().is_some_and(|mission| { + !mission + .control_device_tables + .iter() + .any(|table| table.handle == target && table.node_provider_depletion_marked) + }) +} + +/// Replaces the selected warbot's order with a patrol around a point or an object. +pub fn patrol_at( + engine: &mut Engine, + cockpit: StartingCockpit, + actor: ObjectHandle, + target: PatrolTarget, +) -> bool { + let valid = match target { + PatrolTarget::Point(point) => accepts_waypoint(engine, actor, point), + PatrolTarget::Object(target) => accepts_patrol_object(engine, target), + }; + valid && issue(engine, cockpit, actor, UnitOrder::StrategicPatrol(target)) } fn issue( engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle, - route: Option>, + order: UnitOrder, ) -> bool { if !warbot_rows(engine, cockpit) .iter() @@ -72,6 +113,6 @@ fn issue( mission .unit_patrol .get_or_insert_with(UnitPatrol::scripted) - .command_order(&engine.world, actor, route); + .command_order(&engine.world, actor, order); true } -- cgit v1.2.3