diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 11:28:48 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 11:28:48 +0300 |
| commit | 0b0764de47a0a1fef30464fb5e4be496e101b083 (patch) | |
| tree | 91d129a508a0e2fdbedfdeadf7b9fa5bbd0f1a2e /crates/fparkan-runtime/src/strategic_orders.rs | |
| parent | 733f9d92e0d4e40ed40db42fa6cd11294e49eb7b (diff) | |
| download | fparkan-0b0764de47a0a1fef30464fb5e4be496e101b083.tar.xz fparkan-0b0764de47a0a1fef30464fb5e4be496e101b083.zip | |
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.
Diffstat (limited to 'crates/fparkan-runtime/src/strategic_orders.rs')
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_orders.rs | 53 |
1 files changed, 47 insertions, 6 deletions
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<Vec<[f32; 2]>>, + 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 } |
