From c4439f993e3cd30f98acf65d0cd088abbb389232 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 25 Nov 2026 12:44:27 +0400 Subject: feat(ai): patrol scripted protection points PBM_PLACE_PROTECT recruits free warbots for TARGET_BY_PLACE and preserves its patrol group across Continue calls. New factory units can reinforce it; releasing the group preserves a subsequent movement or attack order. Coverage counts point orders and continuations by clan and both coordinates. Validated with fmt/check/test workspace, stock mission 10 group lifecycle, stock building and factory guard regressions, and 900-second simulations of missions 8, 10 and 12. Mission 10 ran in the window from stock start, issued the point order and reinforced it, with clean Vulkan validation. Original Behavior.dll RVA 0x2d520 confirmed point/radius parameters. Routing, free-unit recruitment and continuation timing remain approximate. Mission chronology alongside the original is open. Simulations expose Handler(13) in mission 8 and another group recruitment mode in mission 12. --- crates/fparkan-runtime/src/unit_patrol.rs | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'crates/fparkan-runtime/src/unit_patrol.rs') diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs index 6fb1c92a..8817495e 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -253,6 +253,17 @@ impl UnitPatrol { .retain(|unit| unit.handle != handle || unit.center_object != Some(target)); } + pub(super) fn has_point_order(&self, handle: ObjectHandle, point: [f32; 2]) -> bool { + self.units + .iter() + .any(|unit| unit.handle == handle && unit.patrols_point(point)) + } + + pub(super) fn clear_point_order(&mut self, handle: ObjectHandle, point: [f32; 2]) { + self.units + .retain(|unit| unit.handle != handle || !unit.patrols_point(point)); + } + pub(super) fn shut_down(&mut self, handle: ObjectHandle) -> bool { // shortcut: stop autonomous movement and fire until the native shutdown task is modeled. self.units.retain(|unit| unit.handle != handle); @@ -512,6 +523,13 @@ fn new_patrol_replaces_a_script_attack_order() { } impl PatrollingUnit { + fn patrols_point(&self, point: [f32; 2]) -> bool { + self.center_object.is_none() + && self.attack_target.is_none() + && self.destinations.is_none() + && self.center == point + } + fn center(&self, world: &World) -> Option<[f32; 2]> { // shortcut: use the target's transform as the patrol center until native building approaches are wired. match self.center_object { @@ -527,6 +545,31 @@ impl PatrollingUnit { } } +#[cfg(test)] +#[test] +fn point_patrol_cleanup_preserves_reassigned_orders() { + let mut world = fparkan_world::new(fparkan_world::WorldConfig::default()); + let actor = fparkan_world::construct_object( + &mut world, + fparkan_world::ObjectDraft { original_id: None }, + ) + .unwrap(); + fparkan_world::register_object(&mut world, actor).unwrap(); + let mut patrol = UnitPatrol::scripted(); + let point = [1124.0, 783.0]; + patrol.order(&world, actor, point, 60.0); + assert!(patrol.has_point_order(actor, point)); + patrol.clear_point_order(actor, [1125.0, 783.0]); + assert!(patrol.has_point_order(actor, point)); + patrol.move_to(&world, actor, point, false); + assert!(!patrol.has_point_order(actor, point)); + patrol.clear_point_order(actor, point); + assert!(patrol.is_patrolling(actor)); + patrol.order(&world, actor, point, 90.0); + patrol.clear_point_order(actor, point); + assert!(!patrol.is_patrolling(actor)); +} + #[cfg(test)] #[test] fn shutdown_clears_patrol_until_a_new_order_arrives() { -- cgit v1.2.3