diff options
Diffstat (limited to 'apps/fparkan-game/src/satellite_map.rs')
| -rw-r--r-- | apps/fparkan-game/src/satellite_map.rs | 44 |
1 files changed, 41 insertions, 3 deletions
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(), ) }, ); |
