diff options
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 7 | ||||
| -rw-r--r-- | apps/fparkan-game/src/satellite_map.rs | 66 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/satellite_contacts.rs | 51 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/unit_patrol/orders.rs | 54 | ||||
| -rw-r--r-- | docs/appendices/ui-shell.md | 15 |
5 files changed, 158 insertions, 35 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 7f6a98f9..1eb3d895 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -10789,6 +10789,7 @@ impl StaticVulkanApp { { self.cockpit = Some(hero); self.boarded_hero_index = None; + self.boarding_target = None; self.camera_mode = "starting-cockpit"; eprintln!( "player_disembark object={} queue_time_ms={control_clock_ms}", @@ -10964,7 +10965,6 @@ impl StaticVulkanApp { .map_err(|error| error.to_string())?; capture_notice = entry.capture_notice(); if let Some(target) = entry.captured { - self.boarding_target = mission_object_handle(engine, target); eprintln!( "player_capture object={} queue_time_ms={control_clock_ms}", target.0 @@ -11674,7 +11674,10 @@ impl StaticVulkanApp { renderer, &mut self.mesh, frame.viewport, - self.mission_engine.as_ref().zip(self.cockpit), + self.mission_engine + .as_ref() + .zip(self.cockpit) + .map(|(engine, cockpit)| (engine, cockpit, self.boarding_target)), )?; } #[cfg(windows)] diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs index 37d60fa9..c74e893a 100644 --- a/apps/fparkan-game/src/satellite_map.rs +++ b/apps/fparkan-game/src/satellite_map.rs @@ -7,6 +7,7 @@ use super::{ use fparkan_assets::{satellite_map::load_satellite_map, RgbaImage}; use fparkan_runtime::{satellite_contacts, Engine, StartingCockpit}; use fparkan_vfs::DirectoryVfs; +use fparkan_world::ObjectHandle; use std::{path::Path, sync::Arc}; const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]; @@ -68,7 +69,7 @@ impl SatelliteMap { renderer: &mut VulkanSmokeRenderer, mesh: &mut VulkanStaticMesh, viewport: [f32; 2], - player: Option<(&Engine, StartingCockpit)>, + player: Option<(&Engine, StartingCockpit, Option<ObjectHandle>)>, ) -> Result<(), String> { let count = if self.visible { 6 } else { 0 }; for index in self.ranges() { @@ -124,14 +125,14 @@ impl SatelliteMap { viewport: [f32; 2], center: [f32; 2], size: f32, - player: Option<(&Engine, StartingCockpit)>, + player: Option<(&Engine, StartingCockpit, Option<ObjectHandle>)>, ) -> Result<(), String> { let (buildings, units) = player.zip(self.extent).map_or_else( || (Vec::new(), Vec::new()), - |((engine, cockpit), extent)| { + |((engine, cockpit, selected), extent)| { ( satellite_contacts::owned_buildings(engine, cockpit, extent).collect(), - satellite_contacts::owned_units(engine, cockpit, extent).collect(), + satellite_contacts::owned_units(engine, cockpit, extent, selected).collect(), ) }, ); @@ -141,7 +142,7 @@ impl SatelliteMap { paint_building(&self.icons, &mut layer, *building); } for unit in &units { - paint_unit(&mut layer, *unit); + paint_unit(&mut layer, unit); } renderer .update_material_texture(self.contact_layer.material_index, 0, &texture(layer)) @@ -172,7 +173,17 @@ fn empty_layer() -> RgbaImage { } } -fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) { +fn paint_unit(layer: &mut RgbaImage, unit: &satellite_contacts::UnitContact) { + let mut from = unit.pixel; + for &point in &unit.route { + paint_line(layer, from, point, [100, 200, 100, 255]); + for dy in -1..=1 { + for dx in -1..=1 { + paint_unit_pixel(layer, point, [dx, dy], [200, 200, 100, 255]); + } + } + from = point; + } let radius = if unit.cross { 2 } else { 1 }; for dy in -radius..=radius { for dx in -radius..=radius { @@ -201,24 +212,31 @@ fn paint_unit(layer: &mut RgbaImage, unit: satellite_contacts::UnitContact) { paint_unit_pixel(layer, unit.pixel, point, color); } } - let [end_x, end_y] = heading.tip_offset; - let [mut x, mut y] = [0, 0]; - let [dx, dy] = [end_x.abs(), -end_y.abs()]; - let mut error = dx + dy; - loop { - paint_unit_pixel(layer, unit.pixel, [x, y], color); - if [x, y] == [end_x, end_y] { - break; - } - let twice = 2 * error; - if twice >= dy { - error += dy; - x += end_x.signum(); - } - if twice <= dx { - error += dx; - y += end_y.signum(); - } + let tip = std::array::from_fn(|axis| unit.pixel[axis].saturating_add(heading.tip_offset[axis])); + paint_line(layer, unit.pixel, tip, color); +} + +fn paint_line(layer: &mut RgbaImage, from: [i32; 2], to: [i32; 2], color: [u8; 4]) { + let [dx, dy] = std::array::from_fn(|axis| i128::from(to[axis]) - i128::from(from[axis])); + let major = usize::from(dy.abs() > dx.abs()); + let minor = 1 - major; + let span = [dx, dy][major].abs(); + if span == 0 { + paint_unit_pixel(layer, from, [0, 0], color); + return; + } + // Intersect the major-axis interval with the map before rasterizing. Off-map + // orders retain the direction of the original segment without a long loop. + let start = from[major].min(to[major]).max(0); + let end = from[major].max(to[major]).min(MAP_SIZE as i32 - 1); + let rise = [dx, dy][minor]; + for coordinate in start..=end { + let step = (i128::from(coordinate) - i128::from(from[major])).abs(); + let offset = ((step * rise.abs() + span / 2) / span) * rise.signum(); + let mut point = from; + point[major] = coordinate; + point[minor] = (i128::from(from[minor]) + offset) as i32; + paint_unit_pixel(layer, point, [0, 0], color); } } diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs index a766e911..f3867ac8 100644 --- a/crates/fparkan-runtime/src/satellite_contacts.rs +++ b/crates/fparkan-runtime/src/satellite_contacts.rs @@ -15,11 +15,12 @@ pub struct BuildingContact { } /// The original mark for a moving unit within the satellite image. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct UnitContact { pub pixel: [i32; 2], pub cross: bool, pub heading: Option<UnitHeading>, + pub route: Vec<[i32; 2]>, } /// The selected vehicle or unboarded hero's outline and heading stroke. @@ -55,8 +56,14 @@ pub fn owned_units( engine: &Engine, cockpit: StartingCockpit, extent: f32, + selected: Option<ObjectHandle>, ) -> impl Iterator<Item = UnitContact> + '_ { let boarded = crate::player_vehicle(engine).map(|vehicle| vehicle.handle); + let selected = boarded.or(selected); + let patrol = engine + .loaded + .as_ref() + .and_then(|mission| mission.unit_patrol.as_ref()); owned_contacts(engine, cockpit, extent, move |draft, class| { let hero = class == crate::HERO_UNIT_CLASS; if class & crate::autodemo::MOBILE_UNIT == 0 || (hero && boarded.is_some()) { @@ -71,7 +78,7 @@ pub fn owned_units( Some((hero, flags.chassis_type == Some(1))) }) .map(move |(pixel, handle, pose, (hero, cross))| { - let selected = boarded == Some(handle); + let selected = selected == Some(handle); UnitContact { pixel, cross, @@ -80,6 +87,13 @@ pub fn owned_units( } else { None }, + route: patrol.filter(|_| selected).map_or_else(Vec::new, |patrol| { + patrol + .satellite_route(handle) + .into_iter() + .filter_map(|xy| project(xy, extent)) + .collect() + }), } }) } @@ -226,18 +240,41 @@ mod tests { let mut pose = transform_state(&engine.world, handle).unwrap(); let [x, y, _] = pose.position.map(f32::from_bits); let start = project([x, y], extent).unwrap(); - assert!(!owned_units(&engine, cockpit, extent).any(|contact| contact.pixel == start)); + assert!(!owned_units(&engine, cockpit, extent, Some(handle)) + .any(|contact| contact.pixel == start)); set_owner(&mut engine.world, handle, owner).unwrap(); - let captured = owned_units(&engine, cockpit, extent) + let destination = [x, y + 50.0]; + engine + .loaded + .as_mut() + .unwrap() + .unit_patrol + .get_or_insert_with(crate::unit_patrol::UnitPatrol::scripted) + .move_to(&engine.world, handle, destination, false); + let chosen = owned_units(&engine, cockpit, extent, Some(handle)) + .find(|contact| contact.pixel == start) + .expect("selected warbot mark"); + assert!(chosen.heading.is_some_and(|heading| heading.selected)); + assert_eq!(chosen.route, [project(destination, extent).unwrap()]); + let captured = owned_units(&engine, cockpit, extent, None) .find(|contact| contact.pixel == start) .expect("captured warbot mark"); assert_eq!(captured.heading, None); + assert!(captured.route.is_empty()); + engine + .loaded + .as_mut() + .unwrap() + .unit_patrol + .as_mut() + .unwrap() + .clear_move(handle); pose.position[0] = (x + extent / 8.0).to_bits(); set_transform(&mut engine.world, handle, pose).unwrap(); let moved = project([x + extent / 8.0, y], extent).unwrap(); assert_eq!(moved, [start[0] + 32, start[1]]); - let units: Vec<_> = owned_units(&engine, cockpit, extent).collect(); + let units: Vec<_> = owned_units(&engine, cockpit, extent, None).collect(); let moved_contact = UnitContact { pixel: moved, ..captured @@ -255,7 +292,7 @@ mod tests { let vehicle = crate::board_friendly_warbot(&mut engine, Some(handle)) .unwrap() .unwrap(); - let headings: Vec<_> = owned_units(&engine, vehicle, extent) + let headings: Vec<_> = owned_units(&engine, vehicle, extent, None) .filter(|unit| unit.heading.is_some()) .collect(); assert_eq!( @@ -266,7 +303,7 @@ mod tests { }] ); assert_eq!(crate::disembark_warbot(&mut engine).unwrap(), Some(cockpit)); - let headings: Vec<_> = owned_units(&engine, cockpit, extent) + let headings: Vec<_> = owned_units(&engine, cockpit, extent, None) .filter_map(|unit| unit.heading) .collect(); assert_eq!(headings, [unit_heading(pose, false, false).unwrap()]); diff --git a/crates/fparkan-runtime/src/unit_patrol/orders.rs b/crates/fparkan-runtime/src/unit_patrol/orders.rs index cde2bd09..560f2142 100644 --- a/crates/fparkan-runtime/src/unit_patrol/orders.rs +++ b/crates/fparkan-runtime/src/unit_patrol/orders.rs @@ -50,6 +50,32 @@ pub(crate) fn supports_order(order: &Handler15Invocation) -> bool { } impl UnitPatrol { + pub(crate) fn satellite_route(&self, actor: ObjectHandle) -> Vec<[f32; 2]> { + let active = self.units.iter().find(|unit| unit.handle == actor); + // iron3d+0x77ae0 prefers the path whenever there are unvisited points. + if let Some(unit) = active.filter(|unit| !unit.points.is_empty()) { + return unit.points.iter().copied().collect(); + } + let mut points = Vec::new(); + if let Some(unit) = active { + unit.append_point_orders(&mut points); + } + if let Some((_, queue)) = self + .script_orders + .iter() + .find(|(handle, _)| *handle == actor) + { + for order in queue { + match order { + UnitOrder::Move(point) | UnitOrder::Patrol(point, _) => points.push(*point), + UnitOrder::Resume(unit) => unit.append_point_orders(&mut points), + UnitOrder::Attack(..) | UnitOrder::Shutdown => {} + } + } + } + points + } + pub(crate) fn clear_capture_order(&mut self, unit: ObjectHandle, building: ObjectHandle) { self.units .retain(|order| order.handle != unit || order.capture_target != Some(building)); @@ -314,6 +340,16 @@ impl UnitPatrol { } } +impl PatrollingUnit { + fn append_point_orders(&self, points: &mut Vec<[f32; 2]>) { + if let Some(destinations) = &self.destinations { + points.extend(destinations); + } else if self.patrols_point(self.center) && self.raid_factory.is_none() { + points.push(self.center); + } + } +} + #[cfg(test)] mod tests { use super::*; @@ -334,6 +370,24 @@ mod tests { } #[test] + fn satellite_route_prefers_remaining_waypoints_to_coordinate_orders() { + let mut world = fparkan_world::new(Default::default()); + let actor = object(&mut world); + let enemy = object(&mut world); + let mut patrol = UnitPatrol::scripted(); + patrol.enqueue_script_order(&world, actor, UnitOrder::Move([20.0, 30.0]), false); + patrol.enqueue_script_order(&world, actor, UnitOrder::Attack(enemy, 1), true); + patrol.enqueue_script_order(&world, actor, UnitOrder::Patrol([40.0, 50.0], 60.0), true); + assert_eq!(patrol.satellite_route(actor), [[20.0, 30.0], [40.0, 50.0]]); + + patrol.units[0].points = VecDeque::from([[10.0, 18.0], [20.0, 30.0]]); + assert_eq!(patrol.satellite_route(actor), [[10.0, 18.0], [20.0, 30.0]]); + patrol.units[0].points.pop_front(); + assert_eq!(patrol.satellite_route(actor), [[20.0, 30.0]]); + assert!(patrol.satellite_route(enemy).is_empty()); + } + + #[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/ui-shell.md b/docs/appendices/ui-shell.md index 073db7b0..4249346b 100644 --- a/docs/appendices/ui-shell.md +++ b/docs/appendices/ui-shell.md @@ -191,8 +191,19 @@ RVA `0xa490` возвращает поле, которое RVA `0x17660` запÐ проверяет отрисовщик меток, и выбирает занятый варбот. Пока герой внутри, на карте остаётся метка этой машины с белым контуром и её собственным курсом. При выходе RVA `0x63e3f` снимает выделение машины, и на карте -возвращается метка героя. Маршруты выбранных машин, -обнаружение чужих объектов и указатели внешних камер остаются открыты. +возвращается метка героя. + +Выбранная машина показывает также оставшийся маршрут. RVA `0x77ae0` +берёт готовые точки пути от элемента `+0xc0` до `+0xc4`. Пока этот список +пуст, используются координаты записей очереди с типом 2 или видом цели +`0x202`. Например, готовый путь через две точки скрывает более поздний +приказ, пока машина не закончит этот путь. Вызов DLL подтвердил линию +`#64C864` от текущей позиции через точки и квадраты 3×3 цвета `#C8C864` +на их концах. FParkan использует оставшиеся точки контроллера движения +и очередь приказов. Выбор союзного варбота через `F` включает его маршрут. + +Групповой выбор в стратегическом режиме, обнаружение чужих объектов +и указатели внешних камер остаются открыты. ## Контракт новой реализации |
