-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix_line_spell: prevent narrow line spells from being stopped early (
#40242) * bugfix_line_spell: prevent narrow line spells from being stopped early Line attack spells with narrow AOE (0 or 1) were being prevented from actually working as intended. The exception added to the condition prevents exiting early if the spell is a line attack. * bugfix_line_spell: Split `spell_effect_area` for testability Splits spell effect area calculation out of `spell_effect_area` to allow independent testing without calling the drawing function `explosion_handler::draw_custom_explosion` * bugfix_line_spell: Generate test to ensure narrow beam spell consistency
- Loading branch information
1 parent
c9a7081
commit 4dfa4f0
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#ifndef CATA_SRC_MAGIC_SPELL_EFFECT_HELPERS_H | ||
#define CATA_SRC_MAGIC_SPELL_EFFECT_HELPERS_H | ||
|
||
#include <functional> | ||
#include <set> | ||
|
||
class Creature; | ||
class spell; | ||
struct tripoint; | ||
|
||
// spells do not reduce in damage the further away from the epicenter the targets are | ||
// rather they do their full damage in the entire area of effect | ||
std::set<tripoint> calculate_spell_effect_area( const spell &sp, const tripoint &target, | ||
std::function<std::set<tripoint>( const spell &, const tripoint &, const tripoint &, int, bool )> | ||
aoe_func, const Creature &caster, bool ignore_walls = false ); | ||
|
||
#endif // CATA_SRC_MAGIC_SPELL_EFFECT_HELPERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <sstream> | ||
|
||
#include "catch/catch.hpp" | ||
#include "json.h" | ||
#include "magic.h" | ||
#include "magic_spell_effect_helpers.h" | ||
#include "npc.h" | ||
|
||
TEST_CASE( "line_attack", "[magic]" ) | ||
{ | ||
// manually construct a testable spell | ||
std::istringstream str( | ||
" {\n" | ||
" \"id\": \"test_line_spell\",\n" | ||
" \"name\": { \"str\": \"Test Line Spell\" },\n" | ||
" \"description\": \"Spews a line of magic\",\n" | ||
" \"valid_targets\": [ \"ground\" ],\n" | ||
" \"damage_type\": \"none\",\n" | ||
" \"min_range\": 5,\n" | ||
" \"max_range\": 5,\n" | ||
" \"effect\": \"line_attack\",\n" | ||
" \"min_aoe\": 0,\n" | ||
" \"max_aoe\": 0,\n" | ||
" \"flags\": [ \"VERBAL\", \"NO_HANDS\", \"NO_LEGS\" ]\n" | ||
" }\n" ); | ||
|
||
JsonIn in( str ); | ||
JsonObject obj( in ); | ||
spell_type::load_spell( obj, "" ); | ||
|
||
spell sp( spell_id( "test_line_spell" ) ); | ||
|
||
// set up Character to test with, only need position | ||
npc c; | ||
c.setpos( tripoint_zero ); | ||
|
||
// target point 5 tiles east of zero | ||
tripoint target = tripoint_east * 5; | ||
|
||
// Ensure that AOE=0 spell covers the 5 tiles along vector towards target | ||
SECTION( "aoe=0" ) { | ||
const std::set<tripoint> reference( { tripoint_east * 1, tripoint_east * 2, tripoint_east * 3, tripoint_east * 4, tripoint_east * 5 } ); | ||
|
||
std::set<tripoint> targets = calculate_spell_effect_area( sp, target, | ||
spell_effect::spell_effect_line, c, true ); | ||
|
||
CHECK( reference == targets ); | ||
} | ||
} |