Skip to content

Commit

Permalink
typified map.h and dependents
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrikLundell committed Jan 12, 2025
1 parent 9a3e97c commit f2e3ee4
Show file tree
Hide file tree
Showing 21 changed files with 226 additions and 415 deletions.
2 changes: 1 addition & 1 deletion src/avatar_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint_rel_ms &d )
get_option<bool>( "AUTO_FEATURES" ) && get_option<bool>( "AUTO_MINING" ) &&
!m.veh_at( dest_loc ) && !you.is_underwater() && !you.has_effect( effect_stunned ) &&
!you.has_effect( effect_psi_stunned ) && !is_riding && !you.has_effect( effect_incorporeal ) &&
!m.impassable_field_at( d.raw() ) && !you.has_flag( json_flag_CANNOT_MOVE ) ) {
!m.impassable_field_at( dest_loc ) && !you.has_flag( json_flag_CANNOT_MOVE ) ) {
if( weapon && weapon->has_flag( flag_DIG_TOOL ) ) {
if( weapon->type->can_use( "JACKHAMMER" ) &&
weapon->ammo_sufficient( &you ) ) {
Expand Down
6 changes: 3 additions & 3 deletions src/cata_tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms &center, int wid
invisible[0] = true;
} else {
if( would_apply_vision_effects( offscreen_type ) ) {
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0},
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0},
tile_render_info::vision_effect{ offscreen_type } );
}
break;
Expand Down Expand Up @@ -1690,7 +1690,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms &center, int wid
|| you.sees_with_specials( *critter ) ) ) ) {
invisible[0] = true;
} else {
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0},
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0},
tile_render_info::vision_effect{ vis_type } );
break;
}
Expand All @@ -1701,7 +1701,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms &center, int wid
invisible[1 + i] = apply_visible( np, ch2, here );
}

