aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/satellite_contacts.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 22:23:04 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 22:23:04 +0300
commit7848a77aef2995d855a5b07de138c8b9d3f6fdc8 (patch)
treea7dbc7c1f5cda441b65aad7875c11dcf5e51d176 /crates/fparkan-runtime/src/satellite_contacts.rs
parent90ea3afec48e2bac7016db08987e5c94878b1993 (diff)
downloadfparkan-7848a77aef2995d855a5b07de138c8b9d3f6fdc8.tar.xz
fparkan-7848a77aef2995d855a5b07de138c8b9d3f6fdc8.zip
feat(ui): draw selected warbot routes on the satellite map
Diffstat (limited to 'crates/fparkan-runtime/src/satellite_contacts.rs')
-rw-r--r--crates/fparkan-runtime/src/satellite_contacts.rs51
1 files changed, 44 insertions, 7 deletions
diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs
index a766e911..f3867ac8 100644
--- a/crates/fparkan-runtime/src/satellite_contacts.rs
+++ b/crates/fparkan-runtime/src/satellite_contacts.rs
@@ -15,11 +15,12 @@ pub struct BuildingContact {
}
/// The original mark for a moving unit within the satellite image.
-#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UnitContact {
pub pixel: [i32; 2],
pub cross: bool,
pub heading: Option<UnitHeading>,
+ pub route: Vec<[i32; 2]>,
}
/// The selected vehicle or unboarded hero's outline and heading stroke.
@@ -55,8 +56,14 @@ pub fn owned_units(
engine: &Engine,
cockpit: StartingCockpit,
extent: f32,
+ selected: Option<ObjectHandle>,
) -> impl Iterator<Item = UnitContact> + '_ {
let boarded = crate::player_vehicle(engine).map(|vehicle| vehicle.handle);
+ let selected = boarded.or(selected);
+ let patrol = engine
+ .loaded
+ .as_ref()
+ .and_then(|mission| mission.unit_patrol.as_ref());
owned_contacts(engine, cockpit, extent, move |draft, class| {
let hero = class == crate::HERO_UNIT_CLASS;
if class & crate::autodemo::MOBILE_UNIT == 0 || (hero && boarded.is_some()) {
@@ -71,7 +78,7 @@ pub fn owned_units(
Some((hero, flags.chassis_type == Some(1)))
})
.map(move |(pixel, handle, pose, (hero, cross))| {
- let selected = boarded == Some(handle);
+ let selected = selected == Some(handle);
UnitContact {
pixel,
cross,
@@ -80,6 +87,13 @@ pub fn owned_units(
} else {
None
},
+ route: patrol.filter(|_| selected).map_or_else(Vec::new, |patrol| {
+ patrol
+ .satellite_route(handle)
+ .into_iter()
+ .filter_map(|xy| project(xy, extent))
+ .collect()
+ }),
}
})
}
@@ -226,18 +240,41 @@ mod tests {
let mut pose = transform_state(&engine.world, handle).unwrap();
let [x, y, _] = pose.position.map(f32::from_bits);
let start = project([x, y], extent).unwrap();
- assert!(!owned_units(&engine, cockpit, extent).any(|contact| contact.pixel == start));
+ assert!(!owned_units(&engine, cockpit, extent, Some(handle))
+ .any(|contact| contact.pixel == start));
set_owner(&mut engine.world, handle, owner).unwrap();
- let captured = owned_units(&engine, cockpit, extent)
+ let destination = [x, y + 50.0];
+ engine
+ .loaded
+ .as_mut()
+ .unwrap()
+ .unit_patrol
+ .get_or_insert_with(crate::unit_patrol::UnitPatrol::scripted)
+ .move_to(&engine.world, handle, destination, false);
+ let chosen = owned_units(&engine, cockpit, extent, Some(handle))
+ .find(|contact| contact.pixel == start)
+ .expect("selected warbot mark");
+ assert!(chosen.heading.is_some_and(|heading| heading.selected));
+ assert_eq!(chosen.route, [project(destination, extent).unwrap()]);
+ let captured = owned_units(&engine, cockpit, extent, None)
.find(|contact| contact.pixel == start)
.expect("captured warbot mark");
assert_eq!(captured.heading, None);
+ assert!(captured.route.is_empty());
+ engine
+ .loaded
+ .as_mut()
+ .unwrap()
+ .unit_patrol
+ .as_mut()
+ .unwrap()
+ .clear_move(handle);
pose.position[0] = (x + extent / 8.0).to_bits();
set_transform(&mut engine.world, handle, pose).unwrap();
let moved = project([x + extent / 8.0, y], extent).unwrap();
assert_eq!(moved, [start[0] + 32, start[1]]);
- let units: Vec<_> = owned_units(&engine, cockpit, extent).collect();
+ let units: Vec<_> = owned_units(&engine, cockpit, extent, None).collect();
let moved_contact = UnitContact {
pixel: moved,
..captured
@@ -255,7 +292,7 @@ mod tests {
let vehicle = crate::board_friendly_warbot(&mut engine, Some(handle))
.unwrap()
.unwrap();
- let headings: Vec<_> = owned_units(&engine, vehicle, extent)
+ let headings: Vec<_> = owned_units(&engine, vehicle, extent, None)
.filter(|unit| unit.heading.is_some())
.collect();
assert_eq!(
@@ -266,7 +303,7 @@ mod tests {
}]
);
assert_eq!(crate::disembark_warbot(&mut engine).unwrap(), Some(cockpit));
- let headings: Vec<_> = owned_units(&engine, cockpit, extent)
+ let headings: Vec<_> = owned_units(&engine, cockpit, extent, None)
.filter_map(|unit| unit.heading)
.collect();
assert_eq!(headings, [unit_heading(pose, false, false).unwrap()]);