Skip to content

Commit

Permalink
Make test guy attack debug mon, not themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll committed Apr 14, 2024
1 parent 1aea145 commit 4e7e229
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/enchantments_test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "avatar.h"
#include "cata_catch.h"
#include "creature_tracker.h"
#include "field.h"
#include "item.h"
#include "item_group.h"
Expand Down Expand Up @@ -202,7 +203,7 @@ TEST_CASE( "Enchantment_SPEED_test", "[magic][enchantments]" )
REQUIRE( guy.get_speed_bonus() == 0 );
}

static int test_melee_attack_attack_speed( Character &guy )
static int test_melee_attack_attack_speed( Character &guy, Creature &mon )

Check failure on line 206 in tests/enchantments_test.cpp

View workflow job for this annotation

GitHub Actions / build (other)

unused parameter 'mon' [clang-diagnostic-unused-parameter,-warnings-as-errors]

Check failure on line 206 in tests/enchantments_test.cpp

View workflow job for this annotation

GitHub Actions / build (other)

parameter 'mon' is unused [misc-unused-parameters,-warnings-as-errors]
{
int i = 0;
int prev_attack = 0;
Expand Down Expand Up @@ -232,21 +233,23 @@ TEST_CASE( "Enchantment_ATTACK_SPEED_test", "[magic][enchantments]" )
Character &guy = get_player_character();
clear_avatar();
g->place_critter_at( pseudo_debug_mon, tripoint_south );
creature_tracker &creatures = get_creature_tracker();
Creature &mon = *creatures.creature_at<Creature>( tripoint_south );
int moves_spent_on_attacks = 0;


INFO( "Character, melee skill lvl 10, attacks with no enchantment" );
// 38 moves per attack
INFO( "10 attacks cost 380 moves" );
moves_spent_on_attacks = test_melee_attack_attack_speed( guy );
moves_spent_on_attacks = test_melee_attack_attack_speed( guy, mon );
REQUIRE( moves_spent_on_attacks == -380 );


INFO( "Character, melee skill lvl 10, attacks with enchantment, that halves attack speed cost" );
guy.i_add( item( "test_ATTACK_SPEED_ench_item" ) );
// 25 moves per attack
INFO( "10 attacks cost only 250 moves" );
moves_spent_on_attacks = test_melee_attack_attack_speed( guy );
moves_spent_on_attacks = test_melee_attack_attack_speed( guy, mon );
REQUIRE( moves_spent_on_attacks == -250 );
clear_avatar();

Expand All @@ -255,12 +258,12 @@ TEST_CASE( "Enchantment_ATTACK_SPEED_test", "[magic][enchantments]" )
guy.i_add( item( "test_ATTACK_SPEED_ench_item_2" ) );
// 100 moves per attack
INFO( "10 attacks cost 1000 moves" );
moves_spent_on_attacks = test_melee_attack_attack_speed( guy );
moves_spent_on_attacks = test_melee_attack_attack_speed( guy, mon );
REQUIRE( moves_spent_on_attacks == -1000 );
}


static int test_melee_attack_attack_stamina( Character &guy )
static int test_melee_attack_attack_stamina( Character &guy, Creature &mon )
{
int i = 0;
int stamina_prev = 0;
Expand All @@ -271,7 +274,7 @@ static int test_melee_attack_attack_stamina( Character &guy )

while( i != 10 ) {
stamina_prev = guy.get_stamina();
guy.melee_attack_abstract( guy, false, matec_id( "" ) );
guy.melee_attack_abstract( mon, false, matec_id( "" ) );
add_msg( "attack %i: stamina cost: %i, current amount of stamina: %i", i,
stamina_prev - guy.get_stamina(),
guy.get_stamina() );
Expand All @@ -289,6 +292,8 @@ TEST_CASE( "Enchantment_MELEE_STAMINA_CONSUMPTION_test", "[magic][enchantments]"
Character &guy = get_player_character();
clear_avatar();
g->place_critter_at( pseudo_debug_mon, tripoint_south );
creature_tracker &creatures = get_creature_tracker();
Creature &mon = *creatures.creature_at<Creature>( tripoint_south );
int stamina_init = 0;
int stamina_current = 0;
int stamina_spent = 0;
Expand All @@ -299,7 +304,7 @@ TEST_CASE( "Enchantment_MELEE_STAMINA_CONSUMPTION_test", "[magic][enchantments]"
// 165 stamina per attack
INFO( "10 attacks cost 1650 stamina" );
stamina_init = guy.get_stamina();
stamina_current = test_melee_attack_attack_stamina( guy );
stamina_current = test_melee_attack_attack_stamina( guy, mon );
stamina_spent = stamina_init - stamina_current;
REQUIRE( stamina_spent == 1650 );
clear_avatar();
Expand All @@ -310,7 +315,7 @@ TEST_CASE( "Enchantment_MELEE_STAMINA_CONSUMPTION_test", "[magic][enchantments]"
// 65 stamina per attack
INFO( "10 attacks cost 650 stamina" );
stamina_init = guy.get_stamina();
stamina_current = test_melee_attack_attack_stamina( guy );
stamina_current = test_melee_attack_attack_stamina( guy, mon );
stamina_spent = stamina_init - stamina_current;
REQUIRE( stamina_spent == 650 );
clear_avatar();
Expand All @@ -321,7 +326,7 @@ TEST_CASE( "Enchantment_MELEE_STAMINA_CONSUMPTION_test", "[magic][enchantments]"
// 330 stamina per attack
INFO( "10 attacks cost 3300 stamina" );
stamina_init = guy.get_stamina();
stamina_current = test_melee_attack_attack_stamina( guy );
stamina_current = test_melee_attack_attack_stamina( guy, mon );
stamina_spent = stamina_init - stamina_current;
REQUIRE( stamina_spent == 3300 );
clear_avatar();
Expand Down

0 comments on commit 4e7e229

Please sign in to comment.