From c762b5d114be3f5ea40fe13ff0c1f727e98f9f0b Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Sat, 14 Dec 2019 11:04:18 -0500 Subject: [PATCH 1/2] 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; From 1de96235b3f7ddfa611d4958aebfcbb5c9d98f8b Mon Sep 17 00:00:00 2001 From: KorGgenT Date: Sat, 14 Dec 2019 11:39:32 -0500 Subject: [PATCH 2/2] change Character::change_side parameter to item_location --- src/character.cpp | 8 +++----- src/character.h | 2 +- src/game.cpp | 18 +----------------- src/game.h | 1 - 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/character.cpp b/src/character.cpp index 68485c3f1dbcf..1809eff252d45 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -2603,11 +2603,9 @@ bool Character::change_side( item &it, bool interactive ) return true; } -bool Character::change_side( int pos, bool interactive ) +bool Character::change_side( item_location &loc, bool interactive ) { - item &it( i_at( pos ) ); - - if( !is_worn( it ) ) { + if( !loc || !is_worn( *loc ) ) { if( interactive ) { add_msg_player_or_npc( m_info, _( "You are not wearing that item." ), @@ -2616,7 +2614,7 @@ bool Character::change_side( int pos, bool interactive ) return false; } - return change_side( it, interactive ); + return change_side( *loc, interactive ); } static void layer_item( std::array &vals, diff --git a/src/character.h b/src/character.h index 84f228e9be0ca..02610eeb724de 100644 --- a/src/character.h +++ b/src/character.h @@ -1505,7 +1505,7 @@ class Character : public Creature, public visitable /** 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 ); + bool change_side( item_location &loc, bool interactive = true ); /** Used to determine player feedback on item use for the inventory code. * rates usability lower for non-tools (books, etc.) */ diff --git a/src/game.cpp b/src/game.cpp index a5df20ff55c33..46f0e37b1fa7d 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2089,7 +2089,7 @@ int game::inventory_item_menu( int pos, int iStartX, int iWidth, avatar_action::plthrow( u, pos ); break; case 'c': - change_side( pos ); + u.change_side( locThisItem ); break; case 'T': u.takeoff( oThisItem ); @@ -8336,22 +8336,6 @@ void game::butcher() } } -void game::change_side( int pos ) -{ - if( pos == INT_MIN ) { - auto filter = [&]( const item & it ) { - return u.is_worn( it ) && it.is_sided(); - }; - pos = u.get_item_position( game_menus::inv::titled_filter_menu( filter, u, - _( "Change side for item" ), _( "You don't have sided items worn." ) ).get_item() ); - } - if( pos == INT_MIN ) { - add_msg( _( "Never mind." ) ); - return; - } - u.change_side( pos ); -} - void game::reload( item_location &loc, bool prompt, bool empty ) { item *it = loc.get_item(); diff --git a/src/game.h b/src/game.h index e3bee9492d814..f91ad8e31585c 100644 --- a/src/game.h +++ b/src/game.h @@ -769,7 +769,6 @@ class game void butcher(); // Butcher a corpse 'B' - void change_side( int pos = INT_MIN ); // Change the side on which an item is worn 'c' void reload( item_location &loc, bool prompt = false, bool empty = true ); void mend( int pos = INT_MIN ); public: