Skip to content

Commit

Permalink
Merge pull request CleverRaven#76992 from PatrikLundell/typify
Browse files Browse the repository at this point in the history
typified a bit of map.cpp + dependents
  • Loading branch information
Maleclypse authored Oct 24, 2024
2 parents 470fb53 + 5648f80 commit ccbb166
Show file tree
Hide file tree
Showing 43 changed files with 251 additions and 439 deletions.
15 changes: 8 additions & 7 deletions src/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,11 +1284,11 @@ std::optional<tripoint> choose_adjacent_highlight( const tripoint &pos, const st
const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed,
bool allow_vertical, bool allow_autoselect )
{
std::vector<tripoint> valid;
std::vector<tripoint_bub_ms> valid;
map &here = get_map();
if( allowed ) {
for( const tripoint &pos : here.points_in_radius( pos, 1 ) ) {
if( allowed( pos ) ) {
for( const tripoint_bub_ms &pos : here.points_in_radius( tripoint_bub_ms( pos ), 1 ) ) {
if( allowed( pos.raw() ) ) {
valid.emplace_back( pos );
}
}
Expand All @@ -1299,22 +1299,23 @@ std::optional<tripoint> choose_adjacent_highlight( const tripoint &pos, const st
add_msg( failure_message );
return std::nullopt;
} else if( valid.size() == 1 && auto_select ) {
return valid.back();
return valid.back().raw();
}

shared_ptr_fast<game::draw_callback_t> hilite_cb;
if( !valid.empty() ) {
hilite_cb = make_shared_fast<game::draw_callback_t>( [&]() {
for( const tripoint &pos : valid ) {
for( const tripoint_bub_ms &pos : valid ) {
here.drawsq( g->w_terrain, pos, drawsq_params().highlight( true ) );
}
} );
g->add_draw_callback( hilite_cb );
}

const std::optional<tripoint> chosen = choose_adjacent( pos, message, allow_vertical );
const std::optional<tripoint_bub_ms> chosen = choose_adjacent( tripoint_bub_ms( pos ), message,
allow_vertical );
if( std::find( valid.begin(), valid.end(), chosen ) != valid.end() ) {
return chosen;
return std::optional<tripoint>( chosen.value().raw() );
}

return std::nullopt;
Expand Down
2 changes: 1 addition & 1 deletion src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8069,7 +8069,7 @@ void pulp_activity_actor::do_turn( player_activity &act, Character &you )
const field_type_id type_blood = ( mess_radius > 1 && x_in_y( pulp_power, 10000 ) ) ?
corpse.get_mtype()->gibType() :
corpse.get_mtype()->bloodType();
here.add_splatter_trail( type_blood, pos.raw(), dest.raw() );
here.add_splatter_trail( type_blood, pos, dest );
}

// mixture of isaac clarke stomps and swinging your weapon
Expand Down
4 changes: 2 additions & 2 deletions src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2710,7 +2710,7 @@ static requirement_check_result generic_multi_activity_check_requirement(
const std::unordered_set<tripoint_abs_ms> &src_set, const bool check_only = false )
{
map &here = get_map();
const tripoint_abs_ms abspos = here.getglobal( you.pos() );
const tripoint_abs_ms abspos = here.getglobal( you.pos_bub() );
zone_manager &mgr = zone_manager::get_manager();

bool &can_do_it = act_info.can_do;
Expand Down Expand Up @@ -3185,7 +3185,7 @@ struct failure_reasons {
bool generic_multi_activity_handler( player_activity &act, Character &you, bool check_only )
{
map &here = get_map();
const tripoint_abs_ms abspos = here.getglobal( you.pos() );
const tripoint_abs_ms abspos = here.getglobal( you.pos_bub() );
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
activity_id activity_to_restore = act.id();
// Nuke the current activity, leaving the backlog alone
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ bool avatar::should_show_map_memory() const

bool avatar::save_map_memory()
{
return player_map_memory->save( get_map().getglobal( pos() ) );
return player_map_memory->save( get_map().getglobal( pos_bub() ) );
}

void avatar::load_map_memory()
{
player_map_memory->load( get_map().getglobal( pos() ) );
player_map_memory->load( get_map().getglobal( pos_bub() ) );
}

void avatar::prepare_map_memory_region( const tripoint_abs_ms &p1, const tripoint_abs_ms &p2 )
Expand Down
2 changes: 1 addition & 1 deletion src/ballistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ dealt_projectile_attack projectile_attack( const projectile &proj_arg,
const size_t bt_len = blood_trail_len( attack.dealt_dam.total_damage() );
if( bt_len > 0 ) {
const tripoint_bub_ms &dest = move_along_line( tp, trajectory, bt_len );
here.add_splatter_trail( blood_type, tp.raw(), dest.raw() );
here.add_splatter_trail( blood_type, tp, dest );
}
}
sfx::do_projectile_hit( *attack.hit_critter );
Expand Down
24 changes: 12 additions & 12 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,8 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
here.prev_o = o;

you.prepare_map_memory_region(
here.getglobal( tripoint( min_mm_reg, center.z ) ),
here.getglobal( tripoint( max_mm_reg, center.z ) )
here.getglobal( tripoint_bub_ms( min_mm_reg.x, min_mm_reg.y, center.z ) ),
here.getglobal( tripoint_bub_ms( max_mm_reg.x, max_mm_reg.y, center.z ) )
);

//set up a default tile for the edges outside the render area
Expand Down Expand Up @@ -1819,8 +1819,8 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
if( is_isometric() && top_any_tile_range.contains( colrow ) ) {
continue;
}
const tripoint p( mem_x, mem_y, center.z );
lit_level lighting = ch.visibility_cache[p.x][p.y];
const tripoint_bub_ms p( mem_x, mem_y, center.z );
lit_level lighting = ch.visibility_cache[p.x()][p.y()];
// `apply_vision_effects` does not memorize anything so we only need
// to call `would_apply_vision_effects` here.
if( would_apply_vision_effects( here.get_visibility( lighting, cache ) ) ) {
Expand All @@ -1830,19 +1830,19 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
std::array<bool, 5> invisible;
invisible[0] = false;
for( int i = 0; i < 4; i++ ) {
const tripoint np = p + neighborhood[i];
invisible[1 + i] = apply_visible( np, ch, here );
const tripoint_bub_ms np = p + neighborhood[i];
invisible[1 + i] = apply_visible( np.raw(), ch, here );
}
//calling draw to memorize (and only memorize) everything.
//bypass cache check in case we learn something new about the terrain's connections
draw_terrain( p, lighting, height_3d, invisible, true );
draw_terrain( p.raw(), lighting, height_3d, invisible, true );
if( here.memory_cache_dec_is_dirty( p ) ) {
you.memorize_clear_decoration( here.getglobal( p ), "" );
draw_furniture( p, lighting, height_3d, invisible, true );
draw_trap( p, lighting, height_3d, invisible, true );
draw_part_con( p, lighting, height_3d, invisible, true );
draw_vpart_no_roof( p, lighting, height_3d, invisible, true );
draw_vpart_roof( p, lighting, height_3d, invisible, true );
draw_furniture( p.raw(), lighting, height_3d, invisible, true );
draw_trap( p.raw(), lighting, height_3d, invisible, true );
draw_part_con( p.raw(), lighting, height_3d, invisible, true );
draw_vpart_no_roof( p.raw(), lighting, height_3d, invisible, true );
draw_vpart_roof( p.raw(), lighting, height_3d, invisible, true );
here.memory_cache_dec_set_dirty( p, false );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8543,7 +8543,7 @@ void Character::rooted()
// TODO: The rates for iron, calcium, and thirst should probably be pulled from the nutritional data rather than being hardcoded here, so that future balance changes don't break this.
{
if( ( has_trait( trait_ROOTS2 ) || has_trait( trait_ROOTS3 ) || has_trait( trait_CHLOROMORPH ) ) &&
get_map().has_flag( ter_furn_flag::TFLAG_PLOWABLE, pos() ) && is_barefoot() ) {
get_map().has_flag( ter_furn_flag::TFLAG_PLOWABLE, pos_bub() ) && is_barefoot() ) {
int time_to_full = 43200; // 12 hours
if( has_trait( trait_ROOTS3 ) || has_trait( trait_CHLOROMORPH ) ) {
time_to_full += -14400; // -4 hours
Expand Down Expand Up @@ -11037,7 +11037,7 @@ void Character::process_effects()
}

// Being stuck in tight spaces sucks. TODO: could be expanded to apply to non-vehicle conditions.
if( will_be_cramped_in_vehicle_tile( get_map().getglobal( pos() ) ) ) {
if( will_be_cramped_in_vehicle_tile( get_map().getglobal( pos_bub() ) ) ) {
if( is_npc() && !has_effect( effect_narcosis ) ) {
npc &as_npc = dynamic_cast<npc &>( *this );
as_npc.complain_about( "cramped_vehicle", 30_minutes, "<cramped_vehicle>", false );
Expand Down
2 changes: 1 addition & 1 deletion src/clzones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ plot_options::query_seed_result plot_options::query_seed()
zone_manager &mgr = zone_manager::get_manager();
map &here = get_map();
const std::unordered_set<tripoint_abs_ms> zone_src_set =
mgr.get_near( zone_type_LOOT_SEEDS, here.getglobal( player_character.pos() ), 60 );
mgr.get_near( zone_type_LOOT_SEEDS, here.getglobal( player_character.pos_bub() ), 60 );
for( const tripoint_abs_ms &elem : zone_src_set ) {
tripoint_bub_ms elem_loc = here.bub_from_abs( elem );
for( item &it : here.i_at( elem_loc ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ void editmap::draw_main_ui_overlay()
hilights["mapgentgt"].draw( *this, true );
drawsq_params params = drawsq_params().center( tripoint_bub_ms( SEEX - 1, SEEY - 1, target.z() ) );
for( const tripoint_omt_ms &p : tmpmap.points_on_zlevel() ) {
tmpmap.drawsq( g->w_terrain, p.raw(), params );
tmpmap.drawsq( g->w_terrain, rebase_bub( p ), params );
}
tmpmap.rebuild_vehicle_level_caches();
#ifdef TILES
Expand Down
7 changes: 4 additions & 3 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6970,13 +6970,13 @@ void game::zones_manager()
}
tripoint_abs_ms first_abs =
m.getglobal(
tripoint(
tripoint_bub_ms(
std::min( first.position->x, second.position->x ),
std::min( first.position->y, second.position->y ),
std::min( first.position->z, second.position->z ) ) );
tripoint_abs_ms second_abs =
m.getglobal(
tripoint(
tripoint_bub_ms(
std::max( first.position->x, second.position->x ),
std::max( first.position->y, second.position->y ),
std::max( first.position->z, second.position->z ) ) );
Expand Down Expand Up @@ -10641,7 +10641,8 @@ bool game::walk_move( const tripoint &dest_loc, const bool via_ramp, const bool
modifier = -m.furn( dest_loc ).obj().movecost;
}

const int mcost = m.combined_movecost( u.pos(), dest_loc, grabbed_vehicle, modifier,
const int mcost = m.combined_movecost( u.pos_bub(), tripoint_bub_ms( dest_loc ), grabbed_vehicle,
modifier,
via_ramp );

if( !furniture_move && grabbed_move( dest_loc - u.pos(), via_ramp ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/game_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ class comestible_inventory_preset : public inventory_selector_preset
if(
( loc->made_of_from_type( phase_id::LIQUID ) &&
loc.where() != item_location::type::container ) &&
!get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, loc.position() ) ) {
!get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, loc.pos_bub() ) ) {
return _( "Can't drink spilt liquids." );
}
if(
Expand Down
6 changes: 3 additions & 3 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13607,7 +13607,7 @@ ret_val<void> item::link_to( vehicle &veh, const point &mount, link_state link_t
link().source = bio_link ? link_state::bio_cable : link_state::no_link;
link().target = link_type;
link().t_veh = veh.get_safe_reference();
link().t_abs_pos = get_map().getglobal( link().t_veh->global_pos3() );
link().t_abs_pos = get_map().getglobal( link().t_veh->pos_bub() );
link().t_mount = mount;
link().s_bub_pos = tripoint_min; // Forces the item to check the length during process_link.

Expand Down Expand Up @@ -13911,7 +13911,7 @@ bool item::process_link( map &here, Character *carrier, const tripoint &pos )
link().last_processed = calendar::turn;

// Set the new absolute position to the vehicle's origin.
tripoint t_veh_bub_pos = t_veh->global_pos3();
tripoint_bub_ms t_veh_bub_pos = t_veh->pos_bub();
tripoint_abs_ms new_t_abs_pos = here.getglobal( t_veh_bub_pos );
if( link().t_abs_pos != new_t_abs_pos ) {
link().t_abs_pos = new_t_abs_pos;
Expand All @@ -13920,7 +13920,7 @@ bool item::process_link( map &here, Character *carrier, const tripoint &pos )

// If either of the link's connected sides moved, check the cable's length.
if( length_check_needed ) {
link().length = rl_dist( pos, t_veh_bub_pos + t_veh->part( link_vp_index ).precalc[0] );
link().length = rl_dist( pos, t_veh_bub_pos.raw() + t_veh->part( link_vp_index ).precalc[0] );
if( check_length() ) {
return reset_link( true, carrier, link_vp_index );
}
Expand Down
2 changes: 1 addition & 1 deletion src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class item_location::impl::item_on_map : public item_location::impl

item *obj = target();
int mv = ch.item_handling_cost( *obj, true, MAP_HANDLING_PENALTY, qty );
mv += 100 * rl_dist( ch.pos(), cur.pos().raw() );
mv += 100 * rl_dist( ch.pos_bub(), cur.pos() );

// TODO: handle unpacking costs

Expand Down
10 changes: 5 additions & 5 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2497,7 +2497,7 @@ std::optional<int> iuse::purify_water( Character *p, item *purifier, item_locati
p->add_msg_if_player( m_info, _( "Purifying %i water using %i %s" ), charges_of_water, to_consume,
purifier->tname( to_consume ) );;
// Pull from surrounding map first because it will update to_consume
get_map().use_amount( p->pos(), PICKUP_RANGE, itype_pur_tablets, to_consume );
get_map().use_amount( p->pos_bub(), PICKUP_RANGE, itype_pur_tablets, to_consume );
// Then pull from inventory
if( to_consume > 0 ) {
p->use_amount( itype_pur_tablets, to_consume );
Expand Down Expand Up @@ -2532,7 +2532,7 @@ std::optional<int> iuse::water_tablets( Character *p, item *it, const tripoint &
return ( !e->empty() && e->has_item_with( []( const item & it ) {
return it.typeId() == itype_water;
} ) ) || ( e->typeId() == itype_water &&
get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, e.position() ) );
get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, e.pos_bub() ) );
}, _( "Purify what?" ), 1, _( "You don't have water to purify." ) );

if( !obj ) {
Expand Down Expand Up @@ -2560,7 +2560,7 @@ std::optional<int> iuse::directional_antenna( Character *p, item *, const tripoi
auto radios = p->cache_get_items_with( itype_radio_on );
// If we don't wield the radio, also check on the ground
if( radios.empty() ) {
map_stack items = get_map().i_at( p->pos() );
map_stack items = get_map().i_at( p->pos_bub() );
for( item &an_item : items ) {
if( an_item.typeId() == itype_radio_on ) {
radios.push_back( &an_item );
Expand Down Expand Up @@ -4960,7 +4960,7 @@ static bool heat_item( Character &p )
return itm->has_temperature() && !itm->has_own_flag( flag_HOT ) &&
( !itm->made_of_from_type( phase_id::LIQUID ) ||
itm.where() == item_location::type::container ||
get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, itm.position() ) );
get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, itm.pos_bub() ) );
}, _( "Heat up what?" ), 1, _( "You don't have any appropriate food to heat up." ) );

item *heat = loc.get_item();
Expand Down Expand Up @@ -8345,7 +8345,7 @@ static bool heat_items( Character *p, item *it, bool liquid_items, bool solid_it
return itm->has_temperature() && !itm->has_own_flag( flag_HOT ) &&
( !itm->made_of_from_type( phase_id::LIQUID ) ||
itm.where() == item_location::type::container ||
get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, itm.position() ) );
get_map().has_flag_furn( ter_furn_flag::TFLAG_LIQUIDCONT, itm.pos_bub() ) );
}, _( "Heat up what?" ), 1, _( "You don't have any appropriate food to heat up." ) );
if( !loc ) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,18 +1130,18 @@ void map::seen_cache_process_ledges( array_of_grids_of<float> &seen_caches,
for( int sy = 0; sy < SEEY; ++sy ) {
// Iterate down z-levels starting from 1 level below origin
for( int sz = origin.z() - 1; sz >= min_z; --sz ) {
const tripoint p( sx + smx * SEEX, sy + smy * SEEY, sz );
const tripoint_bub_ms p( sx + smx * SEEX, sy + smy * SEEY, sz );
const int cache_z = sz + OVERMAP_DEPTH;
// Until invisible tile reached
if( ( *seen_caches[cache_z] )[p.x][p.y] == 0.0f ) {
if( ( *seen_caches[cache_z] )[p.x()][p.y()] == 0.0f ) {
break;
}
// Or floor reached
if( ( *floor_caches[cache_z] ) [p.x][p.y] ) {
if( ( *floor_caches[cache_z] ) [p.x()][p.y()] ) {
// In which case check if it should be obscured by a ledge
if( override_p ? ledge_coverage( origin.raw(), p ) > 100 : ledge_coverage( player_character,
if( override_p ? ledge_coverage( origin, p ) > 100 : ledge_coverage( player_character,
p ) > 100 ) {
( *seen_caches[cache_z] )[p.x][p.y] = 0.0f;
( *seen_caches[cache_z] )[p.x()][p.y()] = 0.0f;
}
break;
}
Expand Down
Loading

0 comments on commit ccbb166

Please sign in to comment.