Skip to content

Commit 0dfb85c

Browse files
authored
Merge pull request #82667 from ehughsbaird/final-assign-monstergenerator
Use optional/mandatory in place of assign in monstergenerator.cpp
2 parents 78eb417 + 58f0470 commit 0dfb85c

File tree

5 files changed

+19
-112
lines changed

5 files changed

+19
-112
lines changed

data/json/monsters/insect_spider.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
"dissect": "dissect_troglobite_sample_single",
207207
"upgrades": { "age_grow": 30, "into": "mon_worm" },
208208
"extend": { "flags": [ "DIGS", "GOODHEARING", "SMALL_HIDER" ] },
209-
"delete": { "flags": [ "SEES", "SMELLS" ], "move_skills": { "climb": 2 } }
209+
"delete": { "flags": [ "SEES" ], "move_skills": { "climb": 2 } }
210210
},
211211
{
212212
"id": "mon_large_cockroach",

data/json/monsters/nether.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
"corpse_type": "NO_CORPSE",
309309
"message": "The %s shatters like pane of glass."
310310
},
311-
"delete": { "flags": [ "ATTACKMON", "ALWAYS_SEES_YOU", "HIT_AND_RUN" ] },
311+
"delete": { "flags": [ "ALWAYS_SEES_YOU" ] },
312312
"extend": { "flags": [ "SILENT_DISAPPEAR" ] }
313313
},
314314
{
@@ -331,7 +331,7 @@
331331
"corpse_type": "NO_CORPSE",
332332
"message": "The %s shatters like pane of glass."
333333
},
334-
"delete": { "flags": [ "ATTACKMON", "ALWAYS_SEES_YOU", "HIT_AND_RUN" ] },
334+
"delete": { "flags": [ "ALWAYS_SEES_YOU" ] },
335335
"extend": { "flags": [ "SILENT_DISAPPEAR" ] }
336336
},
337337
{
@@ -356,7 +356,7 @@
356356
{ "id": "drag_followup", "grab_data": { "drag_distance": 1 } }
357357
],
358358
"death_function": { "corpse_type": "NO_CORPSE", "message": "The %s shatters like pane of glass." },
359-
"delete": { "flags": [ "ATTACKMON", "ALWAYS_SEES_YOU", "HIT_AND_RUN" ] },
359+
"delete": { "flags": [ "ALWAYS_SEES_YOU" ] },
360360
"extend": { "flags": [ "SILENT_DISAPPEAR" ] }
361361
},
362362
{

data/json/monsters/zed_skeletal.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@
5353
"upgrades": { "half_life": 180, "into": "mon_skeleton_hulk" },
5454
"fungalize_into": "mon_skeleton_brute_dusted",
5555
"armor": { "bash": 12, "cut": 30, "acid": 1, "bullet": 30, "electric": 4 },
56-
"extend": { "weakpoint_sets": [ "wps_bone_armor" ], "families": [ "prof_wp_skeleton" ], "flags": [ "PULP_PRYING" ] },
57-
"delete": { "flags": [ "STUMBLES" ] }
56+
"extend": { "weakpoint_sets": [ "wps_bone_armor" ], "families": [ "prof_wp_skeleton" ], "flags": [ "PULP_PRYING" ] }
5857
},
5958
{
6059
"id": "mon_skeleton_electric",

data/mods/CrazyCataclysm/crazy_monsters.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
"copy-from": "mon_zombie_electric",
1515
"special_attacks": [ [ "SHOCKING_REVEAL", 25 ] ]
1616
},
17-
{
18-
"id": "halloween_dragon",
19-
"type": "MONSTER",
20-
"name": { "str": "inflatable dragon" },
21-
"copy-from": "mon_dragon_dummy",
22-
"delete": { "flags": [ "NOT_HALLUCINATION" ] }
23-
},
2417
{
2518
"id": "halloween_ghost",
2619
"type": "MONSTER",

src/monstergenerator.cpp

Lines changed: 14 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <unordered_set>
99
#include <utility>
1010

11-
#include "assign.h"
1211
#include "cached_options.h"
1312
#include "calendar.h"
1413
#include "cata_utility.h"
@@ -42,6 +41,8 @@
4241

4342
struct itype;
4443

44+
static const harvest_id harvest_list_human( "human" );
45+
4546
static const material_id material_flesh( "flesh" );
4647

4748
static const speed_description_id speed_description_DEFAULT( "DEFAULT" );
@@ -852,8 +853,9 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
852853

853854
optional( jo, was_loaded, "bodytype", bodytype );
854855
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 );
857859

858860
optional( jo, was_loaded, "phase", phase, make_flag_reader( gen.phase_map, "phase id" ),
859861
phase_id::SOLID );
@@ -955,7 +957,7 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
955957
weighted_string_id_reader<efftype_id, int> { 1 } );
956958

957959
optional( jo, was_loaded, "starting_ammo", starting_ammo );
958-
assign( jo, "luminance", luminance, true );
960+
optional( jo, was_loaded, "luminance", luminance, 0 );
959961
optional( jo, was_loaded, "revert_to_itype", revert_to_itype, itype_id() );
960962
optional( jo, was_loaded, "broken_itype", broken_itype, itype_id() );
961963
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 )
987989
"death_drops for mtype " + id.str() );
988990
}
989991

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 );
993994

994995
optional( jo, was_loaded, "dissect", dissect );
995996

996-
optional( jo, was_loaded, "decay", decay );
997+
optional( jo, was_loaded, "decay", decay, harvest_id::NULL_ID() );
997998

998999
optional( jo, was_loaded, "shearing", shearing );
9991000

@@ -1131,49 +1132,7 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
11311132
optional( jo, was_loaded, "burn_into", burn_into, string_id_reader<::mtype> {},
11321133
mtype_id::NULL_ID() );
11331134

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> {} );
11771136

11781137
// Can't calculate yet - we want all flags first
11791138
optional( jo, was_loaded, "bash_skill", bash_skill, -1 );
@@ -1212,49 +1171,7 @@ void species_type::load( const JsonObject &jo, std::string_view )
12121171
optional( jo, was_loaded, "description", description );
12131172
optional( jo, was_loaded, "footsteps", footsteps, to_translation( "footsteps." ) );
12141173

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> {} );
12581175

12591176
const auto trigger_reader = enum_flags_reader<mon_trigger> { "monster trigger" };
12601177
optional( jo, was_loaded, "anger_triggers", anger, trigger_reader );
@@ -1389,12 +1306,10 @@ mtype_special_attack MonsterGenerator::create_actor( const JsonObject &obj,
13891306

13901307
void mattack_actor::load( const JsonObject &jo, const std::string &src )
13911308
{
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 );
13951311
} 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 );
13981313
}
13991314

14001315
mandatory( jo, was_loaded, "cooldown", cooldown );

0 commit comments

Comments
 (0)