From c2ba6dba6c9d117f9bf4e946e25150c907dadda4 Mon Sep 17 00:00:00 2001 From: Ramza13 <52087122+Ramza13@users.noreply.github.com> Date: Wed, 19 Feb 2020 15:10:02 -0500 Subject: [PATCH] Move string consts --- src/avatar.cpp | 2 +- src/cata_string_consts.h | 14 ++++++++++---- src/character.cpp | 4 ++-- src/consumption.cpp | 4 ++-- src/debug_menu.cpp | 4 ++-- src/faction.cpp | 5 +++-- src/game.cpp | 8 ++++---- src/game_inventory.cpp | 2 +- src/item.cpp | 4 ++-- src/npc.cpp | 10 +++++----- src/npctalk.cpp | 2 +- src/npctalk_funcs.cpp | 6 +++--- src/player.cpp | 4 ++-- src/suffer.cpp | 8 ++++---- src/veh_interact.cpp | 2 +- tests/stomach_contents_test.cpp | 27 ++++++++++++++------------- 16 files changed, 57 insertions(+), 49 deletions(-) diff --git a/src/avatar.cpp b/src/avatar.cpp index c52af877b5dcc..dea5853d96a54 100644 --- a/src/avatar.cpp +++ b/src/avatar.cpp @@ -1354,7 +1354,7 @@ void avatar::upgrade_stat_prompt( const Character::stat &stat ) faction *avatar::get_faction() const { - return g->faction_manager_ptr->get( faction_id( "your_followers" ) ); + return g->faction_manager_ptr->get( faction_your_followers ); } void avatar::set_movement_mode( character_movemode new_mode ) diff --git a/src/cata_string_consts.h b/src/cata_string_consts.h index cda318081a5ff..dd253ba236273 100644 --- a/src/cata_string_consts.h +++ b/src/cata_string_consts.h @@ -1406,15 +1406,17 @@ static const std::string part_location_onroof( "on_roof" ); static const std::string GUN_MODE_VAR_NAME( "item::mode" ); static const std::string CLOTHING_MOD_VAR_PREFIX( "clothing_mod_" ); -static const faction_id your_followers( "your_followers" ); -static const faction_id no_faction( "no_faction" ); +static const faction_id faction_amf( "amf" ); +static const faction_id faction_your_followers( "your_followers" ); +static const faction_id faction_no_faction( "no_faction" ); static const std::string errstring( "ERROR" ); -static const ammotype ammo_bolt( "bolt" ); static const ammotype ammo_battery( "battery" ); -static const ammotype ammo_reactor_slurry( "reactor_slurry" ); +static const ammotype ammo_bolt( "bolt" ); +static const ammotype ammo_money( "money" ); static const ammotype ammo_plutonium( "plutonium" ); +static const ammotype ammo_reactor_slurry( "reactor_slurry" ); static const std::string title_BIONICS = translate_marker( "BIONICS" ); static const std::string title_EFFECTS = translate_marker( "EFFECTS" ); @@ -1424,7 +1426,11 @@ static const std::string title_SPEED = translate_marker( "SPEED" ); static const std::string title_STATS = translate_marker( "STATS" ); static const std::string title_TRAITS = translate_marker( "TRAITS" ); +const vitamin_id vitamin_calcium( "calcium" ); const vitamin_id vitamin_iron( "iron" ); +const vitamin_id vitamin_vitA( "vitA" ); +const vitamin_id vitamin_vitB( "vitB" ); +const vitamin_id vitamin_vitC( "vitC" ); static const std::string null_item_id( "null" ); diff --git a/src/character.cpp b/src/character.cpp index c49a18314e3a5..497ab9fe4cd83 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -7754,8 +7754,8 @@ void Character::rooted() if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) ) && g->m.has_flag( flag_PLOWABLE, pos() ) && shoe_factor != 1.0 ) { if( one_in( 96 ) ) { - vitamin_mod( vitamin_id( "iron" ), 1, true ); - vitamin_mod( vitamin_id( "calcium" ), 1, true ); + vitamin_mod( vitamin_iron, 1, true ); + vitamin_mod( vitamin_calcium, 1, true ); } if( get_thirst() <= -2000 && x_in_y( 75, 425 ) ) { mod_thirst( -1 ); diff --git a/src/consumption.cpp b/src/consumption.cpp index 06821eb763823..cdae5d7c7bd03 100644 --- a/src/consumption.cpp +++ b/src/consumption.cpp @@ -1245,8 +1245,8 @@ hint_rating Character::rate_action_eat( const item &it ) const bool Character::can_feed_reactor_with( const item &it ) const { static const std::set acceptable = {{ - ammotype( "reactor_slurry" ), - ammotype( "plutonium" ) + ammo_reactor_slurry, + ammo_plutonium } }; diff --git a/src/debug_menu.cpp b/src/debug_menu.cpp index a4d1b1d81cadc..6db651603ad41 100644 --- a/src/debug_menu.cpp +++ b/src/debug_menu.cpp @@ -1130,8 +1130,8 @@ void debug() new_fac_id += temp->name; // create a new "lone wolf" faction for this one NPC faction *new_solo_fac = g->faction_manager_ptr->add_new_faction( temp->name, - faction_id( new_fac_id ), faction_id( "no_faction" ) ); - temp->set_fac( new_solo_fac ? new_solo_fac->id : faction_id( "no_faction" ) ); + faction_id( new_fac_id ), faction_no_faction ); + temp->set_fac( new_solo_fac ? new_solo_fac->id : faction_no_faction ); g->load_npcs(); } break; diff --git a/src/faction.cpp b/src/faction.cpp index 788fadeeb7710..d30a365f8b6a2 100644 --- a/src/faction.cpp +++ b/src/faction.cpp @@ -32,6 +32,7 @@ #include "pimpl.h" #include "type_id.h" #include "point.h" +#include "cata_string_consts.h" namespace npc_factions { @@ -415,7 +416,7 @@ faction *faction_manager::add_new_faction( const std::string &name_new, const fa faction *faction_manager::get( const faction_id &id, const bool complain ) { if( id.is_null() ) { - return get( faction_id( "no_faction" ) ); + return get( faction_no_faction ); } for( auto &elem : factions ) { if( elem.first == id ) { @@ -706,7 +707,7 @@ void faction_manager::display() const } std::vector valfac; // Factions that we know of. for( const auto &elem : g->faction_manager_ptr->all() ) { - if( elem.second.known_by_u && elem.second.id != faction_id( "your_followers" ) ) { + if( elem.second.known_by_u && elem.second.id != faction_your_followers ) { valfac.push_back( &elem.second ); } } diff --git a/src/game.cpp b/src/game.cpp index abe8e801f6a15..6e2342f8c9b74 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -895,7 +895,7 @@ void game::create_starting_npcs() tmp->mission = NPC_MISSION_SHELTER; tmp->chatbin.first_topic = "TALK_SHELTER"; tmp->toggle_trait( trait_NPC_STARTING_NPC ); - tmp->set_fac( no_faction ); + tmp->set_fac( faction_no_faction ); //One random starting NPC mission tmp->add_new_mission( mission::reserve_random( ORIGIN_OPENER_NPC, tmp->global_omt_location(), tmp->getID() ) ); @@ -1791,7 +1791,7 @@ void game::remove_npc_follower( const character_id &id ) static void update_faction_api( npc *guy ) { if( guy->get_faction_ver() < 2 ) { - guy->set_fac( your_followers ); + guy->set_fac( faction_your_followers ); guy->set_faction_ver( 2 ); } } @@ -10864,8 +10864,8 @@ void game::perhaps_add_random_npc() new_fac_id += tmp->name; // create a new "lone wolf" faction for this one NPC faction *new_solo_fac = faction_manager_ptr->add_new_faction( tmp->name, faction_id( new_fac_id ), - no_faction ); - tmp->set_fac( new_solo_fac ? new_solo_fac->id : no_faction ); + faction_no_faction ); + tmp->set_fac( new_solo_fac ? new_solo_fac->id : faction_no_faction ); // adds the npc to the correct overmap. tripoint submap_spawn = omt_to_sm_copy( spawn_point ); tmp->spawn_at_sm( submap_spawn.x, submap_spawn.y, 0 ); diff --git a/src/game_inventory.cpp b/src/game_inventory.cpp index c04c896ac48d0..4a42e61c72d18 100644 --- a/src/game_inventory.cpp +++ b/src/game_inventory.cpp @@ -1615,7 +1615,7 @@ class bionic_install_preset: public inventory_selector_preset } else if( it->has_flag( flag_NO_STERILE ) ) { // NOLINTNEXTLINE(cata-text-style): single space after the period for symmetry return _( "/!\\ CBM is not sterile. /!\\ Please use autoclave to sterilize." ); - } else if( it->has_fault( fault_id( "fault_bionic_salvaged" ) ) ) { + } else if( it->has_fault( fault_bionic_salvaged ) ) { return _( "CBM already deployed. Please reset to factory state." ); } else if( pa.has_bionic( bid ) ) { return _( "CBM already installed" ); diff --git a/src/item.cpp b/src/item.cpp index f4c867a691acb..4004147377887 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -5204,7 +5204,7 @@ bool item::ready_to_revive( const tripoint &pos ) const bool item::is_money() const { - return ammo_types().count( ammotype( "money" ) ); + return ammo_types().count( ammo_money ); } bool item::count_by_charges() const @@ -6397,7 +6397,7 @@ gun_type_type item::gun_type() const // TODO: move to JSON and remove extraction of this from "GUN" (via skill id) //and from "GUNMOD" (via "mod_targets") in lang/extract_json_strings.py if( gun_skill() == skill_archery ) { - if( ammo_types().count( ammotype( "bolt" ) ) || typeId() == "bullet_crossbow" ) { + if( ammo_types().count( ammo_bolt ) || typeId() == "bullet_crossbow" ) { return gun_type_type( translate_marker_context( "gun_type_type", "crossbow" ) ); } else { return gun_type_type( translate_marker_context( "gun_type_type", "bow" ) ); diff --git a/src/npc.cpp b/src/npc.cpp index c0ec9b68fda0d..23ee75d615c5c 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -437,7 +437,7 @@ faction_id npc::get_fac_id() const faction *npc::get_faction() const { if( !my_fac ) { - return g->faction_manager_ptr->get( faction_id( "no_faction" ) ); + return g->faction_manager_ptr->get( faction_no_faction ); } return my_fac; } @@ -844,7 +844,7 @@ void npc::finish_read( item &book ) const skill_id &skill = reading->skill; // NPCs dont need to identify the book or learn recipes yet. // NPCs dont read to other NPCs yet. - const bool display_messages = my_fac->id == faction_id( "your_followers" ) && g->u.sees( pos() ); + const bool display_messages = my_fac->id == faction_your_followers && g->u.sees( pos() ); bool continuous = false; //whether to continue reading or not std::set little_learned; // NPCs who learned a little about the skill std::set cant_learn; @@ -1278,7 +1278,7 @@ void npc::mutiny() // feel for you, but also reduces their respect for you. my_fac->likes_u = std::max( 0, my_fac->likes_u / 2 + 10 ); my_fac->respects_u -= 5; - set_fac( faction_id( "amf" ) ); + set_fac( faction_amf ); say( _( " Adios, motherfucker!" ), sounds::sound_t::order ); if( seen ) { my_fac->known_by_u = true; @@ -1346,7 +1346,7 @@ void npc::make_angry() } // Make associated faction, if any, angry at the player too. - if( my_fac && my_fac->id != faction_id( "no_faction" ) && my_fac->id != faction_id( "amf" ) ) { + if( my_fac && my_fac->id != faction_no_faction && my_fac->id != faction_amf ) { my_fac->likes_u = std::min( -15, my_fac->likes_u - 5 ); my_fac->respects_u = std::min( -15, my_fac->respects_u - 5 ); } @@ -1865,7 +1865,7 @@ bool npc::is_ally( const player &p ) const return true; } if( p.is_player() ) { - if( my_fac && my_fac->id == faction_id( "your_followers" ) ) { + if( my_fac && my_fac->id == faction_your_followers ) { return true; } if( faction_api_version < 2 ) { diff --git a/src/npctalk.cpp b/src/npctalk.cpp index 057d64175f359..e35ba847f096d 100644 --- a/src/npctalk.cpp +++ b/src/npctalk.cpp @@ -2064,7 +2064,7 @@ void talk_effect_fun_t::set_change_faction_rep( int rep_change ) { function = [rep_change]( const dialogue & d ) { npc &p = *d.beta; - if( p.get_faction()->id != faction_id( "no_faction" ) ) { + if( p.get_faction()->id != faction_no_faction ) { p.get_faction()->likes_u += rep_change; p.get_faction()->respects_u += rep_change; } diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index 7ffe35dec2313..a9d0e4cb3de61 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -692,7 +692,7 @@ void talk_function::follow( npc &p ) { g->add_npc_follower( p.getID() ); p.set_attitude( NPCATT_FOLLOW ); - p.set_fac( faction_id( "your_followers" ) ); + p.set_fac( faction_your_followers ); g->u.cash += p.cash; p.cash = 0; } @@ -755,8 +755,8 @@ void talk_function::leave( npc &p ) new_fac_id += p.name; // create a new "lone wolf" faction for this one NPC faction *new_solo_fac = g->faction_manager_ptr->add_new_faction( p.name, - faction_id( new_fac_id ), faction_id( "no_faction" ) ); - p.set_fac( new_solo_fac ? new_solo_fac->id : faction_id( "no_faction" ) ); + faction_id( new_fac_id ), faction_no_faction ); + p.set_fac( new_solo_fac ? new_solo_fac->id : faction_no_faction ); if( new_solo_fac ) { new_solo_fac->known_by_u = true; } diff --git a/src/player.cpp b/src/player.cpp index 32e0a66ccb478..ce65b65c878d7 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2769,7 +2769,7 @@ bool player::add_faction_warning( const faction_id &id ) warning_record[id] = std::make_pair( 1, calendar::turn ); } faction *fac = g->faction_manager_ptr->get( id ); - if( fac != nullptr && is_player() && fac->id != faction_id( "no_faction" ) ) { + if( fac != nullptr && is_player() && fac->id != faction_no_faction ) { fac->likes_u -= 1; fac->respects_u -= 1; } @@ -5442,7 +5442,7 @@ void player::place_corpse() cbm.set_flag( "FILTHY" ); cbm.set_flag( "NO_STERILE" ); cbm.set_flag( "NO_PACKED" ); - cbm.faults.emplace( fault_id( "fault_bionic_salvaged" ) ); + cbm.faults.emplace( fault_bionic_salvaged ); body.put_in( cbm ); } } diff --git a/src/suffer.cpp b/src/suffer.cpp index 5cc31878cb9d4..c3a81480655ba 100644 --- a/src/suffer.cpp +++ b/src/suffer.cpp @@ -625,8 +625,8 @@ void Character::suffer_in_sunlight() } if( x_in_y( sunlight_nutrition, 18000 ) ) { - vitamin_mod( vitamin_id( "vitA" ), 1, true ); - vitamin_mod( vitamin_id( "vitC" ), 1, true ); + vitamin_mod( vitamin_vitA, 1, true ); + vitamin_mod( vitamin_vitC, 1, true ); } if( x_in_y( sunlight_nutrition, 12000 ) ) { @@ -796,8 +796,8 @@ void Character::suffer_from_other_mutations() } if( x_in_y( root_vitamins, 576 ) ) { - vitamin_mod( vitamin_id( "iron" ), 1, true ); - vitamin_mod( vitamin_id( "calcium" ), 1, true ); + vitamin_mod( vitamin_iron, 1, true ); + vitamin_mod( vitamin_calcium, 1, true ); mod_healthy_mod( 5, 50 ); } diff --git a/src/veh_interact.cpp b/src/veh_interact.cpp index 7b6d6a9b4acab..a1a8dfe8fe04b 100644 --- a/src/veh_interact.cpp +++ b/src/veh_interact.cpp @@ -316,7 +316,7 @@ void veh_interact::do_main_loop() if( veh->has_owner() ) { owner_fac = g->faction_manager_ptr->get( veh->get_owner() ); } else { - owner_fac = g->faction_manager_ptr->get( faction_id( "no_faction" ) ); + owner_fac = g->faction_manager_ptr->get( faction_no_faction ); } while( !finish ) { overview(); diff --git a/tests/stomach_contents_test.cpp b/tests/stomach_contents_test.cpp index 8bca831c1d6e1..6b14e9993eee3 100644 --- a/tests/stomach_contents_test.cpp +++ b/tests/stomach_contents_test.cpp @@ -11,6 +11,7 @@ #include "stomach.h" #include "units.h" #include "type_id.h" +#include "cata_string_consts.h" static void reset_time() { @@ -37,11 +38,11 @@ static void clear_stomach( player &p ) static void set_all_vitamins( int target, player &p ) { - p.vitamin_set( vitamin_id( "vitA" ), target ); - p.vitamin_set( vitamin_id( "vitB" ), target ); - p.vitamin_set( vitamin_id( "vitC" ), target ); - p.vitamin_set( vitamin_id( "iron" ), target ); - p.vitamin_set( vitamin_id( "calcium" ), target ); + p.vitamin_set( vitamin_vitA, target ); + p.vitamin_set( vitamin_vitB, target ); + p.vitamin_set( vitamin_vitC, target ); + p.vitamin_set( vitamin_iron, target ); + p.vitamin_set( vitamin_calcium, target ); } // time (in minutes) it takes for the player to feel hungry @@ -172,9 +173,9 @@ TEST_CASE( "all_nutrition_starve_test" ) } if( print_tests ) { printf( "vitamins: vitA %d vitB %d vitC %d calcium %d iron %d\n", - dummy.vitamin_get( vitamin_id( "vitA" ) ), dummy.vitamin_get( vitamin_id( "vitB" ) ), - dummy.vitamin_get( vitamin_id( "vitC" ) ), dummy.vitamin_get( vitamin_id( "calcium" ) ), - dummy.vitamin_get( vitamin_id( "iron" ) ) ); + dummy.vitamin_get( vitamin_vitA ), dummy.vitamin_get( vitamin_vitB ), + dummy.vitamin_get( vitamin_vitC ), dummy.vitamin_get( vitamin_calcium ), + dummy.vitamin_get( vitamin_iron ) ); printf( "\n" ); print_stomach_contents( dummy, print_tests ); printf( "\n" ); @@ -182,11 +183,11 @@ TEST_CASE( "all_nutrition_starve_test" ) CHECK( dummy.get_stored_kcal() >= dummy.get_healthy_kcal() ); // We need to account for a day's worth of error since we're passing a day at a time and we are // close to 0 which is the max value for some vitamins - CHECK( dummy.vitamin_get( vitamin_id( "vitA" ) ) >= -100 ); - CHECK( dummy.vitamin_get( vitamin_id( "vitB" ) ) >= -100 ); - CHECK( dummy.vitamin_get( vitamin_id( "vitC" ) ) >= -100 ); - CHECK( dummy.vitamin_get( vitamin_id( "iron" ) ) >= -100 ); - CHECK( dummy.vitamin_get( vitamin_id( "calcium" ) ) >= -100 ); + CHECK( dummy.vitamin_get( vitamin_vitA ) >= -100 ); + CHECK( dummy.vitamin_get( vitamin_vitB ) >= -100 ); + CHECK( dummy.vitamin_get( vitamin_vitC ) >= -100 ); + CHECK( dummy.vitamin_get( vitamin_iron ) >= -100 ); + CHECK( dummy.vitamin_get( vitamin_calcium ) >= -100 ); } TEST_CASE( "tape_worm_halves_nutrients" )