From 61208d874cb3d9bf93e9f7c60aceebc287454b62 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 11:59:08 +0400 Subject: 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. --- crates/fparkan-runtime/src/unit_patrol/orders.rs | 65 +++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'crates/fparkan-runtime/src/unit_patrol') 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), } @@ -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>, + ) { + 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; @@ -414,6 +452,29 @@ mod tests { assert!(patrol.satellite_route(enemy).is_empty()); } + #[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()); -- cgit v1.2.3