Fix pickup billboards, AI stuck recovery, vehicle top speeds, and add Revision assets

This commit is contained in:
Luxferre committed 2026-12-01 13:59:43 +02:00
1 parent d001f214aa
commit 5a42ca9968
48 files changed
+988 -153

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+59
View File
@@ -2,10 +2,16 @@
#include "assets/rnc.hpp"
#include "core/log.hpp"
#include <cstring>
namespace top_octane::assets {
namespace {
inline uint16_t read_le16(const uint8_t* p) {
return static_cast<uint16_t>(p[0] | (static_cast<uint16_t>(p[1]) << 8));
}
inline uint32_t read_le32(const uint8_t* p) {
return static_cast<uint32_t>(p[0]) |
(static_cast<uint32_t>(p[1]) << 8) |
@@ -79,6 +85,59 @@ bool SpriteBank::load(const Vfs& vfs, const std::string& dat_path, const std::st
return true;
}
bool TmapBank::load(const Vfs& vfs, const Palette& pal,
const std::string& dat_path, const std::string& tab_path) {
std::vector<uint8_t> dat, tab;
if (!vfs.read_file(dat_path, dat) || !vfs.read_file(tab_path, tab)) {
LOG_ERROR("Failed to load TMAPS files: %s / %s", dat_path.c_str(), tab_path.c_str());
return false;
}
if (dat.size() < 8 || std::memcmp(dat.data(), "BULLFROG", 8) != 0 || tab.size() < 10) {
LOG_ERROR("Invalid TMAPS header or table size");
return false;
}
sprites.clear();
const size_t entry_count = tab.size() / 10u;
sprites.reserve(entry_count);
std::vector<uint8_t> unpacked;
for (size_t i = 0; i < entry_count; ++i) {
const uint8_t* e = tab.data() + i * 10u;
uint32_t ulen = read_le32(e + 0);
uint32_t off = read_le32(e + 4);
if (ulen == 0 || off >= dat.size()) {
break;
}
if (!rnc_unpack_bytes(dat.data() + off, dat.size() - off, unpacked) || unpacked.size() < 6) {
LOG_ERROR("Failed to unpack TMAPS entry %zu at offset %u", i, off);
return false;
}
const int w = static_cast<int>(read_le16(unpacked.data() + 2));
const int h = static_cast<int>(read_le16(unpacked.data() + 4));
if (w <= 0 || h <= 0 || 6u + static_cast<size_t>(w) * static_cast<size_t>(h) > unpacked.size()) {
LOG_ERROR("Invalid TMAPS sprite dimensions %dx%d at entry %zu", w, h, i);
return false;
}
SpriteImage img;
img.width = w;
img.height = h;
const size_t pix_count = static_cast<size_t>(w) * static_cast<size_t>(h);
img.rgba.resize(pix_count * 4u);
for (size_t k = 0; k < pix_count; ++k) {
const uint8_t cidx = unpacked[6u + k];
const Rgba8& c = pal.colors[cidx];
img.rgba[k * 4u + 0] = c.r;
img.rgba[k * 4u + 1] = c.g;
img.rgba[k * 4u + 2] = c.b;
img.rgba[k * 4u + 3] = (cidx == 0) ? 0 : 255;
}
sprites.push_back(std::move(img));
}
return !sprites.empty();
}
bool load_raw_screen(const Vfs& vfs, const std::string& path, int width, int height,
const Palette& pal, SpriteImage& out_img) {
std::vector<uint8_t> raw, data;
+30
View File
@@ -22,6 +22,36 @@ struct SpriteBank {
const Palette& pal);
};
// World-space 3D billboard texture bank (DATA/TMAPS.DAT + DATA/TMAPS.TAB, entries 0..47)
struct TmapBank {
std::vector<SpriteImage> sprites; // 0..47; 29..42 are pickup/upgrade icons
bool load(const Vfs& vfs, const Palette& pal,
const std::string& dat_path = "DATA/TMAPS.DAT",
const std::string& tab_path = "DATA/TMAPS.TAB");
};
// Authentic HIOCTANE.EXE Type-5 subtype (0..13) -> TMAPS sprite index (29..42)
inline int pickup_tmap_index(uint8_t subtype) {
switch (subtype) {
case 0: return 41; // Invincible (green shield hex)
case 1: return 42; // Invisible (dark stealth hex)
case 2: return 35; // Shield Extra 10 (teal triangle)
case 3: return 36; // Shield Full 100 (teal diamond)
case 4: return 37; // Shield Double 200 (teal octagon)
case 5: return 32; // Ammo Extra 10 (yellow triangle)
case 6: return 33; // Ammo Full 100 (yellow diamond)
case 7: return 34; // Ammo Double 200 (yellow octagon)
case 8: return 29; // Fuel Extra 10 (purple triangle)
case 9: return 30; // Fuel Full 100 (purple diamond)
case 10: return 31; // Fuel Double 200 (purple octagon)
case 11: return 38; // Minigun Upgrade (red 4-barrel diamond)
case 12: return 39; // Missile Upgrade (red rocket hex)
case 13: return 40; // Booster Upgrade (orange up-chevron diamond)
default: return 38;
}
}
// Loads a raw indexed full-screen image (e.g., TITLE.DAT 320x200 or OSCR0-1.DAT 640x480)
bool load_raw_screen(const Vfs& vfs, const std::string& path, int width, int height,
const Palette& pal, SpriteImage& out_img);
+37 -17
View File
@@ -616,8 +616,7 @@ void GameApp::update_racing_step(float dt) {
if (!race_sim_.crafts().empty()) {
const auto& c0 = race_sim_.crafts()[0];
const auto& sp = sim::kVehicleSpecs[std::clamp(c0.vehicle_idx, 0, 5)];
float spd_ratio = c0.speed_horizontal() / sp.top_speed;
float spd_ratio = c0.speed_horizontal() / 22.0f;
audio_.set_engine_state(c0.recovery_state == sim::RecoveryState::Active,
spd_ratio, c0.boost_timer > 0.05f, c0.scrape_intensity);
}
@@ -837,8 +836,8 @@ void GameApp::update_menu(float dt) {
int dir = m.right ? 1 : (m.left ? -1 : 0);
if (dir != 0) {
audio_.play_sfx("CHANGE.WAV", 0.32f);
if (menu_cursor_ == 1) p1_veh_ = (p1_veh_ + dir + 6) % 6;
else if (menu_cursor_ == 2) p1_team_ = (p1_team_ + dir + 8) % 8;
if (menu_cursor_ == 1) { p1_veh_ = (p1_veh_ + dir + 6) % 6; cfg_.preferred_vehicle = p1_veh_; }
else if (menu_cursor_ == 2) { p1_team_ = (p1_team_ + dir + 8) % 8; cfg_.preferred_team = p1_team_; }
else if (is_split && menu_cursor_ == 4) p2_veh_ = (p2_veh_ + dir + 6) % 6;
else if (is_split && menu_cursor_ == 5) p2_team_ = (p2_team_ + dir + 8) % 8;
}
@@ -1229,7 +1228,15 @@ void GameApp::render_frame(float alpha) {
for (const auto& c : race_sim_.crafts()) {
sim::CraftPose p = sim::interpolate_pose(c, alpha);
Vec4 tint(1, 1, 1, 1);
if (c.damage_flash > 0.0f) tint = Vec4(1.8f, 0.45f, 0.45f, 1.0f);
if (c.damage_flash > 0.0f) {
tint = Vec4(1.8f, 0.45f, 0.45f, 1.0f);
} else if (c.invincible_timer > 0.0f) {
float glow = 1.15f + 0.25f * std::sin(static_cast<float>(ui_time_) * 14.0f);
tint = Vec4(1.35f * glow, 1.18f * glow, 0.45f, 1.0f);
}
if (c.invisible_timer > 0.0f) {
tint.w = 0.32f;
}
float vscale = sim::kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)].visual_scale;
models.push_back({sim::model_key_for(c.vehicle_idx, c.team_idx), p.pos,
p.yaw, p.pitch, p.roll, vscale, tint});
@@ -1263,18 +1270,33 @@ void GameApp::render_frame(float alpha) {
float pscale = (pr.model_key.rfind("BAREL", 0) == 0) ? 0.42f : 0.68f;
models.push_back({pr.model_key, pr.pos, pr.yaw, 0.0f, 0.0f, pscale, Vec4(1, 1, 1, 1)});
}
std::vector<render::WorldBillboard> billboards;
billboards.reserve(race_sim_.pickups().size());
const bool use_tmap_pickups = world_ren_.has_tmaps();
for (const auto& pk : race_sim_.pickups()) {
if (!pk.active) continue;
float bob = std::sin(static_cast<float>(ui_time_) * 3.5f + pk.pos.x) * 0.12f;
float rot = static_cast<float>(ui_time_) * 2.2f;
Vec4 pcol(0.3f, 1.0f, 0.4f, 1.0f);
if (pk.subtype <= 2) pcol = Vec4(1.0f, 0.65f, 0.2f, 1.0f); // fuel
else if (pk.subtype <= 5) pcol = Vec4(0.3f, 0.7f, 1.0f, 1.0f); // shield
else if (pk.subtype <= 9) pcol = Vec4(1.0f, 0.9f, 0.2f, 1.0f); // ammo
else pcol = Vec4(1.0f, 0.35f, 0.9f, 1.0f); // weapon/booster upgrade
Vec3 lcol(0.3f, 1.0f, 0.4f);
if (pk.subtype == 0) lcol = Vec3(0.25f, 1.0f, 0.40f); // invincible green
else if (pk.subtype == 1) lcol = Vec3(0.45f, 0.55f, 0.85f); // invisible slate
else if (pk.subtype <= 4) lcol = Vec3(0.25f, 0.88f, 0.72f); // shield teal
else if (pk.subtype <= 7) lcol = Vec3(1.0f, 0.88f, 0.20f); // ammo yellow
else if (pk.subtype <= 10) lcol = Vec3(0.78f, 0.42f, 1.0f); // fuel purple
else if (pk.subtype <= 12) lcol = Vec3(1.0f, 0.25f, 0.22f); // minigun / missile crimson
else lcol = Vec3(1.0f, 0.52f, 0.14f); // booster bright orange
Vec3 ppos = pk.pos + Vec3(0, bob, 0);
models.push_back({"CONE0-0", ppos, rot, 0.0f, 0.0f, 0.65f, pcol});
all_lights.push_back({ppos + Vec3(0.0f, 0.25f, 0.0f), 3.4f, Vec3(pcol.x, pcol.y, pcol.z), 0.46f});
if (use_tmap_pickups) {
float alpha_p = (pk.subtype == 1) ? 0.78f : 1.0f;
billboards.push_back({ppos + Vec3(0.0f, 0.15f, 0.0f), 1.05f,
assets::pickup_tmap_index(pk.subtype),
Vec4(1.0f, 1.0f, 1.0f, alpha_p)});
} else {
models.push_back({"CONE0-0", ppos, rot, 0.0f, 0.0f, 0.65f,
Vec4(lcol.x, lcol.y, lcol.z, 1.0f)});
}
all_lights.push_back({ppos + Vec3(0.0f, 0.25f, 0.0f), 3.4f, lcol, 0.46f});
}
for (const auto& pj : race_sim_.projectiles()) {
if (!pj.active) continue;
@@ -1363,7 +1385,8 @@ void GameApp::render_frame(float alpha) {
float min_cam_y = race_sim_.level().sample_height_world(cams[vp].eye.x, cams[vp].eye.z) + 0.4f;
if (cams[vp].eye.y < min_cam_y) cams[vp].eye.y = min_cam_y;
auto vp_lights = select_viewport_lights(all_lights, cams[vp].target, draw_dist);
world_ren_.render_world_view(cams[vp], models, parts, vp, split_count, cfg_, vp_lights, craft_shadows);
world_ren_.render_world_view(cams[vp], models, parts, vp, split_count, cfg_,
vp_lights, craft_shadows, billboards);
}
world_ren_.end_classic_world_pass(win_w_, win_h_, cfg_);
@@ -1568,10 +1591,7 @@ void GameApp::render_hud_viewport(const sim::CraftState& craft, const render::Re
};
// Draw Speed Wave + Fuel + Shield + Ammo + Speedometer + Right Boost/Lock Wing
const auto& spec = sim::kVehicleSpecs[std::clamp(craft.vehicle_idx, 0, 5)];
float boost_mult = 1.0f + 0.14f * static_cast<float>(craft.booster_level - 1);
float max_ref_spd = spec.top_speed + spec.boost_bonus * boost_mult;
float spd_frac = std::clamp(craft.speed_horizontal() / std::max(max_ref_spd, 1.0f), 0.0f, 1.0f);
float spd_frac = std::clamp(craft.speed_horizontal() / sim::kGlobalSpeedGaugeMax, 0.0f, 1.0f);
draw_arc(kFuelArc, 17, static_cast<int>(fuel_frac * 10000.0f), status_tint(fuel_frac, 2u), 0.26f);
draw_arc(kSpeedWaveDim, 19, static_cast<int>(spd_frac * 10000.0f), Vec4(1.0f, 1.0f, 1.0f, 0.95f), 0.22f);
+207 -2
View File
@@ -548,6 +548,58 @@ void main() {
}
)glsl";
constexpr const char* kBillboardVS = R"glsl(
#version 330 core
layout(location = 0) in vec3 aPos;
layout(location = 1) in vec2 aUv;
layout(location = 2) in vec4 aColor;
uniform mat4 uViewProj;
out vec2 vUv;
out vec4 vColor;
out vec3 vWorldPos;
void main() {
vUv = aUv;
vColor = aColor;
vWorldPos = aPos;
gl_Position = uViewProj * vec4(aPos, 1.0);
}
)glsl";
constexpr const char* kBillboardFS = R"glsl(
#version 330 core
in vec2 vUv;
in vec4 vColor;
in vec3 vWorldPos;
uniform sampler2D uTex;
uniform vec3 uCamPos;
uniform vec3 uFogColor;
uniform float uDrawDist;
uniform float uModernLighting;
out vec4 FragColor;
void main() {
vec4 tex = texture(uTex, vUv);
if (tex.a < 0.5) discard;
vec3 col = tex.rgb * vColor.rgb;
if (uModernLighting > 0.5) {
col *= 1.12;
}
float dist = length(vWorldPos - uCamPos);
float fogStart = uDrawDist * 0.45;
float fogFactor = clamp((dist - fogStart) / max(uDrawDist - fogStart, 1.0), 0.0, 1.0);
float fog2 = fogFactor * fogFactor;
vec3 rgb = mix(col, uFogColor, fog2);
FragColor = vec4(rgb, tex.a * vColor.a);
}
)glsl";
constexpr const char* kClassicVS = R"glsl(
#version 330 core
layout(location = 0) in vec2 aPos;
@@ -692,6 +744,7 @@ bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
!model_shader_.build(kModelVS, kModelFS, "model") ||
!sky_shader_.build(kSkyVS, kSkyFS, "sky") ||
!particle_shader_.build(kParticleVS, kParticleFS, "particle") ||
!billboard_shader_.build(kBillboardVS, kBillboardFS, "billboard") ||
!classic_shader_.build(kClassicVS, kClassicFS, "classic") ||
!shadow_world_shader_.build(kShadowWorldVS, kShadowWorldFS, "shadow_world") ||
!shadow_model_shader_.build(kShadowModelVS, kShadowModelFS, "shadow_model")) {
@@ -713,6 +766,79 @@ bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Shelf-pack world billboard sprites (DATA/TMAPS.DAT) with 1px transparent padding
tmap_rects_.clear();
if (vfs.exists("DATA/TMAPS.DAT") && vfs.exists("DATA/TMAPS.TAB")) {
assets::TmapBank tmaps;
if (tmaps.load(vfs, pal) && !tmaps.sprites.empty()) {
constexpr int kAtlasW = 512;
constexpr int kPad = 1;
struct Placement {
size_t idx = 0;
int x = 0;
int y = 0;
int w = 0;
int h = 0;
};
std::vector<size_t> order(tmaps.sprites.size());
for (size_t i = 0; i < order.size(); ++i) order[i] = i;
std::sort(order.begin(), order.end(), [&](size_t a, size_t b) {
return tmaps.sprites[a].height > tmaps.sprites[b].height;
});
std::vector<Placement> placed;
placed.reserve(order.size());
int cur_x = kPad;
int cur_y = kPad;
int row_h = 0;
for (size_t idx : order) {
const auto& sp = tmaps.sprites[idx];
if (sp.width <= 0 || sp.height <= 0 || sp.rgba.empty()) continue;
if (cur_x + sp.width + kPad > kAtlasW) {
cur_x = kPad;
cur_y += row_h + kPad;
row_h = 0;
}
placed.push_back({idx, cur_x, cur_y, sp.width, sp.height});
cur_x += sp.width + kPad;
row_h = std::max(row_h, sp.height);
}
int needed_h = cur_y + row_h + kPad;
int atlas_h = 64;
while (atlas_h < needed_h) atlas_h <<= 1;
std::vector<uint8_t> atlas_rgba(static_cast<size_t>(kAtlasW) * static_cast<size_t>(atlas_h) * 4u, 0);
tmap_rects_.resize(tmaps.sprites.size());
for (const auto& pl : placed) {
const auto& sp = tmaps.sprites[pl.idx];
for (int sy = 0; sy < pl.h; ++sy) {
const uint8_t* src_row = &sp.rgba[static_cast<size_t>(sy) * static_cast<size_t>(pl.w) * 4u];
uint8_t* dst_row = &atlas_rgba[(static_cast<size_t>(pl.y + sy) * kAtlasW + pl.x) * 4u];
std::copy(src_row, src_row + static_cast<size_t>(pl.w) * 4u, dst_row);
}
TmapUvRect r;
r.u0 = static_cast<float>(pl.x) / static_cast<float>(kAtlasW);
r.v0 = static_cast<float>(pl.y) / static_cast<float>(atlas_h);
r.u1 = static_cast<float>(pl.x + pl.w) / static_cast<float>(kAtlasW);
r.v1 = static_cast<float>(pl.y + pl.h) / static_cast<float>(atlas_h);
r.aspect = static_cast<float>(pl.w) / static_cast<float>(pl.h);
r.valid = true;
tmap_rects_[pl.idx] = r;
}
glGenTextures(1, &tex_tmaps_atlas_);
glBindTexture(GL_TEXTURE_2D, tex_tmaps_atlas_);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kAtlasW, atlas_h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, atlas_rgba.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
} else {
LOG_WARN("DATA/TMAPS.DAT found but failed to decode; pickups will use fallback geometry");
}
}
// Upload 256 x 1 palette texture for Classic Mode quantization
uint8_t pal_rgba[256 * 4];
for (int i = 0; i < 256; ++i) {
@@ -823,6 +949,21 @@ bool WorldRenderer::init(const Vfs& vfs, const assets::Palette& pal) {
gl::VertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 11 * sizeof(float),
reinterpret_cast<void*>(9 * sizeof(float)));
// Dynamic textured billboard stream VAO/VBO (pos3 + uv2 + color4 = 9 floats)
gl::GenVertexArrays(1, &billboard_vao_);
gl::GenBuffers(1, &billboard_vbo_);
gl::BindVertexArray(billboard_vao_);
gl::BindBuffer(GL_ARRAY_BUFFER, billboard_vbo_);
gl::BufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);
gl::EnableVertexAttribArray(0);
gl::VertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 9 * sizeof(float), nullptr);
gl::EnableVertexAttribArray(1);
gl::VertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
reinterpret_cast<void*>(3 * sizeof(float)));
gl::EnableVertexAttribArray(2);
gl::VertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 9 * sizeof(float),
reinterpret_cast<void*>(5 * sizeof(float)));
gl::BindVertexArray(0);
initialized_ = true;
return true;
@@ -844,6 +985,8 @@ void WorldRenderer::shutdown() {
if (quad_vbo_) gl::DeleteBuffers(1, &quad_vbo_);
if (part_vao_) gl::DeleteVertexArrays(1, &part_vao_);
if (part_vbo_) gl::DeleteBuffers(1, &part_vbo_);
if (billboard_vao_) gl::DeleteVertexArrays(1, &billboard_vao_);
if (billboard_vbo_) gl::DeleteBuffers(1, &billboard_vbo_);
if (classic_fbo_) gl::DeleteFramebuffers(1, &classic_fbo_);
if (classic_depth_rbo_) gl::DeleteRenderbuffers(1, &classic_depth_rbo_);
if (shadow_fbo_) gl::DeleteFramebuffers(1, &shadow_fbo_);
@@ -851,20 +994,24 @@ void WorldRenderer::shutdown() {
if (tex_terrain_array_) glDeleteTextures(1, &tex_terrain_array_);
if (tex_sky_) glDeleteTextures(1, &tex_sky_);
if (tex_obj_atlas_) glDeleteTextures(1, &tex_obj_atlas_);
if (tex_tmaps_atlas_) glDeleteTextures(1, &tex_tmaps_atlas_);
if (tex_palette_) glDeleteTextures(1, &tex_palette_);
if (classic_color_tex_) glDeleteTextures(1, &classic_color_tex_);
if (shadow_depth_tex_) glDeleteTextures(1, &shadow_depth_tex_);
sky_vao_ = sky_vbo_ = quad_vao_ = quad_vbo_ = part_vao_ = part_vbo_ = 0;
billboard_vao_ = billboard_vbo_ = 0;
classic_fbo_ = classic_depth_rbo_ = classic_color_tex_ = 0;
shadow_fbo_ = shadow_depth_tex_ = 0;
tex_terrain_array_ = tex_sky_ = tex_obj_atlas_ = tex_palette_ = 0;
tex_terrain_array_ = tex_sky_ = tex_obj_atlas_ = tex_tmaps_atlas_ = tex_palette_ = 0;
tmap_rects_.clear();
classic_w_ = classic_h_ = 0;
world_shader_.destroy();
model_shader_.destroy();
sky_shader_.destroy();
particle_shader_.destroy();
billboard_shader_.destroy();
classic_shader_.destroy();
shadow_world_shader_.destroy();
shadow_model_shader_.destroy();
@@ -1093,6 +1240,11 @@ void WorldRenderer::apply_texture_filtering(TextureFilterMode mode) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mag_f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_f);
}
if (tex_tmaps_atlas_) {
glBindTexture(GL_TEXTURE_2D, tex_tmaps_atlas_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, mag_f);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_f);
}
}
void WorldRenderer::begin_frame(int backbuffer_w, int backbuffer_h, const GameConfig& cfg) {
@@ -1122,7 +1274,8 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
const std::vector<ParticleQuad>& particles,
int viewport_index, int split_count, const GameConfig& cfg,
const std::vector<DynamicLight>& lights,
const std::vector<CraftShadow>& craft_shadows) {
const std::vector<CraftShadow>& craft_shadows,
const std::vector<WorldBillboard>& billboards) {
int target_w = cfg.classic_mode ? classic_w_ : backbuffer_w_;
int target_h = cfg.classic_mode ? classic_h_ : backbuffer_h_;
const bool modern = !cfg.classic_mode;
@@ -1340,6 +1493,58 @@ void WorldRenderer::render_world_view(const RenderCamera& cam, const std::vector
for (const auto& inst : models) {
if (inst.tint.w >= 0.99f) draw_model(inst);
}
// 3b. Textured World Billboards (authentic Bullfrog TMAPS powerup & pickup icons)
if (!billboards.empty() && tex_tmaps_atlas_ && billboard_vao_) {
Vec3 cam_right(view.m[0], view.m[4], view.m[8]);
Vec3 cam_up(view.m[1], view.m[5], view.m[9]);
std::vector<float> bverts;
bverts.reserve(billboards.size() * 6 * 9);
for (const auto& b : billboards) {
if (b.tmap_id < 0 || static_cast<size_t>(b.tmap_id) >= tmap_rects_.size()) continue;
const TmapUvRect& rect = tmap_rects_[static_cast<size_t>(b.tmap_id)];
if (!rect.valid) continue;
Vec3 rx = cam_right * (b.size * 0.5f * rect.aspect);
Vec3 ry = cam_up * (b.size * 0.5f);
Vec3 c0 = b.pos - rx - ry;
Vec3 c1 = b.pos + rx - ry;
Vec3 c2 = b.pos + rx + ry;
Vec3 c3 = b.pos - rx + ry;
auto emit = [&](const Vec3& q, float u, float v) {
bverts.push_back(q.x); bverts.push_back(q.y); bverts.push_back(q.z);
bverts.push_back(u); bverts.push_back(v);
bverts.push_back(b.tint.x); bverts.push_back(b.tint.y);
bverts.push_back(b.tint.z); bverts.push_back(b.tint.w);
};
// Bottom uses v1 and top uses v0 (row 0 = top of decoded TMAP image)
emit(c0, rect.u0, rect.v1); emit(c1, rect.u1, rect.v1); emit(c2, rect.u1, rect.v0);
emit(c0, rect.u0, rect.v1); emit(c2, rect.u1, rect.v0); emit(c3, rect.u0, rect.v0);
}
if (!bverts.empty()) {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_TRUE);
billboard_shader_.use();
billboard_shader_.set_mat4("uViewProj", view_proj);
billboard_shader_.set_vec3("uCamPos", cam.eye);
billboard_shader_.set_vec3("uFogColor", fog_color_);
billboard_shader_.set_float("uDrawDist", draw_dist);
billboard_shader_.set_float("uModernLighting", modern ? 1.0f : 0.0f);
gl::ActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex_tmaps_atlas_);
billboard_shader_.set_int("uTex", 0);
gl::BindVertexArray(billboard_vao_);
gl::BindBuffer(GL_ARRAY_BUFFER, billboard_vbo_);
gl::BufferData(GL_ARRAY_BUFFER,
static_cast<GLsizeiptr>(bverts.size() * sizeof(float)),
bverts.data(), GL_DYNAMIC_DRAW);
glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(bverts.size() / 9));
glDisable(GL_BLEND);
}
}
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthMask(GL_FALSE);
+25 -2
View File
@@ -3,6 +3,7 @@
#include "assets/level.hpp"
#include "assets/model.hpp"
#include "assets/palette.hpp"
#include "assets/sprites.hpp"
#include "assets/textures.hpp"
#include "core/config.hpp"
#include "core/math.hpp"
@@ -46,6 +47,13 @@ struct ParticleQuad {
bool additive = true;
};
struct WorldBillboard {
Vec3 pos;
float size = 1.0f;
int tmap_id = 38;
Vec4 tint{1.0f, 1.0f, 1.0f, 1.0f};
};
struct DynamicLight {
Vec3 pos;
float radius = 6.0f;
@@ -83,7 +91,8 @@ public:
const std::vector<ParticleQuad>& particles,
int viewport_index, int split_count, const GameConfig& cfg,
const std::vector<DynamicLight>& lights = {},
const std::vector<CraftShadow>& craft_shadows = {});
const std::vector<CraftShadow>& craft_shadows = {},
const std::vector<WorldBillboard>& billboards = {});
// Finalizes Classic Mode FBO quantization blit if active; call before drawing crisp 2D UI or after
void end_classic_world_pass(int backbuffer_w, int backbuffer_h, const GameConfig& cfg);
@@ -94,6 +103,7 @@ public:
const WorldGeometry& geometry() const { return world_geo_; }
const assets::ObjectTextureAtlas& object_atlas() const { return obj_atlas_; }
bool has_tmaps() const { return tex_tmaps_atlas_ != 0 && !tmap_rects_.empty(); }
private:
struct GpuMesh {
@@ -103,6 +113,15 @@ private:
GLsizei index_count = 0;
};
struct TmapUvRect {
float u0 = 0.0f;
float v0 = 0.0f;
float u1 = 1.0f;
float v1 = 1.0f;
float aspect = 1.0f;
bool valid = false;
};
struct WorldLightingTheme {
Vec3 sun_dir{0.45f, 0.80f, 0.38f};
Vec3 sun_color{1.0f, 0.96f, 0.88f};
@@ -129,6 +148,7 @@ private:
ShaderProgram model_shader_;
ShaderProgram sky_shader_;
ShaderProgram particle_shader_;
ShaderProgram billboard_shader_;
ShaderProgram classic_shader_;
ShaderProgram shadow_world_shader_;
ShaderProgram shadow_model_shader_;
@@ -137,8 +157,10 @@ private:
GLuint tex_terrain_array_ = 0;
GLuint tex_sky_ = 0;
GLuint tex_obj_atlas_ = 0;
GLuint tex_tmaps_atlas_ = 0;
GLuint tex_palette_ = 0;
TextureFilterMode active_filter_ = TextureFilterMode::Linear;
std::vector<TmapUvRect> tmap_rects_;
// Shadow map FBO (2048x2048 directional shadow depth map for Modern Mode)
static constexpr int kShadowMapSize = 2048;
@@ -151,8 +173,9 @@ private:
GLuint sky_vao_ = 0, sky_vbo_ = 0;
int sky_vert_count_ = 0;
// Dynamic particles
// Dynamic particles & billboards
GLuint part_vao_ = 0, part_vbo_ = 0;
GLuint billboard_vao_ = 0, billboard_vbo_ = 0;
// Fullscreen quad & Classic Mode FBO
GLuint quad_vao_ = 0, quad_vbo_ = 0;
+271 -67
View File
@@ -1,75 +1,284 @@
#include "sim/ai_driver.hpp"
#include "sim/vehicle_defs.hpp"
#include <algorithm>
#include <array>
#include <cmath>
namespace top_octane::sim {
CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
const std::vector<CraftState>& all_crafts, int difficulty) {
const std::vector<CraftState>& all_crafts, int difficulty,
float dt) {
CraftInput out;
if (ai.recovery_state != RecoveryState::Active || level.main_waypoints.empty()) {
return out;
}
int n_wp = static_cast<int>(level.main_waypoints.size());
int wp_idx = ai.ai_target_wp % n_wp;
const auto& cur_wp = level.main_waypoints[wp_idx];
Vec2 to_wp(cur_wp.x - ai.curr_pose.pos.x, cur_wp.z - ai.curr_pose.pos.z);
if (to_wp.len() < 5.0f) {
ai.ai_target_wp = (wp_idx + 1) % n_wp;
wp_idx = ai.ai_target_wp;
const VehicleSpec& spec = kVehicleSpecs[std::clamp(ai.vehicle_idx, 0, 5)];
const float probe_r = spec.collision_radius + 0.08f;
const int n_wp = static_cast<int>(level.main_waypoints.size());
int wp_idx = ((ai.ai_target_wp % n_wp) + n_wp) % n_wp;
ai.ai_target_wp = wp_idx;
if (ai.ai_pit_cooldown > 0.0f) {
ai.ai_pit_cooldown = std::max(0.0f, ai.ai_pit_cooldown - dt);
}
// 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);
auto is_ai_blocked = [&](float wx, float wz, float ref_y) -> bool {
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 > assets::kMapWidth - 2.5f ||
pz < 1.5f || pz > assets::kMapHeight - 2.5f) {
return true;
}
float local_floor = 0.0f;
float local_ceil = 1e6f;
level.sample_surface_and_ceiling(px, pz, ref_y, local_floor, local_ceil);
if (local_floor > ref_y + 0.72f) {
return true;
}
float probe_y = (local_floor > ref_y)
? (local_floor + 0.28f)
: std::max(local_floor + 0.24f, std::min(ref_y, local_floor + 0.35f));
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 true;
}
}
return false;
};
auto has_clear_corridor = [&](Vec2 a, Vec2 b, float start_y) -> bool {
Vec2 d = b - a;
float dist = d.len();
if (dist < 0.2f) {
return !is_ai_blocked(b.x, b.y, start_y);
}
int steps = std::max(1, static_cast<int>(std::ceil(dist / 0.65f)));
float cur_y = start_y;
for (int s = 1; s <= steps; ++s) {
float t = static_cast<float>(s) / static_cast<float>(steps);
Vec2 p = a + d * t;
float nf = 0.0f;
float nc = 1e6f;
level.sample_surface_and_ceiling(p.x, p.y, cur_y, nf, nc);
if (nf > cur_y + 0.72f) {
return false;
}
if (is_ai_blocked(p.x, p.y, cur_y)) {
return false;
}
cur_y = nf + spec.hover_offset;
}
return true;
};
auto find_clear_wp_in_range = [&](int off_min, int off_max, bool penalize_blocked) -> int {
int best = wp_idx;
float best_score = 1e18f;
Vec2 cur_pos(ai.curr_pose.pos.x, ai.curr_pose.pos.z);
for (int off = off_min; off <= off_max; ++off) {
int cand = ((wp_idx + off) % n_wp + n_wp) % n_wp;
const auto& w = level.main_waypoints[cand];
float fy = 0.0f, cy = 1e6f;
level.sample_surface_and_ceiling(w.x, w.z, ai.curr_pose.pos.y, fy, cy);
if (is_ai_blocked(w.x, w.z, fy + spec.hover_offset)) continue;
Vec2 wp2(w.x, w.z);
float dist = (wp2 - cur_pos).len();
if (penalize_blocked && !has_clear_corridor(cur_pos, wp2, ai.curr_pose.pos.y)) {
dist += 50.0f;
}
if (dist < best_score) {
best_score = dist;
best = cand;
}
}
return best;
};
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);
const bool on_needed_pad = (ai.active_recharge_mask != 0) &&
((need_fuel && (ai.active_recharge_mask & 2u)) ||
(need_shield && (ai.active_recharge_mask & 1u)) ||
(need_ammo && (ai.active_recharge_mask & 4u)));
bool charging_pit = on_needed_pad && (ai.ai_pit_stay_timer < 2.2f);
if (charging_pit) {
ai.ai_pit_stay_timer += dt;
} else if (ai.ai_pit_stay_timer > 0.0f) {
ai.ai_pit_stay_timer = 0.0f;
ai.ai_pit_cooldown = 8.0f;
ai.ai_seeking_pit = false;
if ((need_fuel || need_shield || need_ammo) && !level.pads.empty()) {
float best_d2 = 16.0f * 16.0f;
}
float spd = ai.speed_horizontal();
if (!ai.ai_anchor_init) {
ai.ai_progress_anchor = ai.curr_pose.pos;
ai.ai_anchor_init = true;
}
if (ai.race_time > 2.0f && !ai.finished) {
Vec2 da(ai.curr_pose.pos.x - ai.ai_progress_anchor.x,
ai.curr_pose.pos.z - ai.ai_progress_anchor.z);
if (da.len() >= 2.5f) {
ai.ai_progress_anchor = ai.curr_pose.pos;
ai.ai_progress_timer = 0.0f;
ai.ai_stuck_timer = 0.0f;
} else if (!charging_pit) {
ai.ai_progress_timer += dt;
if (spd < 1.8f) {
ai.ai_stuck_timer += dt;
} else {
ai.ai_stuck_timer = std::max(0.0f, ai.ai_stuck_timer - dt * 1.5f);
}
}
}
// Stage 2 Failsafe Track Recovery if trapped for >= 6.0s without progress
if (!charging_pit && ai.ai_progress_timer >= 6.0f && (!ai.is_human || ai.autopilot)) {
int rec_wp = find_clear_wp_in_range(-1, 2, false);
const auto& rw = level.main_waypoints[rec_wp];
if (Vec2(rw.x - ai.curr_pose.pos.x, rw.z - ai.curr_pose.pos.z).len() > 28.0f) {
rec_wp = find_clear_wp_in_range(0, n_wp - 1, false);
}
const auto& wp = level.main_waypoints[rec_wp];
const auto& wpn = level.main_waypoints[(rec_wp + 1) % n_wp];
float fy = 0.0f, cy = 1e6f;
level.sample_surface_and_ceiling(wp.x, wp.z, ai.curr_pose.pos.y, fy, cy);
ai.curr_pose.pos = Vec3(wp.x, fy + spec.hover_offset, wp.z);
ai.curr_pose.yaw = std::atan2(wpn.x - wp.x, wpn.z - wp.z);
ai.curr_pose.pitch = 0.0f;
ai.curr_pose.roll = 0.0f;
ai.vel = Vec3(0.0f, 0.0f, 0.0f);
float imp = 0.0f;
bool scr = false;
resolve_world_collisions(ai, level, imp, scr);
ai.prev_pose = ai.curr_pose;
ai.current_wp = rec_wp;
ai.ai_target_wp = (rec_wp + 1) % n_wp;
ai.ai_stuck_timer = 0.0f;
ai.ai_unstuck_timer = 0.0f;
ai.ai_progress_timer = 0.0f;
ai.ai_pit_stay_timer = 0.0f;
ai.ai_pit_cooldown = 8.0f;
ai.ai_seeking_pit = false;
ai.ai_progress_anchor = ai.curr_pose.pos;
ai.ai_anchor_init = true;
return out;
}
// Stage 1 Reverse-and-Turn Escape from tight corners/dead-end bays
if (ai.ai_unstuck_timer <= 0.0f && !charging_pit &&
(ai.ai_stuck_timer >= 0.85f || ai.ai_progress_timer >= 3.2f)) {
ai.ai_seeking_pit = false;
ai.ai_pit_cooldown = 8.0f;
Vec2 fwd_h(std::sin(ai.curr_pose.yaw), std::cos(ai.curr_pose.yaw));
Vec2 left_h(-fwd_h.y, fwd_h.x);
Vec2 cur_p(ai.curr_pose.pos.x, ai.curr_pose.pos.z);
float left_clear = 0.0f;
float right_clear = 0.0f;
for (float d = 1.0f; d <= 3.0f; d += 0.7f) {
Vec2 pl = cur_p - fwd_h * d + left_h * (d * 0.85f);
Vec2 pr = cur_p - fwd_h * d - left_h * (d * 0.85f);
if (!is_ai_blocked(pl.x, pl.y, ai.curr_pose.pos.y)) left_clear += 1.0f;
if (!is_ai_blocked(pr.x, pr.y, ai.curr_pose.pos.y)) right_clear += 1.0f;
}
ai.ai_unstuck_steer = (left_clear >= right_clear) ? -1.0f : 1.0f;
ai.ai_unstuck_timer = 0.85f;
ai.ai_stuck_timer = 0.0f;
Vec2 wp_pos_cur(level.main_waypoints[wp_idx].x, level.main_waypoints[wp_idx].z);
float cur_wp_dist = (wp_pos_cur - cur_p).len();
int fwd_wp = find_clear_wp_in_range(0, 2, true);
if (fwd_wp != wp_idx) {
Vec2 fwd_pos(level.main_waypoints[fwd_wp].x, level.main_waypoints[fwd_wp].z);
if ((fwd_pos - cur_p).len() < cur_wp_dist &&
has_clear_corridor(cur_p, fwd_pos, ai.curr_pose.pos.y)) {
ai.ai_target_wp = fwd_wp;
}
}
}
if (ai.ai_unstuck_timer > 0.0f) {
ai.ai_unstuck_timer = std::max(0.0f, ai.ai_unstuck_timer - dt);
out.steer = ai.ai_unstuck_steer;
out.throttle = 0.0f;
out.brake = 1.0f;
return out;
}
// Portal-safe forward waypoint advance
Vec2 cur_pos(ai.curr_pose.pos.x, ai.curr_pose.pos.z);
const auto& cur_wp = level.main_waypoints[wp_idx];
Vec2 cur_wp_pos(cur_wp.x, cur_wp.z);
float dist_to_wp = (cur_wp_pos - cur_pos).len();
int next_wp_idx = (wp_idx + 1) % n_wp;
Vec2 next_wp_pos(level.main_waypoints[next_wp_idx].x, level.main_waypoints[next_wp_idx].z);
Vec2 seg_to_next = next_wp_pos - cur_wp_pos;
float dist_to_next = (next_wp_pos - cur_pos).len();
bool passed_wp = ((cur_pos - cur_wp_pos).dot(seg_to_next) > 0.0f) &&
(dist_to_next < dist_to_wp) &&
has_clear_corridor(cur_pos, next_wp_pos, ai.curr_pose.pos.y);
if (dist_to_wp < 3.4f ||
(dist_to_wp < 5.2f && has_clear_corridor(cur_pos, next_wp_pos, ai.curr_pose.pos.y)) ||
passed_wp) {
wp_idx = next_wp_idx;
ai.ai_target_wp = wp_idx;
cur_wp_pos = next_wp_pos;
dist_to_wp = dist_to_next;
}
// Line-of-sight-validated pitstop detour
Vec2 tgt_pos = cur_wp_pos;
ai.ai_seeking_pit = false;
Vec2 wp_dir = (dist_to_wp > 1e-3f) ? ((cur_wp_pos - cur_pos) * (1.0f / dist_to_wp))
: Vec2(std::sin(ai.curr_pose.yaw), std::cos(ai.curr_pose.yaw));
if (ai.ai_pit_cooldown <= 0.0f && (need_fuel || need_shield || need_ammo) && !level.pads.empty()) {
float best_d2 = 14.0f * 14.0f;
for (const auto& pad : level.pads) {
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();
if (d2 < best_d2) {
Vec2 to_pad = p - cur_pos;
float d2 = to_pad.len_sq();
if (d2 >= best_d2 || d2 < 0.04f) continue;
if (to_pad.normalized().dot(wp_dir) <= 0.20f) continue;
if (!has_clear_corridor(cur_pos, p, ai.curr_pose.pos.y)) continue;
float pad_floor_y = level.sample_height_world(p.x, p.y) + spec.hover_offset;
if (!has_clear_corridor(p, cur_wp_pos, pad_floor_y)) continue;
best_d2 = d2;
tgt_pos = p;
ai.ai_seeking_pit = true;
}
}
}
auto is_ai_blocked = [&](float wx, float wz) -> bool {
int ix = static_cast<int>(std::floor(wx));
int iz = static_cast<int>(std::floor(wz));
float local_floor = 0.0f;
float local_ceil = 1e6f;
level.sample_surface_and_ceiling(wx, wz, ai.curr_pose.pos.y, local_floor, local_ceil);
float probe_y = local_floor + 0.28f;
return level.is_cell_solid_at_point(ix, iz, wx, wz, probe_y) ||
level.is_cliff_blocking_at_y(ix, iz, ai.curr_pose.pos.y);
};
// Spread AI racing lines gently so racers overtake instead of forming a single line
// Narrow-portal-safe racing line lane offset
if (!ai.ai_seeking_pit) {
const auto& nxt = level.main_waypoints[(wp_idx + 1) % n_wp];
Vec2 seg = Vec2(nxt.x - tgt_pos.x, nxt.z - tgt_pos.y).normalized();
Vec2 seg_vec(nxt.x - tgt_pos.x, nxt.z - tgt_pos.y);
float seg_len = seg_vec.len();
Vec2 seg = seg_vec.normalized();
Vec2 right(-seg.y, seg.x);
float lane = (static_cast<float>((ai.id % 5) - 2)) * 0.55f;
Vec2 shifted = tgt_pos + right * lane;
if (!is_ai_blocked(shifted.x, shifted.y)) {
float tgt_y = level.sample_height_world(shifted.x, shifted.y) + spec.hover_offset;
Vec2 margin_r = right * 1.15f;
Vec2 look_ahead = shifted + seg * std::min(5.0f, seg_len);
if (!is_ai_blocked(shifted.x + margin_r.x, shifted.y + margin_r.y, tgt_y) &&
!is_ai_blocked(shifted.x - margin_r.x, shifted.y - margin_r.y, tgt_y) &&
has_clear_corridor(cur_pos, shifted, ai.curr_pose.pos.y) &&
has_clear_corridor(shifted, look_ahead, tgt_y)) {
tgt_pos = shifted;
}
}
// Forward column-obstacle lookahead & lateral bypass lane selection
Vec2 cur_pos(ai.curr_pose.pos.x, ai.curr_pose.pos.z);
// Forward corridor lookahead & multi-angle fan obstacle avoidance
Vec2 to_tgt = tgt_pos - cur_pos;
float tgt_dist = to_tgt.len();
Vec2 base_dir = (tgt_dist > 1e-3f)
@@ -77,44 +286,34 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
: Vec2(std::sin(ai.curr_pose.yaw), std::cos(ai.curr_pose.yaw));
float hit_dist = -1.0f;
float max_probe = std::min(tgt_dist, 7.5f);
for (float d = 1.0f; d <= max_probe; d += 0.75f) {
float probe_y = ai.curr_pose.pos.y;
for (float d = 0.85f; d <= max_probe; d += 0.70f) {
Vec2 p = cur_pos + base_dir * d;
if (is_ai_blocked(p.x, p.y)) {
float nf = 0.0f, nc = 1e6f;
level.sample_surface_and_ceiling(p.x, p.y, probe_y, nf, nc);
if (nf > probe_y + 0.72f || is_ai_blocked(p.x, p.y, probe_y)) {
hit_dist = d;
break;
}
probe_y = nf + spec.hover_offset;
}
if (hit_dist > 0.0f) {
Vec2 perp(-base_dir.y, base_dir.x);
const float probe_ds[3] = {hit_dist * 0.5f, hit_dist, hit_dist + 2.0f};
const float offs[5] = {1.5f, 2.5f, 3.5f, 4.5f, 5.5f};
bool found_bypass = false;
float best_side = 1.0f;
float best_off = 3.5f;
for (float off : offs) {
for (float side : {-1.0f, 1.0f}) {
bool clear = true;
for (float pd : probe_ds) {
Vec2 p = cur_pos + base_dir * pd + perp * (side * off);
if (p.x < 2.0f || p.x > assets::kMapWidth - 3.0f ||
p.y < 2.0f || p.y > assets::kMapHeight - 3.0f ||
is_ai_blocked(p.x, p.y)) {
clear = false;
static constexpr std::array<float, 12> kFanAngles = {
0.314f, -0.314f, 0.628f, -0.628f, 0.960f, -0.960f,
1.309f, -1.309f, 1.745f, -1.745f, 2.269f, -2.269f
};
float fan_len = std::min(std::max(hit_dist + 2.5f, 4.5f), 7.5f);
for (float ang : kFanAngles) {
float ca = std::cos(ang);
float sa = std::sin(ang);
Vec2 cand_dir(base_dir.x * ca - base_dir.y * sa,
base_dir.x * sa + base_dir.y * ca);
Vec2 fan_end = cur_pos + cand_dir * fan_len;
if (has_clear_corridor(cur_pos, fan_end, ai.curr_pose.pos.y)) {
tgt_pos = fan_end;
break;
}
}
if (clear) {
best_side = side;
best_off = off;
found_bypass = true;
break;
}
}
if (found_bypass) break;
}
if (found_bypass) {
tgt_pos = cur_pos + base_dir * std::max(hit_dist, 2.5f) + perp * (best_side * (best_off + 0.6f));
}
}
// Craft avoidance repulsion
@@ -135,16 +334,18 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
out.steer = std::clamp(-err * 1.85f, -1.0f, 1.0f);
float diff_pace = (difficulty == 0) ? 0.78f : (difficulty == 2 ? 1.0f : 0.90f);
float spd = ai.speed_horizontal();
bool is_corner = (level.main_waypoints[wp_idx].subtype == 1);
if (hit_dist > 0.0f && hit_dist < 1.6f && spd < 1.2f && ai.race_time > 1.5f) {
if (charging_pit) {
out.throttle = (spd > 3.5f) ? 0.0f : 0.18f;
out.brake = (spd > 5.0f) ? 0.35f : 0.0f;
} else if (hit_dist > 0.0f && hit_dist < 1.6f && spd < 1.2f && ai.race_time > 1.5f) {
out.throttle = 0.0f;
out.brake = 0.65f;
} else if (std::abs(err) > 0.65f && spd > 9.5f) {
} else if (std::abs(err) > 0.65f && spd > spec.top_speed * 0.52f) {
out.throttle = 0.25f * diff_pace;
out.brake = 0.35f;
} else if (is_corner && spd > 13.0f * diff_pace) {
} else if (is_corner && spd > spec.top_speed * 0.72f * diff_pace) {
out.throttle = 0.50f * diff_pace;
} else {
out.throttle = diff_pace;
@@ -154,11 +355,14 @@ CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
}
}
// Combat AI: shoot opponents in sights!
// Combat AI: shoot visible opponents in sights!
if (ai.ammo > 5.0f) {
Vec3 fwd = ai.forward_dir();
for (const auto& other : all_crafts) {
if (other.id == ai.id || other.recovery_state != RecoveryState::Active) continue;
if (other.id == ai.id || other.recovery_state != RecoveryState::Active ||
other.invisible_timer > 0.0f) {
continue;
}
Vec3 to_e = other.curr_pose.pos - ai.curr_pose.pos;
float dist = to_e.len();
if (dist < 1.2f || dist > 22.0f) continue;
+2 -1
View File
@@ -10,6 +10,7 @@ namespace top_octane::sim {
// Computes autonomous steering, throttle, boost, pit detour, and weapon inputs for an AI craft
CraftInput compute_ai_input(CraftState& ai, const assets::LevelData& level,
const std::vector<CraftState>& all_crafts, int difficulty);
const std::vector<CraftState>& all_crafts, int difficulty,
float dt = 1.0f / 60.0f);
} // namespace top_octane::sim
+84 -33
View File
@@ -59,48 +59,61 @@ void apply_damage(CraftState& victim, int attacker_id, const std::vector<CraftSt
}
void apply_pickup(CraftState& c, uint8_t subtype, std::vector<SimEvent>& events) {
// Map Bullfrog type-5 subtypes to authentic Hi-Octane powerups
// Authentic HIOCTANE.EXE Type-5 subtype table (0..13 -> TMAPS 29..42)
const VehicleSpec& sp = kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)];
std::string msg;
SimSoundCue cue = SimSoundCue::Pickup;
switch (subtype) {
case 0:
c.invincible_timer = 15.0f;
msg = "INVINCIBLE";
cue = SimSoundCue::Powerup;
break;
case 1:
c.fuel = std::min(c.max_fuel, c.fuel + 35.0f);
msg = "FUEL";
c.invisible_timer = 15.0f;
msg = "INVISIBLE";
cue = SimSoundCue::Powerup;
break;
case 2:
c.max_fuel = std::min(220.0f, c.max_fuel + 25.0f);
c.fuel = c.max_fuel;
msg = "EXTRA FUEL";
cue = SimSoundCue::Powerup;
c.shield = std::min(c.max_shield, c.shield + std::max(25.0f, c.max_shield * 0.30f));
msg = "SHIELD EXTRA";
break;
case 3:
c.shield = std::min(c.max_shield, c.shield + 40.0f);
msg = "SHIELD";
c.shield = std::max(c.shield, c.max_shield);
msg = "SHIELD FULL";
break;
case 4:
case 5:
c.max_shield = std::min(260.0f, c.max_shield + 30.0f);
c.max_shield = std::max(c.max_shield, sp.max_shield * 2.0f);
c.shield = c.max_shield;
msg = "EXTRA SHIELD";
msg = "DOUBLE SHIELD";
cue = SimSoundCue::Powerup;
break;
case 5:
c.ammo = std::min(c.max_ammo, c.ammo + std::max(25.0f, c.max_ammo * 0.30f));
msg = "AMMO EXTRA";
break;
case 6:
case 7:
c.ammo = std::min(c.max_ammo, c.ammo + 45.0f);
msg = "AMMO";
c.ammo = std::max(c.ammo, c.max_ammo);
msg = "AMMO FULL";
break;
case 8:
case 9:
c.max_ammo = std::min(250.0f, c.max_ammo + 30.0f);
case 7:
c.max_ammo = std::max(c.max_ammo, sp.max_ammo * 2.0f);
c.ammo = c.max_ammo;
msg = "EXTRA AMMO";
msg = "DOUBLE AMMO";
cue = SimSoundCue::Powerup;
break;
case 8:
c.fuel = std::min(c.max_fuel, c.fuel + std::max(25.0f, c.max_fuel * 0.30f));
msg = "FUEL EXTRA";
break;
case 9:
c.fuel = std::max(c.fuel, c.max_fuel);
msg = "FUEL FULL";
break;
case 10:
c.booster_level = std::min(3, c.booster_level + 1);
c.fuel = std::min(c.max_fuel, c.fuel + 30.0f);
msg = "BOOSTER UPGRADED";
c.max_fuel = std::max(c.max_fuel, sp.max_fuel * 2.0f);
c.fuel = c.max_fuel;
msg = "DOUBLE FUEL";
cue = SimSoundCue::Powerup;
break;
case 11:
@@ -110,13 +123,18 @@ void apply_pickup(CraftState& c, uint8_t subtype, std::vector<SimEvent>& events)
cue = SimSoundCue::Powerup;
break;
case 12:
case 13:
default:
c.missile_level = std::min(3, c.missile_level + 1);
c.ammo = std::min(c.max_ammo, c.ammo + 35.0f);
msg = "MISSILE UPGRADED";
cue = SimSoundCue::Powerup;
break;
case 13:
default:
c.booster_level = std::min(3, c.booster_level + 1);
c.fuel = std::min(c.max_fuel, c.fuel + 35.0f);
msg = "BOOSTER UPGRADED";
cue = SimSoundCue::Powerup;
break;
}
events.push_back({cue, c.curr_pose.pos, c.is_human ? c.player_index : -1,
c.is_human ? msg : "", 0.25f});
@@ -278,15 +296,45 @@ void step_combat_and_world(
c.shield = c.max_shield;
c.fuel = c.max_fuel;
c.ammo = std::max(c.ammo, c.max_ammo * 0.5f);
// Place gently at nearest main waypoint if available
// Place cleanly at nearest clear main waypoint and resolve against morphed walls
if (!level.main_waypoints.empty()) {
const auto& wp = level.main_waypoints[c.current_wp % level.main_waypoints.size()];
const auto& wpn = level.main_waypoints[(c.current_wp + 1) % level.main_waypoints.size()];
c.curr_pose.pos = Vec3(wp.x, level.sample_height_world(wp.x, wp.z) + 0.45f, wp.z);
c.curr_pose.yaw = std::atan2(wpn.x - wp.x, wpn.z - wp.z);
c.prev_pose = c.curr_pose;
c.vel = Vec3(0, 0, 0);
size_t best_wp = 0;
float best_d2 = 1e18f;
for (size_t wi = 0; wi < level.main_waypoints.size(); ++wi) {
const auto& w = level.main_waypoints[wi];
float dx = w.x - c.curr_pose.pos.x;
float dz = w.z - c.curr_pose.pos.z;
float d2 = dx * dx + dz * dz;
if (d2 < best_d2) {
best_d2 = d2;
best_wp = wi;
}
}
const auto& wp = level.main_waypoints[best_wp];
const auto& wpn = level.main_waypoints[(best_wp + 1) % level.main_waypoints.size()];
const VehicleSpec& sp_rec = kVehicleSpecs[std::clamp(c.vehicle_idx, 0, 5)];
float fy = 0.0f, cy = 1e6f;
level.sample_surface_and_ceiling(wp.x, wp.z, c.curr_pose.pos.y, fy, cy);
c.curr_pose.pos = Vec3(wp.x, fy + sp_rec.hover_offset, wp.z);
c.curr_pose.yaw = std::atan2(wpn.x - wp.x, wpn.z - wp.z);
c.curr_pose.pitch = 0.0f;
c.curr_pose.roll = 0.0f;
c.vel = Vec3(0, 0, 0);
float dummy_imp = 0.0f;
bool dummy_scr = false;
resolve_world_collisions(c, level, dummy_imp, dummy_scr);
c.prev_pose = c.curr_pose;
c.current_wp = static_cast<int>(best_wp);
c.ai_target_wp = static_cast<int>((best_wp + 1) % level.main_waypoints.size());
}
c.ai_stuck_timer = 0.0f;
c.ai_unstuck_timer = 0.0f;
c.ai_progress_timer = 0.0f;
c.ai_pit_stay_timer = 0.0f;
c.ai_pit_cooldown = 0.0f;
c.ai_seeking_pit = false;
c.ai_progress_anchor = c.curr_pose.pos;
c.ai_anchor_init = true;
} else if (c.shield <= 0.1f) {
int rec_ticks = static_cast<int>(std::lround(c.recovery_timer * 60.0f));
if (rec_ticks % 4 == 0) {
@@ -329,7 +377,10 @@ void step_combat_and_world(
int best_tgt = -1;
float best_score = 0.72f; // ~44 deg half-cone
for (size_t j = 0; j < crafts.size(); ++j) {
if (i == j || crafts[j].recovery_state != RecoveryState::Active) continue;
if (i == j || crafts[j].recovery_state != RecoveryState::Active ||
crafts[j].invisible_timer > 0.0f) {
continue;
}
Vec3 to_tgt = crafts[j].curr_pose.pos - c.curr_pose.pos;
float dist = to_tgt.len();
if (dist < 1.0f || dist > 38.0f) continue;
@@ -487,7 +538,7 @@ void step_combat_and_world(
victim.is_human ? victim.player_index : -1, "", 0.20f});
}
if (setup.damage_enabled) {
if (setup.damage_enabled && victim.invincible_timer <= 0.0f) {
victim.shield -= pr.damage;
victim.armour_used += pr.damage;
if (victim.shield <= 0.0f) {
+3 -1
View File
@@ -354,6 +354,8 @@ CraftStepFeedback step_craft_physics(CraftState& craft, const CraftInput& input,
if (craft.minigun_cd > 0.0f) craft.minigun_cd = std::max(0.0f, craft.minigun_cd - dt);
if (craft.missile_cd > 0.0f) craft.missile_cd = std::max(0.0f, craft.missile_cd - dt);
if (craft.boost_cooldown > 0.0f) craft.boost_cooldown = std::max(0.0f, craft.boost_cooldown - dt);
if (craft.invincible_timer > 0.0f) craft.invincible_timer = std::max(0.0f, craft.invincible_timer - dt);
if (craft.invisible_timer > 0.0f) craft.invisible_timer = std::max(0.0f, craft.invisible_timer - dt);
if (craft.refuel_sound_cd > 0.0f) craft.refuel_sound_cd = std::max(0.0f, craft.refuel_sound_cd - dt);
// Steering & banking
@@ -436,7 +438,7 @@ CraftStepFeedback step_craft_physics(CraftState& craft, const CraftInput& input,
}
// Sub-stepped integration + column/wall collision (horizontal pushout BEFORE floor sampling!)
constexpr int kSubSteps = 2;
constexpr int kSubSteps = 3;
float sub_dt = dt / static_cast<float>(kSubSteps);
for (int s = 0; s < kSubSteps; ++s) {
craft.curr_pose.pos.x += craft.vel.x * sub_dt;
+10
View File
@@ -57,6 +57,8 @@ struct CraftState {
float missile_cd = 0.0f;
float boost_timer = 0.0f;
float boost_cooldown = 0.0f;
float invincible_timer = 0.0f;
float invisible_timer = 0.0f;
float damage_flash = 0.0f;
int lock_target_id = -1;
float lock_progress = 0.0f;
@@ -96,6 +98,14 @@ struct CraftState {
float ai_fire_delay = 0.0f;
bool ai_seeking_pit = false;
int ai_pit_pad_idx = -1;
float ai_stuck_timer = 0.0f;
float ai_unstuck_timer = 0.0f;
float ai_unstuck_steer = 1.0f;
float ai_pit_cooldown = 0.0f;
float ai_pit_stay_timer = 0.0f;
Vec3 ai_progress_anchor{0.0f, 0.0f, 0.0f};
float ai_progress_timer = 0.0f;
bool ai_anchor_init = false;
float speed_horizontal() const {
return std::sqrt(vel.x * vel.x + vel.z * vel.z);
+10 -4
View File
@@ -172,6 +172,8 @@ bool RaceSim::start_race(const assets::LevelData& level, const RaceSetup& setup,
c.ammo = c.max_ammo = sp.max_ammo;
c.placement = id + 1;
c.ai_target_wp = level_.main_waypoints.size() > 1 ? 1 : 0;
c.ai_progress_anchor = pose.pos;
c.ai_anchor_init = true;
return c;
};
@@ -344,13 +346,13 @@ void RaceSim::step(const CraftInput& p1_input, const CraftInput& p2_input, float
c.autopilot ? "AUTO PILOT ON" : "AUTO PILOT OFF", 0.0f});
}
if (c.autopilot) {
CraftInput ai_in = compute_ai_input(c, level_, crafts_, setup_.difficulty);
CraftInput ai_in = compute_ai_input(c, level_, crafts_, setup_.difficulty, dt);
in.steer = ai_in.steer;
in.throttle = ai_in.throttle;
in.brake = ai_in.brake;
}
} else {
in = compute_ai_input(c, level_, crafts_, setup_.difficulty);
in = compute_ai_input(c, level_, crafts_, setup_.difficulty, dt);
}
inputs[i] = in;
@@ -522,8 +524,8 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
}
}
// Wrong way detection via nearest main waypoint forward dot product
if (level_.main_waypoints.size() >= 2 && c.speed_horizontal() > 3.0f) {
// Track nearest main waypoint continuously; flag wrong-way when moving against circuit
if (level_.main_waypoints.size() >= 2) {
size_t best_wp = 0;
float best_d2 = 1e18f;
for (size_t i = 0; i < level_.main_waypoints.size(); ++i) {
@@ -536,11 +538,15 @@ void RaceSim::update_checkpoints_and_laps(CraftState& c, float dt) {
}
}
c.current_wp = static_cast<int>(best_wp);
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();
Vec2 vel_dir = Vec2(c.vel.x, c.vel.z).normalized();
c.wrong_way = (track_dir.dot(vel_dir) < -0.55f);
} else {
c.wrong_way = false;
}
}
}
+14 -12
View File
@@ -32,19 +32,21 @@ struct VehicleSpec {
float hover_offset; // vertical center offset above road surface
};
inline constexpr float kGlobalSpeedGaugeMax = 33.5f;
inline constexpr std::array<VehicleSpec, 6> kVehicleSpecs = {{
// 0: KD-1 Speeder (CAR) - Well-rounded standard hovercar
{"KD-1 SPEEDER", "CAR0-", 5, 5, 7, 5, 1.00f, 18.5f, 19.0f, 10.0f, 7.5f, 2.55f, 4.6f, 100.0f, 100.0f, 100.0f, 9.0f, 42.0f, 0.72f, 0.48f, 0.28f},
// 1: Beserker (TANK) - Heavy assault craft
{"BESERKER", "TANK0-", 8, 8, 5, 8, 1.35f, 16.5f, 16.0f, 9.0f, 6.5f, 2.15f, 5.0f, 110.0f, 135.0f, 125.0f, 12.0f, 54.0f, 0.36f, 0.56f, 0.26f},
// 2: Jugga (JUGGA) - Maximum armour & firepower juggernaut
{"JUGGA", "JUGGA0-",10,10, 4,10, 1.65f, 15.2f, 14.2f, 8.0f, 6.0f, 1.90f, 5.2f, 125.0f, 165.0f, 150.0f, 14.0f, 62.0f, 0.42f, 0.60f, 0.28f},
// 3: Vampyr (JET) - Top speed interceptor
{"VAMPYR", "JET0-", 4, 4,10, 7, 0.85f, 21.0f, 21.5f, 11.0f, 8.8f, 2.75f, 4.1f, 95.0f, 90.0f, 110.0f, 11.0f, 48.0f, 0.44f, 0.50f, 0.30f},
// 4: Outrider (BIKE) - Ultra-nimble light hoverbike
{"OUTRIDER", "BIKE0-", 2, 3, 9, 4, 0.70f, 19.8f, 23.0f, 12.0f, 8.2f, 3.25f, 4.8f, 90.0f, 80.0f, 90.0f, 8.0f, 38.0f, 0.68f, 0.42f, 0.22f},
// 5: Flexiwing (SKIM) - Balanced high-grip glider
{"FLEXIWING", "SKIM0-", 6, 6, 8, 6, 1.05f, 19.0f, 19.8f, 10.5f, 7.6f, 2.70f, 5.6f, 105.0f, 115.0f, 105.0f, 10.0f, 45.0f, 0.36f, 0.52f, 0.26f},
// 0: KD-1 Speeder (CAR) - Well-rounded standard hovercar (stat_speed=7)
{"KD-1 SPEEDER", "CAR0-", 5, 5, 7, 5, 1.00f, 18.9f, 19.5f, 10.0f, 7.9f, 2.55f, 4.6f, 100.0f, 100.0f, 100.0f, 9.0f, 42.0f, 0.72f, 0.48f, 0.28f},
// 1: Beserker (TANK) - Heavy assault craft (stat_speed=5)
{"BESERKER", "TANK0-", 8, 8, 5, 8, 1.35f, 15.9f, 16.2f, 9.0f, 6.7f, 2.15f, 5.0f, 110.0f, 135.0f, 125.0f, 12.0f, 54.0f, 0.36f, 0.56f, 0.26f},
// 2: Jugga (JUGGA) - Maximum armour & firepower juggernaut (stat_speed=4)
{"JUGGA", "JUGGA0-",10,10, 4,10, 1.65f, 14.4f, 14.2f, 8.0f, 6.1f, 1.90f, 5.2f, 125.0f, 165.0f, 150.0f, 14.0f, 62.0f, 0.42f, 0.60f, 0.28f},
// 3: Vampyr (JET) - Top speed interceptor (stat_speed=10)
{"VAMPYR", "JET0-", 4, 4,10, 7, 0.85f, 23.4f, 23.0f, 11.0f, 9.8f, 2.75f, 4.1f, 95.0f, 90.0f, 110.0f, 11.0f, 48.0f, 0.44f, 0.50f, 0.30f},
// 4: Outrider (BIKE) - Ultra-nimble light hoverbike (stat_speed=9)
{"OUTRIDER", "BIKE0-", 2, 3, 9, 4, 0.70f, 21.9f, 24.0f, 12.0f, 9.2f, 3.25f, 4.8f, 90.0f, 80.0f, 90.0f, 8.0f, 38.0f, 0.68f, 0.42f, 0.22f},
// 5: Flexiwing (SKIM) - Balanced high-grip glider (stat_speed=8)
{"FLEXIWING", "SKIM0-", 6, 6, 8, 6, 1.05f, 20.4f, 21.0f, 10.5f, 8.6f, 2.70f, 5.6f, 105.0f, 115.0f, 105.0f, 10.0f, 45.0f, 0.36f, 0.52f, 0.26f},
}};
inline constexpr std::array<const char*, 8> kTeamNames = {{
+52
View File
@@ -189,6 +189,58 @@ int main() {
CHECK(load_raw_screen(vfs, "DATA/ONET0-1.DAT", 640, 480, pal, onet_img));
std::cout << "[PASS] 12 Sprite/Font Banks & 3 Raw Screens validated\n";
// 4b. World Billboard Texture Bank (DATA/TMAPS.DAT + DATA/TMAPS.TAB)
{
TmapBank tmaps;
CHECK(tmaps.load(vfs, pal));
CHECK(tmaps.sprites.size() == 48);
for (uint8_t sub = 0; sub <= 13; ++sub) {
int tid = pickup_tmap_index(sub);
CHECK(tid >= 29 && tid <= 42);
const auto& sp = tmaps.sprites[static_cast<size_t>(tid)];
CHECK(sp.width > 0 && sp.height > 0);
bool any_opaque = false;
for (size_t p = 3; p < sp.rgba.size(); p += 4) {
if (sp.rgba[p] > 0) {
any_opaque = true;
break;
}
}
CHECK(any_opaque);
}
std::cout << "[PASS] TMAPS.DAT/TAB (48 world billboard textures & 14 pickup icons) validated\n";
}
// 4c. Bullfrog Revision Upgrade Pack Assets (PANEL9-*, TRACK0-0/1, TEXTU0-6..8, TABLE0-7..8, LEVEL0-7..9)
{
for (const char* pbn : {"PANEL9-0", "PANEL9-1"}) {
SpriteBank psb;
std::string base = std::string("DATA/") + pbn;
CHECK(psb.load(vfs, base + ".DAT", base + ".TAB", pal));
CHECK(psb.sprites.size() == 310);
}
SpriteBank trk0, trk1;
CHECK(trk0.load(vfs, "DATA/TRACK0-0.DAT", "DATA/TRACK0-0.TAB", pal));
CHECK(trk1.load(vfs, "DATA/TRACK0-1.DAT", "DATA/TRACK0-1.TAB", pal));
CHECK(trk0.sprites.size() >= 10);
CHECK(trk1.sprites.size() >= 16);
auto check_unpacked_size = [&](const std::string& rel, size_t expected_bytes) -> bool {
std::vector<uint8_t> raw, dec;
return vfs.read_file(rel, raw) && rnc_unpack(raw, dec) && dec.size() == expected_bytes;
};
for (int t = 6; t <= 8; ++t) {
CHECK(check_unpacked_size("DATA/TEXTU0-" + std::to_string(t) + ".DAT", 256u * 64u * 64u));
}
for (int t = 7; t <= 8; ++t) {
CHECK(check_unpacked_size("DATA/TABLE0-" + std::to_string(t) + ".DAT", 83968u));
}
for (int l = 7; l <= 9; ++l) {
CHECK(check_unpacked_size("MAPS/LEVEL0-" + std::to_string(l) + ".DAT", 896140u));
}
std::cout << "[PASS] Revision Upgrade Pack assets (PANEL9-*, TRACK0-0/1, TEXTU0-6..8, TABLE0-7..8, LEVEL0-7..9) validated\n";
}
// 5. Optional Intro FLIC movie (all 548 frames when DATA/INTRO.DAT is present)
if (vfs.exists("DATA/INTRO.DAT")) {
FlicPlayer flic;
+133 -8
View File
@@ -202,7 +202,7 @@ int main() {
// 6. Authentic Sector Morphing across all 6 levels (Timed, Craft, Rocket triggers + columns/lights/pickups)
{
const size_t expected_morph_counts[6] = {1, 2, 5, 2, 7, 6};
const size_t expected_morph_counts[6] = {1, 3, 5, 6, 7, 6};
for (int l = 1; l <= 6; ++l) {
assets::LevelData lvl;
CHECK(lvl.load(vfs, l));
@@ -292,7 +292,7 @@ int main() {
CHECK(!msim.level().is_cell_solid_at_point(67, 63, 67.5f, 63.5f, col_y));
}
// 6d. Level 4: Rocket id=153 collapses reactor (68,75) & unlocks grp=10 pickups; Craft id=256 + Rocket id=40 open bunker ONCE
// 6d. Level 4: Rocket id=153 collapses reactor wall (69,83) & unlocks grp=10 pickups; Craft id=256 + Rocket id=40 open bunker ONCE
{
assets::LevelData lvl4;
CHECK(lvl4.load(vfs, 4));
@@ -301,8 +301,8 @@ int main() {
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl4, ms));
CHECK(msim.level().cell(68, 75).height == 3360);
CHECK(msim.level().cell(43, 114).tex_or_col == -172);
CHECK(msim.level().cell(69, 83).height == 2992);
CHECK(msim.level().cell(43, 114).tex_or_col == -168);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
auto& p1 = msim.crafts_mut()[0];
@@ -315,7 +315,7 @@ int main() {
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
}
CHECK(msim.level().cell(68, 75).height == 2048);
CHECK(msim.level().cell(69, 83).height == 2048);
bool g10_unlocked = false;
for (const auto& pk : msim.pickups()) {
if (pk.group == 10) {
@@ -330,7 +330,7 @@ int main() {
p1.curr_pose.pos = Vec3(44.5f, msim.level().sample_height_world(44.5f, 49.5f) + 0.30f, 49.5f);
p1.prev_pose = p1.curr_pose;
for (int t = 0; t < 40; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
CHECK(msim.level().cell(43, 114).tex_or_col == -171);
CHECK(msim.level().cell(43, 114).tex_or_col == -167);
p1.curr_pose.pos = Vec3(44.5f, msim.level().sample_height_world(44.5f, 117.0f) + 0.30f, 117.0f);
p1.curr_pose.yaw = kPi;
@@ -342,7 +342,7 @@ int main() {
fire.fire_missile = (t == 0);
msim.step(fire, CraftInput{}, dt);
}
CHECK(msim.level().cell(43, 114).tex_or_col == -171);
CHECK(msim.level().cell(43, 114).tex_or_col == -167);
}
// 6e. Level 5: Rocket id=286 blasts pillar (70,81); Craft id=275 starts blinking tunnel lights at (10,25)
@@ -354,7 +354,7 @@ int main() {
ms.num_ai = 0;
sim::RaceSim msim;
CHECK(msim.start_race(lvl5, ms));
CHECK(msim.level().cell(70, 81).tex_or_col == -53);
CHECK(msim.level().cell(70, 81).tex_or_col == -60);
CHECK(msim.level().cell(10, 25).illumination == 12800);
for (int t = 0; t < 200; ++t) msim.step(CraftInput{}, CraftInput{}, dt);
@@ -930,5 +930,130 @@ int main() {
}
std::cout << "[PASS] Original explosions, smoke trails, wreck plumes & steam vents validated\n";
// 10. Authentic Type-5 Pickup Subtypes (upgrades, double caps, invincible, invisible)
{
assets::LevelData flat_lvl;
flat_lvl.map.resize(assets::kMapWidth * assets::kMapHeight);
for (auto& m : flat_lvl.map) {
m.height = 2048;
m.tex_or_col = 0;
}
sim::RaceSetup ps;
ps.mode = sim::GameMode::DeathMatch;
ps.track_number = 1;
ps.num_ai = 1;
ps.damage_enabled = true;
ps.weapons_enabled = true;
std::vector<sim::CraftState> crafts(2);
crafts[0].id = 0;
crafts[0].vehicle_idx = 0;
crafts[0].curr_pose.pos = Vec3(50.0f, 0.28f, 50.0f);
crafts[0].prev_pose = crafts[0].curr_pose;
crafts[0].fuel = 20.0f;
crafts[0].shield = 20.0f;
crafts[0].ammo = 20.0f;
crafts[1].id = 1;
crafts[1].vehicle_idx = 0;
crafts[1].curr_pose.pos = Vec3(50.0f, 0.28f, 44.0f);
crafts[1].curr_pose.yaw = 0.0f; // facing +Z toward craft 0
crafts[1].prev_pose = crafts[1].curr_pose;
std::vector<sim::PickupItem> pks;
for (uint8_t sub = 0; sub <= 13; ++sub) {
sim::PickupItem pk;
pk.entity_id = static_cast<uint16_t>(sub + 1);
pk.subtype = sub;
pk.group = 1;
pk.group_unlocked = true;
pk.active = true;
pk.pos = Vec3(50.0f, 0.30f, 50.0f);
pks.push_back(pk);
}
std::vector<sim::PropObject> props;
std::vector<sim::ParticleBurst> parts;
std::vector<sim::SimEvent> evs;
std::vector<sim::Projectile> projs;
bool ro = false;
int wid = -1;
std::vector<CraftInput> ins(2);
sim::step_combat_and_world(ps, flat_lvl, crafts, ins, projs, pks, props, parts, evs, ro, wid, dt);
CHECK(crafts[0].invincible_timer > 10.0f);
CHECK(crafts[0].invisible_timer > 10.0f);
CHECK(crafts[0].max_shield >= 199.0f && crafts[0].shield >= 199.0f);
CHECK(crafts[0].max_ammo >= 199.0f && crafts[0].ammo >= 199.0f);
CHECK(crafts[0].max_fuel >= 199.0f && crafts[0].fuel >= 199.0f);
CHECK(crafts[0].minigun_level == 2);
CHECK(crafts[0].missile_level == 2);
CHECK(crafts[0].booster_level == 2);
// Invisible blocks lock-on; Invincible blocks projectile damage
crafts[1].lock_target_id = 0;
crafts[1].lock_progress = 0.8f;
float inv_sh = crafts[0].shield;
ins[1].fire_minigun = true;
for (int t = 0; t < 15; ++t) {
sim::step_combat_and_world(ps, flat_lvl, crafts, ins, projs, pks, props, parts, evs, ro, wid, dt);
CHECK(crafts[1].lock_target_id == -1);
CHECK(crafts[1].lock_progress == 0.0f);
}
CHECK(crafts[0].shield == inv_sh);
}
std::cout << "[PASS] Authentic pickup subtypes (upgrades, double caps, invincible, invisible) validated\n";
// 11. Full 8-racer AI anti-stuck & progression check across all 6 tracks
for (int l = 1; l <= 6; ++l) {
assets::LevelData lvl;
CHECK(lvl.load(vfs, l));
sim::RaceSetup ms;
ms.mode = sim::GameMode::SingleRace;
ms.track_number = l;
ms.total_laps = 2;
ms.difficulty = 1; // Medium AI with full combat, pitstops, morphing & pickups
ms.num_ai = 7;
sim::RaceSim msim;
CHECK(msim.start_race(lvl, ms));
msim.crafts_mut()[0].autopilot = true;
int stalled_ticks[8]{};
int max_stalled_ticks[8]{};
for (int t = 0; t < 9000 && !msim.race_finished(); ++t) {
msim.step(CraftInput{}, CraftInput{}, dt);
if (msim.countdown_active()) continue;
for (size_t i = 0; i < msim.crafts().size(); ++i) {
const auto& c = msim.crafts()[i];
if (c.recovery_state == sim::RecoveryState::Active) {
int cx = static_cast<int>(std::floor(c.curr_pose.pos.x));
int cz = static_cast<int>(std::floor(c.curr_pose.pos.z));
CHECK(!msim.level().is_cell_solid_at_point(
cx, cz, c.curr_pose.pos.x, c.curr_pose.pos.z, c.curr_pose.pos.y));
}
if (c.finished || c.recovery_state != sim::RecoveryState::Active ||
c.active_recharge_mask != 0) {
stalled_ticks[i] = 0;
continue;
}
if (c.speed_horizontal() < 1.5f && c.race_time > 2.0f) {
stalled_ticks[i]++;
max_stalled_ticks[i] = std::max(max_stalled_ticks[i], stalled_ticks[i]);
} else {
stalled_ticks[i] = 0;
}
}
}
int progressed = 0;
for (size_t i = 0; i < msim.crafts().size(); ++i) {
const auto& c = msim.crafts()[i];
CHECK(max_stalled_ticks[i] < 420); // never stuck >= 7.0 seconds
CHECK(c.checkpoints_passed >= 4);
if (c.finished || c.lap >= 2) ++progressed;
}
CHECK(progressed >= 6);
}
std::cout << "[PASS] All 6 tracks 8-racer AI anti-stuck & progression validated\n";
return 0;
}
+51 -6
View File
@@ -381,23 +381,23 @@ int main() {
CHECK(c.curr_pose.pos.y >= deck_y + 0.14f);
}
// 9c. Sheer terrain cliff blocking (Level 1 z=58..59) vs downhill drop clearance (Level 5 (22,99))
// 9c. Sheer terrain cliff blocking (Level 1 x=34..35) vs downhill drop clearance (Level 5 (22,99))
{
sim::CraftState cliff_car;
cliff_car.id = 0;
cliff_car.vehicle_idx = 0;
cliff_car.curr_pose.pos = Vec3(28.5f, lvl1.sample_height_world(28.5f, 57.5f) + 0.28f, 57.5f);
cliff_car.curr_pose.yaw = 0.0f;
cliff_car.curr_pose.pos = Vec3(32.5f, lvl1.sample_height_world(32.5f, 57.5f) + 0.28f, 57.5f);
cliff_car.curr_pose.yaw = kHalfPi;
cliff_car.prev_pose = cliff_car.curr_pose;
cliff_car.vel = Vec3(0.0f, 0.0f, 14.0f);
cliff_car.vel = Vec3(14.0f, 0.0f, 0.0f);
cliff_car.fuel = cliff_car.max_fuel = 100.0f;
CraftInput in;
in.throttle = 1.0f;
for (int t = 0; t < 40; ++t) {
sim::step_craft_physics(cliff_car, in, lvl1, dt, false);
}
CHECK(cliff_car.curr_pose.pos.z < 58.65f);
CHECK(cliff_car.curr_pose.pos.y < 1.0f);
CHECK(cliff_car.curr_pose.pos.x < 33.85f);
CHECK(cliff_car.curr_pose.pos.y < 0.0f);
sim::CraftState drop_car;
drop_car.id = 0;
@@ -434,5 +434,50 @@ int main() {
trapped.curr_pose.pos.y));
}
std::cout << "[PASS] Sloped column, overpass deck, cliff wall, downhill drop & escape verified\n";
// 10. Verify all 6 vehicles accelerate to strictly distinct stat-ordered cruise and boost top speeds
{
assets::LevelData flat_lvl;
flat_lvl.map.resize(assets::kMapWidth * assets::kMapHeight);
for (auto& m : flat_lvl.map) {
m.height = 2048;
m.tex_or_col = 0;
}
float dt = static_cast<float>(FixedStepClock::kFixedDt);
auto measure_max_speed = [&](int veh_idx, bool with_boost) -> float {
sim::CraftState c;
c.id = 0;
c.vehicle_idx = veh_idx;
c.curr_pose.pos = Vec3(15.0f, 0.28f, 80.0f);
c.curr_pose.yaw = kHalfPi;
c.prev_pose = c.curr_pose;
c.fuel = c.max_fuel = 1000.0f;
c.shield = c.max_shield = 100.0f;
CraftInput in;
in.throttle = 1.0f;
in.boost = with_boost;
for (int t = 0; t < 270; ++t) { // 4.5 seconds unobstructed +X run (kMapWidth = 256)
sim::step_craft_physics(c, in, flat_lvl, dt, false);
}
return c.speed_horizontal();
};
// Ordered strictly from lowest stat_speed to highest: Jugga(4) < Beserker(5) < Speeder(7) < Flexiwing(8) < Outrider(9) < Vampyr(10)
constexpr int kSpeedOrder[6] = {2, 1, 0, 5, 4, 3};
float cruise[6]{};
float boosted[6]{};
for (int v = 0; v < 6; ++v) {
cruise[v] = measure_max_speed(v, false);
boosted[v] = measure_max_speed(v, true);
}
for (int k = 0; k < 5; ++k) {
int va = kSpeedOrder[k];
int vb = kSpeedOrder[k + 1];
CHECK(cruise[vb] - cruise[va] >= 1.2f);
CHECK(boosted[vb] - boosted[va] >= 1.8f);
}
CHECK(cruise[3] - cruise[2] >= 8.5f); // Vampyr vs Jugga
std::cout << "[PASS] Vehicle top speeds & boost velocities strictly differentiate all 6 crafts\n";
}
return 0;
}