Skip to content

Commit

Permalink
Clean up splints usage (#38052)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramza13 authored Feb 17, 2020
1 parent 418a392 commit 85bfff5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/cata_string_consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ static const std::string flag_SMOKABLE( "SMOKABLE" );
static const std::string flag_SMOKED( "SMOKED" );
static const std::string flag_SPEAR( "SPEAR" );
static const std::string flag_SPEEDLOADER( "SPEEDLOADER" );
static const std::string flag_SPLINT( "SPLINT" );
static const std::string flag_SPR_START( "SPR_START" );
static const std::string flag_STR_DRAW( "STR_DRAW" );
static const std::string flag_STURDY( "STURDY" );
Expand Down
18 changes: 18 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,24 @@ ret_val<bool> Character::can_wear( const item &it, bool with_equip_change ) cons
}
}

if( it.has_flag( flag_SPLINT ) ) {
bool need_splint = false;
for( const body_part bp : all_body_parts ) {
if( !it.covers( bp ) ) {
continue;
}
if( is_limb_broken( bp_to_hp( bp ) ) && !worn_with_flag( flag_SPLINT, bp ) ) {
need_splint = true;
break;
}
}
if( !need_splint ) {
return ret_val<bool>::make_failure( is_player() ?
_( "You don't have any broken limbs this could help." )
: _( "%s doesn't have any broken limbs this could help." ), name );
}
}

if( it.has_flag( "RESTRICT_HANDS" ) && !has_two_arms() ) {
return ret_val<bool>::make_failure( ( is_player() ? _( "You don't have enough arms to wear that." )
: string_format( _( "%s doesn't have enough arms to wear that." ), name ) ) );
Expand Down
3 changes: 0 additions & 3 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4645,9 +4645,6 @@ void iexamine::autodoc( player &p, const tripoint &examp )
item &equipped_splint = patient.i_add( splint );
cata::optional<std::list<item>::iterator> worn_item =
patient.wear( equipped_splint, false );
if( worn_item && !patient.worn_with_flag( "SPLINT", part ) ) {
patient.change_side( **worn_item, false );
}
}
patient.add_effect( effect_mending, 0_turns, part, true );
effect &mending_effect = patient.get_effect( effect_mending, part );
Expand Down
59 changes: 27 additions & 32 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,19 @@
#include "faction.h"
#include "magic.h"
#include "clothing_mod.h"
#include "cata_string_consts.h"

class npc_class;

static const std::string GUN_MODE_VAR_NAME( "item::mode" );
static const std::string CLOTHING_MOD_VAR_PREFIX( "clothing_mod_" );

static const skill_id skill_survival( "survival" );
static const skill_id skill_melee( "melee" );
static const skill_id skill_unarmed( "unarmed" );
static const skill_id skill_cooking( "cooking" );

static const quality_id quality_jack( "JACK" );
static const quality_id quality_lift( "LIFT" );

static const species_id ROBOT( "ROBOT" );

static const efftype_id effect_cig( "cig" );
static const efftype_id effect_shakes( "shakes" );
static const efftype_id effect_sleep( "sleep" );
static const efftype_id effect_weed_high( "weed_high" );

static const fault_id fault_gun_blackpowder( "fault_gun_blackpowder" );

static const trait_id trait_small2( "SMALL2" );
static const trait_id trait_small_ok( "SMALL_OK" );
static const trait_id trait_huge( "HUGE" );
static const trait_id trait_huge_ok( "HUGE_OK" );

class npc_class;

using npc_class_id = string_id<npc_class>;

std::string rad_badge_color( const int rad )
Expand Down Expand Up @@ -3619,23 +3605,32 @@ nc_color item::color_in_inventory() const
void item::on_wear( Character &p )
{
if( is_sided() && get_side() == side::BOTH ) {
// for sided items wear the item on the side which results in least encumbrance
int lhs = 0;
int rhs = 0;
if( has_flag( flag_SPLINT ) ) {
set_side( side::LEFT );
if( ( covers( bp_leg_l ) && p.is_limb_broken( hp_leg_r ) &&
!p.worn_with_flag( flag_SPLINT, bp_leg_r ) ) ||
( covers( bp_arm_l ) && p.is_limb_broken( hp_arm_r ) &&
!p.worn_with_flag( flag_SPLINT, bp_arm_r ) ) ) {
set_side( side::RIGHT );
}
} else {
// for sided items wear the item on the side which results in least encumbrance
int lhs = 0;
int rhs = 0;
set_side( side::LEFT );
const auto left_enc = p.get_encumbrance( *this );
for( const body_part bp : all_body_parts ) {
lhs += left_enc[bp].encumbrance;
}

set_side( side::LEFT );
const auto left_enc = p.get_encumbrance( *this );
for( const body_part bp : all_body_parts ) {
lhs += left_enc[bp].encumbrance;
}
set_side( side::RIGHT );
const auto right_enc = p.get_encumbrance( *this );
for( const body_part bp : all_body_parts ) {
rhs += right_enc[bp].encumbrance;
}

set_side( side::RIGHT );
const auto right_enc = p.get_encumbrance( *this );
for( const body_part bp : all_body_parts ) {
rhs += right_enc[bp].encumbrance;
set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
}

set_side( lhs <= rhs ? side::LEFT : side::RIGHT );
}

// TODO: artifacts currently only work with the player character
Expand Down
10 changes: 9 additions & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
#include "flat_set.h"
#include "stomach.h"
#include "teleport.h"
#include "cata_string_consts.h"

const double MAX_RECOIL = 3000;

Expand Down Expand Up @@ -3963,7 +3964,14 @@ void player::use( item_location loc )
}
} else if( used.type->has_use() ) {
invoke_item( &used, loc.position() );

} else if( used.has_flag( flag_SPLINT ) ) {
ret_val<bool> need_splint = can_wear( used );
if( need_splint.success() ) {
wear_item( used );
loc.remove_item();
} else {
add_msg( m_info, need_splint.str() );
}
} else {
add_msg( m_info, _( "You can't do anything interesting with your %s." ),
used.tname() );
Expand Down

0 comments on commit 85bfff5

Please sign in to comment.