cntrl/tests/skills_test.cpp
dandovlatov a90d763f49 Polished CONCRETE CALL and WARP with reliable triggers and skill-specific VFX
Systemic:
- Queued manual presses until the skill is actually ready; manual hold is per
  skill, so J no longer parks WARP/FLUORESCENT on manual.
- Required line of sight for targeting, flight and damage; steered the heap toward
  moving crowds; locked WARP to the crowd present at cast (manual no-target
  fields remain area hazards).
- Reused the targeting hash, throttled fruitless autoplay scans, raised event
  capacity and emitted skill VFX events before per-hit events.
- Used explicit SkillCast bit flags, showed applied damage, skipped dead enemies and
  kept cooldowns advancing inside the blackout pocket.

Visual:
- Tinted ground waves per skill (teal WARP, pale concrete CALL, yellow light).
- Added landing telegraphs, dust wakes and a teal collapse burst; grey concrete
  impact decals; per-skill HUD accents and a queued-press badge.
- Added --skill-test staging with sim-time-keyed captures for VFX QA.

Tests: 16/16 pass, including new queue lifetime, per-skill autoplay, cast flag
and moving-target cases.
2026-11-25 03:57:09 +04:00

311 lines
12 KiB
C++

// Active skills: CONCRETE CALL and WARP — manual casts, autoplay, effects.
#include <algorithm>
#include <cstdio>
#include "game/game.hpp"
namespace {
constexpr float kDt = 1.0f / 60.0f;
float total_hp(const EnemySystem& enemies) {
float hp = 0.0f;
for (const Enemy& e : enemies.enemies) hp += e.hp;
return hp;
}
void spawn_crowd(Game& game) {
game.enemy_system.clear();
game.player.pos = {0.0f, 0.0f};
game.enemy_system.spawn(EnemyType::HissBrute, {1.5f, 0.0f}, game.corruption);
game.enemy_system.spawn(EnemyType::HissBrute, {2.5f, 0.0f}, game.corruption);
game.enemy_system.spawn(EnemyType::HissBrute, {2.0f, 1.0f}, game.corruption);
}
bool failed = false;
void check(bool ok, const char* what) {
if (!ok) {
std::printf("FAIL: %s\n", what);
failed = true;
}
}
} // namespace
int main() {
// --- Manual cast (J) ---
{
Game game(7);
spawn_crowd(game);
const float hp_before = total_hp(game.enemy_system);
InputState in{};
in.skill_concrete = true;
game.update(in, kDt);
check(game.skill_system.piles.size() == 1, "J spawns a concrete pile");
check(game.skill_system.cooldowns[static_cast<int>(SkillType::ConcreteCall)] > 0.0f,
"J starts the skill cooldown");
check(!game.skill_system.autoplay_active(), "manual press pauses autoplay");
bool cast_event = false;
for (int i = 0; i < game.events.count; ++i)
if (game.events.items[i].type == EventType::SkillCast) cast_event = true;
check(cast_event, "J emits a SkillCast event");
bool tagged = false;
for (int i = 0; i < game.events.count; ++i)
if (game.events.items[i].type == EventType::SkillCast
&& (game.events.items[i].flags & kCastConcrete)
&& !(game.events.items[i].flags & kCastWarp))
tagged = true;
check(tagged, "CALL's cast event uses its own flag bit");
game.events.clear();
in.skill_concrete = false;
bool detonated = false;
for (int tick = 0; tick < 120; ++tick) {
game.update(in, kDt);
for (int i = 0; i < game.events.count; ++i) {
const GameEvent& e = game.events.items[i];
if (e.type == EventType::AreaDetonation
&& (e.flags & kDetonateConcrete)) detonated = true;
}
game.events.clear();
}
check(detonated, "pile detonates with concrete debris");
check(total_hp(game.enemy_system) < hp_before - 100.0f,
"detonation damages the crowd");
}
// --- Autoplay without any key press (generic for future skills) ---
{
Game game(8);
spawn_crowd(game);
InputState in{}; // no skill button
game.update(in, kDt);
check(game.skill_system.piles.size() == 1, "skill autoplays when idle");
check(game.skill_system.autoplay_active(), "autoplay stays active");
game.events.clear();
for (int tick = 0; tick < 120; ++tick) {
game.update(in, kDt);
game.events.clear();
}
check(game.skill_system.piles.empty(), "autoplayed pile completes");
}
// --- Autoplay can be switched off; manual casts still work ---
{
Game game(9);
spawn_crowd(game);
InputState in{};
in.toggle_autoplay = true;
game.update(in, kDt);
check(!game.skill_system.autoplay_enabled, "L disables autoplay");
check(!game.skill_system.autoplay_active(), "disabled autoplay is inactive");
game.events.clear();
in.toggle_autoplay = false;
in.skill_concrete = true;
game.update(in, kDt);
check(game.skill_system.piles.size() == 1,
"manual cast works with autoplay off");
game.events.clear();
}
// --- WARP (K): enemies magnetize together, then burst ---
{
Game game(10);
game.enemy_system.clear();
game.player.pos = {0.0f, 0.0f};
game.enemy_system.spawn(EnemyType::HissBrute, {2.0f, 0.0f}, game.corruption);
game.enemy_system.spawn(EnemyType::HissBrute, {5.0f, 0.0f}, game.corruption);
game.enemy_system.spawn(EnemyType::HissBrute, {3.0f, 2.0f}, game.corruption);
const float hp_before = total_hp(game.enemy_system);
const auto spread = [](const EnemySystem& enemies, Vec2 center) {
float sum = 0.0f;
for (const Enemy& e : enemies.enemies) sum += distance(e.pos, center);
return sum / static_cast<float>(enemies.enemies.size());
};
InputState in{};
in.skill_warp = true;
game.update(in, kDt);
check(game.skill_system.warps.size() == 1, "K spawns a warp field");
check(game.skill_system.cooldowns[static_cast<int>(SkillType::Warp)] > 0.0f,
"K starts the warp cooldown");
bool cast_event = false;
for (int i = 0; i < game.events.count; ++i) {
const GameEvent& e = game.events.items[i];
if (e.type == EventType::SkillCast
&& (e.flags & kCastWarp))
cast_event = true;
}
check(cast_event, "warp emits a tagged SkillCast event");
const Vec2 center = game.skill_system.warps[0].pos;
const float spread_before = spread(game.enemy_system, center);
in.skill_warp = false;
for (int tick = 0; tick < 30; ++tick) {
game.update(in, kDt);
game.events.clear();
}
check(spread(game.enemy_system, center) < spread_before * 0.8f,
"warp pulls enemies together");
bool burst = false;
for (int tick = 0; tick < 40; ++tick) {
game.update(in, kDt);
for (int i = 0; i < game.events.count; ++i)
if (game.events.items[i].type == EventType::WarpBurst) burst = true;
game.events.clear();
}
check(burst, "warp field collapses with a burst event");
check(game.skill_system.warps.empty(), "warp field is consumed");
check(total_hp(game.enemy_system) < hp_before - 100.0f,
"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<int>(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
& kCastWarp)
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);
spawn_crowd(game);
game.skill_system.autoplay_enabled = false;
const int ci = static_cast<int>(SkillType::ConcreteCall);
game.skill_system.cooldowns[ci] = 0.5f;
InputState in{};
in.skill_concrete = true;
game.update(in, kDt);
check(game.skill_system.piles.empty(), "press on cooldown does not double-cast");
check(game.skill_system.queued[ci], "manual press is queued while cooling down");
check(game.skill_system.press_feedback[ci] > 0.0f,
"manual press flashes the HUD stamp immediately");
in.skill_concrete = false;
for (int tick = 0; tick < 45 && game.skill_system.piles.empty(); ++tick)
game.update(in, kDt);
check(game.skill_system.piles.size() == 1,
"queued manual cast fires as soon as the cooldown ends");
check(!game.skill_system.queued[ci], "queue clears after the cast");
}
// --- A remembered press outlives a long cooldown -----------------------
// The old queue expired with the 5 s manual window, so a K pressed early
// in WARP's 9 s cooldown was silently dropped.
{
Game game(14);
spawn_crowd(game);
game.config.no_player_damage = true; // survive the whole 9 s cooldown
game.skill_system.autoplay_enabled = false;
const int wi = static_cast<int>(SkillType::Warp);
game.skill_system.cooldowns[wi] = 8.9f;
InputState in{};
in.skill_warp = true;
game.update(in, kDt);
check(game.skill_system.queued[wi],
"a press early in a long cooldown is remembered");
in.skill_warp = false;
bool cast = false;
for (int tick = 0; tick < 600 && !cast; ++tick) {
game.update(in, kDt);
for (int i = 0; i < game.events.count; ++i) {
const GameEvent& e = game.events.items[i];
if (e.type == EventType::SkillCast && (e.flags & kCastWarp))
cast = true;
}
game.events.clear();
}
check(cast, "queued WARP fires after the full cooldown elapses");
check(!game.skill_system.queued[wi], "queue clears once it fires");
}
// --- Manual control is per skill, not global ---------------------------
{
Game game(15);
spawn_crowd(game);
InputState in{};
in.skill_concrete = true;
game.update(in, kDt);
check(game.skill_system.autoplay_active(SkillType::Warp),
"pressing J leaves WARP on autoplay");
in.skill_concrete = false;
bool warp_cast = false;
for (int tick = 0; tick < 30 && !warp_cast; ++tick) {
game.update(in, kDt);
for (int i = 0; i < game.events.count; ++i)
if (game.events.items[i].type == EventType::SkillCast
&& (game.events.items[i].flags & kCastWarp))
warp_cast = true;
game.events.clear();
}
check(warp_cast, "WARP still autoplays during CALL's manual window");
}
// --- The heap follows a crowd that moves during flight -----------------
{
Game game(16);
game.enemy_system.clear();
game.player.pos = {0.0f, 0.0f};
game.skill_system.autoplay_enabled = false;
game.enemy_system.spawn(EnemyType::HissBrute, {6.0f, 0.0f}, game.corruption);
game.enemy_system.spawn(EnemyType::HissBrute, {7.0f, 0.5f}, game.corruption);
InputState in{};
in.skill_concrete = true;
game.update(in, kDt);
check(game.skill_system.piles.size() == 1, "CALL cast for retarget test");
const Vec2 start = game.skill_system.piles[0].target;
for (Enemy& e : game.enemy_system.enemies) e.pos += Vec2{0.0f, 2.0f};
in.skill_concrete = false;
float highest = start.y;
for (int tick = 0; tick < 50 && game.skill_system.piles.size() == 1; ++tick) {
for (Enemy& e : game.enemy_system.enemies) e.speed = 0.0f;
game.update(in, kDt);
if (game.skill_system.piles.size() == 1)
highest = std::max(highest, game.skill_system.piles[0].target.y);
game.events.clear();
}
check(highest > start.y + 0.4f,
"CALL steers its landing point toward a moving crowd");
}
if (failed) return 1;
std::printf("skills: OK\n");
return 0;
}