From dc92ae05f97d84a1681995e0712b01053e48704c Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 12:48:50 +0400 Subject: feat(ui): show live contacts below the strategic satellite map Use the installed title, close control and contact glyphs. Display the hovered object with clan emblem, name, order and durability in the strategic layout. Compared the Captain and Small Warehouse readouts with the original and checked map closing and cockpit return in stock Two Fortresses. --- apps/fparkan-game/src/main.rs | 2 + apps/fparkan-game/src/mission_overlay.rs | 9 +- apps/fparkan-game/src/satellite_map.rs | 89 +++++++- apps/fparkan-game/src/satellite_map_chrome.rs | 107 +++++++++ apps/fparkan-game/src/strategic_view.rs | 34 ++- crates/fparkan-assets/src/lib.rs | 1 + crates/fparkan-assets/src/satellite_map_chrome.rs | 242 +++++++++++++++++++++ crates/fparkan-assets/src/strategic_roster.rs | 10 +- crates/fparkan-runtime/src/lib.rs | 1 + .../fparkan-runtime/src/strategic_map_readout.rs | 148 +++++++++++++ crates/fparkan-runtime/src/strategic_roster.rs | 10 +- docs/appendices/knowledge-boundaries.md | 2 + docs/appendices/ui-shell.md | 14 ++ 13 files changed, 641 insertions(+), 28 deletions(-) create mode 100644 apps/fparkan-game/src/satellite_map_chrome.rs create mode 100644 crates/fparkan-assets/src/satellite_map_chrome.rs create mode 100644 crates/fparkan-runtime/src/strategic_map_readout.rs diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 02727c17..77039061 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -35,6 +35,8 @@ mod motion_effects; mod player_collision; mod satellite_map; #[cfg(windows)] +mod satellite_map_chrome; +#[cfg(windows)] mod strategic_balance_hud; #[cfg(windows)] mod strategic_roster_hud; diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index 66a40697..0b0eec9a 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -81,8 +81,8 @@ impl MissionOverlay { .inspect_err(|error| eprintln!("strategy_balance_unavailable reason={error}")) .ok() }); - let satellite_map = - SatelliteMap::load(root, mission, engine, preview).unwrap_or_else(|error| { + let satellite_map = SatelliteMap::load(root, mission, engine, cockpit.is_some(), preview) + .unwrap_or_else(|error| { eprintln!("satellite_map_unavailable mission={mission} reason={error}"); None }); @@ -312,10 +312,7 @@ impl StaticVulkanApp { &mut self.mesh, player, demo_target.is_some(), - self.command_view.is_some(), - self.command_view - .as_ref() - .and_then(|view| view.route_draft()), + self.command_view.as_ref(), )?; } let cockpit = self.cockpit.filter(|_| self.command_view.is_none()); diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs index 5eb8ec21..a2be6288 100644 --- a/apps/fparkan-game/src/satellite_map.rs +++ b/apps/fparkan-game/src/satellite_map.rs @@ -1,5 +1,6 @@ use super::{ mission_overlay::{add_overlay_sprite, overlay_texture}, + strategic_view::ActiveCommandView, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, }; use fparkan_assets::{ @@ -30,6 +31,8 @@ pub(super) struct SatelliteMap { units: Vec, visible: bool, command_layout: bool, + #[cfg(windows)] + chrome: Option, } impl SatelliteMap { @@ -37,6 +40,7 @@ impl SatelliteMap { root: &Path, mission: &str, engine: &Engine, + _command_enabled: bool, preview: &mut StaticPreviewScene, ) -> Result, String> { let Some(assets) = load_satellite_map(Arc::new(DirectoryVfs::new(root)), mission)? else { @@ -53,21 +57,51 @@ impl SatelliteMap { compass_right, compass_bottom, ]; + let frame = add_overlay_sprite(preview, assets.frame, bounds, [1.0; 3], 1.0)?; + let background = + add_overlay_sprite(preview, assets.background, image, MAP_TINT, MAP_ALPHA)?; + let compass = add_overlay_sprite(preview, assets.compass, compass, [1.0; 3], 1.0)?; + let contact_layer = add_overlay_sprite(preview, empty_layer(), image, [1.0; 3], 1.0)?; + #[cfg(windows)] + let chrome = _command_enabled + .then(|| { + super::satellite_map_chrome::SatelliteMapChrome::load( + root, + assets.icons.clone(), + preview, + ) + }) + .and_then(|result| { + result + .inspect_err(|error| { + eprintln!("satellite_map_chrome_unavailable reason={error}") + }) + .ok() + }); Ok(Some(Self { - frame: add_overlay_sprite(preview, assets.frame, bounds, [1.0; 3], 1.0)?, - background: add_overlay_sprite(preview, assets.background, image, MAP_TINT, MAP_ALPHA)?, - compass: add_overlay_sprite(preview, assets.compass, compass, [1.0; 3], 1.0)?, - contact_layer: add_overlay_sprite(preview, empty_layer(), image, [1.0; 3], 1.0)?, + frame, + background, + compass, + contact_layer, icons: assets.icons, extent: satellite_contacts::landscape_extent(engine), buildings: Vec::new(), units: Vec::new(), visible: false, command_layout: false, + #[cfg(windows)] + chrome, })) } - pub(super) fn ranges(&self) -> [usize; 4] { + pub(super) fn ranges(&self) -> impl Iterator + '_ { + let ranges = self.map_ranges().into_iter(); + #[cfg(windows)] + let ranges = ranges.chain(self.chrome.iter().flat_map(|chrome| chrome.ranges())); + ranges + } + + fn map_ranges(&self) -> [usize; 4] { [ self.frame.range_index, self.background.range_index, @@ -103,22 +137,55 @@ impl SatelliteMap { self.visible && (left..right).contains(&x) && (top..bottom).contains(&y) } + pub(super) fn chrome_at(&self, _pointer: [f32; 2]) -> bool { + #[cfg(windows)] + return self.visible + && self.chrome.is_some() + && fparkan_assets::satellite_map_chrome::covers_pointer(_pointer); + #[cfg(not(windows))] + false + } + + pub(super) fn close_command_at(&mut self, _pointer: [f32; 2]) -> bool { + #[cfg(windows)] + if self.visible + && self.chrome.is_some() + && fparkan_assets::satellite_map_chrome::close_at(_pointer) + { + return self.hide(); + } + false + } + pub(super) fn draw( &mut self, renderer: &mut VulkanSmokeRenderer, mesh: &mut VulkanStaticMesh, player: Option<(&Engine, StartingCockpit, Option)>, automatic: bool, - command_layout: bool, - draft: Option<&[[f32; 2]]>, + command: Option<&ActiveCommandView>, ) -> Result<(), String> { let visible = self.visible || automatic; let count = if visible { 6 } else { 0 }; - for index in self.ranges() { + for index in self.map_ranges() { renderer .set_draw_range_index_count(index, count) .map_err(|error| error.to_string())?; } + let command_layout = command.is_some(); + #[cfg(windows)] + { + let contact = command + .and_then(ActiveCommandView::pointer) + .and_then(|point| self.command_destination(point)) + .zip(player) + .and_then(|(xy, (engine, cockpit, _))| { + fparkan_runtime::strategic_map_readout::contact_at(engine, cockpit, xy) + }); + if let Some(chrome) = &mut self.chrome { + chrome.draw(renderer, visible && command_layout, contact)?; + } + } if !visible { return Ok(()); } @@ -141,7 +208,11 @@ impl SatelliteMap { } } } - self.update_contacts(renderer, player, draft)?; + self.update_contacts( + renderer, + player, + command.and_then(ActiveCommandView::route_draft), + )?; Ok(()) } diff --git a/apps/fparkan-game/src/satellite_map_chrome.rs b/apps/fparkan-game/src/satellite_map_chrome.rs new file mode 100644 index 00000000..cb02a43f --- /dev/null +++ b/apps/fparkan-game/src/satellite_map_chrome.rs @@ -0,0 +1,107 @@ +use super::{ + mission_overlay::{add_overlay_sprite, overlay_texture}, + DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, +}; +use fparkan_assets::{ + satellite_map_chrome::{Contact, MapChrome, FOOTER, HEADER}, + RgbaImage, +}; +use fparkan_platform_winit::text::StringResources; +use fparkan_runtime::strategic_map_readout::ContactReadout; +use std::path::Path; + +pub(super) struct SatelliteMapChrome { + header: EnvironmentGpuRange, + footer: EnvironmentGpuRange, + art: MapChrome, + strings: StringResources, + current: Option, +} + +impl SatelliteMapChrome { + pub(super) fn load( + root: &Path, + icons: RgbaImage, + preview: &mut StaticPreviewScene, + ) -> Result { + let strings = StringResources::open(&root.join("iron3d.dll"))?; + let title = strings.get(0x13d2).ok_or("missing satellite map title")?; + let art = MapChrome::load(&DirectoryVfs::new(root), icons)?; + Ok(Self { + header: add_overlay_sprite( + preview, + art.header(&title)?, + HEADER.map(|n| n as f32), + [1.0; 3], + 1.0, + )?, + footer: add_overlay_sprite( + preview, + art.footer(None)?, + FOOTER.map(|n| n as f32), + [1.0; 3], + 1.0, + )?, + art, + strings, + current: None, + }) + } + + pub(super) fn ranges(&self) -> [usize; 2] { + [self.header.range_index, self.footer.range_index] + } + + pub(super) fn draw( + &mut self, + renderer: &mut VulkanSmokeRenderer, + visible: bool, + contact: Option, + ) -> Result<(), String> { + for range in self.ranges() { + renderer + .set_draw_range_index_count(range, if visible { 6 } else { 0 }) + .map_err(|error| error.to_string())?; + } + if visible && (contact != self.current) { + let label = contact.map(|entry| self.label(entry)).transpose()?; + let entry = contact.zip(label.as_deref()).map(|(entry, label)| Contact { + label, + class: entry.class, + size: entry.size, + chassis: entry.chassis, + clan: entry.clan, + emblem_tint: entry.emblem_tint, + durability_percent: entry.durability_percent, + }); + renderer + .update_material_texture( + self.footer.material_index, + 0, + &overlay_texture(self.art.footer(entry)?), + ) + .map_err(|error| error.to_string())?; + self.current = contact; + } + Ok(()) + } + + fn label(&self, contact: ContactReadout) -> Result { + let mut name = self + .strings + .get(contact.name_label) + .ok_or_else(|| format!("missing map contact string {:#x}", contact.name_label))?; + if let Some((prefix, serial)) = contact.callsign { + let prefix: String = prefix.into_iter().collect(); + name = format!("{prefix}-{serial} {name}"); + } + if let Some(order) = contact.order_label { + let status = self + .strings + .get(order) + .ok_or_else(|| format!("missing map order string {order:#x}"))?; + name.push_str(&format!(" [{status}]")); + } + Ok(name) + } +} diff --git a/apps/fparkan-game/src/strategic_view.rs b/apps/fparkan-game/src/strategic_view.rs index 3cecce16..b19de9d4 100644 --- a/apps/fparkan-game/src/strategic_view.rs +++ b/apps/fparkan-game/src/strategic_view.rs @@ -52,6 +52,11 @@ impl ActiveCommandView { } } + #[cfg(windows)] + pub(super) fn pointer(&self) -> Option<[f32; 2]> { + self.pointer + } + #[cfg(windows)] pub(super) fn order_panel(&self, rows: &[WarbotRow]) -> Option> { rows.iter() @@ -80,7 +85,7 @@ impl StaticVulkanApp { let kind = match view .order_input .as_ref() - .filter(|_| !over_strategy_controls(xy, rows)) + .filter(|_| !self.over_strategy_controls(xy, rows)) { Some(OrderInput::Route(_)) => { if self.pick_route_point(xy, view.selected_warbot).is_some() { @@ -281,13 +286,23 @@ impl StaticVulkanApp { let Some(xy) = view.pointer else { return; }; + if button == MouseButton::Left + && self + .overlay + .satellite_map + .as_mut() + .is_some_and(|map| map.close_command_at(xy)) + { + return; + } let rows = self .mission_engine .as_ref() .zip(self.cockpit) .filter(|_| button == MouseButton::Left && view.warbots_open) .map_or_else(Vec::new, |(engine, cockpit)| warbot_rows(engine, cockpit)); - let target = if button == MouseButton::Left && !over_strategy_controls(xy, rows.len()) { + let target = if button == MouseButton::Left && !self.over_strategy_controls(xy, rows.len()) + { match &view.order_input { Some(OrderInput::Route(_)) => self .pick_route_point(xy, view.selected_warbot) @@ -465,6 +480,16 @@ impl StaticVulkanApp { (hit.distance <= self.view_camera.far_plane).then_some(hit) } + fn over_strategy_controls(&self, xy: [f32; 2], rows: usize) -> bool { + (0.0..fparkan_assets::strategy_toolbar::EXTENT[0] as f32).contains(&xy[0]) + || covers_pointer(xy, rows) + || self + .overlay + .satellite_map + .as_ref() + .is_some_and(|map| map.chrome_at(xy)) + } + #[cfg(windows)] pub(super) fn strategic_warbot_rows(&mut self) -> Vec { let Some(view) = self.command_view.as_mut().filter(|view| view.warbots_open) else { @@ -479,8 +504,3 @@ impl StaticVulkanApp { rows } } - -fn over_strategy_controls(xy: [f32; 2], rows: usize) -> bool { - (0.0..fparkan_assets::strategy_toolbar::EXTENT[0] as f32).contains(&xy[0]) - || covers_pointer(xy, rows) -} diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs index 1f2cb172..72401c66 100644 --- a/crates/fparkan-assets/src/lib.rs +++ b/crates/fparkan-assets/src/lib.rs @@ -46,6 +46,7 @@ pub mod mission_loader; pub mod mission_pager; pub mod object_descriptions; pub mod satellite_map; +pub mod satellite_map_chrome; pub mod strategic_balance; pub mod strategic_roster; pub mod strategy_cursor; diff --git a/crates/fparkan-assets/src/satellite_map_chrome.rs b/crates/fparkan-assets/src/satellite_map_chrome.rs new file mode 100644 index 00000000..30b41e06 --- /dev/null +++ b/crates/fparkan-assets/src/satellite_map_chrome.rs @@ -0,0 +1,242 @@ +//! Compound header and contact footer from the strategic satellite map. + +use crate::{ + game_font::{load_layout_font, BitmapFont}, + mission_pager::copy_sprite, + strategic_roster::durability_fill, + ui_sprite::{atlas_region, load_ui_page, load_ui_sprites}, + RgbaImage, +}; +use fparkan_vfs::Vfs; + +/// Header and footer bounds in the original 640×480 strategic layout. +pub const HEADER: [u32; 4] = [374, 43, 640, 62]; +pub const FOOTER: [u32; 4] = [374, 330, 640, 349]; +const CLOSE: [u32; 4] = [605, 43, 640, 63]; +const WIDTH: u32 = 266; +const HEIGHT: u32 = 19; +const TEXT_LEFT: u32 = 72; +const TEXT_WIDTH: u32 = 183; + +/// Tests the original close rectangle, including the last logical row. +pub fn close_at(pointer: [f32; 2]) -> bool { + contains(CLOSE, pointer) +} + +/// Whether an event belongs to the header or footer instead of the map or scene. +pub fn covers_pointer(pointer: [f32; 2]) -> bool { + contains([HEADER[0], HEADER[1], HEADER[2], CLOSE[3]], pointer) || contains(FOOTER, pointer) +} + +fn contains([left, top, right, bottom]: [u32; 4], pointer: [f32; 2]) -> bool { + let [x, y] = pointer.map(f32::round_ties_even); + (left as f32..right as f32).contains(&x) && (top as f32..bottom as f32).contains(&y) +} + +/// Live text and art selectors for a single contact. +pub struct Contact<'a> { + pub label: &'a str, + pub class: u32, + pub size: u32, + pub chassis: u32, + pub clan: u16, + pub emblem_tint: [u8; 3], + pub durability_percent: Option, +} + +/// Loaded material for the two strips. +pub struct MapChrome { + font: BitmapFont, + cap: RgbaImage, + body: RgbaImage, + close: RgbaImage, + exit_icon: RgbaImage, + emitter: RgbaImage, + ray: RgbaImage, + end: RgbaImage, + unit_icons: RgbaImage, + extra_icons: RgbaImage, + contact_icons: RgbaImage, +} + +impl MapChrome { + /// Reads the compound controls and marker atlas from the installed game. + pub fn load(vfs: &dyn Vfs, contact_icons: RgbaImage) -> Result { + let [cap, body, close, emitter, ray, end] = load_ui_sprites( + vfs, + "ui/compaund.cfg", + [ + "ccres_ending_text", + "ccres_body_text", + "ccres_exit_button_normal", + "ccres_ray_emitter_off", + "ccres_ray_body", + "ccres_ray_ending", + ], + )?; + let [exit_icon] = load_ui_sprites(vfs, "ui/hq.cfg", ["exit_icon"])?; + Ok(Self { + font: load_layout_font(vfs)?, + cap, + body, + close, + exit_icon, + emitter, + ray, + end, + unit_icons: load_ui_page(vfs, "ui_menu")?, + extra_icons: load_ui_page(vfs, "ui_menu3")?, + contact_icons, + }) + } + + /// Renders the map title and its close button. + pub fn header(&self, title: &str) -> Result { + let mut image = empty_strip(); + let text = self.font.centered_line(title, 226, HEIGHT as u16)?; + stamp(&mut image, &self.cap, [0, 0, 5, HEIGHT], [255; 3]); + stamp(&mut image, &self.body, [5, 0, 231, HEIGHT], [255; 3]); + stamp(&mut image, &text, [5, 0, 231, HEIGHT], [128, 255, 128]); + stamp(&mut image, &self.close, [231, 0, WIDTH, HEIGHT], [255; 3]); + stamp(&mut image, &self.exit_icon, [246, 3, 259, 16], [255; 3]); + Ok(image) + } + + /// Renders the stationary footer and its optional hovered contact. + pub fn footer(&self, contact: Option>) -> Result { + let mut image = empty_strip(); + stamp(&mut image, &self.cap, [0, 0, 5, HEIGHT], [255; 3]); + stamp(&mut image, &self.body, [5, 0, 62, HEIGHT], [255; 3]); + copy_sprite( + &mut image, + &self.cap, + [61, 0, 67, HEIGHT], + [true, false], + [255; 3], + ); + stamp( + &mut image, + &self.emitter, + [62, 0, TEXT_LEFT + 1, HEIGHT], + [255; 3], + ); + let right = TEXT_LEFT + TEXT_WIDTH; + stamp( + &mut image, + &self.ray, + [TEXT_LEFT, 0, right + 1, HEIGHT], + [255; 3], + ); + stamp( + &mut image, + &self.end, + [right, 0, right + 6, HEIGHT], + [255; 3], + ); + let Some(contact) = contact else { + return Ok(image); + }; + if let Some(emblem) = atlas_region( + &self.contact_icons, + [u32::from(contact.clan) * 32, 224, 32, 32], + ) { + stamp(&mut image, &emblem, [7, 2, 22, 17], contact.emblem_tint); + } + self.paint_glyphs(&mut image, &contact); + if let Some((width, rgba)) = contact + .durability_percent + .and_then(|percent| durability_fill(percent, TEXT_WIDTH)) + { + stamp( + &mut image, + &RgbaImage { + width: 1, + height: 1, + rgba8: rgba.to_vec(), + }, + [TEXT_LEFT + 2, 3, TEXT_LEFT + width, HEIGHT - 3], + [255; 3], + ); + } + let label = self + .font + .centered_line(contact.label, TEXT_WIDTH as u16, HEIGHT as u16)?; + stamp(&mut image, &label, [TEXT_LEFT, 0, right, HEIGHT], [255; 3]); + Ok(image) + } + + fn paint_glyphs(&self, image: &mut RgbaImage, contact: &Contact<'_>) { + let building = contact.class & 0x8000_0000 != 0; + let tint = match (building, contact.size) { + (false, 1) => [255, 231, 255], + (false, 2) => [255, 128, 128], + (false, 3) => [128, 255, 128], + (false, 4) => [128, 128, 255], + (true, 2) => [255, 0, 0], + (true, 3) => [0, 255, 0], + (true, 4 | 5) => [0, 0, 255], + _ => [255; 3], + }; + let atlas = if contact.class == 0x8000_0200 { + &self.extra_icons + } else { + &self.unit_icons + }; + let class = match contact.class { + 0x0100_2000 => Some([81, 110]), + 0x0100_4000 => Some([65, 110]), + 0x0100_8000 | 0x0101_0000 | 0x0102_0000 => Some([49, 110]), + 0x8000_0002 => Some([113, 126]), + 0x8000_0004 => Some([129, 126]), + 0x8000_0008 => Some([81, 110]), + 0x8000_0010 => Some([129, 94]), + 0x8000_0040 => Some([97, 126]), + 0x8000_0200 => Some([148, 27]), + 0x8000_0400 => Some([49, 126]), + 0x8001_0000 | 0x8002_0000 | 0x8004_0000 => Some([65, 126]), + 0x8010_0000 | 0x8020_0000 => Some([81, 126]), + _ => None, + }; + if let Some(glyph) = class.and_then(|[x, y]| atlas_region(atlas, [x, y, 15, 15])) { + stamp(image, &glyph, [26, 2, 41, 17], tint); + } + if !building { + let x = match contact.chassis { + 1 => 97, + 2 => 49, + 3 => 65, + 4 => 81, + _ => return, + }; + if let Some(glyph) = atlas_region(&self.unit_icons, [x, 94, 15, 15]) { + stamp(image, &glyph, [45, 2, 60, 17], tint); + } + } + } +} + +fn empty_strip() -> RgbaImage { + RgbaImage { + width: WIDTH, + height: HEIGHT, + rgba8: vec![0; (WIDTH * HEIGHT * 4) as usize], + } +} + +fn stamp(image: &mut RgbaImage, sprite: &RgbaImage, bounds: [u32; 4], tint: [u8; 3]) { + copy_sprite(image, sprite, bounds, [false; 2], tint); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn close_button_is_separate_from_the_image_and_the_title() { + assert!(close_at([605.0, 43.0])); + assert!(close_at([639.0, 62.0])); + assert!(!close_at([604.0, 43.0])); + assert!(!covers_pointer([620.0, 63.0])); + assert!(covers_pointer([620.0, 335.0])); + } +} diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs index 6c755300..b41e4102 100644 --- a/crates/fparkan-assets/src/strategic_roster.rs +++ b/crates/fparkan-assets/src/strategic_roster.rs @@ -203,7 +203,10 @@ impl RosterImages { ); } self.icons(&mut panel, row, [12, y + 2]); - if let Some((width, rgba)) = row.durability_percent.and_then(durability_fill) { + if let Some((width, rgba)) = row + .durability_percent + .and_then(|percent| durability_fill(percent, TEXT_WIDTH)) + { let fill = RgbaImage { width: 1, height: 1, @@ -262,8 +265,8 @@ fn stamp(panel: &mut RgbaImage, sprite: &RgbaImage, bounds: [u32; 4], tint: [u8; copy_sprite(panel, sprite, bounds, [false; 2], tint); } -fn durability_fill(percent: i32) -> Option<(u32, [u8; 4])> { - let width = (f64::from(percent.min(100)) * f64::from(TEXT_WIDTH) * f64::from(0.01_f32)) +pub(crate) fn durability_fill(percent: i32, span: u32) -> Option<(u32, [u8; 4])> { + let width = (f64::from(percent.min(100)) * f64::from(span) * f64::from(0.01_f32)) .round_ties_even() as u32; let rgba = match percent { ..=19 => [128, 0, 0, 128], @@ -289,6 +292,7 @@ mod tests { #[test] fn original_durability_colours_follow_the_rounded_health_percentage() { + let durability_fill = |percent| super::durability_fill(percent, TEXT_WIDTH); assert_eq!(durability_fill(0), None); assert_eq!(durability_fill(19), Some((47, [128, 0, 0, 128]))); assert_eq!(durability_fill(20), Some((50, [128, 128, 0, 128]))); diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 1db75dbc..ad5709b3 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -73,6 +73,7 @@ mod node_stage; mod projectile_capacity; pub mod satellite_contacts; pub mod strategic_balance; +pub mod strategic_map_readout; pub mod strategic_orders; pub mod strategic_roster; pub mod strategic_view; diff --git a/crates/fparkan-runtime/src/strategic_map_readout.rs b/crates/fparkan-runtime/src/strategic_map_readout.rs new file mode 100644 index 00000000..33d24b0f --- /dev/null +++ b/crates/fparkan-runtime/src/strategic_map_readout.rs @@ -0,0 +1,148 @@ +//! Live information for the hovered object on the strategic satellite map. + +use crate::{ + satellite_contacts, + strategic_roster::{order_label, unit_prefix}, + Engine, StartingCockpit, HERO_UNIT_CLASS, +}; +use fparkan_world::identity_metadata; + +/// Object data and original resource selectors for the map footer. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct ContactReadout { + pub class: u32, + pub size: u32, + pub chassis: u32, + pub clan: u16, + pub emblem_tint: [u8; 3], + pub name_label: u32, + pub callsign: Option<([char; 3], u32)>, + pub order_label: Option, + pub durability_percent: Option, +} + +/// Resolves the hovered map contact. Empty terrain and depleted objects have no readout. +pub fn contact_at( + engine: &Engine, + cockpit: StartingCockpit, + point: [f32; 2], +) -> Option { + let handle = satellite_contacts::pick_contact(engine, cockpit, point)?; + let mission = engine.loaded.as_ref()?; + let player = identity_metadata(&engine.world, cockpit.handle) + .ok()? + .owner_id?; + let identity = identity_metadata(&engine.world, handle).ok()?; + let owner = identity.owner_id?; + let original = identity.original_id?.0; + let draft = mission.object_drafts.get(original as usize)?; + let class = draft.unit_dat_header_flags?; + let building = class & 0x8000_0000 != 0; + let root = &draft.unit_components.first()?.resource_raw; + let size = crate::unit_size_class::classify(if building { 3 } else { 4 }, root); + let chassis = mission + .unit_chassis_flags + .get(&original) + .and_then(|flags| flags.chassis_type) + .unwrap_or(0); + let (name_label, callsign, order_label) = if building { + (building_label(class, size), None, None) + } else { + let (role, label) = match class { + 0x0100_2000 => ('T', 0x1838), + 0x0100_4000 => ('B', 0x1839), + 0x0100_8000 => ('W', 0x183a), + 0x0101_0000 => ('C', 0x183b), + HERO_UNIT_CLASS => ('?', 0x1856), + // Animals have map marks but no footer. + _ => return None, + }; + let callsign = (class != HERO_UNIT_CLASS) + .then(|| { + Some(( + unit_prefix(size, chassis, role), + mission.unit_serials.get(handle)?, + )) + }) + .flatten(); + let task = mission + .unit_patrol + .as_ref() + .map_or(0, |patrol| patrol.active_order_code(handle)); + (label, callsign, Some(order_label(task))) + }; + let observer = mission.mission.clans.get(usize::from(player.0))?; + let target = mission.mission.clans.get(usize::from(owner.0))?; + let relation = observer + .relations + .iter() + .find(|entry| entry.other_clan_name.raw == target.name.raw) + .map(|entry| entry.relation_value); + let emblem_tint = emblem_tint(owner == player, relation, building); + let durability_percent = mission + .control_device_tables + .iter() + .find(|table| table.handle == handle) + .and_then(crate::warbot_stats::durability_percent); + Some(ContactReadout { + class, + size, + chassis, + clan: owner.0, + emblem_tint, + name_label, + callsign, + order_label, + durability_percent, + }) +} + +fn emblem_tint(own: bool, relation: Option, building: bool) -> [u8; 3] { + match (own, relation, building) { + (false, Some(0), true) => [255; 3], + (false, Some(0), false) => [255, 0, 0], + (false, Some(1), _) => [128; 3], + _ => satellite_contacts::OWN_TINT, + } +} + +fn building_label(class: u32, size: u32) -> u32 { + // iron3d+0x33a90 uses the type and Behavior's size selector. + match (class, size) { + (0x8000_0002, _) => 0x1799, + (0x8000_0004, 2..=4) => 0x178d + size, + (0x8000_0008, 2..=4) => 0x1792 + size, + (0x8000_0010, 2..=4) => 0x17a1 + size, + (0x8000_0040, _) => 0x17a8, + (0x8000_0200, 2..=3) => 0x17b5 + size, + (0x8000_0400, 2..=5) => 0x179c + size, + (0x8000_1000, 2..=5) => 0x17b0 + size, + (0x8001_0000, _) => 0x17c6, + (0x8002_0000, _) => 0x17cc, + (0x8004_0000, _) => 0x17d2, + (0x8010_0000, _) => 0x17bd, + (0x8020_0000, _) => 0x17c3, + _ => 0x183d, + } +} + +#[cfg(test)] +mod tests { + use super::{building_label, emblem_tint}; + + #[test] + fn warehouse_size_changes_the_name_while_bunker_class_fixes_it() { + assert_eq!(building_label(0x8000_0008, 2), 0x1794); + assert_eq!(building_label(0x8000_0008, 3), 0x1795); + assert_eq!(building_label(0x8002_0000, 3), 0x17cc); + assert_eq!(building_label(0x8000_0008, 5), 0x183d); + } + + #[test] + fn the_own_clan_keeps_its_blue_emblem() { + assert_eq!(emblem_tint(true, Some(1), false), [128, 128, 255]); + assert_eq!(emblem_tint(false, Some(1), false), [128; 3]); + assert_eq!(emblem_tint(false, Some(0), true), [255; 3]); + assert_eq!(emblem_tint(false, Some(0), false), [255, 0, 0]); + } +} diff --git a/crates/fparkan-runtime/src/strategic_roster.rs b/crates/fparkan-runtime/src/strategic_roster.rs index 07735aff..1e3bd8bd 100644 --- a/crates/fparkan-runtime/src/strategic_roster.rs +++ b/crates/fparkan-runtime/src/strategic_roster.rs @@ -46,7 +46,7 @@ impl UnitSerials { self.slots.insert(handle.slot, (handle.generation, *serial)); } - fn get(&self, handle: ObjectHandle) -> Option { + pub(super) fn get(&self, handle: ObjectHandle) -> Option { let &(generation, serial) = self.slots.get(&handle.slot)?; (generation == handle.generation).then_some(serial) } @@ -117,7 +117,7 @@ pub fn warbot_rows(engine: &Engine, cockpit: StartingCockpit) -> Vec .map_or(0, |patrol| patrol.active_order_code(handle)); let row = WarbotRow { handle, - prefix: [letter(b"?TSML", size), letter(b"?FSWTAU", chassis), role], + prefix: unit_prefix(size, chassis, role), serial, class_label, order_label: order_label(order), @@ -137,7 +137,11 @@ fn letter(alphabet: &[u8], value: u32) -> char { char::from(alphabet.get(value as usize).copied().unwrap_or(b'?')) } -fn order_label(order: u32) -> u32 { +pub(super) fn unit_prefix(size: u32, chassis: u32, role: char) -> [char; 3] { + [letter(b"?TSML", size), letter(b"?FSWTAU", chassis), role] +} + +pub(super) fn order_label(order: u32) -> u32 { match order { 0 => 0x1824, 2 => 0x1828, diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md index 45b94522..4481d692 100644 --- a/docs/appendices/knowledge-boundaries.md +++ b/docs/appendices/knowledge-boundaries.md @@ -313,6 +313,8 @@ FParkan. Маршрут и патруль используют программ флаг области. Выбор объекта в 3D опирается на геометрию столкновений FParkan. Аппаратный режим ANI, указатели остальных действий и подсветка приказа после щелчка остаются открытыми. +В строке контакта карты открыты специальные имена, сетевой выбор +эмблемы и подсказка при наведении на кнопку закрытия. Балансы используют текущие итоги симуляции кланов. Для повторного входа из бункера используется материал пола. Движение камеры из варбота с МФУ и проверка входа и возврата в штатной игре остаются открытыми. diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md index d45a8737..50c2114d 100644 --- a/docs/appendices/ui-shell.md +++ b/docs/appendices/ui-shell.md @@ -164,6 +164,20 @@ RVA `0x733e0` задаёт рамку от `(374, 0)` до `(640, 266)` в си `(474, 6)`, а сторона равна 320 пикселям. Автодемо использует эту раскладку с живыми отметками клана и маршрутом выбранного варбота. +В стратегическом режиме RVA `0x73c80` ставит карту ниже заголовка. +Заголовок начинается в `(374, 43)` и использует строку `0x13d2`. +Кнопка с `exit_icon` принимает щелчок в прямоугольнике от `(605, 43)` +до `(640, 63)` и закрывает карту. В кабине и AutoDemo этих строк нет. + +Под картой, на Y = 330, та же функция показывает сведения об объекте +под указателем. Пустая область оставляет строку пустой. Для юнитов +здесь показан статус приказа. Для строений имя берётся из таблицы типов +и размеров (RVA `0x33a90`). Например, малый склад использует строку +`0x1794`, а средний бункер — `0x17cc`. Эмблемы кланов берутся из +восьми квадратов 32×32 вдоль нижнего края страницы `icons` (RVA +`0x65690`). Полоса заполняется по общей прочности, как в строке списка +варботов. Подпись исчезает при уходе с отметки или истощении объекта. + В кадровом проходе `iron3d.dll` RVA `0x60f50` отключает тест глубины перед вызовом игрового HUD на `0x610bb`. В обычном режиме HUD рисует спутниковую карту через RVA `0x73ba0`. В Vulkan экранные слои карты и -- cgit v1.2.3