aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 05:49:08 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 05:49:08 +0300
commit0d8031eccad92190ea01c2c7f9a2cee28adecb62 (patch)
tree2e391fbe4d92f5876641fe232363bdd6b30ab6d9 /apps/fparkan-game
parentca1828fc869aaeb72df00c642f918a7723c84df4 (diff)
downloadfparkan-0d8031eccad92190ea01c2c7f9a2cee28adecb62.tar.xz
fparkan-0d8031eccad92190ea01c2c7f9a2cee28adecb62.zip
fix(ui): validate warbot designs on transfer
Keep the selected model open on a failed research check and post the original central-computer message to the shared pager and history. Verified rejection and corrected production order in the Field Camp window with Vulkan validation.
Diffstat (limited to 'apps/fparkan-game')
-rw-r--r--apps/fparkan-game/src/factory_menu.rs36
-rw-r--r--apps/fparkan-game/src/mission_hints.rs75
-rw-r--r--apps/fparkan-game/src/mission_notices.rs19
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs28
4 files changed, 112 insertions, 46 deletions
diff --git a/apps/fparkan-game/src/factory_menu.rs b/apps/fparkan-game/src/factory_menu.rs
index 1b2a084e..46519199 100644
--- a/apps/fparkan-game/src/factory_menu.rs
+++ b/apps/fparkan-game/src/factory_menu.rs
@@ -14,8 +14,8 @@ use fparkan_assets::factory_projects::{
hit_test, FactoryProjectAction, FactoryProjectImages, EXTENT, ORIGIN, PROJECT_SLOTS,
};
use fparkan_runtime::{
- factory_design_bytes, factory_part_variants, factory_project_components, Engine,
- FactoryPartChange,
+ check_factory_design, factory_design_bytes, factory_part_variants, factory_project_components,
+ Engine, FactoryPartChange,
};
use fparkan_world::ObjectHandle;
use std::{
@@ -340,6 +340,28 @@ impl FactoryProjectPanel {
}
impl StaticVulkanApp {
+ fn send_designer_project(&mut self) {
+ let (Some(menu), Some(engine), Some(cockpit)) =
+ (&mut self.factory_menu, &self.mission_engine, self.cockpit)
+ else {
+ return;
+ };
+ let Some(designer) = &menu.designer else {
+ return;
+ };
+ let Some(project) = designer.selected else {
+ return;
+ };
+ let scheme = menu.choices[designer.slots.start + project].scheme;
+ if let Err(error) = check_factory_design(engine, cockpit, scheme, &designer.changes) {
+ eprintln!("designer_transfer_rejected {error}");
+ #[cfg(windows)]
+ self.present_computer_notice(0x83f, self.simulation_time_ms);
+ return;
+ }
+ menu.designer_action(DesignerAction::Send, self.simulation_time_ms);
+ }
+
pub(super) fn handle_designer_project_key(
&mut self,
key: PhysicalKey,
@@ -439,9 +461,7 @@ impl StaticVulkanApp {
KeyCode::Escape => {
menu.designer_action(DesignerAction::Exit, self.simulation_time_ms)
}
- KeyCode::Enter | KeyCode::NumpadEnter => {
- menu.designer_action(DesignerAction::Send, self.simulation_time_ms)
- }
+ KeyCode::Enter | KeyCode::NumpadEnter => self.send_designer_project(),
_ => {}
}
self.update_mission_title();
@@ -641,7 +661,11 @@ impl StaticVulkanApp {
}
designer.dirty = true;
} else if let Some(action) = designer.hover {
- menu.designer_action(action, self.simulation_time_ms);
+ if action == DesignerAction::Send {
+ self.send_designer_project();
+ } else {
+ menu.designer_action(action, self.simulation_time_ms);
+ }
self.update_mission_title();
}
return true;
diff --git a/apps/fparkan-game/src/mission_hints.rs b/apps/fparkan-game/src/mission_hints.rs
index 47ecc25c..f9713335 100644
--- a/apps/fparkan-game/src/mission_hints.rs
+++ b/apps/fparkan-game/src/mission_hints.rs
@@ -15,11 +15,15 @@ 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 CENTRAL_COMPUTER: u32 = 0x605;
const INSTRUCTOR: u32 = 0x0bf1;
const INFORMATION_SYSTEM: u32 = 0x1846;
pub(super) struct MissionHints {
messages: Option<MessageResources>,
+ sender_strings: Option<StringResources>,
+ pager: Option<MissionPager>,
+ overflow_hint: String,
range: EnvironmentGpuRange,
pending: Option<PagerMessage>,
active: Option<RenderedMessage>,
@@ -50,9 +54,6 @@ struct MessageResources {
config: Arc<[u8]>,
catalog: Arc<[u8]>,
strings: StringResources,
- sender_strings: Option<StringResources>,
- pager: MissionPager,
- overflow_hint: String,
}
impl MissionHints {
@@ -69,6 +70,24 @@ impl MissionHints {
eprintln!("sim_coverage mission_text_unavailable=1 reason={error}");
None
});
+ 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
+ }
+ };
+ let overflow_hint = sender_strings
+ .as_ref()
+ .and_then(|strings| strings.get(0x1840))
+ .map(|text| text.replace("%s", "F1"))
+ .unwrap_or_default();
+ let pager = MissionPager::load(&DirectoryVfs::new(root))
+ .map(Some)
+ .unwrap_or_else(|error| {
+ eprintln!("sim_coverage mission_text_unavailable=1 reason={error}");
+ None
+ });
eprintln!("sim_coverage mission_outcome_display_approx=1");
let material = append_environment_gradient_material(&mut preview.materials)?;
preview.materials[material].screen_tl = true;
@@ -85,6 +104,9 @@ impl MissionHints {
// Keep the degenerate reservation until the renderer receives live caption vertices.
Ok(Self {
messages,
+ sender_strings,
+ pager,
+ overflow_hint,
range,
pending: None,
active: None,
@@ -114,20 +136,38 @@ impl MissionHints {
.filter(|text| !text.trim().is_empty())
.ok_or_else(|| format!("missing string {id} for {symbol}"))?;
let sender_id = sender_resource_id(&fields);
- let sender = messages
+ let sender = self
.sender_strings
.as_ref()
.and_then(|strings| strings.get(sender_id));
if sender.is_none() {
eprintln!("sim_coverage mission_text_unavailable=1 sender={sender_id} index={index}");
}
+ Ok(self.enqueue(index, sender.unwrap_or_default(), body, clock))
+ }
+
+ pub(super) fn post_computer(&mut self, id: u32, clock: u32) -> Result<(&str, &str), String> {
+ let strings = self
+ .sender_strings
+ .as_ref()
+ .ok_or("missing iron3d.dll strings")?;
+ let sender = strings
+ .get(CENTRAL_COMPUTER)
+ .ok_or("missing central computer caption")?;
+ let body = strings
+ .get(id)
+ .ok_or_else(|| format!("missing iron3d.dll string {id:#06x}"))?;
+ Ok(self.enqueue(id, sender, body, clock))
+ }
+
+ fn enqueue(&mut self, index: u32, sender: String, body: String, clock: u32) -> (&str, &str) {
let pending = self.pending.insert(PagerMessage {
index,
- sender: sender.unwrap_or_default(),
+ sender,
body,
posted_ms: clock,
});
- Ok((&pending.sender, &pending.body))
+ (&pending.sender, &pending.body)
}
pub(super) fn toggle_current(&mut self) {
@@ -165,14 +205,12 @@ impl MissionHints {
.map_err(|error| error.to_string());
}
self.outcome = None;
- if let Some(message) = self.pending.take() {
+ if let (Some(message), Some(pager)) = (self.pending.take(), &self.pager) {
self.active = None;
if pager_visible(message.posted_ms, clock) {
let index = message.index;
- let resources = self.messages.as_ref().expect("posted message resources");
- let (extent, bounds, texture) = match resources
- .pager
- .paint(&message.sender, &message.body, &resources.overflow_hint)
+ let (extent, bounds, texture) = match pager
+ .paint(&message.sender, &message.body, &self.overflow_hint)
.and_then(|(image, bounds)| {
Ok(([image.width, image.height], bounds, panel_texture(image)?))
}) {
@@ -282,26 +320,11 @@ 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");
- let overflow_hint = sender_strings
- .as_ref()
- .and_then(|strings| strings.get(0x1840))
- .map(|text| text.replace("%s", "F1"))
- .unwrap_or_default();
Ok(Some(Self {
config,
catalog,
strings,
- sender_strings,
- pager: MissionPager::load(&vfs)?,
- overflow_hint,
}))
}
}
diff --git a/apps/fparkan-game/src/mission_notices.rs b/apps/fparkan-game/src/mission_notices.rs
index b633856c..048674fb 100644
--- a/apps/fparkan-game/src/mission_notices.rs
+++ b/apps/fparkan-game/src/mission_notices.rs
@@ -2,6 +2,25 @@ use crate::StaticVulkanApp;
use fparkan_runtime::MissionNotice;
impl StaticVulkanApp {
+ #[cfg(windows)]
+ pub(super) fn present_computer_notice(&mut self, id: u32, clock_ms: u32) {
+ let posted = self
+ .overlay
+ .hints
+ .as_mut()
+ .ok_or_else(|| "pager unavailable".to_string())
+ .and_then(|hints| hints.post_computer(id, clock_ms));
+ let result = posted.and_then(|(sender, body)| {
+ if let Some(help) = &mut self.overlay.help {
+ help.post(sender, body)?;
+ }
+ Ok(())
+ });
+ if let Err(error) = result {
+ eprintln!("computer_notice_unavailable id={id:#06x} reason={error}");
+ }
+ }
+
pub(super) fn present_mission_notice(&mut self, notice: MissionNotice, clock_ms: u32) {
match notice {
MissionNotice::BuildingCaptured { .. } | MissionNotice::VehicleCaptured => {}
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs
index 0c3ad122..02263a85 100644
--- a/apps/fparkan-game/src/mission_overlay.rs
+++ b/apps/fparkan-game/src/mission_overlay.rs
@@ -57,13 +57,6 @@ impl MissionOverlay {
None
})
});
- #[cfg(windows)]
- let hints = MissionHints::load(root, mission, preview)
- .map(Some)
- .unwrap_or_else(|error| {
- eprintln!("sim_coverage mission_text_unavailable=1 reason={error}");
- None
- });
let satellite_map =
SatelliteMap::load(root, mission, engine, preview).unwrap_or_else(|error| {
eprintln!("satellite_map_unavailable mission={mission} reason={error}");
@@ -78,20 +71,27 @@ impl MissionOverlay {
None
})
});
- #[cfg(windows)]
- let help = cockpit.and_then(|_| {
- MissionHelp::load(root, mission, preview)
+ let factory_projects = cockpit.and_then(|_| {
+ FactoryProjectPanel::load(root, preview, engine)
.map(Some)
.unwrap_or_else(|error| {
- eprintln!("mission_help_unavailable reason={error}");
+ eprintln!("factory_project_panel_unavailable reason={error}");
None
})
});
- let factory_projects = cockpit.and_then(|_| {
- FactoryProjectPanel::load(root, preview, engine)
+ #[cfg(windows)]
+ let hints = MissionHints::load(root, mission, preview)
+ .map(Some)
+ .unwrap_or_else(|error| {
+ eprintln!("sim_coverage mission_text_unavailable=1 reason={error}");
+ None
+ });
+ #[cfg(windows)]
+ let help = cockpit.and_then(|_| {
+ MissionHelp::load(root, mission, preview)
.map(Some)
.unwrap_or_else(|error| {
- eprintln!("factory_project_panel_unavailable reason={error}");
+ eprintln!("mission_help_unavailable reason={error}");
None
})
});