Skip to content

Commit

Permalink
Merge pull request #78140 from PatrikLundell/typify
Browse files Browse the repository at this point in the history
typified item.h + cpp
  • Loading branch information
Maleclypse authored Dec 4, 2024
2 parents 42953ae + aac168d commit 1bd3650
Show file tree
Hide file tree
Showing 42 changed files with 394 additions and 403 deletions.
18 changes: 9 additions & 9 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,10 @@ static hack_result hack_attempt( Character &who, item_location &tool )
int success = std::ceil( normal_roll( hack_level( who, tool ), hack_stddev ) );
if( success < 0 ) {
who.add_msg_if_player( _( "You cause a short circuit!" ) );
tool->ammo_consume( tool->ammo_required(), tool.position(), &who );
tool->ammo_consume( tool->ammo_required(), tool.pos_bub(), &who );

if( success <= -5 ) {
tool->ammo_consume( ( tool->ammo_required() * 2 ), tool.position(), &who );
tool->ammo_consume( ( tool->ammo_required() * 2 ), tool.pos_bub(), &who );
}
return hack_result::FAIL;
} else if( success < 6 ) {
Expand Down Expand Up @@ -1417,7 +1417,7 @@ void hacksaw_activity_actor::do_turn( player_activity &/*act*/, Character &who )
ammo_consumed *= iter->second;
}

