From da4c8ed23fe5289dbdc7d81a6eb6ddf66ff94ef7 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 05:05:02 +0400 Subject: fix(movement): route autonomous units around buildings Project the bounds of live building meshes onto the ground and expand them by the vehicle radius. The shared route follower chooses exterior corners for blocked legs and can leave a footprint containing its starting position. Verified a detour on the stock factory geometry, stock builder resupply, a window run of Single.01, and 15 minutes of simulation on all 29 missions. Narrow openings, flying clearance and moving bodies remain open. --- crates/fparkan-runtime/src/unit_patrol.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (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 0cbb4959..e8f94b3f 100644 --- a/crates/fparkan-runtime/src/unit_patrol.rs +++ b/crates/fparkan-runtime/src/unit_patrol.rs @@ -3,7 +3,9 @@ use super::{ boarding::WARBOT_CLASS, next_crt_rand, patrol_points::{PatrolPointReport, PatrolPoints}, + projectile::unit_sphere, route_motion::{follow_route, route_points, turn_toward}, + route_obstacles::BuildingFootprints, unit_combat::CombatTarget, unit_speed::{order_speed, UnitSpeedKind, UnitSpeedReport}, EngineError, LoadedMissionState, MissionDocument, MissionObjectDraft, MissionScriptBundle, @@ -30,6 +32,7 @@ pub(super) struct UnitPatrol { pub(super) speed_report: UnitSpeedReport, pub(super) motion_report: crate::UnitMotionReport, pub(super) factory_raid_clans: usize, + buildings: BuildingFootprints, } #[derive(Clone)] @@ -158,6 +161,7 @@ impl UnitPatrol { speed_report: UnitSpeedReport::default(), motion_report: crate::UnitMotionReport::default(), factory_raid_clans: 0, + buildings: BuildingFootprints::default(), } } @@ -401,6 +405,7 @@ impl UnitPatrol { speed_report: UnitSpeedReport::default(), motion_report: crate::UnitMotionReport::default(), factory_raid_clans: 0, + buildings: BuildingFootprints::default(), }) } @@ -425,6 +430,9 @@ impl UnitPatrol { }); let seconds = now_ms.saturating_sub(state.clock_ms) as f32 * 0.001; state.clock_ms = state.clock_ms.max(now_ms); + if seconds > 0.0 && !state.units.is_empty() { + state.buildings.refresh(world, mission); + } let mut poses = Vec::new(); for unit in &mut state.units { let Ok(before) = transform_state(world, unit.handle) else { @@ -611,7 +619,16 @@ impl UnitPatrol { } else { 9.0 }; - let after = follow_route(before, &mut unit.points, speed, seconds, |xy| { + let clearance = motion_object + .original_id + .and_then(|id| { + let (center, radius) = + unit_sphere(&mission.mission_assets, id as usize, before)?; + Some(radius + (center[0] - from[0]).hypot(center[1] - from[1])) + }) + .unwrap_or(0.0); + let obstacles = state.buildings.with_clearance(clearance); + let after = follow_route(before, &mut unit.points, speed, seconds, &obstacles, |xy| { terrain.height_at(xy).map_err(EngineError::Terrain) })?; if after != before { -- cgit v1.2.3