aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/mission_hints.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 20:11:00 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 20:11:00 +0300
commit480161a733ebcb8261b13cf602df24d4423b4125 (patch)
tree5acfd62fa9b6c216b8ce0928d6e57068a0f20eb5 /apps/fparkan-game/src/mission_hints.rs
parent90cc800c36c6c8f974c2f96fa6499ad3486a7ef1 (diff)
downloadfparkan-480161a733ebcb8261b13cf602df24d4423b4125.tar.xz
fparkan-480161a733ebcb8261b13cf602df24d4423b4125.zip
fix(ui): show the original sender on mission messages
Diffstat (limited to 'apps/fparkan-game/src/mission_hints.rs')
-rw-r--r--apps/fparkan-game/src/mission_hints.rs51
1 files changed, 48 insertions, 3 deletions
diff --git a/apps/fparkan-game/src/mission_hints.rs b/apps/fparkan-game/src/mission_hints.rs
index 191932cb..9e6e2055 100644
--- a/apps/fparkan-game/src/mission_hints.rs
+++ b/apps/fparkan-game/src/mission_hints.rs
@@ -14,6 +14,8 @@ const WIDTH: u16 = 640;
const HEIGHT: u16 = 384;
const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]];
const PAGER_DURATION_MS: u32 = 20_000;
+const INSTRUCTOR: u32 = 0x0bf1;
+const INFORMATION_SYSTEM: u32 = 0x1846;
pub(super) struct MissionHints {
messages: Option<MessageResources>,
@@ -45,6 +47,7 @@ struct MessageResources {
config: Arc<[u8]>,
catalog: Arc<[u8]>,
strings: StringResources,
+ sender_strings: Option<StringResources>,
}
impl MissionHints {
@@ -89,18 +92,30 @@ impl MissionHints {
.messages
.as_ref()
.ok_or("missing mission message resources")?;
- let symbol = audio::message_symbol(&messages.config, index, "TEXT_RESOURCE")?
+ let config = String::from_utf8_lossy(&messages.config);
+ let fields = audio::message_fields(&config, index)
+ .ok_or_else(|| format!("missing message {index}"))?;
+ let resource = fields
+ .get("TEXT_RESOURCE")
.ok_or_else(|| format!("missing TEXT_RESOURCE for message {index}"))?;
- let symbol = symbol.to_ascii_uppercase();
+ let symbol = audio::parse_cfg_value(resource)?.to_ascii_uppercase();
let text = String::from_utf8_lossy(&messages.catalog);
let id = audio::config_objects(&text)
.find_map(|object| object.get(&symbol).and_then(|value| value.parse().ok()))
.ok_or_else(|| format!("missing string ID for {symbol}"))?;
- let body = messages
+ let mut body = messages
.strings
.get(id)
.filter(|text| !text.trim().is_empty())
.ok_or_else(|| format!("missing string {id} for {symbol}"))?;
+ if let Some(strings) = &messages.sender_strings {
+ let sender = sender_resource_id(&fields);
+ if let Some(label) = strings.get(sender) {
+ body = format!("{label}\n{body}");
+ } else {
+ eprintln!("sim_coverage mission_text_unavailable=1 sender={sender} index={index}");
+ }
+ }
self.pending = Some(PagerMessage {
index,
body,
@@ -238,15 +253,31 @@ impl MessageResources {
let library = normalize_relative(library.as_bytes(), PathPolicy::StrictLegacy)
.map_err(|error| error.to_string())?;
let strings = StringResources::open(&root.join(library.as_str()))?;
+ let sender_strings = match StringResources::open(&root.join("iron3d.dll")) {
+ Ok(strings) => Some(strings),
+ Err(error) => {
+ eprintln!("sim_coverage mission_text_unavailable=1 resource=iron3d.dll field=sender reason={error}");
+ None
+ }
+ };
eprintln!("sim_coverage mission_text_display_approx=1");
Ok(Some(Self {
config,
catalog,
strings,
+ sender_strings,
}))
}
}
+fn sender_resource_id(fields: &std::collections::BTreeMap<String, &str>) -> u32 {
+ if fields.contains_key("INFO_SYSTEM") {
+ INFORMATION_SYSTEM
+ } else {
+ INSTRUCTOR
+ }
+}
+
fn pager_visible(posted_ms: u32, clock: u32) -> bool {
clock.wrapping_sub(posted_ms) < PAGER_DURATION_MS
}
@@ -274,6 +305,20 @@ mod tests {
use super::*;
#[test]
+ fn information_sender_is_selected_by_the_presence_of_the_field() {
+ let config = "object first\nmessage_index=1\nend\n\
+ object second\nmessage_index=2\ninfo_system=false\nend\n";
+ assert_eq!(
+ sender_resource_id(&audio::message_fields(config, 1).unwrap()),
+ INSTRUCTOR
+ );
+ assert_eq!(
+ sender_resource_id(&audio::message_fields(config, 2).unwrap()),
+ INFORMATION_SYSTEM
+ );
+ }
+
+ #[test]
fn pager_expires_twenty_seconds_after_posting_across_clock_wrap() {
let posted = u32::MAX - 500;
assert!(pager_visible(posted, posted));