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
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: 16 additions & 0 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2988,6 +2988,21 @@ bool overmap::check_ot_subtype( const std::string &otype, int x, int y, int z )
return is_ot_subtype( otype.c_str(), oter );
}

bool overmap::check_overmap_special_type( const overmap_special_id &id,
const tripoint &location ) const
{
// Try and find the special associated with this location.
auto found_id = overmap_special_placements.find( location );

// There was no special here, so bail.
if( found_id == overmap_special_placements.end() ) {
return false;
}

// Return whether the found special was a match with our requested id.
return found_id->second == id;
}

void overmap::good_river( int x, int y, int z )
{
if( !is_ot_type( "river", get_ter( x, y, z ) ) ) {
Expand Down Expand Up @@ -3286,6 +3301,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 ) {
Expand Down
6 changes: 6 additions & 0 deletions src/overmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -346,6 +351,7 @@ class overmap
// Polishing
bool check_ot_type( const std::string &otype, int x, int y, int z ) const;
bool check_ot_subtype( const std::string &otype, int x, int y, int z ) const;
bool check_overmap_special_type( const overmap_special_id &id, const tripoint &location ) const;
void chip_rock( int x, int y, int z );

void polish_river();
Expand Down
69 changes: 69 additions & 0 deletions src/savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down