Skip to content

Commit

Permalink
Fix charge spawning in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RenechCDDA committed Apr 2, 2024
1 parent 5782745 commit 2fcfdc4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ item::item( const itype *type, time_point turn, int qty ) : type( type ), bday(
if( qty >= 0 ) {
if( type->can_have_charges() ) {
charges = qty;
} else {
} else if( qty > 1 ) {
debugmsg( "Tried to set charges for item %s that could not have them!", tname() );
}
} else {
Expand Down
1 change: 0 additions & 1 deletion src/mattack_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ void gun_actor::shoot( monster &z, const tripoint &target, const gun_mode_id &mo
}

tmp.set_wielded_item( gun );
tmp.i_add( item( "UPS_off", calendar::turn, 1000 ) );

add_msg_if_player_sees( z, m_warning, description.translated(), z.name(),
tmp.get_wielded_item()->tname() );
Expand Down
2 changes: 1 addition & 1 deletion tests/food_fun_for_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ TEST_CASE( "fun_for_food_eaten_too_often", "[fun_for][food][monotony]" )
std::pair<int, int> actual_fun;

// A big box of tasty toast-ems
item toastem( "toastem", calendar::turn, 10 );
item toastem( "toastem", calendar::turn );
REQUIRE( toastem.is_comestible() );

// Base fun value and monotony penalty for toast-em
Expand Down
43 changes: 22 additions & 21 deletions tests/item_autopickup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ TEST_CASE( "auto_pickup_should_recognize_container_content", "[autopickup][item]
REQUIRE( here.i_at( ground ).empty() );

// add random items to the tile on the ground
here.add_item( ground, item( itype_marble, calendar::turn, 10 ) );
here.add_item( ground, item( itype_pebble, calendar::turn, 15 ) );
here.add_item( ground, item( itype_marble, calendar::turn ) );
here.add_item( ground, item( itype_pebble, calendar::turn ) );

// codeine (20)(WL)
// codeine (WL)
WHEN( "there is an item on the ground whitelisted in auto-pickup rules" ) {
unique_item item_codeine = unique_item( itype_codeine, 20 );
unique_item item_codeine = unique_item( itype_codeine );
REQUIRE( item_codeine.spawn_item( ground ) );
add_autopickup_rule( item_codeine.get(), true );

Expand All @@ -226,9 +226,9 @@ TEST_CASE( "auto_pickup_should_recognize_container_content", "[autopickup][item]
expect_to_find( backpack, { &item_codeine } );
}
}
// plastic prescription bottle > (WL)aspirin (12)
// plastic prescription bottle > (WL)aspirin
WHEN( "there is a container on the ground containing only items whitelisted in auto-pickup rules" ) {
unique_item item_aspirin = unique_item( itype_aspirin, 12 );
unique_item item_aspirin = unique_item( itype_aspirin );
unique_item item_prescription_bottle = unique_item(
itype_bottle_plastic_pill_prescription, {
&item_aspirin
Expand All @@ -244,10 +244,10 @@ TEST_CASE( "auto_pickup_should_recognize_container_content", "[autopickup][item]
} );
}
}
// plastic bag > paper (5), paper wrapper (WL) > chocolate candy (3)
// plastic bag > paper, paper wrapper (WL) > chocolate candy
WHEN( "there is a container on the ground with a deeply nested item whitelisted in auto-pickup rules" ) {
const unique_item item_paper = unique_item( itype_paper, 5 );
const unique_item item_chocolate_candy = unique_item( itype_candy2, 3 );
const unique_item item_paper = unique_item( itype_paper );
const unique_item item_chocolate_candy = unique_item( itype_candy2 );
const unique_item item_paper_wrapper = unique_item( itype_wrapper, {
&item_chocolate_candy
} );
Expand Down Expand Up @@ -387,8 +387,8 @@ TEST_CASE( "auto_pickup_should_consider_item_rigidness_and_seal", "[autopickup][
// small tin can (sealed) > canned tuna fish (WL), canned meat
WHEN( "there is a sealed container on the ground containing items whitelisted in auto-pickup rules" ) {
item item_medium_tin_can = item( itype_can_medium );
unique_item item_canned_tuna = unique_item( itype_can_tuna, 1, true );
unique_item item_canned_meat = unique_item( itype_meat_canned, 1, true );
unique_item item_canned_tuna = unique_item( itype_can_tuna, true );
unique_item item_canned_meat = unique_item( itype_meat_canned, true );

// insert items inside can and seal it
item_medium_tin_can.force_insert_item( *item_canned_tuna.get(), pocket_type_container );
Expand All @@ -410,8 +410,8 @@ TEST_CASE( "auto_pickup_should_consider_item_rigidness_and_seal", "[autopickup][
WHEN( "there is a sealed container on the ground containing no whitelisted items" ) {
item item_medium_tin_can = item( itype_can_medium );
item item_bottle_plastic = item( itype_bottle_plastic );
unique_item item_canned_tuna = unique_item( itype_can_tuna, 1, true );
unique_item item_canned_meat = unique_item( itype_meat_canned, 1, true );
unique_item item_canned_tuna = unique_item( itype_can_tuna, true );
unique_item item_canned_meat = unique_item( itype_meat_canned, true );

// insert items inside can and seal it
item_medium_tin_can.force_insert_item( *item_canned_tuna.get(), pocket_type_container );
Expand Down Expand Up @@ -447,15 +447,16 @@ TEST_CASE( "auto_pickup_should_respect_volume_and_weight_limits", "[autopickup][
item &backpack = *backpack_iter;
REQUIRE( they.has_item( backpack ) );

// backpack > lump of steel (5)(WL), cigrarette (3)(WL), paper (10)(WL)
// backpack > lump of steel (WL), cigrarette (WL), paper (WL)
GIVEN( "there is a container with some items that exceed volume or weight limit" ) {
options_manager &options = get_options();
options_manager::cOpt &ap_weight_limit = options.get_option( "AUTO_PICKUP_WEIGHT_LIMIT" );
options_manager::cOpt &ap_volume_limit = options.get_option( "AUTO_PICKUP_VOLUME_LIMIT" );

// Note: This relies on charge-spawning behavior for steel lumps
unique_item item_lump_of_steel = unique_item( itype_steel_lump, 5 );
unique_item item_cigarette = unique_item( itype_cig, 3 );
unique_item item_paper = unique_item( itype_paper, 10 );
unique_item item_cigarette = unique_item( itype_cig );
unique_item item_paper = unique_item( itype_paper );
unique_item item_backpack = unique_item( itype_backpack, {
&item_lump_of_steel, &item_cigarette, &item_paper
} );
Expand Down Expand Up @@ -524,16 +525,16 @@ TEST_CASE( "auto_pickup_should_consider_item_ownership", "[autopickup][item]" )
REQUIRE( they.has_item( backpack ) );

// candy cigarette(WL)
// pack(WL) > cigarette (2)(WL), rolling paper (10)(WL)
// pack(WL) > cigarette (WL), rolling paper (WL)
GIVEN( "there is a container with some items and an item outside it on the ground" ) {
options_manager::cOpt &autopickup_owned = get_options().get_option( "AUTO_PICKUP_OWNED" );
// make sure the autopickup owned option is disabled
if( autopickup_owned.value_as<bool>() ) {
autopickup_owned.setValue( "false" );
}
unique_item item_candy_cigarette = unique_item( itype_candycigarette );
unique_item item_cigarette = unique_item( itype_cig, 2 );
unique_item item_rolling_paper = unique_item( itype_rolling_paper, 10 );
unique_item item_cigarette = unique_item( itype_cig );
unique_item item_rolling_paper = unique_item( itype_rolling_paper );
unique_item item_pack = unique_item( itype_box_cigarette, {
&item_cigarette, &item_rolling_paper
} );
Expand Down Expand Up @@ -601,8 +602,8 @@ TEST_CASE( "auto_pickup_should_not_implicitly_pickup_corpses", "[autopickup][ite
expect_to_find( *body_bag, {} );
}
WHEN( "the corpse contains whitelisted items" ) {
unique_item item_cigarette = unique_item( itype_cig, 5 );
unique_item item_rolling_paper = unique_item( itype_rolling_paper, 10 );
unique_item item_cigarette = unique_item( itype_cig );
unique_item item_rolling_paper = unique_item( itype_rolling_paper );

item *found = item_corpse.find_on_ground( ground );
found->force_insert_item( *item_cigarette.get(), pocket_type_container );
Expand Down

0 comments on commit 2fcfdc4

Please sign in to comment.