Skip to content

Commit

Permalink
typified a bit of map.h/cpp + dependents (#76712)
Browse files Browse the repository at this point in the history
* typified a bit of map.h/cpp + dependents

* demanded changes

* demanded master changes drawn to its conclusion

* second int should be in corresponding location
  • Loading branch information
PatrikLundell authored Oct 3, 2024
1 parent cdba3a4 commit c5c0114
Show file tree
Hide file tree
Showing 82 changed files with 524 additions and 527 deletions.
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,7 @@ void activity_handlers::operation_do_turn( player_activity *act, Character *you
const bionic_id bid( act->str_values[cbm_id] );
const bool autodoc = act->str_values[is_autodoc] == "true";
Character &player_character = get_player_character();
const bool u_see = player_character.sees( you->pos() ) &&
const bool u_see = player_character.sees( you->pos_bub() ) &&
( !player_character.has_effect( effect_narcosis ) ||
player_character.has_bionic( bio_painkiller ) ||
player_character.has_flag( json_flag_PAIN_IMMUNE ) );
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 @@ -587,12 +587,12 @@ static bool vehicle_activity( Character &you, const tripoint_bub_ms &src_loc, in
// for someone else who stored that position at the start of their activity.
// so we may need to go looking a bit further afield to find it , at activities end.
for( const tripoint &pt : veh->get_points( true ) ) {
you.activity.coord_set.insert( here.getabs( pt ) );
you.activity.coord_set.insert( here.getglobal( pt ).raw() );
}
// values[0]
you.activity.values.push_back( here.getabs( src_loc ).x );
you.activity.values.push_back( here.getglobal( src_loc ).x() );
// values[1]
you.activity.values.push_back( here.getabs( src_loc ).y );
you.activity.values.push_back( here.getglobal( src_loc ).y() );
// values[2]
you.activity.values.push_back( point_zero.x );
// values[3]
Expand Down Expand Up @@ -2970,8 +2970,8 @@ static requirement_check_result generic_multi_activity_check_requirement(
return requirement_check_result::SKIP_LOCATION_NO_LOCATION;
}
act_prev.coords.push_back(
here.getabs(
candidates[std::max( 0, static_cast<int>( candidates.size() / 2 ) )] )
here.getglobal(
candidates[std::max( 0, static_cast<int>( candidates.size() / 2 ) )] ).raw()
);
}
act_prev.placement = src;
Expand Down
4 changes: 2 additions & 2 deletions src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,11 +686,11 @@ void avatar_action::swim( map &m, avatar &you, const tripoint &p )
return;
}
}
tripoint old_abs_pos = m.getabs( you.pos_bub() );
tripoint_abs_ms old_abs_pos = m.getglobal( you.pos_bub() );
you.setpos( p );
g->update_map( you );

cata_event_dispatch::avatar_moves( old_abs_pos, you, m );
cata_event_dispatch::avatar_moves( old_abs_pos.raw(), you, m );