tool->ammo_consume( ammo_consumed, tool.position(), &who );
tool->ammo_consume( ammo_consumed, tool.pos_bub(), &who );
sfx::play_activity_sound( "tool", "hacksaw", sfx::get_heard_volume( target ) );
if( calendar::once_every( 1_minutes ) ) {
//~ Sound of a metal sawing tool at work!
Expand Down Expand Up @@ -2642,7 +2642,7 @@ void boltcutting_activity_actor::start( player_activity &act, Character &/*who*/
void boltcutting_activity_actor::do_turn( player_activity &/*act*/, Character &who )
{
if( tool->ammo_sufficient( &who ) ) {
tool->ammo_consume( tool->ammo_required(), tool.position(), &who );
tool->ammo_consume( tool->ammo_required(), tool.pos_bub(), &who );
} else {
if( who.is_avatar() ) {
who.add_msg_if_player( m_bad, _( "Your %1$s ran out of charges." ), tool->tname() );
Expand Down Expand Up @@ -5429,7 +5429,7 @@ void oxytorch_activity_actor::start( player_activity &act, Character &/*who*/ )
void oxytorch_activity_actor::do_turn( player_activity &/*act*/, Character &who )
{
if( tool->ammo_sufficient( &who ) ) {
tool->ammo_consume( tool->ammo_required(), tool.position(), &who );
tool->ammo_consume( tool->ammo_required(), tool.pos_bub(), &who );
sfx::play_activity_sound( "tool", "oxytorch", sfx::get_heard_volume( target ) );
if( calendar::once_every( 2_turns ) ) {
sounds::sound( target, 10, sounds::sound_t::destructive_activity, _( "hissssssssss!" ) );
Expand Down Expand Up @@ -5900,7 +5900,7 @@ void prying_activity_actor::do_turn( player_activity &/*act*/, Character &who )
if( iter != tool->type->ammo_scale.end() ) {
ammo_consumed *= iter->second;
}
tool->ammo_consume( ammo_consumed, tool.position(), &who );
tool->ammo_consume( ammo_consumed, tool.pos_bub(), &who );
if( prying_nails ) {
sfx::play_activity_sound( "tool", "hammer", sfx::get_heard_volume( target ) );
}
Expand Down Expand Up @@ -6763,12 +6763,12 @@ void firstaid_activity_actor::finish( player_activity &act, Character &who )
it.remove_item();
} else if( used_tool->is_medication() ) {
if( !it->count_by_charges() ||
it->use_charges( it->typeId(), charges_consumed, used, it.position() ) ) {
it->use_charges( it->typeId(), charges_consumed, used, it.pos_bub() ) ) {
it.remove_item();
}
} else if( used_tool->is_tool() ) {
if( used_tool->type->charges_to_use() ) {
it->activation_consume( charges_consumed, it.position(), &who );
it->activation_consume( charges_consumed, it.pos_bub(), &who );
}
}

Expand Down Expand Up @@ -7871,7 +7871,7 @@ void heat_activity_actor::finish( player_activity &act, Character &p )
get_map().veh_at( h.vpt ).value().vehicle().discharge_battery( requirements.ammo *
h.heating_effect );
} else {
h.loc->activation_consume( requirements.ammo, h.loc.position(), &p );
h.loc->activation_consume( requirements.ammo, h.loc.pos_bub(), &p );
}
}
p.add_msg_if_player( m_good, _( "You heated your items." ) );
Expand Down
8 changes: 4 additions & 4 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ void activity_handlers::butcher_finish( player_activity *act, Character *you )

// Dump items from the "container" before destroying it.
// Presumably, the character would be doing this while setting up for butchering.
corpse_item.spill_contents( target.position() );
corpse_item.spill_contents( target.pos_bub() );
corpse_item.erase_var( butcher_progress_var( action ) );

if( action == butcher_type::QUARTER ) {
Expand Down Expand Up @@ -1904,7 +1904,7 @@ void activity_handlers::start_fire_finish( player_activity *act, Character *you
return;
}

it.activation_consume( 1, you->pos(), you );
it.activation_consume( 1, you->pos_bub(), you );

you->practice( skill_survival, act->index, 5 );

Expand Down Expand Up @@ -2205,7 +2205,7 @@ void activity_handlers::vibe_do_turn( player_activity *act, Character *you )

if( calendar::once_every( 1_minutes ) ) {
if( vibrator_item.ammo_remaining( you ) > 0 ) {
vibrator_item.ammo_consume( 1, you->pos(), you );
vibrator_item.ammo_consume( 1, you->pos_bub(), you );
you->add_morale( morale_feeling_good, 3, 40 );
if( vibrator_item.ammo_remaining( you ) == 0 ) {
add_msg( m_info, _( "The %s runs out of batteries." ), vibrator_item.tname() );
Expand Down Expand Up @@ -2504,7 +2504,7 @@ void repair_item_finish( player_activity *act, Character *you, bool no_menu )

if( attempt != repair_item_actor::AS_CANT ) {
if( ploc && ploc->where() == item_location::type::map ) {
used_tool->ammo_consume( used_tool->ammo_required(), ploc->position(), you );
used_tool->ammo_consume( used_tool->ammo_required(), ploc->pos_bub(), you );
} else {
you->consume_charges( *used_tool, used_tool->ammo_required() );
}
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ bool avatar::invoke_item( item *used, const tripoint_bub_ms &pt, int pre_obtain_
} else if( num_methods == 1 && !has_relic ) {
return invoke_item( used, use_methods.begin()->first, pt, pre_obtain_moves );
} else if( num_methods == 0 && has_relic ) {
return used->use_relic( *this, pt.raw() );
return used->use_relic( *this, pt );
}

uilist umenu;
Expand Down Expand Up @@ -1507,7 +1507,7 @@ bool avatar::invoke_item( item *used, const tripoint_bub_ms &pt, int pre_obtain_
int choice = umenu.ret;
// Use the relic
if( choice == num_methods ) {
return used->use_relic( *this, pt.raw() );
return used->use_relic( *this, pt );
}
if( choice < 0 || choice >= num_methods ) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void drop_or_embed_projectile( const dealt_projectile_attack &attack )
}
if( effects.count( ammo_effect_ACT_ON_RANGED_HIT ) ) {
// Don't drop if it exploded
do_drop = !dropped_item.activate_thrown( attack.end_point.raw() );
do_drop = !dropped_item.activate_thrown( attack.end_point );
}

map &here = get_map();
Expand Down
30 changes: 15 additions & 15 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2411,7 +2411,7 @@ void Character::process_turn()
last_item = itype_null;

cache_visit_items_with( "is_relic", &item::is_relic, [this]( item & it ) {
it.process_relic( this, pos() );
it.process_relic( this, pos_bub() );
} );

suffer();
Expand Down Expand Up @@ -7158,15 +7158,15 @@ bool Character::invoke_item( item *used, const std::string &method, const tripoi

if( actually_used->is_comestible() ) {
const bool ret = consume_effects( *used );
const int consumed = used->activation_consume( charges_used.value(), pt.raw(), this );
const int consumed = used->activation_consume( charges_used.value(), pt, this );
if( consumed == 0 ) {
// Nothing was consumed from within the item. "Eat" the item itself away.
i_rem( actually_used );
}
return ret;
}

actually_used->activation_consume( charges_used.value(), pt.raw(), this );
actually_used->activation_consume( charges_used.value(), pt, this );

if( actually_used->has_flag( flag_SINGLE_USE ) || actually_used->is_bionic() ||
actually_used->is_deployable() ) {
Expand Down Expand Up @@ -9606,10 +9606,10 @@ units::energy Character::consume_ups( units::energy qty, const int radius )
if( qty != 0_kJ ) {
cache_visit_items_with( flag_IS_UPS, [&qty]( item & it ) {
if( it.is_tool() && it.type->tool->fuel_efficiency >= 0 ) {
qty -= it.energy_consume( qty, tripoint::zero, nullptr,
qty -= it.energy_consume( qty, tripoint_bub_ms::zero, nullptr,
it.type->tool->fuel_efficiency );
} else {
qty -= it.energy_consume( qty, tripoint::zero, nullptr );
qty -= it.energy_consume( qty, tripoint_bub_ms::zero, nullptr );
}
} );
}
Expand Down Expand Up @@ -9660,7 +9660,7 @@ std::list<item> Character::use_charges( const itype_id &what, int qty, const int
}
if( qty > 0 ) {
visit_items( [this, &what, &qty, &res, &del, &filter, &in_tools]( item * e, item * ) {
if( e->use_charges( what, qty, res, pos(), filter, this, in_tools ) ) {
if( e->use_charges( what, qty, res, pos_bub(), filter, this, in_tools ) ) {
del.push_back( e );
}
return qty > 0 ? VisitResponse::NEXT : VisitResponse::ABORT;
Expand Down Expand Up @@ -12740,11 +12740,11 @@ void Character::leak_items()
{
std::vector<item_location> removed_items;
if( weapon.is_container() ) {
if( weapon.leak( get_map(), this, pos() ) ) {
weapon.spill_contents( pos() );
if( weapon.leak( get_map(), this, pos_bub() ) ) {
weapon.spill_contents( pos_bub() );
}
} else if( weapon.made_of( phase_id::LIQUID ) ) {
if( weapon.leak( get_map(), this, pos() ) ) {
if( weapon.leak( get_map(), this, pos_bub() ) ) {
get_map().add_item_or_charges( pos_bub(), weapon );
removed_items.emplace_back( *this, &weapon );
add_msg_if_player( m_warning, _( "%s spilled from your hand." ), weapon.tname() );
Expand All @@ -12755,8 +12755,8 @@ void Character::leak_items()
if( !it || ( !it->is_container() && !it->made_of( phase_id::LIQUID ) ) ) {
continue;
}
if( it->leak( get_map(), this, pos() ) ) {
it->spill_contents( pos() );
if( it->leak( get_map(), this, pos_bub() ) ) {
it->spill_contents( pos_bub() );
removed_items.push_back( it );
}
}
Expand All @@ -12767,8 +12767,8 @@ void Character::leak_items()

void Character::process_items()
{
if( weapon.process( get_map(), this, pos() ) ) {
weapon.spill_contents( pos() );
if( weapon.process( get_map(), this, pos_bub() ) ) {
weapon.spill_contents( pos_bub() );
remove_weapon();
}

Expand All @@ -12777,8 +12777,8 @@ void Character::process_items()
if( !it ) {
continue;
}
if( it->process( get_map(), this, pos() ) ) {
it->spill_contents( pos() );
if( it->process( get_map(), this, pos_bub() ) ) {
it->spill_contents( pos_bub() );
removed_items.push_back( it );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/character_armor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
} else if( armor.has_flag( flag_USE_POWER_WHEN_HIT ) &&
units::from_kilojoule( du.amount ) < armor.energy_remaining( nullptr, true ) ) {
armor.energy_consume( units::from_kilojoule( du.amount ),
pos(), nullptr );
pos_bub(), nullptr );
}
// We copy the damage unit here since it will be mutated by mitigate_damage()
damage_unit pre_mitigation = du;
Expand Down Expand Up @@ -321,7 +321,7 @@ bool Character::armor_absorb( damage_unit &du, item &armor, const bodypart_id &b
} else if( armor.has_flag( flag_USE_POWER_WHEN_HIT ) &&
units::from_kilojoule( du.amount ) < armor.energy_remaining( nullptr, true ) ) {
armor.energy_consume( units::from_kilojoule( du.amount ),
pos(), nullptr );
pos_bub(), nullptr );
}
// We copy the damage unit here since it will be mutated by mitigate_damage()
damage_unit pre_mitigation = du;
Expand Down
2 changes: 1 addition & 1 deletion src/character_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ item Character::i_rem( const item *it )

void Character::i_rem_keep_contents( const item *const it )
{
i_rem( it ).spill_contents( pos() );
i_rem( it ).spill_contents( pos_bub() );
}

bool Character::i_add_or_drop( item &it, int qty, const item *avoid,
Expand Down
4 changes: 2 additions & 2 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,7 @@ std::list<item> Character::consume_items( map &m, const comp_selection<item_comp
it.spill_contents( *this );
}
// todo: make a proper solution that overflows with the proper item_location
it.overflow( pos() );
it.overflow( pos_bub() );
}
empty_buckets( *this );
return ret;
Expand Down Expand Up @@ -2597,7 +2597,7 @@ item_location Character::create_in_progress_disassembly( item_location target )
remove_ammo( orig_item, *this );
remove_radio_mod( orig_item, *this );
if( orig_item.is_container() ) {
orig_item.spill_contents( pos() );
orig_item.spill_contents( pos_bub() );
}
if( orig_item.count_by_charges() ) {
//subtract selected number of rounds to disassemble
Expand Down
2 changes: 1 addition & 1 deletion src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ avatar::smash_result avatar::smash( tripoint_bub_ms &smashp )
const int vol = weapon->volume() * glass_fraction / units::legacy_volume_factor;
if( glass_portion && rng( 0, vol + 3 ) < vol ) {
add_msg( m_bad, _( "Your %s shatters!" ), weapon->tname() );
weapon->spill_contents( pos() );
weapon->spill_contents( pos_bub() );
sounds::sound( pos(), 24, sounds::sound_t::combat, "CRACK!", true, "smash",
"glass" );
deal_damage( nullptr, bodypart_id( "hand_r" ), damage_instance( damage_cut,
Expand Down
8 changes: 4 additions & 4 deletions src/iexamine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ bool iexamine::try_start_hacking( Character &you, const tripoint_bub_ms &examp )
return false;
} else {
item_location hacking_tool = item_location{you, &you.best_item_with_quality( qual_HACK )};
hacking_tool->ammo_consume( hacking_tool->ammo_required(), hacking_tool.position(), &you );
hacking_tool->ammo_consume( hacking_tool->ammo_required(), hacking_tool.pos_bub(), &you );
you.assign_activity( hacking_activity_actor( hacking_tool ) );
you.activity.placement = get_map().getglobal( examp );
return true;
Expand Down Expand Up @@ -4925,7 +4925,7 @@ static void reload_furniture( Character &you, const tripoint_bub_ms &examp, bool
you.mod_moves( -you.item_handling_cost( moved ) );
std::list<item>used;
if( opt.ammo.get_item()->use_charges( opt_type->get_id(), amount, used,
opt.ammo.position() ) ) {
opt.ammo.pos_bub() ) ) {
opt.ammo.remove_item();
}

Expand Down Expand Up @@ -6304,7 +6304,7 @@ static void mill_activate( Character &you, const tripoint_bub_ms &examp )
for( item &it : here.i_at( examp ) ) {
if( it.type->milling_data && !it.type->milling_data->into_.is_null() ) {
// Do one final rot check before milling, then apply the PROCESSING flag to prevent further checks.
it.process_temperature_rot( 1, examp.raw(), get_map(), nullptr );
it.process_temperature_rot( 1, examp, get_map(), nullptr );
it.set_flag( flag_PROCESSING );
}
}
Expand Down Expand Up @@ -6405,7 +6405,7 @@ static void smoker_activate( Character &you, const tripoint_bub_ms &examp )
you.use_charges( itype_fire, 1 );
for( item &it : here.i_at( examp ) ) {
if( it.has_flag( flag_SMOKABLE ) ) {
it.process_temperature_rot( 1, examp.raw(), get_map(), nullptr );
it.process_temperature_rot( 1, examp, get_map(), nullptr );
it.set_flag( flag_PROCESSING );
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/iexamine_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ std::vector<item_location> cardreader_examine_actor::get_cards( Character &you,
continue;
}
if( omt_allowed_radius ) {
tripoint cardloc = it->get_var( "spawn_location_omt", tripoint::invalid );
tripoint_abs_omt cardloc = it->get_var( "spawn_location_omt", tripoint_abs_omt::min );
// Cards without a location are treated as valid
if( cardloc == tripoint::min ) {
if( cardloc == tripoint_abs_omt::min ) {
ret.push_back( it );
continue;
}
int dist = rl_dist( cardloc.xy(),
coords::project_to<coords::omt>( get_map().getglobal( examp ) ).xy().raw() );
coords::project_to<coords::omt>( get_map().getglobal( examp ) ).xy() );
if( dist > *omt_allowed_radius ) {
continue;
}
Expand Down
Loading

0 comments on commit 1bd3650

Please sign in to comment.