here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0},
here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0},
tile_render_info::sprite{ ll, invisible } );
// Stop building draw points below when floor reached
if( here.dont_draw_lower_floor( pos ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/creature_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void creature_tracker::remove_dead()
template<typename T>
T *creature_tracker::creature_at( const tripoint &p, bool allow_hallucination )
{
return creature_at<T>( get_map().getglobal( p ), allow_hallucination );
return creature_at<T>( get_map().getglobal( tripoint_bub_ms( p ) ), allow_hallucination );
}

template<typename T>
Expand Down Expand Up @@ -423,7 +423,7 @@ void creature_tracker::flood_fill_zone( const Creature &origin )
template<typename T>
const T *creature_tracker::creature_at( const tripoint &p, bool allow_hallucination ) const
{
return creature_at<T>( get_map().getglobal( p ), allow_hallucination );
return creature_at<T>( get_map().getglobal( tripoint_bub_ms( p ) ), allow_hallucination );
}

template<typename T>
Expand Down
8 changes: 4 additions & 4 deletions src/iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ std::optional<int> iuse::meth( Character *p, item *, const tripoint_bub_ms & )
map &here = get_map();
// breathe out some smoke
for( int i = 0; i < 3; i++ ) {
point offset( rng( -2, 2 ), rng( -2, 2 ) );
point_rel_ms offset( rng( -2, 2 ), rng( -2, 2 ) );
here.add_field( p->pos_bub() + offset, field_type_id( "fd_methsmoke" ), 2 );
}
} else {
Expand Down Expand Up @@ -8229,7 +8229,7 @@ heating_requirements heating_requirements_for_weight( const units::mass &frozen,
return {volume, ammo, time};
}

static std::optional<std::pair<tripoint, itype_id>> appliance_heater_selector( Character *p )
static std::optional<std::pair<tripoint_bub_ms, itype_id>> appliance_heater_selector( Character *p )
{
const std::optional<tripoint_bub_ms> pt = choose_adjacent_highlight( _( "Select an appliance." ),
_( "There is no appliance nearby." ), ACTION_EXAMINE, false );
Expand Down Expand Up @@ -8264,7 +8264,7 @@ static std::optional<std::pair<tripoint, itype_id>> appliance_heater_selector( C
p->add_msg_if_player( m_info, _( "You haven't selected any heater." ) );
return std::nullopt;
} else {
return std::make_pair( pt.value().raw(), pseudo_tools[app_menu.ret] );
return std::make_pair( pt.value(), pseudo_tools[app_menu.ret] );
}

}
Expand Down Expand Up @@ -8322,7 +8322,7 @@ heater find_heater( Character *p, item *it )
1,
_( "You don't have a proper heating tool. Try selecting an appliance with a heater." ) );
if( !loc ) {
std::optional<std::pair<tripoint, itype_id>> app = appliance_heater_selector( p );
std::optional<std::pair<tripoint_bub_ms, itype_id>> app = appliance_heater_selector( p );
if( !app ) {
return {loc, true, -1, 0, vpt, pseudo_flag};
} else {
Expand Down
21 changes: 8 additions & 13 deletions src/lightmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,11 +672,6 @@ void map::add_light_source( const tripoint_bub_ms &p, float luminance )

// Tile light/transparency: 3D

lit_level map::light_at( const tripoint &p ) const
{
return map::light_at( tripoint_bub_ms( p ) );
}

lit_level map::light_at( const tripoint_bub_ms &p ) const
{
if( !inbounds( p ) ) {
Expand Down Expand Up @@ -1432,21 +1427,21 @@ void map::apply_light_arc( const tripoint_bub_ms &p, const units::angle &angle,

void map::apply_light_ray(
cata::mdarray<bool, point_bub_ms, LIGHTMAP_CACHE_X, LIGHTMAP_CACHE_Y> &lit,
const tripoint &s, const tripoint &e, float luminance )
const tripoint_bub_ms &s, const tripoint_bub_ms &e, float luminance )
{
point a( std::abs( e.x - s.x ) * 2, std::abs( e.y - s.y ) * 2 );
point d( ( s.x < e.x ) ? 1 : -1, ( s.y < e.y ) ? 1 : -1 );
point a( std::abs( e.x() - s.x() ) * 2, std::abs( e.y() - s.y() ) * 2 );
point d( ( s.x() < e.x() ) ? 1 : -1, ( s.y() < e.y() ) ? 1 : -1 );
point_bub_ms p( s.xy() );

quadrant quad = quadrant_from_x_y( d.x, d.y );

// TODO: Invert that z comparison when it's sane
if( s.z != e.z || ( s.x == e.x && s.y == e.y ) ) {
if( s.z() != e.z() || ( s.x() == e.x() && s.y() == e.y() ) ) {
return;
}

auto &lm = get_cache( s.z ).lm;
auto &transparency_cache = get_cache( s.z ).transparency_cache;
auto &lm = get_cache( s.z() ).lm;
auto &transparency_cache = get_cache( s.z() ).transparency_cache;

float distance = 1.0f;
float transparency = LIGHT_TRANSPARENCY_OPEN_AIR;
Expand Down Expand Up @@ -1485,7 +1480,7 @@ void map::apply_light_ray(
}

distance += scaling_factor;
} while( !( p.x() == e.x && p.y() == e.y ) );
} while( !( p.x() == e.x() && p.y() == e.y() ) );
} else {
int t = a.x - ( a.y / 2 );
do {
Expand Down Expand Up @@ -1517,6 +1512,6 @@ void map::apply_light_ray(
}

distance += scaling_factor;
} while( !( p.x() == e.x && p.y() == e.y ) );
} while( !( p.x() == e.x() && p.y() == e.y() ) );
}
}
86 changes: 3 additions & 83 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ std::set<tripoint_bub_ms> map::get_moving_vehicle_targets( const Creature &z, in
if( !v.v->is_moving() ) {
continue;
}
if( std::abs( v.pos.z - zpos.z() ) > fov_3d_z_range ) {
if( std::abs( v.pos.z() - zpos.z() ) > fov_3d_z_range ) {
continue;
}
if( rl_dist( zpos, tripoint_bub_ms( v.pos ) ) > max_range + 40 ) {
Expand Down Expand Up @@ -1301,7 +1301,7 @@ VehicleList map::get_vehicles( const tripoint_bub_ms &start, const tripoint_bub_
elem->sm_pos.z = cz;
wrapped_vehicle w;
w.v = elem.get();
w.pos = w.v->pos_bub().raw();
w.pos = w.v->pos_bub();
vehs.push_back( w );
}
}
Expand All @@ -1316,11 +1316,6 @@ optional_vpart_position map::veh_at( const tripoint_abs_ms &p ) const
return veh_at( bub_from_abs( p ) );
}

optional_vpart_position map::veh_at( const tripoint &p ) const
{
return veh_at( tripoint_bub_ms( p ) );
}

optional_vpart_position map::veh_at( const tripoint_bub_ms &p ) const
{
if( !inbounds( p ) || !const_cast<map *>( this )->get_cache( p.z() ).get_veh_in_active_range() ) {
Expand Down Expand Up @@ -1707,11 +1702,6 @@ bool map::has_furn( const tripoint_bub_ms &p ) const
return furn( p ) != furn_str_id::NULL_ID();
}

furn_id map::furn( const tripoint &p ) const
{
return furn( tripoint_bub_ms( p ) );
}

furn_id map::furn( const tripoint_bub_ms p ) const
{
if( !inbounds( p ) ) {
Expand Down Expand Up @@ -1898,10 +1888,6 @@ std::string map::furnname( const tripoint_bub_ms &p )
* retained for high performance comparisons, save/load, and gradual transition
* to string terrain.id
*/
ter_id map::ter( const tripoint p ) const
{
return ter( tripoint_bub_ms( p ) );
}
ter_id map::ter( const tripoint_bub_ms &p ) const
{
if( !inbounds( p ) ) {
Expand Down Expand Up @@ -2643,11 +2629,6 @@ int map::climb_difficulty( const tripoint_bub_ms &p ) const
return std::max( 0, best_difficulty - blocks_movement );
}

bool map::has_floor( const tripoint &p ) const
{
return map::has_floor( tripoint_bub_ms( p ) );
}

bool map::has_floor( const tripoint_bub_ms &p ) const
{
if( !zlevels || p.z() < -OVERMAP_DEPTH + 1 || p.z() > OVERMAP_HEIGHT ) {
Expand All @@ -2660,11 +2641,6 @@ bool map::has_floor( const tripoint_bub_ms &p ) const
!has_flag( ter_furn_flag::TFLAG_NO_FLOOR_WATER, p );
}

bool map::has_floor_or_water( const tripoint &p ) const
{
return map::has_floor_or_water( tripoint_bub_ms( p ) );
}

bool map::has_floor_or_water( const tripoint_bub_ms &p ) const
{
if( !zlevels || p.z() < -OVERMAP_DEPTH + 1 || p.z() > OVERMAP_HEIGHT ) {
Expand Down Expand Up @@ -2695,22 +2671,12 @@ bool map::supports_above( const tripoint_bub_ms &p ) const
return veh_at( p ).has_value();
}

bool map::has_floor_or_support( const tripoint &p ) const
{
return map::has_floor_or_support( tripoint_bub_ms( p ) );
}

bool map::has_floor_or_support( const tripoint_bub_ms &p ) const
{
const tripoint_bub_ms below( p.xy(), p.z() - 1 );
return !valid_move( p, below, false, true );
}

bool map::has_vehicle_floor( const tripoint &p ) const
{
const tripoint_bub_ms p_bub( p );
return has_vehicle_floor( p_bub );
}
bool map::has_vehicle_floor( const tripoint_bub_ms &p ) const
{
return veh_at( p ).part_with_feature( "BOARDABLE", false ) ||
Expand Down Expand Up @@ -3076,11 +3042,6 @@ bool map::can_put_items_ter_furn( const tripoint_bub_ms &p ) const
return !has_flag( ter_furn_flag::TFLAG_NOITEM, p ) && !has_flag( ter_furn_flag::TFLAG_SEALED, p );
}

bool map::has_flag_ter( const std::string &flag, const tripoint &p ) const
{
return ter( tripoint_bub_ms( p ) ).obj().has_flag( flag );
}

bool map::has_flag_ter( const std::string &flag, const tripoint_bub_ms &p ) const
{
return ter( p ).obj().has_flag( flag );
Expand Down Expand Up @@ -5353,7 +5314,7 @@ void map::make_active( item_location &loc )
item *target = loc.get_item();

point_sm_ms l;
submap *const current_submap = get_submap_at( loc.position(), l.raw() );
submap *const current_submap = get_submap_at( loc.pos_bub(), l );
if( current_submap == nullptr ) {
debugmsg( "Tried to make active at (%d,%d) but the submap is not loaded", l.x(), l.y() );
return;
Expand Down Expand Up @@ -6439,11 +6400,6 @@ std::optional<field_entry> map::get_impassable_field_at( const tripoint_bub_ms &
return potential_field;
}

bool map::impassable_field_at( const tripoint &p )
{
return impassable_field_at( tripoint_bub_ms( p ) );
}

bool map::impassable_field_at( const tripoint_bub_ms &p )
{
for( auto &pr : field_at( p ) ) {
Expand All @@ -6455,11 +6411,6 @@ bool map::impassable_field_at( const tripoint_bub_ms &p )
return false;
}

std::vector<field_type_id> map::get_impassable_field_type_ids_at( const tripoint &p )
{
return get_impassable_field_type_ids_at( tripoint_bub_ms( p ) );
}

std::vector<field_type_id> map::get_impassable_field_type_ids_at( const tripoint_bub_ms &p )
{
std::vector<field_type_id> fields;
Expand Down Expand Up @@ -9045,11 +8996,6 @@ const std::vector<tripoint_bub_ms> &map::trap_locations( const trap_id &type ) c
return traplocs[type.to_i()];
}

bool map::inbounds( const tripoint &p ) const
{
return inbounds( tripoint_bub_ms( p ) );
}

bool map::inbounds( const tripoint_abs_ms &p ) const
{
return inbounds( bub_from_abs( p ) );
Expand Down Expand Up @@ -9625,11 +9571,6 @@ void map::build_map_cache( const int zlev, bool skip_lightmap )
//////////
///// coordinate helpers

tripoint_abs_ms map::getglobal( const tripoint &p ) const
{
return map::getglobal( tripoint_bub_ms( p ) );
}

tripoint_abs_ms map::getglobal( const tripoint_bub_ms &p ) const
{
return tripoint_abs_ms{ p.x() + abs_ms.x(), p.y() + abs_ms.y(), p.z() };
Expand Down Expand Up @@ -10242,17 +10183,6 @@ tripoint_range<tripoint_bub_ms> map::points_in_rectangle( const tripoint_bub_ms
return tripoint_range<tripoint_bub_ms>( min, max );
}

tripoint_range<tripoint> map::points_in_radius( const tripoint &center, size_t radius,
size_t radiusz ) const
{
const tripoint min( std::max<int>( 0, center.x - radius ), std::max<int>( 0, center.y - radius ),
clamp<int>( center.z - radiusz, -OVERMAP_DEPTH, OVERMAP_HEIGHT ) );
const tripoint max( std::min<int>( SEEX * my_MAPSIZE - 1, center.x + radius ),
std::min<int>( SEEX * my_MAPSIZE - 1, center.y + radius ), clamp<int>( center.z + radiusz,
-OVERMAP_DEPTH, OVERMAP_HEIGHT ) );
return tripoint_range<tripoint>( min, max );
}

tripoint_range<tripoint_bub_ms> map::points_in_radius(
const tripoint_bub_ms &center, size_t radius, size_t radiusz ) const
{
Expand Down Expand Up @@ -10552,11 +10482,6 @@ void map::update_pathfinding_cache( int zlev ) const
cache.dirty_points.clear();
}

void map::clip_to_bounds( tripoint &p ) const
{
clip_to_bounds( p.x, p.y, p.z );
}

void map::clip_to_bounds( tripoint_bub_ms &p ) const
{
clip_to_bounds( p.x(), p.y(), p.z() );
Expand Down Expand Up @@ -10689,11 +10614,6 @@ bool map::has_haulable_items( const tripoint_bub_ms &pos )
return false;
}

std::vector<item_location> map::get_haulable_items( const tripoint &pos )
{
return map::get_haulable_items( tripoint_bub_ms( pos ) );
}

std::vector<item_location> map::get_haulable_items( const tripoint_bub_ms &pos )
{
std::vector<item_location> target_items;
Expand Down
Loading

0 comments on commit f2e3ee4

Please sign in to comment.