aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/fparkan-game/src/satellite_map.rs58
-rw-r--r--crates/fparkan-runtime/src/satellite_contacts.rs133
-rw-r--r--docs/appendices/ui-shell.md15
3 files changed, 164 insertions, 42 deletions
diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs
index f5dabd6f..37d60fa9 100644
--- a/apps/fparkan-game/src/satellite_map.rs
+++ b/apps/fparkan-game/src/satellite_map.rs
@@ -175,19 +175,59 @@ fn empty_layer() -> RgbaImage {
fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) {
let radius = if unit.cross { 2 } else { 1 };
for dy in -radius..=radius {
- let y = unit.pixel[1].saturating_add(dy);
- if !(0..MAP_SIZE as i32).contains(&y) {
- continue;
- }
for dx in -radius..=radius {
- let x = unit.pixel[0].saturating_add(dx);
- if !(0..MAP_SIZE as i32).contains(&x) || (unit.cross && dx != 0 && dy != 0) {
- continue;
+ if !unit.cross || dx == 0 || dy == 0 {
+ paint_unit_pixel(layer, unit.pixel, [dx, dy], [128, 128, 255, 255]);
}
- let dst = (y as usize * MAP_SIZE + x as usize) * 4;
- layer.rgba8[dst..dst + 4].copy_from_slice(&[128, 128, 255, 255]);
}
}
+
+ let Some(heading) = unit.heading else {
+ return;
+ };
+ let color = if heading.selected {
+ [255; 4]
+ } else {
+ [0, 255, 0, 255]
+ };
+ let border = radius + 2;
+ for offset in -border..=border {
+ for point in [
+ [offset, -border],
+ [offset, border],
+ [-border, offset],
+ [border, offset],
+ ] {
+ paint_unit_pixel(layer, unit.pixel, point, color);
+ }
+ }
+ let [end_x, end_y] = heading.tip_offset;
+ let [mut x, mut y] = [0, 0];
+ let [dx, dy] = [end_x.abs(), -end_y.abs()];
+ let mut error = dx + dy;
+ loop {
+ paint_unit_pixel(layer, unit.pixel, [x, y], color);
+ if [x, y] == [end_x, end_y] {
+ break;
+ }
+ let twice = 2 * error;
+ if twice >= dy {
+ error += dy;
+ x += end_x.signum();
+ }
+ if twice <= dx {
+ error += dx;
+ y += end_y.signum();
+ }
+ }
+}
+
+fn paint_unit_pixel(layer: &mut RgbaImage, center: [i32; 2], offset: [i32; 2], color: [u8; 4]) {
+ let [x, y] = std::array::from_fn(|axis| center[axis].saturating_add(offset[axis]));
+ if (0..MAP_SIZE as i32).contains(&x) && (0..MAP_SIZE as i32).contains(&y) {
+ let dst = (y as usize * MAP_SIZE + x as usize) * 4;
+ layer.rgba8[dst..dst + 4].copy_from_slice(&color);
+ }
}
fn paint_building(
diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs
index a7c4cb7b..a766e911 100644
--- a/crates/fparkan-runtime/src/satellite_contacts.rs
+++ b/crates/fparkan-runtime/src/satellite_contacts.rs
@@ -1,8 +1,10 @@
//! Live contacts for the satellite map.
use crate::{Engine, MissionObjectDraft, StartingCockpit};
+use fparkan_render::LegacyIron3dEulerTransform;
use fparkan_world::{
- handle_by_original_id, identity_metadata, registration_sequence, transform_state,
+ handle_by_original_id, identity_metadata, registration_sequence, transform_state, ObjectHandle,
+ TransformState,
};
/// The original icon crop and position within the 256-pixel satellite image.
@@ -17,6 +19,14 @@ pub struct BuildingContact {
pub struct UnitContact {
pub pixel: [i32; 2],
pub cross: bool,
+ pub heading: Option<UnitHeading>,
+}
+
+/// The selected vehicle or unboarded hero's outline and heading stroke.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub struct UnitHeading {
+ pub tip_offset: [i32; 2],
+ pub selected: bool,
}
/// Width of the original landscape square used by the map projection.
@@ -37,7 +47,7 @@ pub fn owned_buildings(
extent: f32,
) -> impl Iterator<Item = BuildingContact> + '_ {
owned_contacts(engine, cockpit, extent, |_, class| icon_x(class))
- .map(|(pixel, icon_x)| BuildingContact { pixel, icon_x })
+ .map(|(pixel, _, _, icon_x)| BuildingContact { pixel, icon_x })
}
/// Current marks for the player's vehicles, including newly registered factory output.
@@ -46,8 +56,10 @@ pub fn owned_units(
cockpit: StartingCockpit,
extent: f32,
) -> impl Iterator<Item = UnitContact> + '_ {
+ let boarded = crate::player_vehicle(engine).map(|vehicle| vehicle.handle);
owned_contacts(engine, cockpit, extent, move |draft, class| {
- if class & crate::autodemo::MOBILE_UNIT == 0 || class == crate::HERO_UNIT_CLASS {
+ let hero = class == crate::HERO_UNIT_CLASS;
+ if class & crate::autodemo::MOBILE_UNIT == 0 || (hero && boarded.is_some()) {
return None;
}
// iron3d+0x77f33 reads Behavior property 0x207 (ChassisType).
@@ -56,9 +68,37 @@ pub fn owned_units(
.as_ref()?
.unit_chassis_flags
.get(&draft.original_id?.0)?;
- Some(flags.chassis_type == Some(1))
+ Some((hero, flags.chassis_type == Some(1)))
+ })
+ .map(move |(pixel, handle, pose, (hero, cross))| {
+ let selected = boarded == Some(handle);
+ UnitContact {
+ pixel,
+ cross,
+ heading: if hero || selected {
+ unit_heading(pose, cross, selected)
+ } else {
+ None
+ },
+ }
+ })
+}
+
+fn unit_heading(pose: TransformState, cross: bool, selected: bool) -> Option<UnitHeading> {
+ // iron3d+0x753e0 takes the second column of the unit's world transform.
+ let basis = LegacyIron3dEulerTransform {
+ translation: [0.0; 3],
+ orientation_radians: pose.orientation.map(f32::from_bits),
+ }
+ .try_row_major()?;
+ // iron3d+0x77ae0 scales forward XY by the glyph width and inverts Y.
+ let length = f64::from(if cross { 4 } else { 3 }) * f64::from(1.8_f32);
+ let tip_offset =
+ [basis[1], -basis[5]].map(|axis| (f64::from(axis) * length).round_ties_even() as i32);
+ Some(UnitHeading {
+ tip_offset,
+ selected,
})
- .map(|(pixel, cross)| UnitContact { pixel, cross })
}
fn owned_contacts<'a, T>(
@@ -66,7 +106,7 @@ fn owned_contacts<'a, T>(
cockpit: StartingCockpit,
extent: f32,
marker: impl Fn(&MissionObjectDraft, u32) -> Option<T> + Copy + 'a,
-) -> impl Iterator<Item = ([i32; 2], T)> + 'a {
+) -> impl Iterator<Item = ([i32; 2], ObjectHandle, TransformState, T)> + 'a {
let owner = identity_metadata(&engine.world, cockpit.handle)
.ok()
.and_then(|identity| identity.owner_id);
@@ -79,11 +119,9 @@ fn owned_contacts<'a, T>(
if Some(clan) != owner {
return None;
}
- let [world_x, world_y, _] = transform_state(&engine.world, handle)
- .ok()?
- .position
- .map(f32::from_bits);
- Some((project([world_x, world_y], extent)?, marker))
+ 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))
})
})
}
@@ -116,7 +154,7 @@ fn project([x, y]: [f32; 2], extent: f32) -> Option<[i32; 2]> {
#[cfg(test)]
mod tests {
- use super::{icon_x, project};
+ use super::{icon_x, project, unit_heading, TransformState, UnitHeading};
#[test]
fn satellite_coordinates_match_the_original_inset_and_rounding() {
@@ -130,6 +168,22 @@ mod tests {
}
#[test]
+ fn satellite_heading_uses_chassis_glyph_width_and_inverts_world_y() {
+ let mut pose = TransformState::default();
+ pose.orientation[2] = std::f32::consts::FRAC_PI_2.to_bits();
+ assert_eq!(
+ unit_heading(pose, false, false),
+ Some(UnitHeading {
+ tip_offset: [-5, 0],
+ selected: false,
+ }),
+ );
+ pose.orientation[2] = (-0.6_f32).atan2(0.8).to_bits();
+ assert_eq!(unit_heading(pose, false, true).unwrap().tip_offset, [3, -4]);
+ assert_eq!(unit_heading(pose, true, true).unwrap().tip_offset, [4, -6]);
+ }
+
+ #[test]
#[ignore = "requires licensed corpus"]
fn captured_warbot_mark_uses_its_live_owner_and_position() {
use super::{landscape_extent, owned_units, UnitContact};
@@ -140,6 +194,7 @@ mod tests {
use fparkan_vfs::DirectoryVfs;
use fparkan_world::{
handle_by_original_id, identity_metadata, set_owner, set_transform, transform_state,
+ OriginalObjectId,
};
use std::sync::Arc;
@@ -160,17 +215,7 @@ mod tests {
.unwrap();
let cockpit = starting_cockpit(&engine).unwrap();
let extent = landscape_extent(&engine).unwrap();
- let id = engine
- .loaded
- .as_ref()
- .unwrap()
- .object_drafts
- .iter()
- .find(|draft| draft.unit_dat_header_flags == Some(crate::boarding::WARBOT_CLASS))
- .unwrap()
- .original_id
- .unwrap();
- let handle = handle_by_original_id(&engine.world, id).unwrap();
+ let handle = handle_by_original_id(&engine.world, OriginalObjectId(11)).unwrap();
let owner = identity_metadata(&engine.world, cockpit.handle)
.unwrap()
.owner_id;
@@ -183,22 +228,48 @@ mod tests {
let start = project([x, y], extent).unwrap();
assert!(!owned_units(&engine, cockpit, extent).any(|contact| contact.pixel == start));
set_owner(&mut engine.world, handle, owner).unwrap();
- assert!(owned_units(&engine, cockpit, extent).any(|contact| contact
- == UnitContact {
- pixel: start,
- cross: false
- }));
+ let captured = owned_units(&engine, cockpit, extent)
+ .find(|contact| contact.pixel == start)
+ .expect("captured warbot mark");
+ assert_eq!(captured.heading, None);
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();
- assert!(units.contains(&UnitContact {
+ let moved_contact = UnitContact {
pixel: moved,
- cross: false
- }));
+ ..captured
+ };
+ assert!(units.contains(&moved_contact));
assert!(!units.iter().any(|contact| contact.pixel == start));
+ assert!(units
+ .iter()
+ .any(|contact| contact.heading.is_some_and(|heading| !heading.selected)));
+
+ let mut hero_pose = transform_state(&engine.world, cockpit.handle).unwrap();
+ hero_pose.position = pose.position;
+ hero_pose.position[0] = (f32::from_bits(pose.position[0]) - 15.0).to_bits();
+ set_transform(&mut engine.world, cockpit.handle, hero_pose).unwrap();
+ let vehicle = crate::board_friendly_warbot(&mut engine, Some(handle))
+ .unwrap()
+ .unwrap();
+ let headings: Vec<_> = owned_units(&engine, vehicle, extent)
+ .filter(|unit| unit.heading.is_some())
+ .collect();
+ assert_eq!(
+ headings,
+ [UnitContact {
+ heading: unit_heading(pose, moved_contact.cross, true),
+ ..moved_contact
+ }]
+ );
+ assert_eq!(crate::disembark_warbot(&mut engine).unwrap(), Some(cockpit));
+ let headings: Vec<_> = owned_units(&engine, cockpit, extent)
+ .filter_map(|unit| unit.heading)
+ .collect();
+ assert_eq!(headings, [unit_heading(pose, false, false).unwrap()]);
}
#[test]
diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md
index 0ef10228..073db7b0 100644
--- a/docs/appendices/ui-shell.md
+++ b/docs/appendices/ui-shell.md
@@ -180,8 +180,19 @@ RVA `0xa490` возвращает поле, которое RVA `0x17660` запÐ
и положение берёт из живого мира. Метка появляется после регистрации машины
и перемещается за ней, когда та пересекает границу пикселя на карте.
-Указатели героя и занятой машины, маршруты выбранных объектов, обнаружение
-чужих объектов и доступность командного режима в разных кабинах открыты.
+У героя тот же квадрат, зелёный контур и линия курса. RVA `0x753e0`
+берёт направление из второго столбца матрицы объекта. RVA `0x77ae0`
+умножает его горизонтальные компоненты на ширину метки и на 1,8, меняет
+знак Y и округляет смещение конца линии. Например, при курсе
+`(0,6; 0,8)` вызов DLL даёт смещение `(+3, −4)` для квадрата и
+`(+4, −6)` для креста.
+
+При посадке RVA `0x63c60` выводит героя из группы ландшафта, которую
+проверяет отрисовщик меток, и выбирает занятый варбот. Пока герой внутри,
+на карте остаётся метка этой машины с белым контуром и её собственным
+курсом. При выходе RVA `0x63e3f` снимает выделение машины, и на карте
+возвращается метка героя. Маршруты выбранных машин,
+обнаружение чужих объектов и указатели внешних камер остаются открыты.
## Контракт новой реализации