Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove most of body_part enum usage #5721

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@
int level_cap = std::min<int>( MAX_SKILL,
( static_cast<int>( corpse->size ) + ( cbms.size() * 2 + 1 ) ) );
int size_mult = corpse->size > creature_size::medium ? ( corpse->size * corpse->size ) : 8;
int practice_amt = ( size_mult + 1 ) * ( ( time_to_cut / 150 ) + 1 ) *

Check warning on line 1300 in src/activity_handlers.cpp

View workflow job for this annotation

GitHub Actions / build

performing an implicit widening conversion to type 'size_type' (aka 'unsigned long') of a multiplication performed in type 'int' [bugprone-implicit-widening-of-multiplication-result]
( cbms.size() * cbms.size() / 2 + 1 );
p->practice( skill_firstaid, practice_amt, level_cap );
add_msg( m_debug, "Experience: %d, Level cap: %d, Time to cut: %d", practice_amt, level_cap,
Expand Down Expand Up @@ -4423,7 +4423,7 @@
z->name() );
z->friendly = -1;
if( z->has_flag( MF_RIDEABLE_MECH ) ) {
z->add_effect( effect_pet, 1_turns, num_bp );
z->add_effect( effect_pet, 1_turns );
}
} else if( success >= -2 ) {
//A near success
Expand Down
25 changes: 12 additions & 13 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
namespace
{
const activity_id ACT_ARMOR_LAYERS( "ACT_ARMOR_LAYERS" );
const bodypart_str_id body_part_appendix( "num_bp" );

Check warning on line 36 in src/armor_layers.cpp

View workflow job for this annotation

GitHub Actions / build

Variable 'body_part_appendix' declared but not used. [cata-unused-statics]
const flag_id json_flag_HIDDEN( "HIDDEN" );

std::string clothing_layer( const item &worn_item );
Expand Down Expand Up @@ -78,7 +78,7 @@
std::vector<std::set<std::string>> lists_of_bad_items_within;

for( const bodypart_id &bp : c.get_all_body_parts() ) {
if( _bp->token && _bp != body_part_appendix ) {
if( _bp->token && _bp.id().is_null() ) {
continue;
}
if( !worn_item->covers( bp ) ) {
Expand Down Expand Up @@ -288,9 +288,9 @@
props.reserve( 5 );

const std::string space = " ";
const int coverage = bp == body_part_appendix ? worn_item.get_avg_coverage() :
const int coverage = bp.id().is_null() ? worn_item.get_avg_coverage() :
worn_item.get_coverage( bp );
const int encumbrance = bp == body_part_appendix ? worn_item.get_avg_encumber(
const int encumbrance = bp.id().is_null() ? worn_item.get_avg_encumber(
c ) : worn_item.get_encumber( c, bp );
props.push_back( string_format( "<color_c_green>[%s]</color>", _( "Properties" ) ) );
props.push_back( name_and_value( space + _( "Coverage:" ),
Expand Down Expand Up @@ -436,7 +436,7 @@
* + 3 - horizontal lines;
* + 1 - caption line;
* + 2 - innermost/outermost string lines;
* + num_bp - sub-categories (torso, head, eyes, etc.);
* + num_of_parts - sub-categories (torso, head, eyes, etc.);
* + 1 - gap;
* number of lines required for displaying all items is calculated dynamically,
* because some items can have multiple entries (i.e. cover a few parts of body).
Expand All @@ -452,7 +452,7 @@
for( const bodypart_id &it : all_parts ) {
armor_cat.insert( it );
}
armor_cat.insert( body_part_appendix );
armor_cat.insert( bodypart_str_id::NULL_ID().id() );

int req_right_h = 3 + 1 + 2 + num_of_parts + 1;
for( const bodypart_id &cover : armor_cat ) {
Expand All @@ -468,9 +468,9 @@
* + 1 - caption line;
* + 8 - general properties
* + 13 - ASSUMPTION: max possible number of flags @ item
* + num_bp+1 - warmth & enc block
* + num_of_parts+1 - warmth & enc block
*/
const int req_mid_h = 3 + 1 + 8 + 13 + num_bp + 1;
const int req_mid_h = 3 + 1 + 8 + 13 + num_of_parts + 1;

int win_h = 0;
int win_w = 0;
Expand Down Expand Up @@ -542,7 +542,6 @@
ctxt.register_action( "NEXT_TAB" );
ctxt.register_action( "MOVE_ARMOR" );
ctxt.register_action( "CHANGE_SIDE" );
ctxt.register_action( "TOGGLE_CLOTH" );
ctxt.register_action( "ASSIGN_INVLETS" );
ctxt.register_action( "SORT_ARMOR" );
ctxt.register_action( "EQUIP_ARMOR" );
Expand Down Expand Up @@ -574,7 +573,7 @@

// top bar
wprintz( w_sort_cat, c_white, _( "Sort Armor" ) );
const auto name = bp != body_part_appendix ? body_part_name_as_heading( bp, 1 ) : _( "All" );
const auto name = bp.id() ? body_part_name_as_heading( bp, 1 ) : _( "All" );
wprintz( w_sort_cat, c_yellow, " << %s >>", name );
right_print( w_sort_cat, 0, 0, c_white, string_format(
_( "[<color_yellow>%s</color>] Hide sprite. "
Expand Down Expand Up @@ -678,7 +677,7 @@
}
int pos = 1, curr = 0;
for( const bodypart_id cover : rl ) {
if( cover == body_part_appendix ) {
if( cover.id().is_null() ) {
continue;
}
if( curr >= rightListOffset && pos <= rightListLines ) {
Expand Down Expand Up @@ -743,7 +742,7 @@
// Create ptr list of items to display
tmp_worn.clear();
const bodypart_id &bp = armor_cat[ tabindex ];
if( bp == body_part_appendix ) {
if( bp.id().is_null() ) {
// All
int i = 0;
for( auto it = who.worn.begin(); it != who.worn.end(); ++it ) {
Expand Down Expand Up @@ -874,7 +873,7 @@
bool equipped = who.as_player()->wear_possessed( *loc );
if( equipped ) {
const bodypart_id &bp = armor_cat[tabindex];
if( tabindex == num_bp || loc->covers( bp ) ) {
if( tabindex == num_of_parts || loc->covers( bp ) ) {
// Set ourselves up to be pointing at the new item
// TODO: This doesn't work yet because we don't save our
// state through other activities, but that's a thing
Expand All @@ -886,7 +885,7 @@
if( i == loc ) {
found = true;
}
return !found && ( tabindex == num_bp || i->covers( bp ) );
return !found && ( tabindex == num_of_parts || i->covers( bp ) );
} );
}
} else if( who.is_npc() ) {
Expand Down
8 changes: 5 additions & 3 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ static void draw_bionics_tabs( const catacurses::window &win, const size_t activ
wnoutrefresh( win );
}

static void draw_description( const catacurses::window &win, const bionic &bio )
static void draw_description( const catacurses::window &win, const bionic &bio,
const Character &who )
{
werase( win );
const int width = getmaxx( win );
Expand All @@ -384,7 +385,8 @@ static void draw_description( const catacurses::window &win, const bionic &bio )

// TODO: Unhide when enforcing limits
if( get_option < bool >( "CBM_SLOTS_ENABLED" ) ) {
const bool each_bp_on_new_line = ypos + static_cast<int>( num_bp ) + 1 < getmaxy( win );
int body_part_count = who.get_all_body_parts().size();
const bool each_bp_on_new_line = ypos + body_part_count + 1 < getmaxy( win );
fold_and_print( win, point( 0, ypos ), width, c_light_gray, list_occupied_bps( bio.id,
_( "This bionic occupies the following body parts:" ), each_bp_on_new_line ) );
}
Expand Down Expand Up @@ -707,7 +709,7 @@ void show_bionics_ui( Character &who )

draw_bionics_titlebar( w_title, &who, menu_mode );
if( menu_mode == EXAMINING && !current_bionic_list->empty() ) {
draw_description( w_description, *( *current_bionic_list )[cursor] );
draw_description( w_description, *( *current_bionic_list )[cursor], who );
}
} );

Expand Down
Loading
Loading