diff --git a/src/computer.cpp b/src/computer.cpp index 2897ecc887b56..d234a47ea3ea2 100644 --- a/src/computer.cpp +++ b/src/computer.cpp @@ -592,10 +592,11 @@ void computer::activate_function( computer_action action ) const tripoint center = g->u.global_omt_location(); for( int i = -60; i <= 60; i++ ) { for( int j = -60; j <= 60; j++ ) { - const oter_id &oter = overmap_buffer.ter( center.x + i, center.y + j, center.z ); + point offset( i, j ); + const oter_id &oter = overmap_buffer.ter( center + offset ); if( is_ot_match( "sewer", oter, ot_match_type::type ) || is_ot_match( "sewage", oter, ot_match_type::prefix ) ) { - overmap_buffer.set_seen( center.x + i, center.y + j, center.z, true ); + overmap_buffer.set_seen( center + offset, true ); } } } @@ -609,10 +610,11 @@ void computer::activate_function( computer_action action ) const tripoint center = g->u.global_omt_location(); for( int i = -60; i <= 60; i++ ) { for( int j = -60; j <= 60; j++ ) { - const oter_id &oter = overmap_buffer.ter( center.x + i, center.y + j, center.z ); + point offset( i, j ); + const oter_id &oter = overmap_buffer.ter( center + offset ); if( is_ot_match( "subway", oter, ot_match_type::type ) || is_ot_match( "lab_train_depot", oter, ot_match_type::contains ) ) { - overmap_buffer.set_seen( center.x + i, center.y + j, center.z, true ); + overmap_buffer.set_seen( center + offset, true ); } } } @@ -628,6 +630,10 @@ void computer::activate_function( computer_action action ) add_msg( m_info, _( "Target acquisition canceled." ) ); return; } + + // TODO: Z + target.z = 0; + if( query_yn( _( "Confirm nuclear missile launch." ) ) ) { add_msg( m_info, _( "Nuclear missile launched!" ) ); //Remove the option to fire another missile. @@ -666,7 +672,7 @@ void computer::activate_function( computer_action action ) tmpmap.save(); } - const oter_id oter = overmap_buffer.ter( target.x, target.y, 0 ); + const oter_id oter = overmap_buffer.ter( target ); //~ %s is terrain name g->u.add_memorial_log( pgettext( "memorial_male", "Launched a nuke at a %s." ), pgettext( "memorial_female", "Launched a nuke at a %s." ), diff --git a/src/defense.cpp b/src/defense.cpp index 56f8d4e78e82b..21b52b56ca199 100644 --- a/src/defense.cpp +++ b/src/defense.cpp @@ -213,7 +213,7 @@ void defense_game::init_constructions() void defense_game::init_map() { - auto &starting_om = overmap_buffer.get( 0, 0 ); + auto &starting_om = overmap_buffer.get( point_zero ); for( int x = 0; x < OMAPX; x++ ) { for( int y = 0; y < OMAPY; y++ ) { starting_om.ter( x, y, 0 ) = oter_id( "field" ); diff --git a/src/editmap.cpp b/src/editmap.cpp index 0d38d8c3c1f95..df3b2e922c1df 100644 --- a/src/editmap.cpp +++ b/src/editmap.cpp @@ -1644,7 +1644,7 @@ int editmap::mapgen_preview( const real_coords &tc, uilist &gmenu ) // Coordinates of the overmap terrain that should be generated. const point omt_pos = ms_to_omt_copy( tc.abs_pos ); - oter_id &omt_ref = overmap_buffer.ter( omt_pos.x, omt_pos.y, target.z ); + oter_id &omt_ref = overmap_buffer.ter( tripoint( omt_pos, target.z ) ); // Copy to store the original value, to restore it upon canceling const oter_id orig_oters = omt_ref; omt_ref = oter_id( gmenu.ret ); diff --git a/src/explosion.cpp b/src/explosion.cpp index 6179c7ca9cdf7..4b756c9a7b1b7 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -19,6 +19,7 @@ #include "calendar.h" #include "cata_utility.h" #include "color.h" +#include "coordinate_conversions.h" #include "creature.h" #include "damage.h" #include "debug.h" @@ -822,10 +823,9 @@ void nuke( const tripoint &p ) { // TODO: nukes hit above surface, not critter = 0 // TODO: Z - int x = p.x; - int y = p.y; + tripoint p_surface( p.xy(), 0 ); tinymap tmpmap; - tmpmap.load( x * 2, y * 2, 0, false ); + tmpmap.load( omt_to_sm_copy( p_surface ), false ); tripoint dest( 0, 0, p.z ); int &i = dest.x; int &j = dest.y; @@ -841,9 +841,9 @@ void nuke( const tripoint &p ) } } tmpmap.save(); - overmap_buffer.ter( x, y, 0 ) = oter_id( "crater" ); + overmap_buffer.ter( p_surface ) = oter_id( "crater" ); // Kill any npcs on that omap location. - for( const auto &npc : overmap_buffer.get_npcs_near_omt( x, y, 0, 0 ) ) { + for( const auto &npc : overmap_buffer.get_npcs_near_omt( p_surface, 0 ) ) { npc->marked_for_death = true; } } diff --git a/src/faction.cpp b/src/faction.cpp index 9f24f30025094..c798a4314743e 100644 --- a/src/faction.cpp +++ b/src/faction.cpp @@ -405,7 +405,7 @@ int npc::faction_display( const catacurses::window &fac_w, const int width ) con cata::optional dest = get_mission_destination(); if( dest ) { basecamp *dest_camp; - cata::optional temp_camp = overmap_buffer.find_camp( dest->x, dest->y ); + cata::optional temp_camp = overmap_buffer.find_camp( dest->xy() ); if( temp_camp ) { dest_camp = *temp_camp; dest_string = _( "travelling to : " ) + dest_camp->camp_name(); @@ -423,7 +423,7 @@ int npc::faction_display( const catacurses::window &fac_w, const int width ) con tripoint guy_abspos = global_omt_location(); basecamp *stationed_at; bool is_stationed = false; - cata::optional p = overmap_buffer.find_camp( guy_abspos.x, guy_abspos.y ); + cata::optional p = overmap_buffer.find_camp( guy_abspos.xy() ); if( p ) { is_stationed = true; stationed_at = *p; @@ -467,10 +467,10 @@ int npc::faction_display( const catacurses::window &fac_w, const int width ) con } } // if camp that player is at, has a radio tower - cata::optional player_camp = overmap_buffer.find_camp( g->u.global_omt_location().x, - g->u.global_omt_location().y ); + cata::optional player_camp = + overmap_buffer.find_camp( g->u.global_omt_location().xy() ); if( const cata::optional player_camp = overmap_buffer.find_camp( - g->u.global_omt_location().x, g->u.global_omt_location().y ) ) { + g->u.global_omt_location().xy() ) ) { if( ( *player_camp )->has_provides( "radio_tower" ) ) { max_range *= 5; } @@ -607,7 +607,7 @@ void new_faction_manager::display() const // create a list of faction camps std::vector camps; for( auto elem : g->u.camps ) { - cata::optional p = overmap_buffer.find_camp( elem.x, elem.y ); + cata::optional p = overmap_buffer.find_camp( elem.xy() ); if( !p ) { continue; } diff --git a/src/faction_camp.cpp b/src/faction_camp.cpp index 0125c587d51d8..a86b32e97aaae 100644 --- a/src/faction_camp.cpp +++ b/src/faction_camp.cpp @@ -431,12 +431,12 @@ static cata::optional get_basecamp( npc &p, const std::string &camp_ { tripoint omt_pos = p.global_omt_location(); - cata::optional bcp = overmap_buffer.find_camp( omt_pos.x, omt_pos.y ); + cata::optional bcp = overmap_buffer.find_camp( omt_pos.xy() ); if( bcp ) { return bcp; } g->m.add_camp( p.pos(), "faction_camp" ); - bcp = overmap_buffer.find_camp( omt_pos.x, omt_pos.y ); + bcp = overmap_buffer.find_camp( omt_pos.xy() ); if( !bcp ) { return cata::nullopt; } @@ -2569,7 +2569,7 @@ std::string talk_function::name_mission_tabs( const tripoint &omt_pos, const std if( role_id != base_camps::id ) { return cur_title; } - cata::optional temp_camp = overmap_buffer.find_camp( omt_pos.x, omt_pos.y ); + cata::optional temp_camp = overmap_buffer.find_camp( omt_pos.xy() ); if( !temp_camp ) { return cur_title; } @@ -2907,7 +2907,7 @@ tripoint om_target_tile( const tripoint &omt_pos, int min_range, int range, oter_id &omt_ref = overmap_buffer.ter( omt_tgt ); - if( must_see && !overmap_buffer.seen( omt_tgt.x, omt_tgt.y, omt_tgt.z ) ) { + if( must_see && !overmap_buffer.seen( omt_tgt ) ) { errors = true; popup( _( "You must be able to see the target that you select." ) ); } diff --git a/src/game.cpp b/src/game.cpp index c79b96bdb513d..41201948728dc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -3444,12 +3444,13 @@ void game::draw_minimap() const int omx = cursx + i; const int omy = cursy + j; nc_color ter_color; + tripoint omp( omx, omy, get_levz() ); std::string ter_sym; - const bool seen = overmap_buffer.seen( omx, omy, get_levz() ); - const bool vehicle_here = overmap_buffer.has_vehicle( omx, omy, get_levz() ); - if( overmap_buffer.has_note( omx, omy, get_levz() ) ) { + const bool seen = overmap_buffer.seen( omp ); + const bool vehicle_here = overmap_buffer.has_vehicle( omp ); + if( overmap_buffer.has_note( omp ) ) { - const std::string ¬e_text = overmap_buffer.note( omx, omy, get_levz() ); + const std::string ¬e_text = overmap_buffer.note( omp ); ter_color = c_yellow; ter_sym = "N"; @@ -3542,15 +3543,15 @@ void game::draw_minimap() ter_color = c_cyan; ter_sym = "c"; } else { - const oter_id &cur_ter = overmap_buffer.ter( omx, omy, get_levz() ); + const oter_id &cur_ter = overmap_buffer.ter( omp ); ter_sym = cur_ter->get_symbol(); - if( overmap_buffer.is_explored( omx, omy, get_levz() ) ) { + if( overmap_buffer.is_explored( omp ) ) { ter_color = c_dark_gray; } else { ter_color = cur_ter->get_color(); } } - if( !drew_mission && targ.x == omx && targ.y == omy ) { + if( !drew_mission && targ.xy() == omp.xy() ) { // If there is a mission target, and it's not on the same // overmap terrain as the player character, mark it. // TODO: Inform player if the mission is above or below @@ -3619,14 +3620,15 @@ void game::draw_minimap() } const int omx = cursx + i; const int omy = cursy + j; - if( overmap_buffer.get_horde_size( omx, omy, get_levz() ) >= HORDE_VISIBILITY_SIZE ) { + tripoint omp( omx, omy, get_levz() ); + if( overmap_buffer.get_horde_size( omp ) >= HORDE_VISIBILITY_SIZE ) { const tripoint cur_pos { omx, omy, get_levz() }; - if( overmap_buffer.seen( omx, omy, get_levz() ) + if( overmap_buffer.seen( omp ) && g->u.overmap_los( cur_pos, sight_points ) ) { mvwputch( w_minimap, j + 3, i + 3, c_green, - overmap_buffer.get_horde_size( omx, omy, get_levz() ) > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' ); + overmap_buffer.get_horde_size( omp ) > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' ); } } } @@ -10376,23 +10378,26 @@ void game::vertical_notes( int z_before, int z_after ) for( int y = -REVEAL_RADIUS; y <= REVEAL_RADIUS; y++ ) { const int cursx = gpos.x + x; const int cursy = gpos.y + y; - if( !overmap_buffer.seen( cursx, cursy, z_before ) ) { + const tripoint cursp_before( cursx, cursy, z_before ); + const tripoint cursp_after( cursx, cursy, z_after ); + + if( !overmap_buffer.seen( cursp_before ) ) { continue; } - if( overmap_buffer.has_note( cursx, cursy, z_after ) ) { + if( overmap_buffer.has_note( cursp_before ) ) { // Already has a note -> never add an AUTO-note continue; } - const oter_id &ter = overmap_buffer.ter( cursx, cursy, z_before ); - const oter_id &ter2 = overmap_buffer.ter( cursx, cursy, z_after ); + const oter_id &ter = overmap_buffer.ter( cursp_before ); + const oter_id &ter2 = overmap_buffer.ter( cursp_after ); if( z_after > z_before && ter->has_flag( known_up ) && !ter2->has_flag( known_down ) ) { - overmap_buffer.set_seen( cursx, cursy, z_after, true ); - overmap_buffer.add_note( cursx, cursy, z_after, string_format( ">:W;%s", _( "AUTO: goes down" ) ) ); + overmap_buffer.set_seen( cursp_after, true ); + overmap_buffer.add_note( cursp_after, string_format( ">:W;%s", _( "AUTO: goes down" ) ) ); } else if( z_after < z_before && ter->has_flag( known_down ) && !ter2->has_flag( known_up ) ) { - overmap_buffer.set_seen( cursx, cursy, z_after, true ); - overmap_buffer.add_note( cursx, cursy, z_after, string_format( "<:W;%s", _( "AUTO: goes up" ) ) ); + overmap_buffer.set_seen( cursp_after, true ); + overmap_buffer.add_note( cursp_after, string_format( "<:W;%s", _( "AUTO: goes up" ) ) ); } } } @@ -10487,30 +10492,30 @@ void game::update_overmap_seen() const int dist = u.overmap_sight_range( light_level( u.posz() ) ); const int dist_squared = dist * dist; // We can always see where we're standing - overmap_buffer.set_seen( ompos.x, ompos.y, ompos.z, true ); + overmap_buffer.set_seen( ompos, true ); for( int dx = -dist; dx <= dist; dx++ ) { for( int dy = -dist; dy <= dist; dy++ ) { const int h_squared = dx * dx + dy * dy; if( trigdist && h_squared > dist_squared ) { continue; } - int x = ompos.x + dx; - int y = ompos.y + dy; + const tripoint p = ompos + point( dx, dy ); // If circular distances are enabled, scale overmap distances by the diagonality of the sight line. const float multiplier = trigdist ? std::sqrt( h_squared ) / std::max( std::abs( dx ), std::abs( dy ) ) : 1; - const std::vector line = line_to( ompos.x, ompos.y, x, y, 0 ); + const std::vector line = line_to( ompos, p, 0 ); float sight_points = dist; for( auto it = line.begin(); it != line.end() && sight_points >= 0; ++it ) { - const oter_id &ter = overmap_buffer.ter( it->x, it->y, ompos.z ); + const oter_id &ter = overmap_buffer.ter( *it ); sight_points -= static_cast( ter->get_see_cost() ) * multiplier; } if( sight_points >= 0 ) { - overmap_buffer.set_seen( x, y, ompos.z, true ); - for( int z = ompos.z - 1; z >= 0; z-- ) { - overmap_buffer.set_seen( x, y, z, true ); - } + tripoint seen( p ); + do { + overmap_buffer.set_seen( seen, true ); + --seen.z; + } while( seen.z >= 0 ); } } } @@ -11639,7 +11644,7 @@ overmap &game::get_cur_om() const // The player is located in the middle submap of the map. const tripoint sm = m.get_abs_sub() + tripoint( HALF_MAPSIZE, HALF_MAPSIZE, 0 ); const tripoint pos_om = sm_to_om_copy( sm ); - return overmap_buffer.get( pos_om.x, pos_om.y ); + return overmap_buffer.get( pos_om.xy() ); } std::vector game::allies() diff --git a/src/iexamine.cpp b/src/iexamine.cpp index 1a446090f0acb..15ff22ed76245 100644 --- a/src/iexamine.cpp +++ b/src/iexamine.cpp @@ -1286,8 +1286,7 @@ void iexamine::bulletin_board( player &p, const tripoint &examp ) { g->validate_camps(); point omt = ms_to_omt_copy( g->m.getabs( examp.x, examp.y ) ); - tripoint omt_tri = tripoint( omt.x, omt.y, p.pos().z ); - cata::optional bcp = overmap_buffer.find_camp( omt_tri.x, omt_tri.y ); + cata::optional bcp = overmap_buffer.find_camp( omt ); if( bcp ) { basecamp *temp_camp = *bcp; temp_camp->validate_assignees(); diff --git a/src/map.cpp b/src/map.cpp index 7f61fdc10ab3e..7f31c4ed2611c 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -5566,7 +5566,7 @@ void map::update_visibility_cache( const int zlev ) const tripoint sm( gridx, gridy, 0 ); const auto abs_sm = map::abs_sub + sm; const auto abs_omt = sm_to_omt_copy( abs_sm ); - overmap_buffer.set_seen( abs_omt.x, abs_omt.y, abs_omt.z, true ); + overmap_buffer.set_seen( abs_omt, true ); } } } @@ -6706,9 +6706,9 @@ void map::loadn( const int gridx, const int gridy, const bool update_vehicles ) // Optimized mapgen function that only works properly for very simple overmap types // Does not create or require a temporary map and does its own saving -static void generate_uniform( const int x, const int y, const int z, const ter_id &terrain_type ) +static void generate_uniform( const tripoint &p, const ter_id &terrain_type ) { - dbg( D_INFO ) << "generate_uniform x: " << x << " y: " << y << " abs_z: " << z + dbg( D_INFO ) << "generate_uniform p: " << p << " terrain_type: " << terrain_type.id().str(); constexpr size_t block_size = SEEX * SEEY; @@ -6718,7 +6718,7 @@ static void generate_uniform( const int x, const int y, const int z, const ter_i sm->is_uniform = true; std::uninitialized_fill_n( &sm->ter[0][0], block_size, terrain_type ); sm->last_touched = calendar::turn; - MAPBUFFER.add_submap( x + xd, y + yd, z, sm ); + MAPBUFFER.add_submap( p + point(xd, yd), sm ); } } } @@ -6733,47 +6733,42 @@ void map::loadn( const int gridx, const int gridy, const int gridz, const bool u << "], worldy[" << abs_sub.y << "], gridx[" << gridx << "], gridy[" << gridy << "], gridz[" << gridz << "])"; - const int absx = abs_sub.x + gridx, - absy = abs_sub.y + gridy; + const tripoint grid_abs_sub(abs_sub.x + gridx, abs_sub.y + gridy, gridz ); const size_t gridn = get_nonant( { gridx, gridy, gridz } ); - dbg( D_INFO ) << "map::loadn absx: " << absx << " absy: " << absy - << " gridn: " << gridn; + dbg( D_INFO ) << "map::loadn grid_abs_sub: " << grid_abs_sub << " gridn: " << gridn; const int old_abs_z = abs_sub.z; // Ugly, but necessary at the moment abs_sub.z = gridz; - submap *tmpsub = MAPBUFFER.lookup_submap( absx, absy, gridz ); + submap *tmpsub = MAPBUFFER.lookup_submap( grid_abs_sub ); if( tmpsub == nullptr ) { // It doesn't exist; we must generate it! dbg( D_INFO | D_WARNING ) << "map::loadn: Missing mapbuffer data. Regenerating."; // Each overmap square is two nonants; to prevent overlap, generate only at // squares divisible by 2. - const int newmapx = absx - ( abs( absx ) % 2 ); - const int newmapy = absy - ( abs( absy ) % 2 ); - // Short-circuit if the map tile is uniform - int overx = newmapx; - int overy = newmapy; - sm_to_omt( overx, overy ); + const tripoint grid_abs_omt = sm_to_omt_copy( grid_abs_sub ); + const tripoint grid_abs_sub_rounded = omt_to_sm_copy( grid_abs_omt ); - const oter_id terrain_type = overmap_buffer.ter( overx, overy, gridz ); + const oter_id terrain_type = overmap_buffer.ter( grid_abs_omt ); + // Short-circuit if the map tile is uniform // TODO: Replace with json mapgen functions. if( terrain_type == air ) { - generate_uniform( newmapx, newmapy, gridz, t_open_air ); + generate_uniform( grid_abs_sub_rounded, t_open_air ); } else if( terrain_type == rock ) { - generate_uniform( newmapx, newmapy, gridz, t_rock ); + generate_uniform( grid_abs_sub_rounded, t_rock ); } else { tinymap tmp_map; - tmp_map.generate( newmapx, newmapy, gridz, calendar::turn ); + tmp_map.generate( grid_abs_sub_rounded, calendar::turn ); } // This is the same call to MAPBUFFER as above! - tmpsub = MAPBUFFER.lookup_submap( absx, absy, gridz ); + tmpsub = MAPBUFFER.lookup_submap( grid_abs_sub ); if( tmpsub == nullptr ) { - dbg( D_ERROR ) << "failed to generate a submap at " << absx << absy << abs_sub.z; - debugmsg( "failed to generate a submap at %d,%d,%d", absx, absy, abs_sub.z ); + dbg( D_ERROR ) << "failed to generate a submap at " << grid_abs_sub; + debugmsg( "failed to generate a submap at %s", grid_abs_sub.to_string() ); return; } } @@ -6785,7 +6780,7 @@ void map::loadn( const int gridx, const int gridy, const int gridz, const bool u set_pathfinding_cache_dirty( gridz ); setsubmap( gridn, tmpsub ); if( !tmpsub->active_items.empty() ) { - submaps_with_active_items.emplace( absx, absy, gridz ); + submaps_with_active_items.emplace( grid_abs_sub ); } if( tmpsub->field_count > 0 ) { get_cache( gridz ).field_cache.set( gridx + ( gridy * MAPSIZE ) ); @@ -7418,10 +7413,10 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight ) { // Load unloaded monsters - overmap_buffer.spawn_monster( abs_sub.x + gp.x, abs_sub.y + gp.y, gp.z ); + overmap_buffer.spawn_monster( gp + abs_sub.xy() ); // Only spawn new monsters after existing monsters are loaded. - auto groups = overmap_buffer.groups_at( abs_sub.x + gp.x, abs_sub.y + gp.y, gp.z ); + auto groups = overmap_buffer.groups_at( gp + abs_sub.xy() ); for( auto &mgp : groups ) { spawn_monsters_submap_group( gp, *mgp, ignore_sight ); } @@ -7546,18 +7541,19 @@ bool tinymap::fake_load( const furn_id &fur_type, const ter_id &ter_type, const set_abs_sub( 0, 0, 0 ); for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) { for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { - submap *tmpsub = MAPBUFFER.lookup_submap( gridx, gridy, 0 ); + const tripoint gridp( gridx, gridy, 0 ); + submap *tmpsub = MAPBUFFER.lookup_submap( gridp ); if( tmpsub == nullptr ) { - generate_uniform( gridx, gridy, 0, ter_type ); + generate_uniform( gridp, ter_type ); do_terset = false; - tmpsub = MAPBUFFER.lookup_submap( gridx, gridy, 0 ); + tmpsub = MAPBUFFER.lookup_submap( gridp ); if( tmpsub == nullptr ) { dbg( D_ERROR ) << "failed to generate a fake submap at 0, 0, 0 "; debugmsg( "failed to generate a fake submap at 0,0,0" ); return false; } } - const size_t gridn = get_nonant( { gridx, gridy, 0 } ); + const size_t gridn = get_nonant( gridp ); setsubmap( gridn, tmpsub ); } diff --git a/src/map.h b/src/map.h index 1033c72f6ea20..328c7356b3ae3 100644 --- a/src/map.h +++ b/src/map.h @@ -348,6 +348,9 @@ class map * @param update_vehicles If true, add vehicles to the vehicle cache. */ void load( const int wx, const int wy, const int wz, const bool update_vehicles ); + void load( const tripoint &p, const bool update_vehicles ) { + load( p.x, p.y, p.z, update_vehicles ); + } /** * Shift the map along the vector (sx,sy). * This is like loading the map with coordinates derived from the current @@ -1222,6 +1225,9 @@ class map // mapgen.cpp functions void generate( const int x, const int y, const int z, const time_point &when ); + void generate( const tripoint &p, const time_point &when ) { + generate( p.x, p.y, p.z, when ); + } void place_spawns( const mongroup_id &group, const int chance, const int x1, const int y1, const int x2, const int y2, const float intensity, const bool individual = false, const bool friendly = false ); diff --git a/src/map_extras.cpp b/src/map_extras.cpp index 5162a27e925e4..0a01afe44a442 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -420,10 +420,11 @@ static void mx_collegekids( map &m, const tripoint & ) static void mx_roadblock( map &m, const tripoint &abs_sub ) { - std::string north = overmap_buffer.ter( abs_sub.x / 2, abs_sub.y / 2 - 1, abs_sub.z ).id().c_str(); - std::string south = overmap_buffer.ter( abs_sub.x / 2, abs_sub.y / 2 + 1, abs_sub.z ).id().c_str(); - std::string west = overmap_buffer.ter( abs_sub.x / 2 - 1, abs_sub.y / 2, abs_sub.z ).id().c_str(); - std::string east = overmap_buffer.ter( abs_sub.x / 2 + 1, abs_sub.y / 2, abs_sub.z ).id().c_str(); + const tripoint abs_omt = sm_to_omt_copy( abs_sub ); + std::string north = overmap_buffer.ter( abs_omt + point( 0, -1 ) ).id().str(); + std::string south = overmap_buffer.ter( abs_omt + point( 0, 1 ) ).id().str(); + std::string west = overmap_buffer.ter( abs_omt + point( -1, 0 ) ).id().str(); + std::string east = overmap_buffer.ter( abs_omt + point( 1, 0 ) ).id().str(); bool northroad = false; bool eastroad = false; @@ -590,10 +591,11 @@ static void mx_marloss_pilgrimage( map &m, const tripoint &abs_sub ) static void mx_bandits_block( map &m, const tripoint &abs_sub ) { - const oter_id &north = overmap_buffer.ter( abs_sub.x, abs_sub.y - 1, abs_sub.z ); - const oter_id &south = overmap_buffer.ter( abs_sub.x, abs_sub.y + 1, abs_sub.z ); - const oter_id &west = overmap_buffer.ter( abs_sub.x - 1, abs_sub.y, abs_sub.z ); - const oter_id &east = overmap_buffer.ter( abs_sub.x + 1, abs_sub.y, abs_sub.z ); + const tripoint abs_omt = sm_to_omt_copy( abs_sub ); + const oter_id &north = overmap_buffer.ter( abs_omt + point( 0, -1 ) ); + const oter_id &south = overmap_buffer.ter( abs_omt + point( 0, 1 ) ); + const oter_id &west = overmap_buffer.ter( abs_omt + point( -1, 0 ) ); + const oter_id &east = overmap_buffer.ter( abs_omt + point( 1, 0 ) ); const bool forest_at_north = is_ot_match( "forest", north, ot_match_type::prefix ); const bool forest_at_south = is_ot_match( "forest", south, ot_match_type::prefix ); @@ -819,11 +821,12 @@ static void mx_portal( map &m, const tripoint &abs_sub ) static void mx_minefield( map &m, const tripoint &abs_sub ) { - const oter_id ¢er = overmap_buffer.ter( abs_sub.x, abs_sub.y, abs_sub.z ); - const oter_id &north = overmap_buffer.ter( abs_sub.x, abs_sub.y - 1, abs_sub.z ); - const oter_id &south = overmap_buffer.ter( abs_sub.x, abs_sub.y + 1, abs_sub.z ); - const oter_id &west = overmap_buffer.ter( abs_sub.x - 1, abs_sub.y, abs_sub.z ); - const oter_id &east = overmap_buffer.ter( abs_sub.x + 1, abs_sub.y, abs_sub.z ); + const tripoint abs_omt = sm_to_omt_copy( abs_sub ); + const oter_id ¢er = overmap_buffer.ter( abs_omt ); + const oter_id &north = overmap_buffer.ter( abs_omt + point( 0, -1 ) ); + const oter_id &south = overmap_buffer.ter( abs_omt + point( 0, 1 ) ); + const oter_id &west = overmap_buffer.ter( abs_omt + point( -1, 0 ) ); + const oter_id &east = overmap_buffer.ter( abs_omt + point( 1, 0 ) ); const bool bridge_at_center = is_ot_match( "bridge", center, ot_match_type::type ); const bool bridge_at_north = is_ot_match( "bridge", north, ot_match_type::type ); @@ -1909,10 +1912,11 @@ static void mx_roadworks( map &m, const tripoint &abs_sub ) // equipment in a box // (curved roads & intersections excluded, perhaps TODO) - const oter_id &north = overmap_buffer.ter( abs_sub.x, abs_sub.y - 1, abs_sub.z ); - const oter_id &south = overmap_buffer.ter( abs_sub.x, abs_sub.y + 1, abs_sub.z ); - const oter_id &west = overmap_buffer.ter( abs_sub.x - 1, abs_sub.y, abs_sub.z ); - const oter_id &east = overmap_buffer.ter( abs_sub.x + 1, abs_sub.y, abs_sub.z ); + const tripoint abs_omt = sm_to_omt_copy( abs_sub ); + const oter_id &north = overmap_buffer.ter( abs_omt + point( 0, -1 ) ); + const oter_id &south = overmap_buffer.ter( abs_omt + point( 0, 1 ) ); + const oter_id &west = overmap_buffer.ter( abs_omt + point( -1, 0 ) ); + const oter_id &east = overmap_buffer.ter( abs_omt + point( 1, 0 ) ); const bool road_at_north = is_ot_match( "road", north, ot_match_type::type ); const bool road_at_south = is_ot_match( "road", south, ot_match_type::type ); diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 4a59dfabce429..2e2941473d43c 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -120,28 +120,26 @@ void map::generate( const int x, const int y, const int z, const time_point &whe } } // x, and y are submap coordinates, convert to overmap terrain coordinates - int overx = x; - int overy = y; - sm_to_omt( overx, overy ); - const regional_settings *rsettings = &overmap_buffer.get_settings( overx, overy, z ); - oter_id terrain_type = overmap_buffer.ter( overx, overy, z ); - oter_id t_above = overmap_buffer.ter( overx, overy, z + 1 ); - oter_id t_below = overmap_buffer.ter( overx, overy, z - 1 ); - oter_id t_north = overmap_buffer.ter( overx, overy - 1, z ); - oter_id t_neast = overmap_buffer.ter( overx + 1, overy - 1, z ); - oter_id t_east = overmap_buffer.ter( overx + 1, overy, z ); - oter_id t_seast = overmap_buffer.ter( overx + 1, overy + 1, z ); - oter_id t_south = overmap_buffer.ter( overx, overy + 1, z ); - oter_id t_swest = overmap_buffer.ter( overx - 1, overy + 1, z ); - oter_id t_west = overmap_buffer.ter( overx - 1, overy, z ); - oter_id t_nwest = overmap_buffer.ter( overx - 1, overy - 1, z ); + tripoint abs_omt = sm_to_omt_copy( tripoint( x, y, z ) ); + const regional_settings *rsettings = &overmap_buffer.get_settings( abs_omt ); + oter_id terrain_type = overmap_buffer.ter( abs_omt ); + oter_id t_above = overmap_buffer.ter( abs_omt + tripoint( 0, 0, 1 ) ); + oter_id t_below = overmap_buffer.ter( abs_omt + tripoint( 0, 0, -1 ) ); + oter_id t_north = overmap_buffer.ter( abs_omt + tripoint( 0, -1, 0 ) ); + oter_id t_neast = overmap_buffer.ter( abs_omt + tripoint( 1, -1, 0 ) ); + oter_id t_east = overmap_buffer.ter( abs_omt + tripoint( 1, 0, 0 ) ); + oter_id t_seast = overmap_buffer.ter( abs_omt + tripoint( 1, 1, 0 ) ); + oter_id t_south = overmap_buffer.ter( abs_omt + tripoint( 0, 1, 0 ) ); + oter_id t_swest = overmap_buffer.ter( abs_omt + tripoint( -1, 1, 0 ) ); + oter_id t_west = overmap_buffer.ter( abs_omt + tripoint( -1, 0, 0 ) ); + oter_id t_nwest = overmap_buffer.ter( abs_omt + tripoint( -1, -1, 0 ) ); // This attempts to scale density of zombies inversely with distance from the nearest city. // In other words, make city centers dense and perimeters sparse. float density = 0.0; - for( int i = overx - MON_RADIUS; i <= overx + MON_RADIUS; i++ ) { - for( int j = overy - MON_RADIUS; j <= overy + MON_RADIUS; j++ ) { - density += overmap_buffer.ter( i, j, z )->get_mondensity(); + for( int i = -MON_RADIUS; i <= MON_RADIUS; i++ ) { + for( int j = -MON_RADIUS; j <= MON_RADIUS; j++ ) { + density += overmap_buffer.ter( abs_omt + point( i, j ) )->get_mondensity(); } } density = density / 100; @@ -6844,8 +6842,8 @@ void map::place_spawns( const mongroup_id &group, const int chance, const bool individual, const bool friendly ) { if( !group.is_valid() ) { - const point omt = sm_to_omt_copy( get_abs_sub().x, get_abs_sub().y ); - const oter_id &oid = overmap_buffer.ter( omt.x, omt.y, get_abs_sub().z ); + const tripoint omt = sm_to_omt_copy( get_abs_sub() ); + const oter_id &oid = overmap_buffer.ter( omt ); debugmsg( "place_spawns: invalid mongroup '%s', om_terrain = '%s' (%s)", group.c_str(), oid.id().c_str(), oid->get_mapgen_id().c_str() ); return; @@ -6986,8 +6984,8 @@ std::vector map::place_items( const items_location &loc, int chance, int return res; } if( !item_group::group_is_defined( loc ) ) { - const point omt = sm_to_omt_copy( get_abs_sub().x, get_abs_sub().y ); - const oter_id &oid = overmap_buffer.ter( omt.x, omt.y, get_abs_sub().z ); + const tripoint omt = sm_to_omt_copy( get_abs_sub() ); + const oter_id &oid = overmap_buffer.ter( omt ); debugmsg( "place_items: invalid item group '%s', om_terrain = '%s' (%s)", loc.c_str(), oid.id().c_str(), oid->get_mapgen_id().c_str() ); return res; @@ -7280,8 +7278,7 @@ void map::rotate( int turns ) // TODO: This radius can be smaller - how small? const int radius = HALF_MAPSIZE + 3; // uses submap coordinates - const std::vector> npcs = overmap_buffer.get_npcs_near( abs_sub.x, abs_sub.y, - abs_sub.z, radius ); + const std::vector> npcs = overmap_buffer.get_npcs_near( abs_sub, radius ); for( const std::shared_ptr &i : npcs ) { npc &np = *i; const tripoint sq = np.global_square_location(); @@ -8357,9 +8354,9 @@ bool update_mapgen_function_json::update_map( const tripoint &omt_pos, int offse mission *miss, bool verify ) const { tinymap update_tmap; - const regional_settings &rsettings = overmap_buffer.get_settings( omt_pos.x, omt_pos.y, - omt_pos.z ); - update_tmap.load( omt_pos.x * 2, omt_pos.y * 2, omt_pos.z, false ); + const regional_settings &rsettings = overmap_buffer.get_settings( omt_pos ); + const tripoint sm_pos = omt_to_sm_copy( omt_pos ); + update_tmap.load( sm_pos, false ); const std::string map_id = overmap_buffer.ter( omt_pos ).id().c_str(); oter_id north = overmap_buffer.ter( omt_pos + tripoint( 0, -1, 0 ) ); oter_id south = overmap_buffer.ter( omt_pos + tripoint( 0, 1, 0 ) ); diff --git a/src/mission_companion.cpp b/src/mission_companion.cpp index dc78ffe468d74..f93447fd4edc4 100644 --- a/src/mission_companion.cpp +++ b/src/mission_companion.cpp @@ -1482,7 +1482,7 @@ bool talk_function::companion_om_combat_check( const std::vector &group for( int y = 0; y < 2; y++ ) { point sm( ( om_tgt.x * 2 ) + x, ( om_tgt.x * 2 ) + y ); const point omp = sm_to_om_remain( sm ); - overmap &omi = overmap_buffer.get( omp.x, omp.y ); + overmap &omi = overmap_buffer.get( omp ); const tripoint current_submap_loc( om_tgt.x * 2 + x, om_tgt.y * 2 + y, om_tgt.z ); auto monster_bucket = omi.monster_map.equal_range( current_submap_loc ); @@ -1881,8 +1881,7 @@ std::vector talk_function::companion_rank( const std::vector npc_ptr talk_function::companion_choose( const std::string &skill_tested, int skill_level ) { std::vector available; - cata::optional bcp = overmap_buffer.find_camp( g->u.global_omt_location().x, - g->u.global_omt_location().y ); + cata::optional bcp = overmap_buffer.find_camp( g->u.global_omt_location().xy() ); for( auto &elem : g->get_follower_list() ) { npc_ptr guy = overmap_buffer.find_npc( elem ); @@ -1905,8 +1904,7 @@ npc_ptr talk_function::companion_choose( const std::string &skill_tested, int sk } } else { const tripoint &guy_omt_pos = guy->global_omt_location(); - cata::optional guy_camp = overmap_buffer.find_camp( guy_omt_pos.x, - guy_omt_pos.y ); + cata::optional guy_camp = overmap_buffer.find_camp( guy_omt_pos.xy() ); if( guy_camp ) { // get NPCs assigned to guard a remote base basecamp *temp_camp = *guy_camp; @@ -2090,7 +2088,7 @@ void talk_function::loot_building( const tripoint &site ) } } bay.save(); - overmap_buffer.ter( site.x, site.y, site.z ) = oter_id( "looted_building" ); + overmap_buffer.ter( site ) = oter_id( "looted_building" ); } void mission_data::add( const std::string &id, const std::string &name_display, diff --git a/src/mission_start.cpp b/src/mission_start.cpp index 38c3e7c96dc02..50b1b69c1bd8e 100644 --- a/src/mission_start.cpp +++ b/src/mission_start.cpp @@ -204,7 +204,7 @@ void mission_start::place_npc_software( mission *miss ) compmap.load( place.x * 2, place.y * 2, place.z, false ); tripoint comppoint; - oter_id oter = overmap_buffer.ter( place.x, place.y, place.z ); + oter_id oter = overmap_buffer.ter( place ); if( is_ot_match( "house", oter, ot_match_type::prefix ) || is_ot_match( "s_pharm", oter, ot_match_type::type ) || oter == "" ) { comppoint = find_potential_computer_point( compmap, place.z ); diff --git a/src/mission_util.cpp b/src/mission_util.cpp index e685b7a2c987a..9b905b76e3d77 100644 --- a/src/mission_util.cpp +++ b/src/mission_util.cpp @@ -120,8 +120,9 @@ static tripoint random_house_in_city( const city_reference &cref ) int endy = city_center_omt.y + size; for( int x = startx; x <= endx; x++ ) { for( int y = starty; y <= endy; y++ ) { - if( overmap_buffer.check_ot( "house", ot_match_type::type, x, y, z ) ) { - valid.push_back( tripoint( x, y, z ) ); + tripoint p( x, y, z ); + if( overmap_buffer.check_ot( "house", ot_match_type::type, p ) ) { + valid.push_back( p ); } } } diff --git a/src/monster.cpp b/src/monster.cpp index 47625d6972acd..412d2f5fb20fc 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -2075,13 +2075,13 @@ void monster::die( Creature *nkiller ) if( !is_hallucination() && has_flag( MF_QUEEN ) ) { // The submap coordinates of this monster, monster groups coordinates are // submap coordinates. - const point abssub = ms_to_sm_copy( g->m.getabs( posx(), posy() ) ); + const tripoint abssub = ms_to_sm_copy( g->m.getabs( pos() ) ); // Do it for overmap above/below too for( int z = 1; z >= -1; --z ) { for( int x = -HALF_MAPSIZE; x <= HALF_MAPSIZE; x++ ) { for( int y = -HALF_MAPSIZE; y <= HALF_MAPSIZE; y++ ) { - std::vector groups = overmap_buffer.groups_at( abssub.x + x, abssub.y + y, - g->get_levz() + z ); + tripoint offset( x, y, z ); + std::vector groups = overmap_buffer.groups_at( abssub + offset ); for( auto &mgp : groups ) { if( MonsterGroupManager::IsMonsterInGroup( mgp->type, type->id ) ) { mgp->dying = true; diff --git a/src/npc.cpp b/src/npc.cpp index 5b3ee255e5caa..4c77f7938557c 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -643,8 +643,8 @@ void npc::setpos( const tripoint &pos ) submap_coords.y = g->get_levy() + pos.y / SEEY; const point pos_om_new = sm_to_om_copy( submap_coords ); if( !is_fake() && pos_om_old != pos_om_new ) { - overmap &om_old = overmap_buffer.get( pos_om_old.x, pos_om_old.y ); - overmap &om_new = overmap_buffer.get( pos_om_new.x, pos_om_new.y ); + overmap &om_old = overmap_buffer.get( pos_om_old ); + overmap &om_new = overmap_buffer.get( pos_om_new ); if( const auto ptr = om_old.erase_npc( getID() ) ) { om_new.insert_npc( ptr ); } else { @@ -664,8 +664,8 @@ void npc::travel_overmap( const tripoint &pos ) reach_omt_destination(); } if( !is_fake() && pos_om_old != pos_om_new ) { - overmap &om_old = overmap_buffer.get( pos_om_old.x, pos_om_old.y ); - overmap &om_new = overmap_buffer.get( pos_om_new.x, pos_om_new.y ); + overmap &om_old = overmap_buffer.get( pos_om_old ); + overmap &om_new = overmap_buffer.get( pos_om_new ); if( const auto ptr = om_old.erase_npc( getID() ) ) { om_new.insert_npc( ptr ); } else { @@ -1655,8 +1655,7 @@ bool npc::is_leader() const bool npc::is_assigned_to_camp() const { - cata::optional bcp = overmap_buffer.find_camp( global_omt_location().x, - global_omt_location().y ); + cata::optional bcp = overmap_buffer.find_camp( global_omt_location().xy() ); if( !bcp ) { return false; } diff --git a/src/npctalk.cpp b/src/npctalk.cpp index a559b297258c9..27e96b4ca2328 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -2802,7 +2802,7 @@ void conditional_t::set_at_om_location( JsonObject &jo, const std::string &membe oter_id &omt_ref = overmap_buffer.ter( omt_pos ); if( location == "FACTION_CAMP_ANY" ) { - cata::optional bcp = overmap_buffer.find_camp( omt_pos.x, omt_pos.y ); + cata::optional bcp = overmap_buffer.find_camp( omt_pos.xy() ); if( bcp ) { return true; } diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index 4d4ceb09fcee0..2f44032527be8 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -229,7 +229,7 @@ void talk_function::goto_location( npc &p ) if( elem == p.global_omt_location() ) { continue; } - cata::optional camp = overmap_buffer.find_camp( elem.x, elem.y ); + cata::optional camp = overmap_buffer.find_camp( elem.xy() ); if( !camp ) { continue; } @@ -282,8 +282,7 @@ void talk_function::assign_guard( npc &p ) p.set_mission( NPC_MISSION_GUARD_ALLY ); p.chatbin.first_topic = "TALK_FRIEND_GUARD"; p.set_omt_destination(); - cata::optional bcp = overmap_buffer.find_camp( p.global_omt_location().x, - p.global_omt_location().y ); + cata::optional bcp = overmap_buffer.find_camp( p.global_omt_location().xy() ); if( bcp ) { basecamp *temp_camp = *bcp; temp_camp->validate_assignees(); @@ -319,8 +318,7 @@ void talk_function::stop_guard( npc &p ) p.chatbin.first_topic = "TALK_FRIEND"; p.goal = npc::no_goal_point; p.guard_pos = npc::no_goal_point; - cata::optional bcp = overmap_buffer.find_camp( p.global_omt_location().x, - p.global_omt_location().y ); + cata::optional bcp = overmap_buffer.find_camp( p.global_omt_location().xy() ); if( bcp ) { basecamp *temp_camp = *bcp; temp_camp->validate_assignees(); diff --git a/src/overmap.cpp b/src/overmap.cpp index 7f6d03856d501..77e25f2ee242b 100644 --- a/src/overmap.cpp +++ b/src/overmap.cpp @@ -1186,6 +1186,14 @@ bool &overmap::seen( int x, int y, int z ) return layer[z + OVERMAP_DEPTH].visible[x][y]; } +bool overmap::seen( int x, int y, int z ) const +{ + if( !inbounds( tripoint( x, y, z ) ) ) { + return false; + } + return layer[z + OVERMAP_DEPTH].visible[x][y]; +} + bool &overmap::explored( int x, int y, int z ) { if( !inbounds( tripoint( x, y, z ) ) ) { @@ -4086,7 +4094,7 @@ void overmap::place_specials( overmap_special_batch &enabled_specials ) // Since this starts at enabled_specials::origin, it will only place new overmaps // in the 5x5 area surrounding the initial overmap, bounding the amount of work we will do. for( point candidate_addr : closest_points_first( 2, custom_overmap_specials.get_origin() ) ) { - if( !overmap_buffer.has( candidate_addr.x, candidate_addr.y ) ) { + if( !overmap_buffer.has( candidate_addr ) ) { int current_distance = square_dist( pos().x, pos().y, candidate_addr.x, candidate_addr.y ); if( nearest_candidates.empty() || current_distance == previous_distance ) { @@ -4100,7 +4108,7 @@ void overmap::place_specials( overmap_special_batch &enabled_specials ) if( !nearest_candidates.empty() ) { std::shuffle( nearest_candidates.begin(), nearest_candidates.end(), rng_get_engine() ); point new_om_addr = nearest_candidates.front(); - overmap_buffer.create_custom_overmap( new_om_addr.x, new_om_addr.y, custom_overmap_specials ); + overmap_buffer.create_custom_overmap( new_om_addr, custom_overmap_specials ); } else { add_msg( _( "Unable to place all configured specials, some missions may fail to initialize." ) ); } @@ -4258,21 +4266,21 @@ void overmap::place_radios() void overmap::open( overmap_special_batch &enabled_specials ) { - const std::string terfilename = overmapbuffer::terrain_filename( loc.x, loc.y ); + const std::string terfilename = overmapbuffer::terrain_filename( loc ); using namespace std::placeholders; if( read_from_file_optional( terfilename, std::bind( &overmap::unserialize, this, _1 ) ) ) { - const std::string plrfilename = overmapbuffer::player_filename( loc.x, loc.y ); + const std::string plrfilename = overmapbuffer::player_filename( loc ); read_from_file_optional( plrfilename, std::bind( &overmap::unserialize_view, this, _1 ) ); } else { // No map exists! Prepare neighbors, and generate one. std::vector pointers; // Fetch south and north for( int i = -1; i <= 1; i += 2 ) { - pointers.push_back( overmap_buffer.get_existing( loc.x, loc.y + i ) ); + pointers.push_back( overmap_buffer.get_existing( loc + point( 0, i ) ) ); } // Fetch east and west for( int i = -1; i <= 1; i += 2 ) { - pointers.push_back( overmap_buffer.get_existing( loc.x + i, loc.y ) ); + pointers.push_back( overmap_buffer.get_existing( loc + point( i, 0 ) ) ); } // pointers looks like (north, south, west, east) @@ -4283,8 +4291,8 @@ void overmap::open( overmap_special_batch &enabled_specials ) // Note: this may throw io errors from std::ofstream void overmap::save() const { - const std::string plrfilename = overmapbuffer::player_filename( loc.x, loc.y ); - const std::string terfilename = overmapbuffer::terrain_filename( loc.x, loc.y ); + const std::string plrfilename = overmapbuffer::player_filename( loc ); + const std::string terfilename = overmapbuffer::terrain_filename( loc ); ofstream_wrapper fout_player( plrfilename ); serialize_view( fout_player ); diff --git a/src/overmap.h b/src/overmap.h index db9c16defd4a5..01c72dbe9bdcf 100644 --- a/src/overmap.h +++ b/src/overmap.h @@ -70,8 +70,7 @@ struct om_map_extra { }; struct om_vehicle { - int x; // overmap x coordinate of tracked vehicle - int y; // overmap y coordinate + point p; // overmap coordinates of tracked vehicle std::string name; }; @@ -163,6 +162,7 @@ class overmap overmap( const overmap & ) = default; overmap( overmap && ) = default; overmap( int x, int y ); + overmap( const point &p ) : overmap( p.x, p.y ) {} ~overmap(); overmap &operator=( const overmap & ) = default; @@ -197,19 +197,56 @@ class overmap oter_id &ter( const tripoint &p ); const oter_id get_ter( const int x, const int y, const int z ) const; const oter_id get_ter( const tripoint &p ) const; - bool &seen( int x, int y, int z ); - bool &explored( int x, int y, int z ); + bool &seen( int x, int y, int z ); + bool &seen( const tripoint &p ) { + return seen( p.x, p.y, p.z ); + } + bool seen( int x, int y, int z ) const; + bool seen( const tripoint &p ) const { + return seen( p.x, p.y, p.z ); + } + bool &explored( int x, int y, int z ); + bool &explored( const tripoint &p ) { + return explored( p.x, p.y, p.z ); + } bool is_explored( const int x, const int y, const int z ) const; + bool is_explored( const tripoint &p ) const { + return is_explored( p.x, p.y, p.z ); + } bool has_note( int x, int y, int z ) const; + bool has_note( const tripoint &p ) const { + return has_note( p.x, p.y, p.z ); + } const std::string ¬e( int x, int y, int z ) const; + const std::string ¬e( const tripoint &p ) const { + return note( p.x, p.y, p.z ); + } void add_note( int x, int y, int z, std::string message ); + void add_note( const tripoint &p, std::string message ) { + add_note( p.x, p.y, p.z, message ); + } void delete_note( int x, int y, int z ); + void delete_note( const tripoint &p ) { + delete_note( p.x, p.y, p.z ); + } bool has_extra( int x, int y, int z ) const; + bool has_extra( const tripoint &p ) const { + return has_extra( p.x, p.y, p.z ); + } const string_id &extra( int x, int y, int z ) const; + const string_id &extra( const tripoint &p ) const { + return extra( p.x, p.y, p.z ); + } void add_extra( int x, int y, int z, const string_id &id ); + void add_extra( const tripoint &p, const string_id &id ) { + add_extra( p.x, p.y, p.z, id ); + } void delete_extra( int x, int y, int z ); + void delete_extra( const tripoint &p ) { + delete_extra( p.x, p.y, p.z ); + } /** * Getter for overmap scents. @@ -278,6 +315,9 @@ class overmap std::vector cities; std::vector roads_out; cata::optional find_camp( const int x, const int y ); + cata::optional find_camp( const point &p ) { + return find_camp( p.x, p.y ); + } /// Adds the npc to the contained list of npcs ( @ref npcs ). void insert_npc( std::shared_ptr who ); /// Removes the npc and returns it ( or returns nullptr if not found ). @@ -398,6 +438,9 @@ class overmap const overmap_connection &connection ); // Polishing bool check_ot( const std::string &otype, ot_match_type match_type, int x, int y, int z ) const; + bool check_ot( const std::string &otype, ot_match_type match_type, const tripoint &p ) const { + return check_ot( otype, match_type, p.x, p.y, p.z ); + } bool check_overmap_special_type( const overmap_special_id &id, const tripoint &location ) const; void chip_rock( int x, int y, int z ); diff --git a/src/overmap_ui.cpp b/src/overmap_ui.cpp index a6569c26353d9..8701facd1fba3 100644 --- a/src/overmap_ui.cpp +++ b/src/overmap_ui.cpp @@ -124,7 +124,7 @@ static std::array, npm_width *npm_height> get_o for( const tripoint &dest : tripoint_range( current - shift, current + shift ) ) { nc_color ter_color = c_black; std::string ter_sym = " "; - const bool see = has_debug_vision || overmap_buffer.seen( dest.x, dest.y, dest.z ); + const bool see = has_debug_vision || overmap_buffer.seen( dest ); if( see ) { // Only load terrain if we can actually see it oter_id cur_ter = overmap_buffer.ter( dest ); @@ -192,8 +192,8 @@ static weather_type get_weather_at_point( const tripoint &pos ) } auto iter = weather_cache.find( pos ); if( iter == weather_cache.end() ) { - const auto abs_ms_pos = tripoint( pos.x * SEEX * 2, pos.y * SEEY * 2, pos.z ); - const auto &wgen = overmap_buffer.get_settings( pos.x, pos.y, pos.z ).weather; + const tripoint abs_ms_pos = sm_to_ms_copy( omt_to_sm_copy( pos ) ); + const auto &wgen = overmap_buffer.get_settings( pos ).weather; const auto weather = wgen.get_weather_conditions( abs_ms_pos, calendar::turn, g->get_seed() ); iter = weather_cache.insert( std::make_pair( pos, weather ) ).first; } @@ -256,7 +256,7 @@ static void draw_city_labels( const catacurses::window &w, const tripoint ¢e continue; // right under the cursor. } - if( !overmap_buffer.seen( city_pos.x, city_pos.y, center.z ) ) { + if( !overmap_buffer.seen( tripoint( city_pos, center.z ) ) ) { continue; // haven't seen it. } @@ -294,7 +294,7 @@ static void draw_camp_labels( const catacurses::window &w, const tripoint ¢e continue; // right under the cursor. } - if( !overmap_buffer.seen( camp_pos.x, camp_pos.y, center.z ) ) { + if( !overmap_buffer.seen( tripoint( camp_pos, center.z ) ) ) { continue; // haven't seen it. } @@ -396,7 +396,8 @@ static point draw_notes( const tripoint &origin ) const int distance_player = rl_dist( p_player, p_omt ); const point sm_pos = omt_to_sm_copy( p_omt ); const point p_om = omt_to_om_remain( p_omt ); - const std::string location_desc = overmap_buffer.get_description_at( sm_pos, origin.z ); + const std::string location_desc = + overmap_buffer.get_description_at( tripoint( sm_pos, origin.z ) ); nmenu.addentry_desc( string_format( _( "[%s] %s" ), colorize( note_symbol, note_color ), note_text ), string_format( @@ -423,14 +424,11 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr const tripoint &orig, bool blink, bool show_explored, bool fast_scroll, input_context *inp_ctxt, const draw_data_t &data ) { - const int z = center.z; - const int cursx = center.x; - const int cursy = center.y; const int om_map_width = OVERMAP_WINDOW_WIDTH; const int om_map_height = OVERMAP_WINDOW_HEIGHT; const int om_half_width = om_map_width / 2; const int om_half_height = om_map_height / 2; - const bool viewing_weather = ( ( data.debug_weather || data.visible_weather ) && z == 10 ); + const bool viewing_weather = ( ( data.debug_weather || data.visible_weather ) && center.z == 10 ); // Target of current mission const tripoint target = g->u.get_active_mission_target(); @@ -463,7 +461,7 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr const mongroup *mgroup = nullptr; std::vector mgroups; if( data.debug_mongroup ) { - mgroups = overmap_buffer.monsters_at( center.x, center.y, center.z ); + mgroups = overmap_buffer.monsters_at( center ); for( const auto &mgp : mgroups ) { mgroup = mgp; if( mgp->horde ) { @@ -478,9 +476,8 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr std::array, cache_size> cache {{}}; size_t cache_next = 0; - const auto set_color_and_symbol = [&]( const oter_id & cur_ter, const int omx, const int omy, - const int z, std::string & ter_sym, - nc_color & ter_color ) { + const auto set_color_and_symbol = [&]( const oter_id & cur_ter, const tripoint omp, + std::string & ter_sym, nc_color & ter_color ) { // First see if we have the oter_t cached oter_t const *info = nullptr; for( const auto &c : cache ) { @@ -497,14 +494,13 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr } // Ok, we found something if( info ) { - const bool explored = show_explored && overmap_buffer.is_explored( omx, omy, z ); + const bool explored = show_explored && overmap_buffer.is_explored( omp ); ter_color = explored ? c_dark_gray : info->get_color( uistate.overmap_show_land_use_codes ); ter_sym = info->get_symbol( uistate.overmap_show_land_use_codes ); } }; - const int offset_x = cursx - om_half_width; - const int offset_y = cursy - om_half_height; + const tripoint corner = center - point( om_half_width, om_half_height ); // For use with place_special: cache the color and symbol of each submap // and record the bounds to optimize lookups below @@ -540,12 +536,12 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr if( blink ) { const auto &npcs = overmap_buffer.get_npcs_near_player( sight_points ); for( const auto &np : npcs ) { - if( np->posz() != z ) { + if( np->posz() != center.z ) { continue; } const tripoint pos = np->global_omt_location(); - if( has_debug_vision || overmap_buffer.seen( pos.x, pos.y, pos.z ) ) { + if( has_debug_vision || overmap_buffer.seen( pos ) ) { auto iter = npc_color.find( pos ); nc_color np_color = np->basic_symbol_color(); if( iter == npc_color.end() ) { @@ -582,7 +578,7 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr player_path_route.push_back( tri_to_add ); } for( const auto &np : followers ) { - if( np->posz() != z ) { + if( np->posz() != center.z ) { continue; } if( !np->omt_path.empty() ) { @@ -608,60 +604,58 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr for( int i = 0; i < om_map_width; ++i ) { for( int j = 0; j < om_map_height; ++j ) { - const int omx = i + offset_x; - const int omy = j + offset_y; + const tripoint omp = corner + point( i, j ); oter_id cur_ter = oter_str_id::NULL_ID(); nc_color ter_color = c_black; std::string ter_sym = " "; - const bool see = has_debug_vision || overmap_buffer.seen( omx, omy, z ); + const bool see = has_debug_vision || overmap_buffer.seen( omp ); if( see ) { // Only load terrain if we can actually see it - cur_ter = overmap_buffer.ter( omx, omy, z ); + cur_ter = overmap_buffer.ter( omp ); } - const tripoint cur_pos {omx, omy, z}; // Check if location is within player line-of-sight - const bool los = see && g->u.overmap_los( cur_pos, sight_points ); - const bool los_sky = g->u.overmap_los( cur_pos, sight_points * 2 ); - int mycount = std::count( path_route.begin(), path_route.end(), cur_pos ); + const bool los = see && g->u.overmap_los( omp, sight_points ); + const bool los_sky = g->u.overmap_los( omp, sight_points * 2 ); + int mycount = std::count( path_route.begin(), path_route.end(), omp ); bool player_path_count = false; std::vector::iterator it; - it = std::find( player_path_route.begin(), player_path_route.end(), cur_pos ); + it = std::find( player_path_route.begin(), player_path_route.end(), omp ); if( it != player_path_route.end() ) { player_path_count = true; } - if( blink && cur_pos == orig ) { + if( blink && omp == orig ) { // Display player pos, should always be visible ter_color = g->u.symbol_color(); ter_sym = "@"; } else if( viewing_weather && ( data.debug_weather || los_sky ) ) { - const weather_type type = get_weather_at_point( tripoint( omx, omy, z ) ); + const weather_type type = get_weather_at_point( omp ); ter_color = weather::map_color( type ); ter_sym = weather::glyph( type ); - } else if( data.debug_scent && get_scent_glyph( cur_pos, ter_color, ter_sym ) ) { - } else if( blink && has_target && omx == target.x && omy == target.y ) { + } else if( data.debug_scent && get_scent_glyph( omp, ter_color, ter_sym ) ) { + } else if( blink && has_target && omp.xy() == target.xy() ) { // Mission target, display always, player should know where it is anyway. ter_color = c_red; ter_sym = "*"; - if( target.z > z ) { + if( target.z > center.z ) { ter_sym = "^"; - } else if( target.z < z ) { + } else if( target.z < center.z ) { ter_sym = "v"; } - } else if( blink && uistate.overmap_show_map_notes && overmap_buffer.has_note( cur_pos ) ) { + } else if( blink && uistate.overmap_show_map_notes && overmap_buffer.has_note( omp ) ) { // Display notes in all situations, even when not seen std::tie( ter_sym, ter_color, std::ignore ) = - get_note_display_info( overmap_buffer.note( cur_pos ) ); + get_note_display_info( overmap_buffer.note( omp ) ); } else if( !see ) { // All cases above ignore the seen-status, ter_color = c_dark_gray; ter_sym = "#"; // All cases below assume that see is true. - } else if( blink && npc_color.count( cur_pos ) != 0 ) { + } else if( blink && npc_color.count( omp ) != 0 ) { // Visible NPCs are cached already - ter_color = npc_color[ cur_pos ].color; + ter_color = npc_color[ omp ].color; ter_sym = "@"; } else if( blink && mycount != 0 && g->debug_pathfinding ) { ter_color = c_red; @@ -670,25 +664,25 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr ter_color = c_blue; ter_sym = "!"; } else if( blink && showhordes && los && - overmap_buffer.get_horde_size( omx, omy, z ) >= HORDE_VISIBILITY_SIZE ) { + overmap_buffer.get_horde_size( omp ) >= HORDE_VISIBILITY_SIZE ) { // Display Hordes only when within player line-of-sight ter_color = c_green; - ter_sym = overmap_buffer.get_horde_size( omx, omy, z ) > HORDE_VISIBILITY_SIZE * 2 ? "Z" : "z"; - } else if( blink && overmap_buffer.has_vehicle( omx, omy, z ) ) { + ter_sym = overmap_buffer.get_horde_size( omp ) > HORDE_VISIBILITY_SIZE * 2 ? "Z" : "z"; + } else if( blink && overmap_buffer.has_vehicle( omp ) ) { // Display Vehicles only when player can see the location ter_color = c_cyan; ter_sym = "c"; - } else if( !sZoneName.empty() && tripointZone.x == omx && tripointZone.y == omy ) { + } else if( !sZoneName.empty() && tripointZone.xy() == omp.xy() ) { ter_color = c_yellow; ter_sym = "Z"; } else if( !uistate.overmap_show_forest_trails && cur_ter && is_ot_match( "forest_trail", cur_ter, ot_match_type::type ) ) { // If forest trails shouldn't be displayed, and this is a forest trail, then // instead render it like a forest. - set_color_and_symbol( forest, omx, omy, z, ter_sym, ter_color ); + set_color_and_symbol( forest, omp, ter_sym, ter_color ); } else { // Nothing special, but is visible to the player. - set_color_and_symbol( cur_ter, omx, omy, z, ter_sym, ter_color ); + set_color_and_symbol( cur_ter, omp, ter_sym, ter_color ); } // Are we debugging monster groups? @@ -696,15 +690,15 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr // Check if this tile is the target of the currently selected group // Convert to position within overmap - int localx = omx * 2; - int localy = omy * 2; - sm_to_om_remain( localx, localy ); + point omp_in_om( omp.xy() ); + omt_to_om_remain( omp_in_om ); + point group_target = sm_to_omt_copy( mgroup->target.xy() ); - if( mgroup && mgroup->target.x / 2 == localx / 2 && mgroup->target.y / 2 == localy / 2 ) { + if( mgroup && group_target == omp_in_om ) { ter_color = c_red; ter_sym = "x"; } else { - const auto &groups = overmap_buffer.monsters_at( omx, omy, center.z ); + const auto &groups = overmap_buffer.monsters_at( omp ); for( auto &mgp : groups ) { if( mgp->type == mongroup_id( "GROUP_FOREST" ) ) { // Don't flood the map with forest creatures. @@ -732,14 +726,14 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr // Preview for place_terrain or place_special if( uistate.place_terrain || uistate.place_special ) { - if( blink && uistate.place_terrain && omx == cursx && omy == cursy ) { + if( blink && uistate.place_terrain && omp.xy() == center.xy() ) { ter_color = uistate.place_terrain->get_color(); ter_sym = uistate.place_terrain->get_symbol(); } else if( blink && uistate.place_special ) { - if( omx - cursx >= s_begin.x && omx - cursx <= s_end.x && - omy - cursy >= s_begin.y && omy - cursy <= s_end.y ) { - const point cache_point( omx - cursx, omy - cursy ); - const auto sm = special_cache.find( cache_point ); + const point from_center = omp.xy() - center.xy(); + if( from_center.x >= s_begin.x && from_center.x <= s_end.x && + from_center.y >= s_begin.y && from_center.y <= s_end.y ) { + const auto sm = special_cache.find( from_center ); if( sm != special_cache.end() ) { ter_color = sm->second.second; @@ -749,12 +743,12 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr } // Highlight areas that already have been generated if( MAPBUFFER.lookup_submap( - omt_to_sm_copy( tripoint( omx, omy, z ) ) ) ) { + omt_to_sm_copy( omp ) ) ) { ter_color = red_background( ter_color ); } } - if( omx == cursx && omy == cursy && !uistate.place_special ) { + if( omp.xy() == center.xy() && !uistate.place_special ) { csee = see; ccur_ter = cur_ter; mvwputch_hi( w, j, i, ter_color, ter_sym ); @@ -764,21 +758,18 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr } } - if( z == 0 && uistate.overmap_show_city_labels ) { - draw_city_labels( w, tripoint( cursx, cursy, z ) ); - draw_camp_labels( w, tripoint( cursx, cursy, z ) ); + if( center.z == 0 && uistate.overmap_show_city_labels ) { + draw_city_labels( w, center ); + draw_camp_labels( w, center ); } - if( has_target && blink && - ( target.x < offset_x || - target.x >= offset_x + om_map_width || - target.y < offset_y || - target.y >= offset_y + om_map_height ) ) { - int marker_x = clamp( target.x - offset_x, 0, om_map_width - 1 ); - int marker_y = clamp( target.y - offset_y, 0, om_map_height - 1 ); + rectangle screen_bounds( corner.xy(), corner.xy() + point( om_map_width, om_map_height ) ); + + if( has_target && blink && !screen_bounds.contains_half_open( target.xy() ) ) { + point marker = clamp_half_open( target.xy(), screen_bounds ) - corner.xy(); std::string marker_sym = " "; - switch( direction_from( cursx, cursy, target.x, target.y ) ) { + switch( direction_from( center, target ) ) { case NORTH: marker_sym = "^"; break; @@ -806,13 +797,13 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr default: break; //Do nothing } - mvwputch( w, marker_y, marker_x, c_red, marker_sym ); + mvwputch( w, marker.y, marker.x, c_red, marker_sym ); } std::vector> corner_text; if( uistate.overmap_show_map_notes ) { - const std::string ¬e_text = overmap_buffer.note( cursx, cursy, z ); + const std::string ¬e_text = overmap_buffer.note( center ); if( !note_text.empty() ) { const std::tuple note_info = get_note_display_info( note_text ); @@ -823,13 +814,13 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr } } - for( const auto &npc : overmap_buffer.get_npcs_near_omt( cursx, cursy, z, 0 ) ) { + for( const auto &npc : overmap_buffer.get_npcs_near_omt( center, 0 ) ) { if( !npc->marked_for_death ) { corner_text.emplace_back( npc->basic_symbol_color(), npc->name ); } } - for( auto &v : overmap_buffer.get_vehicle( cursx, cursy, z ) ) { + for( auto &v : overmap_buffer.get_vehicle( center ) ) { corner_text.emplace_back( c_white, v.name ); } @@ -854,7 +845,7 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr mvwputch( w, corner_text.size(), maxlen, c_white, LINE_XOOX ); } - if( !sZoneName.empty() && tripointZone.x == cursx && tripointZone.y == cursy ) { + if( !sZoneName.empty() && tripointZone.xy() == center.xy() ) { std::string sTemp = _( "Zone:" ); sTemp += " " + sZoneName; @@ -902,18 +893,17 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr } } else { const auto &ter = ccur_ter.obj(); - const auto sm_pos = omt_to_sm_copy( tripoint( cursx, cursy, z ) ); + const auto sm_pos = omt_to_sm_copy( center ); mvwputch( wbar, 1, 1, ter.get_color(), ter.get_symbol() ); lines = fold_and_print( wbar, 1, 3, 25, c_light_gray, overmap_buffer.get_description_at( sm_pos ) ); } } else if( viewing_weather ) { - const auto curs_pos = tripoint( cursx, cursy, z ); const bool weather_is_visible = ( data.debug_weather || - g->u.overmap_los( curs_pos, sight_points * 2 ) ); + g->u.overmap_los( center, sight_points * 2 ) ); if( weather_is_visible ) { - weather_datum weather = weather_data( get_weather_at_point( curs_pos ) ); + weather_datum weather = weather_data( get_weather_at_point( center ) ); mvwprintz( wbar, 1, 1, weather.color, weather.name ); } else { mvwprintz( wbar, 1, 1, c_dark_gray, _( "# Unexplored" ) ); @@ -956,7 +946,7 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr } const bool show_overlays = uistate.overmap_show_overlays || uistate.overmap_blinking; - const bool is_explored = overmap_buffer.is_explored( cursx, cursy, z ); + const bool is_explored = overmap_buffer.is_explored( center ); print_hint( "LEVEL_UP" ); print_hint( "LEVEL_DOWN" ); @@ -978,10 +968,10 @@ void draw( const catacurses::window &w, const catacurses::window &wbar, const tr print_hint( "QUIT" ); } - point omt( cursx, cursy ); + point omt = center.xy(); const point om = omt_to_om_remain( omt ); mvwprintz( wbar, getmaxy( wbar ) - 1, 1, c_red, - _( "LEVEL %i, %d'%d, %d'%d" ), z, om.x, omt.x, om.y, omt.y ); + _( "LEVEL %i, %d'%d, %d'%d" ), center.z, om.x, omt.x, om.y, omt.y ); // draw nice crosshair around the cursor if( blink && !uistate.place_terrain && !uistate.place_special ) { @@ -1268,12 +1258,12 @@ static void place_ter_or_special( tripoint &curs, const tripoint &orig, const bo } else if( action == "CONFIRM" ) { // Actually modify the overmap if( terrain ) { overmap_buffer.ter( curs ) = uistate.place_terrain->id.id(); - overmap_buffer.set_seen( curs.x, curs.y, curs.z, true ); + overmap_buffer.set_seen( curs, true ); } else { overmap_buffer.place_special( *uistate.place_special, curs, uistate.omedit_rotation, false, true ); for( const overmap_special_terrain &s_ter : uistate.place_special->terrains ) { const tripoint pos = curs + om_direction::rotate( s_ter.p, uistate.omedit_rotation ); - overmap_buffer.set_seen( pos.x, pos.y, pos.z, true ); + overmap_buffer.set_seen( pos, true ); } } break; @@ -1460,7 +1450,7 @@ static tripoint display( const tripoint &orig, const draw_data_t &data = draw_da } else if( action == "TOGGLE_CITY_LABELS" ) { uistate.overmap_show_city_labels = !uistate.overmap_show_city_labels; } else if( action == "TOGGLE_EXPLORED" ) { - overmap_buffer.toggle_explored( curs.x, curs.y, curs.z ); + overmap_buffer.toggle_explored( curs ); } else if( action == "TOGGLE_FAST_SCROLL" ) { fast_scroll = !fast_scroll; } else if( action == "TOGGLE_FOREST_TRAILS" ) { diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index 313905ef7b82e..fba4f00a44ff0 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -60,29 +60,27 @@ int camp_reference::get_distance_from_bounds() const return distance - omt_to_sm_copy( 4 ); } -std::string overmapbuffer::terrain_filename( const int x, const int y ) +std::string overmapbuffer::terrain_filename( const point &p ) { std::ostringstream filename; filename << g->get_world_base_save_path() << "/"; - filename << "o." << x << "." << y; + filename << "o." << p.x << "." << p.y; return filename.str(); } -std::string overmapbuffer::player_filename( const int x, const int y ) +std::string overmapbuffer::player_filename( const point &p ) { std::ostringstream filename; - filename << g->get_player_base_save_path() << ".seen." << x << "." << y; + filename << g->get_player_base_save_path() << ".seen." << p.x << "." << p.y; return filename.str(); } -overmap &overmapbuffer::get( const int x, const int y ) +overmap &overmapbuffer::get( const point &p ) { - const point p { x, y }; - if( last_requested_overmap != nullptr && last_requested_overmap->pos() == p ) { return *last_requested_overmap; } @@ -93,7 +91,7 @@ overmap &overmapbuffer::get( const int x, const int y ) } // That constructor loads an existing overmap or creates a new one. - overmap &new_om = *( overmaps[ p ] = std::make_unique( x, y ) ); + overmap &new_om = *( overmaps[ p ] = std::make_unique( p ) ); new_om.populate(); // Note: fix_mongroups might load other overmaps, so overmaps.back() is not // necessarily the overmap at (x,y) @@ -104,17 +102,15 @@ overmap &overmapbuffer::get( const int x, const int y ) return new_om; } -void overmapbuffer::create_custom_overmap( const int x, const int y, - overmap_special_batch &specials ) +void overmapbuffer::create_custom_overmap( const point &p, overmap_special_batch &specials ) { - point p( x, y ); if( last_requested_overmap != nullptr ) { auto om_iter = overmaps.find( p ); if( om_iter != overmaps.end() && om_iter->second.get() == last_requested_overmap ) { last_requested_overmap = nullptr; } } - overmap &new_om = *( overmaps[ p ] = std::make_unique( x, y ) ); + overmap &new_om = *( overmaps[ p ] = std::make_unique( p ) ); new_om.populate( specials ); } @@ -136,13 +132,13 @@ void overmapbuffer::fix_mongroups( overmap &new_overmap ) point smabs( mg.pos.x + new_overmap.pos().x * OMAPX * 2, mg.pos.y + new_overmap.pos().y * OMAPY * 2 ); point omp = sm_to_om_remain( smabs ); - if( !has( omp.x, omp.y ) ) { + if( !has( omp ) ) { // Don't generate new overmaps, as this can be called from the // overmap-generating code. ++it; continue; } - overmap &om = get( omp.x, omp.y ); + overmap &om = get( omp ); mg.pos.x = smabs.x; mg.pos.y = smabs.y; om.add_mon_group( mg ); @@ -180,7 +176,7 @@ void overmapbuffer::fix_npcs( overmap &new_overmap ) const tripoint npc_omt_pos = np.global_omt_location(); const point npc_om_pos = omt_to_om_copy( npc_omt_pos.x, npc_omt_pos.y ); const point &loc = new_overmap.pos(); - if( !has( npc_om_pos.x, npc_om_pos.y ) ) { + if( !has( npc_om_pos ) ) { // This can't really happen without save editing // We have no sane option here, just place the NPC on the edge debugmsg( "NPC %s is out of bounds, on non-generated overmap %d,%d", @@ -196,7 +192,7 @@ void overmapbuffer::fix_npcs( overmap &new_overmap ) } // Simplest case: just move the pointer - get( npc_om_pos.x, npc_om_pos.y ).insert_npc( ptr ); + get( npc_om_pos ).insert_npc( ptr ); } } @@ -215,45 +211,46 @@ void overmapbuffer::clear() last_requested_overmap = nullptr; } -const regional_settings &overmapbuffer::get_settings( int x, int y, int z ) +const regional_settings &overmapbuffer::get_settings( const tripoint &p ) { - ( void )z; - overmap &om = get_om_global( x, y ); + overmap &om = get_om_global( p ); return om.get_settings(); } -void overmapbuffer::add_note( int x, int y, int z, const std::string &message ) +void overmapbuffer::add_note( const tripoint &p, const std::string &message ) { - overmap &om = get_om_global( x, y ); - om.add_note( x, y, z, message ); + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + om.add_note( local, message ); } -void overmapbuffer::delete_note( int x, int y, int z ) +void overmapbuffer::delete_note( const tripoint &p ) { - if( has_note( x, y, z ) ) { - overmap &om = get_om_global( x, y ); - om.delete_note( x, y, z ); + if( has_note( p ) ) { + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + om.delete_note( local ); } } -void overmapbuffer::add_extra( int x, int y, int z, const string_id &id ) +void overmapbuffer::add_extra( const tripoint &p, const string_id &id ) { - overmap &om = get_om_global( x, y ); - om.add_extra( x, y, z, id ); + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + om.add_extra( local, id ); } -void overmapbuffer::delete_extra( int x, int y, int z ) +void overmapbuffer::delete_extra( const tripoint &p ) { - if( has_extra( x, y, z ) ) { - overmap &om = get_om_global( x, y ); - om.delete_extra( x, y, z ); + if( has_extra( p ) ) { + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + om.delete_extra( local ); } } -overmap *overmapbuffer::get_existing( int x, int y ) +overmap *overmapbuffer::get_existing( const point &p ) { - const point p {x, y}; - if( last_requested_overmap && last_requested_overmap->pos() == p ) { return last_requested_overmap; } @@ -266,10 +263,10 @@ overmap *overmapbuffer::get_existing( int x, int y ) // checked in a previous call of this function). return nullptr; } - if( file_exist( terrain_filename( x, y ) ) ) { + if( file_exist( terrain_filename( p ) ) ) { // File exists, load it normally (the get function // indirectly call overmap::open to do so). - return &get( x, y ); + return &get( p ); } // File does not exist (or not readable which is essentially // the same for our usage). A second call of this function with @@ -281,27 +278,26 @@ overmap *overmapbuffer::get_existing( int x, int y ) return nullptr; } -bool overmapbuffer::has( int x, int y ) +bool overmapbuffer::has( const point &p ) { - return get_existing( x, y ) != nullptr; + return get_existing( p ) != nullptr; } overmap &overmapbuffer::get_om_global( int &x, int &y ) { const point om_pos = omt_to_om_remain( x, y ); - return get( om_pos.x, om_pos.y ); + return get( om_pos ); } overmap &overmapbuffer::get_om_global( const point &p ) { const point om_pos = omt_to_om_copy( p ); - return get( om_pos.x, om_pos.y ); + return get( om_pos ); } overmap &overmapbuffer::get_om_global( const tripoint &p ) { - const point om_pos = omt_to_om_copy( { p.x, p.y } ); - return get( om_pos.x, om_pos.y ); + return get_om_global( p.xy() ); } overmap_with_local_coordinates overmapbuffer::get_om_global_with_coordinates( const tripoint &p ) @@ -309,26 +305,25 @@ overmap_with_local_coordinates overmapbuffer::get_om_global_with_coordinates( co int x = p.x; int y = p.y; const point om_pos = omt_to_om_remain( x, y ); - overmap *om = &get( om_pos.x, om_pos.y ); + overmap *om = &get( om_pos ); return { om, tripoint( x, y, p.z ) }; } overmap *overmapbuffer::get_existing_om_global( int &x, int &y ) { const point om_pos = omt_to_om_remain( x, y ); - return get_existing( om_pos.x, om_pos.y ); + return get_existing( om_pos ); } overmap *overmapbuffer::get_existing_om_global( const point &p ) { const point om_pos = omt_to_om_copy( p ); - return get_existing( om_pos.x, om_pos.y ); + return get_existing( om_pos ); } overmap *overmapbuffer::get_existing_om_global( const tripoint &p ) { - const tripoint om_pos = omt_to_om_copy( p ); - return get_existing( om_pos.x, om_pos.y ); + return get_existing_om_global( p.xy() ); } cata::optional @@ -338,7 +333,7 @@ overmapbuffer::get_existing_om_global_with_coordinates( int x = p.x; int y = p.y; const point om_pos = omt_to_om_remain( x, y ); - overmap *om = get_existing( om_pos.x, om_pos.y ); + overmap *om = get_existing( om_pos ); if( om == nullptr ) { return cata::nullopt; } @@ -359,53 +354,59 @@ bool overmapbuffer::is_omt_generated( const tripoint &loc ) return om->overmap_pointer->is_omt_generated( om->coordinates ); } -bool overmapbuffer::has_note( int x, int y, int z ) +bool overmapbuffer::has_note( const tripoint &p ) { - const overmap *om = get_existing_om_global( x, y ); - return ( om != nullptr ) && om->has_note( x, y, z ); + tripoint local( p ); + const overmap *om = get_existing_om_global( local.x, local.y ); + return ( om != nullptr ) && om->has_note( local ); } -const std::string &overmapbuffer::note( int x, int y, int z ) +const std::string &overmapbuffer::note( const tripoint &p ) { - const overmap *om = get_existing_om_global( x, y ); + tripoint local( p ); + const overmap *om = get_existing_om_global( local.x, local.y ); if( om == nullptr ) { static const std::string empty_string; return empty_string; } - return om->note( x, y, z ); + return om->note( local ); } -bool overmapbuffer::has_extra( int x, int y, int z ) +bool overmapbuffer::has_extra( const tripoint &p ) { - const overmap *om = get_existing_om_global( x, y ); - return ( om != nullptr ) && om->has_extra( x, y, z ); + tripoint local( p ); + const overmap *om = get_existing_om_global( local.x, local.y ); + return ( om != nullptr ) && om->has_extra( local ); } -const string_id &overmapbuffer::extra( int x, int y, int z ) +const string_id &overmapbuffer::extra( const tripoint &p ) { - const overmap *om = get_existing_om_global( x, y ); + tripoint local( p ); + const overmap *om = get_existing_om_global( local.x, local.y ); if( om == nullptr ) { static string_id id; return id; } - return om->extra( x, y, z ); + return om->extra( local ); } -bool overmapbuffer::is_explored( int x, int y, int z ) +bool overmapbuffer::is_explored( const tripoint &p ) { - const overmap *om = get_existing_om_global( x, y ); - return ( om != nullptr ) && om->is_explored( x, y, z ); + tripoint local( p ); + const overmap *om = get_existing_om_global( local.x, local.y ); + return ( om != nullptr ) && om->is_explored( local ); } -void overmapbuffer::toggle_explored( int x, int y, int z ) +void overmapbuffer::toggle_explored( const tripoint &p ) { - overmap &om = get_om_global( x, y ); - om.explored( x, y, z ) = !om.explored( x, y, z ); + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + om.explored( local ) = !om.explored( local ); } -bool overmapbuffer::has_horde( const int x, const int y, const int z ) +bool overmapbuffer::has_horde( const tripoint &p ) { - for( const auto &m : overmap_buffer.monsters_at( x, y, z ) ) { + for( const auto &m : overmap_buffer.monsters_at( p ) ) { if( m->horde ) { return true; } @@ -414,10 +415,10 @@ bool overmapbuffer::has_horde( const int x, const int y, const int z ) return false; } -int overmapbuffer::get_horde_size( const int x, const int y, const int z ) +int overmapbuffer::get_horde_size( const tripoint &p ) { int horde_size = 0; - for( const auto &m : overmap_buffer.monsters_at( x, y, z ) ) { + for( const auto &m : overmap_buffer.monsters_at( p ) ) { if( m->horde ) { if( !m->monsters.empty() ) { horde_size += m->monsters.size(); @@ -434,19 +435,20 @@ int overmapbuffer::get_horde_size( const int x, const int y, const int z ) return horde_size; } -bool overmapbuffer::has_camp( int x, int y, int z ) +bool overmapbuffer::has_camp( const tripoint &p ) { - if( z ) { + if( p.z ) { return false; } - const overmap *const om = get_existing_om_global( x, y ); + point local( p.xy() ); + const overmap *const om = get_existing_om_global( local.x, local.y ); if( !om ) { return false; } for( const auto &v : om->camps ) { - if( v.camp_omt_pos().x == x && v.camp_omt_pos().y == y ) { + if( v.camp_omt_pos().xy() == local ) { return true; } } @@ -454,19 +456,20 @@ bool overmapbuffer::has_camp( int x, int y, int z ) return false; } -bool overmapbuffer::has_vehicle( int x, int y, int z ) +bool overmapbuffer::has_vehicle( const tripoint &p ) { - if( z ) { + if( p.z ) { return false; } - const overmap *const om = get_existing_om_global( x, y ); + point local( p.xy() ); + const overmap *const om = get_existing_om_global( local.x, local.y ); if( !om ) { return false; } for( const auto &v : om->vehicles ) { - if( v.second.x == x && v.second.y == y ) { + if( v.second.p == local ) { return true; } } @@ -474,18 +477,19 @@ bool overmapbuffer::has_vehicle( int x, int y, int z ) return false; } -std::vector overmapbuffer::get_vehicle( int x, int y, int z ) +std::vector overmapbuffer::get_vehicle( const tripoint &p ) { std::vector result; - if( z != 0 ) { + if( p.z != 0 ) { return result; } - overmap *om = get_existing_om_global( x, y ); + point local( p.xy() ); + overmap *om = get_existing_om_global( local.x, local.y ); if( om == nullptr ) { return result; } for( const auto &ov : om->vehicles ) { - if( ov.second.x == x && ov.second.y == y ) { + if( ov.second.p == local ) { result.push_back( ov.second ); } } @@ -524,33 +528,31 @@ void overmapbuffer::move_hordes() } } -std::vector overmapbuffer::monsters_at( int x, int y, int z ) +std::vector overmapbuffer::monsters_at( const tripoint &p ) { // (x,y) are overmap terrain coordinates, they spawn 2x2 submaps, // but monster groups are defined with submap coordinates. + tripoint p_sm = omt_to_sm_copy( p ); std::vector result; - std::vector tmp = groups_at( x * 2, y * 2, z ); - result.insert( result.end(), tmp.begin(), tmp.end() ); - tmp = groups_at( x * 2, y * 2 + 1, z ); - result.insert( result.end(), tmp.begin(), tmp.end() ); - tmp = groups_at( x * 2 + 1, y * 2 + 1, z ); - result.insert( result.end(), tmp.begin(), tmp.end() ); - tmp = groups_at( x * 2 + 1, y * 2, z ); - result.insert( result.end(), tmp.begin(), tmp.end() ); + for( point offset : std::array { { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } } } ) { + std::vector tmp = groups_at( p_sm + offset ); + result.insert( result.end(), tmp.begin(), tmp.end() ); + } return result; } -std::vector overmapbuffer::groups_at( int x, int y, int z ) +std::vector overmapbuffer::groups_at( const tripoint &p ) { std::vector result; - const point omp = sm_to_om_remain( x, y ); - if( !has( omp.x, omp.y ) ) { + point sm_within_om( p.xy() ); + const point omp = sm_to_om_remain( sm_within_om ); + if( !has( omp ) ) { return result; } - const tripoint dpos( x, y, z ); - overmap &om = get( omp.x, omp.y ); - for( auto it = om.zg.lower_bound( dpos ), end = om.zg.upper_bound( dpos ); it != end; ++it ) { - auto &mg = it->second; + overmap &om = get( omp ); + auto groups_range = om.zg.equal_range( tripoint( sm_within_om, p.z ) ); + for( auto it = groups_range.first; it != groups_range.second; ++it ) { + mongroup &mg = it->second; if( mg.empty() ) { continue; } @@ -600,8 +602,7 @@ void overmapbuffer::move_vehicle( vehicle *veh, const point &old_msp ) overmap &new_om = get_om_global( new_omt.x, new_omt.y ); // *_omt is now local to the overmap, and it's in overmap terrain system if( &old_om == &new_om ) { - new_om.vehicles[veh->om_id].x = new_omt.x; - new_om.vehicles[veh->om_id].y = new_omt.y; + new_om.vehicles[veh->om_id].p = new_omt; } else { old_om.vehicles.erase( veh->om_id ); add_vehicle( veh ); @@ -640,8 +641,7 @@ void overmapbuffer::add_vehicle( vehicle *veh ) id++; } om_vehicle &tracked_veh = om.vehicles[id]; - tracked_veh.x = omt.x; - tracked_veh.y = omt.y; + tracked_veh.p = omt; tracked_veh.name = veh->name; veh->om_id = id; } @@ -653,22 +653,25 @@ void overmapbuffer::add_camp( const basecamp &camp ) om.camps.push_back( camp ); } -bool overmapbuffer::seen( int x, int y, int z ) +bool overmapbuffer::seen( const tripoint &p ) { - const overmap *om = get_existing_om_global( x, y ); - return ( om != nullptr ) && const_cast( om )->seen( x, y, z ); + tripoint local( p ); + const overmap *om = get_existing_om_global( local.x, local.y ); + return ( om != nullptr ) && om->seen( local ); } -void overmapbuffer::set_seen( int x, int y, int z, bool seen ) +void overmapbuffer::set_seen( const tripoint &p, bool seen ) { - overmap &om = get_om_global( x, y ); - om.seen( x, y, z ) = seen; + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + om.seen( local ) = seen; } -oter_id &overmapbuffer::ter( int x, int y, int z ) +oter_id &overmapbuffer::ter( const tripoint &p ) { - overmap &om = get_om_global( x, y ); - return om.ter( x, y, z ); + tripoint local( p ); + overmap &om = get_om_global( local.x, local.y ); + return om.ter( local ); } bool overmapbuffer::reveal( const point ¢er, int radius, int z ) @@ -690,24 +693,23 @@ bool overmapbuffer::reveal( const tripoint ¢er, int radius, bool result = false; for( int i = -radius; i <= radius; i++ ) { for( int j = -radius; j <= radius; j++ ) { - const int x = center.x + i; - const int y = center.y + j; - if( seen( x, y, center.z ) ) { + const tripoint p = center + point( i, j ); + if( seen( p ) ) { continue; } if( trigdist && i * i + j * j > radius_squared ) { continue; } - // We need to make new ints to pass by reference to get_om_global, because it modifies them - // to be local to that overmap. - int local_x = center.x + i; - int local_y = center.y + j; - const oter_id &ter = get_om_global( local_x, local_y ).get_ter( local_x, local_y, 0 ); + // We need to make new coords to pass by reference to get_om_global, + // because it modifies them to be local to that overmap. + tripoint local = p; + const overmap &om = get_om_global( local.x, local.y ); + const oter_id &ter = om.get_ter( local.x, local.y, 0 ); if( !filter( ter ) ) { continue; } result = true; - set_seen( x, y, center.z, true ); + set_seen( local, true ); } } return result; @@ -849,16 +851,11 @@ bool overmapbuffer::check_overmap_special_type_existing( const overmap_special_i return om->overmap_pointer->check_overmap_special_type( id, om->coordinates ); } -bool overmapbuffer::check_ot( const std::string &type, ot_match_type match_type, int x, int y, - int z ) +bool overmapbuffer::check_ot( const std::string &type, ot_match_type match_type, const tripoint &p ) { - overmap &om = get_om_global( x, y ); - return om.check_ot( type, match_type, x, y, z ); -} -bool overmapbuffer::check_ot( const std::string &type, ot_match_type match_type, - const tripoint &loc ) -{ - return check_ot( type, match_type, loc.x, loc.y, loc.z ); + tripoint local = p; + overmap &om = get_om_global( local.x, local.y ); + return om.check_ot( type, match_type, local ); } bool overmapbuffer::check_overmap_special_type( const overmap_special_id &id, const tripoint &loc ) @@ -893,10 +890,10 @@ bool overmapbuffer::is_findable_location( const tripoint &location, const omt_fi return false; } - if( params.must_see && !seen( location.x, location.y, location.z ) ) { + if( params.must_see && !seen( location ) ) { return false; } - if( params.cant_see && seen( location.x, location.y, location.z ) ) { + if( params.cant_see && seen( location ) ) { return false; } @@ -1038,14 +1035,11 @@ std::shared_ptr overmapbuffer::find_npc( int id ) return nullptr; } -cata::optional overmapbuffer::find_camp( const int x, const int y ) +cata::optional overmapbuffer::find_camp( const point &p ) { for( auto &it : overmaps ) { - if( auto p = it.second->find_camp( x, y ) ) { - if( p ) { - basecamp *temp_camp = *p; - return temp_camp; - } + if( cata::optional camp = it.second->find_camp( p ) ) { + return camp; } } return cata::nullopt; @@ -1056,7 +1050,7 @@ void overmapbuffer::insert_npc( const std::shared_ptr &who ) assert( who ); const tripoint npc_omt_pos = who->global_omt_location(); const point npc_om_pos = omt_to_om_copy( npc_omt_pos.x, npc_omt_pos.y ); - get( npc_om_pos.x, npc_om_pos.y ).insert_npc( who ); + get( npc_om_pos ).insert_npc( who ); } std::shared_ptr overmapbuffer::remove_npc( const int id ) @@ -1077,7 +1071,7 @@ std::vector> overmapbuffer::get_npcs_near_player( int radiu omt_to_sm( plpos.x, plpos.y ); // INT_MIN is a (a bit ugly) way to inform get_npcs_near not to filter by z-level const int zpos = g->m.has_zlevels() ? INT_MIN : plpos.z; - return get_npcs_near( plpos.x, plpos.y, zpos, radius ); + return get_npcs_near( tripoint( plpos.xy(), zpos ), radius ); } std::vector overmapbuffer::get_overmaps_near( const tripoint &location, @@ -1094,7 +1088,7 @@ std::vector overmapbuffer::get_overmaps_near( const tripoint &locatio for( int x = start.x; x <= end.x; ++x ) { for( int y = start.y; y <= end.y; ++y ) { - if( const auto existing_om = get_existing( x, y ) ) { + if( overmap *existing_om = get_existing( point( x, y ) ) ) { result.emplace_back( existing_om ); } } @@ -1130,18 +1124,17 @@ std::vector> overmapbuffer::get_companion_mission_npcs() } // If z == INT_MIN, allow all z-levels -std::vector> overmapbuffer::get_npcs_near( int x, int y, int z, int radius ) +std::vector> overmapbuffer::get_npcs_near( const tripoint &p, int radius ) { std::vector> result; - tripoint p{ x, y, z }; for( auto &it : get_overmaps_near( p, radius ) ) { auto temp = it->get_npcs( [&]( const npc & guy ) { // Global position of NPC, in submap coordinates const tripoint pos = guy.global_sm_location(); - if( z != INT_MIN && pos.z != z ) { + if( p.z != INT_MIN && pos.z != p.z ) { return false; } - return square_dist( x, y, pos.x, pos.y ) <= radius; + return square_dist( p.xy(), pos.xy() ) <= radius; } ); result.insert( result.end(), temp.begin(), temp.end() ); } @@ -1149,18 +1142,18 @@ std::vector> overmapbuffer::get_npcs_near( int x, int y, in } // If z == INT_MIN, allow all z-levels -std::vector> overmapbuffer::get_npcs_near_omt( int x, int y, int z, +std::vector> overmapbuffer::get_npcs_near_omt( const tripoint &p, int radius ) { std::vector> result; - for( auto &it : get_overmaps_near( omt_to_sm_copy( x, y ), radius ) ) { + for( auto &it : get_overmaps_near( omt_to_sm_copy( p.xy() ), radius ) ) { auto temp = it->get_npcs( [&]( const npc & guy ) { // Global position of NPC, in submap coordinates tripoint pos = guy.global_omt_location(); - if( z != INT_MIN && pos.z != z ) { + if( p.z != INT_MIN && pos.z != p.z ) { return false; } - return square_dist( x, y, pos.x, pos.y ) <= radius; + return square_dist( p.xy(), pos.xy() ) <= radius; } ); result.insert( result.end(), temp.begin(), temp.end() ); } @@ -1285,7 +1278,7 @@ city_reference overmapbuffer::closest_known_city( const tripoint ¢er ) const auto it = std::find_if( cities.begin(), cities.end(), [this]( const city_reference & elem ) { const tripoint p = sm_to_omt_copy( elem.abs_sm_pos ); - return seen( p.x, p.y, p.z ); + return seen( p ); } ); if( it != cities.end() ) { @@ -1358,13 +1351,13 @@ static int modulo( int v, int m ) return r >= 0 ? r : r + m; } -void overmapbuffer::spawn_monster( const int x, const int y, const int z ) +void overmapbuffer::spawn_monster( const tripoint &p ) { // Create a copy, so we can reuse x and y later - point sm( x, y ); + point sm = p.xy(); const point omp = sm_to_om_remain( sm ); - overmap &om = get( omp.x, omp.y ); - const tripoint current_submap_loc( sm.x, sm.y, z ); + overmap &om = get( omp ); + const tripoint current_submap_loc( tripoint( sm, p.z ) ); auto monster_bucket = om.monster_map.equal_range( current_submap_loc ); std::for_each( monster_bucket.first, monster_bucket.second, [&]( std::pair &monster_entry ) { @@ -1377,10 +1370,9 @@ void overmapbuffer::spawn_monster( const int x, const int y, const int z ) point ms( modulo( this_monster.posx(), SEEX ), modulo( this_monster.posy(), SEEY ) ); assert( ms.x >= 0 && ms.x < SEEX ); assert( ms.y >= 0 && ms.y < SEEX ); - ms.x += x * SEEX; - ms.y += y * SEEY; + ms += sm_to_ms_copy( p.xy() ); // The monster position must be local to the main map when added via game::add_zombie - const tripoint local = tripoint( g->m.getlocal( ms.x, ms.y ), z ); + const tripoint local = tripoint( g->m.getlocal( ms.x, ms.y ), p.z ); assert( g->m.inbounds( local ) ); this_monster.spawn( local ); g->add_zombie( this_monster ); @@ -1394,7 +1386,7 @@ void overmapbuffer::despawn_monster( const monster &critter ) tripoint sm = ms_to_sm_copy( g->m.getabs( critter.pos() ) ); // Get the overmap coordinates and get the overmap, sm is now local to that overmap const point omp = sm_to_om_remain( sm.x, sm.y ); - overmap &om = get( omp.x, omp.y ); + overmap &om = get( omp ); // Store the monster using coordinates local to the overmap. om.monster_map.insert( std::make_pair( sm, critter ) ); } @@ -1454,9 +1446,9 @@ overmapbuffer::t_extras_vector overmapbuffer::get_extras( int z, const std::stri return result; } -bool overmapbuffer::is_safe( int x, int y, int z ) +bool overmapbuffer::is_safe( const tripoint &p ) { - for( auto &mongrp : monsters_at( x, y, z ) ) { + for( auto &mongrp : monsters_at( p ) ) { if( !mongrp->is_safe() ) { return false; } diff --git a/src/overmapbuffer.h b/src/overmapbuffer.h index b646af259c5e4..36de261d5b91a 100644 --- a/src/overmapbuffer.h +++ b/src/overmapbuffer.h @@ -110,71 +110,44 @@ class overmapbuffer public: overmapbuffer(); - static std::string terrain_filename( const int x, const int y ); - static std::string player_filename( const int x, const int y ); + static std::string terrain_filename( const point & ); + static std::string player_filename( const point & ); /** * Uses overmap coordinates, that means x and y are directly * compared with the position of the overmap. */ - overmap &get( const int x, const int y ); + overmap &get( const point & ); void save(); void clear(); - void create_custom_overmap( const int x, const int y, overmap_special_batch &specials ); + void create_custom_overmap( const point &, overmap_special_batch &specials ); /** * Uses global overmap terrain coordinates, creates the * overmap if needed. */ - oter_id &ter( int x, int y, int z ); - oter_id &ter( const tripoint &p ) { - return ter( p.x, p.y, p.z ); - } + oter_id &ter( const tripoint &p ); /** * Uses global overmap terrain coordinates. */ - bool has_note( int x, int y, int z ); - bool has_note( const tripoint &p ) { - return has_note( p.x, p.y, p.z ); - } - const std::string ¬e( int x, int y, int z ); - const std::string ¬e( const tripoint &p ) { - return note( p.x, p.y, p.z ); - } - void add_note( int x, int y, int z, const std::string &message ); - void add_note( const tripoint &p, const std::string &message ) { - add_note( p.x, p.y, p.z, message ); - } - void delete_note( int x, int y, int z ); - void delete_note( const tripoint &p ) { - delete_note( p.x, p.y, p.z ); - } - bool has_extra( int x, int y, int z ); - bool has_extra( const tripoint &p ) { - return has_extra( p.x, p.y, p.z ); - } - const string_id &extra( int x, int y, int z ); - const string_id &extra( const tripoint &p ) { - return extra( p.x, p.y, p.z ); - } - void add_extra( int x, int y, int z, const string_id &id ); - void add_extra( const tripoint &p, const string_id &id ) { - add_extra( p.x, p.y, p.z, id ); - } - void delete_extra( int x, int y, int z ); - void delete_extra( const tripoint &p ) { - delete_extra( p.x, p.y, p.z ); - } - bool is_explored( int x, int y, int z ); - void toggle_explored( int x, int y, int z ); - bool seen( int x, int y, int z ); - void set_seen( int x, int y, int z, bool seen = true ); - bool has_camp( int x, int y, int z ); - bool has_vehicle( int x, int y, int z ); - bool has_horde( int x, int y, int z ); - int get_horde_size( int x, int y, int z ); - std::vector get_vehicle( int x, int y, int z ); - const regional_settings &get_settings( int x, int y, int z ); + bool has_note( const tripoint &p ); + const std::string ¬e( const tripoint &p ); + void add_note( const tripoint &, const std::string &message ); + void delete_note( const tripoint &p ); + bool has_extra( const tripoint &p ); + const string_id &extra( const tripoint &p ); + void add_extra( const tripoint &p, const string_id &id ); + void delete_extra( const tripoint &p ); + bool is_explored( const tripoint &p ); + void toggle_explored( const tripoint &p ); + bool seen( const tripoint &p ); + void set_seen( const tripoint &p, bool seen = true ); + bool has_camp( const tripoint &p ); + bool has_vehicle( const tripoint &p ); + bool has_horde( const tripoint &p ); + int get_horde_size( const tripoint &p ); + std::vector get_vehicle( const tripoint &p ); + const regional_settings &get_settings( const tripoint &p ); /** * Accessors for horde introspection into overmaps. * Probably also useful for NPC overmap-scale navigation. @@ -199,10 +172,7 @@ class overmapbuffer * Check for any dangerous monster groups at the global overmap terrain coordinates. * If there are any, it's not safe. */ - bool is_safe( int x, int y, int z ); - bool is_safe( const tripoint &p ) { - return is_safe( p.x, p.y, p.z ); - } + bool is_safe( const tripoint &p ); /** * Move the tracking mark of the given vehicle. @@ -231,7 +201,7 @@ class overmapbuffer */ void add_camp( const basecamp &camp ); - cata::optional find_camp( const int x, const int y ); + cata::optional find_camp( const point &p ); /** * Get all npcs in a area with given radius around (x, y). * Only npcs on the given z-level are considered. @@ -243,7 +213,7 @@ class overmapbuffer * specific submap. */ - std::vector> get_npcs_near( int x, int y, int z, int radius ); + std::vector> get_npcs_near( const tripoint &p, int radius ); /** * Get all (currently loaded!) npcs that have a companion * mission set. @@ -255,7 +225,7 @@ class overmapbuffer * A radius of 0 returns all npcs that are on that specific * overmap terrain tile. */ - std::vector> get_npcs_near_omt( int x, int y, int z, int radius ); + std::vector> get_npcs_near_omt( const tripoint &p, int radius ); /** * Same as @ref get_npcs_near(int,int,int,int) but uses * player position as center. @@ -365,18 +335,18 @@ class overmapbuffer cata::optional get_existing_om_global_with_coordinates( const tripoint &p ); /** - * (x,y) are global overmap coordinates (same as @ref get). + * Pass global overmap coordinates (same as @ref get). * @returns true if the buffer has a overmap with * the given coordinates. */ - bool has( int x, int y ); + bool has( const point &p ); /** * Get an existing overmap, does not create a new one * and may return NULL if the requested overmap does not * exist. * (x,y) are global overmap coordinates (same as @ref get). */ - overmap *get_existing( int x, int y ); + overmap *get_existing( const point &p ); /** * Returns whether or not the location has been generated (e.g. mapgen has run). * @param loc is in world-global omt coordinates. @@ -413,22 +383,22 @@ class overmapbuffer void process_mongroups(); /** * Let hordes move a step. Note that this may move monster groups inside the reality bubble, - * therefor you should probably call @ref map::spawn_monsters to spawn them. + * therefore you should probably call @ref map::spawn_monsters to spawn them. */ void move_hordes(); // hordes -- this uses overmap terrain coordinates! - std::vector monsters_at( int x, int y, int z ); + std::vector monsters_at( const tripoint &p ); /** - * Monster groups at (x,y,z) - absolute submap coordinates. + * Monster groups at p - absolute submap coordinates. * Groups with no population are not included. */ - std::vector groups_at( int x, int y, int z ); + std::vector groups_at( const tripoint &p ); /** * Spawn monsters from the overmap onto the main map (game::m). - * (x,y,z) is an absolute *submap* coordinate. + * p is an absolute *submap* coordinate. */ - void spawn_monster( const int x, const int y, const int z ); + void spawn_monster( const tripoint &p ); /** * Despawn the monster back onto the overmap. The monsters position * (monster::pos()) is interpreted as relative to the main map. @@ -462,9 +432,6 @@ class overmapbuffer city_reference closest_known_city( const tripoint ¢er ); std::string get_description_at( const tripoint &where ); - inline std::string get_description_at( const point &where, const int z ) { - return get_description_at( tripoint( where, z ) ); - } /** * Place the specified overmap special directly on the map using the provided location and rotation. @@ -531,7 +498,6 @@ class overmapbuffer * overmap terrain coordinates. * This function may create a new overmap if needed. */ - bool check_ot( const std::string &otype, ot_match_type match_type, int x, int y, int z ); bool check_ot( const std::string &otype, ot_match_type match_type, const tripoint &loc ); bool check_overmap_special_type( const overmap_special_id &id, const tripoint &loc ); diff --git a/src/panels.cpp b/src/panels.cpp index d096db80476d8..ed818656f4544 100644 --- a/src/panels.cpp +++ b/src/panels.cpp @@ -217,15 +217,14 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const for( int i = -( width / 2 ); i <= width - ( width / 2 ) - 1; i++ ) { for( int j = -( height / 2 ); j <= height - ( height / 2 ) - 1; j++ ) { - const int omx = cursx + i; - const int omy = cursy + j; + const tripoint omp( cursx + i, cursy + j, g->get_levz() ); nc_color ter_color; std::string ter_sym; - const bool seen = overmap_buffer.seen( omx, omy, g->get_levz() ); - const bool vehicle_here = overmap_buffer.has_vehicle( omx, omy, g->get_levz() ); - if( overmap_buffer.has_note( omx, omy, g->get_levz() ) ) { + const bool seen = overmap_buffer.seen( omp ); + const bool vehicle_here = overmap_buffer.has_vehicle( omp ); + if( overmap_buffer.has_note( omp ) ) { - const std::string ¬e_text = overmap_buffer.note( omx, omy, g->get_levz() ); + const std::string ¬e_text = overmap_buffer.note( omp ); ter_color = c_yellow; ter_sym = "N"; @@ -318,15 +317,15 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const ter_color = c_cyan; ter_sym = "c"; } else { - const oter_id &cur_ter = overmap_buffer.ter( omx, omy, g->get_levz() ); + const oter_id &cur_ter = overmap_buffer.ter( omp ); ter_sym = cur_ter->get_symbol(); - if( overmap_buffer.is_explored( omx, omy, g->get_levz() ) ) { + if( overmap_buffer.is_explored( omp ) ) { ter_color = c_dark_gray; } else { ter_color = cur_ter->get_color(); } } - if( !drew_mission && targ.x == omx && targ.y == omy ) { + if( !drew_mission && targ.xy() == omp.xy() ) { // If there is a mission target, and it's not on the same // overmap terrain as the player character, mark it. // TODO: Inform player if the mission is above or below @@ -393,16 +392,13 @@ void overmap_ui::draw_overmap_chunk( const catacurses::window &w_minimap, const if( i > -3 && i < 3 && j > -3 && j < 3 ) { continue; // only do hordes on the border, skip inner map } - const int omx = cursx + i; - const int omy = cursy + j; - if( overmap_buffer.get_horde_size( omx, omy, g->get_levz() ) >= HORDE_VISIBILITY_SIZE ) { - const tripoint cur_pos{ - omx, omy, g->get_levz() - }; - if( overmap_buffer.seen( omx, omy, g->get_levz() ) - && g->u.overmap_los( cur_pos, sight_points ) ) { + const tripoint omp( cursx + i, cursy + j, g->get_levz() ); + int horde_size = overmap_buffer.get_horde_size( omp ); + if( horde_size >= HORDE_VISIBILITY_SIZE ) { + if( overmap_buffer.seen( omp ) + && g->u.overmap_los( omp, sight_points ) ) { mvwputch( w_minimap, j + 3, i + 3, c_green, - overmap_buffer.get_horde_size( omx, omy, g->get_levz() ) > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' ); + horde_size > HORDE_VISIBILITY_SIZE * 2 ? 'Z' : 'z' ); } } } diff --git a/src/savegame.cpp b/src/savegame.cpp index 59042e8dd38a8..bed882461a8ac 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -957,9 +957,9 @@ void overmap::unserialize( std::istream &fin ) if( tracker_member_name == "id" ) { jsin.read( id ); } else if( tracker_member_name == "x" ) { - jsin.read( new_tracker.x ); + jsin.read( new_tracker.p.x ); } else if( tracker_member_name == "y" ) { - jsin.read( new_tracker.y ); + jsin.read( new_tracker.p.y ); } else if( tracker_member_name == "name" ) { jsin.read( new_tracker.name ); } @@ -1388,8 +1388,8 @@ void overmap::serialize( std::ostream &fout ) const json.start_object(); json.member( "id", i.first ); json.member( "name", i.second.name ); - json.member( "x", i.second.x ); - json.member( "y", i.second.y ); + json.member( "x", i.second.p.x ); + json.member( "y", i.second.p.y ); json.end_object(); } json.end_array(); diff --git a/src/savegame_legacy.cpp b/src/savegame_legacy.cpp index 98954ac99acdc..b6f3893739d59 100644 --- a/src/savegame_legacy.cpp +++ b/src/savegame_legacy.cpp @@ -433,7 +433,7 @@ void overmap::unserialize_legacy( std::istream &fin ) } else if( datatype == 'v' ) { om_vehicle v; int id; - fin >> id >> v.name >> v.x >> v.y; + fin >> id >> v.name >> v.p.x >> v.p.y; vehicles[id] = v; } else if( datatype == 'n' ) { // NPC // When we start loading a new NPC, check to see if we've accumulated items for diff --git a/src/start_location.cpp b/src/start_location.cpp index 96b47addc57a6..87a63fbf1f87d 100644 --- a/src/start_location.cpp +++ b/src/start_location.cpp @@ -214,7 +214,7 @@ tripoint start_location::find_player_initial_location() const // creating overmaps as necessary. const int radius = 3; for( const point &omp : closest_points_first( radius, point_zero ) ) { - overmap &omap = overmap_buffer.get( omp.x, omp.y ); + overmap &omap = overmap_buffer.get( omp ); const tripoint omtstart = omap.find_random_omt( target() ); if( omtstart != overmap::invalid_tripoint ) { return omtstart + point( omp.x * OMAPX, omp.y * OMAPY ); diff --git a/src/tutorial.cpp b/src/tutorial.cpp index a0e863783a926..527442c41ac8c 100644 --- a/src/tutorial.cpp +++ b/src/tutorial.cpp @@ -66,7 +66,7 @@ bool tutorial_game::init() // overmap terrain coordinates const int lx = 50; const int ly = 50; - auto &starting_om = overmap_buffer.get( 0, 0 ); + auto &starting_om = overmap_buffer.get( point_zero ); for( int i = 0; i < OMAPX; i++ ) { for( int j = 0; j < OMAPY; j++ ) { starting_om.ter( i, j, -1 ) = rock; diff --git a/tests/npc_talk_test.cpp b/tests/npc_talk_test.cpp index 2ea8e2f58e8f2..b49c4935f2450 100644 --- a/tests/npc_talk_test.cpp +++ b/tests/npc_talk_test.cpp @@ -75,8 +75,8 @@ static void gen_response_lines( dialogue &d, size_t expected_count ) static void change_om_type( const std::string &new_type ) { - const point omt_pos = ms_to_omt_copy( g->m.getabs( g->u.posx(), g->u.posy() ) ); - oter_id &omt_ref = overmap_buffer.ter( omt_pos.x, omt_pos.y, g->u.posz() ); + const tripoint omt_pos = ms_to_omt_copy( g->m.getabs( g->u.pos() ) ); + oter_id &omt_ref = overmap_buffer.ter( omt_pos ); omt_ref = oter_id( new_type ); } diff --git a/tests/overmap_test.cpp b/tests/overmap_test.cpp index d54d31901ea93..a0f9b0524a7a0 100644 --- a/tests/overmap_test.cpp +++ b/tests/overmap_test.cpp @@ -38,11 +38,11 @@ TEST_CASE( "default_overmap_generation_always_succeeds" ) int overmaps_to_construct = 10; for( point candidate_addr : closest_points_first( 10, { 0, 0 } ) ) { // Skip populated overmaps. - if( overmap_buffer.has( candidate_addr.x, candidate_addr.y ) ) { + if( overmap_buffer.has( candidate_addr ) ) { continue; } overmap_special_batch test_specials = overmap_specials::get_default_batch( candidate_addr ); - overmap_buffer.create_custom_overmap( candidate_addr.x, candidate_addr.y, test_specials ); + overmap_buffer.create_custom_overmap( candidate_addr, test_specials ); for( const auto &special_placement : test_specials ) { auto special = special_placement.special_details; INFO( "In attempt #" << overmaps_to_construct @@ -84,10 +84,10 @@ TEST_CASE( "default_overmap_generation_has_non_mandatory_specials_at_origin" ) overmap_special_batch test_specials = overmap_special_batch( origin, specials ); // Run the overmap creation, which will try to place our specials. - overmap_buffer.create_custom_overmap( origin.x, origin.y, test_specials ); + overmap_buffer.create_custom_overmap( origin, test_specials ); // Get the origin overmap... - overmap *test_overmap = overmap_buffer.get_existing( origin.x, origin.y ); + overmap *test_overmap = overmap_buffer.get_existing( origin ); // ...and assert that the optional special exists on this map. bool found_optional = false; diff --git a/tests/test_main.cpp b/tests/test_main.cpp index fac9ea7e31ac3..38f3be29485a1 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -149,7 +149,7 @@ static void init_global_game_state( const std::vector &mods, g->m = map( get_option( "ZLEVELS" ) ); overmap_special_batch empty_specials( { 0, 0 } ); - overmap_buffer.create_custom_overmap( 0, 0, empty_specials ); + overmap_buffer.create_custom_overmap( point_zero, empty_specials ); g->m.load( g->get_levx(), g->get_levy(), g->get_levz(), false ); }