1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include "catch/catch.hpp"
#include "item.h"
#include "mondefense.h"
#include "monster.h"
#include "npc.h"
#include "projectile.h"
void test_zapback( Creature &attacker, const bool expect_damage,
const dealt_projectile_attack *proj = nullptr )
{
monster defender( mtype_id( "mon_zombie_electric" ) );
int prev_hp = attacker.get_hp();
mdefense::zapback( defender, &attacker, proj );
if( expect_damage ) {
CHECK( attacker.get_hp() < prev_hp );
} else {
CHECK( attacker.get_hp() == prev_hp );
}
}
TEST_CASE( "zapback_npc_unarmed", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
test_zapback( attacker, true );
}
TEST_CASE( "zapback_npc_nonconductive_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
item rock( "rock" );
attacker.wield( rock );
test_zapback( attacker, false );
}
TEST_CASE( "zapback_npc_nonconductive_unarmed_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
// AFAICT this is the only nonconductive unarmed weapon.
item knuckle_nail( "knuckle_nail" );
attacker.wield( knuckle_nail );
test_zapback( attacker, false );
}
TEST_CASE( "zapback_npc_reach_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
item pike( "pike" );
attacker.wield( pike );
test_zapback( attacker, false );
}
TEST_CASE( "zapback_npc_ranged_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
item gun( "glock_19" );
attacker.wield( gun );
dealt_projectile_attack attack;
test_zapback( attacker, false, &attack );
}
TEST_CASE( "zapback_npc_thrown_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
dealt_projectile_attack attack;
test_zapback( attacker, false, &attack );
}
TEST_CASE( "zapback_npc_firing_ranged_reach_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
item ranged_reach_weapon( "reach_bow" );
attacker.wield( ranged_reach_weapon );
dealt_projectile_attack attack;
test_zapback( attacker, false, &attack );
}
TEST_CASE( "zapback_npc_meleeattack_ranged_reach_weapon", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
item ranged_reach_weapon( "reach_bow" );
REQUIRE( ranged_reach_weapon.gun_set_mode( gun_mode_id( "MELEE" ) ) );
attacker.wield( ranged_reach_weapon );
test_zapback( attacker, true );
}
TEST_CASE( "zapback_npc_electricity_immune", "[mondefense]" )
{
standard_npc attacker( "Attacker" );
attacker.add_bionic( bionic_id( "bio_power_storage" ) );
attacker.add_bionic( bionic_id( "bio_faraday" ) );
attacker.charge_power( 100 );
// Don't forget to turn it on...
test_zapback( attacker, true );
// Wow this is a raw index?
attacker.activate_bionic( 0 );
test_zapback( attacker, false );
}
TEST_CASE( "zapback_monster", "[mondefense]" )
{
monster attacker( mtype_id( "mon_zombie" ) );
test_zapback( attacker, true );
}
|