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/satellite_contacts.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crates/fparkan-runtime/src/satellite_contacts.rs') diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs index 17030fc1..31181bc1 100644 --- a/crates/fparkan-runtime/src/satellite_contacts.rs +++ b/crates/fparkan-runtime/src/satellite_contacts.rs @@ -45,6 +45,29 @@ pub fn landscape_extent(engine: &Engine) -> Option { (extent.is_finite() && extent > 0.0).then_some(extent) } +/// Picks a live unit within 40 world units or a building within 80, in registry order. +pub fn pick_contact( + engine: &Engine, + cockpit: StartingCockpit, + [x, y]: [f32; 2], +) -> Option { + let extent = landscape_extent(engine)?; + visible_contacts(engine, cockpit, extent, |_, class| { + let unit = unit_class(class); + (unit || icon_x(class).is_some()).then_some(unit) + }) + .filter_map(|(_, handle, pose, _, unit)| { + let [u, v, _] = pose.position.map(f32::from_bits); + let limit = if unit { 40.0 } else { 80.0 }; + let distance = f64::from(u - x).hypot(f64::from(v - y)); + (distance < limit).then_some(())?; + let sequence = registration_sequence(&engine.world, handle).ok()??; + Some((!unit, sequence, handle)) + }) + .min_by_key(|&(building, sequence, _)| (building, sequence)) + .map(|(_, _, handle)| handle) +} + /// Building marks for the player's own clan and its radar contacts. pub fn visible_buildings( engine: &Engine, -- cgit v1.2.3