Skip to content

Commit

Permalink
Merge pull request CleverRaven#38168 from Ramza13/even_more_string_co…
Browse files Browse the repository at this point in the history
…nsts

Move string consts into single file
  • Loading branch information
ZhilkinSerg authored Feb 20, 2020
2 parents 24a32c0 + c2ba6db commit 2bf1c1e
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
14 changes: 10 additions & 4 deletions src/cata_string_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1429,15 +1429,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" );
Expand All @@ -1447,7 +1449,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" );

Expand Down
4 changes: 2 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7752,8 +7752,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 );
Expand Down
4 changes: 2 additions & 2 deletions src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ammotype> acceptable = {{
ammotype( "reactor_slurry" ),
ammotype( "plutonium" )
ammo_reactor_slurry,
ammo_plutonium
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/faction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "pimpl.h"
#include "type_id.h"
#include "point.h"
#include "cata_string_consts.h"

namespace npc_factions
{
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -706,7 +707,7 @@ void faction_manager::display() const
}
std::vector<const faction *> 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 );
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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 );
}
}
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down
4 changes: 2 additions & 2 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" ) );
Expand Down
10 changes: 5 additions & 5 deletions src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<std::string> little_learned; // NPCs who learned a little about the skill
std::set<std::string> cant_learn;
Expand Down Expand Up @@ -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( _( "<follower_mutiny> Adios, motherfucker!" ), sounds::sound_t::order );
if( seen ) {
my_fac->known_by_u = true;
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,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;
}
Expand Down Expand Up @@ -5441,7 +5441,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 );
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/suffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
27 changes: 14 additions & 13 deletions tests/stomach_contents_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "stomach.h"
#include "units.h"
#include "type_id.h"
#include "cata_string_consts.h"

static void reset_time()
{
Expand All @@ -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
Expand Down Expand Up @@ -172,21 +173,21 @@ 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" );
}
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" )
Expand Down

0 comments on commit 2bf1c1e

Please sign in to comment.