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

Add tracking of overmap special for placed terrain #27074

Merged
Changes from 1 commit
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
Next Next commit
Add tracking of overmap special for placed terrain
  • Loading branch information
ralreegorganon committed Dec 14, 2018
commit b2c2c8269bf2461f7b600aaf4eb35985f0c5ccd5
1 change: 1 addition & 0 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
@@ -3286,6 +3286,7 @@ void overmap::place_special( const overmap_special &special, const tripoint &p,
const tripoint location = p + om_direction::rotate( elem.p, dir );
const oter_id tid = elem.terrain->get_rotated( dir );

overmap_special_placements[location] = special.id;
ter( location.x, location.y, location.z ) = tid;

if( blob ) {
5 changes: 5 additions & 0 deletions src/overmap.h
Original file line number Diff line number Diff line change
@@ -265,6 +265,11 @@ class overmap
std::array<map_layer, OVERMAP_LAYERS> layer;
std::unordered_map<tripoint, scent_trace> scents;

// Records the locations where a given overmap special was placed, which
// can be used after placement to lookup whether a given location was created
// as part of a special.
std::unordered_map<tripoint, overmap_special_id> overmap_special_placements;

regional_settings settings;

oter_id get_default_terrain( int z ) const;
69 changes: 69 additions & 0 deletions src/savegame.cpp
Original file line number Diff line number Diff line change
@@ -971,10 +971,46 @@ void overmap::unserialize( std::istream &fin )
}
npcs.push_back( new_npc );
}
} else if( name == "overmap_special_placements" ) {
jsin.start_array();
while( !jsin.end_array() ) {
jsin.start_object();
overmap_special_id s;
while( !jsin.end_object() ) {
std::string name = jsin.get_member_name();
if( name == "special" ) {
jsin.read( s );
} else if( name == "placements" ) {
jsin.start_array();
while( !jsin.end_array() ) {
jsin.start_object();
while( !jsin.end_object() ) {
std::string name = jsin.get_member_name();
if( name == "points" ) {
jsin.start_array();
while( !jsin.end_array() ) {
jsin.start_object();
tripoint p;
while( !jsin.end_object() ) {
std::string name = jsin.get_member_name();
if( name == "p" ) {
jsin.read( p );
overmap_special_placements[p] = s;
}
}
}
}
}
}
}
}
}
}
}
}



static void unserialize_array_from_compacted_sequence( JsonIn &jsin, bool ( &array )[OMAPX][OMAPY] )
{
int count = 0;
@@ -1316,6 +1352,39 @@ void overmap::serialize( std::ostream &fout ) const
json.end_array();
fout << std::endl;

// Condense the overmap special placements so that all placements of a given special
// are grouped under a single key for that special.
std::map<overmap_special_id, std::vector<tripoint>> condensed_overmap_special_placements;
for( const auto &placement : overmap_special_placements ) {
condensed_overmap_special_placements[placement.second].emplace_back( placement.first );
}

json.member( "overmap_special_placements" );
json.start_array();
for( const auto &placement : condensed_overmap_special_placements ) {
json.start_object();
json.member( "special", placement.first );
json.member( "placements" );
json.start_array();
// When we have a discriminator for different instances of a given special,
// we'd use that that group them, but since that doesn't exist yet we'll
// dump all the points of a given special into a single entry.
json.start_object();
json.member( "points" );
json.start_array();
for( const tripoint &pos : placement.second ) {
json.start_object();
json.member( "p", pos );
json.end_object();
}
json.end_array();
json.end_object();
json.end_array();
json.end_object();
}
json.end_array();
fout << std::endl;

json.end_object();
fout << std::endl;
}