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

Expand NULL_ID() usage #79190

Merged
merged 4 commits into from
Jan 17, 2025
Merged
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
16 changes: 15 additions & 1 deletion data/core/sentinels.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@
"base_hp": 60,
"drench_capacity": 1,
"legacy_id": "NUM_BP",
"sub_parts": [ "sub_limb_debug" ]
"sub_parts": [ "sub_bp_null" ]
},
{
"id": "sub_bp_null",
"type": "sub_body_part",
"parent": "bp_null",
"side": 0,
"opposite": "sub_bp_null",
"name": { "str": "Null sub_body_part, if you see this please report it", "//~": "NO_I18N" }
},
{
"id": "mx_null",
Expand Down Expand Up @@ -50,6 +58,12 @@
"name": { "str": "This is a bug" },
"description": "This fault id is a reserved sentinel."
},
{
"type": "attack_vector",
"id": "vector_null",
"//": "Fallback weapon vector, unarmed attacks always go through techs",
"weapon": true
},
{
"type": "SPELL",
"id": "null",
Expand Down
6 changes: 0 additions & 6 deletions data/json/attack_vectors.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[
{
"type": "attack_vector",
"id": "vector_null",
"//": "Fallback weapon vector, unarmed attacks always go through techs",
"weapon": true
},
{
"type": "attack_vector",
"id": "test_test",
Expand Down
4 changes: 2 additions & 2 deletions data/json/body_parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -900,15 +900,15 @@
"parent": "bp_null",
"side": 0,
"opposite": "sub_limb_debug",
"name": "debug limb should never be seen"
"name": { "str": "debug limb should never be seen", "//~": "NO_I18N" }
},
{
"id": "sub_limb_debug_tail",
"type": "sub_body_part",
"parent": "debug_tail",
"side": 0,
"opposite": "sub_limb_debug_tail",
"name": "debug limb for debug tail"
"name": { "str": "debug limb for debug tail", "//~": "NO_I18N" }
},
{
"id": "torso_upper",
Expand Down
17 changes: 9 additions & 8 deletions src/armor_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ std::vector<std::string> clothing_properties(
_( "Item provides no protection" ) ) );
return props;
}
if( bp == bodypart_id( "bp_null" ) ) {
if( bp == bodypart_str_id::NULL_ID() ) {
// if the armor has no protection data
if( worn_item.find_armor_data()->sub_data.empty() ) {
props.push_back( string_format( "<color_c_red>%s</color>",
Expand Down Expand Up @@ -356,7 +356,7 @@ std::vector<std::string> clothing_protection( const item &worn_item, const int w
}

// if bp is null its gonna be impossible to really get good info
if( bp == bodypart_id( "bp_null" ) ) {
if( bp == bodypart_str_id::NULL_ID() ) {
// if we have exactly one entry for armor we can use that data
if( worn_item.find_armor_data()->sub_data.size() == 1 ) {
used_bp = *worn_item.get_covered_body_parts().begin();
Expand Down Expand Up @@ -464,7 +464,7 @@ item_penalties outfit::get_item_penalties( std::list<item>::const_iterator worn_
std::vector<std::set<std::string>> lists_of_bad_items_within;

for( const bodypart_id &bp : c.get_all_body_parts() ) {
if( bp != _bp && _bp != bodypart_id( "bp_null" ) ) {
if( bp != _bp && _bp != bodypart_str_id::NULL_ID() ) {
continue;
}
if( !worn_item_it->covers( bp ) ) {
Expand Down Expand Up @@ -614,7 +614,7 @@ void outfit::sort_armor( Character &guy )
for( const bodypart_id &it : guy.get_all_body_parts() ) {
armor_cat.insert( it );
}
armor_cat.insert( bodypart_id( "bp_null" ) );
armor_cat.insert( bodypart_str_id::NULL_ID() );
const int num_of_parts = guy.get_all_body_parts().size();

int win_h = 0;
Expand Down Expand Up @@ -713,7 +713,7 @@ void outfit::sort_armor( Character &guy )
// Create ptr list of items to display
tmp_worn.clear();
const bodypart_id &bp = armor_cat[ tabindex ];
if( bp == bodypart_id( "bp_null" ) ) {
if( bp == bodypart_str_id::NULL_ID() ) {
// All
for( auto it = worn.begin(); it != worn.end(); ++it ) {
tmp_worn.push_back( it );
Expand Down Expand Up @@ -754,7 +754,8 @@ void outfit::sort_armor( Character &guy )
// top bar
std::string header_title = _( "Sort Armor" );
wprintz( w_sort_cat, c_white, header_title );
std::string temp = bp != bodypart_id( "bp_null" ) ? body_part_name_as_heading( bp, 1 ) : _( "All" );
std::string temp = bp == bodypart_str_id::NULL_ID() ? _( "All" ) : body_part_name_as_heading( bp,
1 );
temp = string_format( " << %s >>", temp );
wprintz( w_sort_cat, c_yellow, temp );
int keyhint_offset = utf8_width( header_title ) + utf8_width( temp ) + 1;
Expand Down Expand Up @@ -864,7 +865,7 @@ void outfit::sort_armor( Character &guy )
// Right list
rightListSize = 0;
for( const bodypart_id &cover : armor_cat ) {
if( cover == bodypart_id( "bp_null" ) ) {
if( cover == bodypart_str_id::NULL_ID() ) {
continue;
}
if( !combine_bp( cover ) || rl.count( cover.obj().opposite_part ) == 0 ) {
Expand All @@ -882,7 +883,7 @@ void outfit::sort_armor( Character &guy )
int encumbrance_char_allowance = 4; //Enough for " 99+", will increase if necessary
int item_name_offset = 2;
for( const bodypart_id &cover : rl ) {
if( cover == bodypart_id( "bp_null" ) ) {
if( cover == bodypart_str_id::NULL_ID() ) {
continue;
}
if( curr >= rightListOffset && pos <= rightListLines ) {
Expand Down
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,7 +1840,7 @@ void avatar::add_pain_msg( int val, const bodypart_id &bp ) const
if( has_flag( json_flag_PAIN_IMMUNE ) ) {
return;
}
if( bp == bodypart_id( "bp_null" ) ) {
if( bp == bodypart_str_id::NULL_ID() ) {
if( val > 20 ) {
add_msg_if_player( _( "Your body is wracked with excruciating pain!" ) );
} else if( val > 10 ) {
Expand Down
20 changes: 9 additions & 11 deletions src/bodypart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

const bodypart_str_id body_part_arm_l( "arm_l" );
const bodypart_str_id body_part_arm_r( "arm_r" );
const bodypart_str_id body_part_bp_null( "bp_null" );
const bodypart_str_id body_part_eyes( "eyes" );
const bodypart_str_id body_part_foot_l( "foot_l" );
const bodypart_str_id body_part_foot_r( "foot_r" );
Expand All @@ -35,8 +34,6 @@ const bodypart_str_id body_part_leg_r( "leg_r" );
const bodypart_str_id body_part_mouth( "mouth" );
const bodypart_str_id body_part_torso( "torso" );

const sub_bodypart_str_id sub_body_part_sub_limb_debug( "sub_limb_debug" );

side opposite_side( side s )
{
switch( s ) {
Expand Down Expand Up @@ -641,7 +638,7 @@ std::set<translation, localized_comparator> body_part_type::consolidate(
//first try to compress sets of sub body parts together into a full limb
for( size_t i = 0; i < covered.size(); i++ ) {
const sub_bodypart_id &sbp = covered[i];
if( sbp == sub_body_part_sub_limb_debug ) {
if( sbp == sub_bodypart_str_id::NULL_ID() ) {
// if we have already covered this continue
continue;
}
Expand All @@ -650,9 +647,10 @@ std::set<translation, localized_comparator> body_part_type::consolidate(
bool found_all = true;
for( const sub_bodypart_str_id &searching : sbp->parent->sub_parts ) {
//skip secondary locations for this
if( !searching->secondary ) {
found_all = std::find( covered.begin(), covered.end(), searching.id() ) != covered.end() &&
found_all;
if( !searching->secondary &&
std::find( covered.begin(), covered.end(), searching.id() ) == covered.end() ) {
found_all = false;
break;
}
}

Expand All @@ -664,7 +662,7 @@ std::set<translation, localized_comparator> body_part_type::consolidate(
for( const sub_bodypart_str_id &searching : sbp->parent->sub_parts ) {
if( !searching->secondary ) {
auto sbp_it = std::find( covered.begin(), covered.end(), searching.id() );
*sbp_it = sub_body_part_sub_limb_debug;
*sbp_it = sub_bodypart_str_id::NULL_ID();
}
}
}
Expand Down Expand Up @@ -698,13 +696,13 @@ std::set<translation, localized_comparator> body_part_type::consolidate(

for( size_t i = 0; i < covered.size(); i++ ) {
const sub_bodypart_id &sbp = covered[i];
if( sbp == sub_body_part_sub_limb_debug ) {
if( sbp == sub_bodypart_str_id::NULL_ID() ) {
// if we have already covered this value as a pair continue
continue;
}
sub_bodypart_id temp;
// if our sub part has an opposite
if( sbp->opposite != sub_body_part_sub_limb_debug ) {
if( sbp->opposite != sub_bodypart_str_id::NULL_ID() ) {
temp = sbp->opposite;
} else {
// if it doesn't have an opposite add it to the return vector alone and continue
Expand All @@ -720,7 +718,7 @@ std::set<translation, localized_comparator> body_part_type::consolidate(
to_return.insert( sbp->name_multiple );
found = true;
// set the found part to a null value
sbp_it = sub_body_part_sub_limb_debug;
sbp_it = sub_bodypart_str_id::NULL_ID();
break;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ template <typename T> class generic_factory;
using bodypart_str_id = string_id<body_part_type>;
using bodypart_id = int_id<body_part_type>;

extern const bodypart_str_id body_part_bp_null;
extern const bodypart_str_id body_part_head;
extern const bodypart_str_id body_part_eyes;
extern const bodypart_str_id body_part_mouth;
Expand All @@ -45,8 +44,6 @@ extern const bodypart_str_id body_part_foot_l;
extern const bodypart_str_id body_part_leg_r;
extern const bodypart_str_id body_part_foot_r;

extern const sub_bodypart_str_id sub_body_part_sub_limb_debug;

// The order is important ; pldata.h has to be in the same order
enum body_part : int {
bp_torso = 0,
Expand Down
5 changes: 2 additions & 3 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ void Character::forced_dismount()
}
const int dodge = get_dodge();
const int damage = std::max( 0, rng( 1, 20 ) - rng( dodge, dodge * 2 ) );
bodypart_id hit( "bp_null" );
bodypart_id hit = bodypart_str_id::NULL_ID();
switch( rng( 1, 10 ) ) {
case 1:
if( one_in( 2 ) ) {
Expand Down Expand Up @@ -3710,8 +3710,7 @@ void Character::apply_skill_boost()

std::pair<bodypart_id, int> Character::best_part_to_smash() const
{
const bodypart_id bp_null( "bp_null" );
std::pair<bodypart_id, int> best_part_to_smash = {bp_null, 0};
std::pair<bodypart_id, int> best_part_to_smash = {bodypart_str_id::NULL_ID().id(), 0};
int tmp_bash_armor = 0;
for( const bodypart_id &bp : get_all_body_parts() ) {
tmp_bash_armor += worn.damage_resist( damage_bash, bp );
Expand Down
2 changes: 1 addition & 1 deletion src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -3202,7 +3202,7 @@ class Character : public Creature, public visitable
void on_item_acquire( const item &it );
/** Called when effect intensity has been changed */
void on_effect_int_change( const efftype_id &eid, int intensity,
const bodypart_id &bp = bodypart_id( "bp_null" ) ) override;
const bodypart_id &bp = bodypart_str_id::NULL_ID() ) override;
/** Called when a mutation is gained */
void on_mutation_gain( const trait_id &mid );
/** Called when a mutation is lost */
Expand Down
6 changes: 3 additions & 3 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,7 @@ void Creature::set_body()

bool Creature::has_part( const bodypart_id &id, body_part_filter filter ) const
{
return get_part_id( id, filter, true ) != body_part_bp_null;
return get_part_id( id, filter, true ) != bodypart_str_id::NULL_ID();
}

bodypart *Creature::get_part( const bodypart_id &id )
Expand Down Expand Up @@ -2423,7 +2423,7 @@ bodypart_id Creature::get_part_id( const bodypart_id &id,
}
}
// try to find the next best thing
std::pair<bodypart_id, float> best = { body_part_bp_null, 0.0f };
std::pair<bodypart_id, float> best = { bodypart_str_id::NULL_ID().id(), 0.0f };
if( filter >= body_part_filter::next_best ) {
for( const std::pair<const bodypart_str_id, bodypart> &bp : body ) {
for( const std::pair<const body_part_type::type, float> &mp : bp.first->limbtypes ) {
Expand All @@ -2436,7 +2436,7 @@ bodypart_id Creature::get_part_id( const bodypart_id &id,
}
}
}
if( best.first == body_part_bp_null && !suppress_debugmsg ) {
if( best.first == bodypart_str_id::NULL_ID() && !suppress_debugmsg ) {
debugmsg( "Could not find equivalent bodypart id %s in %s's body", id.id().c_str(), get_name() );
}

Expand Down
6 changes: 3 additions & 3 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ static void character_edit_hp_menu( Character &you )
hotkey++;
}
smenu.addentry( pos, true, hotkey, "%s: %d", _( "All" ), you.get_lowest_hp() );
part_ids.emplace_back( body_part_bp_null );
part_ids.emplace_back( bodypart_str_id::NULL_ID().id() );
smenu.query();
bodypart_str_id bp = body_part_no_a_real_part;
bool all_select = false;
Expand All @@ -2071,11 +2071,11 @@ static void character_edit_hp_menu( Character &you )
return;
}
bp = part_ids.at( smenu.ret ).id();
if( bp == body_part_bp_null ) {
if( bp == bodypart_str_id::NULL_ID() ) {
all_select = true;
}

if( bp.is_valid() && bp != body_part_bp_null ) {
if( bp.is_valid() && bp != bodypart_str_id::NULL_ID() ) {
int value;
if( query_int( value, _( "Set the hitpoints to? Currently: %d" ),
you.get_part_hp_cur( bp.id() ) ) &&
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class wear_inventory_preset: public armor_inventory_preset
return loc->is_armor() &&
( !loc.has_parent() || !is_worn_ablative( loc.parent_item(), loc ) ) &&
!you.is_worn( *loc ) &&
( bp != bodypart_id( "bp_null" ) ? loc->covers( bp ) : true );
( bp != bodypart_str_id::NULL_ID() ? loc->covers( bp ) : true );
}

std::string get_denial( const item_location &loc ) const override {
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ item_location molle_attach( Character &you, item &tool );
item_location veh_tool_attach( Character &you, const std::string &vp_name,
const std::set<itype_id> &allowed_types );
/** Choose item to wear. */
item_location wear( Character &you, const bodypart_id &bp = bodypart_id( "bp_null" ) );
item_location wear( Character &you, const bodypart_id &bp = bodypart_str_id::NULL_ID() );
/** Choose item to take off. */
item_location take_off();
/** Item cut up menu. */
Expand Down
3 changes: 1 addition & 2 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,9 +1047,8 @@ avatar::smash_result avatar::smash( tripoint_bub_ms &smashp )
}

if( !has_weapon() ) {
const bodypart_id bp_null( "bp_null" );
std::pair<bodypart_id, int> best_part_to_smash = this->best_part_to_smash();
if( best_part_to_smash.first != bp_null && here.is_bashable( smashp ) ) {
if( best_part_to_smash.first != bodypart_str_id::NULL_ID() && here.is_bashable( smashp ) ) {
std::string name_to_bash = _( "thing" );
if( here.is_bashable_furn( smashp ) ) {
name_to_bash = here.furnname( smashp );
Expand Down
18 changes: 8 additions & 10 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ static const ammotype ammo_bolt( "bolt" );
static const ammotype ammo_money( "money" );
static const ammotype ammo_plutonium( "plutonium" );

static const attack_vector_id attack_vector_vector_null( "vector_null" );

static const bionic_id bio_digestion( "bio_digestion" );

static const bodygraph_id bodygraph_full_body_iteminfo( "full_body_iteminfo" );
Expand Down Expand Up @@ -2318,8 +2316,8 @@ double item::effective_dps( const Character &guy, Creature &mon ) const
Creature *temp_mon = &mon;
double subtotal_damage = 0;
damage_instance base_damage;
guy.roll_all_damage( crit, base_damage, true, *this, attack_vector_vector_null,
sub_body_part_sub_limb_debug, &mon, bp );
guy.roll_all_damage( crit, base_damage, true, *this, attack_vector_id::NULL_ID(),
sub_bodypart_str_id::NULL_ID(), &mon, bp );
damage_instance dealt_damage = base_damage;
dealt_damage = guy.modify_damage_dealt_with_enchantments( dealt_damage );
// TODO: Modify DPS calculation to consider weakpoints.
Expand All @@ -2345,8 +2343,8 @@ double item::effective_dps( const Character &guy, Creature &mon ) const
if( has_technique( RAPID ) ) {
Creature *temp_rs_mon = &mon;
damage_instance rs_base_damage;
guy.roll_all_damage( crit, rs_base_damage, true, *this, attack_vector_vector_null,
sub_body_part_sub_limb_debug, &mon, bp );
guy.roll_all_damage( crit, rs_base_damage, true, *this, attack_vector_id::NULL_ID(),
sub_bodypart_str_id::NULL_ID(), &mon, bp );
damage_instance dealt_rs_damage = rs_base_damage;
for( damage_unit &dmg_unit : dealt_rs_damage.damage_units ) {
dmg_unit.damage_multiplier *= 0.66;
Expand Down Expand Up @@ -5622,11 +5620,11 @@ void item::melee_combat_info( std::vector<iteminfo> &info, const iteminfo_query
( !dmg_types.empty() || type->m_to_hit > 0 ) ) || debug_mode ) {
bodypart_id bp = bodypart_id( "torso" );
damage_instance non_crit;
player_character.roll_all_damage( false, non_crit, true, *this, attack_vector_vector_null,
sub_body_part_sub_limb_debug, nullptr, bp );
player_character.roll_all_damage( false, non_crit, true, *this, attack_vector_id::NULL_ID(),
sub_bodypart_str_id::NULL_ID(), nullptr, bp );
damage_instance crit;
player_character.roll_all_damage( true, crit, true, *this, attack_vector_vector_null,
sub_body_part_sub_limb_debug, nullptr, bp );
player_character.roll_all_damage( true, crit, true, *this, attack_vector_id::NULL_ID(),
sub_bodypart_str_id::NULL_ID(), nullptr, bp );
int attack_cost = player_character.attack_speed( *this );
insert_separation_line( info );
if( parts->test( iteminfo_parts::DESCRIPTION_MELEEDMG ) ) {
Expand Down
Loading
Loading