Skip to content

Commit

Permalink
Backporting CleverRaven#49396 Fix classic zombies map extras chance v…
Browse files Browse the repository at this point in the history
…alues which could cause debugmsg
  • Loading branch information
ZhilkinSerg committed Aug 14, 2021
1 parent 7525457 commit 87e68db
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 7 deletions.
14 changes: 7 additions & 7 deletions data/mods/classic_zombies/exclusions.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"type": "region_overlay",
"regions": [ "all" ],
"map_extras": {
"forest": { "chance": 20, "extras": { "mx_portal": 0, "mx_portal_in": 0, "mx_spider": 0 } },
"forest_thick": { "chance": 20, "extras": { "mx_portal": 0, "mx_portal_in": 0, "mx_shia": 0, "mx_spider": 0, "mx_jabberwock": 0 } },
"forest_water": { "chance": 20, "extras": { "mx_portal": 0, "mx_portal_in": 0, "mx_spider": 0 } },
"field": { "chance": 90, "extras": { "mx_portal": 0, "mx_portal_in": 0 } },
"road": { "chance": 75, "extras": { "mx_portal": 0, "mx_portal_in": 0 } },
"build": { "chance": 90, "extras": { "mx_house_spider": 0, "mx_house_wasp": 0, "mx_portal": 0, "mx_portal_in": 0 } },
"forest": { "extras": { "mx_portal": 0, "mx_portal_in": 0, "mx_spider": 0 } },
"forest_thick": { "extras": { "mx_portal": 0, "mx_portal_in": 0, "mx_shia": 0, "mx_spider": 0, "mx_jabberwock": 0 } },
"forest_water": { "extras": { "mx_portal": 0, "mx_portal_in": 0, "mx_spider": 0 } },
"field": { "extras": { "mx_portal": 0, "mx_portal_in": 0 } },
"road": { "extras": { "mx_portal": 0, "mx_portal_in": 0 } },
"build": { "extras": { "mx_house_spider": 0, "mx_house_wasp": 0, "mx_portal": 0, "mx_portal_in": 0 } },
"marloss": { "chance": 0, "extras": { "mx_marloss_pilgrimage": 0 } },
"subway": { "chance": 75, "extras": { "mx_portal": 0, "mx_portal_in": 0 } }
"subway": { "extras": { "mx_portal": 0, "mx_portal_in": 0 } }
}
}
]
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ void DynamicDataLoader::check_consistency( loading_ui &ui )
{ _( "Martial arts" ), &check_martialarts },
{ _( "Mutations" ), &mutation_branch::check_consistency },
{ _( "Mutation Categories" ), &mutation_category_trait::check_consistency },
{ _( "Region settings" ), check_region_settings },
{ _( "Overmap land use codes" ), &overmap_land_use_codes::check_consistency },
{ _( "Overmap connections" ), &overmap_connections::check_consistency },
{ _( "Overmap terrain" ), &overmap_terrains::check_consistency },
Expand Down
34 changes: 34 additions & 0 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "enum_conversions.h"
#include "json.h"
#include "options.h"
#include "output.h"
#include "rng.h"
#include "string_formatter.h"
#include "translations.h"
Expand Down Expand Up @@ -595,6 +596,39 @@ void load_region_settings( const JsonObject &jo )
region_settings_map[new_region.id] = new_region;
}

void check_region_settings()
{
for( const std::pair<const std::string, regional_settings> &p : region_settings_map ) {
const std::string &region_name = p.first;
const regional_settings &region = p.second;
for( const std::pair<const std::string, map_extras> &p2 : region.region_extras ) {
const std::string extras_name = p.first;
const map_extras &extras = p2.second;
if( extras.chance == 0 ) {
continue;
}
const weighted_int_list<std::string> &values = extras.values;
if( !values.is_valid() ) {
if( values.empty() ) {
debugmsg( "Invalid map extras for region \"%s\", extras \"%s\". "
"Extras have nonzero chance but no extras are listed.",
region_name, extras_name );
} else {
std::string list_of_values =
enumerate_as_string( values,
[]( const weighted_object<int, std::string> &w ) {
return '"' + w.obj + '"';
} );
debugmsg( "Invalid map extras for region \"%s\", extras \"%s\". "
"Extras %s are listed, but all have zero weight.",
region_name, extras_name,
list_of_values );
}
}
}
}
}

void reset_region_settings()
{
region_settings_map.clear();
Expand Down
1 change: 1 addition & 0 deletions src/regional_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ using t_regional_settings_map_citr = t_regional_settings_map::const_iterator;
extern t_regional_settings_map region_settings_map;

void load_region_settings( const JsonObject &jo );
void check_region_settings();
void reset_region_settings();
void load_region_overlay( const JsonObject &jo );
void apply_region_overlay( const JsonObject &jo, regional_settings &region );
Expand Down
4 changes: 4 additions & 0 deletions src/weighted_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ template <typename W, typename T> struct weighted_list {
return total_weight;
}

bool is_valid() const {
return get_weight() > 0;
}

typename std::vector<weighted_object<W, T> >::iterator begin() {
return objects.begin();
}
Expand Down

0 comments on commit 87e68db

Please sign in to comment.