From ca0fae58475246eb4e11b93562e6495f797bb986 Mon Sep 17 00:00:00 2001 From: dandovlatov Date: Wed, 25 Nov 2026 01:06:26 +0400 Subject: [PATCH] FBC: NIGHT SHIFT - skill debris surfaces, reliable WARP and opt-in tracing - Skills shake nearby shelves, tables and garbage cans into paper + rock debris; props stay intact, destroyed bins stop shedding, and rock debris can originate from prop surfaces - Manual K always casts WARP (field drops ahead of the agent when no crowd is in range); autoplay still waits for a real target - Add opt-in --trace categories for silent skill decisions, debris bursts, input and consumed events, with zero cost when disabled - Add debris_surface_wiring and debug_trace_toggle regression tests --- CMakeLists.txt | 18 +++++++ README.md | 9 +++- src/core/debug.cpp | 82 +++++++++++++++++++++++++++++++ src/core/debug.hpp | 33 +++++++++++++ src/game/skills.cpp | 72 ++++++++++++++++++++++----- src/level/level_data.cpp | 15 ++++++ src/level/level_data.hpp | 3 ++ src/main.cpp | 10 ++++ src/render/debris.cpp | 18 +++++-- src/render/debris.hpp | 4 ++ src/render/dressing.cpp | 36 ++++++++++++-- src/render/dressing.hpp | 15 ++++++ src/render/presenter.cpp | 34 +++++++++++++ src/render/presenter.hpp | 3 ++ tests/debris_test.cpp | 103 +++++++++++++++++++++++++++++++++++++++ tests/debug_test.cpp | 46 +++++++++++++++++ tests/skills_test.cpp | 37 ++++++++++++++ 17 files changed, 517 insertions(+), 21 deletions(-) create mode 100644 src/core/debug.cpp create mode 100644 src/core/debug.hpp create mode 100644 tests/debris_test.cpp create mode 100644 tests/debug_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 91318da..dc41a4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,7 @@ FetchContent_Declare(raylib FetchContent_MakeAvailable(raylib) add_library(level_core STATIC + src/core/debug.cpp src/level/json.cpp src/level/level_data.cpp src/level/asset_catalog.cpp @@ -35,6 +36,10 @@ add_executable(level_core_test tests/level_core_test.cpp) target_link_libraries(level_core_test PRIVATE level_core) add_test(NAME level_core_test COMMAND level_core_test) +add_executable(debug_test tests/debug_test.cpp) +target_link_libraries(debug_test PRIVATE level_core) +add_test(NAME debug_trace_toggle COMMAND debug_test) + # Simulation-only test: the player must keep moving through enemy contact. set(GAME_SIM_SOURCES src/game/blackout.cpp @@ -64,6 +69,19 @@ target_link_libraries(blackout_test PRIVATE level_core) add_dependencies(blackout_test bake_level) add_test(NAME blackout_ritual COMMAND blackout_test) +# Presentation-only debris wiring: proves shelves/tables/bins expose surface +# origins and both debris systems can burst from them without GL context. +add_executable(debris_test tests/debris_test.cpp + src/game/floor.cpp + src/render/dressing.cpp + src/render/debris.cpp + src/render/box_batch.cpp + src/render/models.cpp + src/render/profiler.cpp) +target_link_libraries(debris_test PRIVATE raylib level_core) +add_dependencies(debris_test bake_level) +add_test(NAME debris_surface_wiring COMMAND debris_test) + set(LEVEL_JSON ${CMAKE_SOURCE_DIR}/assets/levels/floor01.json) set(BAKED_HPP ${CMAKE_SOURCE_DIR}/src/game/level_baked.hpp) add_custom_command( diff --git a/README.md b/README.md index f3e55b7..d5dd65a 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,11 @@ becomes your permanent skill for the run (Mega Man structure, Control skin). Active skills — CONCRETE CALL (`[J]`, hurls rubble at a crowd) and WARP (`[K]`, magnetizes enemies together before collapsing them) — also **autoplay** when the player isn't pressing their keys; pressing one takes manual control -briefly, and `[L]` switches autoplay off entirely. The HUD stamps show both -cooldowns and the shared mode. +briefly, and `[L]` switches autoplay off entirely. A manual `[K]` always fires — +with no crowd in range the warp field drops just ahead of you. The HUD stamps +show both cooldowns and the shared mode. Every skill shakes nearby shelves, tables and +garbage cans into paper + rock debris; the props stay intact (area blasts can +still destroy loose litter outright). **Difficulty:** Risk of Rain 2-style continuous *Corruption* scaling — the clock is the enemy. See `docs/GAME_DESIGN.md`. **Projector-screen blackout:** walk into the Projector Room's big screen and the @@ -79,6 +82,8 @@ Dev tools: `--bot` (kiting autopilot), `--no-damage` (stress mode), `--room-test` (frozen look at the new open-plan room), `--aoe-test` (repeating area blasts in the open-plan room for litter/destruction VFX look-dev), `--floor-overview` (whole-floor overhead dev camera for the Floor 01 blockout), +`--trace skills,debris,input,events` (or `--trace all`) for opt-in diagnostic +traces of silent skill/targeting decisions, debris bursts and consumed events, `--plaza-test` (start in the central plaza hub scene), `--office-test` (start in the office suite and inspect its destructible paper/bins), `--blackout-test` (start inside the projector screen), `--blackout-auto` diff --git a/src/core/debug.cpp b/src/core/debug.cpp new file mode 100644 index 0000000..9d39a1f --- /dev/null +++ b/src/core/debug.cpp @@ -0,0 +1,82 @@ +#include "core/debug.hpp" + +#include +#include +#include + +namespace debug { +namespace { + +unsigned g_mask = None; + +struct NamedCategory { + const char* name; + Category bit; +}; + +constexpr NamedCategory kCategories[] = { + {"skills", Skills}, {"debris", Debris}, {"input", Input}, + {"events", Events}, {"all", All}, +}; + +const char* category_name(Category cat) { + for (const NamedCategory& c : kCategories) { + if (c.bit == cat) return c.name; + } + return "mixed"; +} + +} // namespace + +void set_mask(unsigned mask_value) { g_mask = mask_value; } +unsigned mask() { return g_mask; } +bool enabled(Category cat) { return (g_mask & static_cast(cat)) != 0; } + +bool parse(const char* text, unsigned& out_mask) { + if (text == nullptr || *text == '\0') { + out_mask = None; + return true; + } + unsigned parsed = None; + std::string token; + for (const char* p = text;; ++p) { + const bool end = (*p == ',' || *p == '\0'); + if (end && !token.empty()) { + const std::size_t first = token.find_first_not_of(" \t"); + const std::size_t last = token.find_last_not_of(" \t"); + const std::string name = first == std::string::npos + ? std::string() + : token.substr(first, last - first + 1); + bool found = false; + for (const NamedCategory& c : kCategories) { + if (name == c.name) { + parsed |= static_cast(c.bit); + found = true; + break; + } + } + if (!found) { + std::fprintf(stderr, + "debug: unknown category '%s' (skills,debris,input,events,all)\n", + name.c_str()); + return false; + } + token.clear(); + } + if (*p == '\0') break; + if (!end) token.push_back(*p); + } + out_mask = parsed; + return true; +} + +void trace(Category cat, const char* fmt, ...) { + std::fprintf(stderr, "[dbg:%s] ", category_name(cat)); + va_list args; + va_start(args, fmt); + std::vfprintf(stderr, fmt, args); + va_end(args); + std::fputc('\n', stderr); +} + +} // namespace debug diff --git a/src/core/debug.hpp b/src/core/debug.hpp new file mode 100644 index 0000000..8a04c73 --- /dev/null +++ b/src/core/debug.hpp @@ -0,0 +1,33 @@ +#pragma once + +// Opt-in tracing for decisions that would otherwise fail silently. Off by +// default and free when disabled: DEBUG_TRACE skips even formatting. Enable +// with `--trace skills,debris,input,events` (or `--trace all`). +namespace debug { + +enum Category : unsigned { + None = 0, + Skills = 1u << 0, + Debris = 1u << 1, + Input = 1u << 2, + Events = 1u << 3, + All = Skills | Debris | Input | Events, +}; + +void set_mask(unsigned mask); +unsigned mask(); +bool enabled(Category cat); + +// Parses a comma-separated category list. On an unknown name, writes a warning +// to stderr, returns false and leaves `out_mask` untouched. +bool parse(const char* text, unsigned& out_mask); + +void trace(Category cat, const char* fmt, ...); + +} // namespace debug + +#define DEBUG_TRACE(cat, ...) \ + do { \ + if (::debug::enabled(cat)) \ + ::debug::trace(cat, __VA_ARGS__); \ + } while (0) diff --git a/src/game/skills.cpp b/src/game/skills.cpp index d094480..c25c469 100644 --- a/src/game/skills.cpp +++ b/src/game/skills.cpp @@ -4,6 +4,7 @@ #include #include +#include "core/debug.hpp" #include "core/events.hpp" #include "core/spatial_hash.hpp" #include "game/buffs.hpp" @@ -71,12 +72,30 @@ bool pick_crowd(const EnemySystem& enemies, Vec2 from, Vec2& center) { } void try_cast(SkillSystem& skills, Player& player, EnemySystem& enemies, - EventQueue& events) { + EventQueue& events, bool manual) { const int index = static_cast(SkillType::ConcreteCall); - if (skills.cooldowns[index] > 0.0f || !player.alive()) return; + if (skills.cooldowns[index] > 0.0f || !player.alive()) { + if (manual) + DEBUG_TRACE(debug::Skills, + "concrete: blocked (cd %.2f, alive=%d)", + skills.cooldowns[index], player.alive() ? 1 : 0); + return; + } Vec2 center{}; - if (!pick_crowd(enemies, player.pos, center)) return; // keep the cast ready + if (!pick_crowd(enemies, player.pos, center)) { + if (manual) { + float nearest = 1e9f; + for (const Enemy& e : enemies.enemies) + nearest = std::min(nearest, distance(e.pos, player.pos)); + DEBUG_TRACE(debug::Skills, + "concrete: no crowd within %.1f m (nearest %.1f m)", + kCastRange, nearest); + } + return; // keep the cast ready + } + DEBUG_TRACE(debug::Skills, "concrete: cast at %.1f %.1f", center.x, + center.y); ConcretePile pile; pile.pos = player.pos; @@ -93,12 +112,29 @@ void try_cast(SkillSystem& skills, Player& player, EnemySystem& enemies, } void try_cast_warp(SkillSystem& skills, Player& player, EnemySystem& enemies, - EventQueue& events) { + EventQueue& events, bool manual) { const int index = static_cast(SkillType::Warp); - if (skills.cooldowns[index] > 0.0f || !player.alive()) return; + if (skills.cooldowns[index] > 0.0f || !player.alive()) { + if (manual) + DEBUG_TRACE(debug::Skills, "warp: blocked (cd %.2f, alive=%d)", + skills.cooldowns[index], player.alive() ? 1 : 0); + return; + } Vec2 center{}; - if (!pick_crowd(enemies, player.pos, center)) return; + if (!pick_crowd(enemies, player.pos, center)) { + // A manual K press always fires — the key must never feel dead. With + // no crowd in range the field drops just ahead of the agent so the + // collapse is still visible. Autoplay waits for a real crowd. + if (!manual) return; // autoplay waits for a crowd; don't spam the log + DEBUG_TRACE(debug::Skills, "warp: no crowd, manual field at %.1f %.1f", + player.pos.x + player.facing.x * 3.0f, + player.pos.y + player.facing.y * 3.0f); + center = player.pos + player.facing * 3.0f; + } else { + DEBUG_TRACE(debug::Skills, "warp: crowd at %.1f %.1f", center.x, + center.y); + } WarpField field; field.pos = center; @@ -113,12 +149,19 @@ void try_cast_warp(SkillSystem& skills, Player& player, EnemySystem& enemies, // The projector-screen ritual reward: flood the room with fluorescent light. void try_cast_fluorescent(SkillSystem& skills, Player& player, EnemySystem& enemies, - BuffSystem& buffs, EventQueue& events) { + BuffSystem& buffs, EventQueue& events, bool manual) { const int index = static_cast(SkillType::Fluorescent); if (!skills.fluorescent_unlocked || skills.cooldowns[index] > 0.0f || !player.alive()) { + if (manual) + DEBUG_TRACE(debug::Skills, + "fluorescent: blocked (unlocked=%d, cd %.2f, alive=%d)", + skills.fluorescent_unlocked ? 1 : 0, + skills.cooldowns[index], player.alive() ? 1 : 0); return; } + DEBUG_TRACE(debug::Skills, "fluorescent: cast at %.1f %.1f", player.pos.x, + player.pos.y); BuffEffect effect; effect.damage_taken_mult = kLightDamageMult; for (std::size_t i = 0; i < enemies.enemies.size(); ++i) { @@ -184,16 +227,19 @@ void SkillSystem::reset() { void SkillSystem::note_input(const InputState& in) { if (in.skill_concrete) { + DEBUG_TRACE(debug::Input, "key: J (CONCRETE CALL)"); manual_hold = kManualHold; queued[static_cast(SkillType::ConcreteCall)] = true; press_feedback[static_cast(SkillType::ConcreteCall)] = 0.35f; } if (in.skill_warp) { + DEBUG_TRACE(debug::Input, "key: K (WARP)"); manual_hold = kManualHold; queued[static_cast(SkillType::Warp)] = true; press_feedback[static_cast(SkillType::Warp)] = 0.35f; } if (in.skill_fluorescent) { + DEBUG_TRACE(debug::Input, "key: U (FLUORESCENT)"); manual_hold = kManualHold; queued[static_cast(SkillType::Fluorescent)] = true; press_feedback[static_cast(SkillType::Fluorescent)] = 0.35f; @@ -237,23 +283,23 @@ void SkillSystem::update(float dt, const InputState& in, Player& player, const float before_c = cooldowns[ci], before_w = cooldowns[wi], before_f = cooldowns[fi]; if (in.skill_concrete || queued[ci]) { - try_cast(*this, player, enemies, events); + try_cast(*this, player, enemies, events, true); if (cooldowns[ci] > before_c) queued[ci] = false; } if (in.skill_warp || queued[wi]) { - try_cast_warp(*this, player, enemies, events); + try_cast_warp(*this, player, enemies, events, true); if (cooldowns[wi] > before_w) queued[wi] = false; } if (in.skill_fluorescent || queued[fi]) { - try_cast_fluorescent(*this, player, enemies, buffs, events); + try_cast_fluorescent(*this, player, enemies, buffs, events, true); if (cooldowns[fi] > before_f) queued[fi] = false; } if (autoplay_active()) { // Generic autoplay: every skill is cast from this same path when the // player isn't driving them by hand. - try_cast(*this, player, enemies, events); - try_cast_warp(*this, player, enemies, events); - try_cast_fluorescent(*this, player, enemies, buffs, events); + try_cast(*this, player, enemies, events, false); + try_cast_warp(*this, player, enemies, events, false); + try_cast_fluorescent(*this, player, enemies, buffs, events, false); } for (std::size_t i = 0; i < piles.size();) { diff --git a/src/level/level_data.cpp b/src/level/level_data.cpp index 978b730..ecb5e61 100644 --- a/src/level/level_data.cpp +++ b/src/level/level_data.cpp @@ -215,6 +215,21 @@ bool prop_kind_from_name(const std::string& name, PropKind& kind) { return true; } +bool is_debris_source(const Prop& p) { + switch (p.kind) { + case PropKind::Shelf: + case PropKind::ArchiveShelf: + case PropKind::MeetingTable: + case PropKind::Desk: + return true; + default: break; + } + // Outfit props carry their model name instead of a structural kind. + return p.model == "ArchiveShelf" || p.model == "Cabinet" + || p.model == "MeetingTable" || p.model == "OfficeDesk" + || p.model == "GarbageCan"; +} + json::Value to_json(const LevelData& l) { json::Value root = json::Value::obj(); root.set("version", json::Value::num(l.version)); diff --git a/src/level/level_data.hpp b/src/level/level_data.hpp index 8d6ddd8..f47b372 100644 --- a/src/level/level_data.hpp +++ b/src/level/level_data.hpp @@ -142,6 +142,9 @@ const char* room_kind_name(RoomKind kind); bool room_kind_from_name(const std::string& name, RoomKind& kind); const char* prop_kind_name(PropKind kind); bool prop_kind_from_name(const std::string& name, PropKind& kind); +// Presentation hint: shelves, tables/desks and garbage cans shed debris when a +// skill goes off nearby. Pure level-data query so it can be tested headlessly. +bool is_debris_source(const Prop& p); LevelData floor01_default(); diff --git a/src/main.cpp b/src/main.cpp index f35833e..0016b14 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ #include "raylib.h" +#include "core/debug.hpp" #include "game/game.hpp" #include "render/layout.hpp" #include "render/presenter.hpp" @@ -58,6 +59,7 @@ struct Options { float cam_height = 0.0f; // --cam-height : initial camera height float cam_forward = 0.0f; // --cam-forward : initial forward offset const char* level_path = nullptr; // --level : authoring JSON to load + const char* trace = nullptr; // --trace : opt-in debug categories }; Options parse_options(int argc, char** argv) { @@ -118,6 +120,10 @@ Options parse_options(int argc, char** argv) { opts.cam_height = static_cast(std::atof(argv[i + 1])); } else if (std::strcmp(argv[i], "--cam-forward") == 0 && i + 1 < argc) { opts.cam_forward = static_cast(std::atof(argv[i + 1])); + } else if (std::strcmp(argv[i], "--trace") == 0 && i + 1 < argc) { + opts.trace = argv[++i]; + } else if (std::strncmp(argv[i], "--trace=", 8) == 0) { + opts.trace = argv[i] + 8; } } return opts; @@ -245,6 +251,10 @@ InputState read_input(const Game& game, bool bot, const InputFrame& frame) { int main(int argc, char** argv) { SetTraceLogLevel(LOG_WARNING); const Options opts = parse_options(argc, argv); + if (opts.trace != nullptr) { + unsigned trace_mask = debug::None; + if (debug::parse(opts.trace, trace_mask)) debug::set_mask(trace_mask); + } // The future graphics menu writes this same setting; --aniso lets us // exercise it from the CLI until that menu exists. gfx::graphics_settings().concrete_filter = gfx::filtering_from_aniso(opts.aniso); diff --git a/src/render/debris.cpp b/src/render/debris.cpp index e53d3b6..1e94858 100644 --- a/src/render/debris.cpp +++ b/src/render/debris.cpp @@ -175,13 +175,25 @@ void ConcreteDebris::clear() { } void ConcreteDebris::burst(Vec2 center, float radius, int count) { + burst(center, radius, count, nullptr, 0); +} + +void ConcreteDebris::burst(Vec2 center, float radius, int count, + const Vector3* origins, int origin_count) { for (int i = 0; i < count && static_cast(chunks_.size()) < kCapacity; ++i) { ConcreteChunk c; const float a = range(0.0f, 6.2831853f); - const float d = range(0.2f, radius * 0.9f); - c.pos = {center.x + std::cos(a) * d, 0.09f, - center.y + std::sin(a) * d}; + if (origins != nullptr && origin_count > 0) { + const Vector3& src = origins[GetRandomValue(0, origin_count - 1)]; + c.pos = {src.x + range(-0.24f, 0.24f), + src.y + range(-0.08f, 0.10f), + src.z + range(-0.24f, 0.24f)}; + } else { + const float d = range(0.2f, radius * 0.9f); + c.pos = {center.x + std::cos(a) * d, 0.09f, + center.y + std::sin(a) * d}; + } const float spread = range(1.8f, 4.8f) * (1.0f + radius * 0.12f); c.vel = {std::cos(a) * spread, range(2.6f, 6.2f), std::sin(a) * spread}; diff --git a/src/render/debris.hpp b/src/render/debris.hpp index d04aa82..916eb66 100644 --- a/src/render/debris.hpp +++ b/src/render/debris.hpp @@ -72,6 +72,10 @@ public: int count() const { return static_cast(chunks_.size()); } void burst(Vec2 center, float radius, int count); + // Surface-shed variant: chunks fly off shelves/tables/garbage cans instead + // of erupting from the floor at the blast centre. + void burst(Vec2 center, float radius, int count, + const Vector3* origins, int origin_count); void update(float dt); void draw(Vector3 camera_pos) const; diff --git a/src/render/dressing.cpp b/src/render/dressing.cpp index 9f780d1..7e409b0 100644 --- a/src/render/dressing.cpp +++ b/src/render/dressing.cpp @@ -22,12 +22,13 @@ void Dressing::add(ActorModel model, float x, float y, float z, float yaw, void Dressing::init(const Floor* floor) { props_.clear(); props_.reserve(80); + surfaces_.clear(); + surfaces_.reserve(64); if (floor == nullptr) return; for (const level::Prop& p : floor->data().props) { - if (!p.destructible) continue; ActorModel model = ActorModel::LooseSheet; - if (!ModelBank::actor_from_name(p.model, model)) continue; + const bool has_model = ModelBank::actor_from_name(p.model, model); Vec2 pos = level::to_world(floor->data(), p.pos); if (!p.room_kind.empty()) { for (const FloorRoom& r : floor->rooms()) { @@ -37,7 +38,20 @@ void Dressing::init(const Floor* floor) { break; } } - add(model, pos.x, p.y, pos.y, p.yaw, p.scale); + + int prop_index = -1; + if (p.destructible && has_model) { + add(model, pos.x, p.y, pos.y, p.yaw, p.scale); + prop_index = static_cast(props_.size()) - 1; + } + if (level::is_debris_source(p)) { + // Structural props have no GLB: their authored height is the + // surface. Modelled props use the bank's visual height. + const float top = p.y + (has_model + ? ModelBank::height(model) * p.scale + : p.h + 0.05f); + surfaces_.push_back({pos, top, prop_index}); + } } } @@ -79,6 +93,22 @@ int Dressing::destroy_in_radius(Vec2 center, float radius, Vector3* out, return written; } +int Dressing::surface_sources_in_radius(Vec2 center, float radius, + Vector3* out, int capacity) const { + const float reach_sq = radius * radius; + int written = 0; + for (const Surface& s : surfaces_) { + if (out == nullptr || written >= capacity) break; + if (s.prop >= 0 && !props_[static_cast(s.prop)].alive) + continue; + const float dx = s.pos.x - center.x; + const float dz = s.pos.y - center.y; + if (dx * dx + dz * dz > reach_sq) continue; + out[written++] = {s.pos.x, s.top, s.pos.y}; + } + return written; +} + int Dressing::alive_count() const { int n = 0; for (const Prop& p : props_) if (p.alive) ++n; diff --git a/src/render/dressing.hpp b/src/render/dressing.hpp index 9a77d48..1ec654d 100644 --- a/src/render/dressing.hpp +++ b/src/render/dressing.hpp @@ -21,6 +21,11 @@ public: // into `out` so debris can originate from the papers that were destroyed. int destroy_in_radius(Vec2 center, float radius, Vector3* out, int capacity); + // Skill-driven surface shedding: shelves, tables/desks and garbage cans + // stay intact but shed paper/rock debris from their top surface. + int surface_sources_in_radius(Vec2 center, float radius, Vector3* out, + int capacity) const; + int alive_count() const; private: @@ -34,8 +39,18 @@ private: bool alive = true; }; + // Presentation-only surface anchor; never drawn or destroyed here. + // `prop` links bins that are also destructible dressing so they stop + // shedding once an area blast has actually destroyed them. + struct Surface { + Vec2 pos{}; + float top = 0.0f; + int prop = -1; + }; + void add(ActorModel model, float x, float y, float z, float yaw, float scale = 1.0f); std::vector props_; + std::vector surfaces_; }; diff --git a/src/render/presenter.cpp b/src/render/presenter.cpp index c4ef96f..d34ae75 100644 --- a/src/render/presenter.cpp +++ b/src/render/presenter.cpp @@ -1,5 +1,6 @@ #include "render/presenter.hpp" +#include "core/debug.hpp" #include "game/floor.hpp" #include "game/weapons.hpp" #include "render/layout.hpp" @@ -301,6 +302,22 @@ void Presenter::spawn_sparks(Vec2 pos, float height, Color color, int count, } } +void Presenter::shed_surface_debris(Vec2 center, float radius) { + Vector3 origins[12]; + const int n = dressing_.surface_sources_in_radius( + center, radius, origins, static_cast(std::size(origins))); + DEBUG_TRACE(debug::Debris, + "surface query at %.1f %.1f r=%.1f -> %d origins", center.x, + center.y, radius, n); + if (n <= 0) return; + const int paper_count = std::min(24, 6 + n * 2); + const int rock_count = std::min(18, 5 + n * 2); + DEBUG_TRACE(debug::Debris, "surface shed: %d paper, %d rock", paper_count, + rock_count); + debris_.burst(center, 0.9f, radius, origins, n, paper_count); + concrete_debris_.burst(center, radius, rock_count, origins, n); +} + void Presenter::init(float arena_half, const Floor& floor) { floor_mode_ = true; camera_.position = {floor.spawn().x, tuning_.height, floor.spawn().y + tuning_.forward}; @@ -1214,6 +1231,9 @@ void Presenter::draw_scene(Game& game) { damage_flash_ = 1.0f; spawn_sparks(e.pos, 1.0f, Color{255, 80, 70, 255}, 6, 3.0f); } else if (e.type == EventType::SkillCast) { + DEBUG_TRACE(debug::Events, + "SkillCast flags=%u pos=%.1f %.1f r=%.1f", e.flags, + e.pos.x, e.pos.y, e.magnitude); // Both skills telegraph their landing zone; only concrete kicks up // dust, warp uses the teal containment palette. const bool warp = (e.flags & static_cast(SkillType::Warp)) != 0; @@ -1231,15 +1251,25 @@ void Presenter::draw_scene(Game& game) { spawn_sparks(game.player.pos, 0.35f, Color{180, 176, 166, 255}, 8, 2.6f); } + // All three skills shake nearby surfaces loose: paper + rock + // debris flies off shelves, tables and garbage cans while the + // props themselves stay put. + shed_surface_debris(game.player.pos, 5.0f); + if (distance(e.pos, game.player.pos) > 1.0f) { + shed_surface_debris(e.pos, std::max(4.0f, e.magnitude)); + } aura_.spawn_ground({e.pos.x, 0.09f, e.pos.y}, std::max(1.0f, e.magnitude), warp ? 0.9f : 0.55f, anim_time_); shake_ = std::max(shake_, 0.08f); } else if (e.type == EventType::WarpBurst) { + DEBUG_TRACE(debug::Events, "WarpBurst pos=%.1f %.1f r=%.1f", + e.pos.x, e.pos.y, e.magnitude); aura_.spawn_ground({e.pos.x, 0.09f, e.pos.y}, std::max(1.0f, e.magnitude) * 1.2f, 1.0f, anim_time_); spawn_sparks(e.pos, 0.9f, Color{120, 240, 220, 255}, 16, 4.5f); + shed_surface_debris(e.pos, std::max(4.0f, e.magnitude)); shake_ = std::max(shake_, 0.22f); } else if (e.type == EventType::BlackoutStart) { shake_ = std::max(shake_, 0.3f); @@ -1271,6 +1301,8 @@ void Presenter::draw_scene(Game& game) { : Color{255, 220, 150, 235}, 2 + tier, 1.8f); } else if (e.type == EventType::AreaDetonation) { + DEBUG_TRACE(debug::Events, "AreaDetonation flags=%u pos=%.1f %.1f r=%.1f", + e.flags, e.pos.x, e.pos.y, e.magnitude); const float radius = std::max(1.0f, e.magnitude); Vector3 origins[16]; const int destroyed = dressing_.destroy_in_radius( @@ -1284,6 +1316,8 @@ void Presenter::draw_scene(Game& game) { concrete_debris_.burst( e.pos, radius, std::min(28, 12 + static_cast(radius * 3.0f))); + // The impact shakes nearby furniture as well as the floor. + shed_surface_debris(e.pos, radius); spawn_sparks(e.pos, 0.25f, Color{170, 166, 158, 255}, 10, 3.4f); } scorch_.add(e.pos, radius * 0.6f); diff --git a/src/render/presenter.hpp b/src/render/presenter.hpp index 095e08c..86f8cce 100644 --- a/src/render/presenter.hpp +++ b/src/render/presenter.hpp @@ -76,6 +76,9 @@ private: void draw_initial_scene(const Game& game, const ViewCull& cull); void draw_office_suite(const Game& game, const ViewCull& cull); void spawn_sparks(Vec2 pos, float height, Color color, int count, float speed); + // Skills shake nearby shelves/tables/garbage cans into paper + rock debris + // without destroying the props (presentation-only). + void shed_surface_debris(Vec2 center, float radius); Camera3D camera_{}; CameraTuning tuning_; diff --git a/tests/debris_test.cpp b/tests/debris_test.cpp new file mode 100644 index 0000000..1bd50fe --- /dev/null +++ b/tests/debris_test.cpp @@ -0,0 +1,103 @@ +// Debris integration: skills shed paper + rock from shelves, tables and bins. +// The props must stay intact; only their surface positions feed the bursts. +#include + +#include "game/floor.hpp" +#include "level/level_data.hpp" +#include "render/debris.hpp" +#include "render/dressing.hpp" + +namespace { + +bool failed = false; + +void check(bool ok, const char* what) { + if (!ok) { + std::printf("FAIL: %s\n", what); + failed = true; + } +} + +level::Prop decor(const char* model = "") { + level::Prop p; + p.kind = PropKind::Decor; + p.model = model; + return p; +} + +} // namespace + +int main() { + // --- Classification: shelves, tables and garbage cans shed debris ----- + { + level::Prop p; + p.kind = PropKind::Shelf; + check(level::is_debris_source(p), "Shelf is a debris source"); + p.kind = PropKind::ArchiveShelf; + check(level::is_debris_source(p), "ArchiveShelf is a debris source"); + p.kind = PropKind::MeetingTable; + check(level::is_debris_source(p), "MeetingTable is a debris source"); + p.kind = PropKind::Desk; + check(level::is_debris_source(p), "Desk is a debris source"); + p.kind = PropKind::Pillar; + check(!level::is_debris_source(p), "Pillar is not a debris source"); + check(level::is_debris_source(decor("GarbageCan")), + "GarbageCan outfit is a debris source"); + check(level::is_debris_source(decor("Cabinet")), + "Cabinet outfit is a debris source"); + check(level::is_debris_source(decor("OfficeDesk")), + "OfficeDesk outfit is a debris source"); + check(!level::is_debris_source(decor("LooseSheet")), + "LooseSheet is destroyed, not a surface source"); + } + + // --- Real floor data produces surface origins near furniture ---------- + Floor floor; + Dressing dressing; + dressing.init(&floor); + + Vector3 origins[24]; + // Plaza bins sit ~34-39 m from the room centre; a skill cast there must + // still find them as surfaces. + const int plaza = dressing.surface_sources_in_radius( + {-22.5f, 13.5f}, 45.0f, origins, static_cast(std::size(origins))); + check(plaza > 0, "plaza garbage cans are debris surfaces"); + + // A bin destroyed by a blast stops shedding: it is no longer in the scene. + const Vec2 bin{-58.5f, -1.5f}; + int before = dressing.surface_sources_in_radius(bin, 2.0f, origins, + static_cast(std::size(origins))); + check(before > 0, "bin is a surface before the blast"); + dressing.destroy_in_radius(bin, 2.0f, nullptr, 0); + const int after = dressing.surface_sources_in_radius( + bin, 2.0f, origins, static_cast(std::size(origins))); + check(after < before, "destroyed bin stops shedding debris"); + + const int gate = dressing.surface_sources_in_radius( + {12.0f, 70.0f}, 40.0f, origins, static_cast(std::size(origins))); + check(gate > 0, "gate archive aisle has debris surfaces"); + bool tall_surface = false; + for (int i = 0; i < gate; ++i) tall_surface |= origins[i].y > 1.5f; + check(tall_surface, "shelf surfaces sit above the floor"); + + // Props stay intact: shedding must not reduce the destructible dressing. + const int alive_before = dressing.alive_count(); + dressing.surface_sources_in_radius({12.0f, 70.0f}, 40.0f, origins, + static_cast(std::size(origins))); + check(dressing.alive_count() == alive_before, + "surface shedding does not destroy props"); + + // --- Both debris systems accept surface origins ----------------------- + { + PaperDebris paper; + ConcreteDebris rocks; + paper.burst({12.0f, 70.0f}, 0.9f, 4.0f, origins, gate, 12); + rocks.burst({12.0f, 70.0f}, 4.0f, 12, origins, gate); + check(paper.count() > 0, "paper debris spawns from surface origins"); + check(rocks.count() > 0, "rock debris spawns from surface origins"); + } + + if (failed) return 1; + std::printf("debris: OK\n"); + return 0; +} diff --git a/tests/debug_test.cpp b/tests/debug_test.cpp new file mode 100644 index 0000000..8dcd042 --- /dev/null +++ b/tests/debug_test.cpp @@ -0,0 +1,46 @@ +// Opt-in debug tracing: category parsing and enable/disable behaviour. +#include + +#include "core/debug.hpp" + +namespace { + +bool failed = false; + +void check(bool ok, const char* what) { + if (!ok) { + std::printf("FAIL: %s\n", what); + failed = true; + } +} + +} // namespace + +int main() { + unsigned mask = debug::All; + check(debug::parse(nullptr, mask) && mask == debug::None, + "null category list clears the mask"); + check(debug::parse("", mask) && mask == debug::None, + "empty category list clears the mask"); + check(debug::parse("skills", mask) && mask == debug::Skills, + "single category parses"); + check(debug::parse("skills,debris", mask) + && mask == (debug::Skills | debug::Debris), + "comma-separated categories parse"); + check(debug::parse(" skills , input ", mask) + && mask == (debug::Skills | debug::Input), + "whitespace around names is ignored"); + check(debug::parse("all", mask) && mask == debug::All, + "'all' enables every category"); + check(!debug::parse("nope", mask) && mask == debug::All, + "unknown category fails without changing the mask"); + + debug::set_mask(debug::Skills); + check(debug::enabled(debug::Skills), "enabled category reports true"); + check(!debug::enabled(debug::Debris), "disabled category reports false"); + debug::set_mask(debug::None); + + if (failed) return 1; + std::printf("debug: OK\n"); + return 0; +} diff --git a/tests/skills_test.cpp b/tests/skills_test.cpp index 2572336..796b60b 100644 --- a/tests/skills_test.cpp +++ b/tests/skills_test.cpp @@ -156,6 +156,43 @@ int main() { "warp burst damages the crowd"); } + // --- Manual WARP always fires, even with no crowd in range ------------- + { + Game game(12); + game.enemy_system.clear(); + game.skill_system.autoplay_enabled = false; + game.player.pos = {0.0f, 0.0f}; + game.player.facing = {0.0f, 1.0f}; + + InputState in{}; + in.skill_warp = true; + game.update(in, kDt); + check(game.skill_system.warps.size() == 1, + "K casts WARP with no enemies in range"); + check(game.skill_system.cooldowns[static_cast(SkillType::Warp)] > 0.0f, + "no-target WARP still starts its cooldown"); + bool cast_event = false; + for (int i = 0; i < game.events.count; ++i) + if (game.events.items[i].type == EventType::SkillCast + && game.events.items[i].flags + == static_cast(SkillType::Warp)) + cast_event = true; + check(cast_event, "no-target WARP emits its telegraph event"); + const Vec2 expected{0.0f, 3.0f}; + check(distance(game.skill_system.warps[0].pos, expected) < 0.01f, + "no-target field drops ahead of the agent"); + } + + // --- Autoplay does not spam fields when the floor is empty ------------- + { + Game game(13); + game.enemy_system.clear(); + InputState in{}; + for (int tick = 0; tick < 120; ++tick) game.update(in, kDt); + check(game.skill_system.warps.empty(), + "autoplay waits for a crowd before casting WARP"); + } + // --- A manual press during cooldown is queued, not dropped ------------- { Game game(11);