Skip to content

Commit

Permalink
Merge pull request #40637 from jbytheway/string_id_itype
Browse files Browse the repository at this point in the history
Convert itype_id to string_id<itype>
  • Loading branch information
kevingranade authored May 20, 2020
2 parents 11c8cb9 + a1e0ed8 commit 2647a67
Show file tree
Hide file tree
Showing 175 changed files with 2,196 additions and 1,626 deletions.
2 changes: 1 addition & 1 deletion src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ bool can_move_vertical_at( const tripoint &p, int movez )
if( movez == -1 ) {
return !g->u.is_underwater() && !g->u.worn_with_flag( flag_FLOTATION );
} else {
return g->u.swim_speed() < 500 || g->u.is_wearing( "swim_fins" );
return g->u.swim_speed() < 500 || g->u.is_wearing( itype_id( "swim_fins" ) );
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

static const bionic_id bio_fingerhack( "bio_fingerhack" );

static const itype_id itype_bone_human( "bone_human" );
static const itype_id itype_electrohack( "electrohack" );

static const skill_id skill_computer( "computer" );

static const trait_id trait_ILLITERATE( "ILLITERATE" );
Expand Down Expand Up @@ -76,7 +79,7 @@ void dig_activity_actor::finish( player_activity &act, Character &who )
g->m.furn_set( location, f_coffin_o );
who.add_msg_if_player( m_warning, _( "Something crawls out of the coffin!" ) );
} else {
g->m.spawn_item( location, "bone_human", rng( 5, 15 ) );
g->m.spawn_item( location, itype_bone_human, rng( 5, 15 ) );
g->m.furn_set( location, f_coffin_c );
}
std::vector<item *> dropped = g->m.place_items( "allclothes", 50, location, location, false,
Expand Down Expand Up @@ -244,7 +247,7 @@ static hack_result hack_attempt( Character &who )
if( who.has_trait( trait_ILLITERATE ) ) {
return HACK_UNABLE;
}
const bool using_electrohack = who.has_charges( "electrohack", 25 ) &&
const bool using_electrohack = who.has_charges( itype_electrohack, 25 ) &&
query_yn( _( "Use electrohack?" ) );
const bool using_fingerhack = !using_electrohack && who.has_bionic( bio_fingerhack ) &&
who.get_power_level() > 24_kJ && query_yn( _( "Use fingerhack?" ) );
Expand All @@ -261,7 +264,7 @@ static hack_result hack_attempt( Character &who )
if( using_fingerhack ) {
who.mod_power_level( -25_kJ );
} else {
who.use_charges( "electrohack", 25 );
who.use_charges( itype_electrohack, 25 );
}

// only skilled supergenius never cause short circuits, but the odds are low for people
Expand All @@ -273,13 +276,13 @@ static hack_result hack_attempt( Character &who )
if( using_fingerhack ) {
who.mod_power_level( -25_kJ );
} else {
who.use_charges( "electrohack", 25 );
who.use_charges( itype_electrohack, 25 );
}

if( success <= -5 ) {
if( using_electrohack ) {
who.add_msg_if_player( m_bad, _( "Your electrohack is ruined!" ) );
who.use_amount( "electrohack", 1 );
who.use_amount( itype_electrohack, 1 );
} else {
who.add_msg_if_player( m_bad, _( "Your power is drained!" ) );
who.mod_power_level( units::from_kilojoule( -rng( 25,
Expand Down
168 changes: 101 additions & 67 deletions src/activity_handlers.cpp

Large diffs are not rendered by default.

48 changes: 29 additions & 19 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ static const activity_id ACT_VEHICLE_REPAIR( "ACT_VEHICLE_REPAIR" );
static const efftype_id effect_pet( "pet" );
static const efftype_id effect_nausea( "nausea" );

static const itype_id itype_battery( "battery" );
static const itype_id itype_detergent( "detergent" );
static const itype_id itype_log( "log" );
static const itype_id itype_soap( "soap" );
static const itype_id itype_soldering_iron( "soldering_iron" );
static const itype_id itype_water( "water" );
static const itype_id itype_water_clean( "water_clean" );
static const itype_id itype_welder( "welder" );

static const trap_str_id tr_firewood_source( "tr_firewood_source" );
static const trap_str_id tr_unfinished_construction( "tr_unfinished_construction" );

Expand Down Expand Up @@ -564,14 +573,14 @@ void activity_handlers::washing_finish( player_activity *act, player *p )
return is_crafting_component( it ) && ( !it.count_by_charges() || it.made_of( LIQUID ) );
};
const inventory &crafting_inv = p->crafting_inventory();
if( !crafting_inv.has_charges( "water", required.water, is_liquid_crafting_component ) &&
!crafting_inv.has_charges( "water_clean", required.water, is_liquid_crafting_component ) ) {
if( !crafting_inv.has_charges( itype_water, required.water, is_liquid_crafting_component ) &&
!crafting_inv.has_charges( itype_water_clean, required.water, is_liquid_crafting_component ) ) {
p->add_msg_if_player( _( "You need %1$i charges of water or clean water to wash these items." ),
required.water );
act->set_to_null();
return;
} else if( !crafting_inv.has_charges( "soap", required.cleanser ) &&
!crafting_inv.has_charges( "detergent", required.cleanser ) ) {
} else if( !crafting_inv.has_charges( itype_soap, required.cleanser ) &&
!crafting_inv.has_charges( itype_detergent, required.cleanser ) ) {
p->add_msg_if_player( _( "You need %1$i charges of cleansing agent to wash these items." ),
required.cleanser );
act->set_to_null();
Expand All @@ -585,13 +594,13 @@ void activity_handlers::washing_finish( player_activity *act, player *p )
}

std::vector<item_comp> comps;
comps.push_back( item_comp( "water", required.water ) );
comps.push_back( item_comp( "water_clean", required.water ) );
comps.push_back( item_comp( itype_water, required.water ) );
comps.push_back( item_comp( itype_water_clean, required.water ) );
p->consume_items( comps, 1, is_liquid_crafting_component );

std::vector<item_comp> comps1;
comps1.push_back( item_comp( "soap", required.cleanser ) );
comps1.push_back( item_comp( "detergent", required.cleanser ) );
comps1.push_back( item_comp( itype_soap, required.cleanser ) );
comps1.push_back( item_comp( itype_detergent, required.cleanser ) );
p->consume_items( comps1 );

p->add_msg_if_player( m_good, _( "You washed your items." ) );
Expand Down Expand Up @@ -1048,12 +1057,12 @@ static bool are_requirements_nearby( const std::vector<tripoint> &loot_spots,
vehicle &veh = vp->vehicle();
const cata::optional<vpart_reference> weldpart = vp.part_with_feature( "WELDRIG", true );
if( weldpart ) {
item welder( "welder", 0 );
welder.charges = veh.fuel_left( "battery", true );
item welder( itype_welder, 0 );
welder.charges = veh.fuel_left( itype_battery, true );
welder.item_tags.insert( "PSEUDO" );
temp_inv.add_item( welder );
item soldering_iron( "soldering_iron", 0 );
soldering_iron.charges = veh.fuel_left( "battery", true );
item soldering_iron( itype_soldering_iron, 0 );
soldering_iron.charges = veh.fuel_left( itype_battery, true );
soldering_iron.item_tags.insert( "PSEUDO" );
temp_inv.add_item( soldering_iron );
}
Expand Down Expand Up @@ -1293,7 +1302,7 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
if( act == ACT_MULTIPLE_CHOP_PLANKS ) {
//are there even any logs there?
for( auto &i : g->m.i_at( src_loc ) ) {
if( i.typeId() == "log" ) {
if( i.typeId() == itype_log ) {
// do we have an axe?
if( p.has_quality( qual_AXE, 1 ) ) {
return activity_reason_info::ok( do_activity_reason::NEEDS_CHOPPING );
Expand Down Expand Up @@ -1357,10 +1366,10 @@ static activity_reason_info can_do_activity_there( const activity_id &act, playe
} else {
// do we have the required seed on our person?
const plot_options &options = dynamic_cast<const plot_options &>( zone.get_options() );
const std::string seed = options.get_seed();
const itype_id seed = options.get_seed();
// If its a farm zone with no specified seed, and we've checked for tilling and harvesting.
// then it means no further work can be done here
if( seed.empty() ) {
if( seed.is_empty() ) {
return activity_reason_info::fail( do_activity_reason::ALREADY_DONE );
}
std::vector<item *> seed_inv = p.items_with( []( const item & itm ) {
Expand Down Expand Up @@ -1686,8 +1695,8 @@ static std::vector<std::tuple<tripoint, itype_id, int>> requirements_map( player
}
}
for( const std::tuple<tripoint, itype_id, int> &elem : final_map ) {
add_msg( m_debug, "%s is fetching %s from x: %d y: %d ", p.disp_name(), std::get<1>( elem ),
std::get<0>( elem ).x, std::get<0>( elem ).y );
add_msg( m_debug, "%s is fetching %s from x: %d y: %d ", p.disp_name(),
std::get<1>( elem ).str(), std::get<0>( elem ).x, std::get<0>( elem ).y );
}
return final_map;
}
Expand Down Expand Up @@ -1903,7 +1912,7 @@ static bool chop_plank_activity( player &p, const tripoint &src_loc )
p.consume_charges( *best_qual, best_qual->type->charges_to_use() );
}
for( auto &i : g->m.i_at( src_loc ) ) {
if( i.typeId() == "log" ) {
if( i.typeId() == itype_log ) {
g->m.i_rem( src_loc, &i );
int moves = to_moves<int>( 20_minutes );
p.add_msg_if_player( _( "You cut the log into planks." ) );
Expand Down Expand Up @@ -2637,7 +2646,8 @@ static bool generic_multi_activity_do( player &p, const activity_id &act_id,
std::vector<zone_data> zones = mgr.get_zones( zone_type_FARM_PLOT,
g->m.getabs( src_loc ) );
for( const zone_data &zone : zones ) {
const std::string seed = dynamic_cast<const plot_options &>( zone.get_options() ).get_seed();
const itype_id seed =
dynamic_cast<const plot_options &>( zone.get_options() ).get_seed();
std::vector<item *> seed_inv = p.items_with( [seed]( const item & itm ) {
return itm.typeId() == itype_id( seed );
} );
Expand Down
8 changes: 4 additions & 4 deletions src/advanced_inv_area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,14 @@ void advanced_inv_area::set_container( const advanced_inv_listitem *advitem )
uistate.adv_inv_container_index = advitem->idx;
uistate.adv_inv_container_type = it->typeId();
uistate.adv_inv_container_content_type = !it->is_container_empty() ?
it->contents.legacy_front().typeId() : "null";
it->contents.legacy_front().typeId() : itype_id::NULL_ID();
set_container_position();
} else {
uistate.adv_inv_container_location = -1;
uistate.adv_inv_container_index = 0;
uistate.adv_inv_container_in_vehicle = false;
uistate.adv_inv_container_type = "null";
uistate.adv_inv_container_content_type = "null";
uistate.adv_inv_container_type = itype_id::NULL_ID();
uistate.adv_inv_container_content_type = itype_id::NULL_ID();
}
}

Expand All @@ -345,7 +345,7 @@ bool advanced_inv_area::is_container_valid( const item *it ) const
if( it != nullptr ) {
if( it->typeId() == uistate.adv_inv_container_type ) {
if( it->is_container_empty() ) {
if( uistate.adv_inv_container_content_type == "null" ) {
if( uistate.adv_inv_container_content_type.is_null() ) {
return true;
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_listitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <list>
#include <string>

#include "type_id.h"
#include "units.h"

// see item_factory.h
Expand All @@ -21,7 +22,6 @@ enum aim_location : char;
class advanced_inv_listitem
{
public:
using itype_id = std::string;
/**
* Index of the item in the itemstack.
*/
Expand Down
8 changes: 5 additions & 3 deletions src/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "string_id.h"
#include "type_id.h"

static const itype_id itype_UPS( "UPS" );

namespace
{
using ammo_map_t = std::unordered_map<ammotype, ammunition_type>;
Expand All @@ -24,7 +26,7 @@ void ammunition_type::load_ammunition_type( const JsonObject &jsobj )
{
ammunition_type &res = all_ammunition_types()[ ammotype( jsobj.get_string( "id" ) ) ];
res.name_ = jsobj.get_string( "name" );
res.default_ammotype_ = jsobj.get_string( "default" );
jsobj.read( "default", res.default_ammotype_, true );
}

/** @relates string_id */
Expand Down Expand Up @@ -64,11 +66,11 @@ void ammunition_type::check_consistency()
const auto &at = ammo.second.default_ammotype_;

// TODO: these ammo types should probably not have default ammo at all.
if( at == "UPS" || at == "components" || at == "thrown" ) {
if( at == itype_UPS || at.str() == "components" || at.str() == "thrown" ) {
continue;
}

if( !at.empty() && !item::type_is_defined( at ) ) {
if( !at.is_empty() && !item::type_is_defined( at ) ) {
debugmsg( "ammo type %s has invalid default ammo %s", id.c_str(), at.c_str() );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/ammo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <string>
#include <utility>

class JsonObject;
#include"type_id.h"

using itype_id = std::string;
class JsonObject;

class ammunition_type
{
Expand Down
12 changes: 6 additions & 6 deletions src/artifact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ void it_artifact_armor::create_name( const std::string &type )
name = no_translation( artifact_name( type ) );
}

std::string new_artifact()
itype_id new_artifact()
{
if( one_in( 2 ) ) {
// Generate a "tool" artifact
Expand Down Expand Up @@ -920,7 +920,7 @@ std::string new_artifact()
}
}

std::string new_natural_artifact( artifact_natural_property prop )
itype_id new_natural_artifact( artifact_natural_property prop )
{
// Natural artifacts are always tools.
it_artifact_tool def;
Expand Down Expand Up @@ -1041,7 +1041,7 @@ std::string new_natural_artifact( artifact_natural_property prop )
}

// Make a special debugging artifact.
std::string architects_cube()
itype_id architects_cube()
{
it_artifact_tool def;

Expand Down Expand Up @@ -1136,7 +1136,7 @@ void load_artifacts( const std::string &path )

void it_artifact_tool::deserialize( const JsonObject &jo )
{
id = jo.get_string( "id" );
jo.read( "id", id, true );
name = no_translation( jo.get_string( "name" ) );
description = no_translation( jo.get_string( "description" ) );
if( jo.has_int( "sym" ) ) {
Expand Down Expand Up @@ -1188,7 +1188,7 @@ void it_artifact_tool::deserialize( const JsonObject &jo )
}

tool->revert_to.emplace( jo.get_string( "revert_to", "null" ) );
if( *tool->revert_to == "null" ) {
if( tool->revert_to->is_null() ) {
tool->revert_to.reset();
}

Expand Down Expand Up @@ -1244,7 +1244,7 @@ void it_artifact_tool::deserialize( const JsonObject &jo )

void it_artifact_armor::deserialize( const JsonObject &jo )
{
id = jo.get_string( "id" );
jo.read( "id", id, true );
name = no_translation( jo.get_string( "name" ) );
description = no_translation( jo.get_string( "description" ) );
if( jo.has_int( "sym" ) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/artifact.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ class it_artifact_armor : public itype

/* FUNCTIONS */

std::string new_artifact();
std::string new_natural_artifact( artifact_natural_property prop );
std::string architects_cube();
itype_id new_artifact();
itype_id new_natural_artifact( artifact_natural_property prop );
itype_id architects_cube();

// note: needs to be called by main() before MAPBUFFER.load
void load_artifacts( const std::string &path );
Expand Down
6 changes: 4 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static const efftype_id effect_slept_through_alarm( "slept_through_alarm" );
static const efftype_id effect_stim( "stim" );
static const efftype_id effect_stim_overdose( "stim_overdose" );

static const itype_id itype_guidebook( "guidebook" );

static const trait_id trait_ARACHNID_ARMS( "ARACHNID_ARMS" );
static const trait_id trait_ARACHNID_ARMS_OK( "ARACHNID_ARMS_OK" );
static const trait_id trait_CENOBITE( "CENOBITE" );
Expand Down Expand Up @@ -418,7 +420,7 @@ bool avatar::read( item &it, const bool continuous )
return true;
}

if( it.typeId() == "guidebook" ) {
if( it.typeId() == itype_guidebook ) {
// special guidebook effect: print a misc. hint when read
if( reader != this ) {
add_msg( m_info, fail_messages[0] );
Expand Down Expand Up @@ -922,7 +924,7 @@ void avatar::do_read( item &book )
activity.set_to_null();
}

bool avatar::has_identified( const std::string &item_id ) const
bool avatar::has_identified( const itype_id &item_id ) const
{
return items_identified.count( item_id ) > 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class avatar : public player
/** Completes book reading action. **/
void do_read( item &book );
/** Note that we've read a book at least once. **/
bool has_identified( const std::string &item_id ) const override;
bool has_identified( const itype_id &item_id ) const override;

hint_rating rate_action_read( const item &it ) const;

Expand Down Expand Up @@ -251,7 +251,7 @@ class avatar : public player
mission *active_mission;

// Items the player has identified.
std::unordered_set<std::string> items_identified;
std::unordered_set<itype_id> items_identified;

object_type grab_type;

Expand Down
Loading

0 comments on commit 2647a67

Please sign in to comment.