Skip to content

Commit

Permalink
move player::change_side to Character
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT committed Dec 17, 2019
1 parent 327f864 commit c762b5d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 57 deletions.
53 changes: 53 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,59 @@ int Character::extraEncumbrance( const layer_level level, const int bp ) const
return encumbrance_cache[bp].layer_penalty_details[static_cast<int>( 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." ),
_( "<npcname> 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." ),
_( "<npcname> 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." ),
_( "<npcname> isn't wearing that item." ) );
}
return false;
}

return change_side( it, interactive );
}

static void layer_item( std::array<encumbrance_data, num_bp> &vals,
const item &it,
std::array<layer_level, num_bp> &highest_layer_so_far,
Expand Down
9 changes: 9 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,15 @@ class Character : public Creature, public visitable<Character>
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;
}
Expand Down
53 changes: 0 additions & 53 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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." ),
_( "<npcname> 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." ),
_( "<npcname> 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." ),
_( "<npcname> 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() ) {
Expand Down
4 changes: 0 additions & 4 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,6 @@ class player : public Character
*/
cata::optional<std::list<item>::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<const item *> get_dependent_worn_items( const item &it ) const;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c762b5d

Please sign in to comment.