Skip to content

Commit

Permalink
Removed one getlocal (#73940)
Browse files Browse the repository at this point in the history
Co-authored-by: RenechCDDA <[email protected]>
  • Loading branch information
PatrikLundell and RenechCDDA authored May 25, 2024
1 parent 76300ac commit 4c6b918
Show file tree
Hide file tree
Showing 58 changed files with 257 additions and 176 deletions.
2 changes: 1 addition & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6955,7 +6955,7 @@ void longsalvage_activity_actor::finish( player_activity &act, Character &who )
// Check first and only if possible attempt it with player char
// This suppresses warnings unless it is an item the player wears
if( actor->valid_to_cut_up( nullptr, it ) ) {
item_location item_loc( map_cursor( who.pos() ), &it );
item_location item_loc( map_cursor( who.pos_bub() ), &it );
actor->try_to_cut_up( who, *salvage_tool, item_loc );
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ void activity_handlers::vehicle_finish( player_activity *act, Character *you )
{
map &here = get_map();
//Grab this now, in case the vehicle gets shifted
const optional_vpart_position vp = here.veh_at( here.getlocal( tripoint( act->values[0],
const optional_vpart_position vp = here.veh_at( here.bub_from_abs( tripoint( act->values[0],
act->values[1],
you->posz() ) ) );
veh_interact::complete_vehicle( *you );
Expand Down Expand Up @@ -3872,7 +3872,7 @@ void activity_handlers::spellcasting_finish( player_activity *act, Character *yo

// choose target for spell before continuing
const std::optional<tripoint> target = act->coords.empty() ? spell_being_cast.select_target(
you ) : get_map().getlocal( act->coords.front() );
you ) : get_map().bub_from_abs( act->coords.front() ).raw();
if( target ) {
// npcs check for target viability
if( !you->is_npc() || spell_being_cast.is_valid_target( *you, *target ) ) {
Expand Down
10 changes: 5 additions & 5 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ std::vector<item_location> drop_on_map( Character &you, item_drop_reason reason,
std::vector<item_location> items_dropped;
for( const item &it : items ) {
item &dropped_item = here.add_item_or_charges( where, it );
items_dropped.emplace_back( map_cursor( where.raw() ), &dropped_item );
items_dropped.emplace_back( map_cursor( where ), &dropped_item );
item( it ).handle_pickup_ownership( you );
}

Expand Down Expand Up @@ -1856,7 +1856,7 @@ static bool fetch_activity(
const int distance = ACTIVITY_SEARCH_DISTANCE )
{
map &here = get_map();
if( !here.can_put_items_ter_furn( here.getlocal( you.backlog.front().coords.back() ) ) ) {
if( !here.can_put_items_ter_furn( here.bub_from_abs( you.backlog.front().coords.back() ) ) ) {
return false;
}
const std::vector<std::tuple<tripoint_bub_ms, itype_id, int>> mental_map_2 =
Expand Down Expand Up @@ -1957,7 +1957,7 @@ static bool butcher_corpse_activity( Character &you, const tripoint_bub_ms &src_
elem.set_var( "activity_var", you.name );
you.assign_activity( ACT_BUTCHER_FULL, 0, true );
// TODO: fix point types
you.activity.targets.emplace_back( map_cursor( src_loc.raw() ), &elem );
you.activity.targets.emplace_back( map_cursor( src_loc ), &elem );
you.activity.placement = here.getglobal( src_loc );
return true;
}
Expand Down Expand Up @@ -3132,7 +3132,7 @@ static bool generic_multi_activity_do(
player_activity act = player_activity( disassemble_activity_actor( r.time_to_craft_moves( you,
recipe_time_flag::ignore_proficiencies ) * qty ) );
// TODO: fix point types
act.targets.emplace_back( map_cursor( src_loc.raw() ), &elem );
act.targets.emplace_back( map_cursor( src_loc ), &elem );
act.placement = here.getglobal( src_loc );
act.position = qty;
act.index = false;
Expand Down Expand Up @@ -3532,7 +3532,7 @@ int get_auto_consume_moves( Character &you, const bool food )
}
} else {
for( item &it : here.i_at( here.getlocal( loc ) ) ) {
item_location i_loc( map_cursor( here.getlocal( loc ) ), &it );
item_location i_loc( map_cursor( here.bub_from_abs( loc ) ), &it );
visit_item_contents( i_loc, visit );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void advanced_inventory_pane::add_items_from_area( advanced_inv_area &square,
square.i_stacked( square.get_vehicle_stack() ) :
square.i_stacked( m.i_at( square.pos ) );

map_cursor loc_cursor( square.pos );
map_cursor loc_cursor( tripoint_bub_ms( square.pos ) );
for( size_t x = 0; x < stacks.size(); ++x ) {
std::vector<item_location> locs;
locs.reserve( stacks[x].size() );
Expand Down
2 changes: 1 addition & 1 deletion src/auto_pickup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ drop_locations auto_pickup::select_items(
const std::vector<item_stack::iterator> &from, const tripoint &location )
{
drop_locations result;
const map_cursor map_location = map_cursor( location );
const map_cursor map_location = map_cursor( tripoint_bub_ms( location ) );

// iterate over all item stacks found in location
for( const item_stack::iterator &stack : from ) {
Expand Down
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ void avatar::rebuild_aim_cache()
{
double pi = 2 * acos( 0.0 );

const tripoint local_last_target = get_map().getlocal( last_target_pos.value() );
const tripoint local_last_target = get_map().bub_from_abs( last_target_pos.value() ).raw();

float base_angle = atan2f( local_last_target.y - posy(),
local_last_target.x - posx() );
Expand Down
2 changes: 1 addition & 1 deletion src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ bool basecamp::point_within_camp( const tripoint_abs_omt &p ) const
void basecamp::load_data( const std::string &data )
{
std::stringstream stream( data );
stream >> name >> bb_pos.x >> bb_pos.y;
stream >> name >> bb_pos.x() >> bb_pos.y();
// add space to name
replace( name.begin(), name.end(), '_', ' ' );
}
Expand Down
17 changes: 10 additions & 7 deletions src/basecamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ class basecamp
return !name.empty() && omt_pos != tripoint_abs_omt();
}
inline int board_x() const {
return bb_pos.x;
return bb_pos.x();
}
inline int board_y() const {
return bb_pos.y;
return bb_pos.y();
}
inline tripoint_abs_omt camp_omt_pos() const {
return omt_pos;
Expand All @@ -179,14 +179,17 @@ class basecamp
return name;
}
tripoint get_bb_pos() const {
return bb_pos.raw();
}
tripoint_abs_ms get_bb_pos_abs() const {
return bb_pos;
}
void validate_bb_pos( const tripoint &new_abs_pos ) {
if( bb_pos == tripoint_zero ) {
void validate_bb_pos( const tripoint_abs_ms &new_abs_pos ) {
if( bb_pos.raw() == tripoint_zero ) {
bb_pos = new_abs_pos;
}
}
void set_bb_pos( const tripoint &new_abs_pos ) {
void set_bb_pos( const tripoint_abs_ms &new_abs_pos ) {
bb_pos = new_abs_pos;
}
void set_by_radio( bool access_by_radio );
Expand Down Expand Up @@ -488,8 +491,8 @@ class basecamp
// omt pos
tripoint_abs_omt omt_pos;
std::vector<npc_ptr> assigned_npcs; // NOLINT(cata-serialize)
// location of associated bulletin board in abs coords
tripoint bb_pos;
// location of associated bulletin board
tripoint_abs_ms bb_pos;
std::map<point, expansion_data> expansions;
comp_list camp_workers; // NOLINT(cata-serialize)
basecamp_map camp_map; // NOLINT(cata-serialize)
Expand Down
8 changes: 4 additions & 4 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ bool Character::check_outbounds_activity( const player_activity &act, bool check
map &here = get_map();
if( ( act.placement != tripoint_abs_ms() && act.placement != player_activity::invalid_place &&
!here.inbounds( here.getlocal( act.placement ) ) ) || ( !act.coords.empty() &&
!here.inbounds( here.getlocal( act.coords.back() ) ) ) ) {
!here.inbounds( here.bub_from_abs( act.coords.back() ) ) ) ) {
if( is_npc() && !check_only ) {
// stash activity for when reloaded.
stashed_outbounds_activity = act;
Expand Down Expand Up @@ -3006,7 +3006,7 @@ std::vector<item_location> Character::nearby( const
return VisitResponse::NEXT;
} );

for( const map_cursor &cur : map_selector( pos(), radius ) ) {
for( const map_cursor &cur : map_selector( pos_bub(), radius ) ) {
cur.visit_items( [&]( const item * e, const item * parent ) {
if( func( e, parent ) ) {
res.emplace_back( cur, const_cast<item *>( e ) );
Expand Down Expand Up @@ -3114,7 +3114,7 @@ units::mass Character::best_nearby_lifting_assist( const tripoint &world_pos ) c
}
}
int lift_quality = std::max( { this->max_quality( qual_LIFT ), mech_lift,
map_selector( this->pos(), PICKUP_RANGE ).max_quality( qual_LIFT ),
map_selector( this->pos_bub(), PICKUP_RANGE ).max_quality( qual_LIFT ),
vehicle_selector( world_pos, 4, true, true ).max_quality( qual_LIFT )
} );
return lifting_quality_to_mass( lift_quality );
Expand Down Expand Up @@ -11380,7 +11380,7 @@ bool Character::has_destination() const
bool Character::has_destination_activity() const
{
return !get_destination_activity().is_null() && destination_point &&
pos() == get_map().getlocal( *destination_point );
pos_bub() == get_map().bub_from_abs( *destination_point );
}

void Character::start_destination_activity()
Expand Down
2 changes: 1 addition & 1 deletion src/character_guns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ std::vector<item_location> Character::find_ammo( const item &obj, bool empty, in
find_ammo_helper( const_cast<Character &>( *this ), obj, empty, std::back_inserter( res ), true );

if( radius >= 0 ) {
for( map_cursor &cursor : map_selector( pos(), radius ) ) {
for( map_cursor &cursor : map_selector( pos_bub(), radius ) ) {
find_ammo_helper( cursor, obj, empty, std::back_inserter( res ), false );
}
for( vehicle_cursor &cursor : vehicle_selector( pos(), radius ) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/character_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ item_location Character::i_add( item it, bool /* should_stack */, const item *av
if( added == item_location::nowhere ) {
if( !allow_wield || !wield( it ) ) {
if( allow_drop ) {
return item_location( map_cursor( pos() ), &get_map().add_item_or_charges( pos(), it ) );
return item_location( map_cursor( pos_bub() ), &get_map().add_item_or_charges( pos(), it ) );
} else {
return added;
}
Expand Down Expand Up @@ -368,7 +368,7 @@ item_location Character::i_add( item it, int &copies_remaining,
}
if( allow_drop && copies_remaining > 0 ) {
item map_added = get_map().add_item_or_charges( pos_bub(), it, copies_remaining );
added = added ? added : item_location( map_cursor( pos() ), &map_added );
added = added ? added : item_location( map_cursor( pos_bub() ), &map_added );
}
}
return added;
Expand All @@ -394,7 +394,7 @@ ret_val<item_location> Character::i_add_or_fill( item &it, bool should_stack, co
if( new_charge >= 1 ) {
if( !allow_wield || !wield( it ) ) {
if( allow_drop ) {
loc = item_location( map_cursor( pos() ), &get_map().add_item_or_charges( pos(), it ) );
loc = item_location( map_cursor( pos_bub() ), &get_map().add_item_or_charges( pos(), it ) );
}
} else {
loc = item_location( *this, &weapon );
Expand Down
2 changes: 1 addition & 1 deletion src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ void zone_manager::add( const std::string &name, const zone_type_id &type, const
zone_data new_zone = zone_data( name, type, fac, invert, enabled, start, end, options, personal );
// only non personal zones can be vehicle zones
if( !personal ) {
optional_vpart_position const vp = here.veh_at( here.getlocal( start ) );
optional_vpart_position const vp = here.veh_at( here.bub_from_abs( start ) );
if( vp && vp->vehicle().get_owner() == fac && vp.cargo() ) {
// TODO:Allow for loot zones on vehicles to be larger than 1x1
if( start == end &&
Expand Down
8 changes: 4 additions & 4 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ static item_location set_item_map( const tripoint &loc, item &newit )
// Pass false to disallow overflow, null_item_reference indicates failure.
item *it_on_map = &get_map().add_item_or_charges( tile, newit, false );
if( it_on_map != &null_item_reference() ) {
return item_location( map_cursor( tile ), it_on_map );
return item_location( map_cursor( tripoint_bub_ms( tile ) ), it_on_map );
}
}
debugmsg( "Could not place %s on map near (%d, %d, %d)", newit.tname(), loc.x, loc.y, loc.z );
Expand Down Expand Up @@ -2736,7 +2736,7 @@ void Character::disassemble_all( bool one_pass )
bool found_any = false;
std::vector<item_location> to_disassemble;
for( item &it : get_map().i_at( pos() ) ) {
to_disassemble.emplace_back( map_cursor( pos() ), &it );
to_disassemble.emplace_back( map_cursor( pos_bub() ), &it );
}
for( item_location &it_loc : to_disassemble ) {
// Prevent disassembling an in process disassembly because it could have been created by a previous iteration of this loop
Expand Down Expand Up @@ -3143,7 +3143,7 @@ item_location npc::get_item_to_craft()
}
for( item &itm : here.i_at( adj ) ) {
if( itm.get_var( "crafter", "" ) == name ) {
to_craft = item_location( map_cursor( adj ), &itm );
to_craft = item_location( map_cursor( tripoint_bub_ms( adj ) ), &itm );
if( !is_anyone_crafting( to_craft, this ) ) {
return to_craft;
}
Expand Down Expand Up @@ -3185,7 +3185,7 @@ void npc::do_npc_craft( const std::optional<tripoint> &loc, const recipe_id &got
}
for( item &itm : here.i_at( adj ) ) {
if( itm.is_craft() && itm.get_making().npc_can_craft( dummy ) ) {
item_location to_craft = item_location( map_cursor( adj ), &itm );
item_location to_craft = item_location( map_cursor( tripoint_bub_ms( adj ) ), &itm );
if( !is_anyone_crafting( to_craft, this ) ) {
craft_item_list.push_back( to_craft );
}
Expand Down
5 changes: 5 additions & 0 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ void Creature::setpos( const tripoint &p )
on_move( old_loc );
}

void Creature::setpos( const tripoint_bub_ms &p )
{
Creature::setpos( p.raw() );
}

static units::volume size_to_volume( creature_size size_class )
{
// returns midpoint of size from volume_to_size, minus 1_ml
Expand Down
3 changes: 3 additions & 0 deletions src/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ class Creature : public viewer
inline int posz() const {
return get_location().z();
}
// TODO: Get rid of untyped overload
void setpos( const tripoint &p );
void setpos( const tripoint_bub_ms &p );

/** Checks if the creature fits into a given tile. Set the boolean argument to true if the creature would barely fit. */
bool can_move_to_vehicle_tile( const tripoint_abs_ms &loc, bool &cramped ) const;
/** Helper overload for when the boolean is discardable */
Expand Down
4 changes: 2 additions & 2 deletions src/faction_camp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2171,7 +2171,7 @@ void basecamp::abandon_camp()
const tripoint ms_pos = sm_to_ms_copy( sm_pos );
// We cannot use bb_pos here, because bb_pos may be {0,0,0} if you haven't examined the bulletin board on camp ever.
// here.remove_submap_camp( here.getlocal( bb_pos ) );
here.remove_submap_camp( here.getlocal( ms_pos ) );
here.remove_submap_camp( here.bub_from_abs( ms_pos ) );
add_msg( m_info, _( "You abandon %s." ), name );
}

Expand Down Expand Up @@ -5960,7 +5960,7 @@ int basecamp::camp_morale( int change ) const
void basecamp::place_results( const item &result )
{
map &target_bay = get_camp_map();
form_storage_zones( target_bay, target_bay.getglobal( target_bay.getlocal( bb_pos ) ) );
form_storage_zones( target_bay, bb_pos );
tripoint new_spot = target_bay.getlocal( get_dumping_spot() );
// Special handling for liquids
// find any storage-zoned LIQUIDCONT we can dump them in, set that as the item's destination instead
Expand Down
12 changes: 6 additions & 6 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ vehicle *game::place_vehicle_nearby(
vehicle *veh = target_map.add_vehicle( id, tinymap_center, random_entry( angles ),
rng( 50, 80 ), 0, false );
if( veh ) {
tripoint abs_local = m.getlocal( target_map.getabs( tinymap_center ) );
tripoint abs_local = m.bub_from_abs( target_map.getabs( tinymap_center ) ).raw();
veh->sm_pos = ms_to_sm_remain( abs_local );
veh->pos = abs_local.xy();

Expand Down Expand Up @@ -9953,7 +9953,7 @@ void game::butcher()
case MULTIBUTCHER:
butcher_submenu( corpses );
for( map_stack::iterator &it : corpses ) {
u.activity.targets.emplace_back( map_cursor( u.pos() ), &*it );
u.activity.targets.emplace_back( map_cursor( u.pos_bub() ), &*it );
}
break;
case MULTIDISASSEMBLE_ONE:
Expand All @@ -9969,13 +9969,13 @@ void game::butcher()
break;
case BUTCHER_CORPSE: {
butcher_submenu( corpses, indexer_index );
u.activity.targets.emplace_back( map_cursor( u.pos() ), &*corpses[indexer_index] );
u.activity.targets.emplace_back( map_cursor( u.pos_bub() ), &*corpses[indexer_index] );
}
break;
case BUTCHER_DISASSEMBLE: {
// Pick index of first item in the disassembly stack
item *const target = &*disassembly_stacks[indexer_index].first;
u.disassemble( item_location( map_cursor( u.pos() ), target ), true );
u.disassemble( item_location( map_cursor( u.pos_bub() ), target ), true );
}
break;
case BUTCHER_SALVAGE: {
Expand All @@ -9984,7 +9984,7 @@ void game::butcher()
} else {
// Pick index of first item in the salvage stack
item *const target = &*salvage_stacks[indexer_index].first;
item_location item_loc( map_cursor( u.pos() ), target );
item_location item_loc( map_cursor( u.pos_bub() ), target );
salvage_iuse->try_to_cut_up( u, *salvage_tool, item_loc );
}
}
Expand Down Expand Up @@ -11179,7 +11179,7 @@ point game::place_player( const tripoint &dest_loc, bool quick )
if( !corpses.empty() ) {
u.assign_activity( ACT_BUTCHER, 0, true );
for( item *it : corpses ) {
u.activity.targets.emplace_back( map_cursor( u.pos() ), it );
u.activity.targets.emplace_back( map_cursor( u.pos_bub() ), it );
}
}
} else if( pulp_butcher == "pulp" || pulp_butcher == "pulp_adjacent" ||
Expand Down
Loading

0 comments on commit 4c6b918

Please sign in to comment.