18
18
#include < vector>
19
19
20
20
#include " all_enum_values.h"
21
- #include " assign.h"
22
21
#include " auto_note.h"
23
22
#include " avatar.h"
24
23
#include " cached_options.h"
@@ -470,22 +469,19 @@ std::string overmap_land_use_code::get_symbol() const
470
469
return utf32_to_utf8 ( symbol );
471
470
}
472
471
473
- void overmap_land_use_code::load ( const JsonObject &jo, const std::string &src )
472
+ void overmap_land_use_code::load ( const JsonObject &jo, const std::string_view )
474
473
{
475
- const bool strict = src == " dda" ;
476
- assign ( jo, " land_use_code" , land_use_code, strict );
477
- assign ( jo, " name" , name, strict );
478
- assign ( jo, " detailed_definition" , detailed_definition, strict );
474
+ optional ( jo, was_loaded, " land_use_code" , land_use_code );
475
+ optional ( jo, was_loaded, " name" , name );
476
+ optional ( jo, was_loaded, " detailed_definition" , detailed_definition );
479
477
480
478
optional ( jo, was_loaded, " sym" , symbol, unicode_codepoint_from_symbol_reader, NULL_UNICODE );
481
-
482
479
if ( symbol == NULL_UNICODE ) {
483
480
DebugLog ( D_ERROR, D_GAME ) << " `sym` node is not defined properly for `land_use_code`: "
484
481
<< id.c_str () << " (" << name << " )" ;
485
482
}
486
483
487
- optional ( jo, was_loaded, " color" , color, nc_color_reader{} );
488
-
484
+ optional ( jo, was_loaded, " color" , color, nc_color_reader{}, c_black );
489
485
}
490
486
491
487
void overmap_land_use_code::finalize ()
@@ -860,7 +856,7 @@ void oter_vision::level::deserialize( const JsonObject &jo )
860
856
}
861
857
mandatory ( jo, false , " name" , name );
862
858
mandatory ( jo, false , " sym" , symbol, unicode_codepoint_from_symbol_reader );
863
- optional ( jo, false , " color" , color, nc_color_reader{} );
859
+ mandatory ( jo, false , " color" , color, nc_color_reader{} );
864
860
optional ( jo, false , " looks_like" , looks_like );
865
861
}
866
862
@@ -907,35 +903,32 @@ void oter_vision::check() const
907
903
}
908
904
909
905
910
- void oter_type_t::load ( const JsonObject &jo, const std::string &src )
906
+ void oter_type_t::load ( const JsonObject &jo, const std::string_view )
911
907
{
912
- const bool strict = src == " dda" ;
913
-
914
908
optional ( jo, was_loaded, " sym" , symbol, unicode_codepoint_from_symbol_reader, NULL_UNICODE );
915
909
916
- assign ( jo, " name" , name, strict );
910
+ optional ( jo, was_loaded, " name" , name );
917
911
// For some reason an enum can be read as a number??
918
912
if ( jo.has_number ( " see_cost" ) ) {
919
913
jo.throw_error ( string_format ( " In %s: See cost uses invalid number format" , id.str () ) );
920
914
}
921
915
mandatory ( jo, was_loaded, " see_cost" , see_cost );
922
- assign ( jo, " extras" , extras, strict );
923
- assign ( jo, " mondensity" , mondensity, strict );
924
- assign ( jo, " entry_eoc" , entry_EOC, strict );
925
- assign ( jo, " exit_eoc" , exit_EOC, strict );
926
- assign ( jo, " spawns" , static_spawns, strict );
916
+ optional ( jo, was_loaded, " extras" , extras, " none " );
917
+ optional ( jo, was_loaded, " mondensity" , mondensity, 0 );
918
+ optional ( jo, was_loaded, " entry_eoc" , entry_EOC );
919
+ optional ( jo, was_loaded, " exit_eoc" , exit_EOC );
920
+ optional ( jo, was_loaded, " spawns" , static_spawns );
927
921
optional ( jo, was_loaded, " color" , color, nc_color_reader{} );
928
- assign ( jo, " land_use_code" , land_use_code, strict );
922
+ optional ( jo, was_loaded, " land_use_code" , land_use_code, overmap_land_use_code_id::NULL_ID () );
929
923
930
924
if ( jo.has_member ( " looks_like" ) ) {
931
- std::vector<std::string> ll;
932
925
if ( jo.has_array ( " looks_like" ) ) {
933
- jo.read ( " looks_like" , ll );
934
- } else if ( jo.has_string ( " looks_like" ) ) {
935
- const std::string one_look = jo.get_string ( " looks_like" );
936
- ll.push_back ( one_look );
926
+ mandatory ( jo, was_loaded, " looks_like" , looks_like );
927
+ } else {
928
+ std::string one_look;
929
+ mandatory ( jo, was_loaded, " looks_like" , one_look );
930
+ looks_like = { one_look };
937
931
}
938
- looks_like = ll;
939
932
} else if ( jo.has_member ( " copy-from" ) ) {
940
933
looks_like.insert ( looks_like.begin (), jo.get_string ( " copy-from" ) );
941
934
}
@@ -1396,6 +1389,15 @@ tripoint displace( cube_direction d )
1396
1389
cata_fatal ( " Invalid cube_direction" );
1397
1390
}
1398
1391
1392
+ void overmap_special_connection::deserialize ( const JsonObject &jo )
1393
+ {
1394
+ optional ( jo, false , " point" , p );
1395
+ optional ( jo, false , " terrain" , terrain );
1396
+ optional ( jo, false , " existing" , existing, false );
1397
+ optional ( jo, false , " connection" , connection );
1398
+ optional ( jo, false , " from" , from );
1399
+ }
1400
+
1399
1401
struct special_placement_result {
1400
1402
std::vector<tripoint_om_omt> omts_used;
1401
1403
std::vector<std::pair<om_pos_dir, std::string>> joins_used;
@@ -2909,6 +2911,46 @@ struct mutable_overmap_special_data : overmap_special_data {
2909
2911
2910
2912
return { result, unresolved.all_used () };
2911
2913
}
2914
+
2915
+ void load ( const JsonObject &jo, bool was_loaded ) {
2916
+ optional ( jo, was_loaded, " check_for_locations" , check_for_locations );
2917
+ if ( jo.has_array ( " check_for_locations_area" ) ) {
2918
+ JsonArray jar = jo.get_array ( " check_for_locations_area" );
2919
+ while ( jar.has_more () ) {
2920
+ JsonObject joc = jar.next_object ();
2921
+
2922
+ cata::flat_set<string_id<overmap_location>> type;
2923
+ tripoint_rel_omt from;
2924
+ tripoint_rel_omt to;
2925
+ mandatory ( joc, was_loaded, " type" , type );
2926
+ mandatory ( joc, was_loaded, " from" , from );
2927
+ mandatory ( joc, was_loaded, " to" , to );
2928
+ if ( from.x () > to.x () ) {
2929
+ std::swap ( from.x (), to.x () );
2930
+ }
2931
+ if ( from.y () > to.y () ) {
2932
+ std::swap ( from.y (), to.y () );
2933
+ }
2934
+ if ( from.z () > to.z () ) {
2935
+ std::swap ( from.z (), to.z () );
2936
+ }
2937
+ for ( int x = from.x (); x <= to.x (); x++ ) {
2938
+ for ( int y = from.y (); y <= to.y (); y++ ) {
2939
+ for ( int z = from.z (); z <= to.z (); z++ ) {
2940
+ overmap_special_locations loc;
2941
+ loc.p = tripoint_rel_omt ( x, y, z );
2942
+ loc.locations = type;
2943
+ check_for_locations.push_back ( loc );
2944
+ }
2945
+ }
2946
+ }
2947
+ }
2948
+ }
2949
+ mandatory ( jo, was_loaded, " joins" , joins_vec );
2950
+ mandatory ( jo, was_loaded, " overmaps" , overmaps );
2951
+ mandatory ( jo, was_loaded, " root" , root );
2952
+ mandatory ( jo, was_loaded, " phases" , phases );
2953
+ }
2912
2954
};
2913
2955
2914
2956
overmap_special::overmap_special ( const overmap_special_id &i, const overmap_special_terrain &ter )
@@ -3020,15 +3062,15 @@ mapgen_arguments overmap_special::get_args( const mapgendata &md ) const
3020
3062
return mapgen_params_.get_args ( md, mapgen_parameter_scope::overmap_special );
3021
3063
}
3022
3064
3023
- void overmap_special::load ( const JsonObject &jo, const std::string & src )
3065
+ void overmap_special::load ( const JsonObject &jo, const std::string_view src )
3024
3066
{
3025
- const bool strict = src == " dda" ;
3026
3067
// city_building is just an alias of overmap_special
3027
3068
// TODO: This comparison is a hack. Separate them properly.
3028
3069
const bool is_special = jo.get_string ( " type" , " " ) == " overmap_special" ;
3029
3070
3030
3071
optional ( jo, was_loaded, " subtype" , subtype_, overmap_special_subtype::fixed );
3031
3072
optional ( jo, was_loaded, " locations" , default_locations_ );
3073
+ // FIXME: eoc reader for generic factory
3032
3074
if ( jo.has_member ( " eoc" ) ) {
3033
3075
eoc = effect_on_conditions::load_inline_eoc ( jo.get_member ( " eoc" ), src );
3034
3076
has_eoc_ = true ;
@@ -3047,45 +3089,7 @@ void overmap_special::load( const JsonObject &jo, const std::string &src )
3047
3089
case overmap_special_subtype::mutable_: {
3048
3090
shared_ptr_fast<mutable_overmap_special_data> mutable_data =
3049
3091
make_shared_fast<mutable_overmap_special_data>( id );
3050
- std::vector<overmap_special_locations> check_for_locations_merged_data;
3051
- optional ( jo, was_loaded, " check_for_locations" , check_for_locations_merged_data );
3052
- if ( jo.has_array ( " check_for_locations_area" ) ) {
3053
- JsonArray jar = jo.get_array ( " check_for_locations_area" );
3054
- while ( jar.has_more () ) {
3055
- JsonObject joc = jar.next_object ();
3056
-
3057
- cata::flat_set<string_id<overmap_location>> type;
3058
- tripoint_rel_omt from;
3059
- tripoint_rel_omt to;
3060
- mandatory ( joc, was_loaded, " type" , type );
3061
- mandatory ( joc, was_loaded, " from" , from );
3062
- mandatory ( joc, was_loaded, " to" , to );
3063
- if ( from.x () > to.x () ) {
3064
- std::swap ( from.x (), to.x () );
3065
- }
3066
- if ( from.y () > to.y () ) {
3067
- std::swap ( from.y (), to.y () );
3068
- }
3069
- if ( from.z () > to.z () ) {
3070
- std::swap ( from.z (), to.z () );
3071
- }
3072
- for ( int x = from.x (); x <= to.x (); x++ ) {
3073
- for ( int y = from.y (); y <= to.y (); y++ ) {
3074
- for ( int z = from.z (); z <= to.z (); z++ ) {
3075
- overmap_special_locations loc;
3076
- loc.p = tripoint_rel_omt ( x, y, z );
3077
- loc.locations = type;
3078
- check_for_locations_merged_data.push_back ( loc );
3079
- }
3080
- }
3081
- }
3082
- }
3083
- }
3084
- mutable_data->check_for_locations = check_for_locations_merged_data;
3085
- mandatory ( jo, was_loaded, " joins" , mutable_data->joins_vec );
3086
- mandatory ( jo, was_loaded, " overmaps" , mutable_data->overmaps );
3087
- mandatory ( jo, was_loaded, " root" , mutable_data->root );
3088
- mandatory ( jo, was_loaded, " phases" , mutable_data->phases );
3092
+ mutable_data->load ( jo, was_loaded );
3089
3093
data_ = std::move ( mutable_data );
3090
3094
break ;
3091
3095
}
@@ -3094,18 +3098,18 @@ void overmap_special::load( const JsonObject &jo, const std::string &src )
3094
3098
io::enum_to_string ( subtype_ ) ) );
3095
3099
}
3096
3100
3097
- assign ( jo, " city_sizes" , constraints_.city_size , strict );
3101
+ optional ( jo, was_loaded, " city_sizes" , constraints_.city_size , { 0 , INT_MAX } );
3098
3102
3099
3103
if ( is_special ) {
3100
3104
mandatory ( jo, was_loaded, " occurrences" , constraints_.occurrences );
3101
- assign ( jo, " city_distance" , constraints_.city_distance , strict );
3102
- assign ( jo, " priority" , priority_, strict );
3105
+ optional ( jo, was_loaded, " city_distance" , constraints_.city_distance , { 0 , INT_MAX } );
3106
+ optional ( jo, was_loaded, " priority" , priority_, 0 );
3103
3107
}
3104
3108
3105
- assign ( jo, " spawns" , monster_spawns_, strict );
3109
+ optional ( jo, was_loaded, " spawns" , monster_spawns_ );
3106
3110
3107
- assign ( jo, " rotate" , rotatable_, strict );
3108
- assign ( jo, " flags" , flags_, strict );
3111
+ optional ( jo, was_loaded, " rotate" , rotatable_, true );
3112
+ optional ( jo, was_loaded, " flags" , flags_, string_reader{} );
3109
3113
}
3110
3114
3111
3115
void overmap_special::finalize ()
0 commit comments