aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/satellite_contacts.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 22:49:42 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 22:49:42 +0300
commitcc00c2663f205c84e951901b41e8b87b4fffd2c3 (patch)
tree90e5d4f53cf8437a09b2379b188b6016a6e725fc /crates/fparkan-runtime/src/satellite_contacts.rs
parent24e89ffd6b80bf14ddafddd584953338cce697d6 (diff)
downloadfparkan-cc00c2663f205c84e951901b41e8b87b4fffd2c3.tar.xz
fparkan-cc00c2663f205c84e951901b41e8b87b4fffd2c3.zip
feat(ui): show foreign radar contacts on the satellite map
Diffstat (limited to 'crates/fparkan-runtime/src/satellite_contacts.rs')
-rw-r--r--crates/fparkan-runtime/src/satellite_contacts.rs130
1 files changed, 99 insertions, 31 deletions
diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs
index 2229f9ed..12b45037 100644
--- a/crates/fparkan-runtime/src/satellite_contacts.rs
+++ b/crates/fparkan-runtime/src/satellite_contacts.rs
@@ -7,11 +7,14 @@ use fparkan_world::{
TransformState,
};
+const OWN_TINT: [u8; 3] = [128, 128, 255];
+
/// The original icon crop and position within the 256-pixel satellite image.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct BuildingContact {
pub pixel: [i32; 2],
pub icon_x: u32,
+ pub tint: [u8; 3],
}
/// The original mark for a moving unit within the satellite image.
@@ -19,6 +22,7 @@ pub struct BuildingContact {
pub struct UnitContact {
pub pixel: [i32; 2],
pub cross: bool,
+ pub tint: [u8; 3],
pub heading: Option<UnitHeading>,
pub route: Vec<[i32; 2]>,
}
@@ -41,18 +45,23 @@ pub fn landscape_extent(engine: &Engine) -> Option<f32> {
(extent.is_finite() && extent > 0.0).then_some(extent)
}
-/// Current contacts for the player's own clan, which needs no detection test.
-pub fn owned_buildings(
+/// Building marks for the player's own clan and its radar contacts.
+pub fn visible_buildings(
engine: &Engine,
cockpit: StartingCockpit,
extent: f32,
) -> impl Iterator<Item = BuildingContact> + '_ {
- owned_contacts(engine, cockpit, extent, |_, class| icon_x(class))
- .map(|(pixel, _, _, icon_x)| BuildingContact { pixel, icon_x })
+ visible_contacts(engine, cockpit, extent, |_, class| icon_x(class)).map(
+ |(pixel, _, _, tint, icon_x)| BuildingContact {
+ pixel,
+ icon_x,
+ tint,
+ },
+ )
}
-/// Current marks for the player's vehicles, including newly registered factory output.
-pub fn owned_units(
+/// Unit marks for the player's own clan and its radar contacts.
+pub fn visible_units(
engine: &Engine,
cockpit: StartingCockpit,
extent: f32,
@@ -64,9 +73,8 @@ pub fn owned_units(
.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()) {
+ visible_contacts(engine, cockpit, extent, move |draft, class| {
+ if !unit_class(class) {
return None;
}
// iron3d+0x77f33 reads Behavior property 0x207 (ChassisType).
@@ -75,13 +83,17 @@ pub fn owned_units(
.as_ref()?
.unit_chassis_flags
.get(&draft.original_id?.0)?;
- Some((hero, flags.chassis_type == Some(1)))
+ Some((
+ class == crate::HERO_UNIT_CLASS,
+ flags.chassis_type == Some(1),
+ ))
})
- .map(move |(pixel, handle, pose, (hero, cross))| {
+ .map(move |(pixel, handle, pose, tint, (hero, cross))| {
let selected = selected == Some(handle);
UnitContact {
pixel,
cross,
+ tint,
heading: if hero || selected {
unit_heading(pose, cross, selected)
} else {
@@ -115,38 +127,93 @@ fn unit_heading(pose: TransformState, cross: bool, selected: bool) -> Option<Uni
})
}
-fn owned_contacts<'a, T>(
+fn visible_contacts<'a, T>(
engine: &'a Engine,
cockpit: StartingCockpit,
extent: f32,
marker: impl Fn(&MissionObjectDraft, u32) -> Option<T> + Copy + 'a,
-) -> impl Iterator<Item = ([i32; 2], ObjectHandle, TransformState, T)> + 'a {
+) -> impl Iterator<Item = ([i32; 2], ObjectHandle, TransformState, [u8; 3], T)> + 'a {
let owner = identity_metadata(&engine.world, cockpit.handle)
.ok()
.and_then(|identity| identity.owner_id);
engine.loaded.iter().flat_map(move |mission| {
mission.object_drafts.iter().filter_map(move |draft| {
- let marker = marker(draft, draft.unit_dat_header_flags?)?;
+ let owner = owner?;
+ let class = draft.unit_dat_header_flags?;
+ let marker = marker(draft, class)?;
let handle = handle_by_original_id(&engine.world, draft.original_id?)?;
let clan = identity_metadata(&engine.world, handle).ok()?.owner_id?;
registration_sequence(&engine.world, handle).ok()??;
+ if mission
+ .boarding
+ .is_some_and(|boarding| boarding.hero.handle == handle)
+ {
+ return None;
+ }
+ let tint = if clan == owner {
+ OWN_TINT
+ } else {
+ if !mission.radar.contains(owner, handle) {
+ return None;
+ }
+ let observer = mission.mission.clans.get(usize::from(owner.0))?;
+ let target = mission.mission.clans.get(usize::from(clan.0))?;
+ let relation = target
+ .relations
+ .iter()
+ .find(|entry| entry.other_clan_name.raw == observer.name.raw)
+ .map(|entry| entry.relation_value);
+ // iron3d+0x77ae0 skips dormant hostile units, except the spatial clan.
+ if unit_class(class)
+ && target.mode != 0
+ && relation == Some(0)
+ && mission
+ .unit_patrol
+ .as_ref()
+ .is_some_and(|patrol| patrol.is_shut_down(handle))
+ {
+ return None;
+ }
+ clan_tint(target.mode, relation)
+ };
// Both native contact renderers reject Control's 0xfffe sentinel
// even while the object is still registered as a ruin.
- if Some(clan) != owner
- || mission
- .control_device_tables
- .iter()
- .any(|table| table.handle == handle && table.node_provider_depletion_marked)
+ if mission
+ .control_device_tables
+ .iter()
+ .any(|table| table.handle == handle && table.node_provider_depletion_marked)
{
return None;
}
let pose = transform_state(&engine.world, handle).ok()?;
let [world_x, world_y, _] = pose.position.map(f32::from_bits);
- Some((project([world_x, world_y], extent)?, handle, pose, marker))
+ Some((
+ project([world_x, world_y], extent)?,
+ handle,
+ pose,
+ tint,
+ marker,
+ ))
})
})
}
+fn unit_class(class: u32) -> bool {
+ class & crate::autodemo::MOBILE_UNIT != 0 || class == crate::projectile::ANIMAL_UNIT_CLASS
+}
+
+fn clan_tint(mode: u32, relation: Option<i32>) -> [u8; 3] {
+ // iron3d+0x658a0 selects the observed clan's relation to the viewer.
+ match (mode, relation) {
+ (0, _) => [255, 255, 0],
+ (3, _) => [160; 3],
+ (_, Some(0)) => [255, 0, 0],
+ (_, Some(1)) => [255, 0, 255],
+ (_, Some(2)) => [0, 255, 255],
+ _ => [255, 255, 0],
+ }
+}
+
fn icon_x(class: u32) -> Option<u32> {
// iron3d+0x9f460 selects the icon. The atlas positions come from +0x65370.
Some(match class {
@@ -207,7 +274,7 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
fn captured_warbot_mark_uses_its_live_owner_and_position() {
- use super::{landscape_extent, owned_units, UnitContact};
+ use super::{landscape_extent, visible_units, UnitContact};
use crate::{
create, load_gameplay_mission, starting_cockpit, EngineServices, MissionMode,
MissionRequest, MissionStartupInput,
@@ -247,7 +314,7 @@ 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, Some(handle))
+ assert!(!visible_units(&engine, cockpit, extent, Some(handle))
.any(|contact| contact.pixel == start));
set_owner(&mut engine.world, handle, owner).unwrap();
let destination = [x, y + 50.0];
@@ -258,12 +325,12 @@ mod tests {
.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))
+ let chosen = visible_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)
+ let captured = visible_units(&engine, cockpit, extent, None)
.find(|contact| contact.pixel == start)
.expect("captured warbot mark");
assert_eq!(captured.heading, None);
@@ -281,7 +348,7 @@ mod tests {
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, None).collect();
+ let units: Vec<_> = visible_units(&engine, cockpit, extent, None).collect();
let moved_contact = UnitContact {
pixel: moved,
..captured
@@ -299,7 +366,7 @@ mod tests {
let vehicle = crate::board_friendly_warbot(&mut engine, Some(handle))
.unwrap()
.unwrap();
- let headings: Vec<_> = owned_units(&engine, vehicle, extent, None)
+ let headings: Vec<_> = visible_units(&engine, vehicle, extent, None)
.filter(|unit| unit.heading.is_some())
.collect();
assert_eq!(
@@ -310,7 +377,7 @@ mod tests {
}]
);
assert_eq!(crate::disembark_warbot(&mut engine).unwrap(), Some(cockpit));
- let headings: Vec<_> = owned_units(&engine, cockpit, extent, None)
+ let headings: Vec<_> = visible_units(&engine, cockpit, extent, None)
.filter_map(|unit| unit.heading)
.collect();
assert_eq!(headings, [unit_heading(pose, false, false).unwrap()]);
@@ -319,7 +386,7 @@ mod tests {
#[test]
#[ignore = "requires licensed corpus"]
fn captured_factory_mark_disappears_at_control_depletion() {
- use super::{landscape_extent, owned_buildings, BuildingContact};
+ use super::{landscape_extent, visible_buildings, BuildingContact};
use crate::{
apply_loaded_mission_control_node_delta, create, load_gameplay_mission,
loaded_mission_control_device_tables, starting_cockpit, EngineServices,
@@ -367,15 +434,16 @@ mod tests {
let marker = BuildingContact {
pixel: project([x, y], extent).unwrap(),
icon_x: 72,
+ tint: super::OWN_TINT,
};
- assert!(!owned_buildings(&engine, cockpit, extent).any(|contact| contact == marker));
+ assert!(!visible_buildings(&engine, cockpit, extent).any(|contact| contact == marker));
let owner = identity_metadata(&engine.world, cockpit.handle)
.unwrap()
.owner_id;
assert!(owner.is_some());
set_owner(&mut engine.world, handle, owner).unwrap();
- assert!(owned_buildings(&engine, cockpit, extent).any(|contact| contact == marker));
+ assert!(visible_buildings(&engine, cockpit, extent).any(|contact| contact == marker));
let table = loaded_mission_control_device_tables(&engine)
.unwrap()
@@ -396,6 +464,6 @@ mod tests {
assert!(registration_sequence(&engine.world, handle)
.unwrap()
.is_some());
- assert!(!owned_buildings(&engine, cockpit, extent).any(|contact| contact == marker));
+ assert!(!visible_buildings(&engine, cockpit, extent).any(|contact| contact == marker));
}
}