diff --git a/src/game.cpp b/src/game.cpp index eefcdebc56d94..f6442ee6ce932 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1598,7 +1598,7 @@ bool game::do_turn() autopilot_vehicles(); m.vehmove(); m.process_fields(); - m.process_active_items(); + m.process_items(); m.creature_in_field( u ); // Apply sounds from previous turn to monster and NPC AI. diff --git a/src/map.cpp b/src/map.cpp index 47492160c4c75..a264cf7cc5f75 100755 --- a/src/map.cpp +++ b/src/map.cpp @@ -4313,11 +4313,10 @@ void map::update_lum( item_location &loc, bool add ) } } -static bool process_item( item_stack &items, safe_reference &item_ref, - const tripoint &location, - const bool activate, const float insulation, const temperature_flag flag ) +static bool process_map_items( item_stack &items, safe_reference &item_ref, + const tripoint &location, const float insulation, const temperature_flag flag ) { - if( item_ref->process( nullptr, location, activate, insulation, flag ) ) { + if( item_ref->process( nullptr, location, false, insulation, flag ) ) { // Item is to be destroyed so erase it from the map stack // unless it was already destroyed by processing. if( item_ref ) { @@ -4329,13 +4328,6 @@ static bool process_item( item_stack &items, safe_reference &item_ref, return false; } -static bool process_map_items( item_stack &items, safe_reference &item_ref, - const tripoint &location, const std::string &, - const float insulation, const temperature_flag flag ) -{ - return process_item( items, item_ref, location, false, insulation, flag ); -} - static void process_vehicle_items( vehicle &cur_veh, int part ) { const bool washmachine_here = cur_veh.part_flag( part, VPFLAG_WASHING_MACHINE ) && @@ -4422,11 +4414,6 @@ static void process_vehicle_items( vehicle &cur_veh, int part ) } } -void map::process_active_items() -{ - process_items( true, process_map_items, std::string {} ); -} - std::vector map::check_submap_active_item_consistency() { std::vector result; @@ -4453,8 +4440,7 @@ std::vector map::check_submap_active_item_consistency() return result; } -void map::process_items( const bool active, map::map_process_func processor, - const std::string &signal ) +void map::process_items() { const int minz = zlevels ? -OVERMAP_DEPTH : abs_sub.z; const int maxz = zlevels ? OVERMAP_HEIGHT : abs_sub.z; @@ -4468,7 +4454,7 @@ void map::process_items( const bool active, map::map_process_func processor, for( const tripoint &pos : submaps_with_vehicles ) { submap *const current_submap = get_submap_at_grid( pos ); // Vehicles first in case they get blown up and drop active items on the map. - process_items_in_vehicles( *current_submap, pos.z, processor, signal ); + process_items_in_vehicles( *current_submap ); } } // Making a copy, in case the original variable gets modified during `process_items_in_submap` @@ -4476,14 +4462,13 @@ void map::process_items( const bool active, map::map_process_func processor, for( const tripoint &abs_pos : submaps_with_active_items_copy ) { const tripoint local_pos = abs_pos - abs_sub.xy(); submap *const current_submap = get_submap_at_grid( local_pos ); - if( !active || !current_submap->active_items.empty() ) { - process_items_in_submap( *current_submap, local_pos, processor, signal ); + if( !current_submap->active_items.empty() ) { + process_items_in_submap( *current_submap, local_pos ); } } } -void map::process_items_in_submap( submap ¤t_submap, const tripoint &gridp, - map::map_process_func processor, const std::string &signal ) +void map::process_items_in_submap( submap ¤t_submap, const tripoint &gridp ) { // Get a COPY of the active item list for this submap. // If more are added as a side effect of processing, they are ignored this turn. @@ -4503,12 +4488,11 @@ void map::process_items_in_submap( submap ¤t_submap, const tripoint &gridp flag = temperature_flag::TEMP_ROOT_CELLAR; } map_stack items = i_at( map_location ); - processor( items, active_item_ref.item_ref, map_location, signal, 1, flag ); + process_map_items( items, active_item_ref.item_ref, map_location, 1, flag ); } } -void map::process_items_in_vehicles( submap ¤t_submap, const int gridz, - map::map_process_func processor, const std::string &signal ) +void map::process_items_in_vehicles( submap ¤t_submap ) { // a copy, important if the vehicle list changes because a // vehicle got destroyed by a bomb (an active item!), this list @@ -4525,12 +4509,11 @@ void map::process_items_in_vehicles( submap ¤t_submap, const int gridz, continue; } - process_items_in_vehicle( *cur_veh, current_submap, gridz, processor, signal ); + process_items_in_vehicle( *cur_veh, current_submap ); } } -void map::process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap, const int /*gridz*/, - map::map_process_func processor, const std::string &signal ) +void map::process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap ) { const bool engine_heater_is_on = cur_veh.has_part( "E_HEATER", true ) && cur_veh.engine_on; for( const vpart_reference &vp : cur_veh.get_any_parts( VPFLAG_FLUIDTANK ) ) { @@ -4580,7 +4563,7 @@ void map::process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap, co flag = temperature_flag::TEMP_FREEZER; } } - if( !processor( items, active_item_ref.item_ref, item_loc, signal, it_insulation, flag ) ) { + if( !process_map_items( items, active_item_ref.item_ref, item_loc, it_insulation, flag ) ) { // If the item was NOT destroyed, we can skip the remainder, // which handles fallout from the vehicle being damaged. continue; diff --git a/src/map.h b/src/map.h index 3dacf3033bd3f..688ea6b4e779c 100644 --- a/src/map.h +++ b/src/map.h @@ -984,8 +984,6 @@ class map set_temperature( tripoint( p, abs_sub.z ), new_temperature ); } - // Items - void process_active_items(); // Returns points for all submaps with inconsistent state relative to // the list in map. Used in tests. std::vector check_submap_active_item_consistency(); @@ -1691,26 +1689,12 @@ class map ter_id get_roof( const tripoint &p, bool allow_air ); public: - /** - * Processor function pointer used in process_items and brethren. - * - * Note, typedefs should be discouraged because they tend to obfuscate - * code, but due to complexity, a template type makes it worse here. - * It's a really heinous function pointer so a typedef is the best - * solution in this instance. - */ - using map_process_func = bool ( * )( item_stack &, safe_reference &, const tripoint &, - const std::string &, float, temperature_flag ); + void process_items(); private: - // Iterates over every item on the map, passing each item to the provided function. - void process_items( bool active, map_process_func processor, const std::string &signal ); - void process_items_in_submap( submap ¤t_submap, const tripoint &gridp, - map::map_process_func processor, const std::string &signal ); - void process_items_in_vehicles( submap ¤t_submap, int gridz, - map_process_func processor, const std::string &signal ); - void process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap, int gridz, - map::map_process_func processor, const std::string &signal ); + void process_items_in_submap( submap ¤t_submap, const tripoint &gridp ); + void process_items_in_vehicles( submap ¤t_submap ); + void process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap ); /** Enum used by functors in `function_over` to control execution. */ enum iteration_state {