Skip to content

Commit

Permalink
Fix coordinate handling re submaps_with_active_items
Browse files Browse the repository at this point in the history
This was using abs_sub inapropriately to convert between absolute and local coordinates.
Only x and y coordinates need conversion, z does not.
Also map::get_active_items_in_radius() was failing to convert entirely.
  • Loading branch information
kevingranade committed Jul 14, 2019
1 parent 49d4715 commit bbf6f77
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/map.cpp
Expand Up @@ -4118,7 +4118,7 @@ map_stack::iterator map::i_rem( const tripoint &p, map_stack::const_iterator it
// remove from the active items cache (if it isn't there does nothing)
current_submap->active_items.remove( &*it );
if( current_submap->active_items.empty() ) {
submaps_with_active_items.erase( abs_sub + tripoint( p.x / SEEX, p.y / SEEY, p.z ) );
submaps_with_active_items.erase( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) );
}

current_submap->update_lum_rem( l, *it );
Expand All @@ -4145,7 +4145,7 @@ void map::i_clear( const tripoint &p )
current_submap->active_items.remove( &it );
}
if( current_submap->active_items.empty() ) {
submaps_with_active_items.erase( abs_sub + tripoint( p.x / SEEX, p.y / SEEY, p.z ) );
submaps_with_active_items.erase( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) );
}

current_submap->lum[l.x][l.y] = 0;
Expand Down Expand Up @@ -4365,7 +4365,7 @@ item &map::add_item( const tripoint &p, item new_item )
const map_stack::iterator new_pos = current_submap->itm[l.x][l.y].insert( new_item );
if( new_item.needs_processing() ) {
if( current_submap->active_items.empty() ) {
submaps_with_active_items.insert( abs_sub + tripoint( p.x / SEEX, p.y / SEEY, p.z ) );
submaps_with_active_items.insert( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) );
}
current_submap->active_items.add( *new_pos, l );
}
Expand Down Expand Up @@ -4428,8 +4428,8 @@ void map::make_active( item_location &loc )
cata::colony<item>::iterator iter = item_stack.get_iterator_from_pointer( target );

if( current_submap->active_items.empty() ) {
submaps_with_active_items.insert( abs_sub + tripoint( loc.position().x / SEEX,
loc.position().y / SEEY, loc.position().z ) );
submaps_with_active_items.insert( tripoint( abs_sub.x + loc.position().x / SEEX,
abs_sub.y + loc.position().y / SEEY, loc.position().z ) );
}
current_submap->active_items.add( *iter, l );
}
Expand Down Expand Up @@ -4549,7 +4549,7 @@ void map::process_items( const bool active, map::map_process_func processor,
}
}
for( const tripoint &abs_pos : submaps_with_active_items ) {
const tripoint local_pos = abs_pos - abs_sub;
const tripoint local_pos = tripoint( abs_pos.xy() - abs_sub.xy(), abs_pos.z );
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 );
Expand Down Expand Up @@ -5528,7 +5528,7 @@ void map::update_submap_active_item_status( const tripoint &p )
point l;
submap *const current_submap = get_submap_at( p, l );
if( current_submap->active_items.empty() ) {
submaps_with_active_items.erase( abs_sub + tripoint( p.x / SEEX, p.y / SEEY, p.z ) );
submaps_with_active_items.erase( tripoint( abs_sub.x + p.x / SEEX, abs_sub.y + p.y / SEEY, p.z ) );
}
}

Expand Down Expand Up @@ -8382,7 +8382,8 @@ std::list<item_location> map::get_active_items_in_radius( const tripoint &center
const point maxg( std::min( maxp.x / SEEX, my_MAPSIZE - 1 ),
std::min( maxp.y / SEEY, my_MAPSIZE - 1 ) );

for( const tripoint &submap_loc : submaps_with_active_items ) {
for( const tripoint &abs_submap_loc : submaps_with_active_items ) {
const tripoint submap_loc{ abs_submap_loc.xy() - abs_sub.xy(), abs_submap_loc.z };
if( submap_loc.x < ming.x || submap_loc.y < ming.y ||
submap_loc.x > maxg.x || submap_loc.y > maxg.y ) {
continue;
Expand Down

0 comments on commit bbf6f77

Please sign in to comment.