Skip to content

Commit d01ba04

Browse files
authored
Merge pull request #82900 from GuardianDll/move_body_part_type_type
move body_part_type::type to enums.h to resolve include loop
2 parents e012d67 + ac3bdfa commit d01ba04

30 files changed

+193
-189
lines changed

src/activity_actor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8909,7 +8909,7 @@ void pulp_activity_actor::send_final_message( Character &you ) const
89098909
} else if( pd.stomps_only ) {
89108910
tools = string_format(
89118911
_( "It took you some time, stomping corpses with nothing but your %1$s, and occasionally cutting it with a %2$s." ),
8912-
you.get_random_body_part_of_type( body_part_type::type::leg )->accusative_multiple, pd.cut_tool );
8912+
you.get_random_body_part_of_type( bp_type::leg )->accusative_multiple, pd.cut_tool );
89138913
} else if( pd.weapon_only ) {
89148914
tools = string_format(
89158915
_( "It took you some time, bashing corpses with your %1$s, with occasional cuts with a %2$s." ),
@@ -8922,7 +8922,7 @@ void pulp_activity_actor::send_final_message( Character &you ) const
89228922
} else {
89238923
if( pd.stomps_only ) {
89248924
tools = string_format( _( "It took you some time, stomping corpses with nothing but your %1$s." ),
8925-
you.get_random_body_part_of_type( body_part_type::type::leg )->accusative_multiple );
8925+
you.get_random_body_part_of_type( bp_type::leg )->accusative_multiple );
89268926
} else if( pd.weapon_only ) {
89278927
tools = string_format( _( "It took you some time, bashing corpses with just your %1$s." ),
89288928
pd.bash_tool );

src/anatomy.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "character.h"
1010
#include "creature.h"
1111
#include "debug.h"
12+
#include "enums.h"
1213
#include "flag.h"
1314
#include "generic_factory.h"
1415
#include "messages.h"
@@ -279,20 +280,20 @@ bodypart_id anatomy::select_blocking_part( const Creature *blocker, bool arm, bo
279280
}
280281

281282
// Can we block with our normal boring arm?
282-
if( bp->has_type( body_part_type::type::arm ) && !bp->has_flag( json_flag_NONSTANDARD_BLOCK ) &&
283+
if( bp->has_type( bp_type::arm ) && !bp->has_flag( json_flag_NONSTANDARD_BLOCK ) &&
283284
!arm ) {
284285
add_msg_debug( debugmode::DF_MELEE, "BP %s discarded, no arm blocks allowed",
285286
body_part_name( bp ) );
286287
continue;
287288
// Can we block with our normal boring legs?
288-
} else if( bp->has_type( body_part_type::type::leg ) &&
289+
} else if( bp->has_type( bp_type::leg ) &&
289290
!bp->has_flag( json_flag_NONSTANDARD_BLOCK ) && !leg ) {
290291
add_msg_debug( debugmode::DF_MELEE, "BP %s discarded, no leg blocks allowed",
291292
body_part_name( bp ) );
292293
continue;
293294
// Can we block with our non-normal non-arms/non-legs?
294-
} else if( ( ( !bp->has_type( body_part_type::type::arm ) &&
295-
!bp->has_type( body_part_type::type::leg ) ) || bp->has_flag( json_flag_NONSTANDARD_BLOCK ) ) &&
295+
} else if( ( ( !bp->has_type( bp_type::arm ) &&
296+
!bp->has_type( bp_type::leg ) ) || bp->has_flag( json_flag_NONSTANDARD_BLOCK ) ) &&
296297
!nonstandard ) {
297298
add_msg_debug( debugmode::DF_MELEE, "BP %s discarded, no nonstandard blocks allowed",
298299
body_part_name( bp ) );

src/bodypart.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ std::string enum_to_string<side>( side data )
7373
}
7474

7575
template<>
76-
std::string enum_to_string<body_part_type::type>( body_part_type::type data )
76+
std::string enum_to_string<bp_type>( bp_type data )
7777
{
7878
switch( data ) {
7979
// *INDENT-OFF*
80-
case body_part_type::type::arm: return "arm";
81-
case body_part_type::type::other: return "other";
82-
case body_part_type::type::foot: return "foot";
83-
case body_part_type::type::hand: return "hand";
84-
case body_part_type::type::head: return "head";
85-
case body_part_type::type::leg: return "leg";
86-
case body_part_type::type::mouth: return "mouth";
87-
case body_part_type::type::sensor: return "sensor";
88-
case body_part_type::type::tail: return "tail";
89-
case body_part_type::type::torso: return "torso";
90-
case body_part_type::type::wing: return "wing";
80+
case bp_type::arm: return "arm";
81+
case bp_type::other: return "other";
82+
case bp_type::foot: return "foot";
83+
case bp_type::hand: return "hand";
84+
case bp_type::head: return "head";
85+
case bp_type::leg: return "leg";
86+
case bp_type::mouth: return "mouth";
87+
case bp_type::sensor: return "sensor";
88+
case bp_type::tail: return "tail";
89+
case bp_type::torso: return "torso";
90+
case bp_type::wing: return "wing";
9191
// *INDENT-ON*
92-
case body_part_type::type::num_types:
92+
case bp_type::num_types:
9393
break;
9494
}
9595
cata_fatal( "Invalid body part type." );
@@ -249,12 +249,12 @@ void body_part_type::load_bp( const JsonObject &jo, const std::string &src )
249249
body_part_factory.load( jo, src );
250250
}
251251

252-
body_part_type::type body_part_type::primary_limb_type() const
252+
bp_type body_part_type::primary_limb_type() const
253253
{
254254
return _primary_limb_type;
255255
}
256256

257-
bool body_part_type::has_type( const body_part_type::type &type ) const
257+
bool body_part_type::has_type( const bp_type &type ) const
258258
{
259259
return limbtypes.count( type ) > 0;
260260
}
@@ -349,21 +349,21 @@ void body_part_type::load( const JsonObject &jo, std::string_view )
349349
optional( jo, was_loaded, "is_vital", is_vital, false );
350350
if( jo.has_array( "limb_types" ) ) {
351351
limbtypes.clear();
352-
body_part_type::type first_type = body_part_type::type::num_types;
352+
bp_type first_type = bp_type::num_types;
353353
bool set_first_type = true;
354354
for( JsonValue jval : jo.get_array( "limb_types" ) ) {
355355
float weight = 1.0f;
356-
body_part_type::type limb_type;
356+
bp_type limb_type;
357357
if( jval.test_array() ) {
358358
JsonArray jarr = jval.get_array();
359-
limb_type = io::string_to_enum<body_part_type::type>( jarr.get_string( 0 ) );
359+
limb_type = io::string_to_enum<bp_type>( jarr.get_string( 0 ) );
360360
weight = jarr.get_float( 1 );
361361
set_first_type = false;
362362
} else {
363-
limb_type = io::string_to_enum<body_part_type::type>( jval.get_string() );
363+
limb_type = io::string_to_enum<bp_type>( jval.get_string() );
364364
}
365365
limbtypes.emplace( limb_type, weight );
366-
if( first_type == body_part_type::type::num_types ) {
366+
if( first_type == bp_type::num_types ) {
367367
first_type = limb_type;
368368
}
369369
}
@@ -373,12 +373,12 @@ void body_part_type::load( const JsonObject &jo, std::string_view )
373373
}
374374
} else {
375375
limbtypes.clear();
376-
body_part_type::type limb_type = {};
376+
bp_type limb_type = {};
377377
mandatory( jo, was_loaded, "limb_type", limb_type );
378378
limbtypes.emplace( limb_type, 1.0f );
379379
}
380380

381-
if( _primary_limb_type == body_part_type::type::num_types ) {
381+
if( _primary_limb_type == bp_type::num_types ) {
382382
float high = 0.f;
383383
for( auto &bp_type : limbtypes ) {
384384
if( high < bp_type.second ) {

src/bodypart.h

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -183,31 +183,6 @@ struct body_part_type {
183183
* the different types of body parts there are.
184184
* this allows for the ability to group limbs or determine a limb of a certain type
185185
*/
186-
enum class type {
187-
// this is where helmets go, and is a vital part.
188-
head,
189-
// the torso is generally the center of mass of a creature
190-
torso,
191-
// provides sight
192-
sensor,
193-
// you eat and scream with this
194-
mouth,
195-
// may manipulate objects to some degree, is a main part
196-
arm,
197-
// manipulates objects. usually is not a main part.
198-
hand,
199-
// provides motive power
200-
leg,
201-
// helps with balance. usually is not a main part
202-
foot,
203-
// may reduce fall damage
204-
wing,
205-
// may provide balance or manipulation
206-
tail,
207-
// more of a general purpose limb, such as horns.
208-
other,
209-
num_types
210-
};
211186

212187
std::vector<std::pair<bodypart_str_id, mod_id>> src;
213188

@@ -238,7 +213,7 @@ struct body_part_type {
238213
bodypart_str_id opposite_part;
239214

240215
// A weighted list of limb types. The type with the highest weight is the primary type
241-
std::map<body_part_type::type, float> limbtypes;
216+
std::map<bp_type, float> limbtypes;
242217

243218
// Limb-specific attacks
244219
std::set<matec_id> techniques;
@@ -332,7 +307,7 @@ struct body_part_type {
332307

333308
private:
334309
int bionic_slots_ = 0;
335-
body_part_type::type _primary_limb_type = body_part_type::type::num_types;
310+
bp_type _primary_limb_type = bp_type::num_types;
336311
// Protection from various damage types
337312
resistances armor;
338313

@@ -346,8 +321,8 @@ struct body_part_type {
346321
bool was_loaded = false;
347322

348323
bool has_flag( const json_character_flag &flag ) const;
349-
body_part_type::type primary_limb_type() const;
350-
bool has_type( const body_part_type::type &type ) const;
324+
bp_type primary_limb_type() const;
325+
bool has_type( const bp_type &type ) const;
351326

352327
// return a random sub part from the weighted list of subparts
353328
// if secondary is true instead returns a part from only the secondary sublocations
@@ -393,11 +368,6 @@ struct body_part_type {
393368
&covered );
394369
};
395370

396-
template<>
397-
struct enum_traits<body_part_type::type> {
398-
static constexpr body_part_type::type last = body_part_type::type::num_types;
399-
};
400-
401371
struct layer_details {
402372

403373
std::vector<int> pieces;

src/character.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,7 @@ bool Character::has_min_manipulators() const
22362236
bool Character::has_two_arms_lifting() const
22372237
{
22382238
// 0.5f is one "standard" arm, so if you have more than that you barely qualify.
2239-
return get_limb_score( limb_score_lift, body_part_type::type::arm ) > 0.5f;
2239+
return get_limb_score( limb_score_lift, bp_type::arm ) > 0.5f;
22402240
}
22412241

22422242
std::set<matec_id> Character::get_limb_techs() const
@@ -2255,7 +2255,7 @@ std::set<matec_id> Character::get_limb_techs() const
22552255
int Character::get_working_arm_count() const
22562256
{
22572257
int limb_count = 0;
2258-
body_part_type::type arm_type = body_part_type::type::arm;
2258+
bp_type arm_type = bp_type::arm;
22592259
for( const bodypart_id &part : get_all_body_parts_of_type( arm_type ) ) {
22602260
// Almost broken or overencumbered arms don't count
22612261
if( get_part( part )->get_limb_score( *this,
@@ -2273,7 +2273,7 @@ bool Character::enough_working_legs() const
22732273
int limb_count = 0;
22742274
int working_limb_count = 0;
22752275
for( const bodypart_id &part : get_all_body_parts() ) {
2276-
if( part->primary_limb_type() == body_part_type::type::leg ) {
2276+
if( part->primary_limb_type() == bp_type::leg ) {
22772277
limb_count++;
22782278
if( !is_limb_broken( part ) ) {
22792279
working_limb_count++;
@@ -2289,7 +2289,7 @@ int Character::get_working_leg_count() const
22892289
{
22902290
int working_limb_count = 0;
22912291
for( const bodypart_id &part : get_all_body_parts() ) {
2292-
if( part->primary_limb_type() == body_part_type::type::leg ) {
2292+
if( part->primary_limb_type() == bp_type::leg ) {
22932293
if( !is_limb_broken( part ) ) {
22942294
working_limb_count++;
22952295
}
@@ -4219,7 +4219,7 @@ int layer_details::layer( const int encumbrance, bool conflicts )
42194219
return total - current;
42204220
}
42214221

4222-
int Character::avg_encumb_of_limb_type( body_part_type::type part_type ) const
4222+
int Character::avg_encumb_of_limb_type( bp_type part_type ) const
42234223
{
42244224
float limb_encumb = 0.0f;
42254225
int num_limbs = 0;
@@ -5801,7 +5801,7 @@ bool Character::check_immunity_data( const field_immunity_data &ft ) const
58015801
}
58025802
}
58035803
bool immune_by_body_part_resistance = !ft.immunity_data_body_part_env_resistance.empty();
5804-
for( const std::pair<body_part_type::type, int> &fide :
5804+
for( const std::pair<bp_type, int> &fide :
58055805
ft.immunity_data_body_part_env_resistance ) {
58065806
for( const bodypart_id &bp : get_all_body_parts_of_type( fide.first ) ) {
58075807
if( get_env_resist( bp ) < fide.second ) {
@@ -5818,7 +5818,7 @@ bool Character::check_immunity_data( const field_immunity_data &ft ) const
58185818

58195819
bool immune_by_worn_flags = !ft.immunity_data_part_item_flags.empty();
58205820
// Check if all worn flags are fulfilled
5821-
for( const std::pair<body_part_type::type, flag_id> &fide :
5821+
for( const std::pair<bp_type, flag_id> &fide :
58225822
ft.immunity_data_part_item_flags ) {
58235823
for( const bodypart_id &bp : get_all_body_parts_of_type( fide.first ) ) {
58245824
if( !worn_with_flag( fide.second, bp ) ) {
@@ -5835,7 +5835,7 @@ bool Character::check_immunity_data( const field_immunity_data &ft ) const
58355835
}
58365836

58375837
// Check if the optional worn flags are fulfilled
5838-
for( const std::pair<body_part_type::type, flag_id> &fide :
5838+
for( const std::pair<bp_type, flag_id> &fide :
58395839
ft.immunity_data_part_item_flags_any ) {
58405840
for( const bodypart_id &bp : get_all_body_parts_of_type( fide.first ) ) {
58415841
if( worn_with_flag( fide.second, bp ) ) {
@@ -6894,7 +6894,7 @@ void Character::recalc_limb_energy_usage()
68946894
float total_limb_count = 0.0f;
68956895
float bionic_limb_count = 0.0f;
68966896
float bionic_powercost = 0;
6897-
body_part_type::type arm_type = body_part_type::type::arm;
6897+
bp_type arm_type = bp_type::arm;
68986898
for( const bodypart_id &bp : get_all_body_parts_of_type( arm_type ) ) {
68996899
total_limb_count++;
69006900
if( bp->has_flag( json_flag_BIONIC_LIMB ) ) {
@@ -6919,7 +6919,7 @@ void Character::recalc_limb_energy_usage()
69196919
total_limb_count = 0.0f;
69206920
bionic_limb_count = 0.0f;
69216921
bionic_powercost = 0;
6922-
body_part_type::type leg_type = body_part_type::type::leg;
6922+
bp_type leg_type = bp_type::leg;
69236923
for( const bodypart_id &bp : get_all_body_parts_of_type( leg_type ) ) {
69246924
total_limb_count++;
69256925
if( bp->has_flag( json_flag_BIONIC_LIMB ) ) {
@@ -7324,8 +7324,8 @@ int Character::item_handling_cost( const item &it, bool penalties, int base_cost
73247324
// Grabbed penalty scales for grabbed arms/hands
73257325
int pen = 2;
73267326
for( const effect &eff : get_effects_with_flag( json_flag_GRAB ) ) {
7327-
if( eff.get_bp()->primary_limb_type() == body_part_type::type::arm ||
7328-
eff.get_bp()->primary_limb_type() == body_part_type::type::hand ) {
7327+
if( eff.get_bp()->primary_limb_type() == bp_type::arm ||
7328+
eff.get_bp()->primary_limb_type() == bp_type::hand ) {
73297329
pen++;
73307330
}
73317331
}
@@ -7336,12 +7336,12 @@ int Character::item_handling_cost( const item &it, bool penalties, int base_cost
73367336
if( !bulk_cost ) {
73377337
// For single handed items use the least encumbered hand
73387338
if( it.is_two_handed( *this ) ) {
7339-
for( const bodypart_id &part : get_all_body_parts_of_type( body_part_type::type::hand ) ) {
7339+
for( const bodypart_id &part : get_all_body_parts_of_type( bp_type::hand ) ) {
73407340
mv += encumb( part );
73417341
}
73427342
} else {
73437343
int min_encumb = INT_MAX;
7344-
for( const bodypart_id &part : get_all_body_parts_of_type( body_part_type::type::hand ) ) {
7344+
for( const bodypart_id &part : get_all_body_parts_of_type( bp_type::hand ) ) {
73457345
min_encumb = std::min( min_encumb, encumb( part ) );
73467346
}
73477347
mv += min_encumb;
@@ -13696,8 +13696,8 @@ bodypart_id Character::most_staunchable_bp( int &max_staunch )
1369613696
add_msg_debug( debugmode::DF_CHARACTER, "Wound care proficiency found, new limit %d", max_staunch );
1369713697
}
1369813698

13699-
int num_broken_arms = get_num_broken_body_parts_of_type( body_part_type::type::arm );
13700-
int num_arms = get_num_body_parts_of_type( body_part_type::type::arm );
13699+
int num_broken_arms = get_num_broken_body_parts_of_type( bp_type::arm );
13700+
int num_arms = get_num_body_parts_of_type( bp_type::arm );
1370113701

1370213702
// Don't warn about encumbrance if your arms are broken
1370313703
if( num_broken_arms ) {
@@ -13713,7 +13713,7 @@ bodypart_id Character::most_staunchable_bp( int &max_staunch )
1371313713
for( const bodypart_id &bp : get_all_body_parts() ) {
1371413714
intensity = get_effect_int( effect_bleed, bp );
1371513715
// Staunching a bleeding on one of your arms is hard (handle multiple arms)
13716-
if( bp->has_type( body_part_type::type::arm ) ) {
13716+
if( bp->has_type( bp_type::arm ) ) {
1371713717
intensity /= ( 1.0f - 1.0f / num_arms );
1371813718
}
1371913719
// Tourniquets make staunching easier, letting you treat arterial bleeds on your legs
@@ -13791,7 +13791,7 @@ void Character::pause()
1379113791
bodypart_id bp_id = most_staunchable_bp( max );
1379213792

1379313793
// Don't warn about encumbrance if your arms are broken
13794-
int num_broken_arms = get_num_broken_body_parts_of_type( body_part_type::type::arm );
13794+
int num_broken_arms = get_num_broken_body_parts_of_type( bp_type::arm );
1379513795
if( num_broken_arms ) {
1379613796
add_msg_player_or_npc( m_warning,
1379713797
_( "Your broken limb significantly hampers your efforts to put pressure on a bleeding wound!" ),

src/character.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ class Character : public Creature, public visitable
992992

993993
/** Returns ENC provided by armor, etc. */
994994
int encumb( const bodypart_id &bp ) const;
995-
int avg_encumb_of_limb_type( body_part_type::type part_type ) const;
995+
int avg_encumb_of_limb_type( bp_type part_type ) const;
996996

997997
/** Returns body weight plus weight of inventory and worn/wielded items */
998998
units::mass get_weight() const override;
@@ -1511,10 +1511,10 @@ class Character : public Creature, public visitable
15111511
// Get the specified limb score. If bp is defined, only the scores from that body part type are summed.
15121512
// override forces the limb score to be affected by encumbrance/wounds (-1 == no override).
15131513
float get_limb_score( const limb_score_id &score,
1514-
const body_part_type::type &bp = body_part_type::type::num_types,
1514+
const bp_type &bp = bp_type::num_types,
15151515
int override_encumb = -1, int override_wounds = -1 ) const;
15161516
float manipulator_score( const std::map<bodypart_str_id, bodypart> &body,
1517-
body_part_type::type type, int override_encumb, int override_wounds ) const;
1517+
bp_type type, int override_encumb, int override_wounds ) const;
15181518

15191519
bool has_min_manipulators() const;
15201520
// technically this is "has more than one arm"

src/character_attire.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ bool Character::is_wearing_shoes( const side &check_side ) const
650650

651651
for( const bodypart_id &part : get_all_body_parts() ) {
652652
// Is any right|left foot...
653-
if( !part->has_type( body_part_type::type::foot ) ) {
653+
if( !part->has_type( bp_type::foot ) ) {
654654
continue;
655655
}
656656
side_covered = worn.is_wearing_shoes( part );

0 commit comments

Comments
 (0)