From 1bb530ef979ae05448e7fb6d1bccd93627504593 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Mon, 10 Feb 2020 15:45:40 +0100 Subject: [PATCH] Partially encapsulate fld --- src/lightmap.cpp | 4 ++-- src/map.cpp | 12 ++++++------ src/map_field.cpp | 2 +- src/submap.h | 14 +++++++++++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/lightmap.cpp b/src/lightmap.cpp index cfb868e350d88..35621adb8e9d7 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -126,7 +126,7 @@ bool map::build_transparency_cache( const int zlev ) zero_value = value; continue; } - for( const auto &fld : cur_submap->fld[sx][sy] ) { + for( const auto &fld : cur_submap->get_field( { sx, sy } ) ) { const field_entry &cur = fld.second; if( cur.is_transparent() ) { continue; @@ -331,7 +331,7 @@ void map::generate_lightmap( const int zlev ) add_light_source( p, furniture->light_emitted ); } - for( auto &fld : cur_submap->fld[sx][sy] ) { + for( auto &fld : cur_submap->get_field( { sx, sy } ) ) { const field_entry *cur = &fld.second; const int light_emitted = cur->light_emitted(); if( light_emitted > 0 ) { diff --git a/src/map.cpp b/src/map.cpp index c9b9d06fbce3f..a3aec2162a282 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2521,7 +2521,7 @@ void map::decay_fields_and_scent( const time_duration &amount ) const int x = sx + smx * SEEX; const int y = sy + smy * SEEY; - field &fields = cur_submap->fld[sx][sy]; + field &fields = cur_submap->get_field( { sx, sy} ); if( !outside_cache[x][y] ) { to_proc -= fields.field_count(); continue; @@ -5118,7 +5118,7 @@ const field &map::field_at( const tripoint &p ) const point l; submap *const current_submap = get_submap_at( p, l ); - return current_submap->fld[l.x][l.y]; + return current_submap->get_field( l ); } /* @@ -5134,7 +5134,7 @@ field &map::field_at( const tripoint &p ) point l; submap *const current_submap = get_submap_at( p, l ); - return current_submap->fld[l.x][l.y]; + return current_submap->get_field( l ); } time_duration map::mod_field_age( const tripoint &p, const field_type_id &type, @@ -5202,7 +5202,7 @@ field_entry *map::get_field( const tripoint &p, const field_type_id &type ) point l; submap *const current_submap = get_submap_at( p, l ); - return current_submap->fld[l.x][l.y].find_field( type ); + return current_submap->get_field( l ).find_field( type ); } bool map::dangerous_field_at( const tripoint &p ) @@ -5239,7 +5239,7 @@ bool map::add_field( const tripoint &p, const field_type_id &type, int intensity submap *const current_submap = get_submap_at( p, l ); current_submap->is_uniform = false; - if( current_submap->fld[l.x][l.y].add_field( type, intensity, age ) ) { + if( current_submap->get_field( l ).add_field( type, intensity, age ) ) { //Only adding it to the count if it doesn't exist. if( !current_submap->field_count++ ) { get_cache( p.z ).field_cache.set( static_cast( p.x / SEEX + ( ( @@ -5276,7 +5276,7 @@ void map::remove_field( const tripoint &p, const field_type_id &field_to_remove point l; submap *const current_submap = get_submap_at( p, l ); - if( current_submap->fld[l.x][l.y].remove_field( field_to_remove ) ) { + if( current_submap->get_field( l ).remove_field( field_to_remove ) ) { // Only adjust the count if the field actually existed. if( !--current_submap->field_count ) { get_cache( p.z ).field_cache.set( static_cast( p.x / SEEX + ( ( diff --git a/src/map_field.cpp b/src/map_field.cpp index 1cd4247eb2e15..a7c5529b087cb 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -383,7 +383,7 @@ bool map::process_fields_in_submap( submap *const current_submap, const tripoint &p = thep; // Get a reference to the field variable from the submap; // contains all the pointers to the real field effects. - field &curfield = current_submap->fld[locx][locy]; + field &curfield = current_submap->get_field( { static_cast( locx ), static_cast( locy ) } ); for( auto it = curfield.begin(); it != curfield.end(); ) { // Iterating through all field effects in the submap's field. field_entry &cur = it->second; diff --git a/src/submap.h b/src/submap.h index 369c2f2b4d412..6ccb9ab875f80 100644 --- a/src/submap.h +++ b/src/submap.h @@ -157,6 +157,14 @@ class submap : public maptile_soa // TODO: Use private inheritanc return itm[p.x][p.y]; } + field &get_field( const point &p ) { + return fld[p.x][p.y]; + } + + const field &get_field( const point &p ) const { + return fld[p.x][p.y]; + } + struct cosmetic_t { point pos; std::string type; @@ -283,16 +291,16 @@ struct maptile { } const field &get_field() const { - return sm->fld[x][y]; + return sm->get_field( pos() ); } field_entry *find_field( const field_type_id &field_to_find ) { - return sm->fld[x][y].find_field( field_to_find ); + return sm->get_field( pos() ).find_field( field_to_find ); } bool add_field( const field_type_id &field_to_add, const int new_intensity, const time_duration &new_age ) { - const bool ret = sm->fld[x][y].add_field( field_to_add, new_intensity, new_age ); + const bool ret = sm->get_field( pos() ).add_field( field_to_add, new_intensity, new_age ); if( ret ) { sm->field_count++; }