Skip to content

Commit

Permalink
Check mx ids defined for region (cataclysmbnteam#3303)
Browse files Browse the repository at this point in the history
* data: check mx ids defined for region

* Fully implement string_id<map_extra>

* Remove references to non-existent map extras
  • Loading branch information
olanti-p authored Sep 30, 2023
1 parent 1fbcf35 commit c36bcee
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 0 additions & 2 deletions data/mods/DinoMod/regional_overlay.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
"forest_water": {
"chance": 20,
"extras": {
"mx_mass_grave_dino": 30,
"mx_nest_acrocanthosaurus": 30,
"mx_nest_albertosaurus": 30,
"mx_nest_allosaurus": 30,
"mx_nest_ceratosaurus": 30,
"mx_nest_daspletosaurus": 30,
"mx_nest_deinonychus": 30,
"mx_nest_dilophosaurus": 30,
"mx_nest_dromaeosaurus": 30,
Expand Down
3 changes: 0 additions & 3 deletions data/mods/No_Hope/regional_map_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@
}
},
"bridgehead_ground": { "chance": 5, "extras": { "mx_minefield": 100 } },
"road_nesw_manhole": { "chance": 20, "extras": { "mx_city_trap": 100 } },
"build": {
"chance": 90,
"extras": {
Expand Down Expand Up @@ -572,8 +571,6 @@
"mx_casings": 30
}
},
"river": { "chance": 3, "extras": { "mx_reed": 100 } },
"lake_shore": { "chance": 2, "extras": { "mx_reed": 100 } },
"sewer": {
"chance": 1,
"extras": {
Expand Down
1 change: 1 addition & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ void DynamicDataLoader::check_consistency( loading_ui &ui )
{ _( "Overmap specials" ), &overmap_specials::check_consistency },
{ _( "Map extras" ), &MapExtras::check_consistency },
{ _( "Start locations" ), &start_locations::check_consistency },
{ _( "Regional settings" ), &check_regional_settings },
{ _( "Ammunition types" ), &ammunition_type::check_consistency },
{ _( "Traps" ), &trap::check_consistency },
{ _( "Bionics" ), &bionic_data::check_consistency },
Expand Down
8 changes: 2 additions & 6 deletions src/map_extras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "translations.h"
#include "trap.h"
#include "type_id.h"
#include "type_id_implement.h"
#include "ui.h"
#include "units.h"
#include "veh_type.h"
Expand Down Expand Up @@ -185,12 +186,7 @@ generic_factory<map_extra> extras( "map extra" );

} // namespace

/** @relates string_id */
template<>
const map_extra &string_id<map_extra>::obj() const
{
return extras.obj( *this );
}
IMPLEMENT_STRING_ID( map_extra, extras )

namespace MapExtras
{
Expand Down
23 changes: 23 additions & 0 deletions src/regional_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
#include <string>
#include <utility>

#include "consistency_report.h"
#include "debug.h"
#include "enum_conversions.h"
#include "int_id.h"
#include "json.h"
#include "map_extras.h"
#include "options.h"
#include "overmap_special.h"
#include "rng.h"
#include "string_formatter.h"
#include "string_id.h"
#include "translations.h"

ter_furn_id::ter_furn_id() : ter( t_null ), furn( f_null ) { }
Expand Down Expand Up @@ -1093,3 +1096,23 @@ void building_bin::finalize()

finalized = true;
}

void check_regional_settings()
{
for( auto const& [region_id, region] : region_settings_map ) {
consistency_report rep;

for( auto const& [extras_group, extras] : region.region_extras ) {
for( auto const& [extra_id, extra_weight] : extras.values ) {
string_id<map_extra> id( extra_id );
if( !id.is_valid() ) {
rep.warn( "defines unknown map extra '%s'", id );
}
}
}

if( !rep.is_empty() ) {
debugmsg( rep.format( "region_settings", region_id ) );
}
}
}
2 changes: 2 additions & 0 deletions src/regional_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ using t_regional_settings_map = std::unordered_map<std::string, regional_setting
using t_regional_settings_map_citr = t_regional_settings_map::const_iterator;
extern t_regional_settings_map region_settings_map;

void check_regional_settings();

void load_region_settings( const JsonObject &jo );
void reset_region_settings();
void load_region_overlay( const JsonObject &jo );
Expand Down

0 comments on commit c36bcee

Please sign in to comment.