From dcd172891261635d2820538182204552103ed813 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 11:47:14 +0100 Subject: [PATCH] Partially encapsulate itm --- src/map.cpp | 16 ++++++++-------- src/submap.h | 12 ++++++++++-- src/visitable.cpp | 6 +++--- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/map.cpp b/src/map.cpp index 8d53a52a2e0c2..c9b9d06fbce3f 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -3901,7 +3901,7 @@ map_stack map::i_at( const tripoint &p ) point l; submap *const current_submap = get_submap_at( p, l ); - return map_stack{ ¤t_submap->itm[l.x][l.y], p, this }; + return map_stack{ ¤t_submap->get_items( l ), p, this }; } map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it ) @@ -3917,7 +3917,7 @@ map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it current_submap->update_lum_rem( l, *it ); - return current_submap->itm[l.x][l.y].erase( it ); + return current_submap->get_items( l ).erase( it ); } void map::i_rem( const tripoint &p, item *it ) @@ -3934,7 +3934,7 @@ void map::i_clear( const tripoint &p ) point l; submap *const current_submap = get_submap_at( p, l ); - for( item &it : current_submap->itm[l.x][l.y] ) { + for( item &it : current_submap->get_items( l ) ) { // remove from the active items cache (if it isn't there does nothing) current_submap->active_items.remove( &it ); } @@ -3943,7 +3943,7 @@ void map::i_clear( const tripoint &p ) } current_submap->set_lum( l, 0 ); - current_submap->itm[l.x][l.y].clear(); + current_submap->get_items( l ).clear(); } item &map::spawn_an_item( const tripoint &p, item new_item, @@ -4171,7 +4171,7 @@ item &map::add_item( const tripoint &p, item new_item ) current_submap->is_uniform = false; current_submap->update_lum_add( l, new_item ); - const map_stack::iterator new_pos = current_submap->itm[l.x][l.y].insert( new_item ); + const map_stack::iterator new_pos = current_submap->get_items( l ).insert( new_item ); if( new_item.needs_processing() ) { if( current_submap->active_items.empty() ) { submaps_with_active_items.insert( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) ); @@ -4233,7 +4233,7 @@ void map::make_active( item_location &loc ) } point l; submap *const current_submap = get_submap_at( loc.position(), l ); - cata::colony &item_stack = current_submap->itm[l.x][l.y]; + cata::colony &item_stack = current_submap->get_items( l ); cata::colony::iterator iter = item_stack.get_iterator_from_pointer( target ); if( current_submap->active_items.empty() ) { @@ -4600,7 +4600,7 @@ bool map::has_items( const tripoint &p ) const point l; submap *const current_submap = get_submap_at( p, l ); - return !current_submap->itm[l.x][l.y].empty(); + return !current_submap->get_items( l ).empty(); } template @@ -7035,7 +7035,7 @@ void map::actualize( const tripoint &grid ) } // plants contain a seed item which must not be removed under any circumstances if( !furn.has_flag( "DONT_REMOVE_ROTTEN" ) ) { - remove_rotten_items( tmpsub->itm[x][y], pnt ); + remove_rotten_items( tmpsub->get_items( { x, y } ), pnt ); } const auto trap_here = tmpsub->get_trap( p ); diff --git a/src/submap.h b/src/submap.h index 1b4b515ce2461..369c2f2b4d412 100644 --- a/src/submap.h +++ b/src/submap.h @@ -149,6 +149,14 @@ class submap : public maptile_soa // TODO: Use private inheritanc } } + cata::colony &get_items( const point &p ) { + return itm[p.x][p.y]; + } + + const cata::colony &get_items( const point &p ) const { + return itm[p.x][p.y]; + } + struct cosmetic_t { point pos; std::string type; @@ -314,12 +322,12 @@ struct maptile { // For map::draw_maptile size_t get_item_count() const { - return sm->itm[x][y].size(); + return sm->get_items( pos() ).size(); } // Assumes there is at least one item const item &get_uppermost_item() const { - return *std::prev( sm->itm[x][y].cend() ); + return *std::prev( sm->get_items( pos() ).cend() ); } }; diff --git a/src/visitable.cpp b/src/visitable.cpp index 607c2589c9dc9..501faf2754cda 100644 --- a/src/visitable.cpp +++ b/src/visitable.cpp @@ -657,9 +657,9 @@ std::list visitable::remove_items_with( const // fetch the appropriate item stack point offset; submap *sub = g->m.get_submap_at( *cur, offset ); + cata::colony &stack = sub->get_items( offset ); - for( auto iter = sub->itm[ offset.x ][ offset.y ].begin(); - iter != sub->itm[ offset.x ][ offset.y ].end(); ) { + for( auto iter = stack.begin(); iter != stack.end(); ) { if( filter( *iter ) ) { // remove from the active items cache (if it isn't there does nothing) sub->active_items.remove( &*iter ); @@ -669,7 +669,7 @@ std::list visitable::remove_items_with( const // finally remove the item res.push_back( *iter ); - iter = sub->itm[ offset.x ][ offset.y ].erase( iter ); + iter = stack.erase( iter ); if( --count == 0 ) { return res;