Skip to content

Commit

Permalink
Use constant references in function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhilkinSerg committed May 25, 2020
1 parent d327e41 commit df0cda9
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ static activity_reason_info find_base_construction(
const inventory &inv,
const tripoint &loc,
const cata::optional<construction_id> &part_con_idx,
const construction_id idx,
const construction_id &idx,
std::set<construction_id> &used )
{
const construction &build = idx.obj();
Expand Down
4 changes: 2 additions & 2 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ void avatar_action::fire_ranged_mutation( avatar &you, const item &fake_gun )
}

void avatar_action::fire_ranged_bionic( avatar &you, const item &fake_gun,
units::energy cost_per_shot )
const units::energy &cost_per_shot )
{
you.assign_activity( aim_activity_actor::use_bionic( fake_gun, cost_per_shot ), false );
}
Expand Down Expand Up @@ -950,7 +950,7 @@ void avatar_action::eat( avatar &you )
avatar_action::eat( you, loc, true );
}

void avatar_action::eat( avatar &you, item_location loc, bool open_consume_menu )
void avatar_action::eat( avatar &you, const item_location &loc, bool open_consume_menu )
{
if( !loc ) {
you.cancel_activity();
Expand Down
4 changes: 2 additions & 2 deletions src/avatar_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace avatar_action

/** Eat food or fuel 'E' (or 'a') */
void eat( avatar &you );
void eat( avatar &you, item_location loc, bool open_consume_menu = false );
void eat( avatar &you, const item_location &loc, bool open_consume_menu = false );
// special rules for eating: grazing etc
// returns false if no rules are needed
bool eat_here( avatar &you );
Expand Down Expand Up @@ -55,7 +55,7 @@ void fire_wielded_weapon( avatar &you );
void fire_ranged_mutation( avatar &you, const item &fake_gun );

/** Stores fake gun specified by the bionic and starts interactive aiming */
void fire_ranged_bionic( avatar &you, const item &fake_gun, units::energy cost_per_shot );
void fire_ranged_bionic( avatar &you, const item &fake_gun, const units::energy &cost_per_shot );

/**
* Checks if the player can manually (with their 2 hands, not via vehicle controls)
Expand Down
6 changes: 3 additions & 3 deletions src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ bool bionic_data::is_included( const bionic_id &id ) const
return std::find( included_bionics.begin(), included_bionics.end(), id ) != included_bionics.end();
}

void bionic_data::load( const JsonObject &jsobj, const std::string )
void bionic_data::load( const JsonObject &jsobj, const std::string & )
{

mandatory( jsobj, was_loaded, "id", id );
Expand Down Expand Up @@ -1942,7 +1942,7 @@ void Character::consume_anesth_requirment( const itype &cbm, player &patient )
invalidate_crafting_inventory();
}

bool Character::has_installation_requirment( bionic_id bid )
bool Character::has_installation_requirment( const bionic_id &bid )
{
if( bid->installation_requirement.is_empty() ) {
return false;
Expand All @@ -1960,7 +1960,7 @@ bool Character::has_installation_requirment( bionic_id bid )
return true;
}

void Character::consume_installation_requirment( bionic_id bid )
void Character::consume_installation_requirment( const bionic_id &bid )
{
for( const auto &e : bid->installation_requirement->get_components() ) {
as_player()->consume_items( e, 1, is_crafting_component );
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ struct bionic_data {
bool is_included( const bionic_id &id ) const;

bool was_loaded = false;
void load( const JsonObject &obj, std::string );
void load( const JsonObject &obj, const std::string & );
static void load_bionic( const JsonObject &jo, const std::string &src );
static const std::vector<bionic_data> &get_all();
static void check_bionic_consistency();
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ void Character::add_effect( const efftype_id &eff_id, const time_duration &dur,
Creature::add_effect( eff_id, dur, bp, permanent, intensity, force, deferred );
}

void Character::expose_to_disease( const diseasetype_id dis_type )
void Character::expose_to_disease( const diseasetype_id &dis_type )
{
const cata::optional<int> &healt_thresh = dis_type->health_threshold;
if( healt_thresh && healt_thresh.value() < get_healthy() ) {
Expand Down
6 changes: 3 additions & 3 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ class Character : public Creature, public visitable<Character>
int intensity = 0, bool force = false, bool deferred = false ) override;

/**Determine if character is susceptible to dis_type and if so apply the symptoms*/
void expose_to_disease( diseasetype_id dis_type );
void expose_to_disease( const diseasetype_id &dis_type );
/**
* Handles end-of-turn processing.
*/
Expand Down Expand Up @@ -1054,8 +1054,8 @@ class Character : public Creature, public visitable<Character>
bool has_enough_anesth( const itype &cbm );
void consume_anesth_requirment( const itype &cbm, player &patient );
/**Has the required equipement for manual installation*/
bool has_installation_requirment( bionic_id bid );
void consume_installation_requirment( bionic_id bid );
bool has_installation_requirment( const bionic_id &bid );
void consume_installation_requirment( const bionic_id &bid );
/** Handles process of introducing patient into anesthesia during Autodoc operations. Requires anesthesia kits or NOPAIN mutation */
void introduce_into_anesthesia( const time_duration &duration, player &installer,
bool needs_anesthesia );
Expand Down
2 changes: 1 addition & 1 deletion src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ anatomy_id Creature::get_anatomy() const
return creature_anatomy;
}

void Creature::set_anatomy( anatomy_id anat )
void Creature::set_anatomy( const anatomy_id &anat )
{
creature_anatomy = anat;
}
Expand Down
2 changes: 1 addition & 1 deletion src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class Creature

anatomy_id creature_anatomy = anatomy_id( "default_anatomy" );
anatomy_id get_anatomy() const;
void set_anatomy( anatomy_id anat );
void set_anatomy( const anatomy_id &anat );

bodypart_id get_random_body_part( bool main = false ) const;
/**
Expand Down
8 changes: 4 additions & 4 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,8 @@ time_duration companion_travel_time_calc( const std::vector<tripoint> &journey,
int om_carry_weight_to_trips( const std::vector<item *> &itms, npc_ptr comp = nullptr );
/// Determines how many trips it takes to move @ref mass and @ref volume of items
/// with @ref carry_mass and @ref carry_volume moved per trip
int om_carry_weight_to_trips( units::mass mass, units::volume volume, units::mass carry_mass,
units::volume carry_volume );
int om_carry_weight_to_trips( const units::mass &mass, const units::volume &volume,
const units::mass &carry_mass, const units::volume &carry_volume );
/// Formats the variables into a standard looking description to be displayed in a ynquery window
std::string camp_trip_description( const time_duration &total_time,
const time_duration &working_time,
Expand Down Expand Up @@ -3492,8 +3492,8 @@ time_duration companion_travel_time_calc( const std::vector<tripoint> &journey,
return work + one_way * trips * 1_seconds;
}

int om_carry_weight_to_trips( units::mass mass, units::volume volume,
units::mass carry_mass, units::volume carry_volume )
int om_carry_weight_to_trips( const units::mass &mass, const units::volume &volume,
const units::mass &carry_mass, const units::volume &carry_volume )
{
int trips_m = 1 + mass / carry_mass;
int trips_v = 1 + volume / carry_volume;
Expand Down
2 changes: 1 addition & 1 deletion src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ void game::handle_key_blocking_activity()

// call on_contents_changed() for the location's parent and all the way up the chain
// used in game::inventory_item_menu()
static void handle_contents_changed( item_location acted_item )
static void handle_contents_changed( const item_location &acted_item )
{
if( acted_item.where() != item_location::type::container ) {
return;
Expand Down
6 changes: 3 additions & 3 deletions src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void game_menus::inv::common( avatar &you )
} while( loop_options.count( res ) != 0 );
}

void game_menus::inv::common( item_location loc, avatar &you )
void game_menus::inv::common( item_location &loc, avatar &you )
{
// Return to inventory menu on those inputs
static const std::set<int> loop_options = { { '\0', '=', 'f' } };
Expand Down Expand Up @@ -1274,7 +1274,7 @@ class holster_inventory_preset: public weapon_inventory_preset
const item &holster;
};

drop_locations game_menus::inv::holster( player &p, item_location holster )
drop_locations game_menus::inv::holster( player &p, const item_location &holster )
{
const std::string holster_name = holster->tname( 1, false );
const use_function *use = holster->type->get_use( "holster" );
Expand All @@ -1300,7 +1300,7 @@ drop_locations game_menus::inv::holster( player &p, item_location holster )
return insert_menu.execute();
}

void game_menus::inv::insert_items( avatar &you, item_location holster )
void game_menus::inv::insert_items( avatar &you, item_location &holster )
{
drop_locations holstered_list = game_menus::inv::holster( you, holster );
for( drop_location holstered_item : holstered_list ) {
Expand Down
6 changes: 3 additions & 3 deletions src/game_inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ item_location titled_filter_menu( item_location_filter filter, avatar &you,
/*@{*/

void common( avatar &you );
void common( item_location loc, avatar &you );
void common( item_location &loc, avatar &you );
void compare( player &p, const cata::optional<tripoint> &offset );
void reassign_letter( player &p, item &it );
void swap_letters( player &p );
Expand Down Expand Up @@ -98,8 +98,8 @@ item_location use( avatar &you );
/** Item wielding/unwielding menu. */
item_location wield( avatar &you );
/** Item wielding/unwielding menu. */
drop_locations holster( player &p, item_location holster );
void insert_items( avatar &you, item_location holster );
drop_locations holster( player &p, const item_location &holster );
void insert_items( avatar &you, item_location &holster );
/** Choosing a gun to saw down it's barrel. */
item_location saw_barrel( player &p, item &tool );
/** Choose item to wear. */
Expand Down
2 changes: 1 addition & 1 deletion src/handle_liquid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static void serialize_liquid_target( player_activity &act, const vehicle &veh )
act.coords.push_back( veh.global_pos3() );
}

