Fix leaderboard opponent times and authentic pitstop recharging
This commit is contained in:
1 parent
b9353f552c
commit
3a377b0534
8 files changed
+592
-79
No files matched your search
+38
-1
@@ -33,6 +33,9 @@ constexpr size_t kLevelUnpackedSize = 896140;
|
|||||||
constexpr size_t kEntitiesOffset = 0x00000;
|
constexpr size_t kEntitiesOffset = 0x00000;
|
||||||
constexpr size_t kColumnsOffset = 0x17ED8; // 98008
|
constexpr size_t kColumnsOffset = 0x17ED8; // 98008
|
||||||
constexpr size_t kBlocksOffset = 0x1E6DC; // 124636
|
constexpr size_t kBlocksOffset = 0x1E6DC; // 124636
|
||||||
|
constexpr size_t kRegionsOffset = 0x27B2C; // 162604
|
||||||
|
constexpr size_t kRegionStride = 85;
|
||||||
|
constexpr int kMaxRegions = 1000;
|
||||||
constexpr size_t kMapOffset = 0x62C8C; // 404620
|
constexpr size_t kMapOffset = 0x62C8C; // 404620
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@@ -63,6 +66,7 @@ bool LevelData::load(const Vfs& vfs, int level_num) {
|
|||||||
morphs.clear();
|
morphs.clear();
|
||||||
effects.clear();
|
effects.clear();
|
||||||
pads.clear();
|
pads.clear();
|
||||||
|
recovery_spawns.clear();
|
||||||
checkpoints.clear();
|
checkpoints.clear();
|
||||||
|
|
||||||
std::unordered_map<uint16_t, LevelEntity> wp_map;
|
std::unordered_map<uint16_t, LevelEntity> wp_map;
|
||||||
@@ -101,7 +105,7 @@ bool LevelData::load(const Vfs& vfs, int level_num) {
|
|||||||
} else if (e.type == 9) {
|
} else if (e.type == 9) {
|
||||||
wp_map[e.id] = e;
|
wp_map[e.id] = e;
|
||||||
} else if (e.type == 10) {
|
} else if (e.type == 10) {
|
||||||
pads.push_back(e);
|
recovery_spawns.push_back(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +293,39 @@ bool LevelData::load(const Vfs& vfs, int level_num) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse authentic Bullfrog pitstop charger regions (1000 * 85 bytes at 0x27B2C)
|
||||||
|
for (int idx = 0; idx < kMaxRegions; ++idx) {
|
||||||
|
const uint8_t* p = data.data() + kRegionsOffset + static_cast<size_t>(idx) * kRegionStride;
|
||||||
|
uint8_t rtype = p[0];
|
||||||
|
if (rtype < 1 || rtype > 3) continue;
|
||||||
|
float cx = static_cast<float>(read_le16(p + 24)) / 256.0f;
|
||||||
|
float cz = static_cast<float>(read_le16(p + 26)) / 256.0f;
|
||||||
|
float hx = static_cast<float>(read_le16(p + 45)) / 256.0f;
|
||||||
|
float hz = static_cast<float>(read_le16(p + 47)) / 256.0f;
|
||||||
|
if (hx <= 0.0f || hz <= 0.0f) continue;
|
||||||
|
|
||||||
|
bool in_morph_src = false;
|
||||||
|
for (const auto& m : morphs) {
|
||||||
|
if (cx >= static_cast<float>(m.src_x) &&
|
||||||
|
cx <= static_cast<float>(m.src_x + m.size_x + 1) &&
|
||||||
|
cz >= static_cast<float>(m.src_z) &&
|
||||||
|
cz <= static_cast<float>(m.src_z + m.size_z + 1)) {
|
||||||
|
in_morph_src = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (in_morph_src) continue;
|
||||||
|
|
||||||
|
ChargerPad pad;
|
||||||
|
pad.region_id = static_cast<uint16_t>(idx);
|
||||||
|
pad.type = static_cast<ChargerType>(rtype);
|
||||||
|
pad.cx = cx;
|
||||||
|
pad.cz = cz;
|
||||||
|
pad.half_x = hx;
|
||||||
|
pad.half_z = hz;
|
||||||
|
pads.push_back(pad);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
-1
@@ -95,6 +95,21 @@ struct EffectEntity {
|
|||||||
float x = 0.0f, z = 0.0f;
|
float x = 0.0f, z = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ChargerType : uint8_t {
|
||||||
|
Shield = 1, // Green pitstop bay
|
||||||
|
Fuel = 2, // Blue pitstop bay
|
||||||
|
Ammo = 3, // Yellow pitstop bay
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ChargerPad {
|
||||||
|
uint16_t region_id = 0;
|
||||||
|
ChargerType type = ChargerType::Fuel;
|
||||||
|
float cx = 0.0f;
|
||||||
|
float cz = 0.0f;
|
||||||
|
float half_x = 0.0f;
|
||||||
|
float half_z = 0.0f;
|
||||||
|
};
|
||||||
|
|
||||||
struct LevelData {
|
struct LevelData {
|
||||||
int level_number = 1; // 1..6
|
int level_number = 1; // 1..6
|
||||||
int world_index = 0; // 0..5 (corresponding to TEXTU0-x / SKY0-x / TABLE0-x)
|
int world_index = 0; // 0..5 (corresponding to TEXTU0-x / SKY0-x / TABLE0-x)
|
||||||
@@ -113,7 +128,8 @@ struct LevelData {
|
|||||||
std::vector<LevelEntity> triggers; // type 8
|
std::vector<LevelEntity> triggers; // type 8
|
||||||
std::vector<MorphDefinition> morphs; // type 2 subtype 16/23 paired with subtype 9/7 source
|
std::vector<MorphDefinition> morphs; // type 2 subtype 16/23 paired with subtype 9/7 source
|
||||||
std::vector<EffectEntity> effects; // type 2 subtype 1/2/3/5/8
|
std::vector<EffectEntity> effects; // type 2 subtype 1/2/3/5/8
|
||||||
std::vector<LevelEntity> pads; // type 10
|
std::vector<ChargerPad> pads; // authentic charger regions (type 1=Shield, 2=Fuel, 3=Ammo)
|
||||||
|
std::vector<LevelEntity> recovery_spawns; // type 10 (ENTITY_RECOVERY_TRUCK)
|
||||||
|
|
||||||
int min_x = 0, max_x = kMapWidth - 1;
|
int min_x = 0, max_x = kMapWidth - 1;
|
||||||
int min_z = 0, max_z = kMapHeight - 1;
|
int min_z = 0, max_z = kMapHeight - 1;
|
||||||
|
|||||||
+86
-27
@@ -16,7 +16,7 @@ namespace {
|
|||||||
|
|
||||||
std::string format_time(float sec) {
|
std::string format_time(float sec) {
|
||||||
if (sec <= 0.0f) return "--:--.--";
|
if (sec <= 0.0f) return "--:--.--";
|
||||||
int total_cs = static_cast<int>(sec * 100.0f);
|
int total_cs = std::clamp(static_cast<int>(std::lround(sec * 100.0f)), 1, 599999);
|
||||||
int mins = total_cs / 6000;
|
int mins = total_cs / 6000;
|
||||||
int secs = (total_cs / 100) % 60;
|
int secs = (total_cs / 100) % 60;
|
||||||
int cs = total_cs % 100;
|
int cs = total_cs % 100;
|
||||||
@@ -518,7 +518,12 @@ void GameApp::update_racing_step(float dt) {
|
|||||||
post_race_record_flags_ = hiscores_.submit_race(selected_track_, race_sim_.crafts());
|
post_race_record_flags_ = hiscores_.submit_race(selected_track_, race_sim_.crafts());
|
||||||
if (selected_mode_ == sim::GameMode::CloneRace && !race_sim_.crafts().empty() &&
|
if (selected_mode_ == sim::GameMode::CloneRace && !race_sim_.crafts().empty() &&
|
||||||
race_sim_.crafts()[0].finished) {
|
race_sim_.crafts()[0].finished) {
|
||||||
save_clone_recording(vfs_.pref_dir(), race_sim_.current_recording());
|
bool beat_clone = !race_sim_.has_clone_ghost() ||
|
||||||
|
race_sim_.playback_clone().best_race_time >= 1e8f ||
|
||||||
|
race_sim_.crafts()[0].race_time <= race_sim_.playback_clone().best_race_time;
|
||||||
|
if (beat_clone) {
|
||||||
|
save_clone_recording(vfs_.pref_dir(), race_sim_.current_recording());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (selected_mode_ == sim::GameMode::Championship) {
|
if (selected_mode_ == sim::GameMode::Championship) {
|
||||||
champ_.record_race_results(race_sim_.crafts());
|
champ_.record_race_results(race_sim_.crafts());
|
||||||
@@ -1298,18 +1303,29 @@ void GameApp::render_hud_viewport(const sim::CraftState& craft, const render::Re
|
|||||||
ui_ren_.draw_rect(pad, hud_y, hud_w, hud_h, Vec4(0.02f, 0.04f, 0.1f, 0.72f));
|
ui_ren_.draw_rect(pad, hud_y, hud_w, hud_h, Vec4(0.02f, 0.04f, 0.1f, 0.72f));
|
||||||
ui_ren_.draw_rect_outline(pad, hud_y, hud_w, hud_h, 2.0f, Vec4(0.25f, 0.65f, 1.0f, 0.8f));
|
ui_ren_.draw_rect_outline(pad, hud_y, hud_w, hud_h, 2.0f, Vec4(0.25f, 0.65f, 1.0f, 0.8f));
|
||||||
|
|
||||||
auto draw_bar = [&](float bx, float by, const char* lbl, float val, float maxv, const Vec4& col) {
|
auto draw_bar = [&](float bx, float by, const char* lbl, float val, float maxv, const Vec4& col,
|
||||||
ui_ren_.draw_text_fit(bx, by, 72.0f * s, 1.45f * s, lbl, Vec4(0.85f, 0.9f, 1.0f, 1));
|
bool charging) {
|
||||||
|
Vec4 lbl_col = charging
|
||||||
|
? ((static_cast<int>(craft.race_time * 10.0f) & 1) ? Vec4(1.0f, 1.0f, 1.0f, 1.0f)
|
||||||
|
: Vec4(0.45f, 1.0f, 0.55f, 1.0f))
|
||||||
|
: Vec4(0.85f, 0.9f, 1.0f, 1);
|
||||||
|
ui_ren_.draw_text_fit(bx, by, 72.0f * s, 1.45f * s, lbl, lbl_col);
|
||||||
float bar_x = bx + 78.0f * s;
|
float bar_x = bx + 78.0f * s;
|
||||||
float bar_w = 215.0f * s;
|
float bar_w = 215.0f * s;
|
||||||
float bar_h = 12.0f * s;
|
float bar_h = 12.0f * s;
|
||||||
ui_ren_.draw_rect(bar_x, by, bar_w, bar_h, Vec4(0.12f, 0.12f, 0.18f, 0.9f));
|
ui_ren_.draw_rect(bar_x, by, bar_w, bar_h, Vec4(0.12f, 0.12f, 0.18f, 0.9f));
|
||||||
|
if (charging) {
|
||||||
|
ui_ren_.draw_rect_outline(bar_x, by, bar_w, bar_h, 1.0f, Vec4(0.45f, 1.0f, 0.55f, 0.9f));
|
||||||
|
}
|
||||||
float frac = std::clamp(val / std::max(maxv, 1.0f), 0.0f, 1.0f);
|
float frac = std::clamp(val / std::max(maxv, 1.0f), 0.0f, 1.0f);
|
||||||
ui_ren_.draw_rect(bar_x + 1, by + 1, (bar_w - 2) * frac, bar_h - 2, col);
|
ui_ren_.draw_rect(bar_x + 1, by + 1, (bar_w - 2) * frac, bar_h - 2, col);
|
||||||
};
|
};
|
||||||
draw_bar(pad + 10.0f * s, hud_y + 10.0f * s, "SHLD", craft.shield, craft.max_shield, Vec4(0.2f, 0.75f, 1.0f, 1));
|
draw_bar(pad + 10.0f * s, hud_y + 10.0f * s, "SHLD", craft.shield, craft.max_shield,
|
||||||
draw_bar(pad + 10.0f * s, hud_y + 30.0f * s, "FUEL", craft.fuel, craft.max_fuel, Vec4(1.0f, 0.65f, 0.15f, 1));
|
Vec4(0.2f, 0.75f, 1.0f, 1), (craft.active_recharge_mask & 1u) != 0);
|
||||||
draw_bar(pad + 10.0f * s, hud_y + 50.0f * s, "AMMO", craft.ammo, craft.max_ammo, Vec4(0.95f, 0.9f, 0.25f, 1));
|
draw_bar(pad + 10.0f * s, hud_y + 30.0f * s, "FUEL", craft.fuel, craft.max_fuel,
|
||||||
|
Vec4(1.0f, 0.65f, 0.15f, 1), (craft.active_recharge_mask & 2u) != 0);
|
||||||
|
draw_bar(pad + 10.0f * s, hud_y + 50.0f * s, "AMMO", craft.ammo, craft.max_ammo,
|
||||||
|
Vec4(0.95f, 0.9f, 0.25f, 1), (craft.active_recharge_mask & 4u) != 0);
|
||||||
|
|
||||||
int kmh = static_cast<int>(craft.speed_horizontal() * 14.5f);
|
int kmh = static_cast<int>(craft.speed_horizontal() * 14.5f);
|
||||||
char spd_buf[64];
|
char spd_buf[64];
|
||||||
@@ -1776,25 +1792,68 @@ void GameApp::render_menus() {
|
|||||||
float c0 = cx - tbl_w * 0.5f;
|
float c0 = cx - tbl_w * 0.5f;
|
||||||
float c1 = c0 + tbl_w * 0.09f;
|
float c1 = c0 + tbl_w * 0.09f;
|
||||||
float c2 = c0 + tbl_w * 0.31f;
|
float c2 = c0 + tbl_w * 0.31f;
|
||||||
float c3 = c0 + tbl_w * 0.55f;
|
if (selected_mode_ == sim::GameMode::DeathMatch) {
|
||||||
float c4 = c0 + tbl_w * 0.73f;
|
float c3 = c0 + tbl_w * 0.55f;
|
||||||
float c5 = c0 + tbl_w * 0.91f;
|
float c4 = c0 + tbl_w * 0.74f;
|
||||||
ui_ren_.draw_text_fit(c0, 162.0f, tbl_w * 0.08f, 1.65f, str.position, Vec4(0.4f, 0.85f, 1, 1));
|
float c5 = c0 + tbl_w * 0.87f;
|
||||||
ui_ren_.draw_text_fit(c1, 162.0f, tbl_w * 0.21f, 1.65f, str.driver, Vec4(0.4f, 0.85f, 1, 1));
|
ui_ren_.draw_text_fit(c0, 162.0f, tbl_w * 0.08f, 1.65f, str.position, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
ui_ren_.draw_text_fit(c2, 162.0f, tbl_w * 0.23f, 1.65f, "TEAM", Vec4(0.4f, 0.85f, 1, 1));
|
ui_ren_.draw_text_fit(c1, 162.0f, tbl_w * 0.21f, 1.65f, str.driver, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
ui_ren_.draw_text_fit(c3, 162.0f, tbl_w * 0.17f, 1.65f, str.time_hdr, Vec4(0.4f, 0.85f, 1, 1));
|
ui_ren_.draw_text_fit(c2, 162.0f, tbl_w * 0.23f, 1.65f, "TEAM", Vec4(0.4f, 0.85f, 1, 1));
|
||||||
ui_ren_.draw_text_fit(c4, 162.0f, tbl_w * 0.17f, 1.65f, str.best_lap, Vec4(0.4f, 0.85f, 1, 1));
|
ui_ren_.draw_text_fit(c3, 162.0f, tbl_w * 0.18f, 1.65f, str.best_lap, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
ui_ren_.draw_text_fit(c5, 162.0f, tbl_w * 0.09f, 1.65f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
|
ui_ren_.draw_text_fit(c4, 162.0f, tbl_w * 0.12f, 1.65f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
|
||||||
for (size_t i = 0; i < sorted.size(); ++i) {
|
ui_ren_.draw_text_fit(c5, 162.0f, tbl_w * 0.13f, 1.65f, "DEATHS", Vec4(0.4f, 0.85f, 1, 1));
|
||||||
const auto& c = sorted[i];
|
for (size_t i = 0; i < sorted.size(); ++i) {
|
||||||
float ry = 198.0f + static_cast<float>(i) * 32.0f;
|
const auto& c = sorted[i];
|
||||||
Vec4 col = c.is_human ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.85f, 0.9f, 1, 1);
|
float ry = 198.0f + static_cast<float>(i) * 32.0f;
|
||||||
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.08f, 1.65f, std::to_string(c.placement) + ".", col);
|
Vec4 col = c.is_human ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.85f, 0.9f, 1, 1);
|
||||||
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.21f, 1.65f, c.pilot_name, col);
|
int tidx = std::clamp(c.team_idx, 0, 7);
|
||||||
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.23f, 1.65f, sim::kTeamNames[c.team_idx], col);
|
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.08f, 1.65f, std::to_string(c.placement) + ".", col);
|
||||||
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.17f, 1.65f, format_time(c.race_time), col);
|
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.21f, 1.65f, c.pilot_name, col);
|
||||||
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.17f, 1.65f, format_time(c.best_lap_time), col);
|
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.23f, 1.65f, sim::kTeamNames[tidx], col);
|
||||||
ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.09f, 1.65f, std::to_string(c.kills), col);
|
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.18f, 1.65f, format_time(c.best_lap_time), col);
|
||||||
|
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.12f, 1.65f, std::to_string(c.kills), col);
|
||||||
|
ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.13f, 1.65f, std::to_string(c.deaths), col);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (selected_mode_ == sim::GameMode::CloneRace && race_sim_.has_clone_ghost() &&
|
||||||
|
race_sim_.playback_clone().best_race_time < 1e8f) {
|
||||||
|
sim::CraftState ghost;
|
||||||
|
ghost.is_human = false;
|
||||||
|
ghost.pilot_name = "CLONE GHOST";
|
||||||
|
ghost.team_idx = std::clamp(race_sim_.playback_clone().team_idx, 0, 7);
|
||||||
|
ghost.race_time = race_sim_.playback_clone().best_race_time;
|
||||||
|
ghost.best_lap_time = (race_sim_.setup().total_laps <= 1) ? ghost.race_time : 0.0f;
|
||||||
|
ghost.kills = 0;
|
||||||
|
ghost.finished = true;
|
||||||
|
sorted.push_back(std::move(ghost));
|
||||||
|
std::sort(sorted.begin(), sorted.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.race_time < b.race_time;
|
||||||
|
});
|
||||||
|
for (size_t i = 0; i < sorted.size(); ++i) {
|
||||||
|
sorted[i].placement = static_cast<int>(i + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float c3 = c0 + tbl_w * 0.55f;
|
||||||
|
float c4 = c0 + tbl_w * 0.73f;
|
||||||
|
float c5 = c0 + tbl_w * 0.91f;
|
||||||
|
ui_ren_.draw_text_fit(c0, 162.0f, tbl_w * 0.08f, 1.65f, str.position, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
|
ui_ren_.draw_text_fit(c1, 162.0f, tbl_w * 0.21f, 1.65f, str.driver, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
|
ui_ren_.draw_text_fit(c2, 162.0f, tbl_w * 0.23f, 1.65f, "TEAM", Vec4(0.4f, 0.85f, 1, 1));
|
||||||
|
ui_ren_.draw_text_fit(c3, 162.0f, tbl_w * 0.17f, 1.65f, str.time_hdr, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
|
ui_ren_.draw_text_fit(c4, 162.0f, tbl_w * 0.17f, 1.65f, str.best_lap, Vec4(0.4f, 0.85f, 1, 1));
|
||||||
|
ui_ren_.draw_text_fit(c5, 162.0f, tbl_w * 0.09f, 1.65f, "KILLS", Vec4(0.4f, 0.85f, 1, 1));
|
||||||
|
for (size_t i = 0; i < sorted.size(); ++i) {
|
||||||
|
const auto& c = sorted[i];
|
||||||
|
float ry = 198.0f + static_cast<float>(i) * 32.0f;
|
||||||
|
Vec4 col = c.is_human ? Vec4(1, 0.95f, 0.25f, 1) : Vec4(0.85f, 0.9f, 1, 1);
|
||||||
|
int tidx = std::clamp(c.team_idx, 0, 7);
|
||||||
|
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.08f, 1.65f, std::to_string(c.placement) + ".", col);
|
||||||
|
ui_ren_.draw_text_fit(c1, ry, tbl_w * 0.21f, 1.65f, c.pilot_name, col);
|
||||||
|
ui_ren_.draw_text_fit(c2, ry, tbl_w * 0.23f, 1.65f, sim::kTeamNames[tidx], col);
|
||||||
|
ui_ren_.draw_text_fit(c3, ry, tbl_w * 0.17f, 1.65f, format_time(c.race_time), col);
|
||||||
|
ui_ren_.draw_text_fit(c4, ry, tbl_w * 0.17f, 1.65f, format_time(c.best_lap_time), col);
|
||||||
|
ui_ren_.draw_text_fit(c5, ry, tbl_w * 0.09f, 1.65f, std::to_string(c.kills), col);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (post_race_page_ == 1 && !race_sim_.crafts().empty()) {
|
} else if (post_race_page_ == 1 && !race_sim_.crafts().empty()) {
|
||||||
const auto& p1 = race_sim_.crafts()[0];
|
const auto& p1 = race_sim_.crafts()[0];
|
||||||
@@ -1819,7 +1878,7 @@ void GameApp::render_menus() {
|
|||||||
float c4 = c0 + tbl_w * 0.84f;
|
float c4 = c0 + tbl_w * 0.84f;
|
||||||
for (size_t i = 0; i < ds.size(); ++i) {
|
for (size_t i = 0; i < ds.size(); ++i) {
|
||||||
float ry = 210.0f + static_cast<float>(i) * 32.0f;
|
float ry = 210.0f + static_cast<float>(i) * 32.0f;
|
||||||
Vec4 col = (i == 0 && ds[i].name == cfg_.player_name)
|
Vec4 col = (ds[i].name == cfg_.player_name)
|
||||||
? Vec4(1, 0.95f, 0.25f, 1)
|
? Vec4(1, 0.95f, 0.25f, 1)
|
||||||
: Vec4(0.9f, 0.95f, 1, 1);
|
: Vec4(0.9f, 0.95f, 1, 1);
|
||||||
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.09f, 1.7f, std::to_string(i + 1) + ".", col);
|
ui_ren_.draw_text_fit(c0, ry, tbl_w * 0.09f, 1.7f, std::to_string(i + 1) + ".", col);
|
||||||
|
|||||||
+14
-7
@@ -22,20 +22,27 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
|
|||||||
wp_idx = ai.ai_target_wp;
|
wp_idx = ai.ai_target_wp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decide whether to detour briefly over a nearby recharge pad when low on fuel or shield
|
// Decide whether to detour briefly over a nearby recharge pad matching a depleted resource
|
||||||
Vec2 tgt_pos(level.main_waypoints[wp_idx].x, level.main_waypoints[wp_idx].z);
|
Vec2 tgt_pos(level.main_waypoints[wp_idx].x, level.main_waypoints[wp_idx].z);
|
||||||
if ((ai.fuel < ai.max_fuel * 0.25f || ai.shield < ai.max_shield * 0.28f) && !level.pads.empty()) {
|
const bool need_fuel = (ai.fuel < ai.max_fuel * 0.25f);
|
||||||
|
const bool need_shield = (ai.shield < ai.max_shield * 0.28f);
|
||||||
|
const bool need_ammo = (ai.ammo < ai.max_ammo * 0.15f);
|
||||||
|
ai.ai_seeking_pit = false;
|
||||||
|
if ((need_fuel || need_shield || need_ammo) && !level.pads.empty()) {
|
||||||
|
float best_d2 = 16.0f * 16.0f;
|
||||||
for (const auto& pad : level.pads) {
|
for (const auto& pad : level.pads) {
|
||||||
Vec2 p(pad.tile_x() + 0.5f, pad.tile_z() + 0.5f);
|
bool match = (pad.type == assets::ChargerType::Fuel && need_fuel) ||
|
||||||
|
(pad.type == assets::ChargerType::Shield && need_shield) ||
|
||||||
|
(pad.type == assets::ChargerType::Ammo && need_ammo);
|
||||||
|
if (!match) continue;
|
||||||
|
Vec2 p(pad.cx, pad.cz);
|
||||||
float d2 = (p - Vec2(ai.curr_pose.pos.x, ai.curr_pose.pos.z)).len_sq();
|
float d2 = (p - Vec2(ai.curr_pose.pos.x, ai.curr_pose.pos.z)).len_sq();
|
||||||
if (d2 < 14.0f * 14.0f) {
|
if (d2 < best_d2) {
|
||||||
|
best_d2 = d2;
|
||||||
tgt_pos = p;
|
tgt_pos = p;
|
||||||
ai.ai_seeking_pit = true;
|
ai.ai_seeking_pit = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ai.ai_seeking_pit = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto is_ai_blocked = [&](float wx, float wz) -> bool {
|
auto is_ai_blocked = [&](float wx, float wz) -> bool {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ struct CraftState {
|
|||||||
float lock_progress = 0.0f;
|
float lock_progress = 0.0f;
|
||||||
float scrape_intensity = 0.0f;
|
float scrape_intensity = 0.0f;
|
||||||
float refuel_sound_cd = 0.0f;
|
float refuel_sound_cd = 0.0f;
|
||||||
|
uint8_t active_recharge_mask = 0; // bit0=Shield, bit1=Fuel, bit2=Ammo
|
||||||
bool autopilot = false;
|
bool autopilot = false;
|
||||||
|
|
||||||
// Recovery / repair
|
// Recovery / repair
|
||||||
|
|||||||
+154
-42
@@ -10,7 +10,8 @@ namespace top_octane::sim {
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool segments_intersect_or_near(Vec2 p0, Vec2 p1, Vec2 g0, Vec2 g1, float margin = 2.5f) {
|
bool segments_intersect_or_near(Vec2 p0, Vec2 p1, Vec2 g0, Vec2 g1, float margin = 2.5f,
|
||||||
|
float* out_frac = nullptr) {
|
||||||
// Check if craft crossed near checkpoint gate line (segment g0..g1 or center proximity)
|
// Check if craft crossed near checkpoint gate line (segment g0..g1 or center proximity)
|
||||||
Vec2 mid = (g0 + g1) * 0.5f;
|
Vec2 mid = (g0 + g1) * 0.5f;
|
||||||
float gate_half = std::max((g1 - g0).len() * 0.5f, 3.0f) + margin;
|
float gate_half = std::max((g1 - g0).len() * 0.5f, 3.0f) + margin;
|
||||||
@@ -19,14 +20,24 @@ bool segments_intersect_or_near(Vec2 p0, Vec2 p1, Vec2 g0, Vec2 g1, float margin
|
|||||||
}
|
}
|
||||||
Vec2 seg = g1 - g0;
|
Vec2 seg = g1 - g0;
|
||||||
if (seg.len_sq() < 0.25f) {
|
if (seg.len_sq() < 0.25f) {
|
||||||
return (p1 - mid).len() <= 3.5f;
|
if ((p1 - mid).len() <= 3.5f) {
|
||||||
|
if (out_frac) *out_frac = 1.0f;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
Vec2 n(-seg.y, seg.x);
|
Vec2 n(-seg.y, seg.x);
|
||||||
float d0 = (p0 - g0).dot(n);
|
float d0 = (p0 - g0).dot(n);
|
||||||
float d1 = (p1 - g0).dot(n);
|
float d1 = (p1 - g0).dot(n);
|
||||||
if ((d0 <= 0.0f && d1 >= 0.0f) || (d0 >= 0.0f && d1 <= 0.0f)) {
|
if ((d0 <= 0.0f && d1 >= 0.0f) || (d0 >= 0.0f && d1 <= 0.0f)) {
|
||||||
float t = (p1 - g0).dot(seg) / seg.len_sq();
|
float denom = std::abs(d1 - d0);
|
||||||
return t >= -0.35f && t <= 1.35f;
|
float frac = (denom > 1e-5f) ? std::clamp(std::abs(d0) / denom, 0.0f, 1.0f) : 1.0f;
|
||||||
|
Vec2 p_cross = p0 + (p1 - p0) * frac;
|
||||||
|
float t = (p_cross - g0).dot(seg) / seg.len_sq();
|
||||||
|
if (t >= -0.35f && t <= 1.35f) {
|
||||||
|
if (out_frac) *out_frac = frac;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -71,6 +82,7 @@ bool RaceSim::start_race(const assets::LevelData& level, const RaceSetup& setup,
|
|||||||
last_countdown_int_ = 4;
|
last_countdown_int_ = 4;
|
||||||
elapsed_time_ = 0.0f;
|
elapsed_time_ = 0.0f;
|
||||||
race_over_ = false;
|
race_over_ = false;
|
||||||
|
times_finalized_ = false;
|
||||||
winner_id_ = -1;
|
winner_id_ = -1;
|
||||||
|
|
||||||
// Populate pickups (type 5) & props (type 3)
|
// Populate pickups (type 5) & props (type 3)
|
||||||
@@ -290,6 +302,8 @@ void RaceSim::compute_start_grid(int count, std::vector<CraftPose>& out_poses) c
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float dt) {
|
void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float dt) {
|
||||||
|
if (race_over_) return;
|
||||||
|
|
||||||
// Countdown handling
|
// Countdown handling
|
||||||
if (countdown_timer_ > 0.0f) {
|
if (countdown_timer_ > 0.0f) {
|
||||||
countdown_timer_ = std::max(0.0f, countdown_timer_ - dt);
|
countdown_timer_ = std::max(0.0f, countdown_timer_ - dt);
|
||||||
@@ -365,7 +379,7 @@ void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float
|
|||||||
c.race_time += dt;
|
c.race_time += dt;
|
||||||
c.current_lap_time += dt;
|
c.current_lap_time += dt;
|
||||||
}
|
}
|
||||||
update_checkpoints_and_laps(c);
|
update_checkpoints_and_laps(c, dt);
|
||||||
update_recharge_pads(c, dt);
|
update_recharge_pads(c, dt);
|
||||||
update_triggers(c);
|
update_triggers(c);
|
||||||
}
|
}
|
||||||
@@ -397,8 +411,10 @@ void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Record P1 ghost frames (cap at 5 minutes = 18000 frames)
|
// Record P1 ghost frames (cap at 5 minutes = 18000 frames)
|
||||||
if (!crafts_.empty() && recording_.frames.size() < 18000) {
|
if (!crafts_.empty()) {
|
||||||
recording_.frames.push_back(crafts_[0].curr_pose);
|
if (recording_.frames.size() < 18000) {
|
||||||
|
recording_.frames.push_back(crafts_[0].curr_pose);
|
||||||
|
}
|
||||||
if (crafts_[0].finished && recording_.best_race_time > crafts_[0].race_time) {
|
if (crafts_[0].finished && recording_.best_race_time > crafts_[0].race_time) {
|
||||||
recording_.best_race_time = crafts_[0].race_time;
|
recording_.best_race_time = crafts_[0].race_time;
|
||||||
}
|
}
|
||||||
@@ -411,7 +427,7 @@ void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float
|
|||||||
update_particles(dt);
|
update_particles(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RaceSim::update_checkpoints_and_laps(CraftState& c) {
|
void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
|
||||||
if (level_.checkpoints.empty() || c.finished) return;
|
if (level_.checkpoints.empty() || c.finished) return;
|
||||||
int num_cps = static_cast<int>(level_.checkpoints.size());
|
int num_cps = static_cast<int>(level_.checkpoints.size());
|
||||||
Vec2 p0(c.prev_pose.pos.x, c.prev_pose.pos.z);
|
Vec2 p0(c.prev_pose.pos.x, c.prev_pose.pos.z);
|
||||||
@@ -419,23 +435,28 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c) {
|
|||||||
|
|
||||||
int expected = c.next_checkpoint % num_cps;
|
int expected = c.next_checkpoint % num_cps;
|
||||||
const auto& gate = level_.checkpoints[expected];
|
const auto& gate = level_.checkpoints[expected];
|
||||||
if (segments_intersect_or_near(p0, p1, Vec2(gate.x0, gate.z0), Vec2(gate.x1, gate.z1))) {
|
float cross_frac = 1.0f;
|
||||||
|
if (segments_intersect_or_near(p0, p1, Vec2(gate.x0, gate.z0), Vec2(gate.x1, gate.z1),
|
||||||
|
2.5f, &cross_frac)) {
|
||||||
++c.checkpoints_passed;
|
++c.checkpoints_passed;
|
||||||
c.next_checkpoint = (expected + 1) % num_cps;
|
c.next_checkpoint = (expected + 1) % num_cps;
|
||||||
c.wrong_way = false;
|
c.wrong_way = false;
|
||||||
|
|
||||||
if (expected == 0) {
|
if (expected == 0) {
|
||||||
if (c.best_lap_time <= 0.0f || c.current_lap_time < c.best_lap_time) {
|
float rem = (1.0f - cross_frac) * dt;
|
||||||
c.best_lap_time = c.current_lap_time;
|
float lap_time = std::max(0.01f, c.current_lap_time - rem);
|
||||||
|
if (c.best_lap_time <= 0.0f || lap_time < c.best_lap_time) {
|
||||||
|
c.best_lap_time = lap_time;
|
||||||
}
|
}
|
||||||
c.current_lap_time = 0.0f;
|
|
||||||
if (c.lap >= setup_.total_laps && setup_.mode != GameMode::DeathMatch) {
|
if (c.lap >= setup_.total_laps && setup_.mode != GameMode::DeathMatch) {
|
||||||
|
c.race_time = std::max(0.01f, c.race_time - rem);
|
||||||
|
c.current_lap_time = 0.0f;
|
||||||
c.finished = true;
|
c.finished = true;
|
||||||
if (winner_id_ < 0) {
|
if (winner_id_ < 0) {
|
||||||
winner_id_ = c.id;
|
winner_id_ = c.id;
|
||||||
if (c.is_human) race_over_ = true;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
c.current_lap_time = rem;
|
||||||
++c.lap;
|
++c.lap;
|
||||||
if (c.lap == setup_.total_laps && c.is_human) {
|
if (c.lap == setup_.total_laps && c.is_human) {
|
||||||
events_.push_back({SimSoundCue::None, c.curr_pose.pos, c.player_index, "FINAL LAP", 0.0f});
|
events_.push_back({SimSoundCue::None, c.curr_pose.pos, c.player_index, "FINAL LAP", 0.0f});
|
||||||
@@ -467,33 +488,44 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RaceSim::update_recharge_pads(CraftState& c, float dt) {
|
void RaceSim::update_recharge_pads(CraftState& c, float dt) {
|
||||||
|
c.active_recharge_mask = 0;
|
||||||
if (c.recovery_state != RecoveryState::Active) return;
|
if (c.recovery_state != RecoveryState::Active) return;
|
||||||
for (size_t i = 0; i < level_.pads.size(); ++i) {
|
|
||||||
const auto& pad = level_.pads[i];
|
const float px = c.curr_pose.pos.x;
|
||||||
float dx = c.curr_pose.pos.x - (pad.tile_x() + 0.5f);
|
const float pz = c.curr_pose.pos.z;
|
||||||
float dz = c.curr_pose.pos.z - (pad.tile_z() + 0.5f);
|
const float ground_y = level_.sample_height_world(px, pz);
|
||||||
if (dx * dx + dz * dz < 6.25f) {
|
if (c.curr_pose.pos.y > ground_y + 1.5f) return;
|
||||||
// Recharge fuel, shield & ammo smoothly over track pads
|
|
||||||
bool recharged = false;
|
bool in_shield = false;
|
||||||
if (c.fuel < c.max_fuel) {
|
bool in_fuel = false;
|
||||||
c.fuel = std::min(c.max_fuel, c.fuel + 38.0f * dt);
|
bool in_ammo = false;
|
||||||
recharged = true;
|
for (const auto& pad : level_.pads) {
|
||||||
|
if (std::abs(px - pad.cx) <= pad.half_x && std::abs(pz - pad.cz) <= pad.half_z) {
|
||||||
|
switch (pad.type) {
|
||||||
|
case assets::ChargerType::Shield: in_shield = true; break;
|
||||||
|
case assets::ChargerType::Fuel: in_fuel = true; break;
|
||||||
|
case assets::ChargerType::Ammo: in_ammo = true; break;
|
||||||
}
|
}
|
||||||
if (c.shield < c.max_shield) {
|
|
||||||
c.shield = std::min(c.max_shield, c.shield + 32.0f * dt);
|
|
||||||
recharged = true;
|
|
||||||
}
|
|
||||||
if (c.ammo < c.max_ammo) {
|
|
||||||
c.ammo = std::min(c.max_ammo, c.ammo + 35.0f * dt);
|
|
||||||
recharged = true;
|
|
||||||
}
|
|
||||||
if (recharged && c.is_human && c.refuel_sound_cd <= 0.0f) {
|
|
||||||
c.refuel_sound_cd = 0.45f;
|
|
||||||
events_.push_back({SimSoundCue::Refuel, c.curr_pose.pos, c.player_index, "", 0.0f});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_shield && c.shield < c.max_shield) {
|
||||||
|
c.shield = std::min(c.max_shield, c.shield + c.max_shield * 0.50f * dt);
|
||||||
|
c.active_recharge_mask |= 1u;
|
||||||
|
}
|
||||||
|
if (in_fuel && c.fuel < c.max_fuel) {
|
||||||
|
c.fuel = std::min(c.max_fuel, c.fuel + c.max_fuel * 0.55f * dt);
|
||||||
|
c.active_recharge_mask |= 2u;
|
||||||
|
}
|
||||||
|
if (in_ammo && c.ammo < c.max_ammo) {
|
||||||
|
c.ammo = std::min(c.max_ammo, c.ammo + c.max_ammo * 0.55f * dt);
|
||||||
|
c.active_recharge_mask |= 4u;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c.active_recharge_mask != 0 && c.is_human && c.refuel_sound_cd <= 0.0f) {
|
||||||
|
c.refuel_sound_cd = 0.38f;
|
||||||
|
events_.push_back({SimSoundCue::Refuel, c.curr_pose.pos, c.player_index, "", 0.0f});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RaceSim::push_dirty_rect(int x0, int z0, int x1, int z1) {
|
void RaceSim::push_dirty_rect(int x0, int z0, int x1, int z1) {
|
||||||
@@ -924,13 +956,93 @@ void RaceSim::update_standings() {
|
|||||||
crafts_[order[rank]].placement = static_cast<int>(rank + 1);
|
crafts_[order[rank]].placement = static_cast<int>(rank + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In 1P modes, end race when all human players finish
|
// End non-DeathMatch races only when all human players have finished
|
||||||
bool all_humans_done = true;
|
if (setup_.mode != GameMode::DeathMatch) {
|
||||||
for (const auto& c : crafts_) {
|
bool has_human = false;
|
||||||
if (c.is_human && !c.finished) all_humans_done = false;
|
bool all_humans_done = true;
|
||||||
|
for (const auto& c : crafts_) {
|
||||||
|
if (c.is_human) {
|
||||||
|
has_human = true;
|
||||||
|
if (!c.finished) all_humans_done = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (has_human && all_humans_done) {
|
||||||
|
race_over_ = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (all_humans_done && !crafts_.empty()) {
|
if (race_over_ && !times_finalized_ && setup_.mode != GameMode::DeathMatch) {
|
||||||
race_over_ = true;
|
finalize_unfinished_times(order);
|
||||||
|
times_finalized_ = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RaceSim::finalize_unfinished_times(const std::vector<size_t>& order) {
|
||||||
|
if (order.empty()) return;
|
||||||
|
|
||||||
|
const int total_laps = std::max(setup_.total_laps, 1);
|
||||||
|
std::vector<float> cp_seg_len;
|
||||||
|
float lap_dist = 0.0f;
|
||||||
|
float total_race_dist = 0.0f;
|
||||||
|
float winner_speed = 1.0f;
|
||||||
|
|
||||||
|
if (!level_.checkpoints.empty()) {
|
||||||
|
const size_t num_cps = level_.checkpoints.size();
|
||||||
|
cp_seg_len.resize(num_cps);
|
||||||
|
for (size_t k = 0; k < num_cps; ++k) {
|
||||||
|
const auto& g_cur = level_.checkpoints[k];
|
||||||
|
const auto& g_next = level_.checkpoints[(k + 1) % num_cps];
|
||||||
|
cp_seg_len[k] = std::max(Vec2(g_next.cx - g_cur.cx, g_next.cz - g_cur.cz).len(), 1.0f);
|
||||||
|
lap_dist += cp_seg_len[k];
|
||||||
|
}
|
||||||
|
total_race_dist = lap_dist * static_cast<float>(total_laps);
|
||||||
|
const auto& leader = crafts_[order[0]];
|
||||||
|
float ref_time = std::max(leader.finished ? leader.race_time : elapsed_time_, 1.0f);
|
||||||
|
winner_speed = total_race_dist / ref_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
float prev_time = 0.0f;
|
||||||
|
for (size_t rank = 0; rank < order.size(); ++rank) {
|
||||||
|
CraftState& c = crafts_[order[rank]];
|
||||||
|
if (c.finished) {
|
||||||
|
prev_time = std::max(prev_time, c.race_time);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!level_.checkpoints.empty()) {
|
||||||
|
const int num_cps = static_cast<int>(level_.checkpoints.size());
|
||||||
|
const int total_cps = total_laps * num_cps;
|
||||||
|
const int cp_done = std::clamp(c.checkpoints_passed, 0, std::max(total_cps - 1, 0));
|
||||||
|
|
||||||
|
const int full_laps = cp_done / num_cps;
|
||||||
|
const int rem_cps = cp_done % num_cps;
|
||||||
|
float completed_full = static_cast<float>(full_laps) * lap_dist;
|
||||||
|
for (int j = 0; j < rem_cps; ++j) {
|
||||||
|
completed_full += cp_seg_len[static_cast<size_t>(j)];
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t seg_idx = static_cast<size_t>(rem_cps);
|
||||||
|
const auto& g_next = level_.checkpoints[(seg_idx + 1) % level_.checkpoints.size()];
|
||||||
|
float cur_seg = cp_seg_len[seg_idx];
|
||||||
|
float dist_to_next = Vec2(g_next.cx - c.curr_pose.pos.x, g_next.cz - c.curr_pose.pos.z).len();
|
||||||
|
float cur_prog = std::clamp(cur_seg - dist_to_next, 0.0f, cur_seg * 0.98f);
|
||||||
|
float covered_dist = completed_full + cur_prog;
|
||||||
|
float remaining_dist = std::max(0.5f, total_race_dist - covered_dist);
|
||||||
|
|
||||||
|
float avg_speed = covered_dist / std::max(elapsed_time_, 0.5f);
|
||||||
|
float est_speed = std::clamp(avg_speed, std::max(winner_speed * 0.35f, 0.5f),
|
||||||
|
std::max(winner_speed * 1.05f, 1.0f));
|
||||||
|
float est_time = c.race_time + remaining_dist / est_speed;
|
||||||
|
est_time = std::max(est_time, std::max(elapsed_time_ + 0.05f, prev_time + 0.05f));
|
||||||
|
c.race_time = est_time;
|
||||||
|
} else {
|
||||||
|
c.race_time = std::max(c.race_time + 0.5f, prev_time + 0.25f);
|
||||||
|
}
|
||||||
|
|
||||||
|
prev_time = c.race_time;
|
||||||
|
if (c.best_lap_time <= 0.0f) {
|
||||||
|
c.best_lap_time = (total_laps <= 1) ? c.race_time
|
||||||
|
: (c.race_time / static_cast<float>(total_laps));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,7 @@ public:
|
|||||||
bool has_clone_ghost() const { return clone_active_; }
|
bool has_clone_ghost() const { return clone_active_; }
|
||||||
CraftPose interpolated_clone_pose(float alpha) const;
|
CraftPose interpolated_clone_pose(float alpha) const;
|
||||||
const CloneRecording& current_recording() const { return recording_; }
|
const CloneRecording& current_recording() const { return recording_; }
|
||||||
|
const CloneRecording& playback_clone() const { return playback_clone_; }
|
||||||
|
|
||||||
// Checks if morph triggers fired and changed terrain heights or columns
|
// Checks if morph triggers fired and changed terrain heights or columns
|
||||||
bool consume_terrain_dirty(int& x0, int& z0, int& x1, int& z1);
|
bool consume_terrain_dirty(int& x0, int& z0, int& x1, int& z1);
|
||||||
@@ -180,7 +181,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void compute_start_grid(int count, std::vector<CraftPose>& out_poses) const;
|
void compute_start_grid(int count, std::vector<CraftPose>& out_poses) const;
|
||||||
void update_checkpoints_and_laps(CraftState& c);
|
void update_checkpoints_and_laps(CraftState& c, float dt);
|
||||||
void update_recharge_pads(CraftState& c, float dt);
|
void update_recharge_pads(CraftState& c, float dt);
|
||||||
void update_triggers(CraftState& c);
|
void update_triggers(CraftState& c);
|
||||||
void update_timed_triggers(float dt);
|
void update_timed_triggers(float dt);
|
||||||
@@ -190,6 +191,7 @@ private:
|
|||||||
void push_dirty_rect(int x0, int z0, int x1, int z1);
|
void push_dirty_rect(int x0, int z0, int x1, int z1);
|
||||||
void activate_group(uint16_t group, int actor_player, bool allow_banner, bool fast_morph = false);
|
void activate_group(uint16_t group, int actor_player, bool allow_banner, bool fast_morph = false);
|
||||||
void update_standings();
|
void update_standings();
|
||||||
|
void finalize_unfinished_times(const std::vector<size_t>& order);
|
||||||
void update_particles(float dt);
|
void update_particles(float dt);
|
||||||
|
|
||||||
RaceSetup setup_{};
|
RaceSetup setup_{};
|
||||||
@@ -205,6 +207,7 @@ private:
|
|||||||
int last_countdown_int_ = 4;
|
int last_countdown_int_ = 4;
|
||||||
float elapsed_time_ = 0.0f;
|
float elapsed_time_ = 0.0f;
|
||||||
bool race_over_ = false;
|
bool race_over_ = false;
|
||||||
|
bool times_finalized_ = false;
|
||||||
int winner_id_ = -1;
|
int winner_id_ = -1;
|
||||||
|
|
||||||
// Trigger/morph tracking
|
// Trigger/morph tracking
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "sim/combat.hpp"
|
#include "sim/combat.hpp"
|
||||||
#include "sim/race_sim.hpp"
|
#include "sim/race_sim.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -482,5 +484,281 @@ int main() {
|
|||||||
}
|
}
|
||||||
std::cout << "[PASS] Authentic sector morphing, Timed/Craft/Rocket triggers & groups verified across all 6 tracks\n";
|
std::cout << "[PASS] Authentic sector morphing, Timed/Craft/Rocket triggers & groups verified across all 6 tracks\n";
|
||||||
|
|
||||||
|
// 7. PostRace Leaderboard Opponent Times & SplitScreen Completion
|
||||||
|
{
|
||||||
|
// 7a. 1-lap 8-racer race on Track 3
|
||||||
|
assets::LevelData lvl3;
|
||||||
|
CHECK(lvl3.load(vfs, 3));
|
||||||
|
sim::RaceSetup s1;
|
||||||
|
s1.mode = sim::GameMode::SingleRace;
|
||||||
|
s1.track_number = 3;
|
||||||
|
s1.total_laps = 1;
|
||||||
|
s1.difficulty = 1;
|
||||||
|
s1.num_ai = 7;
|
||||||
|
|
||||||
|
sim::RaceSim sim1;
|
||||||
|
CHECK(sim1.start_race(lvl3, s1));
|
||||||
|
sim1.crafts_mut()[0].autopilot = true;
|
||||||
|
for (int t = 0; t < 10000 && !sim1.race_finished(); ++t) {
|
||||||
|
sim1.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
}
|
||||||
|
CHECK(sim1.race_finished());
|
||||||
|
CHECK(sim1.crafts()[0].finished);
|
||||||
|
|
||||||
|
auto sorted1 = sim1.crafts();
|
||||||
|
std::sort(sorted1.begin(), sorted1.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.placement < b.placement;
|
||||||
|
});
|
||||||
|
bool any_unfinished1 = false;
|
||||||
|
for (size_t i = 0; i < sorted1.size(); ++i) {
|
||||||
|
const auto& c = sorted1[i];
|
||||||
|
CHECK(c.placement == static_cast<int>(i + 1));
|
||||||
|
CHECK(c.race_time > 0.0f && c.race_time < 600.0f);
|
||||||
|
CHECK(c.best_lap_time > 0.0f && c.best_lap_time <= c.race_time + 1e-4f);
|
||||||
|
if (!c.finished) {
|
||||||
|
any_unfinished1 = true;
|
||||||
|
if (i > 0) {
|
||||||
|
CHECK(c.race_time > sorted1[i - 1].race_time + 0.04f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CHECK(any_unfinished1);
|
||||||
|
|
||||||
|
// Extra steps after race_finished() must not mutate finalized times or placements
|
||||||
|
for (int t = 0; t < 10; ++t) {
|
||||||
|
sim1.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
}
|
||||||
|
auto after1 = sim1.crafts();
|
||||||
|
std::sort(after1.begin(), after1.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.placement < b.placement;
|
||||||
|
});
|
||||||
|
for (size_t i = 0; i < sorted1.size(); ++i) {
|
||||||
|
CHECK(after1[i].placement == sorted1[i].placement);
|
||||||
|
CHECK(std::abs(after1[i].race_time - sorted1[i].race_time) < 1e-6f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7b. 3-lap 8-racer race on Track 5
|
||||||
|
assets::LevelData lvl5;
|
||||||
|
CHECK(lvl5.load(vfs, 5));
|
||||||
|
sim::RaceSetup s3;
|
||||||
|
s3.mode = sim::GameMode::SingleRace;
|
||||||
|
s3.track_number = 5;
|
||||||
|
s3.total_laps = 3;
|
||||||
|
s3.difficulty = 1;
|
||||||
|
s3.num_ai = 7;
|
||||||
|
|
||||||
|
sim::RaceSim sim3;
|
||||||
|
CHECK(sim3.start_race(lvl5, s3));
|
||||||
|
sim3.crafts_mut()[0].autopilot = true;
|
||||||
|
for (int t = 0; t < 15000 && !sim3.race_finished(); ++t) {
|
||||||
|
sim3.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
}
|
||||||
|
CHECK(sim3.race_finished());
|
||||||
|
CHECK(sim3.crafts()[0].finished);
|
||||||
|
|
||||||
|
auto sorted3 = sim3.crafts();
|
||||||
|
std::sort(sorted3.begin(), sorted3.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.placement < b.placement;
|
||||||
|
});
|
||||||
|
bool any_unfinished3 = false;
|
||||||
|
for (size_t i = 0; i < sorted3.size(); ++i) {
|
||||||
|
const auto& c = sorted3[i];
|
||||||
|
CHECK(c.placement == static_cast<int>(i + 1));
|
||||||
|
CHECK(c.race_time > 0.0f && c.race_time < 600.0f);
|
||||||
|
CHECK(c.best_lap_time > 0.0f && c.best_lap_time <= c.race_time + 1e-4f);
|
||||||
|
if (!c.finished) {
|
||||||
|
any_unfinished3 = true;
|
||||||
|
if (i > 0) {
|
||||||
|
CHECK(c.race_time > sorted3[i - 1].race_time + 0.04f);
|
||||||
|
}
|
||||||
|
} else if (i > 0) {
|
||||||
|
CHECK(c.race_time >= sorted3[i - 1].race_time - 1e-5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CHECK(any_unfinished3);
|
||||||
|
|
||||||
|
game::HighscoreTable hs;
|
||||||
|
hs.clear();
|
||||||
|
int flags = hs.submit_race(5, sim3.crafts());
|
||||||
|
CHECK((flags & 3) == 3);
|
||||||
|
CHECK(hs.tracks[4].best_race_driver == sim3.crafts()[0].pilot_name);
|
||||||
|
CHECK(std::abs(hs.tracks[4].best_race - sim3.crafts()[0].race_time) < 1e-6f);
|
||||||
|
|
||||||
|
// 7c. 2-player SplitScreen completion waits for both humans
|
||||||
|
sim::RaceSetup sp;
|
||||||
|
sp.mode = sim::GameMode::SplitScreen;
|
||||||
|
sp.track_number = 3;
|
||||||
|
sp.total_laps = 1;
|
||||||
|
sp.difficulty = 1;
|
||||||
|
sp.num_ai = 2;
|
||||||
|
|
||||||
|
sim::RaceSim sim_sp;
|
||||||
|
CHECK(sim_sp.start_race(lvl3, sp));
|
||||||
|
sim_sp.crafts_mut()[0].autopilot = true;
|
||||||
|
sim_sp.crafts_mut()[1].autopilot = false;
|
||||||
|
|
||||||
|
// Give P1 a small head start (~2 seconds after 3s countdown), then let P2 drive so unfinished AI may also be checked
|
||||||
|
for (int t = 0; t < 10000 && !sim_sp.crafts()[0].finished; ++t) {
|
||||||
|
if (t == 300) {
|
||||||
|
sim_sp.crafts_mut()[1].autopilot = true;
|
||||||
|
}
|
||||||
|
sim_sp.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
}
|
||||||
|
CHECK(sim_sp.crafts()[0].finished);
|
||||||
|
CHECK(!sim_sp.crafts()[1].finished);
|
||||||
|
CHECK(!sim_sp.race_finished());
|
||||||
|
|
||||||
|
sim_sp.crafts_mut()[1].autopilot = true;
|
||||||
|
for (int t = 0; t < 10000 && !sim_sp.race_finished(); ++t) {
|
||||||
|
sim_sp.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
}
|
||||||
|
CHECK(sim_sp.race_finished());
|
||||||
|
CHECK(sim_sp.crafts()[0].finished);
|
||||||
|
CHECK(sim_sp.crafts()[1].finished);
|
||||||
|
CHECK(sim_sp.crafts()[1].race_time > sim_sp.crafts()[0].race_time);
|
||||||
|
|
||||||
|
auto sorted_sp = sim_sp.crafts();
|
||||||
|
std::sort(sorted_sp.begin(), sorted_sp.end(), [](const auto& a, const auto& b) {
|
||||||
|
return a.placement < b.placement;
|
||||||
|
});
|
||||||
|
for (size_t i = 0; i < sorted_sp.size(); ++i) {
|
||||||
|
const auto& c = sorted_sp[i];
|
||||||
|
CHECK(c.race_time > 0.0f && c.best_lap_time > 0.0f);
|
||||||
|
if (!c.finished) {
|
||||||
|
CHECK(c.race_time > sim_sp.crafts()[1].race_time);
|
||||||
|
if (i > 0) {
|
||||||
|
CHECK(c.race_time > sorted_sp[i - 1].race_time + 0.04f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "[PASS] PostRace leaderboard opponent times & SplitScreen completion validated\n";
|
||||||
|
|
||||||
|
// 8. Authentic Pitstop Fuel / Shield / Ammo Charger Bays
|
||||||
|
{
|
||||||
|
const size_t expected_pad_counts[6] = {3, 3, 3, 7, 6, 7};
|
||||||
|
for (int l = 1; l <= 6; ++l) {
|
||||||
|
assets::LevelData lvl;
|
||||||
|
CHECK(lvl.load(vfs, l));
|
||||||
|
CHECK(lvl.pads.size() == expected_pad_counts[l - 1]);
|
||||||
|
int n_shield = 0, n_fuel = 0, n_ammo = 0;
|
||||||
|
for (const auto& pad : lvl.pads) {
|
||||||
|
if (pad.type == assets::ChargerType::Shield) ++n_shield;
|
||||||
|
else if (pad.type == assets::ChargerType::Fuel) ++n_fuel;
|
||||||
|
else if (pad.type == assets::ChargerType::Ammo) ++n_ammo;
|
||||||
|
}
|
||||||
|
CHECK(n_shield >= 1 && n_fuel >= 1 && n_ammo >= 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Typed pitstop recharge on Level 1
|
||||||
|
{
|
||||||
|
sim::RaceSetup ps;
|
||||||
|
ps.mode = sim::GameMode::SingleRace;
|
||||||
|
ps.track_number = 1;
|
||||||
|
ps.num_ai = 0;
|
||||||
|
ps.fuel_enabled = true;
|
||||||
|
ps.damage_enabled = true;
|
||||||
|
ps.weapons_enabled = true;
|
||||||
|
|
||||||
|
sim::RaceSim psim;
|
||||||
|
CHECK(psim.start_race(lvl1, ps));
|
||||||
|
for (int t = 0; t < 200; ++t) psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
|
||||||
|
auto& p1 = psim.crafts_mut()[0];
|
||||||
|
auto place_p1 = [&](float wx, float wz, float dy = 0.30f) {
|
||||||
|
p1.curr_pose.pos = Vec3(wx, psim.level().sample_height_world(wx, wz) + dy, wz);
|
||||||
|
p1.prev_pose = p1.curr_pose;
|
||||||
|
p1.vel = Vec3(0, 0, 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fuel bay (49.0, 79.0): recharges only fuel + emits Refuel sound
|
||||||
|
p1.fuel = 20.0f;
|
||||||
|
p1.shield = 20.0f;
|
||||||
|
p1.ammo = 20.0f;
|
||||||
|
p1.refuel_sound_cd = 0.0f;
|
||||||
|
place_p1(49.0f, 79.0f);
|
||||||
|
psim.clear_events();
|
||||||
|
bool saw_refuel_sfx = false;
|
||||||
|
for (int t = 0; t < 60; ++t) {
|
||||||
|
psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
for (const auto& ev : psim.events()) {
|
||||||
|
if (ev.sound == sim::SimSoundCue::Refuel) saw_refuel_sfx = true;
|
||||||
|
}
|
||||||
|
psim.clear_events();
|
||||||
|
}
|
||||||
|
CHECK(p1.fuel > 70.0f);
|
||||||
|
CHECK(p1.shield == 20.0f);
|
||||||
|
CHECK(p1.ammo == 20.0f);
|
||||||
|
CHECK(saw_refuel_sfx);
|
||||||
|
|
||||||
|
// Ammo bay (49.0, 85.0): recharges only ammo
|
||||||
|
p1.fuel = 20.0f;
|
||||||
|
place_p1(49.0f, 85.0f);
|
||||||
|
for (int t = 0; t < 60; ++t) psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(p1.ammo > 70.0f);
|
||||||
|
CHECK(p1.shield == 20.0f);
|
||||||
|
CHECK(p1.fuel <= 20.0f);
|
||||||
|
|
||||||
|
// Shield bay (27.0, 98.5): recharges only shield
|
||||||
|
p1.ammo = 20.0f;
|
||||||
|
place_p1(27.0f, 98.5f);
|
||||||
|
for (int t = 0; t < 60; ++t) psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(p1.shield > 65.0f);
|
||||||
|
CHECK(p1.ammo == 20.0f);
|
||||||
|
|
||||||
|
// Legacy Recovery Truck spawn (44.5, 58.5) must NOT recharge resources
|
||||||
|
p1.fuel = 20.0f;
|
||||||
|
p1.shield = 20.0f;
|
||||||
|
p1.ammo = 20.0f;
|
||||||
|
place_p1(44.5f, 58.5f);
|
||||||
|
for (int t = 0; t < 30; ++t) psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(p1.shield == 20.0f);
|
||||||
|
CHECK(p1.ammo == 20.0f);
|
||||||
|
CHECK(p1.fuel <= 20.0f);
|
||||||
|
CHECK(p1.active_recharge_mask == 0);
|
||||||
|
|
||||||
|
// High above Fuel bay canopy (ground_y + 2.5f) must NOT recharge
|
||||||
|
p1.fuel = 20.0f;
|
||||||
|
place_p1(49.0f, 79.0f, 2.5f);
|
||||||
|
psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(p1.active_recharge_mask == 0);
|
||||||
|
CHECK(p1.fuel <= 20.0f);
|
||||||
|
|
||||||
|
// Entering/resting on Fuel bay at 0 fuel refuels directly without Recovery Craft
|
||||||
|
p1.fuel = 0.0f;
|
||||||
|
place_p1(49.0f, 79.0f);
|
||||||
|
for (int t = 0; t < 10; ++t) psim.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(p1.fuel > 5.0f);
|
||||||
|
CHECK(p1.recovery_state == sim::RecoveryState::Active);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overlapping Shield + Ammo pitstop on Level 5 (84.5, 127.0)
|
||||||
|
{
|
||||||
|
assets::LevelData lvl5;
|
||||||
|
CHECK(lvl5.load(vfs, 5));
|
||||||
|
sim::RaceSetup ps5;
|
||||||
|
ps5.mode = sim::GameMode::SingleRace;
|
||||||
|
ps5.track_number = 5;
|
||||||
|
ps5.num_ai = 0;
|
||||||
|
|
||||||
|
sim::RaceSim psim5;
|
||||||
|
CHECK(psim5.start_race(lvl5, ps5));
|
||||||
|
for (int t = 0; t < 200; ++t) psim5.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
|
||||||
|
auto& p1 = psim5.crafts_mut()[0];
|
||||||
|
p1.fuel = 20.0f;
|
||||||
|
p1.shield = 20.0f;
|
||||||
|
p1.ammo = 20.0f;
|
||||||
|
p1.curr_pose.pos = Vec3(84.5f, psim5.level().sample_height_world(84.5f, 127.0f) + 0.30f, 127.0f);
|
||||||
|
p1.prev_pose = p1.curr_pose;
|
||||||
|
p1.vel = Vec3(0, 0, 0);
|
||||||
|
for (int t = 0; t < 60; ++t) psim5.step(CraftInput{}, CraftInput{}, dt);
|
||||||
|
CHECK(p1.shield > 65.0f);
|
||||||
|
CHECK(p1.ammo > 70.0f);
|
||||||
|
CHECK(p1.fuel <= 20.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "[PASS] Authentic pitstop Fuel/Shield/Ammo chargers verified across all 6 tracks\n";
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user