aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/satellite_contacts.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 11:28:48 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 11:28:48 +0300
commit0b0764de47a0a1fef30464fb5e4be496e101b083 (patch)
tree91d129a508a0e2fdbedfdeadf7b9fa5bbd0f1a2e /crates/fparkan-runtime/src/satellite_contacts.rs
parent733f9d92e0d4e40ed40db42fa6cd11294e49eb7b (diff)
downloadfparkan-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/satellite_contacts.rs')
-rw-r--r--crates/fparkan-runtime/src/satellite_contacts.rs23
1 files changed, 23 insertions, 0 deletions
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<f32> {
(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<ObjectHandle> {
+ 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,