diff options
| -rw-r--r-- | apps/fparkan-game/src/factory_menu.rs | 36 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_hints.rs | 75 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_notices.rs | 19 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 28 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/robot_designer.rs | 47 | ||||
| -rw-r--r-- | docs/tomes/06-behavior.md | 7 |
7 files changed, 153 insertions, 61 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 }) }); diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 3a0d7c79..cf9c438f 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -211,7 +211,7 @@ pub use projectile_parts::{depleted_chassis_nodes, depleted_warbot_nodes}; pub use repair_system::toggle_self_repair; pub use research::{at_research_laboratory, order_lab_research}; pub use robot_designer::{ - factory_design_bytes, factory_design_parts, load_gameplay_mission, + check_factory_design, factory_design_bytes, factory_design_parts, load_gameplay_mission, load_gameplay_mission_with_build_parts, restore_factory_design, FactoryPartChange, }; pub use unit_combat::{ diff --git a/crates/fparkan-runtime/src/robot_designer.rs b/crates/fparkan-runtime/src/robot_designer.rs index 741f2132..289881f0 100644 --- a/crates/fparkan-runtime/src/robot_designer.rs +++ b/crates/fparkan-runtime/src/robot_designer.rs @@ -40,6 +40,25 @@ pub fn factory_design_parts( Ok(parts) } +/// Checks the edited project against the current clan's research before transfer. +pub fn check_factory_design( + engine: &Engine, + cockpit: super::StartingCockpit, + scheme: usize, + changes: &[FactoryPartChange], +) -> Result<(), EngineError> { + let mission = engine + .loaded + .as_ref() + .ok_or_else(|| invalid("no mission"))?; + let owner = super::production::player_owner(&engine.world, cockpit)?; + let base = super::factory_project_components(engine, scheme) + .ok_or_else(|| invalid("project has no Unit DAT"))?; + let records = factory_design_parts(base, changes)?; + super::production::clan_scheme_cost(&engine.services.vfs, mission, owner, &records)?; + Ok(()) +} + /// Writes a modified prepared project in the original Unit DAT layout. pub fn factory_design_bytes( engine: &Engine, @@ -593,8 +612,8 @@ mod tests { #[ignore = "requires licensed corpus"] fn licensed_constructor_edits_only_the_selected_guns_equipment() { use super::{ - factory_design_bytes, factory_design_parts, key, restore_factory_design, - FactoryPartChange, + check_factory_design, factory_design_bytes, factory_design_parts, key, + restore_factory_design, FactoryPartChange, }; use crate::{ capture_neutral_building, create, factory_part_variants, factory_project_components, @@ -651,22 +670,22 @@ mod tests { .iter() .position(|part| key(&part.resource_raw) == b"i_arm_b_df") .unwrap(); - assert!(order_factory_design( - &mut engine, - cockpit, - None, - scheme, - &[FactoryPartChange { - component: armor, - resource: "i_arm_b_03".into() - }], - 1, - ) - .is_err()); + let unavailable = [FactoryPartChange { + component: armor, + resource: "i_arm_b_03".into(), + }]; + assert!(check_factory_design(&engine, cockpit, scheme, &unavailable) + .unwrap_err() + .to_string() + .contains("i_arm_b_03")); + assert!( + order_factory_design(&mut engine, cockpit, None, scheme, &unavailable, 1,).is_err() + ); let changes = [FactoryPartChange { component: mounts[0], resource: "i_c06_b_01".into(), }]; + check_factory_design(&engine, cockpit, scheme, &changes).unwrap(); let bytes = factory_design_bytes(&engine, scheme, &changes).unwrap(); let decoded = super::decode_unit_dat(&bytes).unwrap(); assert_eq!(&decoded.header_opaque[..4], &[0xf1, 0xf0, 0, 0]); diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md index bf5e54ff..3f238828 100644 --- a/docs/tomes/06-behavior.md +++ b/docs/tomes/06-behavior.md @@ -3795,6 +3795,13 @@ RVA `0x555b0` и `0x56f50`). FParkan сохраняет выбранные заÐ использовать снова. Пока редактор меняет внутреннее оборудование в существующих креплениях. +Проверка запускается по команде «Передать модель на завод». Если клану +недоступна хотя бы одна деталь, проект остаётся открыт. Оригинальная +строка `0x83f` появляется в пейджере от центрального компьютера +(`iron3d.dll`, RVA `0x50af0`, `0x548d0` и `0x7ef80`). Пейджер рисуется +поверх конструктора и сохраняет запись в журнале F1. Для заводского +заказа используется та же проверка компонентов по таблице исследований. + Две кнопки внизу конструктора сохраняют и открывают проекты. Поле имени принимает до 16 символов. По Enter проект записывается как `UNITS/имя.dat` относительно корня игры. Каждый файл содержит сигнатуру `0xF0F1`, класс |
