Skip to content

Commit

Permalink
Subparts can track separate lists of sublocations that exist bellow t…
Browse files Browse the repository at this point in the history
…hem (#61576)

* Added the secondary location rules for this

* missed a /

* still messing up color formatting

* make it a str id

* make it a str id

* Update src/character_attire.cpp
  • Loading branch information
bombasticSlacks authored Oct 17, 2022
1 parent 6aeded9 commit 0d87154
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
18 changes: 12 additions & 6 deletions data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@
"type": "sub_body_part",
"side": 0,
"opposite": "sub_limb_debug",
"name": "neck"
"name": "neck",
"locations_under": [ "torso_upper" ]
},
{
"id": "torso_lower",
Expand All @@ -460,7 +461,8 @@
"side": 0,
"name": "front torso (hang)",
"opposite": "torso_hanging_back",
"name_multiple": "item hangs off you"
"name_multiple": "item hangs off you",
"locations_under": [ "torso_upper", "torso_lower" ]
},
{
"id": "torso_hanging_back",
Expand All @@ -471,7 +473,8 @@
"side": 0,
"name": "back torso (hang)",
"opposite": "torso_hanging_front",
"name_multiple": "item hangs off you"
"name_multiple": "item hangs off you",
"locations_under": [ "torso_upper", "torso_lower" ]
},
{
"id": "leg_draped_l",
Expand All @@ -482,7 +485,8 @@
"secondary": true,
"opposite": "leg_draped_r",
"name_multiple": "legs (draped)",
"name": "left leg (draped)"
"name": "left leg (draped)",
"locations_under": [ "leg_hip_l", "leg_upper_l" ]
},
{
"id": "leg_draped_r",
Expand All @@ -493,7 +497,8 @@
"secondary": true,
"opposite": "leg_draped_l",
"name_multiple": "legs (draped)",
"name": "right leg (draped)"
"name": "right leg (draped)",
"locations_under": [ "leg_hip_r", "leg_upper_r" ]
},
{
"id": "torso_waist",
Expand All @@ -503,7 +508,8 @@
"secondary": true,
"side": 0,
"name": "waist",
"opposite": "sub_limb_debug"
"opposite": "sub_limb_debug",
"locations_under": [ "leg_hip_r", "leg_hip_l" ]
},
{
"id": "arm_shoulder_r",
Expand Down
2 changes: 1 addition & 1 deletion src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3462,7 +3462,7 @@ void Character::calc_discomfort()
{
// clear all instances of discomfort
remove_effect( effect_chafing );
for( const bodypart_id &bp : worn.where_discomfort() ) {
for( const bodypart_id &bp : worn.where_discomfort( *this ) ) {
if( bp->feels_discomfort ) {
add_effect( effect_chafing, 1_turns, bp, true, 1 );
}
Expand Down
15 changes: 12 additions & 3 deletions src/character_attire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,7 +1860,7 @@ std::map<bodypart_id, int> outfit::warmth( const Character &guy ) const
return total_warmth;
}

std::unordered_set<bodypart_id> outfit::where_discomfort() const
std::unordered_set<bodypart_id> outfit::where_discomfort( const Character &guy ) const
{
// get all rigid body parts to begin with
std::unordered_set<sub_bodypart_id> covered_sbps;
Expand All @@ -1876,8 +1876,17 @@ std::unordered_set<bodypart_id> outfit::where_discomfort() const
// note anything selectively rigid reasonably can be assumed to support itself so we don't need to worry about this
// items must also be somewhat heavy in order to cause discomfort
if( !i.is_bp_rigid_selective( sbp ) && !i.is_bp_comfortable( sbp ) &&
covered_sbps.count( sbp ) != 1 && i.weight() > units::from_gram( 250 ) ) {
uncomfortable_bps.insert( sbp->parent );
i.weight() > units::from_gram( 250 ) ) {

// need to go through each locations under location to check if its covered, since secondary locations can cover multiple underlying locations
for( const sub_bodypart_str_id &under_sbp : sbp->locations_under ) {
if( covered_sbps.count( under_sbp ) != 1 ) {
guy.add_msg_if_player(
string_format( _( "<color_c_red> the %s rubs uncomfortably against your unpadded %s </color>" ),
i.display_name(), under_sbp->name ) );
uncomfortable_bps.insert( sbp->parent );
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/character_attire.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class outfit
cata::optional<std::list<item>::iterator> wear_item( Character &guy, const item &to_wear,
bool interactive, bool do_calc_encumbrance, bool do_sort_items = true, bool quiet = false );
/** Calculate and return any bodyparts that are currently uncomfortable. */
std::unordered_set<bodypart_id> where_discomfort() const;
std::unordered_set<bodypart_id> where_discomfort( const Character &guy ) const;
// used in game::wield
void insert_item_at_index( const item &clothing, int index );
void append_radio_items( std::list<item *> &rc_items );
Expand Down
2 changes: 2 additions & 0 deletions src/subbodypart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void sub_body_part_type::load( const JsonObject &jo, const std::string & )
optional( jo, was_loaded, "side", part_side );
optional( jo, was_loaded, "name_multiple", name_multiple );
optional( jo, was_loaded, "opposite", opposite );
// defaults to self
optional( jo, was_loaded, "locations_under", locations_under, { id } );
}

void sub_body_part_type::reset()
Expand Down
5 changes: 5 additions & 0 deletions src/subbodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ struct sub_body_part_type {
// would have this value
int max_coverage = 0;

// the locations that are under this location
// used with secondary locations to define what sublocations
// exist bellow them for things like discomfort
std::vector<sub_bodypart_str_id> locations_under;

static void load_bp( const JsonObject &jo, const std::string &src );

void load( const JsonObject &jo, const std::string &src );
Expand Down

0 comments on commit 0d87154

Please sign in to comment.