From 6c9fe794cda795b101825091aee4644efd9422f8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 01:39:12 +0400 Subject: feat(ui): show installed warbot weapons in the cockpit Resolve each selected mount through the original objects.dlb short name and render the live weapon bank after boarding. On a stock Fireline start the medium warbot shows the laser and both separate missile racks. Firing the selected rack reduces its ammunition from 18 to 17 while the other still reads 18. --- crates/fparkan-assets/src/lib.rs | 1 + crates/fparkan-assets/src/object_descriptions.rs | 63 ++++++++++++++++++++++++ crates/fparkan-font/src/bitmap.rs | 10 ++++ 3 files changed, 74 insertions(+) create mode 100644 crates/fparkan-assets/src/object_descriptions.rs (limited to 'crates') diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs index bd66a50a..f2601b44 100644 --- a/crates/fparkan-assets/src/lib.rs +++ b/crates/fparkan-assets/src/lib.rs @@ -36,6 +36,7 @@ mod control_drive; mod control_weapon_sound; mod explosion_profile; pub mod game_font; +pub mod object_descriptions; pub mod satellite_map; mod turret_elevation; mod ui_configuration; diff --git a/crates/fparkan-assets/src/object_descriptions.rs b/crates/fparkan-assets/src/object_descriptions.rs new file mode 100644 index 00000000..59c4e88e --- /dev/null +++ b/crates/fparkan-assets/src/object_descriptions.rs @@ -0,0 +1,63 @@ +//! Short names from the original object's description library. + +use crate::ui_configuration::read; +use fparkan_nres::{decode, NresDocument, ReadProfile}; +use fparkan_vfs::Vfs; + +const DESCRIPTION: u32 = u32::from_le_bytes(*b"DSCR"); + +pub struct ObjectDescriptions(NresDocument); + +impl ObjectDescriptions { + pub fn load(vfs: &dyn Vfs) -> Result { + decode(read(vfs, "objects.dlb")?, ReadProfile::Strict) + .map(Self) + .map_err(|error| error.to_string()) + } + + /// The catalogue's `#1` field, kept in the game's text encoding. + #[must_use] + pub fn short_name(&self, prototype: &[u8]) -> Option<&[u8]> { + let id = self.0.find_bytes(prototype)?; + if self.0.entry(id)?.meta().type_id != DESCRIPTION { + return None; + } + short_name(self.0.payload(id).ok()?) + } +} + +fn short_name(description: &[u8]) -> Option<&[u8]> { + description + .split(|&byte| matches!(byte, b'\n' | b'\r' | 0)) + .find_map(|line| line.strip_prefix(b"#1").filter(|name| !name.is_empty())) +} + +#[cfg(test)] +mod tests { + use super::*; + use fparkan_vfs::DirectoryVfs; + + #[test] + fn keeps_the_short_name_bytes_and_ignores_the_long_name() { + assert_eq!( + short_name(b"//catalogue\r\n#1MRL 1\r\n#2long name\0"), + Some(b"MRL 1".as_slice()) + ); + assert_eq!(short_name(b"#2long name only\r\n"), None); + } + + #[test] + #[ignore = "requires licensed corpus"] + fn original_flying_warbot_prototypes_use_the_native_short_names() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let descriptions = ObjectDescriptions::load(&DirectoryVfs::new(root)).unwrap(); + assert_eq!( + descriptions.short_name(b"E_GUN_MC_21"), + Some(b"MDRLas".as_slice()) + ); + assert_eq!( + descriptions.short_name(b"e_gun_ml_10"), + Some(b"MML9S".as_slice()) + ); + } +} diff --git a/crates/fparkan-font/src/bitmap.rs b/crates/fparkan-font/src/bitmap.rs index c28ce7f4..039e3b9f 100644 --- a/crates/fparkan-font/src/bitmap.rs +++ b/crates/fparkan-font/src/bitmap.rs @@ -128,6 +128,16 @@ impl BitmapFont { if unmappable { return Err("game text contains characters outside CP1251".into()); } + self.centered_line_bytes(&bytes, width, height) + } + + /// Composes a single line from a game resource's original CP1251 bytes. + pub fn centered_line_bytes( + &self, + bytes: &[u8], + width: u16, + height: u16, + ) -> Result { let (width, height) = (usize::from(width), usize::from(height)); if height < self.glyph_height || width == 0 { return Err("game text rectangle is too small".into()); -- cgit v1.2.3