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
|
#include "cata_catch.h"
#include "activity_actor_definitions.h"
#include "avatar.h"
#include "calendar.h"
#include "item.h"
#include "map.h"
#include "player_helpers.h"
#include "point.h"
#include <string>
static void check_reload_time( const std::string &weapon, const std::string &ammo,
const std::string &container, int expected_moves )
{
const tripoint test_origin( 60, 60, 0 );
avatar &shooter = get_avatar();
shooter.setpos( test_origin );
shooter.set_wielded_item( item( weapon, calendar::turn_zero, 0 ) );
if( container.empty() ) {
get_map().add_item( test_origin, item( ammo ) );
} else {
shooter.worn.wear_item( shooter, item( container ), false, false );
shooter.i_add( item( ammo, calendar::turn_zero, 1 ) );
}
REQUIRE( !!shooter.used_weapon() );
// Spooky action at a distance to tell load_RAS_weapon where to find the ammo.
item::reload_option opt = shooter.select_ammo( shooter.used_weapon(), false );
shooter.ammo_location = opt.ammo;
CAPTURE( opt.moves() );
CAPTURE( opt.ammo.obtain_cost( shooter, 1 ) );
CAPTURE( shooter.item_reload_cost( *shooter.used_weapon(), *opt.ammo, 1 ) );
CAPTURE( shooter.used_weapon()->get_reload_time() );
CAPTURE( shooter.item_handling_cost( *shooter.used_weapon(), true, 0 ) );
CAPTURE( shooter.used_weapon()->get_reload_time() );
aim_activity_actor act = aim_activity_actor::use_wielded();
int moves_before = shooter.moves;
REQUIRE( act.load_RAS_weapon() );
int moves_after = shooter.moves;
int spent_moves = moves_before - moves_after;
int expected_upper = expected_moves * 1.05;
int expected_lower = expected_moves * 0.95;
CHECK( spent_moves > expected_lower );
CHECK( spent_moves < expected_upper );
}
TEST_CASE( "reload_from_inventory_times", "[reload],[inventory],[balance]" )
{
// Build a list of gear loadouts ranked by expected firing speed.
clear_avatar();
SECTION( "reloading a slingshot" ) {
SECTION( "from a backpack" ) {
check_reload_time( "slingshot", "pebble", "backpack", 350 );
}
SECTION( "from an ammo pouch" ) {
check_reload_time( "slingshot", "pebble", "ammo_pouch", 87 );
}
SECTION( "from a tool belt" ) {
check_reload_time( "slingshot", "pebble", "tool_belt", 150 );
}
SECTION( "from a pocket" ) {
check_reload_time( "slingshot", "pebble", "pants", 150 );
}
SECTION( "from the ground" ) {
check_reload_time( "slingshot", "pebble", "", 130 );
}
}
SECTION( "reloading a staff sling" ) {
SECTION( "from a backpack" ) {
check_reload_time( "staff_sling", "rock", "backpack", 375 );
}
SECTION( "from a stone pouch" ) {
check_reload_time( "staff_sling", "rock", "stone_pouch", 95 );
}
SECTION( "from a tool belt" ) {
check_reload_time( "staff_sling", "rock", "tool_belt", 160 );
}
SECTION( "from a pocket" ) {
check_reload_time( "staff_sling", "rock", "pants", 175 );
}
SECTION( "from the ground" ) {
check_reload_time( "staff_sling", "rock", "", 150 );
}
}
SECTION( "reloading a bow" ) {
SECTION( "from a duffel bag" ) {
check_reload_time( "longbow", "arrow_wood", "long_duffelbag", 360 );
}
SECTION( "from a quiver" ) {
check_reload_time( "longbow", "arrow_wood", "quiver", 80 );
}
SECTION( "from the ground" ) {
check_reload_time( "longbow", "arrow_wood", "", 140 );
}
}
}
|