Skip to content

Commit 58f0470

Browse files
committed
Remove uses of assign in monstergenerator.cpp
Replace everything left using assign with optional/mandatory, and add some more uses of them. Not everything is using optional/mandatory yet, but it's getting close.
1 parent 8a6be3f commit 58f0470

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/monstergenerator.cpp

Lines changed: 8 additions & 10 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" );
@@ -961,7 +962,7 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
961962
weighted_string_id_reader<efftype_id, int> { 1 } );
962963

963964
optional( jo, was_loaded, "starting_ammo", starting_ammo );
964-
assign( jo, "luminance", luminance, true );
965+
optional( jo, was_loaded, "luminance", luminance, 0 );
965966
optional( jo, was_loaded, "revert_to_itype", revert_to_itype, itype_id() );
966967
optional( jo, was_loaded, "broken_itype", broken_itype, itype_id() );
967968
optional( jo, was_loaded, "mech_weapon", mech_weapon, itype_id() );
@@ -993,9 +994,8 @@ void mtype::load( const JsonObject &jo, const std::string_view src )
993994
"death_drops for mtype " + id.str() );
994995
}
995996

996-
assign( jo, "harvest", harvest );
997-
// FIXME: assign doesn't trigger issues that optional does???
998-
//optional( jo, was_loaded, "harvest", harvest, harvest_id::NULL_ID() );
997+
// FIXME: there's code to check if harvest is null, which will never trigger as it defaults to human
998+
optional( jo, was_loaded, "harvest", harvest, harvest_list_human );
999999

10001000
optional( jo, was_loaded, "dissect", dissect );
10011001

@@ -1311,12 +1311,10 @@ mtype_special_attack MonsterGenerator::create_actor( const JsonObject &obj,
13111311

13121312
void mattack_actor::load( const JsonObject &jo, const std::string &src )
13131313
{
1314-
// Legacy support
1315-
if( !jo.has_string( "id" ) ) {
1316-
id = jo.get_string( "type" );
1314+
if( jo.has_string( "id" ) ) {
1315+
mandatory( jo, false, "id", id );
13171316
} else {
1318-
// Loading ids can't be strict at the moment, since it has to match the stored version
1319-
assign( jo, "id", id, false );
1317+
mandatory( jo, false, "type", id );
13201318
}
13211319

13221320
mandatory( jo, was_loaded, "cooldown", cooldown, dbl_or_var_reader{} );

0 commit comments

Comments
 (0)