Skip to content

Commit

Permalink
Remove islot_magazine::protects_contents
Browse files Browse the repository at this point in the history
  • Loading branch information
ymber authored and kevingranade committed May 31, 2020
1 parent 2e2f8e9 commit 62ef415
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 37 deletions.
30 changes: 3 additions & 27 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8371,13 +8371,6 @@ bool item::will_explode_in_fire() const
return true;
}

// Most containers do nothing to protect the contents from fire
if( !type->magazine || !type->magazine->protects_contents ) {
return has_item_with( [&]( const item & it ) {
return this != &it && it.will_explode_in_fire();
} );
}

return false;
}

Expand All @@ -8389,15 +8382,11 @@ bool item::detonate( const tripoint &p, std::vector<item> &drops )
} else if( type->ammo && ( type->ammo->special_cookoff || type->ammo->cookoff ) ) {
int charges_remaining = charges;
const int rounds_exploded = rng( 1, charges_remaining / 2 );
// Yank the exploding item off the map for the duration of the explosion
// so it doesn't blow itself up.
const islot_ammo &ammo_type = *type->ammo;

if( ammo_type.special_cookoff ) {
if( type->ammo->special_cookoff ) {
// If it has a special effect just trigger it.
apply_ammo_effects( p, ammo_type.ammo_effects );
apply_ammo_effects( p, type->ammo->ammo_effects );
}
if( ammo_type.cookoff ) {
if( type->ammo->cookoff ) {
// If ammo type can burn, then create an explosion proportional to quantity.
explosion_handler::explosion( p, 3.0f * sqrtf( sqrtf( rounds_exploded / 25.0f ) ), 0.0f, false, 0 );
}
Expand All @@ -8409,19 +8398,6 @@ bool item::detonate( const tripoint &p, std::vector<item> &drops )
}

return true;
} else if( !contents.empty() && ( !type->magazine || !type->magazine->protects_contents ) ) {
std::vector<item *> removed_items;
bool detonated = false;
for( item *it : contents.all_items_top() ) {
if( it->detonate( p, drops ) ) {
removed_items.push_back( it );
detonated = true;
}
}
for( item *it : removed_items ) {
remove_item( *it );
}
return detonated;
}

return false;
Expand Down
1 change: 0 additions & 1 deletion src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,6 @@ void Item_factory::check_and_create_magazine_pockets( itype &def )
for( const ammotype &amtype : def.magazine->type ) {
mag_data.ammo_restriction.emplace( amtype, def.magazine->capacity );
}
mag_data.fire_protection = def.magazine->protects_contents;
}
if( def.gun ) {
for( const ammotype &amtype : def.gun->ammo ) {
Expand Down
3 changes: 0 additions & 3 deletions src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,6 @@ struct islot_magazine {

/** For ammo belts one linkage (of given type) is dropped for each unit of ammo consumed */
cata::optional<itype_id> linkage;

/** If false, ammo will cook off if this mag is affected by fire */
bool protects_contents = false;
};

struct islot_battery {
Expand Down
12 changes: 6 additions & 6 deletions src/map_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,17 @@ bool map::process_fields_in_submap( submap *const current_submap,
if( !is_sealed && map_tile.get_item_count() > 0 ) {
map_stack items_here = i_at( p );
std::vector<item> new_content;
for( auto explosive = items_here.begin(); explosive != items_here.end(); ) {
if( explosive->will_explode_in_fire() ) {
for( auto it = items_here.begin(); it != items_here.end(); ) {
if( it->will_explode_in_fire() ) {
// We need to make a copy because the iterator validity is not predictable
item copy = *explosive;
explosive = items_here.erase( explosive );
item copy = *it;
it = items_here.erase( it );
if( copy.detonate( p, new_content ) ) {
// Need to restart, iterators may not be valid
explosive = items_here.begin();
it = items_here.begin();
}
} else {
++explosive;
++it;
}
}

Expand Down

0 comments on commit 62ef415

Please sign in to comment.