if( m.veh_at( you.pos_bub() ).part_with_feature( VPFLAG_BOARDABLE, true ) ) {
m.board_vehicle( you.pos_bub(), &you );
Expand Down
2 changes: 1 addition & 1 deletion src/bionics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ bool Character::deactivate_bionic( bionic &bio, bool eff_only )
if( bio.get_uid() == get_weapon_bionic_uid() ) {
bio.set_weapon( *get_wielded_item() );
add_msg_if_player( _( "You withdraw your %s." ), weapon.tname() );
if( get_player_view().sees( pos() ) ) {
if( get_player_view().sees( pos_bub() ) ) {
if( male ) {
add_msg_if_npc( m_info, _( "<npcname> withdraws his %s." ), weapon.tname() );
} else {
Expand Down
32 changes: 16 additions & 16 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,10 +1454,10 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
}
for( int zlevel = center.z; zlevel >= draw_min_z; zlevel -- ) {
// todo: conversion slightly simplified, a couple of calls already use pos as tripoint_bub_ms
const tripoint pos( temp.value(), zlevel );
const tripoint_bub_ms pos( point_bub_ms( temp.value() ), zlevel );
const tripoint_abs_ms pos_global = here.getglobal( pos );
const int &x = pos.x;
const int &y = pos.y;
const int &x = pos.x();
const int &y = pos.y();
const bool is_center_z = zlevel == center.z;
const level_cache &ch2 = here.access_cache( zlevel );

Expand All @@ -1471,12 +1471,12 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
if( has_memory_at( pos_global ) ) {
ll = lit_level::MEMORIZED;
invisible[0] = true;
} else if( has_draw_override( pos ) ) {
} else if( has_draw_override( pos.raw() ) ) {
ll = lit_level::DARK;
invisible[0] = true;
} else {
if( would_apply_vision_effects( offscreen_type ) ) {
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 },
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0},
tile_render_info::vision_effect{ offscreen_type } );
}
break;
Expand All @@ -1500,7 +1500,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
// Add scent type to the overlay_strings list for every visible tile when
// displaying scent
if( g->display_overlay_state( ACTION_DISPLAY_SCENT_TYPE ) && !invisible[0] ) {
const scenttype_id scent_type = get_scent().get_type( pos );
const scenttype_id scent_type = get_scent().get_type( pos.raw() );
if( !scent_type.is_empty() ) {
here.overlay_strings_cache.emplace( player_to_screen( point( x, y ) ) + half_tile,
formatted_text( scent_type.c_str(),
Expand Down Expand Up @@ -1546,7 +1546,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
// Add temperature value to the overlay_strings list for every visible tile when
// displaying temperature
if( g->display_overlay_state( ACTION_DISPLAY_TEMPERATURE ) && !invisible[0] ) {
const units::temperature temp_value = get_weather().get_temperature( pos );
const units::temperature temp_value = get_weather().get_temperature( pos.raw() );
const float celsius_temp_value = units::to_celsius( temp_value );
short color;
const short bold = 8;
Expand Down Expand Up @@ -1639,28 +1639,28 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
const visibility_type vis_type = here.get_visibility( ll, cache );
if( would_apply_vision_effects( vis_type ) ) {
const Creature *critter = creatures.creature_at( pos, true );
if( has_draw_override( pos ) || has_memory_at( pos_global ) ||
if( has_draw_override( pos.raw() ) || has_memory_at( pos_global ) ||
( critter &&
( critter->has_flag( mon_flag_ALWAYS_VISIBLE )
|| you.sees_with_infrared( *critter )
|| you.sees_with_specials( *critter ) ) ) ) {
invisible[0] = true;
} else {
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 },
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0},
tile_render_info::vision_effect{ vis_type } );
break;
}
}
}
for( int i = 0; i < 4; i++ ) {
const tripoint np = pos + neighborhood[i];
invisible[1 + i] = apply_visible( np, ch2, here );
const tripoint_bub_ms np = pos + neighborhood[i];
invisible[1 + i] = apply_visible( np.raw(), ch2, here );
}

here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0 },
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0},
tile_render_info::sprite{ ll, invisible } );
// Stop building draw points below when floor reached
if( here.dont_draw_lower_floor( pos ) ) {
if( here.dont_draw_lower_floor( pos.raw() ) ) {
break;
}
}
Expand Down Expand Up @@ -2789,7 +2789,7 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
case TILE_CATEGORY::FIELD:
case TILE_CATEGORY::LIGHTING:
// stationary map tiles, seed based on map coordinates
seed = simple_point_hash( here.getabs( pos ) );
seed = simple_point_hash( here.getglobal( pos ).raw() );
break;
case TILE_CATEGORY::VEHICLE_PART:
// vehicle parts, seed based on coordinates within the vehicle
Expand Down Expand Up @@ -2821,7 +2821,7 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
if( fid.is_valid() ) {
const furn_t &f = fid.obj();
if( !f.is_movable() ) {
seed = simple_point_hash( here.getabs( pos ) );
seed = simple_point_hash( here.getglobal( pos ).raw() );
}
}
}
Expand All @@ -2837,7 +2837,7 @@ bool cata_tiles::draw_from_id_string_internal( const std::string &id, TILE_CATEG
if( found_id == "graffiti" ) {
seed = std::hash<std::string> {}( here.graffiti_at( pos ) );
} else if( string_starts_with( found_id, "graffiti" ) ) {
seed = simple_point_hash( here.getabs( pos ) );
seed = simple_point_hash( here.getglobal( pos ).raw() );
}
break;
case TILE_CATEGORY::ITEM:
Expand Down
27 changes: 13 additions & 14 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8135,7 +8135,7 @@ dealt_damage_instance Character::deal_damage( Creature *source, bodypart_id bp,
int dam = dealt_dams.total_damage();

// TODO: Pre or post blit hit tile onto "this"'s location here
if( dam > 0 && get_player_view().sees( pos() ) ) {
if( dam > 0 && get_player_view().sees( pos_bub() ) ) {
g->draw_hit_player( *this, dam );

if( is_avatar() && source ) {
Expand Down Expand Up @@ -10569,8 +10569,7 @@ void Character::echo_pulse()

bool Character::knows_trap( const tripoint &pos ) const
{
const tripoint p = get_map().getabs( pos );
return known_traps.count( p ) > 0;
return Character::knows_trap( tripoint_bub_ms( pos ) );
}

bool Character::knows_trap( const tripoint_bub_ms &pos ) const
Expand All @@ -10581,12 +10580,12 @@ bool Character::knows_trap( const tripoint_bub_ms &pos ) const

void Character::add_known_trap( const tripoint &pos, const trap &t )
{
const tripoint p = get_map().getabs( pos );
const tripoint_abs_ms p = get_map().getglobal( pos );
if( t.is_null() ) {
known_traps.erase( p );
known_traps.erase( p.raw() );
} else {
// TODO: known_traps should map to a trap_str_id
known_traps[p] = t.id.str();
known_traps[p.raw()] = t.id.str();
}
}

Expand Down Expand Up @@ -11247,8 +11246,13 @@ npc_attitude Character::get_attitude() const

bool Character::sees( const tripoint &t, bool, int ) const
{
const int wanted_range = rl_dist( pos(), t );
bool can_see = is_avatar() ? get_map().pl_sees( t, std::min( sight_max, wanted_range ) ) :
return sees( tripoint_bub_ms( t ) );
}

bool Character::sees( const tripoint_bub_ms &t, bool, int ) const
{
const int wanted_range = rl_dist( pos_bub(), t );
bool can_see = this->is_avatar() ? get_map().pl_sees( t, std::min( sight_max, wanted_range ) ) :
Creature::sees( t );
// Clairvoyance is now pretty cheap, so we can check it early
if( wanted_range < MAX_CLAIRVOYANCE && wanted_range < clairvoyance() ) {
Expand All @@ -11258,11 +11262,6 @@ bool Character::sees( const tripoint &t, bool, int ) const
return can_see;
}

bool Character::sees( const tripoint_bub_ms &t, bool is_avatar, int range_mod ) const
{
return sees( t.raw(), is_avatar, range_mod );
}

bool Character::sees( const Creature &critter ) const
{
// This handles only the player/npc specific stuff (monsters don't have traits or bionics).
Expand All @@ -11289,7 +11288,7 @@ void Character::set_destination( const std::vector<tripoint_bub_ms> &route,
{
auto_move_route = route;
set_destination_activity( new_destination_activity );
destination_point.emplace( get_map().getabs( route.back() ) );
destination_point.emplace( get_map().getglobal( route.back() ).raw() );
}

void Character::clear_destination()
Expand Down
4 changes: 2 additions & 2 deletions src/computer_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ static void remove_submap_turrets()
map &here = get_map();
for( monster &critter : g->all_monsters() ) {
// Check 1) same overmap coords, 2) turret, 3) hostile
if( ms_to_omt_copy( here.getabs( critter.pos() ) ) == ms_to_omt_copy( here.getabs(
player_character.pos() ) ) &&
if( ms_to_omt_copy( here.getglobal( critter.pos_bub() ).raw() ) == ms_to_omt_copy( here.getglobal(
player_character.pos_bub() ).raw() ) &&
critter.has_flag( mon_flag_CONSOLE_DESPAWN ) &&
critter.attitude_to( player_character ) == Creature::Attitude::HOSTILE ) {
g->remove_zombie( critter );
Expand Down
3 changes: 1 addition & 2 deletions src/construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,8 +1696,7 @@ void construct::done_vehicle( const tripoint_bub_ms &p, Character & )
return;
}

// TODO: fix point types
vehicle *veh = here.add_vehicle( vehicle_prototype_none, p.raw(), 270_degrees, 0, 0 );
vehicle *veh = here.add_vehicle( vehicle_prototype_none, p, 270_degrees, 0, 0 );

if( !veh ) {
debugmsg( "constructing failed: add_vehicle returned null" );
Expand Down
2 changes: 1 addition & 1 deletion src/consumption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ static bool query_consume_ownership( item &target, Character &p )
}
std::vector<npc *> witnesses;
for( npc &elem : g->all_npcs() ) {
if( rl_dist( elem.pos(), p.pos() ) < MAX_VIEW_DISTANCE && elem.sees( p.pos() ) ) {
if( rl_dist( elem.pos(), p.pos() ) < MAX_VIEW_DISTANCE && elem.sees( p.pos_bub() ) ) {
witnesses.push_back( &elem );
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/coordinates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ tripoint_rel_ms rebase_rel( tripoint_bub_ms p )
{
return tripoint_rel_ms( p.raw() );
}
tripoint_rel_sm rebase_rel( tripoint_bub_sm p )
{
return tripoint_rel_sm( p.raw() );
}
tripoint_sm_ms rebase_sm( tripoint_rel_ms p )
{
return tripoint_sm_ms( p.raw() );
Expand All @@ -82,6 +86,10 @@ tripoint_bub_ms rebase_bub( tripoint_rel_ms p )
{
return tripoint_bub_ms( p.raw() );
}
tripoint_bub_sm rebase_bub( tripoint_rel_sm p )
{
return tripoint_bub_sm( p.raw() );
}
point_bub_ms rebase_bub( point_omt_ms p )
{
return point_bub_ms( p.raw() );
Expand Down
2 changes: 2 additions & 0 deletions src/coordinates.h
Original file line number Diff line number Diff line change
Expand Up @@ -768,9 +768,11 @@ point_bub_ms rebase_bub( point_rel_ms p );
tripoint_rel_ms rebase_rel( tripoint_sm_ms p );
tripoint_rel_ms rebase_rel( tripoint_omt_ms p );
tripoint_rel_ms rebase_rel( tripoint_bub_ms p );
tripoint_rel_sm rebase_rel( tripoint_bub_sm p );
tripoint_sm_ms rebase_sm( tripoint_rel_ms p );
tripoint_omt_ms rebase_omt( tripoint_rel_ms p );
tripoint_bub_ms rebase_bub( tripoint_rel_ms p );
tripoint_bub_sm rebase_bub( tripoint_rel_sm p );

// 'Glue' rebase operations for when a tinymap is using the underlying map operation and when a tinymap
// has to be cast to a map to access common functionality. Note that this doesn't actually change anything
Expand Down
5 changes: 3 additions & 2 deletions src/crafting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2662,8 +2662,9 @@ bool Character::disassemble( item_location target, bool interactive, bool disass
if( obj.get_owner() ) {
std::vector<npc *> witnesses;
for( npc &elem : g->all_npcs() ) {
if( rl_dist( elem.pos(), player_character.pos() ) < MAX_VIEW_DISTANCE && elem.get_faction() &&
obj.is_owned_by( elem ) && elem.sees( player_character.pos() ) ) {
if( rl_dist( elem.pos_bub(), player_character.pos_bub() ) < MAX_VIEW_DISTANCE &&
elem.get_faction() &&
obj.is_owned_by( elem ) && elem.sees( player_character.pos_bub() ) ) {
elem.say( "<witnessed_thievery>", 7 );
npc *npc_to_add = &elem;
witnesses.push_back( npc_to_add );
Expand Down
6 changes: 3 additions & 3 deletions src/creature_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void creature_tracker::flood_fill_zone( const Creature &origin )
ff::flood_fill_visit_10_connected( origin.pos_bub(),
[&map]( const tripoint_bub_ms & loc, int direction ) {
if( direction == 0 ) {
return map.inbounds( loc ) && ( map.is_transparent_wo_fields( loc.raw() ) ||
return map.inbounds( loc ) && ( map.is_transparent_wo_fields( loc ) ||
map.passable( loc ) );
}
if( direction == 1 ) {
Expand All @@ -378,7 +378,7 @@ void creature_tracker::flood_fill_zone( const Creature &origin )
return false;
}
if( ( ( up_ter.movecost != 0 && up.get_furn_t().movecost >= 0 ) ||
map.is_transparent_wo_fields( loc.raw() ) ) &&
map.is_transparent_wo_fields( loc ) ) &&
( up_ter.has_flag( ter_furn_flag::TFLAG_NO_FLOOR ) ||
up_ter.has_flag( ter_furn_flag::TFLAG_GOES_DOWN ) ) ) {
return true;
Expand All @@ -396,7 +396,7 @@ void creature_tracker::flood_fill_zone( const Creature &origin )
return false;
}
if( ( ( down_ter.movecost != 0 && down.get_furn_t().movecost >= 0 ) ||
map.is_transparent_wo_fields( loc.raw() ) ) &&
map.is_transparent_wo_fields( loc ) ) &&
( up_ter.has_flag( ter_furn_flag::TFLAG_NO_FLOOR ) ||
up_ter.has_flag( ter_furn_flag::TFLAG_GOES_DOWN ) ) ) {
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/debug_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ static void spawn_nested_mapgen()
}

map &here = get_map();
const tripoint_abs_ms abs_ms( here.getabs( *where ) );
const tripoint_abs_ms abs_ms( here.getglobal( *where ) );
const tripoint_abs_omt abs_omt = project_to<coords::omt>( abs_ms );
const tripoint_abs_sm abs_sub = project_to<coords::sm>( abs_ms );

Expand Down Expand Up @@ -3050,7 +3050,7 @@ static void debug_menu_spawn_vehicle()
if( veh_menu.ret >= 0 && veh_menu.ret < static_cast<int>( veh_strings.size() ) ) {
// Didn't cancel
const vproto_id &selected_opt = veh_strings[veh_menu.ret].second;
tripoint dest = player_character.pos();
tripoint_bub_ms dest = player_character.pos_bub();
uilist veh_cond_menu;
veh_cond_menu.text = _( "Vehicle condition" );
veh_cond_menu.addentry( 3, true, MENU_AUTOASSIGN, _( "Undamaged" ) );
Expand Down
4 changes: 2 additions & 2 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2117,13 +2117,13 @@ void editmap::edit_mapgen()
map &here = get_map();

do {
tc.fromabs( here.getabs( target.xy() ) );
tc.fromabs( here.getglobal( { target.xy(), here.abs_sub.z() } ).xy().raw() );
point_bub_ms omt_lpos = here.bub_from_abs( point_abs_ms( tc.begin_om_pos() ) );
tripoint_bub_ms om_ltarget = omt_lpos + tripoint( -1 + SEEX, -1 + SEEY, target.z() );

if( target.x() != om_ltarget.x() || target.y() != om_ltarget.y() ) {
target = om_ltarget;
tc.fromabs( here.getabs( target.xy() ) );
tc.fromabs( here.getglobal( { target.xy(), here.abs_sub.z() } ).xy().raw() );
}
target_list.clear();
for( int x = target.x() - SEEX + 1; x < target.x() + SEEX + 1; x++ ) {
Expand Down
Loading

0 comments on commit c5c0114

Please sign in to comment.