aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_patrol.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-11-26 04:45:53 +0300
committerValentin Popov <valentin@popov.link>2026-11-26 04:45:53 +0300
commit531753ef5fbfa846b4291864458f511d5c7e1b59 (patch)
treead71fdb5a50ff880fc202d85114c41a5877be276 /crates/fparkan-runtime/src/unit_patrol.rs
parent6ed1829936f23c92b9aec24e0eef6884876bb99b (diff)
downloadfparkan-531753ef5fbfa846b4291864458f511d5c7e1b59.tar.xz
fparkan-531753ef5fbfa846b4291864458f511d5c7e1b59.zip
fix(movement): ground chassis on their lowest mesh points
Sample the terrain under four support points in the initial chassis pose. Preserve any existing positive clearance above support and recalculate the root height after moving or turning, so a low start does not carry penetration across the route. The stock heavy AutoDemo chassis previously put its root at Z 2 with support at Z 2.9537. The same regression now passes. Verified uneven support and descent, all workspace checks, the 29-mission simulation corpus and an AutoDemo window run with clean Vulkan validation.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index e04b8f3a..57e01b78 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -2,6 +2,7 @@ use super::{
autodemo::{MOBILE_UNIT, PLANT_CLASS},
boarding::WARBOT_CLASS,
flight_altitude::FlightClearance,
+ ground_support::GroundSupport,
next_crt_rand,
patrol_points::{PatrolPointReport, PatrolPoints},
route_motion::{follow_route, route_points, turn_toward, RouteClearance},
@@ -49,6 +50,7 @@ struct PatrollingUnit {
attack: Option<ObjectHandle>,
attack_target: Option<(ObjectHandle, usize)>,
raid_factory: Option<(ObjectHandle, usize)>,
+ ground_support: Option<Option<GroundSupport>>,
}
pub(super) struct PreparedPatrol {
@@ -208,6 +210,7 @@ impl UnitPatrol {
attack: None,
attack_target: None,
raid_factory: None,
+ ground_support: None,
});
true
}
@@ -392,6 +395,7 @@ impl UnitPatrol {
attack: None,
attack_target: None,
raid_factory: None,
+ ground_support: None,
})
.collect();
Some(Self {
@@ -554,6 +558,14 @@ impl UnitPatrol {
let flight = (can_fly == Some(true) && radius > 0.0).then_some(FlightClearance {
body_radius: radius,
});
+ let ground = if can_fly == Some(false) {
+ *unit.ground_support.get_or_insert_with(|| {
+ GroundSupport::prepare(&mission.mission_assets, original_id as usize)
+ })
+ } else {
+ None
+ };
+ let height_at = |xy| terrain.height_at(xy).map_err(EngineError::Terrain);
if let Some(enemy) = enemy.filter(|enemy| enemy.in_range) {
let mut after = before;
let (yaw, _) = turn_toward(
@@ -570,6 +582,9 @@ impl UnitPatrol {
after.position[2] = flight.raised(from[2], floor, 9.0, seconds).0.to_bits();
}
}
+ if let Some(ground) = ground {
+ ground.reanchor(before, &mut after, height_at)?;
+ }
if after != before {
poses.push((unit.handle, before, after));
}
@@ -608,6 +623,13 @@ impl UnitPatrol {
unit.retry_ms = now_ms.saturating_add(1_000);
}
if unit.points.is_empty() && flight.is_none() {
+ if let Some(ground) = ground {
+ let mut after = before;
+ ground.reanchor(before, &mut after, height_at)?;
+ if after != before {
+ poses.push((unit.handle, before, after));
+ }
+ }
continue;
}
let speed = if (place_patrol && enemy.is_none()) || unit.destinations.is_some() {
@@ -641,8 +663,9 @@ impl UnitPatrol {
buildings: &buildings,
traffic: &neighbors,
flight,
+ ground,
},
- |xy| terrain.height_at(xy).map_err(EngineError::Terrain),
+ height_at,
)?;
traffic.reserve(unit.handle, swept);
if after != before {