Smooth recovery drone airlift to track and suppress Final Lap / Wrong Way in DeathMatch

- Airlift recovering/repaired crafts smoothly from breakdown site to the target track waypoint (tunnel ceiling-aware cruise arc, interpolated drone pose/pitch, and post-touchdown drone departure)
- Disable FINAL LAP and WRONG WAY warnings in DeathMatch mode while preserving them in race modes
- Extend gameplay regression tests for smooth airlift trajectory/departure and DeathMatch warning suppression
This commit is contained in:
Luxferre committed 2026-12-01 19:38:55 +02:00
1 parent db788a2739
commit bbd701b716
7 files changed
+568 -148

No files matched your search

+249 -48
View File
@@ -33,6 +33,97 @@ float closest_segment_t(const Vec3& a, const Vec3& b, const Vec3& p, Vec3& out_p
return t;
}
float smoothstep01(float t) {
t = std::clamp(t, 0.0f, 1.0f);
return t * t * (3.0f - 2.0f * t);
}
void begin_recovery_sequence(CraftState& c, bool refill, float duration) {
c.vel = Vec3(0.0f, 0.0f, 0.0f);
c.yaw_rate = 0.0f;
c.recovery_state = RecoveryState::CallingRepair;
c.recovery_refill = refill;
c.recovery_duration = duration;
c.recovery_timer = duration;
c.recovery_pos = c.curr_pose.pos;
c.recovery_start_yaw = c.curr_pose.yaw;
c.recovery_start_pitch = c.curr_pose.pitch;
c.recovery_start_roll = c.curr_pose.roll;
c.recovery_target_valid = false;
c.recovery_depart_timer = 0.0f;
c.pit_stuck_timer = 0.0f;
c.stuck_in_pit_hint = false;
c.wrong_way = false;
const Vec3 fwd(std::sin(c.recovery_start_yaw), 0.0f, std::cos(c.recovery_start_yaw));
const Vec3 start_drone = c.recovery_pos - fwd * 2.5f + Vec3(0.0f, 7.5f, 0.0f);
c.recovery_drone_curr_pose = {start_drone, c.recovery_start_yaw, 0.18f, 0.0f};
c.recovery_drone_prev_pose = c.recovery_drone_curr_pose;
}
void init_recovery_flight_plan(CraftState& c, const assets::LevelData& level,
const std::vector<CraftState>& crafts, bool restrict_arc) {
TrackRecoveryTarget tgt = compute_track_recovery_target(c, level, crafts, restrict_arc);
c.recovery_target_pos = tgt.valid ? tgt.pos : c.recovery_pos;
c.recovery_target_yaw = tgt.valid ? tgt.yaw : c.recovery_start_yaw;
c.recovery_target_wp = tgt.valid ? tgt.waypoint_idx : c.current_wp;
c.recovery_target_valid = true;
const Vec3& start = c.recovery_pos;
const Vec3& target = c.recovery_target_pos;
bool all_under_ceiling = true;
float min_ceil = 1e6f;
float max_floor = std::max(start.y, target.y);
float max_obstacle_y = std::max(start.y, target.y);
constexpr int kSamples = 16;
for (int k = 0; k < kSamples; ++k) {
const float t = static_cast<float>(k) / static_cast<float>(kSamples - 1);
const Vec3 sp = lerp(start, target, t);
float fy = 0.0f, cy = 1e6f;
level.sample_surface_and_ceiling(sp.x, sp.z, sp.y, fy, cy);
if (cy >= 1e5f) {
all_under_ceiling = false;
} else {
min_ceil = std::min(min_ceil, cy);
}
max_floor = std::max(max_floor, fy);
const float gy = level.sample_height_world(sp.x, sp.z);
max_obstacle_y = std::max(max_obstacle_y, gy);
const int ix = std::clamp(static_cast<int>(std::floor(sp.x)), 0, assets::kMapWidth - 1);
const int iz = std::clamp(static_cast<int>(std::floor(sp.z)), 0, assets::kMapHeight - 1);
const assets::MapEntry& cell = level.cell(ix, iz);
if (cell.tex_or_col < 0) {
int col_idx = -cell.tex_or_col;
if (col_idx > 0 && col_idx < assets::kMaxColumns) {
uint8_t mask = level.columns[col_idx].shape_mask;
for (int s_hi = 7; s_hi >= 0; --s_hi) {
if ((mask & (1u << s_hi)) != 0) {
max_obstacle_y = std::max(max_obstacle_y, gy + static_cast<float>(s_hi) + 1.0f);
break;
}
}
}
}
}
const float max_y = std::max(start.y, target.y);
const float dx = target.x - start.x;
const float dz = target.z - start.z;
const float dist_2d = std::sqrt(dx * dx + dz * dz);
if (all_under_ceiling && min_ceil < 1e5f) {
const float band_lo = max_y;
const float band_hi = std::max(max_y, min_ceil - 0.65f);
c.recovery_cruise_y = std::clamp(std::max(max_floor + 0.55f, max_y), band_lo, band_hi);
} else {
const float base_lift = (dist_2d < 0.75f)
? (max_y + 0.55f)
: (max_y + std::clamp(1.1f + dist_2d * 0.14f, 1.2f, 3.0f));
c.recovery_cruise_y = std::min(std::max(base_lift, max_obstacle_y + 0.85f), max_y + 5.8f);
}
}
void apply_damage(CraftState& victim, int attacker_id, const std::vector<CraftState>& crafts,
const RaceSetup& setup, std::vector<ParticleBurst>& particles,
std::vector<SimEvent>& events, bool& out_race_over, int& out_winner_id) {
@@ -45,14 +136,7 @@ void apply_damage(CraftState& victim, int attacker_id, const std::vector<CraftSt
// Craft destroyed!
victim.shield = 0.0f;
victim.deaths += 1;
victim.vel = Vec3(0, 0, 0);
victim.recovery_state = RecoveryState::CallingRepair;
victim.recovery_refill = true;
victim.recovery_duration = 3.2f;
victim.recovery_timer = 3.2f;
victim.recovery_pos = victim.curr_pose.pos;
victim.pit_stuck_timer = 0.0f;
victim.stuck_in_pit_hint = false;
begin_recovery_sequence(victim, true, 3.2f);
std::string killer_name = "TRACK";
if (attacker_id >= 0 && attacker_id < static_cast<int>(crafts.size())) {
@@ -315,24 +399,55 @@ void step_combat_and_world(
for (size_t i = 0; i < crafts.size(); ++i) {
CraftState& c = crafts[i];
if (c.recovery_state == RecoveryState::Active && c.recovery_depart_timer > 0.0f) {
c.recovery_depart_timer = std::max(0.0f, c.recovery_depart_timer - dt);
const float dep_dur = std::max(c.recovery_depart_duration, 0.1f);
const float dp = std::clamp(1.0f - (c.recovery_depart_timer / dep_dur), 0.0f, 1.0f);
const float de = dp * dp;
const Vec3 dfwd(std::sin(c.recovery_depart_yaw), 0.0f, std::cos(c.recovery_depart_yaw));
c.recovery_drone_curr_pose.pos =
c.recovery_depart_start + dfwd * (de * 5.5f) + Vec3(0.0f, de * 8.0f, 0.0f);
c.recovery_drone_curr_pose.yaw = c.recovery_depart_yaw;
c.recovery_drone_curr_pose.pitch = 0.22f * dp;
c.recovery_drone_curr_pose.roll = 0.0f;
}
if (c.recovery_state != RecoveryState::Active) {
c.recovery_timer -= dt;
float rec_dur = std::max(c.recovery_duration, 0.1f);
float u = c.recovery_timer / rec_dur;
if (c.recovery_state == RecoveryState::CallingRepair && u < 0.68f) {
const float rec_dur = std::max(c.recovery_duration, 0.1f);
const float u = std::clamp(c.recovery_timer / rec_dur, 0.0f, 1.0f);
const float approach_end_u = 0.72f;
const float carry_start_u = c.recovery_refill ? 0.48f : 0.62f;
if (c.recovery_state == RecoveryState::CallingRepair &&
u < approach_end_u && c.recovery_timer > 0.0f) {
c.recovery_state = RecoveryState::AwaitingRepair;
if (c.is_human) {
events.push_back({SimSoundCue::None, c.curr_pose.pos, c.player_index,
c.recovery_refill ? "AWAITING REPAIR" : "AWAITING RECOVERY", 0.0f});
}
} else if (c.recovery_state == RecoveryState::AwaitingRepair && u < 0.34f) {
}
if (c.recovery_state == RecoveryState::AwaitingRepair &&
u < carry_start_u && c.recovery_timer > 0.0f) {
c.recovery_state = RecoveryState::Repairing;
if (c.is_human) {
events.push_back({c.recovery_refill ? SimSoundCue::Refuel : SimSoundCue::SwitchTrigger,
c.curr_pose.pos, c.player_index,
c.recovery_refill ? "REPAIRING" : "RECOVERING TO TRACK", 0.0f});
}
} else if (c.recovery_timer <= 0.0f) {
}
// Keep landing elevation synchronized with any dynamic terrain morphs under the target
const VehicleSpec& sp_rec = kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)];
if (c.recovery_target_valid) {
const float tgt_gy = level.sample_entity_surface_y(c.recovery_target_pos.x, c.recovery_target_pos.z);
float tgt_fy = 0.0f, tgt_cy = 1e6f;
level.sample_surface_and_ceiling(c.recovery_target_pos.x, c.recovery_target_pos.z,
tgt_gy + sp_rec.hover_offset, tgt_fy, tgt_cy);
c.recovery_target_pos.y = tgt_fy + sp_rec.hover_offset;
}
if (c.recovery_timer <= 0.0f) {
c.recovery_state = RecoveryState::Active;
if (c.recovery_refill) {
c.shield = c.max_shield;
@@ -342,12 +457,118 @@ void step_combat_and_world(
} else if (setup.fuel_enabled && c.fuel < 5.0f) {
c.fuel = 8.0f;
}
place_craft_on_track(c, level, crafts, setup.mode != GameMode::DeathMatch);
float live_y = 0.0f;
if (c.recovery_target_valid &&
is_track_recovery_spot_clear(c, level, crafts, c.recovery_target_pos.x,
c.recovery_target_pos.z, live_y, false)) {
Vec3 land_pos(c.recovery_target_pos.x, live_y, c.recovery_target_pos.z);
finalize_craft_recovery_pose(c, level, land_pos, c.recovery_target_yaw,
c.recovery_target_wp, false);
} else {
place_craft_on_track(c, level, crafts, setup.mode != GameMode::DeathMatch);
}
c.recovery_depart_duration = 0.75f;
c.recovery_depart_timer = 0.75f;
c.recovery_depart_start = c.curr_pose.pos + Vec3(0.0f, 1.05f, 0.0f);
c.recovery_depart_yaw = c.curr_pose.yaw;
c.recovery_drone_curr_pose = {c.recovery_depart_start, c.recovery_depart_yaw, 0.0f, 0.0f};
c.ai_pit_cooldown = 0.0f;
c.recovery_cooldown = 1.5f;
c.recovery_refill = true;
c.recovery_duration = 3.2f;
} else if (c.shield <= 0.1f) {
c.recovery_target_valid = false;
} else if (c.recovery_state == RecoveryState::CallingRepair) {
c.curr_pose.pos = c.recovery_pos;
c.curr_pose.yaw = c.recovery_start_yaw;
c.curr_pose.pitch = c.recovery_start_pitch;
c.curr_pose.roll = c.recovery_start_roll;
const Vec3 sfwd(std::sin(c.recovery_start_yaw), 0.0f, std::cos(c.recovery_start_yaw));
Vec3 approach_start = c.recovery_pos - sfwd * 2.5f + Vec3(0.0f, 7.5f, 0.0f);
Vec3 approach_end = c.recovery_pos + Vec3(0.0f, 1.45f, 0.0f);
float sf = 0.0f, sc = 1e6f;
level.sample_surface_and_ceiling(c.recovery_pos.x, c.recovery_pos.z,
c.recovery_pos.y, sf, sc);
if (sc < 1e5f) {
const float max_drone_y = std::max(c.recovery_pos.y + 1.15f, sc - 0.45f);
approach_start.y = std::min(approach_start.y, max_drone_y);
if (c.recovery_drone_prev_pose.pos.y > max_drone_y) {
c.recovery_drone_prev_pose.pos.y = max_drone_y;
}
}
const float p = std::clamp((1.0f - u) / std::max(1.0f - approach_end_u, 1e-4f), 0.0f, 1.0f);
const float ease_out = 1.0f - (1.0f - p) * (1.0f - p);
Vec3 dpos = lerp(approach_start, approach_end, ease_out);
if (sc < 1e5f) {
dpos.y = std::min(dpos.y, std::max(approach_end.y, sc - 0.45f));
}
c.recovery_drone_curr_pose = {dpos, c.recovery_start_yaw, 0.18f * (1.0f - ease_out), 0.0f};
} else if (c.recovery_state == RecoveryState::AwaitingRepair) {
c.curr_pose.pos = c.recovery_pos;
c.curr_pose.yaw = c.recovery_start_yaw;
c.curr_pose.pitch = c.recovery_start_pitch;
c.curr_pose.roll = c.recovery_start_roll;
const float q = std::clamp((approach_end_u - u) /
std::max(approach_end_u - carry_start_u, 1e-4f), 0.0f, 1.0f);
const float hover_y = lerp(1.45f, 1.05f, q);
c.recovery_drone_curr_pose = {c.curr_pose.pos + Vec3(0.0f, hover_y, 0.0f),
c.curr_pose.yaw, 0.0f, 0.0f};
} else {
// Smoothly airlift craft horizontally & vertically from breakdown site to track
if (!c.recovery_target_valid) {
init_recovery_flight_plan(c, level, crafts, setup.mode != GameMode::DeathMatch);
}
const Vec3 prev_pos = c.curr_pose.pos;
const float s = std::clamp(1.0f - (u / std::max(carry_start_u, 1e-4f)), 0.0f, 1.0f);
const float h = smoothstep01((s - 0.08f) / 0.84f);
float lift = 1.0f;
if (s < 0.25f) {
lift = smoothstep01(s / 0.25f);
} else if (s > 0.75f) {
lift = smoothstep01((1.0f - s) / 0.25f);
}
Vec3 next_pos;
next_pos.x = lerp(c.recovery_pos.x, c.recovery_target_pos.x, h);
next_pos.z = lerp(c.recovery_pos.z, c.recovery_target_pos.z, h);
const float base_y = lerp(c.recovery_pos.y, c.recovery_target_pos.y, h);
next_pos.y = lerp(base_y, c.recovery_cruise_y, lift);
float live_floor = 0.0f, live_ceil = 1e6f;
level.sample_surface_and_ceiling(next_pos.x, next_pos.z, next_pos.y, live_floor, live_ceil);
next_pos.y = std::max(next_pos.y, live_floor + sp_rec.hover_offset);
if (live_ceil < 1e5f && next_pos.y < live_ceil + 0.5f) {
const float max_under = std::max(live_floor + 0.14f, live_ceil - 0.55f);
next_pos.y = std::min(next_pos.y, max_under);
}
const float yaw_s = smoothstep01((s - 0.10f) / 0.78f);
const float lvl_s = smoothstep01(s / 0.25f);
c.curr_pose.pos = next_pos;
c.curr_pose.yaw = lerp_angle(c.recovery_start_yaw, c.recovery_target_yaw, yaw_s);
c.curr_pose.pitch = lerp(c.recovery_start_pitch, 0.0f, lvl_s);
c.curr_pose.roll = lerp(c.recovery_start_roll, 0.0f, lvl_s);
const Vec3 dfwd(std::sin(c.curr_pose.yaw), 0.0f, std::cos(c.curr_pose.yaw));
const Vec3 delta = c.curr_pose.pos - prev_pos;
const float fwd_spd = (dt > 1e-5f)
? ((delta.x * dfwd.x + delta.z * dfwd.z) / dt)
: 0.0f;
const float tilt_fade = std::clamp((1.0f - s) / 0.15f, 0.0f, 1.0f);
c.recovery_drone_curr_pose = {
c.curr_pose.pos + Vec3(0.0f, 1.05f, 0.0f),
c.curr_pose.yaw,
std::clamp(fwd_spd * 0.012f, -0.18f, 0.18f) * tilt_fade,
0.0f,
};
}
if (c.recovery_timer > 0.0f && c.shield <= 0.1f &&
(c.recovery_state != RecoveryState::Repairing || u > 0.25f)) {
int rec_ticks = static_cast<int>(std::lround(c.recovery_timer * 60.0f));
if (rec_ticks % 4 == 0) {
float h0 = fx_hash(pos_seed_u32(c.curr_pose.pos, static_cast<uint32_t>(rec_ticks)));
@@ -370,13 +591,7 @@ void step_combat_and_world(
// Trigger repair if fuel completely depleted and stopped
if (setup.fuel_enabled && c.fuel <= 0.05f && c.speed_horizontal() < 0.8f) {
c.recovery_state = RecoveryState::CallingRepair;
c.recovery_refill = true;
c.recovery_duration = 3.0f;
c.recovery_timer = 3.0f;
c.recovery_pos = c.curr_pose.pos;
c.pit_stuck_timer = 0.0f;
c.stuck_in_pit_hint = false;
begin_recovery_sequence(c, true, 3.0f);
if (c.is_human) {
events.push_back({SimSoundCue::Warning, c.curr_pose.pos, c.player_index, "CALLING REPAIR", 0.2f});
}
@@ -716,28 +931,21 @@ void step_combat_and_world(
}
}
std::vector<RecoveryVisual> get_recovery_visuals(const std::vector<CraftState>& crafts) {
std::vector<RecoveryVisual> get_recovery_visuals(const std::vector<CraftState>& crafts, float alpha) {
std::vector<RecoveryVisual> out;
const float t = std::clamp(alpha, 0.0f, 1.0f);
for (const auto& c : crafts) {
if (c.recovery_state == RecoveryState::CallingRepair ||
c.recovery_state == RecoveryState::AwaitingRepair ||
c.recovery_state == RecoveryState::Repairing) {
const bool recovering = (c.recovery_state == RecoveryState::CallingRepair ||
c.recovery_state == RecoveryState::AwaitingRepair ||
c.recovery_state == RecoveryState::Repairing);
const bool departing = (c.recovery_state == RecoveryState::Active && c.recovery_depart_timer > 0.0f);
if (recovering || departing) {
RecoveryVisual rv;
rv.active = true;
float rec_dur = std::max(c.recovery_duration, 0.1f);
float u = std::clamp(c.recovery_timer / rec_dur, 0.0f, 1.0f);
float hover_y = 0.0f;
if (c.recovery_state == RecoveryState::CallingRepair) {
float t = std::clamp((u - 0.68f) / 0.32f, 0.0f, 1.0f);
hover_y = 1.6f + t * 8.0f;
} else if (c.recovery_state == RecoveryState::AwaitingRepair) {
float t = std::clamp((u - 0.34f) / 0.34f, 0.0f, 1.0f);
hover_y = 1.05f + t * 0.55f;
} else {
hover_y = 1.05f;
}
rv.pos = c.curr_pose.pos + Vec3(0.0f, hover_y, 0.0f);
rv.yaw = c.curr_pose.yaw;
rv.pos = lerp(c.recovery_drone_prev_pose.pos, c.recovery_drone_curr_pose.pos, t);
rv.yaw = lerp_angle(c.recovery_drone_prev_pose.yaw, c.recovery_drone_curr_pose.yaw, t);
rv.pitch = lerp(c.recovery_drone_prev_pose.pitch, c.recovery_drone_curr_pose.pitch, t);
rv.roll = lerp(c.recovery_drone_prev_pose.roll, c.recovery_drone_curr_pose.roll, t);
out.push_back(rv);
}
}
@@ -749,14 +957,7 @@ bool trigger_track_recovery(CraftState& craft, std::vector<SimEvent>& events) {
craft.recovery_cooldown > 0.0f) {
return false;
}
craft.vel = Vec3(0.0f, 0.0f, 0.0f);
craft.recovery_state = RecoveryState::CallingRepair;
craft.recovery_refill = false;
craft.recovery_duration = 1.6f;
craft.recovery_timer = 1.6f;
craft.recovery_pos = craft.curr_pose.pos;
craft.pit_stuck_timer = 0.0f;
craft.stuck_in_pit_hint = false;
begin_recovery_sequence(craft, false, 1.6f);
if (craft.is_human) {
events.push_back({SimSoundCue::Warning, craft.curr_pose.pos, craft.player_index,
"CALLING RECOVERY", 0.18f});