diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-01 21:54:54 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-01 21:54:54 +0300 |
| commit | ff0a199a9162f08e60bcd3bd645d8c2c9199776f (patch) | |
| tree | 0aa02203b4ba6f7dd97b21e3d75f14eb935ac0fe | |
| parent | 8d775c601f492e8f1e2ec1a28835f1ab3a37b076 (diff) | |
| download | fparkan-ff0a199a9162f08e60bcd3bd645d8c2c9199776f.tar.xz fparkan-ff0a199a9162f08e60bcd3bd645d8c2c9199776f.zip | |
feat(ui): show owned units on the satellite map
| -rw-r--r-- | apps/fparkan-game/src/satellite_map.rs | 55 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/satellite_contacts.rs | 121 | ||||
| -rw-r--r-- | docs/appendices/ui-shell.md | 17 |
3 files changed, 170 insertions, 23 deletions
diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs index 83071a52..f5dabd6f 100644 --- a/apps/fparkan-game/src/satellite_map.rs +++ b/apps/fparkan-game/src/satellite_map.rs @@ -19,10 +19,11 @@ pub(super) struct SatelliteMap { background: EnvironmentGpuRange, compass: EnvironmentGpuRange, compass_size: [f32; 2], - building_layer: EnvironmentGpuRange, + contact_layer: EnvironmentGpuRange, icons: RgbaImage, extent: Option<f32>, buildings: Vec<satellite_contacts::BuildingContact>, + units: Vec<satellite_contacts::UnitContact>, visible: bool, } @@ -41,10 +42,11 @@ impl SatelliteMap { background: add_sprite(preview, assets.background)?, compass: add_sprite(preview, assets.compass)?, compass_size, - building_layer: add_sprite(preview, empty_layer())?, + contact_layer: add_sprite(preview, empty_layer())?, icons: assets.icons, extent: satellite_contacts::landscape_extent(engine), buildings: Vec::new(), + units: Vec::new(), visible: false, })) } @@ -53,7 +55,7 @@ impl SatelliteMap { [ self.background.range_index, self.compass.range_index, - self.building_layer.range_index, + self.contact_layer.range_index, ] } @@ -93,7 +95,7 @@ impl SatelliteMap { ); mesh.vertices[self.background.vertex_start..self.background.vertex_start + 4] .copy_from_slice(&background); - self.draw_buildings(renderer, mesh, viewport, center, size, player)?; + self.draw_contacts(renderer, mesh, viewport, center, size, player)?; let scale = size / 256.0; let [width, height] = self.compass_size.map(|dimension| dimension * scale); @@ -115,7 +117,7 @@ impl SatelliteMap { Ok(()) } - fn draw_buildings( + fn draw_contacts( &mut self, renderer: &mut VulkanSmokeRenderer, mesh: &mut VulkanStaticMesh, @@ -124,21 +126,28 @@ impl SatelliteMap { size: f32, player: Option<(&Engine, StartingCockpit)>, ) -> Result<(), String> { - let buildings = - player - .zip(self.extent) - .map_or_else(Vec::new, |((engine, cockpit), extent)| { - satellite_contacts::owned_buildings(engine, cockpit, extent).collect() - }); - if buildings != self.buildings { + let (buildings, units) = player.zip(self.extent).map_or_else( + || (Vec::new(), Vec::new()), + |((engine, cockpit), extent)| { + ( + satellite_contacts::owned_buildings(engine, cockpit, extent).collect(), + satellite_contacts::owned_units(engine, cockpit, extent).collect(), + ) + }, + ); + if buildings != self.buildings || units != self.units { let mut layer = empty_layer(); for building in &buildings { paint_building(&self.icons, &mut layer, *building); } + for unit in &units { + paint_unit(&mut layer, *unit); + } renderer - .update_material_texture(self.building_layer.material_index, 0, &texture(layer)) + .update_material_texture(self.contact_layer.material_index, 0, &texture(layer)) .map_err(|error| error.to_string())?; self.buildings = buildings; + self.units = units; } let vertices = screen_tl_quad_vertices_pixels( center, @@ -149,7 +158,7 @@ impl SatelliteMap { 1.0, UV, ); - let start = self.building_layer.vertex_start; + let start = self.contact_layer.vertex_start; mesh.vertices[start..start + 4].copy_from_slice(&vertices); Ok(()) } @@ -163,6 +172,24 @@ 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; + } + let dst = (y as usize * MAP_SIZE + x as usize) * 4; + layer.rgba8[dst..dst + 4].copy_from_slice(&[128, 128, 255, 255]); + } + } +} + fn paint_building( atlas: &RgbaImage, layer: &mut RgbaImage, diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs index 534ad6f6..a7c4cb7b 100644 --- a/crates/fparkan-runtime/src/satellite_contacts.rs +++ b/crates/fparkan-runtime/src/satellite_contacts.rs @@ -1,6 +1,6 @@ -//! Live building contacts for the satellite map. +//! Live contacts for the satellite map. -use crate::{Engine, StartingCockpit}; +use crate::{Engine, MissionObjectDraft, StartingCockpit}; use fparkan_world::{ handle_by_original_id, identity_metadata, registration_sequence, transform_state, }; @@ -12,6 +12,13 @@ pub struct BuildingContact { pub icon_x: u32, } +/// The original mark for a moving unit within the satellite image. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct UnitContact { + pub pixel: [i32; 2], + pub cross: bool, +} + /// Width of the original landscape square used by the map projection. pub fn landscape_extent(engine: &Engine) -> Option<f32> { let source = engine.loaded.as_ref()?.terrain.source_mesh()?; @@ -29,12 +36,43 @@ pub fn owned_buildings( 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 }) +} + +/// Current marks for the player's vehicles, including newly registered factory output. +pub fn owned_units( + engine: &Engine, + cockpit: StartingCockpit, + extent: f32, +) -> impl Iterator<Item = UnitContact> + '_ { + owned_contacts(engine, cockpit, extent, move |draft, class| { + if class & crate::autodemo::MOBILE_UNIT == 0 || class == crate::HERO_UNIT_CLASS { + return None; + } + // iron3d+0x77f33 reads Behavior property 0x207 (ChassisType). + let flags = engine + .loaded + .as_ref()? + .unit_chassis_flags + .get(&draft.original_id?.0)?; + Some(flags.chassis_type == Some(1)) + }) + .map(|(pixel, cross)| UnitContact { pixel, cross }) +} + +fn owned_contacts<'a, T>( + engine: &'a Engine, + cockpit: StartingCockpit, + extent: f32, + marker: impl Fn(&MissionObjectDraft, u32) -> Option<T> + Copy + 'a, +) -> impl Iterator<Item = ([i32; 2], 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 x = icon_x(draft.unit_dat_header_flags?)?; + let marker = marker(draft, draft.unit_dat_header_flags?)?; 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()??; @@ -45,10 +83,7 @@ pub fn owned_buildings( .ok()? .position .map(f32::from_bits); - Some(BuildingContact { - pixel: project([world_x, world_y], extent)?, - icon_x: x, - }) + Some((project([world_x, world_y], extent)?, marker)) }) }) } @@ -96,6 +131,78 @@ 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 crate::{ + create, load_gameplay_mission, starting_cockpit, EngineServices, MissionMode, + MissionRequest, MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use fparkan_world::{ + handle_by_original_id, identity_metadata, set_owner, set_transform, transform_state, + }; + use std::sync::Arc; + + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.01/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .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 owner = identity_metadata(&engine.world, cockpit.handle) + .unwrap() + .owner_id; + assert_ne!( + identity_metadata(&engine.world, handle).unwrap().owner_id, + owner + ); + 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)); + set_owner(&mut engine.world, handle, owner).unwrap(); + assert!(owned_units(&engine, cockpit, extent).any(|contact| contact + == UnitContact { + pixel: start, + cross: false + })); + + 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 { + pixel: moved, + cross: false + })); + assert!(!units.iter().any(|contact| contact.pixel == start)); + } + + #[test] + #[ignore = "requires licensed corpus"] fn captured_factory_appears_at_its_existing_position() { use super::{landscape_extent, owned_buildings, BuildingContact}; use crate::{ diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md index 83302b4f..0ef10228 100644 --- a/docs/appendices/ui-shell.md +++ b/docs/appendices/ui-shell.md @@ -167,8 +167,21 @@ RVA `0x349b0` округляет координаты постройки в ми `0x7ea80` ищет её в списке обнаруженных объектов. Тип постройки выбирает значок по таблице RVA `0x9f460`, а RVA `0x65370` берёт соответствующий квадрат 24×24 из страницы `icons`. В FParkan значок своей постройки -появляется после смены владельца. Отметки варботов, обнаружение чужих -объектов и доступность командного режима в разных кабинах открыты. +появляется после смены владельца. + +Варботы и вспомогательные машины рисуются поверх значков построек. RVA +`0x77ae0` применяет ту же проекцию к текущей позиции машины и запрашивает +свойство `0x207`. В `Behavior.dll` (SHA-256 +`ddfbdbde07832358fe6e35e01c8dba9b58e7313789498b6049ed51d4ed9baf99`) +RVA `0xa490` возвращает поле, которое RVA `0x17660` заполняет из +`ChassisType` профиля шасси. Вызов `iron3d.dll` подтвердил, что тип 1 даёт +крест с отрезками от −2 до +2, а типы 0 и 4 дают квадрат 3×3. Для своего +клана цвет обеих меток `#8080FF`. FParkan читает тот же профиль, а владельца +и положение берёт из живого мира. Метка появляется после регистрации машины +и перемещается за ней, когда та пересекает границу пикселя на карте. + +Указатели героя и занятой машины, маршруты выбранных объектов, обнаружение +чужих объектов и доступность командного режима в разных кабинах открыты. ## Контракт новой реализации |
