From c762b5d114be3f5ea40fe13ff0c1f727e98f9f0b Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Sat, 14 Dec 2019 11:04:18 -0500 Subject: [PATCH] move player::change_side to Character --- src/character.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/character.h | 9 ++++++++ src/player.cpp | 53 ----------------------------------------------- src/player.h | 4 ---- 4 files changed, 62 insertions(+), 57 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 10740e870ac85..68485c3f1dbcf 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -2566,6 +2566,59 @@ int Character::extraEncumbrance( const layer_level level, const int bp ) const return encumbrance_cache[bp].layer_penalty_details[static_cast( level )].total; } +hint_rating Character::rate_action_change_side( const item &it ) const +{ + if( !is_worn( it ) ) { + return HINT_IFFY; + } + + if( !it.is_sided() ) { + return HINT_CANT; + } + + return HINT_GOOD; +} + +bool Character::change_side( item &it, bool interactive ) +{ + if( !it.swap_side() ) { + if( interactive ) { + add_msg_player_or_npc( m_info, + _( "You cannot swap the side on which your %s is worn." ), + _( " cannot swap the side on which their %s is worn." ), + it.tname() ); + } + return false; + } + + if( interactive ) { + add_msg_player_or_npc( m_info, _( "You swap the side on which your %s is worn." ), + _( " swaps the side on which their %s is worn." ), + it.tname() ); + } + + mod_moves( -250 ); + reset_encumbrance(); + + return true; +} + +bool Character::change_side( int pos, bool interactive ) +{ + item &it( i_at( pos ) ); + + if( !is_worn( it ) ) { + if( interactive ) { + add_msg_player_or_npc( m_info, + _( "You are not wearing that item." ), + _( " isn't wearing that item." ) ); + } + return false; + } + + return change_side( it, interactive ); +} + static void layer_item( std::array &vals, const item &it, std::array &highest_layer_so_far, diff --git a/src/character.h b/src/character.h index 64f16bd158a2a..84f228e9be0ca 100644 --- a/src/character.h +++ b/src/character.h @@ -1502,6 +1502,15 @@ class Character : public Creature, public visitable double footwear_factor() const; /** Returns true if the player is wearing something on their feet that is not SKINTIGHT */ bool is_wearing_shoes( const side &which_side = side::BOTH ) const; + + /** Swap side on which item is worn; returns false on fail. If interactive is false, don't alert player or drain moves */ + bool change_side( item &it, bool interactive = true ); + bool change_side( int pos, bool interactive = true ); + + /** Used to determine player feedback on item use for the inventory code. + * rates usability lower for non-tools (books, etc.) */ + hint_rating rate_action_change_side( const item &it ) const; + bool get_check_encumbrance() { return check_encumbrance; } diff --git a/src/player.cpp b/src/player.cpp index ec1f13a8c1d25..b42973cb490f8 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -4294,19 +4294,6 @@ hint_rating player::rate_action_wear( const item &it ) const return can_wear( it ).success() ? HINT_GOOD : HINT_IFFY; } -hint_rating player::rate_action_change_side( const item &it ) const -{ - if( !is_worn( it ) ) { - return HINT_IFFY; - } - - if( !it.is_sided() ) { - return HINT_CANT; - } - - return HINT_GOOD; -} - bool player::can_reload( const item &it, const itype_id &ammo ) const { if( !it.is_reloadable_with( ammo ) ) { @@ -4771,46 +4758,6 @@ player::wear_item( const item &to_wear, bool interactive ) return new_item_it; } -bool player::change_side( item &it, bool interactive ) -{ - if( !it.swap_side() ) { - if( interactive ) { - add_msg_player_or_npc( m_info, - _( "You cannot swap the side on which your %s is worn." ), - _( " cannot swap the side on which their %s is worn." ), - it.tname() ); - } - return false; - } - - if( interactive ) { - add_msg_player_or_npc( m_info, _( "You swap the side on which your %s is worn." ), - _( " swaps the side on which their %s is worn." ), - it.tname() ); - } - - mod_moves( -250 ); - reset_encumbrance(); - - return true; -} - -bool player::change_side( int pos, bool interactive ) -{ - item &it( i_at( pos ) ); - - if( !is_worn( it ) ) { - if( interactive ) { - add_msg_player_or_npc( m_info, - _( "You are not wearing that item." ), - _( " isn't wearing that item." ) ); - } - return false; - } - - return change_side( it, interactive ); -} - hint_rating player::rate_action_takeoff( const item &it ) const { if( !it.is_armor() ) { diff --git a/src/player.h b/src/player.h index f7a002b23cd5c..ec2c0e7cdd07d 100644 --- a/src/player.h +++ b/src/player.h @@ -794,9 +794,6 @@ class player : public Character */ cata::optional::iterator> wear_item( const item &to_wear, bool interactive = true ); - /** Swap side on which item is worn; returns false on fail. If interactive is false, don't alert player or drain moves */ - bool change_side( item &it, bool interactive = true ); - bool change_side( int pos, bool interactive = true ); /** Returns all items that must be taken off before taking off this item */ std::list get_dependent_worn_items( const item &it ) const; @@ -881,7 +878,6 @@ class player : public Character * rates usability lower for non-tools (books, etc.) */ hint_rating rate_action_use( const item &it ) const; hint_rating rate_action_wear( const item &it ) const; - hint_rating rate_action_change_side( const item &it ) const; hint_rating rate_action_eat( const item &it ) const; hint_rating rate_action_takeoff( const item &it ) const; hint_rating rate_action_reload( const item &it ) const;