Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overmapbuffer function refactoring #32300

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
}
Expand All @@ -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 );
}
}
}
Expand All @@ -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.
Expand Down Expand Up @@ -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." ),
Expand Down
2 changes: 1 addition & 1 deletion src/defense.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
2 changes: 1 addition & 1 deletion src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
10 changes: 5 additions & 5 deletions src/explosion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ int npc::faction_display( const catacurses::window &fac_w, const int width ) con
cata::optional<tripoint> dest = get_mission_destination();
if( dest ) {
basecamp *dest_camp;
cata::optional<basecamp *> temp_camp = overmap_buffer.find_camp( dest->x, dest->y );
cata::optional<basecamp *> temp_camp = overmap_buffer.find_camp( dest->xy() );
if( temp_camp ) {
dest_camp = *temp_camp;
dest_string = _( "travelling to : " ) + dest_camp->camp_name();
Expand All @@ -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<basecamp *> p = overmap_buffer.find_camp( guy_abspos.x, guy_abspos.y );
cata::optional<basecamp *> p = overmap_buffer.find_camp( guy_abspos.xy() );
if( p ) {
is_stationed = true;
stationed_at = *p;
Expand Down Expand Up @@ -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<basecamp *> player_camp = overmap_buffer.find_camp( g->u.global_omt_location().x,
g->u.global_omt_location().y );
cata::optional<basecamp *> player_camp =
overmap_buffer.find_camp( g->u.global_omt_location().xy() );
if( const cata::optional<basecamp *> 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;
}
Expand Down Expand Up @@ -607,7 +607,7 @@ void new_faction_manager::display() const
// create a list of faction camps
std::vector<basecamp *> camps;
for( auto elem : g->u.camps ) {
cata::optional<basecamp *> p = overmap_buffer.find_camp( elem.x, elem.y );
cata::optional<basecamp *> p = overmap_buffer.find_camp( elem.xy() );
if( !p ) {
continue;
}
Expand Down
8 changes: 4 additions & 4 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ static cata::optional<basecamp *> get_basecamp( npc &p, const std::string &camp_
{

tripoint omt_pos = p.global_omt_location();
cata::optional<basecamp *> bcp = overmap_buffer.find_camp( omt_pos.x, omt_pos.y );
cata::optional<basecamp *> 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;
}
Expand Down Expand Up @@ -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<basecamp *> temp_camp = overmap_buffer.find_camp( omt_pos.x, omt_pos.y );
cata::optional<basecamp *> temp_camp = overmap_buffer.find_camp( omt_pos.xy() );
if( !temp_camp ) {
return cur_title;
}
Expand Down Expand Up @@ -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." ) );
}
Expand Down
61 changes: 33 additions & 28 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &note_text = overmap_buffer.note( omx, omy, get_levz() );
const std::string &note_text = overmap_buffer.note( omp );

ter_color = c_yellow;
ter_sym = "N";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' );
}
}
}
Expand Down Expand Up @@ -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" ) ) );
}
}
}
Expand Down Expand 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<float>( std::abs( dx ),
std::abs( dy ) ) : 1;
const std::vector<point> line = line_to( ompos.x, ompos.y, x, y, 0 );
const std::vector<tripoint> 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<int>( 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 );
}
}
}
Expand Down Expand Up @@ -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<npc *> game::allies()
Expand Down
3 changes: 1 addition & 2 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<basecamp *> bcp = overmap_buffer.find_camp( omt_tri.x, omt_tri.y );
cata::optional<basecamp *> bcp = overmap_buffer.find_camp( omt );
if( bcp ) {
basecamp *temp_camp = *bcp;
temp_camp->validate_assignees();
Expand Down
Loading