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:
1 parent
db788a2739
commit
bbd701b716
7 files changed
+568
-148
No files matched your search
@@ -1421,8 +1421,8 @@ void GameApp::render_frame(float alpha) {
|
||||
frame_models_.push_back({sim::model_key_for(rec.vehicle_idx, rec.team_idx), gp.pos,
|
||||
gp.yaw, gp.pitch, gp.roll, gscale, Vec4(0.45f, 0.85f, 1.0f, 0.45f)});
|
||||
}
|
||||
for (const auto& rv : sim::get_recovery_visuals(race_sim_.crafts())) {
|
||||
frame_models_.push_back({"RECOV0-0", rv.pos, rv.yaw, 0.0f, 0.0f,
|
||||
for (const auto& rv : sim::get_recovery_visuals(race_sim_.crafts(), alpha)) {
|
||||
frame_models_.push_back({"RECOV0-0", rv.pos, rv.yaw, rv.pitch, rv.roll,
|
||||
sim::kRecoveryVisualScale, Vec4(1, 1, 1, 1)});
|
||||
}
|
||||
for (const auto& pr : race_sim_.props()) {
|
||||
@@ -1895,7 +1895,7 @@ void GameApp::render_hud_viewport(const sim::CraftState& craft, const render::Re
|
||||
float cy = oy + 126.0f * hs;
|
||||
if (race_sim_.countdown_active() || (!race_sim_.countdown_active() && craft.race_time < 0.85f)) {
|
||||
render_countdown_lights(cx, cy, hs);
|
||||
} else if (craft.wrong_way) {
|
||||
} else if (craft.wrong_way && selected_mode_ != sim::GameMode::DeathMatch) {
|
||||
ui_ren_.draw_text_centered_fit(cx, cy + 28.0f * s, static_cast<float>(vw) * 0.75f, 2.6f * s,
|
||||
str.wrong_way, Vec4(1.0f, 0.22f, 0.20f, 1.0f), true, render::UiFont::MenuLarge);
|
||||
} else {
|
||||
|
||||
+249
-48
@@ -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});
|
||||
|
||||
+5
-2
@@ -10,6 +10,8 @@ struct RecoveryVisual {
|
||||
bool active = false;
|
||||
Vec3 pos{0, 0, 0};
|
||||
float yaw = 0.0f;
|
||||
float pitch = 0.0f;
|
||||
float roll = 0.0f;
|
||||
};
|
||||
|
||||
// Shared deterministic explosion, billowing smoke & spark VFX helpers
|
||||
@@ -39,8 +41,9 @@ void step_combat_and_world(
|
||||
std::vector<ProjectileTrace>* out_projectile_traces = nullptr,
|
||||
uint32_t* io_next_projectile_uid = nullptr);
|
||||
|
||||
// Computes visual Recovery Helicopter (RECOV0-0) positions for any craft under repair
|
||||
std::vector<RecoveryVisual> get_recovery_visuals(const std::vector<CraftState>& crafts);
|
||||
// Computes visual Recovery Helicopter (RECOV0-0) positions for any craft under repair or departing
|
||||
std::vector<RecoveryVisual> get_recovery_visuals(const std::vector<CraftState>& crafts,
|
||||
float alpha = 1.0f);
|
||||
|
||||
// Triggers manual track recovery for an active craft without refilling resources
|
||||
bool trigger_track_recovery(CraftState& craft, std::vector<SimEvent>& events);
|
||||
|
||||
+130
-90
@@ -408,6 +408,7 @@ CraftStepFeedback step_craft_physics(CraftState& craft, const CraftInput& input,
|
||||
bool fuel_enabled) {
|
||||
CraftStepFeedback fb;
|
||||
craft.prev_pose = craft.curr_pose;
|
||||
craft.recovery_drone_prev_pose = craft.recovery_drone_curr_pose;
|
||||
if (!std::isfinite(dt) || dt <= 1e-6f) {
|
||||
return fb;
|
||||
}
|
||||
@@ -724,40 +725,115 @@ bool resolve_craft_pair_collision(CraftState& a, CraftState& b, float& out_rel_s
|
||||
return true;
|
||||
}
|
||||
|
||||
bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
bool restrict_to_checkpoint_arc) {
|
||||
bool is_track_recovery_spot_clear(const CraftState& craft, const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
float wx, float wz, float& out_y, bool check_crafts) {
|
||||
if (wx < 2.0f || wx > static_cast<float>(assets::kMapWidth - 3) ||
|
||||
wz < 2.0f || wz > static_cast<float>(assets::kMapHeight - 3)) {
|
||||
return false;
|
||||
}
|
||||
const VehicleSpec& spec = kVehicleSpecs[std::clamp(craft.vehicle_idx, 0, 5)];
|
||||
const float probe_r = spec.collision_radius + 0.08f;
|
||||
|
||||
auto finalize_pose = [&](const Vec3& pos, float yaw) {
|
||||
craft.curr_pose.pos = pos;
|
||||
craft.curr_pose.yaw = yaw;
|
||||
craft.curr_pose.pitch = 0.0f;
|
||||
craft.curr_pose.roll = 0.0f;
|
||||
craft.vel = Vec3(0.0f, 0.0f, 0.0f);
|
||||
craft.yaw_rate = 0.0f;
|
||||
craft.airborne = false;
|
||||
craft.airtime = 0.0f;
|
||||
craft.air_spin_accum = 0.0f;
|
||||
craft.wrong_way = false;
|
||||
craft.scrape_intensity = 0.0f;
|
||||
craft.boost_timer = 0.0f;
|
||||
float dummy_imp = 0.0f;
|
||||
bool dummy_scr = false;
|
||||
resolve_world_collisions(craft, level, dummy_imp, dummy_scr);
|
||||
float raw_gy = level.sample_height_world(wx, wz);
|
||||
float gy = level.sample_entity_surface_y(wx, wz);
|
||||
float fy = 0.0f, cy = 1e6f;
|
||||
level.sample_surface_and_ceiling(wx, wz, gy + spec.hover_offset, fy, cy);
|
||||
if (cy - fy < 0.70f) {
|
||||
return false;
|
||||
}
|
||||
bool on_bridge = (fy > raw_gy + 0.5f);
|
||||
if (!on_bridge && level.sample_normal_world(wx, wz).y < 0.50f) {
|
||||
return false;
|
||||
}
|
||||
const float probe_y = fy + spec.hover_offset;
|
||||
static constexpr float kOffX[5] = {0.0f, 1.0f, -1.0f, 0.0f, 0.0f};
|
||||
static constexpr float kOffZ[5] = {0.0f, 0.0f, 0.0f, 1.0f, -1.0f};
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
float px = wx + kOffX[k] * probe_r;
|
||||
float pz = wz + kOffZ[k] * probe_r;
|
||||
if (px < 1.5f || px > static_cast<float>(assets::kMapWidth) - 2.5f ||
|
||||
pz < 1.5f || pz > static_cast<float>(assets::kMapHeight) - 2.5f) {
|
||||
return false;
|
||||
}
|
||||
int ix = static_cast<int>(std::floor(px));
|
||||
int iz = static_cast<int>(std::floor(pz));
|
||||
if (level.is_cell_solid_at_point(ix, iz, px, pz, probe_y) ||
|
||||
level.is_cliff_blocking_at_y(ix, iz, probe_y)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (check_crafts) {
|
||||
for (const auto& o : all_crafts) {
|
||||
if (o.id == craft.id) continue;
|
||||
Vec3 other_pos;
|
||||
if (o.recovery_state == RecoveryState::Active) {
|
||||
other_pos = o.curr_pose.pos;
|
||||
} else if (o.recovery_state == RecoveryState::Repairing &&
|
||||
o.recovery_target_valid &&
|
||||
std::abs(o.recovery_timer - craft.recovery_timer) < 0.45f) {
|
||||
other_pos = o.recovery_target_pos;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
float dx = other_pos.x - wx;
|
||||
float dz = other_pos.z - wz;
|
||||
if (dx * dx + dz * dz < 1.6f * 1.6f &&
|
||||
std::abs(other_pos.y - probe_y) < 1.5f) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
out_y = probe_y;
|
||||
return true;
|
||||
}
|
||||
|
||||
void finalize_craft_recovery_pose(CraftState& craft, const assets::LevelData& level,
|
||||
const Vec3& pos, float yaw, int waypoint_idx,
|
||||
bool snap_prev_pose) {
|
||||
craft.curr_pose.pos = pos;
|
||||
craft.curr_pose.yaw = yaw;
|
||||
craft.curr_pose.pitch = 0.0f;
|
||||
craft.curr_pose.roll = 0.0f;
|
||||
craft.vel = Vec3(0.0f, 0.0f, 0.0f);
|
||||
craft.yaw_rate = 0.0f;
|
||||
craft.airborne = false;
|
||||
craft.airtime = 0.0f;
|
||||
craft.air_spin_accum = 0.0f;
|
||||
craft.wrong_way = false;
|
||||
craft.scrape_intensity = 0.0f;
|
||||
craft.boost_timer = 0.0f;
|
||||
float dummy_imp = 0.0f;
|
||||
bool dummy_scr = false;
|
||||
resolve_world_collisions(craft, level, dummy_imp, dummy_scr);
|
||||
if (snap_prev_pose) {
|
||||
craft.prev_pose = craft.curr_pose;
|
||||
craft.pit_stuck_timer = 0.0f;
|
||||
craft.stuck_in_pit_hint = false;
|
||||
craft.ai_stuck_timer = 0.0f;
|
||||
craft.ai_unstuck_timer = 0.0f;
|
||||
craft.ai_progress_timer = 0.0f;
|
||||
craft.ai_pit_stay_timer = 0.0f;
|
||||
craft.ai_seeking_pit = false;
|
||||
craft.ai_progress_anchor = craft.curr_pose.pos;
|
||||
craft.ai_anchor_init = true;
|
||||
craft.ai_wp_best_dist = 1e9f;
|
||||
craft.ai_wp_stall_timer = 0.0f;
|
||||
};
|
||||
}
|
||||
craft.pit_stuck_timer = 0.0f;
|
||||
craft.stuck_in_pit_hint = false;
|
||||
craft.ai_stuck_timer = 0.0f;
|
||||
craft.ai_unstuck_timer = 0.0f;
|
||||
craft.ai_progress_timer = 0.0f;
|
||||
craft.ai_pit_stay_timer = 0.0f;
|
||||
craft.ai_seeking_pit = false;
|
||||
craft.ai_progress_anchor = craft.curr_pose.pos;
|
||||
craft.ai_anchor_init = true;
|
||||
craft.ai_wp_best_dist = 1e9f;
|
||||
craft.ai_wp_stall_timer = 0.0f;
|
||||
if (!level.main_waypoints.empty()) {
|
||||
const int n_wp = static_cast<int>(level.main_waypoints.size());
|
||||
const int wi = ((waypoint_idx % n_wp) + n_wp) % n_wp;
|
||||
craft.current_wp = wi;
|
||||
craft.ai_target_wp = (wi + 1) % n_wp;
|
||||
}
|
||||
}
|
||||
|
||||
TrackRecoveryTarget compute_track_recovery_target(const CraftState& craft,
|
||||
const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
bool restrict_to_checkpoint_arc) {
|
||||
TrackRecoveryTarget result;
|
||||
const VehicleSpec& spec = kVehicleSpecs[std::clamp(craft.vehicle_idx, 0, 5)];
|
||||
|
||||
if (level.main_waypoints.empty()) {
|
||||
float gx = std::clamp(craft.curr_pose.pos.x, 2.0f, static_cast<float>(assets::kMapWidth - 3));
|
||||
@@ -765,61 +841,14 @@ bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
float gy = level.sample_entity_surface_y(gx, gz);
|
||||
float fy = 0.0f, cy = 1e6f;
|
||||
level.sample_surface_and_ceiling(gx, gz, gy + spec.hover_offset, fy, cy);
|
||||
finalize_pose(Vec3(gx, fy + spec.hover_offset, gz), craft.curr_pose.yaw);
|
||||
return true;
|
||||
result.pos = Vec3(gx, fy + spec.hover_offset, gz);
|
||||
result.yaw = craft.curr_pose.yaw;
|
||||
result.waypoint_idx = 0;
|
||||
result.valid = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
const int n_wp = static_cast<int>(level.main_waypoints.size());
|
||||
const float probe_r = spec.collision_radius + 0.08f;
|
||||
|
||||
auto is_spot_clear = [&](float wx, float wz, float& out_y, bool check_crafts) -> bool {
|
||||
if (wx < 2.0f || wx > static_cast<float>(assets::kMapWidth - 3) ||
|
||||
wz < 2.0f || wz > static_cast<float>(assets::kMapHeight - 3)) {
|
||||
return false;
|
||||
}
|
||||
float raw_gy = level.sample_height_world(wx, wz);
|
||||
float gy = level.sample_entity_surface_y(wx, wz);
|
||||
float fy = 0.0f, cy = 1e6f;
|
||||
level.sample_surface_and_ceiling(wx, wz, gy + spec.hover_offset, fy, cy);
|
||||
if (cy - fy < 0.70f) {
|
||||
return false;
|
||||
}
|
||||
bool on_bridge = (fy > raw_gy + 0.5f);
|
||||
if (!on_bridge && level.sample_normal_world(wx, wz).y < 0.50f) {
|
||||
return false;
|
||||
}
|
||||
const float probe_y = fy + spec.hover_offset;
|
||||
static constexpr float kOffX[5] = {0.0f, 1.0f, -1.0f, 0.0f, 0.0f};
|
||||
static constexpr float kOffZ[5] = {0.0f, 0.0f, 0.0f, 1.0f, -1.0f};
|
||||
for (int k = 0; k < 5; ++k) {
|
||||
float px = wx + kOffX[k] * probe_r;
|
||||
float pz = wz + kOffZ[k] * probe_r;
|
||||
if (px < 1.5f || px > static_cast<float>(assets::kMapWidth) - 2.5f ||
|
||||
pz < 1.5f || pz > static_cast<float>(assets::kMapHeight) - 2.5f) {
|
||||
return false;
|
||||
}
|
||||
int ix = static_cast<int>(std::floor(px));
|
||||
int iz = static_cast<int>(std::floor(pz));
|
||||
if (level.is_cell_solid_at_point(ix, iz, px, pz, probe_y) ||
|
||||
level.is_cliff_blocking_at_y(ix, iz, probe_y)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (check_crafts) {
|
||||
for (const auto& o : all_crafts) {
|
||||
if (o.id == craft.id || o.recovery_state != RecoveryState::Active) continue;
|
||||
float dx = o.curr_pose.pos.x - wx;
|
||||
float dz = o.curr_pose.pos.z - wz;
|
||||
if (dx * dx + dz * dz < 1.6f * 1.6f &&
|
||||
std::abs(o.curr_pose.pos.y - probe_y) < 1.5f) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
out_y = probe_y;
|
||||
return true;
|
||||
};
|
||||
|
||||
auto dist_sq_to_wp = [&](int wi) -> float {
|
||||
float dx = level.main_waypoints[wi].x - craft.curr_pose.pos.x;
|
||||
float dz = level.main_waypoints[wi].z - craft.curr_pose.pos.z;
|
||||
@@ -860,7 +889,7 @@ bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
int wi = (wp_start + step) % n_wp;
|
||||
const auto& w = level.main_waypoints[wi];
|
||||
float dummy_y = 0.0f;
|
||||
if (!is_spot_clear(w.x, w.z, dummy_y, false)) continue;
|
||||
if (!is_track_recovery_spot_clear(craft, level, all_crafts, w.x, w.z, dummy_y, false)) continue;
|
||||
float d2 = dist_sq_to_wp(wi);
|
||||
if (d2 < best_d2) {
|
||||
best_d2 = d2;
|
||||
@@ -879,7 +908,7 @@ bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
for (int wi = 0; wi < n_wp; ++wi) {
|
||||
const auto& w = level.main_waypoints[wi];
|
||||
float dummy_y = 0.0f;
|
||||
if (!is_spot_clear(w.x, w.z, dummy_y, false)) continue;
|
||||
if (!is_track_recovery_spot_clear(craft, level, all_crafts, w.x, w.z, dummy_y, false)) continue;
|
||||
float d2 = dist_sq_to_wp(wi);
|
||||
if (d2 < best_d2) {
|
||||
best_d2 = d2;
|
||||
@@ -928,7 +957,7 @@ bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
float tx = wp.x + off.x;
|
||||
float tz = wp.z + off.y;
|
||||
float ty = 0.0f;
|
||||
if (is_spot_clear(tx, tz, ty, true)) {
|
||||
if (is_track_recovery_spot_clear(craft, level, all_crafts, tx, tz, ty, true)) {
|
||||
chosen_x = tx;
|
||||
chosen_z = tz;
|
||||
chosen_y = ty;
|
||||
@@ -938,7 +967,7 @@ bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
}
|
||||
if (!placed_clear) {
|
||||
float ty = 0.0f;
|
||||
if (is_spot_clear(wp.x, wp.z, ty, false)) {
|
||||
if (is_track_recovery_spot_clear(craft, level, all_crafts, wp.x, wp.z, ty, false)) {
|
||||
chosen_y = ty;
|
||||
} else {
|
||||
float gy = level.sample_entity_surface_y(wp.x, wp.z);
|
||||
@@ -948,9 +977,20 @@ bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
}
|
||||
}
|
||||
|
||||
finalize_pose(Vec3(chosen_x, chosen_y, chosen_z), yaw);
|
||||
craft.current_wp = best_wp;
|
||||
craft.ai_target_wp = (best_wp + 1) % n_wp;
|
||||
result.pos = Vec3(chosen_x, chosen_y, chosen_z);
|
||||
result.yaw = yaw;
|
||||
result.waypoint_idx = best_wp;
|
||||
result.valid = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
bool restrict_to_checkpoint_arc) {
|
||||
TrackRecoveryTarget tgt = compute_track_recovery_target(
|
||||
craft, level, all_crafts, restrict_to_checkpoint_arc);
|
||||
if (!tgt.valid) return false;
|
||||
finalize_craft_recovery_pose(craft, level, tgt.pos, tgt.yaw, tgt.waypoint_idx, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,20 @@ struct CraftState {
|
||||
float recovery_cooldown = 0.0f;
|
||||
float pit_stuck_timer = 0.0f;
|
||||
bool stuck_in_pit_hint = false;
|
||||
float recovery_start_yaw = 0.0f;
|
||||
float recovery_start_pitch = 0.0f;
|
||||
float recovery_start_roll = 0.0f;
|
||||
Vec3 recovery_target_pos{0.0f, 0.0f, 0.0f};
|
||||
float recovery_target_yaw = 0.0f;
|
||||
int recovery_target_wp = 0;
|
||||
float recovery_cruise_y = 0.0f;
|
||||
bool recovery_target_valid = false;
|
||||
CraftPose recovery_drone_prev_pose{};
|
||||
CraftPose recovery_drone_curr_pose{};
|
||||
float recovery_depart_timer = 0.0f;
|
||||
float recovery_depart_duration = 0.0f;
|
||||
Vec3 recovery_depart_start{0.0f, 0.0f, 0.0f};
|
||||
float recovery_depart_yaw = 0.0f;
|
||||
|
||||
// Race / Deathmatch progression
|
||||
int lap = 1;
|
||||
@@ -133,6 +147,13 @@ struct CraftStepFeedback {
|
||||
bool out_of_fuel = false;
|
||||
};
|
||||
|
||||
struct TrackRecoveryTarget {
|
||||
Vec3 pos{0.0f, 0.0f, 0.0f};
|
||||
float yaw = 0.0f;
|
||||
int waypoint_idx = 0;
|
||||
bool valid = false;
|
||||
};
|
||||
|
||||
// Pure deterministic 60 Hz hover physics step for one active craft
|
||||
CraftStepFeedback step_craft_physics(CraftState& craft, const CraftInput& input,
|
||||
const assets::LevelData& level, float dt,
|
||||
@@ -145,6 +166,22 @@ bool resolve_world_collisions(CraftState& craft, const assets::LevelData& level,
|
||||
// Resolves sphere-sphere bounce between two active crafts
|
||||
bool resolve_craft_pair_collision(CraftState& a, CraftState& b, float& out_rel_speed);
|
||||
|
||||
// Checks whether a recovery landing spot is drivable, unobstructed, and clear of nearby crafts
|
||||
bool is_track_recovery_spot_clear(const CraftState& craft, const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
float wx, float wz, float& out_y, bool check_crafts);
|
||||
|
||||
// Finds the nearest clear, drivable main track waypoint for recovery or drone airlift
|
||||
TrackRecoveryTarget compute_track_recovery_target(const CraftState& craft,
|
||||
const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
bool restrict_to_checkpoint_arc = true);
|
||||
|
||||
// Finalizes craft kinematics, collision projection, and AI/stuck timers at a recovery landing pose
|
||||
void finalize_craft_recovery_pose(CraftState& craft, const assets::LevelData& level,
|
||||
const Vec3& pos, float yaw, int waypoint_idx,
|
||||
bool snap_prev_pose = true);
|
||||
|
||||
// Safely places a craft on the nearest clear, drivable main track waypoint
|
||||
bool place_craft_on_track(CraftState& craft, const assets::LevelData& level,
|
||||
const std::vector<CraftState>& all_crafts,
|
||||
|
||||
+18
-3
@@ -543,6 +543,10 @@ bool RaceSim::request_track_recovery(int player_index) {
|
||||
}
|
||||
|
||||
void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
|
||||
if (c.recovery_state != RecoveryState::Active) {
|
||||
c.wrong_way = false;
|
||||
return;
|
||||
}
|
||||
if (level_.checkpoints.empty() || c.finished) return;
|
||||
int num_cps = static_cast<int>(level_.checkpoints.size());
|
||||
Vec2 p0(c.prev_pose.pos.x, c.prev_pose.pos.z);
|
||||
@@ -577,7 +581,7 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
|
||||
} else {
|
||||
c.current_lap_time = rem;
|
||||
++c.lap;
|
||||
if (c.lap == setup_.total_laps && c.is_human) {
|
||||
if (setup_.mode != GameMode::DeathMatch && c.lap == setup_.total_laps && c.is_human) {
|
||||
events_.push_back({SimSoundCue::None, c.curr_pose.pos, c.player_index, "FINAL LAP", 0.0f});
|
||||
}
|
||||
}
|
||||
@@ -598,7 +602,9 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
|
||||
}
|
||||
}
|
||||
c.current_wp = static_cast<int>(best_wp);
|
||||
if (c.speed_horizontal() > 3.0f) {
|
||||
if (setup_.mode == GameMode::DeathMatch) {
|
||||
c.wrong_way = false;
|
||||
} else if (c.speed_horizontal() > 3.0f) {
|
||||
const auto& w0 = level_.main_waypoints[best_wp];
|
||||
const auto& w1 = level_.main_waypoints[(best_wp + 1) % level_.main_waypoints.size()];
|
||||
Vec2 track_dir = Vec2(w1.x - w0.x, w1.z - w0.z).normalized();
|
||||
@@ -1016,12 +1022,21 @@ void RaceSim::resnap_entities_in_rects(const std::vector<DirtyRect>& rects) {
|
||||
for (auto& c : crafts_) {
|
||||
if (!touches_any(c.curr_pose.pos.x, c.curr_pose.pos.z, 1.5f)) continue;
|
||||
const float hover = kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)].hover_offset;
|
||||
if (c.recovery_state != RecoveryState::Active) {
|
||||
if (c.recovery_state == RecoveryState::CallingRepair ||
|
||||
c.recovery_state == RecoveryState::AwaitingRepair) {
|
||||
float sy = level_.sample_entity_surface_y(c.curr_pose.pos.x, c.curr_pose.pos.z);
|
||||
c.curr_pose.pos.y = sy + hover;
|
||||
c.recovery_pos.y = c.curr_pose.pos.y;
|
||||
continue;
|
||||
}
|
||||
if (c.recovery_state == RecoveryState::Repairing) {
|
||||
float sy = level_.sample_entity_surface_y(c.curr_pose.pos.x, c.curr_pose.pos.z);
|
||||
c.curr_pose.pos.y = std::max(c.curr_pose.pos.y, sy + hover);
|
||||
continue;
|
||||
}
|
||||
if (c.recovery_state != RecoveryState::Active) {
|
||||
continue;
|
||||
}
|
||||
float imp = 0.0f;
|
||||
bool scr = false;
|
||||
resolve_world_collisions(c, level_, imp, scr);
|
||||
|
||||
Reference in new issue
Block a user