From 7871d3930e13623310fa0c620dc826c00dd11b3b Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 8 May 2026 13:22:52 +0200 Subject: [PATCH] feat(whip): cabla flag whip.damage_pierces_walls a computeDamageRect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quan el flag està actiu (default), l'iteració píxel a píxel ignora `Map::collides` i només respecta `insidePlayfield`. El mur extern, doncs, sempre retalla — fora del playfield no hi ha res a colpejar. Els tests existents passen amb la nova lògica perquè els seus setups posen el damage_rect a corredors lliures (sense sarcs a la trajectòria), i el test W2 segueix verificant el retall del playfield. --- CMakeLists.txt | 1 + source/game/entities/concrete/whip_attack.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 602c69f..280d3fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -398,6 +398,7 @@ if(BUILD_TESTS) tests/audio_cache_stubs.cpp source/core/resources/resource_helper.cpp source/core/resources/resource_pack.cpp + source/game/gameplay_config.cpp source/game/map/map.cpp source/utils/log.cpp ${ENTITY_SOURCES_BASE} diff --git a/source/game/entities/concrete/whip_attack.cpp b/source/game/entities/concrete/whip_attack.cpp index b638eb0..794f4df 100644 --- a/source/game/entities/concrete/whip_attack.cpp +++ b/source/game/entities/concrete/whip_attack.cpp @@ -9,6 +9,7 @@ #include "game/entities/entity_factory.hpp" #include "game/entities/entity_manager.hpp" #include "game/entities/player.hpp" +#include "game/gameplay_config.hpp" #include "game/map/map.hpp" namespace { @@ -174,9 +175,16 @@ void WhipAttack::computeDamageRect(Direction dir, float spawn_x, float spawn_y, // d'atac, fins a topar amb un mur o sarc, o esgotar `range_px`. // L'amplada perpendicular és `tile_size` (els passadissos del joc // tenen exactament aquesta mida i l'atac és lateral). + // + // Si el tweak `whip.damage_pierces_walls` està actiu, la hitbox + // ignora els sarcòfags (passa a través del bloc complet) però + // continua respectant el `insidePlayfield`: fora de la sala no hi + // ha res a colpejar i ampliar-ho generaria visuals/edge cases + // estranys. El mur extern, doncs, sempre retalla. const auto TILE = static_cast(Map::tile_size); const int MAX_PX = static_cast(std::max(0.0F, range_px)); const auto MAX = static_cast(MAX_PX); + const bool PIERCES = GameplayConfig::get().whipDamagePiercesWalls(); float length = 0.0F; auto try_probe = [&](float l) -> bool { @@ -198,7 +206,9 @@ void WhipAttack::computeDamageRect(Direction dir, float spawn_x, float spawn_y, probe = {.x = spawn_x, .y = spawn_y + (MAX - l), .w = TILE, .h = l}; break; } - return Map::insidePlayfield(probe) && !Map::collides(probe); + if (!Map::insidePlayfield(probe)) { return false; } + if (PIERCES) { return true; } + return !Map::collides(probe); }; for (int i = 1; i <= MAX_PX; ++i) {