Skip to content

Commit

Permalink
Add constructor for mapgendata to avoid repeating that piece of code.
Browse files Browse the repository at this point in the history
  • Loading branch information
BevapDin committed Sep 23, 2019
1 parent 874d420 commit e278503
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 28 deletions.
15 changes: 1 addition & 14 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2728,21 +2728,8 @@ void apply_function( const string_id<map_extra> &id, map &m, const tripoint &abs
case map_extra_method::mapgen: {
tripoint over( abs_sub );
sm_to_omt( over );
const regional_settings *rsettings = &overmap_buffer.get_settings( over );
const oter_id terrain_type = overmap_buffer.ter( over );
const oter_id t_above = overmap_buffer.ter( over + tripoint_above );
const oter_id t_below = overmap_buffer.ter( over + tripoint_below );
const oter_id t_north = overmap_buffer.ter( over + tripoint_north );
const oter_id t_north_east = overmap_buffer.ter( over + tripoint_north_east );
const oter_id t_east = overmap_buffer.ter( over + tripoint_east );
const oter_id t_south_east = overmap_buffer.ter( over + tripoint_south_east );
const oter_id t_south = overmap_buffer.ter( over + tripoint_south );
const oter_id t_south_west = overmap_buffer.ter( over + tripoint_south_west );
const oter_id t_west = overmap_buffer.ter( over + tripoint_west );
const oter_id t_north_west = overmap_buffer.ter( over + tripoint_north_west );
mapgendata dat( t_north, t_east, t_south, t_west,
t_north_east, t_south_east, t_south_west, t_north_west,
t_above, t_below, over.z, *rsettings, m );
mapgendata dat( over, m );
run_mapgen_func( extra.generator_id, &m, terrain_type, dat, calendar::turn, 0 );
break;
}
Expand Down
17 changes: 3 additions & 14 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7949,27 +7949,16 @@ bool update_mapgen_function_json::update_map( const tripoint &omt_pos, const poi
mission *miss, bool verify ) const
{
tinymap update_tmap;
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_north );
oter_id south = overmap_buffer.ter( omt_pos + tripoint_south );
oter_id east = overmap_buffer.ter( omt_pos + tripoint_east );
oter_id west = overmap_buffer.ter( omt_pos + tripoint_west );
oter_id northeast = overmap_buffer.ter( omt_pos + tripoint_north_east );
oter_id southeast = overmap_buffer.ter( omt_pos + tripoint_south_east );
oter_id northwest = overmap_buffer.ter( omt_pos + tripoint_north_west );
oter_id southwest = overmap_buffer.ter( omt_pos + tripoint_south_west );
oter_id above = overmap_buffer.ter( omt_pos + tripoint_above );
oter_id below = overmap_buffer.ter( omt_pos + tripoint_below );

mapgendata md( north, south, east, west, northeast, southeast, northwest, southwest,
above, below, omt_pos.z, rsettings, update_tmap );

mapgendata md( omt_pos, update_tmap );

// If the existing map is rotated, we need to rotate it back to the north
// orientation before applying our updates.
int rotation = 0;
// Yeah, because a terrain named "tt_east" (length 7) is clearly not rotated and does not to be checked.
if( map_id.size() > 7 ) {
if( map_id.substr( map_id.size() - 6, 6 ) == "_south" ) {
rotation = 2;
Expand Down
11 changes: 11 additions & 0 deletions src/mapgendata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "regional_settings.h"
#include "map.h"
#include "overmapbuffer.h"

mapgendata::mapgendata( oter_id north, oter_id east, oter_id south, oter_id west,
oter_id northeast, oter_id southeast, oter_id southwest, oter_id northwest,
Expand All @@ -16,6 +17,16 @@ mapgendata::mapgendata( oter_id north, oter_id east, oter_id south, oter_id west
{
}

mapgendata::mapgendata( const tripoint &over, map &m )
: mapgendata( overmap_buffer.ter( over + tripoint_north ),
overmap_buffer.ter( over + tripoint_east ), overmap_buffer.ter( over + tripoint_south ),
overmap_buffer.ter( over + tripoint_west ), overmap_buffer.ter( over + tripoint_north_east ),
overmap_buffer.ter( over + tripoint_south_east ), overmap_buffer.ter( over + tripoint_south_west ),
overmap_buffer.ter( over + tripoint_north_west ), overmap_buffer.ter( over + tripoint_above ),
overmap_buffer.ter( over + tripoint_below ), over.z, overmap_buffer.get_settings( over ), m )
{
}

void mapgendata::set_dir( int dir_in, int val )
{
switch( dir_in ) {
Expand Down
2 changes: 2 additions & 0 deletions src/mapgendata.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class mapgendata
oter_id northeast, oter_id southeast, oter_id southwest, oter_id northwest,
oter_id up, oter_id down, int z, const regional_settings &rsettings, map &mp );

mapgendata( const tripoint &over, map &m );

void set_dir( int dir_in, int val );
void fill( int val );
int &dir( int dir_in );
Expand Down

0 comments on commit e278503

Please sign in to comment.