diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 10:59:08 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 10:59:08 +0300 |
| commit | 61208d874cb3d9bf93e9f7c60aceebc287454b62 (patch) | |
| tree | e23585ccd89bfd73b36174742acc1777f569afa2 | |
| parent | 20161fbf4fab9080a2d0d6ceedbf1344435cfda0 (diff) | |
| download | fparkan-61208d874cb3d9bf93e9f7c60aceebc287454b62.tar.xz fparkan-61208d874cb3d9bf93e9f7c60aceebc287454b62.zip | |
feat(ui): give warbots standing and route orders
Bind the first two commands to the live selection and shared route controller. Build the order panel from the installed compound controls and game font. In stock Two Fortresses, checked Stand, route drafting on the satellite map and terrain, and movement after confirmation with Vulkan validation.
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 9 | ||||
| -rw-r--r-- | apps/fparkan-game/src/satellite_map.rs | 44 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategic_roster_hud.rs | 28 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategic_view.rs | 187 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategic_roster.rs | 11 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategic_roster/orders.rs | 144 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/satellite_contacts.rs | 3 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_orders.rs | 44 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_roster.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol.rs | 5 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol/orders.rs | 65 | ||||
| -rw-r--r-- | docs/appendices/knowledge-boundaries.md | 8 | ||||
| -rw-r--r-- | docs/appendices/ui-shell.md | 17 |
14 files changed, 511 insertions, 56 deletions
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index eab32d2c..8825094b 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -260,7 +260,11 @@ impl StaticVulkanApp { .and_then(|(handle, engine)| { fparkan_runtime::warbot_stats::warbot_stats(engine, handle) }); - roster.draw(renderer, warbot_rows, selected_warbot, card)?; + let orders = self + .command_view + .as_ref() + .and_then(|view| view.order_panel(&warbot_rows)); + roster.draw(renderer, warbot_rows, selected_warbot, card, orders)?; } if let Some(map) = &mut self.overlay.satellite_map { let demo_target = self @@ -292,6 +296,9 @@ impl StaticVulkanApp { player, demo_target.is_some(), self.command_view.is_some(), + self.command_view + .as_ref() + .and_then(|view| view.route_draft()), )?; } 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 032ce555..5eb8ec21 100644 --- a/apps/fparkan-game/src/satellite_map.rs +++ b/apps/fparkan-game/src/satellite_map.rs @@ -16,7 +16,8 @@ const MAP_TINT: [f32; 3] = [55.0 / 255.0, 1.0, 55.0 / 255.0]; const MAP_ALPHA: f32 = 128.0 / 255.0; const MAP_SIZE: usize = 256; // iron3d+0x733e0 gives the mode-2 map its own frame, below the command readouts. -const COMMAND_FRAME_SHIFT: f32 = 63.0 * (2.0 / 480.0); +const COMMAND_TOP: u32 = 63; +const COMMAND_FRAME_SHIFT: f32 = COMMAND_TOP as f32 * (2.0 / 480.0); pub(super) struct SatelliteMap { frame: EnvironmentGpuRange, @@ -79,6 +80,29 @@ impl SatelliteMap { self.visible = !self.visible; } + pub(super) fn show(&mut self) { + self.visible = true; + } + + pub(super) fn hide(&mut self) -> bool { + std::mem::replace(&mut self.visible, false) + } + + pub(super) fn command_destination(&self, point: [f32; 2]) -> Option<[f32; 2]> { + let extent = self.extent.filter(|_| self.visible)?; + let x = point[0] - (MAP_RECT[0] + MAP_INSET) as f32; + let y = point[1] - (MAP_RECT[1] + MAP_INSET + COMMAND_TOP) as f32; + let size = MAP_SIZE as f32; + ((0.0..size).contains(&x) && (0.0..size).contains(&y)) + .then_some([x * extent / size, (size - y) * extent / size]) + } + + pub(super) fn covers_command_point(&self, [x, y]: [f32; 2]) -> bool { + let [left, top, right, bottom] = MAP_RECT.map(|value| value as f32); + let y = y - COMMAND_TOP as f32; + self.visible && (left..right).contains(&x) && (top..bottom).contains(&y) + } + pub(super) fn draw( &mut self, renderer: &mut VulkanSmokeRenderer, @@ -86,6 +110,7 @@ impl SatelliteMap { player: Option<(&Engine, StartingCockpit, Option<ObjectHandle>)>, automatic: bool, command_layout: bool, + draft: Option<&[[f32; 2]]>, ) -> Result<(), String> { let visible = self.visible || automatic; let count = if visible { 6 } else { 0 }; @@ -116,7 +141,7 @@ impl SatelliteMap { } } } - self.update_contacts(renderer, player)?; + self.update_contacts(renderer, player, draft)?; Ok(()) } @@ -124,13 +149,26 @@ impl SatelliteMap { &mut self, renderer: &mut VulkanSmokeRenderer, player: Option<(&Engine, StartingCockpit, Option<ObjectHandle>)>, + draft: Option<&[[f32; 2]]>, ) -> Result<(), String> { let (buildings, units) = player.zip(self.extent).map_or_else( || (Vec::new(), Vec::new()), |((engine, cockpit, selected), extent)| { ( satellite_contacts::visible_buildings(engine, cockpit, extent).collect(), - satellite_contacts::visible_units(engine, cockpit, extent, selected).collect(), + satellite_contacts::visible_units(engine, cockpit, extent, selected) + .map(|mut unit| { + if let Some(points) = draft + .filter(|_| unit.heading.is_some_and(|heading| heading.selected)) + { + unit.route = points + .iter() + .filter_map(|&point| satellite_contacts::project(point, extent)) + .collect(); + } + unit + }) + .collect(), ) }, ); diff --git a/apps/fparkan-game/src/strategic_roster_hud.rs b/apps/fparkan-game/src/strategic_roster_hud.rs index fb64e64f..4d6f82b7 100644 --- a/apps/fparkan-game/src/strategic_roster_hud.rs +++ b/apps/fparkan-game/src/strategic_roster_hud.rs @@ -2,7 +2,7 @@ use super::{ mission_overlay::{add_overlay_sprite, overlay_texture}, DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, }; -use fparkan_assets::strategic_roster::{RosterImages, Row, EXTENT, ORIGIN}; +use fparkan_assets::strategic_roster::{RosterImages, RosterOrder, Row, EXTENT, ORIGIN}; use fparkan_assets::warbot_card::{CardLabels, RatingScale}; use fparkan_platform_winit::text::StringResources; use fparkan_runtime::strategic_roster::WarbotRow; @@ -19,6 +19,8 @@ pub(super) struct StrategicRosterHud { card: Option<WarbotStats>, rows: Vec<WarbotRow>, selected: Option<ObjectHandle>, + order_labels: [String; 3], + orders: Option<Option<RosterOrder>>, } impl StrategicRosterHud { @@ -50,11 +52,13 @@ impl StrategicRosterHud { let [width, height] = EXTENT.map(|value| value as f32); let range = add_overlay_sprite( preview, - images.paint(&[], &[])?, + images.paint(&[], &[], None)?, [left, top, left + width, top + height], [1.0; 3], 1.0, )?; + let [orders, stand, follow] = [0x13dc, 0x1388, 0x1389].map(localized); + let order_labels = [orders?, stand?, follow?]; Ok(Self { range, images, @@ -64,6 +68,8 @@ impl StrategicRosterHud { card: None, rows: Vec::new(), selected: None, + order_labels, + orders: None, }) } @@ -77,11 +83,16 @@ impl StrategicRosterHud { rows: Vec<WarbotRow>, selected: Option<ObjectHandle>, card: Option<WarbotStats>, + orders: Option<Option<RosterOrder>>, ) -> Result<(), String> { renderer .set_draw_range_index_count(self.range_index(), if rows.is_empty() { 0 } else { 6 }) .map_err(|error| error.to_string())?; - if rows.is_empty() || (rows == self.rows && selected == self.selected && card == self.card) + if rows.is_empty() + || (rows == self.rows + && selected == self.selected + && card == self.card + && orders == self.orders) { return Ok(()); } @@ -121,12 +132,21 @@ impl StrategicRosterHud { .update_material_texture( self.range.material_index, 0, - &overlay_texture(self.images.paint(&visible, &lines)?), + &overlay_texture( + self.images.paint( + &visible, + &lines, + orders.map(|hovered| { + (self.order_labels.each_ref().map(String::as_str), hovered) + }), + )?, + ), ) .map_err(|error| error.to_string())?; self.rows = rows; self.selected = selected; self.card = card; + self.orders = orders; Ok(()) } } diff --git a/apps/fparkan-game/src/strategic_view.rs b/apps/fparkan-game/src/strategic_view.rs index 6ceaf741..762e9fbd 100644 --- a/apps/fparkan-game/src/strategic_view.rs +++ b/apps/fparkan-game/src/strategic_view.rs @@ -1,10 +1,15 @@ -use super::{player_movement_key, LegacyD3d7Projection, PreviewCameraFrame, StaticVulkanApp}; -use fparkan_assets::strategic_roster::{hit_test, ListHit}; +use super::{ + player_movement_key, screen_ray_from_pixels, LegacyD3d7Projection, PreviewCameraFrame, + StaticVulkanApp, +}; +use fparkan_assets::strategic_roster::{hit_test, order_at, ListHit, RosterOrder}; use fparkan_assets::strategy_toolbar::{command_button_at, ToolbarAction}; +use fparkan_runtime::strategic_orders; use fparkan_runtime::strategic_roster::{warbot_rows, WarbotRow}; use fparkan_runtime::strategic_view::{ command_post, CommandCamera, CommandCameraInput, COMMAND_FOV, }; +use fparkan_terrain::{FullSurfaceMask, SurfaceQuery, TerrainWorld}; use fparkan_world::ObjectHandle; use winit::{ event::{ElementState, KeyEvent, MouseButton, WindowEvent}, @@ -16,6 +21,7 @@ pub(super) struct ActiveCommandView { pointer: Option<[f32; 2]>, warbots_open: bool, pub(super) selected_warbot: Option<ObjectHandle>, + route_draft: Option<Vec<[f32; 2]>>, } impl ActiveCommandView { @@ -25,9 +31,21 @@ impl ActiveCommandView { .any(|row| Some(row.handle) == self.selected_warbot) { self.selected_warbot = rows.iter().find(|row| row.selectable).map(|row| row.handle); + self.route_draft = None; } self.warbots_open = !rows.is_empty(); } + + pub(super) fn route_draft(&self) -> Option<&[[f32; 2]]> { + self.route_draft.as_deref() + } + + #[cfg(windows)] + pub(super) fn order_panel(&self, rows: &[WarbotRow]) -> Option<Option<RosterOrder>> { + rows.iter() + .any(|row| Some(row.handle) == self.selected_warbot && row.selectable) + .then(|| self.pointer.and_then(|xy| order_at(xy, rows.len()))) + } } impl StaticVulkanApp { @@ -49,6 +67,7 @@ impl StaticVulkanApp { pointer: None, warbots_open: false, selected_warbot: None, + route_draft: None, }); self.camera_mode = "strategic"; self.player_mouse = [0.0; 2]; @@ -150,7 +169,22 @@ impl StaticVulkanApp { } if pressed { match event.physical_key { - PhysicalKey::Code(KeyCode::Escape) => self.close_strategy(), + PhysicalKey::Code(KeyCode::Escape) => { + if !self + .overlay + .satellite_map + .as_mut() + .is_some_and(|map| map.hide()) + { + if let Some(view) = + self.command_view.as_mut().filter(|view| view.warbots_open) + { + view.warbots_open = false; + } else { + self.close_strategy(); + } + } + } PhysicalKey::Code(KeyCode::KeyM) => { if let Some(map) = &mut self.overlay.satellite_map { map.toggle(); @@ -181,56 +215,110 @@ impl StaticVulkanApp { return false; } WindowEvent::MouseInput { state, button, .. } => { - if *state == ElementState::Pressed - && *button == MouseButton::Left - && !self.mission_paused - { - match view.pointer.and_then(command_button_at) { - Some(ToolbarAction::Hero) => { - self.close_strategy(); - self.player_disembark_pressed = self.boarded_hero_index.is_some(); + if *state == ElementState::Pressed && !self.mission_paused { + self.click_strategy(*button); + } + } + _ => return false, + } + true + } + + fn click_strategy(&mut self, button: MouseButton) { + let Some(view) = self.command_view.as_mut() else { + return; + }; + let Some(xy) = view.pointer else { + return; + }; + let map = self.overlay.satellite_map.as_mut(); + let Some((engine, cockpit)) = self.mission_engine.as_mut().zip(self.cockpit) else { + return; + }; + if button == MouseButton::Right { + if let Some((actor, draft)) = view.selected_warbot.zip( + view.route_draft + .as_ref() + .filter(|points| !points.is_empty()), + ) { + strategic_orders::follow_route(engine, cockpit, actor, draft); + view.route_draft = None; + } + return; + } + if button != MouseButton::Left { + return; + } + match command_button_at(xy) { + Some(ToolbarAction::Hero) => { + self.close_strategy(); + self.player_disembark_pressed = self.boarded_hero_index.is_some(); + } + Some(ToolbarAction::Map) => { + if let Some(map) = map { + map.toggle(); + } + } + Some(ToolbarAction::Warbots) if view.warbots_open => view.warbots_open = false, + Some(ToolbarAction::Warbots) => view.refresh_warbots(&warbot_rows(engine, cockpit)), + None => { + if view.warbots_open { + let rows = warbot_rows(engine, cockpit); + match hit_test(xy, rows.len()) { + Some(ListHit::Close) => { + view.warbots_open = false; + return; } - Some(ToolbarAction::Map) => { - if let Some(map) = &mut self.overlay.satellite_map { - map.toggle(); + Some(ListHit::Row(index)) => { + if Some(rows[index].handle) != view.selected_warbot { + view.route_draft = None; + view.selected_warbot = Some(rows[index].handle); } + return; } - Some(ToolbarAction::Warbots) if view.warbots_open => { - view.warbots_open = false; - } - Some(ToolbarAction::Warbots) => { - let rows = self - .mission_engine - .as_ref() - .zip(self.cockpit) - .map_or_else(Vec::new, |(engine, cockpit)| { - warbot_rows(engine, cockpit) - }); - view.refresh_warbots(&rows); + None => {} + } + let actor = view.selected_warbot.filter(|actor| { + rows.iter() + .any(|row| row.handle == *actor && row.selectable) + }); + match actor.zip(order_at(xy, rows.len())) { + Some((actor, RosterOrder::Stand)) => { + strategic_orders::stand(engine, cockpit, actor); + view.route_draft = None; + return; } - None if view.warbots_open => { - let rows = self - .mission_engine - .as_ref() - .zip(self.cockpit) - .map_or_else(Vec::new, |(engine, cockpit)| { - warbot_rows(engine, cockpit) - }); - match view.pointer.and_then(|xy| hit_test(xy, rows.len())) { - Some(ListHit::Close) => view.warbots_open = false, - Some(ListHit::Row(index)) => { - view.selected_warbot = Some(rows[index].handle) - } - None => {} + Some((_, RosterOrder::FollowRoute)) => { + if let Some(map) = map { + map.show(); } + view.route_draft = Some(Vec::new()); + return; } None => {} } } + let Some(draft) = &mut view.route_draft else { + return; + }; + let point = if let Some(map) = map.filter(|map| map.covers_command_point(xy)) { + map.command_destination(xy) + } else { + self.window.as_ref().and_then(|window| { + let size = window.inner_size(); + terrain_destination( + &self.terrain, + &self.view_camera, + [size.width as f32, size.height as f32], + xy, + ) + }) + }; + if let Some(point) = point { + draft.push(point); + } } - _ => return false, } - true } #[cfg(windows)] @@ -247,3 +335,18 @@ impl StaticVulkanApp { rows } } + +fn terrain_destination( + terrain: &TerrainWorld, + camera: &PreviewCameraFrame, + viewport: [f32; 2], + [x, y]: [f32; 2], +) -> Option<[f32; 2]> { + let pixels = [x * viewport[0] / 640.0, y * viewport[1] / 480.0]; + let ray = screen_ray_from_pixels(camera, pixels, viewport)?; + let hit = terrain + .raycast(camera.position, ray, FullSurfaceMask(0)) + .ok()??; + let [x, y, _] = hit.position; + (hit.distance <= camera.far_plane).then_some([x, y]) +} diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs index 0faeb7e4..440ead26 100644 --- a/crates/fparkan-assets/src/strategic_roster.rs +++ b/crates/fparkan-assets/src/strategic_roster.rs @@ -9,6 +9,10 @@ use crate::{ }; use fparkan_vfs::Vfs; +mod orders; +use orders::OrderImages; +pub use orders::{order_at, RosterOrder}; + /// List origin and size in the original logical screen coordinates. pub const ORIGIN: [u32; 2] = [51, 0]; pub const EXTENT: [u32; 2] = [319, 480]; @@ -63,6 +67,7 @@ pub struct RosterImages { end: RgbaImage, class_icon: RgbaImage, chassis_icons: [RgbaImage; 4], + orders: OrderImages, } impl RosterImages { @@ -149,6 +154,7 @@ impl RosterImages { end, class_icon: icon(49, 110)?, chassis_icons: [icon(97, 94)?, icon(49, 94)?, icon(65, 94)?, icon(81, 94)?], + orders: OrderImages::load(vfs)?, }) } @@ -157,6 +163,7 @@ impl RosterImages { &self, rows: &[Row<'_>], card: &[Option<CardLine<'_>>], + orders: Option<([&str; 3], Option<RosterOrder>)>, ) -> Result<RgbaImage, String> { let mut panel = self.background.clone(); if let Some(row) = rows.iter().find(|row| row.selected) { @@ -210,6 +217,10 @@ impl RosterImages { tint, ); } + if let Some((labels, hovered)) = orders { + self.orders + .paint(self, &mut panel, rows.len(), labels, hovered)?; + } Ok(panel) } diff --git a/crates/fparkan-assets/src/strategic_roster/orders.rs b/crates/fparkan-assets/src/strategic_roster/orders.rs new file mode 100644 index 00000000..743b4801 --- /dev/null +++ b/crates/fparkan-assets/src/strategic_roster/orders.rs @@ -0,0 +1,144 @@ +use super::{stamp, RosterImages, ORIGIN, ROW_HEIGHT, ROW_PITCH, ROW_TOP}; +use crate::{ui_sprite::load_ui_sprites, RgbaImage}; +use fparkan_vfs::Vfs; + +const LEFT: u32 = 100; +const RIGHT: u32 = 367; + +/// Commands supported by the strategic warbot panel. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum RosterOrder { + /// Stop in place. + Stand, + /// Draw a route and send it to the unit. + FollowRoute, +} + +const ORDERS: [RosterOrder; 2] = [RosterOrder::Stand, RosterOrder::FollowRoute]; + +/// Returns the visible command at the pointer, excluding borders and row gaps. +pub fn order_at([x, y]: [f32; 2], count: usize) -> Option<RosterOrder> { + let [x, y] = [x.round_ties_even(), y.round_ties_even()]; + if !(LEFT as f32..RIGHT as f32).contains(&x) || !(0.0..480.0).contains(&y) { + return None; + } + let y = (y as u32).checked_sub(panel_top(count) + ROW_PITCH)?; + ORDERS + .get((y / ROW_PITCH) as usize) + .copied() + .filter(|_| y % ROW_PITCH < ROW_HEIGHT) +} + +fn panel_top(count: usize) -> u32 { + ROW_TOP + count.min(19) as u32 * ROW_PITCH +} + +pub(super) struct OrderImages { + stub: RgbaImage, + disabled: RgbaImage, + arrows: [RgbaImage; 2], +} + +impl OrderImages { + pub(super) fn load(vfs: &dyn Vfs) -> Result<Self, String> { + let [stub, disabled] = load_ui_sprites( + vfs, + "ui/compaund.cfg", + ["ccres_ending_stub", "ccres_long_button_off"], + )?; + let arrows = load_ui_sprites(vfs, "ui/hq.cfg", ["scroll_up_icon", "scroll_down_icon"])?; + Ok(Self { + stub, + disabled, + arrows, + }) + } + + pub(super) fn paint( + &self, + roster: &RosterImages, + panel: &mut RgbaImage, + count: usize, + [title, stand, follow]: [&str; 3], + hovered: Option<RosterOrder>, + ) -> Result<(), String> { + let x = LEFT - ORIGIN[0]; + let y = panel_top(count); + let title = roster.font.centered_line(title, 158, ROW_HEIGHT as u16)?; + for (sprite, left, right) in [ + (&self.stub, 0, 9), + (&roster.icon_frame, 8, 167), + (&title, 8, 166), + ] { + stamp( + panel, + sprite, + [x + left, y, x + right, y + ROW_HEIGHT], + [255; 3], + ); + } + for (index, icon) in self.arrows.iter().enumerate() { + let left = 166 + 50 * index as u32; + stamp( + panel, + &self.disabled, + [x + left, y, x + left + 51, y + ROW_HEIGHT], + [255; 3], + ); + let icon_left = x + left + 50_u32.saturating_sub(icon.width) / 2; + let icon_top = y + ROW_HEIGHT.saturating_sub(icon.height) / 2; + stamp( + panel, + icon, + [ + icon_left, + icon_top, + icon_left + icon.width, + icon_top + icon.height, + ], + [128; 3], + ); + } + for (index, (order, label)) in ORDERS.into_iter().zip([stand, follow]).enumerate() { + let y = y + (index as u32 + 1) * ROW_PITCH; + let bottom = y + ROW_HEIGHT; + let label = roster.font.centered_line(label, 247, ROW_HEIGHT as u16)?; + for (sprite, left, right) in [ + (&self.stub, 0, 9), + (&roster.emitter[1], 8, 15), + (&roster.ray, 14, 262), + (&roster.end, 261, 267), + ] { + stamp(panel, sprite, [x + left, y, x + right, bottom], [255; 3]); + } + if hovered == Some(order) { + stamp( + panel, + &RgbaImage { + width: 1, + height: 1, + rgba8: vec![0, 128, 0, 128], + }, + [x + 16, y + 3, x + 260, bottom - 3], + [255; 3], + ); + } + stamp(panel, &label, [x + 14, y, x + 261, bottom], [255; 3]); + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn hit_test_follows_the_last_warbot_row() { + assert_eq!(order_at([250.0, 197.0], 3), None); + assert_eq!(order_at([250.0, 198.0], 3), Some(RosterOrder::Stand)); + assert_eq!(order_at([250.0, 217.0], 3), None); + assert_eq!(order_at([250.0, 218.0], 3), Some(RosterOrder::FollowRoute)); + assert_eq!(order_at([250.0, 218.0], 4), Some(RosterOrder::Stand)); + } +} diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 0cc96e6f..1db75dbc 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_orders; pub mod strategic_roster; pub mod strategic_view; pub mod warbot_stats; diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs index e984baf3..17030fc1 100644 --- a/crates/fparkan-runtime/src/satellite_contacts.rs +++ b/crates/fparkan-runtime/src/satellite_contacts.rs @@ -229,7 +229,8 @@ fn icon_x(class: u32) -> Option<u32> { }) } -fn project([x, y]: [f32; 2], extent: f32) -> Option<[i32; 2]> { +/// Projects world XY onto the original 256-pixel map, including the inverted Y axis. +pub fn project([x, y]: [f32; 2], extent: f32) -> Option<[i32; 2]> { if !x.is_finite() || !y.is_finite() || !extent.is_finite() || extent <= 0.0 { return None; } diff --git a/crates/fparkan-runtime/src/strategic_orders.rs b/crates/fparkan-runtime/src/strategic_orders.rs new file mode 100644 index 00000000..9e364786 --- /dev/null +++ b/crates/fparkan-runtime/src/strategic_orders.rs @@ -0,0 +1,44 @@ +//! Orders issued by the player from the strategic warbot panel. + +use crate::{strategic_roster::warbot_rows, unit_patrol::UnitPatrol, Engine, StartingCockpit}; +use fparkan_world::ObjectHandle; + +/// Stops the selected warbot and clears its outstanding movement orders. +pub fn stand(engine: &mut Engine, cockpit: StartingCockpit, actor: ObjectHandle) -> bool { + issue(engine, cockpit, actor, None) +} + +/// Replaces the selected warbot's order with the confirmed sequence of world points. +pub fn follow_route( + engine: &mut Engine, + cockpit: StartingCockpit, + actor: ObjectHandle, + points: &[[f32; 2]], +) -> bool { + if points.is_empty() || !points.iter().flatten().all(|value| value.is_finite()) { + return false; + } + issue(engine, cockpit, actor, Some(points.to_vec())) +} + +fn issue( + engine: &mut Engine, + cockpit: StartingCockpit, + actor: ObjectHandle, + route: Option<Vec<[f32; 2]>>, +) -> bool { + if !warbot_rows(engine, cockpit) + .iter() + .any(|row| row.handle == actor && row.selectable) + { + return false; + } + let Some(mission) = engine.loaded.as_mut() else { + return false; + }; + mission + .unit_patrol + .get_or_insert_with(UnitPatrol::scripted) + .command_order(&engine.world, actor, route); + true +} diff --git a/crates/fparkan-runtime/src/strategic_roster.rs b/crates/fparkan-runtime/src/strategic_roster.rs index df615e0a..07735aff 100644 --- a/crates/fparkan-runtime/src/strategic_roster.rs +++ b/crates/fparkan-runtime/src/strategic_roster.rs @@ -146,6 +146,7 @@ fn order_label(order: u32) -> u32 { 0x11 => 0x1833, 0x13 => 0x1826, 0x14 => 0x1829, + 0x15 => 0x1827, _ => 0x1835, } } diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index 44e83986..4f708af3 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -32,6 +32,7 @@ pub(super) struct UnitPatrol { animal_migration: Vec<AnimalMigration>, migration_rng: u32, shut_down: HashSet<ObjectHandle>, + standing: HashSet<ObjectHandle>, script_orders: Vec<(ObjectHandle, VecDeque<orders::UnitOrder>)>, script_order_counts: BTreeMap<(u32, u32), u64>, clock_ms: u32, @@ -168,6 +169,7 @@ impl UnitPatrol { animal_migration: Vec::new(), migration_rng: 1, shut_down: HashSet::new(), + standing: HashSet::new(), script_orders: Vec::new(), script_order_counts: BTreeMap::new(), clock_ms: 0, @@ -189,6 +191,7 @@ impl UnitPatrol { ) -> bool { self.script_orders.retain(|(unit, _)| *unit != handle); self.shut_down.remove(&handle); + self.standing.remove(&handle); self.units .retain(|unit| transform_state(world, unit.handle).is_ok()); if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) { @@ -365,6 +368,7 @@ impl UnitPatrol { pub(super) fn shut_down(&mut self, handle: ObjectHandle) -> bool { self.script_orders.retain(|(unit, _)| *unit != handle); + self.standing.remove(&handle); // shortcut: stop autonomous movement and fire until the native shutdown task is modeled. self.units.retain(|unit| unit.handle != handle); self.shut_down.insert(handle) @@ -498,6 +502,7 @@ impl UnitPatrol { animal_migration: Vec::new(), migration_rng: 1, shut_down: HashSet::new(), + standing: HashSet::new(), script_orders: Vec::new(), script_order_counts: BTreeMap::new(), clock_ms: 0, diff --git a/crates/fparkan-runtime/src/unit_patrol/orders.rs b/crates/fparkan-runtime/src/unit_patrol/orders.rs index 8e9260a1..fec2731c 100644 --- a/crates/fparkan-runtime/src/unit_patrol/orders.rs +++ b/crates/fparkan-runtime/src/unit_patrol/orders.rs @@ -9,6 +9,8 @@ pub(super) enum UnitOrder { Move([f32; 2]), Attack(ObjectHandle, usize), Patrol([f32; 2], f32), + Stand, + Route(Vec<[f32; 2]>), Shutdown, Resume(Box<PatrollingUnit>), } @@ -16,10 +18,11 @@ pub(super) enum UnitOrder { impl UnitOrder { fn opcode(&self) -> u32 { match self { - Self::Move(_) => 2, + Self::Move(_) | Self::Route(_) => 2, Self::Attack(..) => 3, Self::Patrol(..) => 4, Self::Shutdown => 0x13, + Self::Stand => 0x15, Self::Resume(_) => unreachable!("a suspended order has already started"), } } @@ -50,6 +53,21 @@ pub(crate) fn supports_order(order: &Handler15Invocation) -> bool { } impl UnitPatrol { + pub(crate) fn command_order( + &mut self, + world: &World, + actor: ObjectHandle, + route: Option<Vec<[f32; 2]>>, + ) { + let order = route.map_or(UnitOrder::Stand, UnitOrder::Route); + self.script_orders.retain(|(unit, _)| *unit != actor); + if self.is_leaving_factory(actor) { + self.script_orders.push((actor, VecDeque::from([order]))); + } else { + self.start_script_order(world, actor, order); + } + } + pub(crate) fn active_order_code(&self, actor: ObjectHandle) -> u32 { if self.is_leaving_factory(actor) { return 0x14; @@ -57,6 +75,9 @@ impl UnitPatrol { if self.is_shut_down(actor) { return UnitOrder::Shutdown.opcode(); } + if self.standing.contains(&actor) { + return UnitOrder::Stand.opcode(); + } let Some(unit) = self.units.iter().find(|unit| unit.handle == actor) else { return 0; }; @@ -96,7 +117,8 @@ impl UnitPatrol { match order { UnitOrder::Move(point) | UnitOrder::Patrol(point, _) => points.push(*point), UnitOrder::Resume(unit) => unit.append_point_orders(&mut points), - UnitOrder::Attack(..) | UnitOrder::Shutdown => {} + UnitOrder::Route(route) => points.extend(route), + UnitOrder::Attack(..) | UnitOrder::Shutdown | UnitOrder::Stand => {} } } } @@ -161,6 +183,8 @@ impl UnitPatrol { queue.push_front(UnitOrder::Resume(Box::new(self.units.remove(index)))); } else if self.is_shut_down(actor) { queue.push_front(UnitOrder::Shutdown); + } else if self.standing.contains(&actor) { + queue.push_front(UnitOrder::Stand); } self.start_script_order(world, actor, order); } @@ -268,6 +292,18 @@ impl UnitPatrol { return true; } match &order { + UnitOrder::Stand => { + self.units.retain(|unit| unit.handle != actor); + self.shut_down.remove(&actor); + self.standing.insert(actor); + return true; + } + UnitOrder::Route(route) => { + for (index, &point) in route.iter().enumerate() { + self.move_to(world, actor, point, index != 0); + } + return true; + } UnitOrder::Move(point) => { self.move_to(world, actor, *point, false); eprintln!( @@ -309,6 +345,8 @@ impl UnitPatrol { world: &World, controls: &[MissionControlDeviceTableState], ) { + self.standing + .retain(|&actor| transform_state(world, actor).is_ok()); self.units.retain(|unit| { let Some((target, _)) = unit.attack_target else { return true; @@ -415,6 +453,29 @@ mod tests { } #[test] + fn command_panel_stops_then_replaces_the_route_with_confirmed_points() { + let mut world = fparkan_world::new(Default::default()); + let actor = object(&mut world); + let other = object(&mut world); + let mut patrol = UnitPatrol::scripted(); + patrol.enqueue_script_order(&world, actor, UnitOrder::Move([10.0, 10.0]), false); + patrol.enqueue_script_order(&world, actor, UnitOrder::Shutdown, true); + patrol.move_to(&world, other, [40.0, 40.0], false); + + patrol.command_order(&world, actor, None); + patrol.advance_script_orders(&world, &[]); + assert_eq!(patrol.active_order_code(actor), 0x15); + assert!(!patrol.is_shut_down(actor)); + assert!(patrol.satellite_route(actor).is_empty()); + assert_eq!(patrol.satellite_route(other), [[40.0, 40.0]]); + + let points = vec![[20.0, 30.0], [30.0, 40.0]]; + patrol.command_order(&world, actor, Some(points.clone())); + assert_eq!(patrol.active_order_code(actor), 2); + assert_eq!(patrol.satellite_route(actor), points); + } + + #[test] fn move_attack_and_shutdown_wait_for_the_preceding_task() { let mut world = fparkan_world::new(Default::default()); let actor = object(&mut world); diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md index 5c0c81ba..6130f000 100644 --- a/docs/appendices/knowledge-boundaries.md +++ b/docs/appendices/knowledge-boundaries.md @@ -306,9 +306,11 @@ seed и общий порядок Control RNG открыты. `control_resource_ `autodemo_camera_follow_approx` и `autodemo_camera_target_approx` отмечают приближённое слежение и выбор размещённых юнитов с камерой через селектор AI. В стратегическом списке варботов доступны показатели выбранной машины и -полосы прочности. Открыты кнопки карточки, панель приказов, голос выбора, -специальные имена машин и остальные разделы. Состояние строки берётся -из действующего приказа FParkan. Стратегический указатель открыт. +полосы прочности и первые два приказа: «Стоять» и «Следовать по маршруту». +Открыты остальные приказы, кнопки карточки, голос выбора, прокрутка и +специальные имена машин. Состояние строки берётся из действующего приказа +FParkan. Стратегический указатель, нативная проверка доступности точки +маршрута и подсветка после щелчка остаются открытыми. Балансы используют текущие итоги симуляции кланов. Для повторного входа из бункера используется материал пола. Движение камеры из варбота с МФУ и проверка входа и возврата в штатной игре остаются открытыми. diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md index 480c9d65..6461c0d3 100644 --- a/docs/appendices/ui-shell.md +++ b/docs/appendices/ui-shell.md @@ -364,6 +364,23 @@ RVA `0x95b20` дописывает состояние первого прикаÐ Для `br_b_01` это 1600 + 300, для `bb_b_01` это 899 + 1. [Хеши GOG-сборок](../reference/original-binaries.md) +### Приказы варботу + +Панель начинается на X = 100 сразу под списком. `iron3d.dll` по RVA +`0x85240` прибавляет 20 на каждую строку к исходному Y = 118. Отбор +доступных команд по классу идёт по таблице с RVA `0x103f98`. Заголовок +и первые две команды используют строки `0x13dc`, `0x1388` и `0x1389`, +составные элементы и тот же игровой шрифт (RVA `0x7b630`, `0x9c7d0`). + +«Стоять» заменяет прежний приказ. Строка сразу показывает «стоит» +(состояние `0x15`, строка `0x1827`). «Следовать по маршруту» открывает +спутниковую карту. Левый щелчок добавляет точку, в том числе на местности +вне карты. Пока игрок рисует линию, статус варбота показывает его +текущее занятие. Правый щелчок передаёт накопленные точки в порядке +выбора, после чего появляется состояние «двигается». Для уже покидающего +завод варбота следующий приказ сохраняется до завершения выезда. +[Хеши GOG-сборок](../reference/original-binaries.md) + ## Оружейные строки кабины В `iron3d.dll` RVA `0x74f40` читает четыре имени орудий героя из строк |
