|
8 | 8 | #include <unordered_set>
|
9 | 9 | #include <utility>
|
10 | 10 |
|
11 |
| -#include "assign.h" |
12 | 11 | #include "cached_options.h"
|
13 | 12 | #include "calendar.h"
|
14 | 13 | #include "cata_utility.h"
|
|
42 | 41 |
|
43 | 42 | struct itype;
|
44 | 43 |
|
| 44 | +static const harvest_id harvest_list_human( "human" ); |
| 45 | + |
45 | 46 | static const material_id material_flesh( "flesh" );
|
46 | 47 |
|
47 | 48 | static const speed_description_id speed_description_DEFAULT( "DEFAULT" );
|
@@ -852,8 +853,9 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
|
852 | 853 |
|
853 | 854 | optional( jo, was_loaded, "bodytype", bodytype );
|
854 | 855 | optional( jo, was_loaded, "color", color, nc_color_reader{}, c_white );
|
855 |
| - optional( jo, was_loaded, "volume", volume, units_bound_reader<units::volume> { 0_ml } ); |
856 |
| - optional( jo, was_loaded, "weight", weight, units_bound_reader<units::mass> { 0_gram } ); |
| 856 | + optional( jo, was_loaded, "volume", volume, units_bound_reader<units::volume> { 0_ml }, 62499_ml ); |
| 857 | + optional( jo, was_loaded, "weight", weight, units_bound_reader<units::mass> { 0_gram }, |
| 858 | + 81499_gram ); |
857 | 859 |
|
858 | 860 | optional( jo, was_loaded, "phase", phase, make_flag_reader( gen.phase_map, "phase id" ),
|
859 | 861 | phase_id::SOLID );
|
@@ -955,7 +957,7 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
|
955 | 957 | weighted_string_id_reader<efftype_id, int> { 1 } );
|
956 | 958 |
|
957 | 959 | optional( jo, was_loaded, "starting_ammo", starting_ammo );
|
958 |
| - assign( jo, "luminance", luminance, true ); |
| 960 | + optional( jo, was_loaded, "luminance", luminance, 0 ); |
959 | 961 | optional( jo, was_loaded, "revert_to_itype", revert_to_itype, itype_id() );
|
960 | 962 | optional( jo, was_loaded, "broken_itype", broken_itype, itype_id() );
|
961 | 963 | optional( jo, was_loaded, "mech_weapon", mech_weapon, itype_id() );
|
@@ -987,13 +989,12 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
|
987 | 989 | "death_drops for mtype " + id.str() );
|
988 | 990 | }
|
989 | 991 |
|
990 |
| - assign( jo, "harvest", harvest ); |
991 |
| - // FIXME: assign doesn't trigger issues that optional does??? |
992 |
| - //optional( jo, was_loaded, "harvest", harvest, harvest_id::NULL_ID() ); |
| 992 | + // FIXME: there's code to check if harvest is null, which will never trigger as it defaults to human |
| 993 | + optional( jo, was_loaded, "harvest", harvest, harvest_list_human ); |
993 | 994 |
|
994 | 995 | optional( jo, was_loaded, "dissect", dissect );
|
995 | 996 |
|
996 |
| - optional( jo, was_loaded, "decay", decay ); |
| 997 | + optional( jo, was_loaded, "decay", decay, harvest_id::NULL_ID() ); |
997 | 998 |
|
998 | 999 | optional( jo, was_loaded, "shearing", shearing );
|
999 | 1000 |
|
@@ -1131,49 +1132,7 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
|
1131 | 1132 | optional( jo, was_loaded, "burn_into", burn_into, string_id_reader<::mtype> {},
|
1132 | 1133 | mtype_id::NULL_ID() );
|
1133 | 1134 |
|
1134 |
| - if( jo.has_member( "flags" ) ) { |
1135 |
| - pre_flags_.clear(); |
1136 |
| - if( jo.has_string( "flags" ) ) { |
1137 |
| - pre_flags_.emplace( jo.get_string( "flags" ) ); |
1138 |
| - } else { |
1139 |
| - for( JsonValue jval : jo.get_array( "flags" ) ) { |
1140 |
| - pre_flags_.emplace( jval.get_string() ); |
1141 |
| - } |
1142 |
| - } |
1143 |
| - } else { |
1144 |
| - if( jo.has_member( "extend" ) ) { |
1145 |
| - JsonObject exjo = jo.get_object( "extend" ); |
1146 |
| - exjo.allow_omitted_members(); |
1147 |
| - if( exjo.has_member( "flags" ) ) { |
1148 |
| - if( exjo.has_string( "flags" ) ) { |
1149 |
| - pre_flags_.emplace( exjo.get_string( "flags" ) ); |
1150 |
| - } else { |
1151 |
| - for( JsonValue jval : exjo.get_array( "flags" ) ) { |
1152 |
| - pre_flags_.emplace( jval.get_string() ); |
1153 |
| - } |
1154 |
| - } |
1155 |
| - } |
1156 |
| - } |
1157 |
| - if( jo.has_member( "delete" ) ) { |
1158 |
| - JsonObject deljo = jo.get_object( "delete" ); |
1159 |
| - deljo.allow_omitted_members(); |
1160 |
| - if( deljo.has_member( "flags" ) ) { |
1161 |
| - if( deljo.has_string( "flags" ) ) { |
1162 |
| - auto iter = pre_flags_.find( mon_flag_str_id( deljo.get_string( "flags" ) ) ); |
1163 |
| - if( iter != pre_flags_.end() ) { |
1164 |
| - pre_flags_.erase( iter ); |
1165 |
| - } |
1166 |
| - } else { |
1167 |
| - for( JsonValue jval : deljo.get_array( "flags" ) ) { |
1168 |
| - auto iter = pre_flags_.find( mon_flag_str_id( jval.get_string() ) ); |
1169 |
| - if( iter != pre_flags_.end() ) { |
1170 |
| - pre_flags_.erase( iter ); |
1171 |
| - } |
1172 |
| - } |
1173 |
| - } |
1174 |
| - } |
1175 |
| - } |
1176 |
| - } |
| 1135 | + optional( jo, was_loaded, "flags", pre_flags_, string_id_reader<mon_flag> {} ); |
1177 | 1136 |
|
1178 | 1137 | // Can't calculate yet - we want all flags first
|
1179 | 1138 | optional( jo, was_loaded, "bash_skill", bash_skill, -1 );
|
@@ -1212,49 +1171,7 @@ void species_type::load( const JsonObject &jo, std::string_view )
|
1212 | 1171 | optional( jo, was_loaded, "description", description );
|
1213 | 1172 | optional( jo, was_loaded, "footsteps", footsteps, to_translation( "footsteps." ) );
|
1214 | 1173 |
|
1215 |
| - if( jo.has_member( "flags" ) ) { |
1216 |
| - flags.clear(); |
1217 |
| - if( jo.has_string( "flags" ) ) { |
1218 |
| - flags.emplace( jo.get_string( "flags" ) ); |
1219 |
| - } else { |
1220 |
| - for( JsonValue jval : jo.get_array( "flags" ) ) { |
1221 |
| - flags.emplace( jval.get_string() ); |
1222 |
| - } |
1223 |
| - } |
1224 |
| - } else { |
1225 |
| - if( jo.has_member( "extend" ) ) { |
1226 |
| - JsonObject exjo = jo.get_object( "extend" ); |
1227 |
| - exjo.allow_omitted_members(); |
1228 |
| - if( exjo.has_member( "flags" ) ) { |
1229 |
| - if( exjo.has_string( "flags" ) ) { |
1230 |
| - flags.emplace( exjo.get_string( "flags" ) ); |
1231 |
| - } else { |
1232 |
| - for( JsonValue jval : exjo.get_array( "flags" ) ) { |
1233 |
| - flags.emplace( jval.get_string() ); |
1234 |
| - } |
1235 |
| - } |
1236 |
| - } |
1237 |
| - } |
1238 |
| - if( jo.has_member( "delete" ) ) { |
1239 |
| - JsonObject deljo = jo.get_object( "delete" ); |
1240 |
| - deljo.allow_omitted_members(); |
1241 |
| - if( deljo.has_member( "flags" ) ) { |
1242 |
| - if( deljo.has_string( "flags" ) ) { |
1243 |
| - auto iter = flags.find( mon_flag_str_id( deljo.get_string( "flags" ) ) ); |
1244 |
| - if( iter != flags.end() ) { |
1245 |
| - flags.erase( iter ); |
1246 |
| - } |
1247 |
| - } else { |
1248 |
| - for( JsonValue jval : deljo.get_array( "flags" ) ) { |
1249 |
| - auto iter = flags.find( mon_flag_str_id( jval.get_string() ) ); |
1250 |
| - if( iter != flags.end() ) { |
1251 |
| - flags.erase( iter ); |
1252 |
| - } |
1253 |
| - } |
1254 |
| - } |
1255 |
| - } |
1256 |
| - } |
1257 |
| - } |
| 1174 | + optional( jo, was_loaded, "flags", flags, string_id_reader<mon_flag> {} ); |
1258 | 1175 |
|
1259 | 1176 | const auto trigger_reader = enum_flags_reader<mon_trigger> { "monster trigger" };
|
1260 | 1177 | optional( jo, was_loaded, "anger_triggers", anger, trigger_reader );
|
@@ -1389,12 +1306,10 @@ mtype_special_attack MonsterGenerator::create_actor( const JsonObject &obj,
|
1389 | 1306 |
|
1390 | 1307 | void mattack_actor::load( const JsonObject &jo, const std::string &src )
|
1391 | 1308 | {
|
1392 |
| - // Legacy support |
1393 |
| - if( !jo.has_string( "id" ) ) { |
1394 |
| - id = jo.get_string( "type" ); |
| 1309 | + if( jo.has_string( "id" ) ) { |
| 1310 | + mandatory( jo, false, "id", id ); |
1395 | 1311 | } else {
|
1396 |
| - // Loading ids can't be strict at the moment, since it has to match the stored version |
1397 |
| - assign( jo, "id", id, false ); |
| 1312 | + mandatory( jo, false, "type", id ); |
1398 | 1313 | }
|
1399 | 1314 |
|
1400 | 1315 | mandatory( jo, was_loaded, "cooldown", cooldown );
|
|
0 commit comments