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

Fix mysterious creation of submap (0,0,-9). #36582

Merged
merged 3 commits into from
Dec 31, 2019
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
37 changes: 11 additions & 26 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7332,44 +7332,29 @@ bool tinymap::inbounds( const tripoint &p ) const

// set up a map just long enough scribble on it
// this tinymap should never, ever get saved
bool tinymap::fake_load( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type,
int fake_map_z )
fake_map::fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type,
const int fake_map_z )
{
const tripoint tripoint_below_zero( 0, 0, fake_map_z );

bool do_terset = true;
set_abs_sub( tripoint_below_zero );
for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) {
for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) {
const tripoint gridp( gridx, gridy, fake_map_z );
submap *tmpsub = MAPBUFFER.lookup_submap( gridp );
if( tmpsub == nullptr ) {
generate_uniform( gridp, ter_type );
do_terset = false;
tmpsub = MAPBUFFER.lookup_submap( gridp );
if( tmpsub == nullptr ) {
dbg( D_ERROR ) << "failed to generate a fake submap at 0,0,-9 ";
debugmsg( "failed to generate a fake submap at 0,0,-9" );
return false;
}
}
const size_t gridn = get_nonant( gridp );
std::unique_ptr<submap> sm = std::make_unique<submap>();

setsubmap( gridn, tmpsub );
}
}
std::uninitialized_fill_n( &sm->ter[0][0], SEEX * SEEY, ter_type );
std::uninitialized_fill_n( &sm->frn[0][0], SEEX * SEEY, fur_type );
std::uninitialized_fill_n( &sm->trp[0][0], SEEX * SEEY, trap_type );

setsubmap( get_nonant( { gridx, gridy, fake_map_z } ), sm.get() );

for( const tripoint &pos : points_in_rectangle( tripoint_below_zero,
tripoint( MAPSIZE * SEEX, MAPSIZE * SEEY, fake_map_z ) ) ) {
if( do_terset ) {
ter_set( pos, ter_type );
temp_submaps_.emplace_back( std::move( sm ) );
}
furn_set( pos, fur_type );
trap_set( pos, trap_type );
}
return true;
}

fake_map::~fake_map() = default;

void map::set_graffiti( const tripoint &p, const std::string &contents )
{
if( !inbounds( p ) ) {
Expand Down
11 changes: 9 additions & 2 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1834,8 +1834,15 @@ class tinymap : public map
public:
tinymap( int mapsize = 2, bool zlevels = false );
bool inbounds( const tripoint &p ) const override;
bool fake_load( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type,
int fake_map_z );
};

class fake_map : public tinymap
{
private:
std::vector<std::unique_ptr<submap>> temp_submaps_;
public:
fake_map( const furn_id &fur_type, const ter_id &ter_type, const trap_id &trap_type,
int fake_map_z );
~fake_map();
};
#endif
17 changes: 3 additions & 14 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7272,8 +7272,6 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_up
const std::string &update_mapgen_id )
{
const int fake_map_z = -9;
const tripoint tripoint_below_zero( 0, 0, fake_map_z );
const tripoint tripoint_fake_map_edge( 23, 23, fake_map_z );

std::map<ter_id, int> terrains;
std::map<furn_id, int> furnitures;
Expand All @@ -7284,10 +7282,8 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_up
return std::make_pair( terrains, furnitures );
}

tinymap fake_map;
if( !fake_map.fake_load( f_null, t_dirt, tr_null, fake_map_z ) ) {
return std::make_pair( terrains, furnitures );
}
::fake_map fake_map( f_null, t_dirt, tr_null, fake_map_z );

oter_id any = oter_id( "field" );
// just need a variable here, it doesn't need to be valid
const regional_settings dummy_settings;
Expand All @@ -7296,20 +7292,13 @@ std::pair<std::map<ter_id, int>, std::map<furn_id, int>> get_changed_ids_from_up
any, any, 0, dummy_settings, fake_map, any, 0.0f, calendar::turn, nullptr );

if( update_function->second[0]->update_map( fake_md ) ) {
for( const tripoint &pos : fake_map.points_in_rectangle( tripoint_below_zero,
tripoint_fake_map_edge ) ) {
for( const tripoint &pos : fake_map.points_on_zlevel( fake_map_z ) ) {
ter_id ter_at_pos = fake_map.ter( pos );
if( ter_at_pos != t_dirt ) {
if( terrains.find( ter_at_pos ) == terrains.end() ) {
terrains[ter_at_pos] = 0;
}
terrains[ter_at_pos] += 1;
}
if( fake_map.has_furn( pos ) ) {
furn_id furn_at_pos = fake_map.furn( pos );
if( furnitures.find( furn_at_pos ) == furnitures.end() ) {
furnitures[furn_at_pos] = 0;
}
furnitures[furn_at_pos] += 1;
}
}
Expand Down