diff --git a/src/game.cpp b/src/game.cpp index 5c362bf943639..1a222aa9d364b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -150,7 +150,6 @@ #include "move_mode.h" #include "mtype.h" #include "npc.h" -#include "npc_class.h" #include "npctrade.h" #include "omdata.h" #include "options.h" @@ -310,6 +309,9 @@ static const mongroup_id GROUP_BLACK_ROAD( "GROUP_BLACK_ROAD" ); static const mtype_id mon_manhack( "mon_manhack" ); +static const npc_class_id NC_DOCTOR( "NC_DOCTOR" ); +static const npc_class_id NC_HALLU( "NC_HALLU" ); + static const overmap_special_id overmap_special_world( "world" ); static const proficiency_id proficiency_prof_parkour( "prof_parkour" ); @@ -1284,7 +1286,7 @@ void game::create_starting_npcs() shared_ptr_fast tmp = make_shared_fast(); tmp->normalize(); - tmp->randomize( one_in( 2 ) ? NC_DOCTOR : NC_NONE ); + tmp->randomize( one_in( 2 ) ? NC_DOCTOR : npc_class_id::NULL_ID() ); // hardcoded, consistent NPC position // start_loc::place_player relies on this and must be updated if this is changed tmp->spawn_at_precise( u.get_location() + point_north_west ); diff --git a/src/mission.cpp b/src/mission.cpp index 407af401e5284..8fecee6d90f7e 100644 --- a/src/mission.cpp +++ b/src/mission.cpp @@ -28,7 +28,6 @@ #include "map_iterator.h" #include "monster.h" #include "npc.h" -#include "npc_class.h" #include "overmap.h" #include "overmapbuffer.h" #include "point.h" @@ -878,7 +877,7 @@ mission::mission() item_id = itype_id::NULL_ID(); item_count = 1; target_id = string_id::NULL_ID(); - recruit_class = NC_NONE; + recruit_class = npc_class_id::NULL_ID(); target_npc_id = character_id(); monster_type = mtype_id::NULL_ID(); monster_kill_goal = -1; diff --git a/src/mission.h b/src/mission.h index 95ca40d7ba91d..848185f3cfd1d 100644 --- a/src/mission.h +++ b/src/mission.h @@ -212,7 +212,7 @@ struct mission_type { bool invisible_on_complete = false; itype_id empty_container = itype_id::NULL_ID(); int item_count = 1; - npc_class_id recruit_class = npc_class_id( "NC_NONE" ); // The type of NPC you are to recruit + npc_class_id recruit_class = npc_class_id::NULL_ID(); // The type of NPC you are to recruit character_id target_npc_id; mtype_id monster_type = mtype_id::NULL_ID(); species_id monster_species; diff --git a/src/mission_start.cpp b/src/mission_start.cpp index 37376f8f0d878..8af91c223e3c7 100644 --- a/src/mission_start.cpp +++ b/src/mission_start.cpp @@ -20,7 +20,6 @@ #include "mapdata.h" #include "messages.h" #include "npc.h" -#include "npc_class.h" #include "omdata.h" #include "overmap.h" #include "overmapbuffer.h" @@ -43,6 +42,10 @@ static const itype_id itype_software_useless( "software_useless" ); static const mission_type_id mission_MISSION_GET_ZOMBIE_BLOOD_ANAL( "MISSION_GET_ZOMBIE_BLOOD_ANAL" ); +static const npc_class_id NC_DOCTOR( "NC_DOCTOR" ); +static const npc_class_id NC_HACKER( "NC_HACKER" ); +static const npc_class_id NC_SCIENTIST( "NC_SCIENTIST" ); + static const ter_str_id ter_t_floor( "t_floor" ); static const ter_str_id ter_t_wall_metal( "t_wall_metal" ); diff --git a/src/npc.cpp b/src/npc.cpp index c6ea72f993c86..9025d185ac062 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -125,6 +125,12 @@ static const mfaction_str_id monfaction_bee( "bee" ); static const mfaction_str_id monfaction_human( "human" ); static const mfaction_str_id monfaction_player( "player" ); +static const npc_class_id NC_ARSONIST( "NC_ARSONIST" ); +static const npc_class_id NC_BOUNTY_HUNTER( "NC_BOUNTY_HUNTER" ); +static const npc_class_id NC_COWBOY( "NC_COWBOY" ); +static const npc_class_id NC_EVAC_SHOPKEEP( "NC_EVAC_SHOPKEEP" ); +static const npc_class_id NC_TRADER( "NC_TRADER" ); + static const overmap_location_str_id overmap_location_source_of_ammo( "source_of_ammo" ); static const overmap_location_str_id overmap_location_source_of_anything( "source_of_anything" ); static const overmap_location_str_id overmap_location_source_of_drink( "source_of_drink" ); @@ -307,10 +313,7 @@ void npc_template::load( const JsonObject &jsobj ) if( jsobj.has_string( "faction" ) ) { guy.set_fac_id( jsobj.get_string( "faction" ) ); } - - if( jsobj.has_int( "class" ) ) { - guy.myclass = npc_class::from_legacy_int( jsobj.get_int( "class" ) ); - } else if( jsobj.has_string( "class" ) ) { + if( jsobj.has_string( "class" ) ) { guy.myclass = npc_class_id( jsobj.get_string( "class" ) ); } diff --git a/src/npc_class.cpp b/src/npc_class.cpp index 2c9a39af5d8ea..202d51f5f707b 100644 --- a/src/npc_class.cpp +++ b/src/npc_class.cpp @@ -22,49 +22,6 @@ #include "skill.h" #include "trait_group.h" -const npc_class_id NC_ARSONIST( "NC_ARSONIST" ); -const npc_class_id NC_BARTENDER( "NC_BARTENDER" ); -const npc_class_id NC_BOUNTY_HUNTER( "NC_BOUNTY_HUNTER" ); -const npc_class_id NC_COWBOY( "NC_COWBOY" ); -const npc_class_id NC_CYBORG( "NC_CYBORG" ); -const npc_class_id NC_DOCTOR( "NC_DOCTOR" ); -const npc_class_id NC_EVAC_SHOPKEEP( "NC_EVAC_SHOPKEEP" ); -const npc_class_id NC_HACKER( "NC_HACKER" ); -const npc_class_id NC_HALLU( "NC_HALLU" ); -const npc_class_id NC_HUNTER( "NC_HUNTER" ); -const npc_class_id NC_JUNK_SHOPKEEP( "NC_JUNK_SHOPKEEP" ); -const npc_class_id NC_NINJA( "NC_NINJA" ); -const npc_class_id NC_NONE( "NC_NONE" ); -const npc_class_id NC_SCAVENGER( "NC_SCAVENGER" ); -const npc_class_id NC_SCIENTIST( "NC_SCIENTIST" ); -const npc_class_id NC_SHOPKEEP( "NC_SHOPKEEP" ); -const npc_class_id NC_SOLDIER( "NC_SOLDIER" ); -const npc_class_id NC_THUG( "NC_THUG" ); -const npc_class_id NC_TRADER( "NC_TRADER" ); - -static const std::array legacy_ids = {{ - NC_NONE, - NC_EVAC_SHOPKEEP, // Found in the Evacuation Center, unique, has more goods than he should be able to carry - NC_SHOPKEEP, // Found in towns. Stays in his shop mostly. - NC_HACKER, // Weak in combat but has hacking skills and equipment - NC_CYBORG, // Broken Cyborg rescued from a lab - NC_DOCTOR, // Found in towns, or roaming. Stays in the clinic. - NC_TRADER, // Roaming trader, journeying between towns. - NC_NINJA, // Specializes in unarmed combat, carries few items - NC_COWBOY, // Gunslinger and survivalist - NC_SCIENTIST, // Uses intelligence-based skills and high-tech items - NC_BOUNTY_HUNTER, // Resourceful and well-armored - NC_THUG, // Moderate melee skills and poor equipment - NC_SCAVENGER, // Good with pistols light weapons - NC_ARSONIST, // Evacuation Center, restocks Molotovs and anarchist type stuff - NC_HUNTER, // Survivor type good with bow or rifle - NC_SOLDIER, // Well equipped and trained combatant, good with rifles and melee - NC_BARTENDER, // Stocks alcohol - NC_JUNK_SHOPKEEP, // Stocks wide range of items... - NC_HALLU // Hallucinatory NPCs - } -}; - static generic_factory npc_class_factory( "npc_class" ); /** @relates string_id */ @@ -81,7 +38,7 @@ bool string_id::is_valid() const return npc_class_factory.is_valid( *this ); } -npc_class::npc_class() : id( NC_NONE ) +npc_class::npc_class() : id( npc_class_id::NULL_ID() ) { } @@ -134,13 +91,6 @@ void npc_class::finalize_all() void npc_class::check_consistency() { - for( const npc_class_id &legacy : legacy_ids ) { - if( !npc_class_factory.is_valid( legacy ) ) { - debugmsg( "Missing legacy npc class %s (at index %d)", - legacy.c_str(), &legacy - legacy_ids.data() ); - } - } - for( const npc_class &cl : npc_class_factory.get_all() ) { for( const shopkeeper_item_group &ig : cl.shop_item_groups ) { if( !item_group::group_is_defined( ig.id ) ) { @@ -373,16 +323,6 @@ void npc_class::load( const JsonObject &jo, const std::string_view ) } } -const npc_class_id &npc_class::from_legacy_int( int i ) -{ - if( i < 0 || static_cast( i ) >= legacy_ids.size() ) { - debugmsg( "Invalid legacy class id: %d", i ); - return npc_class_id::NULL_ID(); - } - - return legacy_ids[ i ]; -} - const std::vector &npc_class::get_all() { return npc_class_factory.get_all(); @@ -398,7 +338,7 @@ const npc_class_id &npc_class::random_common() } if( common_classes.empty() || one_in( common_classes.size() ) ) { - return NC_NONE; + return npc_class_id::NULL_ID(); } return *random_entry( common_classes ); diff --git a/src/npc_class.h b/src/npc_class.h index af07c213fc984..6df827bce3867 100644 --- a/src/npc_class.h +++ b/src/npc_class.h @@ -140,8 +140,6 @@ class npc_class void load( const JsonObject &jo, std::string_view src ); - static const npc_class_id &from_legacy_int( int i ); - static const npc_class_id &random_common(); static void load_npc_class( const JsonObject &jo, const std::string &src ); @@ -155,25 +153,4 @@ class npc_class static void check_consistency(); }; -// TODO: Get rid of that -extern const npc_class_id NC_NONE; -extern const npc_class_id NC_EVAC_SHOPKEEP; -extern const npc_class_id NC_SHOPKEEP; -extern const npc_class_id NC_HACKER; -extern const npc_class_id NC_CYBORG; -extern const npc_class_id NC_DOCTOR; -extern const npc_class_id NC_TRADER; -extern const npc_class_id NC_NINJA; -extern const npc_class_id NC_COWBOY; -extern const npc_class_id NC_SCIENTIST; -extern const npc_class_id NC_BOUNTY_HUNTER; -extern const npc_class_id NC_THUG; -extern const npc_class_id NC_SCAVENGER; -extern const npc_class_id NC_ARSONIST; -extern const npc_class_id NC_HUNTER; -extern const npc_class_id NC_SOLDIER; -extern const npc_class_id NC_BARTENDER; -extern const npc_class_id NC_JUNK_SHOPKEEP; -extern const npc_class_id NC_HALLU; - #endif // CATA_SRC_NPC_CLASS_H diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index cf3820a4b6366..41e1102e49d93 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -97,7 +97,6 @@ #include "mtype.h" #include "mutation.h" #include "npc.h" -#include "npc_class.h" #include "options.h" #include "overmapbuffer.h" #include "pimpl.h" @@ -2077,12 +2076,10 @@ void npc::load( const JsonObject &data ) } int misstmp = 0; - int classtmp = 0; int atttmp = 0; std::string facID; std::string comp_miss_role; tripoint_abs_omt comp_miss_pt; - std::string classid; std::string companion_mission_role; time_point companion_mission_t = calendar::turn_zero; time_point companion_mission_t_r = calendar::turn_zero; @@ -2100,12 +2097,8 @@ void npc::load( const JsonObject &data ) data.read( "marked_for_death", marked_for_death ); data.read( "dead", dead ); data.read( "patience", patience ); - if( data.has_number( "myclass" ) ) { - data.read( "myclass", classtmp ); - myclass = npc_class::from_legacy_int( classtmp ); - } else if( data.has_string( "myclass" ) ) { - data.read( "myclass", classid ); - myclass = npc_class_id( classid ); + if( data.has_string( "myclass" ) ) { + data.read( "myclass", myclass ); } if( data.has_string( "idz" ) ) { data.read( "idz", idz ); @@ -3607,11 +3600,8 @@ void mission::deserialize( const JsonObject &jo ) target_id = string_id( omid ); } - if( jo.has_int( "recruit_class" ) ) { - recruit_class = npc_class::from_legacy_int( jo.get_int( "recruit_class" ) ); - } else { - recruit_class = npc_class_id( jo.get_string( "recruit_class", "NC_NONE" ) ); - } + recruit_class = jo.has_string( "recruit_class" ) ? npc_class_id( jo.get_string( "recruit_class" ) ) + : npc_class_id::NULL_ID(); jo.read( "target_npc_id", target_npc_id ); jo.read( "monster_type", monster_type ); diff --git a/tests/npc_shopkeeper_item_groups_test.cpp b/tests/npc_shopkeeper_item_groups_test.cpp index 835306d13e811..f89fdc41359de 100644 --- a/tests/npc_shopkeeper_item_groups_test.cpp +++ b/tests/npc_shopkeeper_item_groups_test.cpp @@ -60,7 +60,7 @@ TEST_CASE( "npc_shopkeeper_item_groups", "[npc][trade]" ) item_location const scrap_inv = guy.i_add( scrap ); REQUIRE( scrap_inv ); THEN( "sell_belongings is true - item in inventory available for sale" ) { - guy.myclass = NC_NONE; + guy.myclass = npc_class_id::NULL_ID(); REQUIRE( guy.myclass->sells_belongings == true ); REQUIRE( guy.wants_to_sell( scrap_inv ) ); } diff --git a/tests/npc_talk_test.cpp b/tests/npc_talk_test.cpp index dc4275b8d738a..6eec1589368b3 100644 --- a/tests/npc_talk_test.cpp +++ b/tests/npc_talk_test.cpp @@ -52,7 +52,6 @@ static const itype_id itype_manual_speech( "manual_speech" ); static const mtype_id mon_zombie_bio_op( "mon_zombie_bio_op" ); -static const npc_class_id NC_NONE( "NC_NONE" ); static const npc_class_id NC_TEST_CLASS( "NC_TEST_CLASS" ); static const proficiency_id proficiency_prof_test( "prof_test" ); @@ -378,7 +377,7 @@ TEST_CASE( "npc_talk_class", "[npc_talk]" ) npc &talker_npc = prep_test( d ); d.add_topic( "TALK_TEST_NPC_CLASS" ); - talker_npc.myclass = NC_NONE; + talker_npc.myclass = npc_class_id::NULL_ID(); gen_response_lines( d, 1 ); CHECK( d.responses[0].text == "This is a basic test response." ); talker_npc.myclass = NC_TEST_CLASS; @@ -1010,7 +1009,7 @@ TEST_CASE( "npc_talk_effects", "[npc_talk]" ) gen_response_lines( d, 19 ); talk_effect_t &effects = d.responses[18].success; effects.apply( d ); - CHECK( talker_npc.myclass == NC_NONE ); + CHECK( talker_npc.myclass == npc_class_id::NULL_ID() ); } TEST_CASE( "npc_change_topic", "[npc_talk]" ) diff --git a/tests/npc_test.cpp b/tests/npc_test.cpp index 5e86991fbbafd..2530efe425275 100644 --- a/tests/npc_test.cpp +++ b/tests/npc_test.cpp @@ -21,7 +21,6 @@ #include "map_helpers.h" #include "memory_fast.h" #include "npc.h" -#include "npc_class.h" #include "npctalk.h" #include "overmapbuffer.h" #include "pathfinding.h" @@ -75,7 +74,7 @@ static npc create_model() { npc model_npc; model_npc.normalize(); - model_npc.randomize( NC_NONE ); + model_npc.randomize( npc_class_id::NULL_ID() ); for( const trait_id &tr : model_npc.get_mutations() ) { model_npc.unset_mutation( tr ); }