aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 20:28:11 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 20:28:11 +0300
commit9238e2ec8c578145629b5b774b15a0aa205aee32 (patch)
tree06dcf62fe22b347b812fad6bf256fcf092ecdc5b /crates/fparkan-runtime
parent480161a733ebcb8261b13cf602df24d4423b4125 (diff)
downloadfparkan-9238e2ec8c578145629b5b774b15a0aa205aee32.tar.xz
fparkan-9238e2ec8c578145629b5b774b15a0aa205aee32.zip
fix(control): use the original neutral vehicle capture range
The GOG Enter handler shares a strict horizontal 20-unit check for capture and boarding. The stock firing-range window transferred both neutral warbots beyond the old radius, and the licensed Teleport check still credited the mobile HQ.
Diffstat (limited to 'crates/fparkan-runtime')
-rw-r--r--crates/fparkan-runtime/src/boarding.rs32
-rw-r--r--crates/fparkan-runtime/src/mission_events.rs13
2 files changed, 25 insertions, 20 deletions
diff --git a/crates/fparkan-runtime/src/boarding.rs b/crates/fparkan-runtime/src/boarding.rs
index e9dd7531..165df6b1 100644
--- a/crates/fparkan-runtime/src/boarding.rs
+++ b/crates/fparkan-runtime/src/boarding.rs
@@ -85,7 +85,7 @@ pub fn board_friendly_warbot(
return Ok(None);
};
let hero_pose = transform_state(&engine.world, hero.handle)?;
- let [hero_x, hero_y, _] = hero_pose.position.map(f32::from_bits);
+ let hero_position = hero_pose.position.map(f32::from_bits);
let candidate = mission
.object_drafts
.iter()
@@ -108,10 +108,7 @@ pub fn board_friendly_warbot(
return None;
}
let state = transform_state(&engine.world, handle).ok()?;
- let [x, y, _] = state.position.map(f32::from_bits);
- if !within_boarding_range([hero_x, hero_y], [x, y]) {
- return None;
- }
+ vehicle_interaction_distance_sq(hero_position, state.position.map(f32::from_bits))?;
Some((component_cockpit(mission, index, handle)?, state.position))
})
.next();
@@ -151,17 +148,30 @@ pub fn board_friendly_warbot(
Ok(Some(cockpit))
}
-fn within_boarding_range([hero_x, hero_y]: [f32; 2], [x, y]: [f32; 2]) -> bool {
- (x - hero_x).hypot(y - hero_y) < 20.0
+pub(super) fn vehicle_interaction_distance_sq(
+ [hero_x, hero_y, _]: [f32; 3],
+ [x, y, _]: [f32; 3],
+) -> Option<f64> {
+ // iron3d+0x7240b narrows the X delta to f32 before comparing the
+ // horizontal length without storing it back to f32.
+ let dx = f64::from(x - hero_x);
+ let dy = f64::from(y) - f64::from(hero_y);
+ let distance_sq = dx * dx + dy * dy;
+ (distance_sq < 20.0 * 20.0).then_some(distance_sq)
}
#[cfg(test)]
mod tests {
#[test]
- fn boarding_reach_excludes_the_horizontal_boundary() {
- assert!(super::within_boarding_range([0.0, 0.0], [12.0, 15.99]));
- assert!(!super::within_boarding_range([0.0, 0.0], [12.0, 16.0]));
- assert!(!super::within_boarding_range([0.0, 0.0], [f32::NAN, 0.0]));
+ fn vehicle_interaction_ignores_height_and_excludes_the_horizontal_boundary() {
+ use super::vehicle_interaction_distance_sq;
+
+ let hero = [0.0; 3];
+ assert!(vehicle_interaction_distance_sq(hero, [12.0, 15.99, 1_000.0]).is_some());
+ assert!(vehicle_interaction_distance_sq(hero, [19.0, 0.0, -1_000.0]).is_some());
+ assert!(vehicle_interaction_distance_sq(hero, [12.0, 16.0, 0.0]).is_none());
+ assert!(vehicle_interaction_distance_sq(hero, [20.0, 0.0, 0.0]).is_none());
+ assert!(vehicle_interaction_distance_sq(hero, [f32::NAN, 0.0, 0.0]).is_none());
}
}
diff --git a/crates/fparkan-runtime/src/mission_events.rs b/crates/fparkan-runtime/src/mission_events.rs
index 6cd0c9df..1275ea93 100644
--- a/crates/fparkan-runtime/src/mission_events.rs
+++ b/crates/fparkan-runtime/src/mission_events.rs
@@ -391,7 +391,7 @@ impl MissionEvents {
/// Transfers the nearest available neutral warbot or mobile HQ to the player's clan.
///
-/// The provisional interaction uses a 12-unit radius around the player's body.
+/// The distance between the two centers must be under 20 units in the horizontal plane.
/// Returns the original object ID of a successful transfer.
///
/// # Errors
@@ -439,14 +439,9 @@ pub fn capture_neutral_warbot(
.ok()?
.position
.map(f32::from_bits);
- let distance_squared: f32 = position
- .iter()
- .zip(target)
- .map(|(p, q)| (p - q).powi(2))
- .sum();
- // shortcut: radius only, until native aim and range checks are measured.
- (distance_squared <= 12.0_f32.powi(2)).then_some((
- distance_squared,
+ // shortcut: prefer the closest vehicle until native target selection is recovered.
+ Some((
+ super::boarding::vehicle_interaction_distance_sq(position, target)?,
handle,
identity.original_id?,
))