aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_patrol.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 04:15:02 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 04:15:02 +0300
commitb5c1c1d4b108260765095c1dea6814ad6f707589 (patch)
treee1fc34f806a95236261fc2aad96e8dcec99bf085 /crates/fparkan-runtime/src/unit_patrol.rs
parentda4c8ed23fe5289dbdc7d81a6eb6ddf66ff94ef7 (diff)
downloadfparkan-b5c1c1d4b108260765095c1dea6814ad6f707589.tar.xz
fparkan-b5c1c1d4b108260765095c1dea6814ad6f707589.zip
fix(movement): account for vehicle traffic along ground routes
Ground routes now clear live vehicle bounds as well as buildings. Each movement step reserves the space it traversed for the rest of the frame. A parked vehicle can delay arrival without deleting the destination, and an obstructed detour can be replaced. Verified head-on passing, crossing during one long frame and resuming after an occupied goal clears. Workspace checks, the AutoDemo window, stock builder resupply and the 29-mission simulation corpus passed. Tight groups and airborne clearance remain approximate.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index e8f94b3f..5479ef95 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -3,9 +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,
+ route_traffic::FrameTraffic,
unit_combat::CombatTarget,
unit_speed::{order_speed, UnitSpeedKind, UnitSpeedReport},
EngineError, LoadedMissionState, MissionDocument, MissionObjectDraft, MissionScriptBundle,
@@ -430,9 +430,12 @@ 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() {
+ let mut traffic = if seconds > 0.0 && !state.units.is_empty() {
state.buildings.refresh(world, mission);
- }
+ FrameTraffic::read(world, mission)
+ } else {
+ FrameTraffic::default()
+ };
let mut poses = Vec::new();
for unit in &mut state.units {
let Ok(before) = transform_state(world, unit.handle) else {
@@ -619,18 +622,22 @@ impl UnitPatrol {
} else {
9.0
};
- 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)
- })?;
+ let clearance = traffic.radius(unit.handle);
+ let Some(neighbors) = traffic.blockers(unit.handle, [from[0], from[1]], clearance)
+ else {
+ continue;
+ };
+ let buildings = state.buildings.with_clearance(clearance);
+ let (after, swept) = follow_route(
+ before,
+ &mut unit.points,
+ speed,
+ seconds,
+ &buildings,
+ &neighbors,
+ |xy| terrain.height_at(xy).map_err(EngineError::Terrain),
+ )?;
+ traffic.reserve(unit.handle, swept);
if after != before {
poses.push((unit.handle, before, after));
}