26
26
class mapgendata ;
27
27
28
28
static const weighted_string_id_reader<overmap_special_id, int > building_bin_reader ( 1 );
29
+ static const weighted_string_id_reader<furn_id, int > furn_reader ( 1 );
30
+ static const weighted_string_id_reader<ter_id, int > ter_reader ( 1 );
31
+
29
32
/* * SETTING FACTORY */
30
33
namespace
31
34
{
@@ -38,6 +41,11 @@ generic_factory<region_settings_highway>
38
41
region_settings_highway_factory ( " region_settings_highway" );
39
42
generic_factory<region_settings_forest_trail>
40
43
region_settings_forest_trail_factory ( " region_settings_forest_trail" );
44
+ generic_factory<region_settings_city> region_settings_city_factory ( " region_settings_city" );
45
+ generic_factory<region_settings_terrain_furniture>
46
+ region_settings_terrain_furniture_factory ( " region_settings_terrain_furniture" );
47
+ generic_factory<region_terrain_furniture>
48
+ region_terrain_furniture_factory ( " region_terrain_furniture" );
41
49
} // namespace
42
50
43
51
/* * OBJ */
@@ -76,6 +84,21 @@ const region_settings_forest_trail &string_id<region_settings_forest_trail>::obj
76
84
{
77
85
return region_settings_forest_trail_factory.obj ( *this );
78
86
}
87
+ template <>
88
+ const region_settings_city &string_id<region_settings_city>::obj() const
89
+ {
90
+ return region_settings_city_factory.obj ( *this );
91
+ }
92
+ template <>
93
+ const region_settings_terrain_furniture &string_id<region_settings_terrain_furniture>::obj() const
94
+ {
95
+ return region_settings_terrain_furniture_factory.obj ( *this );
96
+ }
97
+ template <>
98
+ const region_terrain_furniture &string_id<region_terrain_furniture>::obj() const
99
+ {
100
+ return region_terrain_furniture_factory.obj ( *this );
101
+ }
79
102
80
103
/* * IS_VALID */
81
104
template <>
@@ -113,6 +136,21 @@ bool string_id<region_settings_forest_trail>::is_valid() const
113
136
{
114
137
return region_settings_forest_trail_factory.is_valid ( *this );
115
138
}
139
+ template <>
140
+ bool string_id<region_settings_city>::is_valid() const
141
+ {
142
+ return region_settings_city_factory.is_valid ( *this );
143
+ }
144
+ template <>
145
+ bool string_id<region_settings_terrain_furniture>::is_valid() const
146
+ {
147
+ return region_settings_terrain_furniture_factory.is_valid ( *this );
148
+ }
149
+ template <>
150
+ bool string_id<region_terrain_furniture>::is_valid() const
151
+ {
152
+ return region_terrain_furniture_factory.is_valid ( *this );
153
+ }
116
154
/* * INIT LOAD */
117
155
void region_settings_river::load_region_settings_river ( const JsonObject &jo,
118
156
const std::string &src )
@@ -148,6 +186,22 @@ void region_settings_forest_trail::load_region_settings_forest_trail( const Json
148
186
{
149
187
region_settings_forest_trail_factory.load ( jo, src );
150
188
}
189
+ void region_settings_city::load_region_settings_city ( const JsonObject &jo,
190
+ const std::string &src )
191
+ {
192
+ region_settings_city_factory.load ( jo, src );
193
+ }
194
+ void region_settings_terrain_furniture::load_region_settings_terrain_furniture (
195
+ const JsonObject &jo,
196
+ const std::string &src )
197
+ {
198
+ region_settings_terrain_furniture_factory.load ( jo, src );
199
+ }
200
+ void region_terrain_furniture::load_region_terrain_furniture ( const JsonObject &jo,
201
+ const std::string &src )
202
+ {
203
+ region_terrain_furniture_factory.load ( jo, src );
204
+ }
151
205
152
206
/* * UNLOAD (RESET) */
153
207
void region_settings_river::reset ()
@@ -178,6 +232,18 @@ void region_settings_forest_trail::reset()
178
232
{
179
233
region_settings_forest_trail_factory.reset ();
180
234
}
235
+ void region_settings_city::reset ()
236
+ {
237
+ region_settings_city_factory.reset ();
238
+ }
239
+ void region_settings_terrain_furniture::reset ()
240
+ {
241
+ region_settings_terrain_furniture_factory.reset ();
242
+ }
243
+ void region_terrain_furniture::reset ()
244
+ {
245
+ region_terrain_furniture_factory.reset ();
246
+ }
181
247
182
248
template <typename T>
183
249
void read_and_set_or_throw ( const JsonObject &jo, const std::string &member, T &target,
@@ -458,6 +524,24 @@ static void load_overmap_feature_flag_settings( const JsonObject &jo,
458
524
}
459
525
}
460
526
527
+ void region_settings_feature_flag::deserialize ( const JsonObject &jo )
528
+ {
529
+ optional ( jo, was_loaded, " blacklist" , blacklist );
530
+ optional ( jo, was_loaded, " whitelist" , whitelist );
531
+ }
532
+
533
+ region_settings_feature_flag ®ion_settings_feature_flag::operator +=
534
+ ( const region_settings_feature_flag &rhs )
535
+ {
536
+ for ( const std::string &bl_copy : rhs.blacklist ) {
537
+ blacklist.emplace ( bl_copy );
538
+ }
539
+ for ( const std::string &wl_copy : rhs.whitelist ) {
540
+ whitelist.emplace ( wl_copy );
541
+ }
542
+ return *this ;
543
+ }
544
+
461
545
static void load_overmap_forest_settings (
462
546
const JsonObject &jo, overmap_forest_settings &overmap_forest_settings, const bool strict,
463
547
const bool overlay )
@@ -553,6 +637,16 @@ static void load_overmap_connection_settings(
553
637
}
554
638
}
555
639
640
+ void region_settings_overmap_connection::deserialize ( const JsonObject &jo )
641
+ {
642
+ optional ( jo, was_loaded, " trail_connection" , trail_connection );
643
+ optional ( jo, was_loaded, " sewer_connection" , sewer_connection );
644
+ optional ( jo, was_loaded, " subway_connection" , subway_connection );
645
+ optional ( jo, was_loaded, " rail_connection" , rail_connection );
646
+ optional ( jo, was_loaded, " intra_city_road_connection" , intra_city_road_connection );
647
+ optional ( jo, was_loaded, " inter_city_road_connection" , inter_city_road_connection );
648
+ }
649
+
556
650
static void load_overmap_lake_settings ( const JsonObject &jo,
557
651
overmap_lake_settings &overmap_lake_settings,
558
652
const bool strict, const bool overlay )
@@ -868,6 +962,76 @@ static void load_region_terrain_and_furniture_settings( const JsonObject &jo,
868
962
}
869
963
}
870
964
965
+ void region_settings_terrain_furniture::load ( const JsonObject &jo, std::string_view )
966
+ {
967
+ optional ( jo, was_loaded, " ter_furn" , ter_furn, auto_flags_reader<region_terrain_furniture_id> {} );
968
+ }
969
+
970
+ region_settings_terrain_furniture ®ion_settings_terrain_furniture::operator +=
971
+ ( const region_settings_terrain_furniture &rhs )
972
+ {
973
+ for ( const region_terrain_furniture_id &rtf : rhs.ter_furn ) {
974
+ /* *
975
+ * This is a copy of the templated apply_region_overlay
976
+ * it is necessary because terrain_furniture objects don't map with an overlay_id
977
+ */
978
+ furn_id f_overlay ( rtf->replaced_furn_id );
979
+ ter_id t_overlay ( rtf->replaced_ter_id );
980
+ bool valid_furniture = !f_overlay.id ().is_null ();
981
+ bool valid_terrain = !t_overlay.id ().is_null ();
982
+ auto predicate = [&valid_terrain, &valid_furniture, &f_overlay,
983
+ &t_overlay]( const region_terrain_furniture_id & this_rtf ) {
984
+ if ( valid_furniture ) {
985
+ return this_rtf->replaced_furn_id == f_overlay;
986
+ }
987
+ if ( valid_terrain ) {
988
+ return this_rtf->replaced_ter_id == t_overlay;
989
+ }
990
+ return false ;
991
+ };
992
+ auto find_collection = std::find_if ( ter_furn.begin (), ter_furn.end (), predicate );
993
+ // found existing regional terrain/furniture, combine the objects
994
+ if ( find_collection != ter_furn.end () ) {
995
+ const_cast <region_terrain_furniture &>( find_collection->obj () ) += *rtf;
996
+ } else {
997
+ debugmsg ( " region_terrain_furniture replaced ter/furn_id %s/%s does not exist in DDA" ,
998
+ t_overlay.id ().str (), f_overlay.id ().str () );
999
+ }
1000
+ }
1001
+ return *this ;
1002
+ }
1003
+
1004
+ void region_terrain_furniture::load ( const JsonObject &jo, std::string_view )
1005
+ {
1006
+ optional ( jo, was_loaded, " ter_id" , replaced_ter_id );
1007
+ optional ( jo, was_loaded, " furn_id" , replaced_furn_id );
1008
+ optional ( jo, was_loaded, " replace_with_terrain" , terrain, ter_reader );
1009
+ optional ( jo, was_loaded, " replace_with_furniture" , furniture, furn_reader );
1010
+ }
1011
+
1012
+ region_terrain_furniture ®ion_terrain_furniture::operator +=( const region_terrain_furniture
1013
+ &rhs )
1014
+ {
1015
+ for ( const std::pair<ter_id, int > &pr : rhs.terrain ) {
1016
+ terrain.try_add ( pr );
1017
+ }
1018
+ for ( const std::pair<furn_id, int > &pr : rhs.furniture ) {
1019
+ furniture.try_add ( pr );
1020
+ }
1021
+ return *this ;
1022
+ }
1023
+
1024
+ void region_settings_city::load ( const JsonObject &jo, std::string_view )
1025
+ {
1026
+ optional ( jo, was_loaded, " shop_radius" , shop_radius );
1027
+ optional ( jo, was_loaded, " shop_sigma" , shop_sigma );
1028
+ optional ( jo, was_loaded, " park_radius" , park_radius );
1029
+ optional ( jo, was_loaded, " park_sigma" , park_sigma );
1030
+ optional ( jo, was_loaded, " houses" , houses.buildings , building_bin_reader );
1031
+ optional ( jo, was_loaded, " shops" , shops.buildings , building_bin_reader );
1032
+ optional ( jo, was_loaded, " parks" , parks.buildings , building_bin_reader );
1033
+ }
1034
+
871
1035
void load_region_settings ( const JsonObject &jo )
872
1036
{
873
1037
regional_settings new_region;
@@ -1341,11 +1505,19 @@ void region_settings_forest_trail::finalize()
1341
1505
trailheads.finalize ();
1342
1506
}
1343
1507
1508
+ void region_settings_city::finalize ()
1509
+ {
1510
+ houses.finalize ();
1511
+ shops.finalize ();
1512
+ parks.finalize ();
1513
+ }
1344
1514
void region_settings_river::finalize () {}
1345
1515
void region_settings_lake::finalize () {}
1346
1516
void region_settings_ocean::finalize () {}
1347
1517
void region_settings_forest::finalize () {}
1348
1518
void region_settings_ravine::finalize () {}
1519
+ void region_settings_terrain_furniture::finalize () {}
1520
+ void region_terrain_furniture::finalize () {}
1349
1521
void overmap_highway_settings::finalize ()
1350
1522
{
1351
1523
// finds longest special in a building collection
@@ -1479,6 +1651,42 @@ furn_id region_terrain_and_furniture_settings::resolve( const furn_id &fid ) con
1479
1651
return result;
1480
1652
}
1481
1653
1654
+ ter_id region_settings_terrain_furniture::resolve ( const ter_id &tid ) const
1655
+ {
1656
+ if ( tid.id ().is_null () ) {
1657
+ return tid;
1658
+ }
1659
+ ter_id result = tid;
1660
+ auto predicate = [&result]( const region_terrain_furniture_id & tid_r ) {
1661
+ return tid_r->replaced_ter_id == result;
1662
+ };
1663
+ auto found_tfid = std::find_if ( ter_furn.begin (), ter_furn.end (), predicate );
1664
+ while ( found_tfid != ter_furn.end () ) {
1665
+ const region_terrain_furniture_id &rtf_id = *found_tfid;
1666
+ result = *rtf_id->terrain .pick ();
1667
+ found_tfid = std::find_if ( ter_furn.begin (), ter_furn.end (), predicate );
1668
+ }
1669
+ return result;
1670
+ }
1671
+
1672
+ furn_id region_settings_terrain_furniture::resolve ( const furn_id &fid ) const
1673
+ {
1674
+ if ( fid.id ().is_null () ) {
1675
+ return fid;
1676
+ }
1677
+ furn_id result = fid;
1678
+ auto predicate = [&result]( const region_terrain_furniture_id & fid_r ) {
1679
+ return fid_r->replaced_furn_id == result;
1680
+ };
1681
+ auto found_tfid = std::find_if ( ter_furn.begin (), ter_furn.end (), predicate );
1682
+ while ( found_tfid != ter_furn.end () ) {
1683
+ const region_terrain_furniture_id &rtf_id = *found_tfid;
1684
+ result = *rtf_id->furniture .pick ();
1685
+ found_tfid = std::find_if ( ter_furn.begin (), ter_furn.end (), predicate );
1686
+ }
1687
+ return result;
1688
+ }
1689
+
1482
1690
void regional_settings::finalize ()
1483
1691
{
1484
1692
if ( default_groundcover_str != nullptr ) {
0 commit comments