static void serialize_liquid_target( player_activity &act, item_location container_item )
static void serialize_liquid_target( player_activity &act, const item_location &container_item )
{
act.values.push_back( LTT_CONTAINER );
act.values.push_back( 0 ); // dummy
Expand Down
6 changes: 3 additions & 3 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ int inventory_column::reassign_custom_invlets( const player &p, int min_invlet,
return cur_invlet;
}

static int num_parents( item_location loc )
static int num_parents( const item_location &loc )
{
if( loc.where() != item_location::type::container ) {
return 0;
Expand Down Expand Up @@ -1267,12 +1267,12 @@ void inventory_selector::add_items( inventory_column &target_column,
}
}

void inventory_selector::add_contained_items( item_location container )
void inventory_selector::add_contained_items( item_location &container )
{
add_contained_items( container, own_inv_column );
}

void inventory_selector::add_contained_items( item_location container, inventory_column &column )
void inventory_selector::add_contained_items( item_location &container, inventory_column &column )
{
for( item *it : container->contents.all_items_top() ) {
item_location child( container, it );
Expand Down
4 changes: 2 additions & 2 deletions src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,8 @@ class inventory_selector
inventory_selector( player &u, const inventory_selector_preset &preset = default_preset );
virtual ~inventory_selector();
/** These functions add items from map / vehicles. */
void add_contained_items( item_location container );
void add_contained_items( item_location container, inventory_column &column );
void add_contained_items( item_location &container );
void add_contained_items( item_location &container, inventory_column &column );
void add_character_items( Character &character );
void add_map_items( const tripoint &target );
void add_vehicle_items( const tripoint &target );
Expand Down
3 changes: 2 additions & 1 deletion src/iuse_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2482,7 +2482,8 @@ int holster_actor::use( player &p, item &it, bool, const tripoint & ) const
return 0;
}
// may not strictly be the correct item_location, but plumbing item_location through all iuse_actor::use won't work
game_menus::inv::insert_items( *p.as_avatar(), item_location( p, &it ) );
item_location item_loc( p, &it );
game_menus::inv::insert_items( *p.as_avatar(), item_loc );
}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class mapgen_basic_container
weighted_int_list<std::shared_ptr<mapgen_function>> weights_;

public:
int add( const std::shared_ptr<mapgen_function> ptr ) {
int add( const std::shared_ptr<mapgen_function> &ptr ) {
assert( ptr );
mapgens_.push_back( ptr );
return mapgens_.size() - 1;
Expand Down Expand Up @@ -334,7 +334,7 @@ class mapgen_factory
return mapgens_.count( key ) != 0;
}
/// @see mapgen_basic_container::add
int add( const std::string &key, const std::shared_ptr<mapgen_function> ptr ) {
int add( const std::string &key, const std::shared_ptr<mapgen_function> &ptr ) {
return mapgens_[key].add( ptr );
}
/// @see mapgen_basic_container::generate
Expand Down
3 changes: 2 additions & 1 deletion src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,8 @@ class npc : public player
// Move to, or grab, our targeted item
void pick_up_item();
// Drop wgt and vol, including all items with less value than min_val
void drop_items( units::mass drop_weight, units::volume drop_volume, int min_val = 0 );
void drop_items( const units::mass &drop_weight, const units::volume &drop_volume,
int min_val = 0 );
/** Picks up items and returns a list of them. */
std::list<item> pick_up_item_map( const tripoint &where );
std::list<item> pick_up_item_vehicle( vehicle &veh, int part_index );
Expand Down
3 changes: 2 additions & 1 deletion src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3081,7 +3081,8 @@ struct ratio_index {
};

/* As of October 2019, this is buggy, do not use!! */
void npc::drop_items( units::mass drop_weight, units::volume drop_volume, int min_val )
void npc::drop_items( const units::mass &drop_weight, const units::volume &drop_volume,
int min_val )
{
/* Remove this when someone debugs it back to functionality */
return;
Expand Down
2 changes: 1 addition & 1 deletion src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void draw_custom_border(
const catacurses::window &w, const catacurses::chtype ls, const catacurses::chtype rs,
const catacurses::chtype ts, const catacurses::chtype bs, const catacurses::chtype tl,
const catacurses::chtype tr, const catacurses::chtype bl, const catacurses::chtype br,
const nc_color FG, const point &pos, int height, int width )
const nc_color &FG, const point &pos, int height, int width )
{
wattron( w, FG );

Expand Down
2 changes: 1 addition & 1 deletion src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void draw_custom_border(
const catacurses::window &w, catacurses::chtype ls = 1, catacurses::chtype rs = 1,
catacurses::chtype ts = 1, catacurses::chtype bs = 1, catacurses::chtype tl = 1,
catacurses::chtype tr = 1, catacurses::chtype bl = 1, catacurses::chtype br = 1,
nc_color FG = BORDER_COLOR, const point &pos = point_zero, int height = 0, int width = 0 );
const nc_color &FG = BORDER_COLOR, const point &pos = point_zero, int height = 0, int width = 0 );
void draw_border( const catacurses::window &w, nc_color border_color = BORDER_COLOR,
const std::string &title = "", nc_color title_color = c_light_red );
void draw_border_below_tabs( const catacurses::window &w, nc_color border_color = BORDER_COLOR );
Expand Down
6 changes: 3 additions & 3 deletions src/stomach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ stomach_contents::stomach_contents( units::volume max_vol, bool is_stomach )
last_ate = calendar::before_time_starts;
}

static std::string ml_to_string( units::volume vol )
static std::string ml_to_string( const units::volume &vol )
{
return to_string( units::to_milliliter<int>( vol ) ) + "_ml";
}
Expand Down Expand Up @@ -274,7 +274,7 @@ void stomach_contents::mod_nutr( int nutr )
mod_calories( -1 * std::round( nutr * 2500.0f / ( 12 * 24 ) ) );
}

void stomach_contents::mod_water( units::volume h2o )
void stomach_contents::mod_water( const units::volume &h2o )
{
if( h2o > 0_ml ) {
water += h2o;
Expand All @@ -286,7 +286,7 @@ void stomach_contents::mod_quench( int quench )
mod_water( 5_ml * quench );
}

void stomach_contents::mod_contents( units::volume vol )
void stomach_contents::mod_contents( const units::volume &vol )
{
if( -vol >= contents ) {
contents = 0_ml;
Expand Down
4 changes: 2 additions & 2 deletions src/stomach.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ class stomach_contents
void mod_nutr( int nutr );
// changes water amount in stomach
// overflow draws from player thirst
void mod_water( units::volume h2o );
void mod_water( const units::volume &h2o );
// changes water amount in stomach converted from quench value
// TODO: Move to mL values of water
void mod_quench( int quench );
// adds volume to your stomach
void mod_contents( units::volume vol );
void mod_contents( const units::volume &vol );

// how long has it been since i ate?
// only really relevant for player::stomach
Expand Down
2 changes: 1 addition & 1 deletion src/veh_interact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ bool veh_interact::can_self_jack()
return false;
}

static void print_message_to( catacurses::window &w_msg, const nc_color col,
static void print_message_to( catacurses::window &w_msg, const nc_color &col,
const std::string &msg )
{
werase( w_msg );
Expand Down

0 comments on commit df0cda9

Please sign in to comment.