From 1e228cae8b507852300c4f463e7dbf0e04cd3a75 Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Mon, 8 Jul 2024 20:08:39 +0200 Subject: [PATCH] typified submap.h/cpp (#74911) --- src/editmap.cpp | 20 +- src/game.cpp | 10 + src/game.h | 3 + src/item.cpp | 7 +- src/item.h | 2 + src/lightmap.cpp | 8 +- src/map.cpp | 572 +++++++++++++++++++------------------ src/map.h | 33 ++- src/map_field.cpp | 22 +- src/mapgen.cpp | 50 ++-- src/monmove.cpp | 5 + src/monster.h | 2 + src/savegame.cpp | 12 +- src/savegame_json.cpp | 34 +-- src/submap.cpp | 107 ++++--- src/submap.h | 113 ++++---- src/vehicle.cpp | 8 +- src/visitable.cpp | 4 +- tests/map_helpers.cpp | 4 +- tests/map_test.cpp | 2 +- tests/submap_load_test.cpp | 32 +-- tests/submap_test.cpp | 20 +- 22 files changed, 548 insertions(+), 522 deletions(-) diff --git a/src/editmap.cpp b/src/editmap.cpp index 2c064be64a0b6..6e0e05235e671 100644 --- a/src/editmap.cpp +++ b/src/editmap.cpp @@ -671,7 +671,7 @@ void editmap::draw_main_ui_overlay() if( sm ) { const tripoint_bub_ms sm_origin = origin_p + tripoint( x * SEEX, y * SEEY, target.z() ); for( const spawn_point &sp : sm->spawns ) { - const tripoint_bub_ms spawn_p = sm_origin + sp.pos; + const tripoint_bub_ms spawn_p = sm_origin + rebase_rel( sp.pos ); const auto spawn_it = spawns.find( spawn_p ); if( spawn_it == spawns.end() ) { const Creature::Attitude att = sp.friendly ? Creature::Attitude::FRIENDLY : Creature::Attitude::ANY; @@ -1918,7 +1918,7 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu ) } else if( gpmenu.ret == 1 ) { tmpmap.rotate( 1 ); } else if( gpmenu.ret == 2 ) { - const point target_sub( target.x() / SEEX, target.y() / SEEY ); + const point_rel_sm target_sub( target.x() / SEEX, target.y() / SEEY ); here.set_transparency_cache_dirty( target.z() ); here.set_outside_cache_dirty( target.z() ); @@ -1933,21 +1933,21 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu ) for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) { // Apply previewed mapgen to map. Since this is a function for testing, we try avoid triggering // functions that would alter the results - const tripoint dest_pos = target_sub + tripoint( x, y, z ); - const tripoint src_pos = tripoint{ x, y, z }; + const tripoint_rel_sm dest_pos = target_sub + tripoint( x, y, z ); + const tripoint_rel_sm src_pos = tripoint_rel_sm{ x, y, z }; submap *destsm = here.get_submap_at_grid( dest_pos ); submap *srcsm = tmpmap.get_submap_at_grid( src_pos ); if( srcsm == nullptr || destsm == nullptr ) { - debugmsg( "Tried to apply previewed mapgen at (%d,%d,%d) but the submap is not loaded", src_pos.x, - src_pos.y, src_pos.z ); + debugmsg( "Tried to apply previewed mapgen at (%d,%d,%d) but the submap is not loaded", src_pos.x(), + src_pos.y(), src_pos.z() ); continue; } std::swap( *destsm, *srcsm ); for( auto &veh : destsm->vehicles ) { - veh->sm_pos = dest_pos; + veh->sm_pos = dest_pos.raw(); } if( !destsm->spawns.empty() ) { // trigger spawnpoints @@ -1960,11 +1960,11 @@ void editmap::mapgen_preview( const real_coords &tc, uilist &gmenu ) // Since we cleared the vehicle cache of the whole z-level (not just the generate map), we add it back here for( int x = 0; x < here.getmapsize(); x++ ) { for( int y = 0; y < here.getmapsize(); y++ ) { - const tripoint dest_pos = tripoint( x, y, target.z() ); + const tripoint_rel_sm dest_pos = tripoint_rel_sm( x, y, target.z() ); const submap *destsm = here.get_submap_at_grid( dest_pos ); if( destsm == nullptr ) { - debugmsg( "Tried to update vehicle cache at (%d,%d,%d) but the submap is not loaded", dest_pos.x, - dest_pos.y, dest_pos.z ); + debugmsg( "Tried to update vehicle cache at (%d,%d,%d) but the submap is not loaded", dest_pos.x(), + dest_pos.y(), dest_pos.z() ); continue; } here.update_vehicle_list( destsm, target.z() ); // update real map's vcaches diff --git a/src/game.cpp b/src/game.cpp index d120ecc6894e7..9401dc66a2dbc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -5040,11 +5040,21 @@ monster *game::place_critter_at( const mtype_id &id, const tripoint &p ) return place_critter_around( id, p, 0 ); } +monster *game::place_critter_at( const mtype_id &id, const tripoint_bub_ms &p ) +{ + return place_critter_around( id, p.raw(), 0 ); +} + monster *game::place_critter_at( const shared_ptr_fast &mon, const tripoint &p ) { return place_critter_around( mon, p, 0 ); } +monster *game::place_critter_at( const shared_ptr_fast &mon, const tripoint_bub_ms &p ) +{ + return place_critter_around( mon, p.raw(), 0 ); +} + monster *game::place_critter_around( const mtype_id &id, const tripoint ¢er, const int radius ) { // TODO: change this into an assert, it must never happen. diff --git a/src/game.h b/src/game.h index c48120acf4017..5dfb8db225898 100644 --- a/src/game.h +++ b/src/game.h @@ -343,8 +343,11 @@ class game * the one contained in @p mon). */ /** @{ */ + // TODO: Get rid of untyped overload. monster *place_critter_at( const mtype_id &id, const tripoint &p ); + monster *place_critter_at( const mtype_id &id, const tripoint_bub_ms &p ); monster *place_critter_at( const shared_ptr_fast &mon, const tripoint &p ); + monster *place_critter_at( const shared_ptr_fast &mon, const tripoint_bub_ms &p ); monster *place_critter_around( const mtype_id &id, const tripoint ¢er, int radius ); monster *place_critter_around( const shared_ptr_fast &mon, const tripoint ¢er, int radius, bool forced = false ); diff --git a/src/item.cpp b/src/item.cpp index b970c2a0417c7..c4455cb23df2a 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -10258,12 +10258,17 @@ bool item::spill_contents( Character &c ) } bool item::spill_contents( const tripoint &pos ) +{ + return item::spill_contents( tripoint_bub_ms( pos ) ); +} + +bool item::spill_contents( const tripoint_bub_ms &pos ) { if( ( !is_container() && !is_magazine() && !uses_magazine() ) || is_container_empty() ) { return true; } - return contents.spill_contents( pos ); + return contents.spill_contents( pos.raw() ); } bool item::spill_open_pockets( Character &guy, const item *avoid ) diff --git a/src/item.h b/src/item.h index b25422a307fe3..1d656e0a95c37 100644 --- a/src/item.h +++ b/src/item.h @@ -1816,7 +1816,9 @@ class item : public visitable * @param pos Position to dump the contents on. * @return If the item is now empty. */ + // TODO: Get rid of untyped overload. bool spill_contents( const tripoint &pos ); + bool spill_contents( const tripoint_bub_ms &pos ); bool spill_open_pockets( Character &guy, const item *avoid = nullptr ); // spill items that don't fit in the container void overflow( const tripoint &pos, const item_location &loc = item_location::nowhere ); diff --git a/src/lightmap.cpp b/src/lightmap.cpp index f03e6da993721..40f24d5d2d3a4 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -129,15 +129,15 @@ bool map::build_transparency_cache( const int zlev ) // calculates transparency of a single tile // x,y - coords in map local coords - auto calc_transp = [&]( const point & p ) { - const point sp = p - sm_offset; + auto calc_transp = [&]( const point_sm_ms & p ) { + const point_sm_ms sp = p - sm_offset; float value = LIGHT_TRANSPARENCY_OPEN_AIR; if( !( cur_submap->get_ter( sp ).obj().transparent && cur_submap->get_furn( sp ).obj().transparent ) ) { return std::make_pair( LIGHT_TRANSPARENCY_SOLID, LIGHT_TRANSPARENCY_SOLID ); } - if( outside_cache[p.x][p.y] ) { + if( outside_cache[p.x()][p.y()] ) { // FIXME: Places inside vehicles haven't been marked as // inside yet so this is incorrectly penalising for // weather in vehicles. @@ -159,7 +159,7 @@ bool map::build_transparency_cache( const int zlev ) if( cur_submap->is_uniform() ) { float value; float dummy; - std::tie( value, dummy ) = calc_transp( sm_offset ); + std::tie( value, dummy ) = calc_transp( point_sm_ms( sm_offset ) ); // if rebuild_all==true all values were already set to LIGHT_TRANSPARENCY_OPEN_AIR if( !rebuild_all || value != LIGHT_TRANSPARENCY_OPEN_AIR ) { bool opaque = value <= LIGHT_TRANSPARENCY_SOLID; diff --git a/src/map.cpp b/src/map.cpp index d5e263c12b333..ea0918dcc17a0 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -32,6 +32,7 @@ #include "coordinate_constants.h" #include "coordinate_conversions.h" #include "coordinates.h" +#include "coords_fwd.h" #include "creature.h" #include "creature_tracker.h" #include "cuboid_rectangle.h" @@ -395,7 +396,7 @@ void map::invalidate_map_cache( const int zlev ) const_maptile map::maptile_at( const tripoint &p ) const { if( !inbounds( p ) ) { - return const_maptile( &null_submap, point_zero ); + return const_maptile( &null_submap, point_sm_ms_zero ); } return maptile_at_internal( p ); @@ -409,7 +410,7 @@ const_maptile map::maptile_at( const tripoint_bub_ms &p ) const maptile map::maptile_at( const tripoint &p ) { if( !inbounds( p ) ) { - return maptile( &null_submap, point_zero ); + return maptile( &null_submap, point_sm_ms_zero ); } return maptile_at_internal( p ); @@ -422,16 +423,16 @@ maptile map::maptile_at( const tripoint_bub_ms &p ) const_maptile map::maptile_at_internal( const tripoint &p ) const { - point l; - const submap *const sm = get_submap_at( p, l ); + point_sm_ms l; + const submap *const sm = get_submap_at( tripoint_bub_ms( p ), l ); return const_maptile( sm, l ); } maptile map::maptile_at_internal( const tripoint &p ) { - point l; - submap *const sm = get_submap_at( p, l ); + point_sm_ms l; + submap *const sm = get_submap_at( tripoint_bub_ms( p ), l ); return maptile( sm, l ); } @@ -543,11 +544,11 @@ void map::reset_vehicles_sm_pos() level_cache &ch = get_cache( z ); for( int x = 0; x < getmapsize(); x++ ) { for( int y = 0; y < getmapsize(); y++ ) { - tripoint const grid( x, y, z ); + tripoint_rel_sm const grid( x, y, z ); submap *const sm = get_submap_at_grid( grid ); if( sm != nullptr ) { for( auto const &elem : sm->vehicles ) { - elem->sm_pos = grid; + elem->sm_pos = grid.raw(); add_vehicle_to_cache( &*elem ); _add_vehicle_to_list( ch, &*elem ); } @@ -598,7 +599,7 @@ std::unique_ptr map::detach_vehicle( vehicle *veh ) } } veh->invalidate_towing( true ); - submap *const current_submap = get_submap_at_grid( veh->sm_pos ); + submap *const current_submap = get_submap_at_grid( tripoint_rel_sm( veh->sm_pos ) ); if( current_submap == nullptr ) { debugmsg( "Tried to detach vehicle at (%d,%d,%d) but the submap is not loaded", veh->sm_pos.x, veh->sm_pos.y, veh->sm_pos.z ); @@ -1739,10 +1740,10 @@ furn_id map::furn( const tripoint &p ) const return furn_str_id::NULL_ID(); } - point l; - const submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried process furniture at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried process furniture at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return furn_str_id::NULL_ID(); } @@ -1773,10 +1774,10 @@ bool map::furn_set( const tripoint_bub_ms &p, const furn_id &new_furniture, cons return false; } } - point l; - submap *const current_submap = unsafe_get_submap_at( p.raw(), l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to set furniture at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to set furniture at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return false; } const furn_id new_target_furniture = new_furniture == furn_f_clear ? furn_str_id::NULL_ID() : @@ -1939,10 +1940,10 @@ ter_id map::ter( const tripoint &p ) const return ter_str_id::NULL_ID().id(); } - point l; - const submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to process terrain at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to process terrain at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return ter_str_id::NULL_ID().id(); } @@ -2249,10 +2250,10 @@ bool map::ter_set( const tripoint &p, const ter_id &new_terrain, bool avoid_crea } } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to set terrain at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to set terrain at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return true; } const ter_id old_id = current_submap->get_ter( l ); @@ -2431,11 +2432,16 @@ bool map::is_wall_adjacent( const tripoint ¢er ) const } bool map::is_open_air( const tripoint &p ) const +{ + return map::is_open_air( tripoint_bub_ms( p ) ); +} + +bool map::is_open_air( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { return false; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { return false; @@ -2443,21 +2449,21 @@ bool map::is_open_air( const tripoint &p ) const return current_submap->is_open_air( l ); } -bool map::is_open_air( const tripoint_bub_ms &p ) const -{ - return map::is_open_air( p.raw() ); -} - // Move cost: 3D int map::move_cost( const tripoint &p, const vehicle *ignored_vehicle ) const +{ + return move_cost( tripoint_bub_ms( p ), ignored_vehicle ); +} + +int map::move_cost( const tripoint_bub_ms &p, const vehicle *ignored_vehicle ) const { // To save all of the bound checks and submaps fetching, we extract it // here instead of using furn(), field_at() and ter(). if( !inbounds( p ) ) { return 0; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { return 0; @@ -2473,11 +2479,6 @@ int map::move_cost( const tripoint &p, const vehicle *ignored_vehicle ) const return move_cost_internal( furniture, terrain, field, veh, part ); } -int map::move_cost( const tripoint_bub_ms &p, const vehicle *ignored_vehicle ) const -{ - return move_cost( p.raw(), ignored_vehicle ); -} - bool map::impassable( const tripoint &p ) const { return !passable( p ); @@ -2504,10 +2505,10 @@ int map::move_cost_ter_furn( const tripoint &p ) const return 0; } - point l; - const submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried process terrain at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried process terrain at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return 0; } @@ -2726,7 +2727,12 @@ bool map::has_floor( const tripoint_bub_ms &p ) const bool map::has_floor_or_water( const tripoint &p ) const { - if( !zlevels || p.z < -OVERMAP_DEPTH + 1 || p.z > OVERMAP_HEIGHT ) { + 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 ) { return true; } if( !inbounds( p ) ) { @@ -3149,10 +3155,10 @@ bool map::has_flag_ter_or_furn( const std::string &flag, const tripoint &p ) con return false; } - point l; - const submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to process terrain at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to process terrain at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return false; } @@ -3196,10 +3202,10 @@ bool map::has_flag_ter_or_furn( const ter_furn_flag flag, const tripoint &p ) co return false; } - point l; - const submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to process terrain at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to process terrain at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return false; } @@ -4896,10 +4902,10 @@ std::string map::get_signage( const tripoint &p ) const return ""; } - point l; - const submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + const submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get signage at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get signage at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return std::string(); } @@ -4911,66 +4917,66 @@ void map::set_signage( const tripoint &p, const std::string &message ) return; } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried set signage at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried set signage at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } current_submap->set_signage( l, message ); } void map::delete_signage( const tripoint &p ) +{ + delete_signage( tripoint_bub_ms( p ) ); +} +void map::delete_signage( const tripoint_bub_ms &p ) { if( !inbounds( p ) ) { return; } - point l; + point_sm_ms l; submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to delete signage at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to delete signage at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } current_submap->delete_signage( l ); } -void map::delete_signage( const tripoint_bub_ms &p ) + +int map::get_radiation( const tripoint &p ) const { - delete_signage( p.raw() ); + return map::get_radiation( tripoint_bub_ms( p ) ); } -int map::get_radiation( const tripoint &p ) const +int map::get_radiation( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { return 0; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get radiation at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get radiation at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return 0; } return current_submap->get_radiation( l ); } -int map::get_radiation( const tripoint_bub_ms &p ) const -{ - return map::get_radiation( p.raw() ); -} - void map::set_radiation( const tripoint &p, const int value ) { if( !inbounds( p ) ) { return; } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to set radiation at (%d,%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to set radiation at (%d,%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } @@ -4983,10 +4989,10 @@ void map::adjust_radiation( const tripoint &p, const int delta ) return; } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to adjust radiation at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to adjust radiation at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } @@ -5025,34 +5031,34 @@ void map::set_temperature_mod( const tripoint &p, units::temperature_delta new_t // Items: 3D map_stack map::i_at( const tripoint &p ) +{ + return i_at( tripoint_bub_ms( p ) ); +} + +map_stack map::i_at( const tripoint_bub_ms &p ) { if( !inbounds( p ) ) { nulitems.clear(); - return map_stack{ &nulitems, p, this }; + return map_stack{ &nulitems, p.raw(), this}; } - point l; + point_sm_ms l; submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get items at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get items at (%d,%d) but the submap is not loaded", l.x(), l.y() ); nulitems.clear(); - return map_stack{ &nulitems, p, this }; + return map_stack{ &nulitems, p.raw(), this}; } - return map_stack{ ¤t_submap->get_items( l ), p, this }; -} - -map_stack map::i_at( const tripoint_bub_ms &p ) -{ - return i_at( p.raw() ); + return map_stack{ ¤t_submap->get_items( l ), p.raw(), this}; } map_stack::iterator map::i_rem( const tripoint &p, const map_stack::const_iterator &it ) { - point l; - submap *const current_submap = get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to remove items at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to remove items at (%d,%d) but the submap is not loaded", l.x(), l.y() ); nulitems.clear(); return map_stack{ &nulitems, p, this } .begin(); } @@ -5078,10 +5084,15 @@ void map::i_rem( const tripoint_bub_ms &p, item *it ) void map::i_clear( const tripoint &p ) { - point l; + i_clear( tripoint_bub_ms( p ) ); +} + +void map::i_clear( const tripoint_bub_ms &p ) +{ + point_sm_ms l; submap *const current_submap = get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to clear items at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to clear items at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } @@ -5089,11 +5100,6 @@ void map::i_clear( const tripoint &p ) current_submap->get_items( l ).clear(); } -void map::i_clear( const tripoint_bub_ms &p ) -{ - i_clear( p.raw() ); -} - std::vector map::spawn_items( const tripoint &p, const std::vector &new_items ) { std::vector ret; @@ -5559,10 +5565,10 @@ void map::update_lum( item_location &loc, bool add ) return; } - point l; - submap *const current_submap = get_submap_at( loc.position(), l ); + point_sm_ms l; + submap *const current_submap = get_submap_at( loc.pos_bub(), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to update lum at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to update lum at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } @@ -5574,7 +5580,7 @@ void map::update_lum( item_location &loc, bool add ) } static bool process_map_items( map &here, item_stack &items, safe_reference &item_ref, - item *parent, const tripoint &location, float insulation, + item *parent, const tripoint_bub_ms &location, float insulation, temperature_flag flag, float spoil_multiplier, bool watertight_container ) { if( item_ref->process( here, nullptr, location, insulation, flag, spoil_multiplier, @@ -5702,7 +5708,7 @@ void map::process_items() submaps_with_vehicles.emplace( pos.x / SEEX, pos.y / SEEY, pos.z ); } for( const tripoint &pos : submaps_with_vehicles ) { - submap *const current_submap = get_submap_at_grid( pos ); + submap *const current_submap = get_submap_at_grid( tripoint_rel_sm( pos ) ); if( current_submap == nullptr ) { debugmsg( "Tried to process items at (%d,%d,%d) but the submap is not loaded", pos.x, pos.y, pos.z ); @@ -5720,15 +5726,14 @@ void map::process_items() continue; } const tripoint_rel_sm local_pos = abs_pos - abs_sub.xy(); - // TODO: fix point types - submap *const current_submap = get_submap_at_grid( local_pos.raw() ); + submap *const current_submap = get_submap_at_grid( local_pos ); if( current_submap == nullptr ) { debugmsg( "Tried to process items at %s but the submap is not loaded", local_pos.to_string() ); continue; } // TODO: fix point types - process_items_in_submap( *current_submap, local_pos.raw() ); + process_items_in_submap( *current_submap, local_pos ); if( current_submap->active_items.empty() ) { iter = submaps_with_active_items.erase( iter ); } else { @@ -5737,20 +5742,21 @@ void map::process_items() } } -void map::process_items_in_submap( submap ¤t_submap, const tripoint &gridp ) +void map::process_items_in_submap( submap ¤t_submap, const tripoint_rel_sm &gridp ) { // Get a COPY of the active item list for this submap. // If more are added as a side effect of processing, they are ignored this turn. // If they are destroyed before processing, they don't get processed. std::vector active_items = current_submap.active_items.get_for_processing(); - const point grid_offset( gridp.x * SEEX, gridp.y * SEEY ); + const point_bub_ms grid_offset( gridp.x() * SEEX, gridp.y() * SEEY ); for( item_reference &active_item_ref : active_items ) { if( !active_item_ref.item_ref ) { // The item was destroyed, so skip it. continue; } - const tripoint map_location = tripoint( grid_offset + active_item_ref.location.raw(), gridp.z ); + const tripoint_bub_ms map_location = tripoint_bub_ms( grid_offset + active_item_ref.location, + gridp.z() ); const furn_t &furn = this->furn( map_location ).obj(); if( furn.has_flag( ter_furn_flag::TFLAG_DONT_REMOVE_ROTTEN ) ) { @@ -5833,7 +5839,7 @@ void map::process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap ) const item &target = *active_item_ref.item_ref; // Find the cargo part and coordinates corresponding to the current active item. const vehicle_part &pt = it->part(); - const tripoint item_loc = it->pos(); + const tripoint_bub_ms item_loc = it->pos_bub(); vehicle_stack items = cur_veh.get_items( pt ); float it_insulation = 1.0f; temperature_flag flag = temperature_flag::NORMAL; @@ -5927,26 +5933,26 @@ bool map::could_see_items( const tripoint_bub_ms &p, const tripoint_bub_ms &from } bool map::has_items( const tripoint &p ) const +{ + return has_items( tripoint_bub_ms( p ) ); +} + +bool map::has_items( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { return false; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to check items at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to check items at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return false; } return !current_submap->get_items( l ).empty(); } -bool map::has_items( const tripoint_bub_ms &p ) const -{ - return has_items( p.raw() ); -} - bool map::only_liquid_in_liquidcont( const tripoint_bub_ms &p ) { if( has_flag( ter_furn_flag::TFLAG_LIQUIDCONT, p ) ) { @@ -6255,15 +6261,25 @@ bool map::can_see_trap_at( const tripoint_bub_ms &p, const Character &c ) const } const trap &map::tr_at( const tripoint &p ) const +{ + return tr_at( tripoint_bub_ms( p ) ); +} + +const trap &map::tr_at( const tripoint_abs_ms &p ) const +{ + return tr_at( bub_from_abs( p ) ); +} + +const trap &map::tr_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { return tr_null.obj(); } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get trap at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get trap at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return tr_null.obj(); } @@ -6275,16 +6291,6 @@ const trap &map::tr_at( const tripoint &p ) const return current_submap->get_trap( l ).obj(); } -const trap &map::tr_at( const tripoint_abs_ms &p ) const -{ - return tr_at( bub_from_abs( p ) ); -} - -const trap &map::tr_at( const tripoint_bub_ms &p ) const -{ - return tr_at( p.raw() ); -} - partial_con *map::partial_con_at( const tripoint_bub_ms &p ) { if( !inbounds( p ) ) { @@ -6339,12 +6345,17 @@ void map::partial_con_set( const tripoint_bub_ms &p, const partial_con &con ) } void map::trap_set( const tripoint &p, const trap_id &type ) +{ + trap_set( tripoint_bub_ms( p ), type ); +} + +void map::trap_set( const tripoint_bub_ms &p, const trap_id &type ) { if( !inbounds( p ) ) { return; } - point l; + point_sm_ms l; submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { debugmsg( "Tried to set trap at %s but the submap is not loaded", l.to_string() ); @@ -6358,7 +6369,7 @@ void map::trap_set( const tripoint &p, const trap_id &type ) return; } - memory_cache_dec_set_dirty( p, true ); + memory_cache_dec_set_dirty( p.raw(), true ); avatar &player_character = get_avatar(); if( player_character.sees( p ) ) { player_character.memorize_clear_decoration( getglobal( p ), "tr_" ); @@ -6370,67 +6381,67 @@ void map::trap_set( const tripoint &p, const trap_id &type ) current_submap->set_trap( l, type ); if( type != tr_null ) { - traplocs[type.to_i()].push_back( p ); + traplocs[type.to_i()].push_back( p.raw() ); } } -void map::trap_set( const tripoint_bub_ms &p, const trap_id &type ) +void map::remove_trap( const tripoint &p ) { - trap_set( p.raw(), type ); + remove_trap( tripoint_bub_ms( p ) ); } -void map::remove_trap( const tripoint &p ) +void map::remove_trap( const tripoint_bub_ms &p ) { if( !inbounds( p ) ) { return; } - point l; + point_sm_ms l; submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to remove trap at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to remove trap at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } trap_id tid = current_submap->get_trap( l ); if( tid != tr_null ) { if( g != nullptr && this == &get_map() ) { - memory_cache_dec_set_dirty( p, true ); + memory_cache_dec_set_dirty( p.raw(), true ); avatar &player_character = get_avatar(); if( player_character.sees( p ) ) { player_character.memorize_clear_decoration( getglobal( p ), "tr_" ); } - player_character.add_known_trap( p, tr_null.obj() ); + player_character.add_known_trap( p.raw(), tr_null.obj() ); } current_submap->set_trap( l, tr_null ); auto &traps = traplocs[tid.to_i()]; - const auto iter = std::find( traps.begin(), traps.end(), p ); + const auto iter = std::find( traps.begin(), traps.end(), p.raw() ); if( iter != traps.end() ) { traps.erase( iter ); } } } -void map::remove_trap( const tripoint_bub_ms &p ) -{ - remove_trap( p.raw() ); -} - /* * Get wrapper for all fields at xyz */ const field &map::field_at( const tripoint &p ) const +{ + return field_at( tripoint_bub_ms( p ) ); +} + +const field &map::field_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { nulfield = field(); return nulfield; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get field at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get field at (%d,%d) but the submap is not loaded", l.x(), l.y() ); nulfield = field(); return nulfield; } @@ -6438,25 +6449,25 @@ const field &map::field_at( const tripoint &p ) const return current_submap->get_field( l ); } -const field &map::field_at( const tripoint_bub_ms &p ) const -{ - return field_at( p.raw() ); -} - /* * As above, except not const */ field &map::field_at( const tripoint &p ) +{ + return field_at( tripoint_bub_ms( p ) ); +} + +field &map::field_at( const tripoint_bub_ms &p ) { if( !inbounds( p ) ) { nulfield = field(); return nulfield; } - point l; + point_sm_ms l; submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get field at (%d,%d,%d) but the submap is not loaded", p.x, p.y, p.z ); + debugmsg( "Tried to get field at (%d,%d,%d) but the submap is not loaded", p.x(), p.y(), p.z() ); nulfield = field(); return nulfield; } @@ -6464,11 +6475,6 @@ field &map::field_at( const tripoint &p ) return current_submap->get_field( l ); } -field &map::field_at( const tripoint_bub_ms &p ) -{ - return field_at( p.raw() ); -} - time_duration map::mod_field_age( const tripoint &p, const field_type_id &type, const time_duration &offset ) { @@ -6559,10 +6565,10 @@ cata::copy_const *map::get_field_helper( return nullptr; } - point l; - auto *const current_submap = m.unsafe_get_submap_at( p, l ); + point_sm_ms l; + auto *const current_submap = m.unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get field at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get field at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return nullptr; } @@ -6618,6 +6624,12 @@ bool map::mopsafe_field_at( const tripoint &p ) bool map::add_field( const tripoint &p, const field_type_id &type_id, int intensity, const time_duration &age, bool hit_player ) +{ + return add_field( tripoint_bub_ms( p ), type_id, intensity, age, hit_player ); +} + +bool map::add_field( const tripoint_bub_ms &p, const field_type_id &type_id, int intensity, + const time_duration &age, bool hit_player ) { if( !inbounds( p ) ) { return false; @@ -6639,7 +6651,7 @@ bool map::add_field( const tripoint &p, const field_type_id &type_id, int intens // Hacky way to force electricity fields to become unlit electricity fields const field_type_id &converted_type_id = ( type_id == fd_electricity || - type_id == fd_electricity_unlit ) ? get_applicable_electricity_field( p ) : type_id; + type_id == fd_electricity_unlit ) ? get_applicable_electricity_field( p.raw() ) : type_id; const field_type &fd_type = *converted_type_id; intensity = std::min( intensity, fd_type.get_max_intensity() ); @@ -6647,42 +6659,36 @@ bool map::add_field( const tripoint &p, const field_type_id &type_id, int intens return false; } - point l; + point_sm_ms l; submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to add field at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to add field at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return false; } current_submap->ensure_nonuniform(); - invalidate_max_populated_zlev( p.z ); + invalidate_max_populated_zlev( p.z() ); if( current_submap->get_field( l ).add_field( converted_type_id, intensity, age ) ) { //Only adding it to the count if it doesn't exist. if( !current_submap->field_count++ ) { - get_cache( p.z ).field_cache.set( - static_cast( p.x / SEEX ) + ( ( p.y / SEEX ) * MAPSIZE ) ); + get_cache( p.z() ).field_cache.set( + static_cast( p.x() / SEEX ) + ( ( p.y() / SEEX ) * MAPSIZE ) ); } } if( hit_player ) { Character &player_character = get_player_character(); - if( g != nullptr && this == &get_map() && p == player_character.pos() ) { + if( g != nullptr && this == &get_map() && p == player_character.pos_bub() ) { //Hit the player with the field if it spawned on top of them. creature_in_field( player_character ); } } - on_field_modified( p, fd_type ); + on_field_modified( p.raw(), fd_type ); return true; } -bool map::add_field( const tripoint_bub_ms &p, const field_type_id &type_id, int intensity, - const time_duration &age, bool hit_player ) -{ - return add_field( p.raw(), type_id, intensity, age, hit_player ); -} - void map::remove_field( const tripoint &p, const field_type_id &field_to_remove ) { set_field_intensity( p, field_to_remove, 0 ); @@ -6719,8 +6725,8 @@ void map::clear_fields( const tripoint &p ) return; } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); current_submap->clear_fields( l ); } @@ -8002,7 +8008,7 @@ void map::load( const tripoint_abs_sm &w, const bool update_vehicle, const int zmin = zlevels ? -OVERMAP_DEPTH : abs_sub.z(); const int zmax = zlevels ? OVERMAP_HEIGHT : abs_sub.z(); for( int gridz = zmin; gridz <= zmax; gridz++ ) { - actualize( tripoint( point( gridx, gridy ), gridz ) ); + actualize( {gridx, gridy, gridz } ); if( pump_events ) { inp_mngr.pump_events(); } @@ -8097,7 +8103,7 @@ void map::shift( const point &sp ) } const tripoint_abs_sm abs = get_abs_sub(); - std::vector loaded_grids; + std::vector loaded_grids; // TODO: fix point types (sp should be relative?) set_abs_sub( abs + sp ); @@ -8150,7 +8156,7 @@ void map::shift( const point &sp ) for( int gridy = y_start; gridy != y_stop; gridy += y_step ) { if( gridx + sp.x != x_stop && gridy + sp.y != y_stop ) { for( int gridz = zmin; gridz <= zmax; gridz++ ) { - const tripoint grid( gridx, gridy, gridz ); + const tripoint_rel_sm grid( gridx, gridy, gridz ); copy_grid( grid, grid + sp ); submap *const cur_submap = get_submap_at_grid( grid ); @@ -8183,7 +8189,7 @@ void map::shift( const point &sp ) } // actualize after loading all submaps to prevent errors // with entities at the edges - for( tripoint loaded_grid : loaded_grids ) { + for( tripoint_rel_sm loaded_grid : loaded_grids ) { actualize( loaded_grid ); } } @@ -8220,7 +8226,7 @@ void map::saven( const tripoint &grid ) dbg( D_INFO ) << "map::saven(worldx[" << abs_sub.x() << "], worldy[" << abs_sub.y() << "], worldz[" << abs_sub.z() << "], gridx[" << grid.x << "], gridy[" << grid.y << "], gridz[" << grid.z << "])"; - const int gridn = get_nonant( grid ); + const int gridn = get_nonant( tripoint_rel_sm( grid ) ); submap *submap_to_save = getsubmap( gridn ); if( submap_to_save == nullptr ) { debugmsg( "Tried to save submap node (%d) but it's not loaded", gridn ); @@ -8346,7 +8352,7 @@ void map::loadn( const point &grid, bool update_vehicles ) set_floor_cache_dirty( z ); set_pathfinding_cache_dirty( z ); tmpsub = MAPBUFFER.lookup_submap( pos ); - setsubmap( get_nonant( { grid, z } ), tmpsub ); + setsubmap( get_nonant( tripoint_rel_sm{ grid.x, grid.y, z } ), tmpsub ); if( !tmpsub->active_items.empty() ) { submaps_with_active_items_dirty.emplace( pos ); } @@ -8389,7 +8395,7 @@ void map::loadn( const point &grid, bool update_vehicles ) } if( zlevels ) { - add_roofs( tripoint( grid, z ) ); + add_roofs( tripoint_rel_sm( grid.x, grid.y, z ) ); } } } @@ -8760,11 +8766,11 @@ void map::decay_cosmetic_fields( const tripoint &p, } } -void map::actualize( const tripoint &grid ) +void map::actualize( const tripoint_rel_sm &grid ) { submap *const tmpsub = get_submap_at_grid( grid ); if( tmpsub == nullptr ) { - debugmsg( "Actualize called on null submap (%d,%d,%d)", grid.x, grid.y, grid.z ); + debugmsg( "Actualize called on null submap (%d,%d,%d)", grid.x(), grid.y(), grid.z() ); return; } @@ -8778,7 +8784,7 @@ void map::actualize( const tripoint &grid ) } const time_duration time_since_last_actualize = calendar::turn - tmpsub->last_touched; - const bool do_funnels = grid.z >= 0; + const bool do_funnels = grid.z() >= 0; // check spoiled stuff, and fill up funnels while we're at it process_items_in_vehicles( *tmpsub ); @@ -8786,8 +8792,8 @@ void map::actualize( const tripoint &grid ) explosion_handler::process_explosions(); for( int x = 0; x < SEEX; x++ ) { for( int y = 0; y < SEEY; y++ ) { - const tripoint pnt = sm_to_ms_copy( grid ) + point( x, y ); - const point p( x, y ); + const tripoint pnt = sm_to_ms_copy( grid.raw() ) + point( x, y ); + const point_sm_ms p( x, y ); const furn_t &furn = *this->furn( pnt ); const ter_t &terr = *this->ter( pnt ); if( !furn.emissions.empty() ) { @@ -8826,7 +8832,7 @@ void map::actualize( const tripoint &grid ) tmpsub->last_touched = calendar::turn; } -void map::add_roofs( const tripoint &grid ) +void map::add_roofs( const tripoint_rel_sm &grid ) { if( !zlevels ) { // No roofs required! @@ -8837,17 +8843,17 @@ void map::add_roofs( const tripoint &grid ) submap *const sub_here = get_submap_at_grid( grid ); if( sub_here == nullptr ) { debugmsg( "Tried to add roofs/floors on null submap on %d,%d,%d", - grid.x, grid.y, grid.z ); + grid.x(), grid.y(), grid.z() ); return; } - bool check_roof = grid.z > -OVERMAP_DEPTH; + bool check_roof = grid.z() > -OVERMAP_DEPTH; - submap *const sub_below = check_roof ? get_submap_at_grid( grid + tripoint_below ) : nullptr; + submap *const sub_below = check_roof ? get_submap_at_grid( grid + tripoint_rel_sm_below ) : nullptr; if( check_roof && sub_below == nullptr ) { debugmsg( "Tried to add roofs to sm at %d,%d,%d, but sm below doesn't exist", - grid.x, grid.y, grid.z ); + grid.x(), grid.y(), grid.z() ); return; } @@ -8873,41 +8879,42 @@ void map::add_roofs( const tripoint &grid ) } } -void map::copy_grid( const tripoint &to, const tripoint &from ) +void map::copy_grid( const tripoint_rel_sm &to, const tripoint_rel_sm &from ) { submap *smap = get_submap_at_grid( from ); if( smap == nullptr ) { - debugmsg( "Tried to copy grid from (%d,%d,%d) but the submap is not loaded", from.x, from.y, - from.z ); + debugmsg( "Tried to copy grid from (%d,%d,%d) but the submap is not loaded", from.x(), from.y(), + from.z() ); return; } - setsubmap( get_nonant( to ), smap ); + setsubmap( get_nonant( tripoint_rel_sm( to ) ), smap ); for( auto &it : smap->vehicles ) { - it->sm_pos = to; + it->sm_pos = to.raw(); } } -void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool ignore_sight ) +void map::spawn_monsters_submap_group( const tripoint_rel_sm &gp, mongroup &group, + bool ignore_sight ) { Character &player_character = get_player_character(); const int s_range = std::min( HALF_MAPSIZE_X, player_character.sight_range( g->light_level( player_character.posz() ) ) ); int pop = group.population; - std::vector locations; + std::vector locations; if( !ignore_sight ) { // If the submap is one of the outermost submaps, assume that monsters are // invisible there. - if( gp.x == 0 || gp.y == 0 || gp.x + 1 == MAPSIZE || gp.y + 1 == MAPSIZE ) { + if( gp.x() == 0 || gp.y() == 0 || gp.x() + 1 == MAPSIZE || gp.y() + 1 == MAPSIZE ) { ignore_sight = true; } } - if( gp.z != player_character.posz() ) { - // Note: this is only OK because 3D vision isn't a thing yet + if( gp.z() != player_character.posz() ) { + // Note: this is only OK because 3D vision isn't a thing yet. 3D vision is a thing! Is this still OK? ignore_sight = true; } - static const auto allow_on_terrain = [&]( const tripoint & p ) { + static const auto allow_on_terrain = [&]( const tripoint_bub_ms & p ) { // TODO: flying creatures should be allowed to spawn without a floor, // but the new creature is created *after* determining the terrain, so // we can't check for it here. @@ -8917,20 +8924,20 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool // If the submap is uniform, we can skip many checks const submap *current_submap = get_submap_at_grid( gp ); if( current_submap == nullptr ) { - debugmsg( "Tried spawn monster group at (%d,%d,%d) but the submap is not loaded", gp.x, gp.y, - gp.z ); + debugmsg( "Tried spawn monster group at (%d,%d,%d) but the submap is not loaded", gp.x(), gp.y(), + gp.z() ); return; } bool ignore_terrain_checks = false; - bool ignore_inside_checks = gp.z < 0; + bool ignore_inside_checks = gp.z() < 0; if( current_submap->is_uniform() ) { - const tripoint upper_left{ SEEX * gp.x, SEEY * gp.y, gp.z }; + const tripoint_bub_ms upper_left{ SEEX * gp.x(), SEEY * gp.y(), gp.z()}; if( !allow_on_terrain( upper_left ) || ( !ignore_inside_checks && has_flag_ter_or_furn( ter_furn_flag::TFLAG_INDOORS, upper_left ) ) ) { - const tripoint glp = getabs( gp ); + const tripoint_abs_ms glp = getglobal( tripoint_bub_ms( gp.x() * SEEX, gp.y() * SEEY, gp.z() ) ); dbg( D_WARNING ) << "Empty locations for group " << group.type.str() << - " at uniform submap " << gp.x << "," << gp.y << "," << gp.z << - " global " << glp.x << "," << glp.y << "," << glp.z; + " at uniform submap " << gp.x() << "," << gp.y() << "," << gp.z() << + " global " << glp.x() << "," << glp.y() << "," << glp.z(); return; } @@ -8941,8 +8948,8 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool creature_tracker &creatures = get_creature_tracker(); for( int x = 0; x < SEEX; ++x ) { for( int y = 0; y < SEEY; ++y ) { - point f( x + SEEX * gp.x, y + SEEY * gp.y ); - tripoint fp{ f, gp.z }; + point_bub_ms f( x + SEEX * gp.x(), y + SEEY * gp.y() ); + tripoint_bub_ms fp{ f, gp.z()}; if( creatures.creature_at( fp ) != nullptr ) { continue; // there is already some creature } @@ -8951,7 +8958,7 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool continue; // solid area, impassable } - if( !ignore_sight && sees( player_character.pos(), fp, s_range ) ) { + if( !ignore_sight && sees( player_character.pos_bub(), fp, s_range ) ) { continue; // monster must spawn outside the viewing range of the player } @@ -8966,10 +8973,10 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool if( locations.empty() ) { // TODO: what now? there is no possible place to spawn monsters, most // likely because the player can see all the places. - const tripoint glp = getabs( gp ); + const tripoint_abs_ms glp = getglobal( tripoint_bub_ms( gp.x() * SEEX, gp.y() * SEEY, gp.z() ) ); dbg( D_WARNING ) << "Empty locations for group " << group.type.str() << - " at " << gp.x << "," << gp.y << "," << gp.z << - " global " << glp.x << "," << glp.y << "," << glp.z; + " at " << gp.x() << "," << gp.y() << "," << gp.z() << + " global " << glp.x() << "," << glp.y() << "," << glp.z(); // Just kill the group. It's not like we're removing existing monsters // Unless it's a horde - then don't kill it and let it spawn behind a tree or smoke cloud if( !group.horde ) { @@ -9004,14 +9011,14 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool // Find horde's target submap for( monster &tmp : group.monsters ) { for( int tries = 0; tries < 10 && !locations.empty(); tries++ ) { - const tripoint local_pos = random_entry_removed( locations ); + const tripoint_bub_ms local_pos = random_entry_removed( locations ); const tripoint_abs_ms abs_pos = get_map().getglobal( local_pos ); if( !tmp.can_move_to( local_pos ) ) { continue; // target can not contain the monster } if( group.horde ) { // Give monster a random point near horde's expected destination - const tripoint_sm_ms pos_in_sm( rng( 0, SEEX ), rng( 0, SEEY ), local_pos.z ); + const tripoint_sm_ms pos_in_sm( rng( 0, SEEX ), rng( 0, SEEY ), local_pos.z() ); const tripoint_abs_ms rand_dest = project_combine( group.target, pos_in_sm ); const int turns = rl_dist( abs_pos, rand_dest ) + group.interest; tmp.wander_to( rand_dest, turns ); @@ -9030,9 +9037,8 @@ void map::spawn_monsters_submap_group( const tripoint &gp, mongroup &group, bool group.clear(); } -void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight, bool spawn_nonlocal ) +void map::spawn_monsters_submap( const tripoint_rel_sm &gp, bool ignore_sight, bool spawn_nonlocal ) { - // TODO: fix point types const tripoint_abs_sm submap_pos( gp + abs_sub.xy() ); // Load unloaded monsters overmap_buffer.spawn_monster( submap_pos, spawn_nonlocal ); @@ -9044,10 +9050,11 @@ void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight, bool spa submap *const current_submap = get_submap_at_grid( gp ); if( current_submap == nullptr ) { - debugmsg( "Tried spawn monsters at (%d,%d,%d) but the submap is not loaded", gp.x, gp.y, gp.z ); + debugmsg( "Tried spawn monsters at (%d,%d,%d) but the submap is not loaded", gp.x(), gp.y(), + gp.z() ); return; } - const tripoint gp_ms = sm_to_ms_copy( gp ); + const tripoint_bub_ms gp_ms = tripoint_bub_ms( sm_to_ms_copy( gp.raw() ) ); creature_tracker &creatures = get_creature_tracker(); @@ -9057,8 +9064,8 @@ void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight, bool spa // NOLINTNEXTLINE(modernize-loop-convert) for( size_t sp_i = 0; sp_i < current_submap->spawns.size(); ++sp_i ) { const spawn_point i = current_submap->spawns[sp_i]; // intentional copy - const tripoint center = gp_ms + i.pos; - const tripoint_range points = points_in_radius( center, 3 ); + const tripoint_bub_ms center = gp_ms + rebase_rel( i.pos ); + const tripoint_range points = points_in_radius( center, 3 ); for( int j = 0; j < i.count; j++ ) { monster tmp( i.type ); @@ -9098,13 +9105,13 @@ void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight, bool spa tmp.ammo = tmp.type->starting_ammo; } - const auto valid_location = [&]( const tripoint & p ) { + const auto valid_location = [&]( const tripoint_bub_ms & p ) { // Checking for creatures via g is only meaningful if this is the main game map. // If it's some local map instance, the coordinates will most likely not even match. return ( !g || &get_map() != this || !creatures.creature_at( p ) ) && tmp.can_move_to( p ); }; - const auto place_it = [&]( const tripoint & p ) { + const auto place_it = [&]( const tripoint_bub_ms & p ) { monster *const placed = g->place_critter_at( make_shared_fast( tmp ), p ); if( !i.data.patrol_points_rel_ms.empty() ) { placed->set_patrol_route( i.data.patrol_points_rel_ms ); @@ -9118,7 +9125,7 @@ void map::spawn_monsters_submap( const tripoint &gp, bool ignore_sight, bool spa // then fall back to picking a random point that is a valid location. if( valid_location( center ) ) { place_it( center ); - } else if( const std::optional pos = random_point( points, valid_location ) ) { + } else if( const std::optional pos = random_point( points, valid_location ) ) { place_it( *pos ); } } @@ -9130,10 +9137,10 @@ void map::spawn_monsters( bool ignore_sight, bool spawn_nonlocal ) { const int zmin = zlevels ? -OVERMAP_DEPTH : abs_sub.z(); const int zmax = zlevels ? OVERMAP_HEIGHT : abs_sub.z(); - tripoint gp; - int &gx = gp.x; - int &gy = gp.y; - int &gz = gp.z; + tripoint_rel_sm gp; + int &gx = gp.x(); + int &gy = gp.y(); + int &gz = gp.z(); for( gz = zmin; gz <= zmax; gz++ ) { for( gx = 0; gx < my_MAPSIZE; gx++ ) { for( gy = 0; gy < my_MAPSIZE; gy++ ) { @@ -9155,7 +9162,7 @@ void map::clear_traps() for( submap *&smap : grid ) { for( int x = 0; x < SEEX; x++ ) { for( int y = 0; y < SEEY; y++ ) { - const point p( x, y ); + const point_sm_ms p( x, y ); smap->set_trap( p, tr_null ); } } @@ -9312,10 +9319,10 @@ void map::set_graffiti( const tripoint &p, const std::string &contents ) if( !inbounds( p ) ) { return; } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to set graffiti at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to set graffiti at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } current_submap->set_graffiti( l, contents ); @@ -9326,55 +9333,55 @@ void map::delete_graffiti( const tripoint &p ) if( !inbounds( p ) ) { return; } - point l; - submap *const current_submap = unsafe_get_submap_at( p, l ); + point_sm_ms l; + submap *const current_submap = unsafe_get_submap_at( tripoint_bub_ms( p ), l ); if( current_submap == nullptr ) { - debugmsg( "Tried to delete graffiti at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to delete graffiti at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; } current_submap->delete_graffiti( l ); } const std::string &map::graffiti_at( const tripoint &p ) const +{ + return map::graffiti_at( tripoint_bub_ms( p ) ); +} + +const std::string &map::graffiti_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { static const std::string empty_string; return empty_string; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get graffiti at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get graffiti at (%d,%d) but the submap is not loaded", l.x(), l.y() ); static const std::string empty_string; return empty_string; } return current_submap->get_graffiti( l ); } -const std::string &map::graffiti_at( const tripoint_bub_ms &p ) const +bool map::has_graffiti_at( const tripoint &p ) const { - return map::graffiti_at( p.raw() ); + return map::has_graffiti_at( tripoint_bub_ms( p ) ); } -bool map::has_graffiti_at( const tripoint &p ) const +bool map::has_graffiti_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { return false; } - point l; + point_sm_ms l; const submap *const current_submap = unsafe_get_submap_at( p, l ); if( current_submap == nullptr ) { - debugmsg( "Tried to get graffiti at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to get graffiti at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return false; } return current_submap->has_graffiti( l ); } -bool map::has_graffiti_at( const tripoint_bub_ms &p ) const -{ - return map::has_graffiti_at( p.raw() ); -} - int map::determine_wall_corner( const tripoint &p ) const { const std::bitset &test_connect_group = ter( p ).obj().connect_to_groups; @@ -9451,7 +9458,7 @@ void map::build_outside_cache( const int zlev ) for( int smx = 0; smx < my_MAPSIZE; ++smx ) { for( int smy = 0; smy < my_MAPSIZE; ++smy ) { - const submap *cur_submap = get_submap_at_grid( { smx, smy, zlev } ); + const submap *cur_submap = get_submap_at_grid( tripoint_rel_sm{ smx, smy, zlev } ); if( cur_submap == nullptr ) { debugmsg( "Tried to build outside cache at (%d,%d,%d) but the submap is not loaded", smx, smy, zlev ); @@ -9460,7 +9467,7 @@ void map::build_outside_cache( const int zlev ) for( int sx = 0; sx < SEEX; ++sx ) { for( int sy = 0; sy < SEEY; ++sy ) { - point sp( sx, sy ); + point_sm_ms sp( sx, sy ); if( cur_submap->get_ter( sp ).obj().has_flag( ter_furn_flag::TFLAG_INDOORS ) || cur_submap->get_furn( sp ).obj().has_flag( ter_furn_flag::TFLAG_INDOORS ) ) { const point p( sx + smx * SEEX, sy + smy * SEEY ); @@ -9498,7 +9505,7 @@ void map::build_obstacle_cache( // TODO: Support z-levels. for( int smx = min_submap.x; smx <= max_submap.x; ++smx ) { for( int smy = min_submap.y; smy <= max_submap.y; ++smy ) { - const submap *cur_submap = get_submap_at_grid( { smx, smy, start.z } ); + const submap *cur_submap = get_submap_at_grid( tripoint_rel_sm{ smx, smy, start.z } ); if( cur_submap == nullptr ) { debugmsg( "Tried to build obstacle cache at (%d,%d,%d) but the submap is not loaded", smx, smy, start.z ); @@ -9508,7 +9515,7 @@ void map::build_obstacle_cache( // TODO: Init indices to prevent iterating over unused submap sections. for( int sx = 0; sx < SEEX; ++sx ) { for( int sy = 0; sy < SEEY; ++sy ) { - const point sp( sx, sy ); + const point_sm_ms sp( sx, sy ); int ter_move = cur_submap->get_ter( sp ).obj().movecost; int furn_move = cur_submap->get_furn( sp ).obj().movecost; const point p2( sx + smx * SEEX, sy + smy * SEEY ); @@ -9601,8 +9608,9 @@ bool map::build_floor_cache( const int zlev ) for( int smx = 0; smx < my_MAPSIZE; ++smx ) { for( int smy = 0; smy < my_MAPSIZE; ++smy ) { - const submap *cur_submap = get_submap_at_grid( { smx, smy, zlev } ); - const submap *below_submap = !lowest_z_lev ? get_submap_at_grid( { smx, smy, zlev - 1 } ) : nullptr; + const submap *cur_submap = get_submap_at_grid( tripoint_rel_sm{ smx, smy, zlev } ); + const submap *below_submap = !lowest_z_lev ? get_submap_at_grid( tripoint_rel_sm{ smx, smy, zlev - 1 } ) : + nullptr; if( cur_submap == nullptr ) { debugmsg( "Tried to build floor cache at (%d,%d,%d) but the submap is not loaded", smx, smy, zlev ); @@ -9616,7 +9624,7 @@ bool map::build_floor_cache( const int zlev ) for( int sx = 0; sx < SEEX; ++sx ) { for( int sy = 0; sy < SEEY; ++sy ) { - point sp( sx, sy ); + point_sm_ms sp( sx, sy ); const ter_t &terrain = cur_submap->get_ter( sp ).obj(); if( terrain.has_flag( ter_furn_flag::TFLAG_NO_FLOOR ) || terrain.has_flag( ter_furn_flag::TFLAG_NO_FLOOR_WATER ) || @@ -9872,7 +9880,7 @@ submap *map::get_submap_at( const tripoint_bub_ms &p ) return map::get_submap_at( p.raw() ); } -const submap *map::get_submap_at( const tripoint &p ) const +const submap *map::get_submap_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { debugmsg( "Tried to access invalid map position %s", p.to_string() ); @@ -9881,30 +9889,31 @@ const submap *map::get_submap_at( const tripoint &p ) const return unsafe_get_submap_at( p ); } -submap *map::get_submap_at_grid( const tripoint &gridp ) +submap *map::get_submap_at_grid( const tripoint_rel_sm &gridp ) { return getsubmap( get_nonant( gridp ) ); } -const submap *map::get_submap_at_grid( const tripoint &gridp ) const +const submap *map::get_submap_at_grid( const tripoint_rel_sm &gridp ) const { return getsubmap( get_nonant( gridp ) ); } -size_t map::get_nonant( const tripoint &gridp ) const +size_t map::get_nonant( const tripoint_rel_sm &gridp ) const { - if( gridp.x < 0 || gridp.x >= my_MAPSIZE || - gridp.y < 0 || gridp.y >= my_MAPSIZE || - gridp.z < -OVERMAP_DEPTH || gridp.z > OVERMAP_HEIGHT ) { - debugmsg( "Tried to access invalid map position at grid (%d,%d,%d)", gridp.x, gridp.y, gridp.z ); + if( gridp.x() < 0 || gridp.x() >= my_MAPSIZE || + gridp.y() < 0 || gridp.y() >= my_MAPSIZE || + gridp.z() < -OVERMAP_DEPTH || gridp.z() > OVERMAP_HEIGHT ) { + debugmsg( "Tried to access invalid map position at grid (%d,%d,%d)", gridp.x(), gridp.y(), + gridp.z() ); return 0; } if( zlevels ) { - const int indexz = gridp.z + OVERMAP_DEPTH; // Can't be lower than 0 - return indexz + ( gridp.x + gridp.y * my_MAPSIZE ) * OVERMAP_LAYERS; + const int indexz = gridp.z() + OVERMAP_DEPTH; // Can't be lower than 0 + return indexz + ( gridp.x() + gridp.y() * my_MAPSIZE ) * OVERMAP_LAYERS; } else { - return gridp.x + gridp.y * my_MAPSIZE; + return gridp.x() + gridp.y() * my_MAPSIZE; } } @@ -9935,7 +9944,7 @@ void map::draw_fill_background( const ter_id &type ) // Fill each submap rather than each tile for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) { for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { - submap *sm = get_submap_at_grid( {gridx, gridy} ); + submap *sm = get_submap_at_grid( point{gridx, gridy} ); if( sm == nullptr ) { debugmsg( "Tried to fill background at (%d,%d) but the submap is not loaded", gridx, gridy ); continue; @@ -10193,9 +10202,9 @@ void map::function_over( const tripoint &start, const tripoint &end, Functor fun const point sm_max( smx < max_sm.x ? SEEX - 1 : max.x % SEEX, smy < max_sm.y ? SEEY - 1 : max.y % SEEY ); - point lp; - int &sx = lp.x; - int &sy = lp.y; + point_sm_ms lp; + int &sx = lp.x(); + int &sy = lp.y(); for( sx = sm_min.x; sx <= sm_max.x; ++sx ) { for( sy = sm_min.y; sy <= sm_max.y; ++sy ) { const iteration_state rval = fun( gp, cur_submap, lp ); @@ -10226,19 +10235,19 @@ void map::scent_blockers( std::array, MAPSIZE_Y> &bl { ter_furn_flag reduce = ter_furn_flag::TFLAG_REDUCE_SCENT; ter_furn_flag block = ter_furn_flag::TFLAG_NO_SCENT; - auto fill_values = [&]( const tripoint & gp, const submap * sm, const point & lp ) { + auto fill_values = [&]( const tripoint & gp, const submap * sm, const point_sm_ms & lp ) { // We need to generate the x/y coordinates, because we can't get them "for free" - const point p = lp + sm_to_ms_copy( gp.xy() ); + const point_sm_ms p = lp + sm_to_ms_copy( gp.xy() ); if( sm->get_ter( lp ).obj().has_flag( block ) ) { - blocks_scent[p.x][p.y] = true; - reduces_scent[p.x][p.y] = false; + blocks_scent[p.x()][p.y()] = true; + reduces_scent[p.x()][p.y()] = false; } else if( sm->get_ter( lp ).obj().has_flag( reduce ) || sm->get_furn( lp ).obj().has_flag( reduce ) ) { - blocks_scent[p.x][p.y] = false; - reduces_scent[p.x][p.y] = true; + blocks_scent[p.x()][p.y()] = false; + reduces_scent[p.x()][p.y()] = true; } else { - blocks_scent[p.x][p.y] = false; - reduces_scent[p.x][p.y] = false; + blocks_scent[p.x()][p.y()] = false; + reduces_scent[p.x()][p.y()] = false; } return ITER_CONTINUE; @@ -10347,31 +10356,30 @@ std::list map::get_active_items_in_radius( const tripoint ¢er std::min( maxp.y / SEEY, my_MAPSIZE - 1 ) ); for( const tripoint_abs_sm &abs_submap_loc : submaps_with_active_items ) { - // TODO: fix point types - const tripoint submap_loc = ( abs_submap_loc - abs_sub.xy() ).raw(); - if( submap_loc.x < ming.x || submap_loc.y < ming.y || - submap_loc.x > maxg.x || submap_loc.y > maxg.y ) { + const tripoint_rel_sm submap_loc = ( abs_submap_loc - abs_sub.xy() ); + if( submap_loc.x() < ming.x || submap_loc.y() < ming.y || + submap_loc.x() > maxg.x || submap_loc.y() > maxg.y ) { continue; } - const point sm_offset( submap_loc.x * SEEX, submap_loc.y * SEEY ); + const point_rel_ms sm_offset( submap_loc.x() * SEEX, submap_loc.y() * SEEY ); submap *sm = get_submap_at_grid( submap_loc ); if( sm == nullptr ) { debugmsg( "Tried get active items in radius of (%d,%d,%d) but the submap is not loaded", - submap_loc.x, submap_loc.y, submap_loc.z ); + submap_loc.x(), submap_loc.y(), submap_loc.z() ); continue; } std::vector items = type == special_item_type::none ? sm->active_items.get() : sm->active_items.get_special( type ); for( const item_reference &elem : items ) { - const tripoint pos( sm_offset + elem.location.raw(), submap_loc.z ); + const tripoint_rel_ms pos( sm_offset + elem.location, submap_loc.z() ); - if( rl_dist( pos, center ) > radius ) { + if( rl_dist( pos.raw(), center ) > radius ) { continue; } if( elem.item_ref ) { - result.emplace_back( map_cursor( tripoint_bub_ms( pos ) ), elem.item_ref.get() ); + result.emplace_back( map_cursor( rebase_bub( pos ) ), elem.item_ref.get() ); } } } @@ -10659,7 +10667,7 @@ int map::calc_max_populated_zlev() bool level_done = false; for( int sx = 0; sx < my_MAPSIZE; sx++ ) { for( int sy = 0; sy < my_MAPSIZE; sy++ ) { - const submap *sm = get_submap_at_grid( tripoint( sx, sy, sz ) ); + const submap *sm = get_submap_at_grid( { sx, sy, sz } ); if( sm == nullptr ) { debugmsg( "Tried to calc max populated zlev at (%d,%d,%d) but the submap is not loaded", sx, sy, sz ); diff --git a/src/map.h b/src/map.h index def2f349e1172..870b3c9b9344d 100644 --- a/src/map.h +++ b/src/map.h @@ -1859,7 +1859,9 @@ class map // TODO: Get rid of untyped overload bool has_floor( const tripoint &p ) const; bool has_floor( const tripoint_bub_ms &p ) const; + // TODO: Get rid of untyped overload bool has_floor_or_water( const tripoint &p ) const; + bool has_floor_or_water( const tripoint_bub_ms &p ) const; /** Does this tile support vehicles and furniture above it */ bool supports_above( const tripoint &p ) const; bool has_floor_or_support( const tripoint &p ) const; @@ -2075,9 +2077,10 @@ class map void rotten_item_spawn( const item &item, const tripoint &p ); private: // Helper #1 - spawns monsters on one submap - void spawn_monsters_submap( const tripoint &gp, bool ignore_sight, bool spawn_nonlocal = false ); + void spawn_monsters_submap( const tripoint_rel_sm &gp, bool ignore_sight, + bool spawn_nonlocal = false ); // Helper #2 - spawns monsters on one submap and from one group on this submap - void spawn_monsters_submap_group( const tripoint &gp, mongroup &group, + void spawn_monsters_submap_group( const tripoint_rel_sm &gp, mongroup &group, bool ignore_sight ); protected: @@ -2087,11 +2090,11 @@ class map * Fast forward a submap that has just been loading into this map. * This is used to rot and remove rotten items, grow plants, fill funnels etc. */ - void actualize( const tripoint &grid ); + void actualize( const tripoint_rel_sm &grid ); /** * Hacks in missing roofs. Should be removed when 3D mapgen is done. */ - void add_roofs( const tripoint &grid ); + void add_roofs( const tripoint_rel_sm &grid ); /** * Try to fill funnel based items here. Simulates rain from @p since till now. * @param p The location in this map where to fill funnels. @@ -2136,7 +2139,7 @@ class map */ void shift_traps( const tripoint &shift ); - void copy_grid( const tripoint &to, const tripoint &from ); + void copy_grid( const tripoint_rel_sm &to, const tripoint_rel_sm &from ); void draw_map( mapgendata &dat ); void draw_lab( mapgendata &dat ); @@ -2203,7 +2206,7 @@ class map // TODO: fix point types (remove the first overload) inline submap *unsafe_get_submap_at( const tripoint &p ) { cata_assert( inbounds( p ) ); - return get_submap_at_grid( { p.x / SEEX, p.y / SEEY, p.z } ); + return get_submap_at_grid( tripoint_rel_sm{ p.x / SEEX, p.y / SEEY, p.z } ); } inline submap *unsafe_get_submap_at( const tripoint_bub_ms &p ) { return unsafe_get_submap_at( p.raw() ); @@ -2219,7 +2222,7 @@ class map // TODO: Get rid of untyped overload submap *get_submap_at( const tripoint &p ); submap *get_submap_at( const tripoint_bub_ms &p ); - const submap *get_submap_at( const tripoint &p ) const; + const submap *get_submap_at( const tripoint_bub_ms &p ) const; submap *get_submap_at( const point &p ) { return get_submap_at( tripoint( p, abs_sub.z() ) ); } @@ -2266,9 +2269,9 @@ class map offset_p.y() = p.y() % SEEY; return get_submap_at( p ); } - const submap *get_submap_at( const tripoint &p, point &offset_p ) const { - offset_p.x = p.x % SEEX; - offset_p.y = p.y % SEEY; + const submap *get_submap_at( const tripoint_bub_ms &p, point_sm_ms &offset_p ) const { + offset_p.x() = p.x() % SEEX; + offset_p.y() = p.y() % SEEY; return get_submap_at( p ); } submap *get_submap_at( const point &p, point &offset_p ) { @@ -2285,17 +2288,17 @@ class map const submap *get_submap_at_grid( const point &gridp ) const { return getsubmap( get_nonant( gridp ) ); } - submap *get_submap_at_grid( const tripoint &gridp ); - const submap *get_submap_at_grid( const tripoint &gridp ) const; + submap *get_submap_at_grid( const tripoint_rel_sm &gridp ); + const submap *get_submap_at_grid( const tripoint_rel_sm &gridp ) const; protected: /** * Get the index of a submap pointer in the grid given by grid coordinates. The grid * coordinates must be valid: 0 <= x < my_MAPSIZE, same for y. * Version with z-levels checks for z between -OVERMAP_DEPTH and OVERMAP_HEIGHT */ - size_t get_nonant( const tripoint &gridp ) const; + size_t get_nonant( const tripoint_rel_sm &gridp ) const; size_t get_nonant( const point &gridp ) const { - return get_nonant( { gridp, abs_sub.z() } ); + return get_nonant( tripoint_rel_sm{ gridp.x, gridp.y, abs_sub.z() } ); } /** * Set the submap pointer in @ref grid at the give index. This is the inverse of @@ -2369,7 +2372,7 @@ class map void process_items(); private: // Iterates over every item on the map, passing each item to the provided function. - void process_items_in_submap( submap ¤t_submap, const tripoint &gridp ); + void process_items_in_submap( submap ¤t_submap, const tripoint_rel_sm &gridp ); void process_items_in_vehicles( submap ¤t_submap ); void process_items_in_vehicle( vehicle &cur_veh, submap ¤t_submap ); diff --git a/src/map_field.cpp b/src/map_field.cpp index eb59434d97251..47e872085b41c 100644 --- a/src/map_field.cpp +++ b/src/map_field.cpp @@ -427,9 +427,9 @@ void map::process_fields_in_submap( submap *const current_submap, scent_block sblk( submap, get_scent() ); // Initialize the map tile wrapper - maptile map_tile( current_submap, point_zero ); - int &locx = map_tile.pos_.x; - int &locy = map_tile.pos_.y; + maptile map_tile( current_submap, point_sm_ms_zero ); + int &locx = map_tile.pos_.x(); + int &locy = map_tile.pos_.y(); const point sm_offset = sm_to_ms_copy( submap.xy() ); field_proc_data pd{ @@ -456,7 +456,7 @@ void map::process_fields_in_submap( submap *const current_submap, } // This is a translation from local coordinates to submap coordinates. - const tripoint p = tripoint( map_tile.pos() + sm_offset, submap.z ); + const tripoint_sm_ms p = tripoint_sm_ms( map_tile.pos() + sm_offset, submap.z ); for( auto it = curfield.begin(); it != curfield.end(); ) { // Iterating through all field effects in the submap's field. @@ -468,7 +468,7 @@ void map::process_fields_in_submap( submap *const current_submap, // The field might have been killed by processing a neighbor field if( prev_intensity == 0 ) { - on_field_modified( p, *pd.cur_fd_type ); + on_field_modified( p.raw(), *pd.cur_fd_type ); --current_submap->field_count; curfield.remove_field( it++ ); continue; @@ -478,19 +478,19 @@ void map::process_fields_in_submap( submap *const current_submap, if( cur.get_field_age() == 0_turns ) { cur.do_decay(); if( !cur.is_field_alive() || cur.get_field_intensity() != prev_intensity ) { - on_field_modified( p, *pd.cur_fd_type ); + on_field_modified( p.raw(), *pd.cur_fd_type ); } it++; continue; } for( const FieldProcessorPtr &proc : pd.cur_fd_type->get_processors() ) { - proc( p, cur, pd ); + proc( p.raw(), cur, pd ); } cur.do_decay(); if( !cur.is_field_alive() || cur.get_field_intensity() != prev_intensity ) { - on_field_modified( p, *pd.cur_fd_type ); + on_field_modified( p.raw(), *pd.cur_fd_type ); } it++; } @@ -1146,9 +1146,9 @@ void field_processor_fd_fire( const tripoint &p, field_entry &cur, field_proc_da count != neighs.size(); i = ( i + 1 ) % neighs.size(), count++ ) { const maptile &neigh = neighs[i].second; - if( ( neigh.pos().x != remove_tile.pos().x && neigh.pos().y != remove_tile.pos().y ) || - ( neigh.pos().x != remove_tile2.pos().x && neigh.pos().y != remove_tile2.pos().y ) || - ( neigh.pos().x != remove_tile3.pos().x && neigh.pos().y != remove_tile3.pos().y ) || + if( ( neigh.pos().x() != remove_tile.pos().x() && neigh.pos().y() != remove_tile.pos().y() ) || + ( neigh.pos().x() != remove_tile2.pos().x() && neigh.pos().y() != remove_tile2.pos().y() ) || + ( neigh.pos().x() != remove_tile3.pos().x() && neigh.pos().y() != remove_tile3.pos().y() ) || x_in_y( 1, std::max( 2, windpower ) ) ) { neighbour_vec.push_back( i ); } diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 904c46f48c958..b3b855c44382f 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -232,7 +232,7 @@ void map::generate( const tripoint_abs_omt &p, const time_point &when, bool save for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) { for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) { - const tripoint pos( gridx, gridy, gridz ); + const tripoint_rel_sm pos( gridx, gridy, gridz ); const size_t grid_pos = get_nonant( pos ); if( !save_results || MAPBUFFER.lookup_submap( p_sm_base.xy() + pos ) == nullptr ) { setsubmap( grid_pos, new submap() ); @@ -270,7 +270,7 @@ void map::generate( const tripoint_abs_omt &p, const time_point &when, bool save for( int gridx = 0; gridx <= 1; gridx++ ) { for( int gridy = 0; gridy <= 1; gridy++ ) { - const tripoint pos( gridx, gridy, gridz ); + const tripoint_rel_sm pos( gridx, gridy, gridz ); const size_t grid_pos = get_nonant( pos ); if( ( !save_results || MAPBUFFER.lookup_submap( p_sm_base.xy() + pos ) == nullptr ) && !getsubmap( grid_pos )->is_uniform() && @@ -308,7 +308,7 @@ void map::generate( const tripoint_abs_omt &p, const time_point &when, bool save // Merge the overlays generated earlier into the current Z level now we have the base map on it. for( int gridx = 0; gridx <= 1; gridx++ ) { for( int gridy = 0; gridy <= 1; gridy++ ) { - const tripoint pos( gridx, gridy, gridz ); + const tripoint_rel_sm pos( gridx, gridy, gridz ); const size_t index = gridx + gridy * 2; if( saved_overlay.at( index ) != nullptr ) { const size_t grid_pos = get_nonant( pos ); @@ -384,7 +384,7 @@ void map::generate( const tripoint_abs_omt &p, const time_point &when, bool save for( int gridx = 0; gridx < my_MAPSIZE; gridx++ ) { for( int gridy = 0; gridy < my_MAPSIZE; gridy++ ) { for( int gridz = -OVERMAP_DEPTH; gridz <= OVERMAP_HEIGHT; gridz++ ) { - const tripoint pos( gridx, gridy, gridz ); + const tripoint_rel_sm pos( gridx, gridy, gridz ); const size_t grid_pos = get_nonant( pos ); if( gridx <= 1 && gridy <= 1 ) { if( MAPBUFFER.lookup_submap( p_sm_base.xy() + pos ) == nullptr ) { @@ -6828,10 +6828,10 @@ void map::add_spawn( debugmsg( "Out of bounds add_spawn(%s, %d, %d, %d)", type.c_str(), count, p.x(), p.y() ); return; } - point offset; - submap *place_on_submap = get_submap_at( p.raw(), offset ); + point_sm_ms offset; + submap *place_on_submap = get_submap_at( p, offset ); if( place_on_submap == nullptr ) { - debugmsg( "Tried to add spawn at (%d,%d) but the submap is not loaded", offset.x, offset.y ); + debugmsg( "Tried to add spawn at (%d,%d) but the submap is not loaded", offset.x(), offset.y() ); return; } @@ -6877,7 +6877,7 @@ vehicle *map::add_vehicle( const vproto_id &type, const tripoint &p, const units vehicle *placed_vehicle = placed_vehicle_up.get(); if( placed_vehicle != nullptr ) { - submap *place_on_submap = get_submap_at_grid( placed_vehicle->sm_pos ); + submap *place_on_submap = get_submap_at_grid( tripoint_rel_sm( placed_vehicle->sm_pos ) ); if( place_on_submap == nullptr ) { debugmsg( "Tried to add vehicle at (%d,%d,%d) but the submap is not loaded", placed_vehicle->sm_pos.x, placed_vehicle->sm_pos.y, placed_vehicle->sm_pos.z ); @@ -7072,10 +7072,10 @@ computer *map::add_computer( const tripoint &p, const std::string &name, int sec { // TODO: Turn this off? furn_set( p, furn_f_console ); - point l; - submap *const place_on_submap = get_submap_at( p, l ); + point_sm_ms l; + submap *const place_on_submap = get_submap_at( tripoint_bub_ms( p ), l ); if( place_on_submap == nullptr ) { - debugmsg( "Tried to add computer at (%d,%d) but the submap is not loaded", l.x, l.y ); + debugmsg( "Tried to add computer at (%d,%d) but the submap is not loaded", l.x(), l.y() ); static computer null_computer = computer( name, security, p ); return &null_computer; } @@ -7158,10 +7158,10 @@ void map::rotate( int turns, const bool setpos_safe ) for( int z_level = bottom_level; z_level <= top_level; z_level++ ) { clear_vehicle_list( z_level ); - submap *pz = get_submap_at_grid( tripoint( point_zero, z_level ) ); - submap *pse = get_submap_at_grid( tripoint( point_south_east, z_level ) ); - submap *pe = get_submap_at_grid( tripoint( point_east, z_level ) ); - submap *ps = get_submap_at_grid( tripoint( point_south, z_level ) ); + submap *pz = get_submap_at_grid( { point_rel_sm_zero, z_level } ); + submap *pse = get_submap_at_grid( { point_rel_sm_south_east, z_level } ); + submap *pe = get_submap_at_grid( { point_rel_sm_east, z_level } ); + submap *ps = get_submap_at_grid( { point_rel_sm_south, z_level } ); if( pz == nullptr || pse == nullptr || pe == nullptr || ps == nullptr ) { debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", point_zero.x, point_zero.y ); @@ -7181,7 +7181,7 @@ void map::rotate( int turns, const bool setpos_safe ) for( int k = 0; k < 4; ++k ) { p = p.rotate( turns, { 2, 2 } ); point tmpp = point_south_east - p; - submap *psep = get_submap_at_grid( tripoint( tmpp, z_level ) ); + submap *psep = get_submap_at_grid( tripoint_rel_sm( tmpp.x, tmpp.y, z_level ) ); if( psep == nullptr ) { debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", tmpp.x, tmpp.y ); continue; @@ -7194,7 +7194,7 @@ void map::rotate( int turns, const bool setpos_safe ) for( int j = 0; j < 2; ++j ) { for( int i = 0; i < 2; ++i ) { point p( i, j ); - submap *sm = get_submap_at_grid( tripoint( p, z_level ) ); + submap *sm = get_submap_at_grid( tripoint_rel_sm( p.x, p.y, z_level ) ); if( sm == nullptr ) { debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", p.x, p.y ); continue; @@ -7252,10 +7252,11 @@ void map::mirror( bool mirror_horizontal, bool mirror_vertical ) for( int z_level = zlevels ? -OVERMAP_DEPTH : abs_sub.z(); z_level <= ( zlevels ? OVERMAP_HEIGHT : abs_sub.z() ); z_level++ ) { - submap *pz = get_submap_at_grid( tripoint( point_zero, z_level ) ); - submap *pse = get_submap_at_grid( tripoint( point_south_east, z_level ) ); - submap *pe = get_submap_at_grid( tripoint( point_east, z_level ) ); - submap *ps = get_submap_at_grid( tripoint( point_south, z_level ) ); + submap *pz = get_submap_at_grid( { point_rel_sm_zero, z_level } ); + submap *pse = get_submap_at_grid( { point_rel_sm_south_east, z_level } ); + submap *pe = get_submap_at_grid( {point_rel_sm_east, z_level + } ); + submap *ps = get_submap_at_grid( { point_rel_sm_south, z_level } ); if( pz == nullptr || pse == nullptr || pe == nullptr || ps == nullptr ) { debugmsg( "Tried to mirror map at (%d, %d, %d) but the submap is not loaded", point_zero.x, point_zero.y, z_level ); @@ -7275,10 +7276,11 @@ void map::mirror( bool mirror_horizontal, bool mirror_vertical ) // Then mirror them. for( int j = 0; j < 2; ++j ) { for( int i = 0; i < 2; ++i ) { - point p( i, j ); - submap *sm = get_submap_at_grid( tripoint( p, z_level ) ); + point_rel_sm p( i, j ); + submap *sm = get_submap_at_grid( { p, z_level } ); if( sm == nullptr ) { - debugmsg( "Tried to mirror map at (%d, %d, %d) but the submap is not loaded", p.x, p.y, z_level ); + debugmsg( "Tried to mirror map at (%d, %d, %d) but the submap is not loaded", p.x(), p.y(), + z_level ); continue; } diff --git a/src/monmove.cpp b/src/monmove.cpp index adf1193bbf126..9034695953503 100644 --- a/src/monmove.cpp +++ b/src/monmove.cpp @@ -285,6 +285,11 @@ bool monster::can_move_to( const tripoint &p ) const return can_reach_to( p ) && will_move_to( p ); } +bool monster::can_move_to( const tripoint_bub_ms &p ) const +{ + return monster::can_move_to( p.raw() ); +} + float monster::rate_target( Creature &c, float best, bool smart ) const { const FastDistanceApproximation d = rl_dist_fast( pos(), c.pos() ); diff --git a/src/monster.h b/src/monster.h index fe096e1577c02..ff960f64b4abd 100644 --- a/src/monster.h +++ b/src/monster.h @@ -209,7 +209,9 @@ class monster : public Creature * can_move_to() is a wrapper for both of them. * know_danger_at() checks for fire, trap etc. (flag PATH_AVOID_) */ + // TODO: Get rid of untyped overload bool can_move_to( const tripoint &p ) const; + bool can_move_to( const tripoint_bub_ms &p ) const; bool can_reach_to( const tripoint &p ) const; bool will_move_to( const tripoint &p ) const; bool know_danger_at( const tripoint &p ) const; diff --git a/src/savegame.cpp b/src/savegame.cpp index e73f86730baa4..0ef732a6e23ee 100644 --- a/src/savegame.cpp +++ b/src/savegame.cpp @@ -1537,7 +1537,7 @@ void timed_event_manager::unserialize_all( const JsonArray &ja ) jo.read( "type", type ); jo.read( "when", when ); jo.read( "key", key ); - point pt; + point_sm_ms pt; if( jo.has_string( "revert" ) ) { revert.set_all_ter( ter_id( jo.get_string( "revert" ) ), true ); } else { @@ -1555,9 +1555,9 @@ void timed_event_manager::unserialize_all( const JsonArray &ja ) } // We didn't always save the point, this is the original logic, it doesn't work right but for older saves at least they won't crash if( !jp.has_member( "point" ) ) { - if( pt.x++ < SEEX ) { - pt.x = 0; - pt.y++; + if( pt.x()++ < SEEX ) { + pt.x() = 0; + pt.y()++; } } } @@ -1636,14 +1636,14 @@ void timed_event_manager::serialize_all( JsonOut &jsout ) jsout.member( "when", elem.when ); jsout.member( "key", elem.key ); if( elem.revert.is_uniform() ) { - jsout.member( "revert", elem.revert.get_ter( point_zero ) ); + jsout.member( "revert", elem.revert.get_ter( point_sm_ms_zero ) ); } else { jsout.member( "revert" ); jsout.start_array(); for( int y = 0; y < SEEY; y++ ) { for( int x = 0; x < SEEX; x++ ) { jsout.start_object(); - point pt( x, y ); + point_sm_ms pt( x, y ); jsout.member( "point", pt ); jsout.member( "furn", elem.revert.get_furn( pt ) ); jsout.member( "ter", elem.revert.get_ter( pt ) ); diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index 48d15efd30ec4..880791a7d06e4 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -4703,7 +4703,7 @@ void submap::store( JsonOut &jsout ) const int count = 0; for( int j = 0; j < SEEY; j++ ) { for( int i = 0; i < SEEX; i++ ) { - const point p( i, j ); + const point_sm_ms p( i, j ); // Save radiation, re-examine this because it doesn't look like it works right int r = get_radiation( p ); if( r == lastrad ) { @@ -4725,12 +4725,12 @@ void submap::store( JsonOut &jsout ) const jsout.start_array(); for( int j = 0; j < SEEY; j++ ) { for( int i = 0; i < SEEX; i++ ) { - const point p( i, j ); + const point_sm_ms p( i, j ); // Save furniture if( get_furn( p ) ) { jsout.start_array(); - jsout.write( p.x ); - jsout.write( p.y ); + jsout.write( p.x() ); + jsout.write( p.y() ); jsout.write( get_furn( p ).obj().id ); jsout.end_array(); } @@ -4756,12 +4756,12 @@ void submap::store( JsonOut &jsout ) const jsout.start_array(); for( int j = 0; j < SEEY; j++ ) { for( int i = 0; i < SEEX; i++ ) { - const point p( i, j ); + const point_sm_ms p( i, j ); // Save traps if( get_trap( p ) ) { jsout.start_array(); - jsout.write( p.x ); - jsout.write( p.y ); + jsout.write( p.x() ); + jsout.write( p.y() ); const trap_id &trap_at = get_trap( p ); // TODO: jsout should support writing an id like jsout.write( trap_id ) jsout.write( trap_at.id().str() ); @@ -4798,8 +4798,8 @@ void submap::store( JsonOut &jsout ) const jsout.start_array(); for( const submap::cosmetic_t &cosm : cosmetics ) { jsout.start_array(); - jsout.write( cosm.pos.x ); - jsout.write( cosm.pos.y ); + jsout.write( cosm.pos.x() ); + jsout.write( cosm.pos.y() ); jsout.write( cosm.type ); jsout.write( cosm.str ); jsout.end_array(); @@ -4814,8 +4814,8 @@ void submap::store( JsonOut &jsout ) const // TODO: json should know how to write string_ids jsout.write( elem.type.str() ); jsout.write( elem.count ); - jsout.write( elem.pos.x ); - jsout.write( elem.pos.y ); + jsout.write( elem.pos.x() ); + jsout.write( elem.pos.y() ); jsout.write( elem.faction_id ); jsout.write( elem.mission_id ); jsout.write( elem.friendly ); @@ -5000,13 +5000,13 @@ void submap::load( const JsonValue &jv, const std::string &member_name, int vers while( items_json.has_more() ) { int i = items_json.next_int(); int j = items_json.next_int(); - const point p( i, j ); + const point_sm_ms p( i, j ); - if( !items_json.next_value().read( m->itm[p.x][p.y], false ) ) { + if( !items_json.next_value().read( m->itm[p.x()][p.y()], false ) ) { debugmsg( "Items array is corrupt in submap at: %s, skipping", p.to_string() ); } // some portion could've been read even if error occurred - for( item &it : m->itm[p.x][p.y] ) { + for( item &it : m->itm[p.x()][p.y()] ) { if( it.is_emissive() ) { update_lum_add( p, it ); } @@ -5066,7 +5066,7 @@ void submap::load( const JsonValue &jv, const std::string &member_name, int vers for( JsonArray graffiti_entry : graffiti_json ) { int i = graffiti_entry.next_int(); int j = graffiti_entry.next_int(); - const point p( i, j ); + const point_sm_ms p( i, j ); set_graffiti( p, graffiti_entry.next_string() ); if( graffiti_entry.size() > 3 ) { graffiti_entry.throw_error( "Too many values for graffiti" ); @@ -5079,7 +5079,7 @@ void submap::load( const JsonValue &jv, const std::string &member_name, int vers for( JsonArray cosmetic_entry : cosmetics_json ) { int i = cosmetic_entry.next_int(); int j = cosmetic_entry.next_int(); - const point p( i, j ); + const point_sm_ms p( i, j ); std::string type; std::string str; JsonValue cosmetic_value = cosmetic_entry.next_value(); @@ -5117,7 +5117,7 @@ void submap::load( const JsonValue &jv, const std::string &member_name, int vers if( spawn_entry.has_more() ) { spawn_entry.throw_error( "Too many values for spawn" ); } - spawn_point tmp( type, count, p, faction_id, mission_id, friendly, name ); + spawn_point tmp( type, count, point_sm_ms( p ), faction_id, mission_id, friendly, name ); spawns.push_back( tmp ); } } else if( member_name == "vehicles" ) { diff --git a/src/submap.cpp b/src/submap.cpp index c6adaf5ba011d..72b30b994f507 100644 --- a/src/submap.cpp +++ b/src/submap.cpp @@ -19,15 +19,15 @@ static const furn_str_id furn_f_console( "f_console" ); static const trap_str_id tr_ledge( "tr_ledge" ); -void maptile_soa::swap_soa_tile( const point &p1, const point &p2 ) +void maptile_soa::swap_soa_tile( const point_sm_ms &p1, const point_sm_ms &p2 ) { - std::swap( ter[p1.x][p1.y], ter[p2.x][p2.y] ); - std::swap( frn[p1.x][p1.y], frn[p2.x][p2.y] ); - std::swap( lum[p1.x][p1.y], lum[p2.x][p2.y] ); - std::swap( itm[p1.x][p1.y], itm[p2.x][p2.y] ); - std::swap( fld[p1.x][p1.y], fld[p2.x][p2.y] ); - std::swap( trp[p1.x][p1.y], trp[p2.x][p2.y] ); - std::swap( rad[p1.x][p1.y], rad[p2.x][p2.y] ); + std::swap( ter[p1.x()][p1.y()], ter[p2.x()][p2.y()] ); + std::swap( frn[p1.x()][p1.y()], frn[p2.x()][p2.y()] ); + std::swap( lum[p1.x()][p1.y()], lum[p2.x()][p2.y()] ); + std::swap( itm[p1.x()][p1.y()], itm[p2.x()][p2.y()] ); + std::swap( fld[p1.x()][p1.y()], fld[p2.x()][p2.y()] ); + std::swap( trp[p1.x()][p1.y()], trp[p2.x()][p2.y()] ); + std::swap( rad[p1.x()][p1.y()], rad[p2.x()][p2.y()] ); } submap::submap( submap && ) noexcept( map_is_noexcept ) = default; @@ -35,7 +35,7 @@ submap::~submap() = default; submap &submap::operator=( submap && ) noexcept = default; -void submap::clear_fields( const point &p ) +void submap::clear_fields( const point_sm_ms &p ) { field &f = get_field( p ); field_count -= f.field_count(); @@ -59,7 +59,7 @@ static cosmetic_find_result make_result( bool b, int ndx ) return result; } static cosmetic_find_result find_cosmetic( - const std::vector &cosmetics, const point &p, const std::string &type ) + const std::vector &cosmetics, const point_sm_ms &p, const std::string &type ) { for( size_t i = 0; i < cosmetics.size(); ++i ) { if( cosmetics[i].pos == p && cosmetics[i].type == type ) { @@ -69,12 +69,12 @@ static cosmetic_find_result find_cosmetic( return make_result( false, -1 ); } -bool submap::has_graffiti( const point &p ) const +bool submap::has_graffiti( const point_sm_ms &p ) const { return find_cosmetic( cosmetics, p, COSMETICS_GRAFFITI ).result; } -const std::string &submap::get_graffiti( const point &p ) const +const std::string &submap::get_graffiti( const point_sm_ms &p ) const { const cosmetic_find_result fresult = find_cosmetic( cosmetics, p, COSMETICS_GRAFFITI ); if( fresult.result ) { @@ -83,7 +83,7 @@ const std::string &submap::get_graffiti( const point &p ) const return STRING_EMPTY; } -void submap::set_graffiti( const point &p, const std::string &new_graffiti ) +void submap::set_graffiti( const point_sm_ms &p, const std::string &new_graffiti ) { ensure_nonuniform(); // Find signage at p if available @@ -95,7 +95,7 @@ void submap::set_graffiti( const point &p, const std::string &new_graffiti ) } } -void submap::delete_graffiti( const point &p ) +void submap::delete_graffiti( const point_sm_ms &p ) { const cosmetic_find_result fresult = find_cosmetic( cosmetics, p, COSMETICS_GRAFFITI ); if( fresult.result ) { @@ -104,17 +104,17 @@ void submap::delete_graffiti( const point &p ) cosmetics.pop_back(); } } -bool submap::has_signage( const point &p ) const +bool submap::has_signage( const point_sm_ms &p ) const { - if( !is_uniform() && m->frn[p.x][p.y].obj().has_flag( ter_furn_flag::TFLAG_SIGN ) ) { + if( !is_uniform() && m->frn[p.x()][p.y()].obj().has_flag( ter_furn_flag::TFLAG_SIGN ) ) { return find_cosmetic( cosmetics, p, COSMETICS_SIGNAGE ).result; } return false; } -std::string submap::get_signage( const point &p ) const +std::string submap::get_signage( const point_sm_ms &p ) const { - if( !is_uniform() && m->frn[p.x][p.y].obj().has_flag( ter_furn_flag::TFLAG_SIGN ) ) { + if( !is_uniform() && m->frn[p.x()][p.y()].obj().has_flag( ter_furn_flag::TFLAG_SIGN ) ) { const cosmetic_find_result fresult = find_cosmetic( cosmetics, p, COSMETICS_SIGNAGE ); if( fresult.result ) { return cosmetics[ fresult.ndx ].str; @@ -123,7 +123,7 @@ std::string submap::get_signage( const point &p ) const return STRING_EMPTY; } -void submap::set_signage( const point &p, const std::string &s ) +void submap::set_signage( const point_sm_ms &p, const std::string &s ) { ensure_nonuniform(); // Find signage at p if available @@ -134,7 +134,7 @@ void submap::set_signage( const point &p, const std::string &s ) insert_cosmetic( p, COSMETICS_SIGNAGE, s ); } } -void submap::delete_signage( const point &p ) +void submap::delete_signage( const point_sm_ms &p ) { const cosmetic_find_result fresult = find_cosmetic( cosmetics, p, COSMETICS_SIGNAGE ); if( fresult.result ) { @@ -144,12 +144,12 @@ void submap::delete_signage( const point &p ) } } -bool submap::has_computer( const point &p ) const +bool submap::has_computer( const point_sm_ms &p ) const { return !is_uniform() && computers.find( p ) != computers.end(); } -const computer *submap::get_computer( const point &p ) const +const computer *submap::get_computer( const point_sm_ms &p ) const { // the returned object will not get modified (should not, at least), so we // don't yet need to update to std::map @@ -160,7 +160,7 @@ const computer *submap::get_computer( const point &p ) const return nullptr; } -computer *submap::get_computer( const point &p ) +computer *submap::get_computer( const point_sm_ms &p ) { const auto it = computers.find( p ); if( it != computers.end() ) { @@ -169,12 +169,7 @@ computer *submap::get_computer( const point &p ) return nullptr; } -computer *submap::get_computer( const point_sm_ms &p ) -{ - return submap::get_computer( p.raw() ); -} - -void submap::set_computer( const point &p, const computer &c ) +void submap::set_computer( const point_sm_ms &p, const computer &c ) { const auto it = computers.find( p ); if( it != computers.end() ) { @@ -184,7 +179,7 @@ void submap::set_computer( const point &p, const computer &c ) } } -void submap::delete_computer( const point &p ) +void submap::delete_computer( const point_sm_ms &p ) { computers.erase( p ); } @@ -199,7 +194,7 @@ bool submap::contains_vehicle( vehicle *veh ) return match != vehicles.end(); } -bool submap::is_open_air( const point &p ) const +bool submap::is_open_air( const point_sm_ms &p ) const { ter_id t = get_ter( p ); return t->trap == tr_ledge; @@ -227,26 +222,26 @@ void submap::rotate( int turns ) // Swap horizontal stripes. for( int j = 0, je = SEEY / 2; j < je; ++j ) { for( int i = j, ie = SEEX - j; i < ie; ++i ) { - m->swap_soa_tile( { i, j }, rotate_point( { i, j } ) ); + m->swap_soa_tile( { i, j }, point_sm_ms( rotate_point( { i, j } ) ) ); } } // Swap vertical stripes so that they don't overlap with // the already swapped horizontals. for( int i = 0, ie = SEEX / 2; i < ie; ++i ) { for( int j = i + 1, je = SEEY - i - 1; j < je; ++j ) { - m->swap_soa_tile( { i, j }, rotate_point( { i, j } ) ); + m->swap_soa_tile( { i, j }, point_sm_ms( rotate_point( { i, j } ) ) ); } } } else { for( int j = 0, je = SEEY / 2; j < je; ++j ) { for( int i = j, ie = SEEX - j - 1; i < ie; ++i ) { - point p = point{ i, j }; - point pp = p; + point_sm_ms p = point_sm_ms{ i, j }; + point_sm_ms pp = p; // three swaps are enough to perform the circular shift of four elements: // 0123 -> 3120 -> 3102 -> 3012 for( int k = 0; k < 3; ++k ) { p = pp; - pp = rotate_point_ccw( pp ); + pp = point_sm_ms( rotate_point_ccw( pp.raw() ) ); m->swap_soa_tile( p, pp ); } } @@ -256,17 +251,17 @@ void submap::rotate( int turns ) active_items.rotate_locations( turns, { SEEX, SEEY } ); for( submap::cosmetic_t &elem : cosmetics ) { - elem.pos = rotate_point( elem.pos ); + elem.pos = point_sm_ms( rotate_point( elem.pos.raw() ) ); } for( spawn_point &elem : spawns ) { - elem.pos = rotate_point( elem.pos ); + elem.pos = point_sm_ms( rotate_point( elem.pos.raw() ) ); } for( auto &elem : vehicles ) { - const point new_pos = rotate_point( elem->pos ); + const point_sm_ms new_pos = point_sm_ms( rotate_point( elem->pos ) ); - elem->pos = new_pos; + elem->pos = new_pos.raw(); // turn the steering wheel, vehicle::turn does not actually // move the vehicle. elem->turn( turns * 90_degrees ); @@ -275,9 +270,9 @@ void submap::rotate( int turns ) elem->precalc_mounts( 0, elem->turn_dir, elem->pivot_anchor[0] ); } - std::map rot_comp; + std::map rot_comp; for( auto &elem : computers ) { - rot_comp.emplace( rotate_point( elem.first ), elem.second ); + rot_comp.emplace( rotate_point( elem.first.raw() ), elem.second ); } computers = rot_comp; } @@ -287,7 +282,7 @@ void submap::mirror( bool horizontally ) if( is_uniform() ) { return; } - std::map mirror_comp; + std::map mirror_comp; if( horizontally ) { for( int i = 0, ie = SEEX / 2; i < ie; i++ ) { @@ -297,13 +292,13 @@ void submap::mirror( bool horizontally ) } for( submap::cosmetic_t &elem : cosmetics ) { - elem.pos = point( -elem.pos.x, elem.pos.y ) + point( SEEX - 1, 0 ); + elem.pos = point_sm_ms( -elem.pos.x(), elem.pos.y() ) + point( SEEX - 1, 0 ); } active_items.mirror( { SEEX, SEEY }, true ); for( auto &elem : computers ) { - mirror_comp.emplace( point( -elem.first.x, elem.first.y ) + point( SEEX - 1, 0 ), elem.second ); + mirror_comp.emplace( point( -elem.first.x(), elem.first.y() ) + point( SEEX - 1, 0 ), elem.second ); } computers = mirror_comp; } else { @@ -314,13 +309,13 @@ void submap::mirror( bool horizontally ) } for( submap::cosmetic_t &elem : cosmetics ) { - elem.pos = point( elem.pos.x, -elem.pos.y ) + point( 0, SEEY - 1 ); + elem.pos = point_sm_ms( elem.pos.x(), -elem.pos.y() ) + point( 0, SEEY - 1 ); } active_items.mirror( { SEEX, SEEY }, false ); for( auto &elem : computers ) { - mirror_comp.emplace( point( elem.first.x, -elem.first.y ) + point( 0, SEEY - 1 ), elem.second ); + mirror_comp.emplace( point( elem.first.x(), -elem.first.y() ) + point( 0, SEEY - 1 ), elem.second ); } computers = mirror_comp; } @@ -331,14 +326,14 @@ void submap::revert_submap( submap &sr ) reverted = true; if( sr.is_uniform() ) { m.reset(); - set_all_ter( sr.get_ter( point_zero ), true ); + set_all_ter( sr.get_ter( point_sm_ms_zero ), true ); return; } ensure_nonuniform(); for( int x = 0; x < SEEX; x++ ) { for( int y = 0; y < SEEY; y++ ) { - point pt( x, y ); + point_sm_ms pt( x, y ); m->frn[x][y] = sr.get_furn( pt ); m->ter[x][y] = sr.get_ter( pt ); m->trp[x][y] = sr.get_trap( pt ); @@ -364,27 +359,27 @@ submap submap::get_revert_submap() const return ret; } -void submap::update_lum_rem( const point &p, const item &i ) +void submap::update_lum_rem( const point_sm_ms &p, const item &i ) { ensure_nonuniform(); if( !i.is_emissive() ) { return; - } else if( m->lum[p.x][p.y] && m->lum[p.x][p.y] < 255 ) { - m->lum[p.x][p.y]--; + } else if( m->lum[p.x()][p.y()] && m->lum[p.x()][p.y()] < 255 ) { + m->lum[p.x()][p.y()]--; return; } // Have to scan through all items to be sure removing i will actually lower // the count below 255. int count = 0; - for( const item &it : m->itm[p.x][p.y] ) { + for( const item &it : m->itm[p.x()][p.y()] ) { if( it.is_emissive() ) { count++; } } if( count <= 256 ) { - m->lum[p.x][p.y] = static_cast( count - 1 ); + m->lum[p.x()][p.y()] = static_cast( count - 1 ); } } @@ -484,8 +479,8 @@ void submap::merge_submaps( submap *copy_from, bool copy_from_is_overlay ) debugmsg( "Camp found on copied submap when none is expected." ); } - for( const std::pair &comp : copy_from->computers ) { - if( this->m->frn[comp.first.x][comp.first.y] == furn_f_console && + for( const std::pair &comp : copy_from->computers ) { + if( this->m->frn[comp.first.x()][comp.first.y()] == furn_f_console && !this->get_computer( comp.first ) ) { this->set_computer( comp.first, comp.second ); } diff --git a/src/submap.h b/src/submap.h index afe5dc279366e..cdce4a9e5a91b 100644 --- a/src/submap.h +++ b/src/submap.h @@ -20,6 +20,7 @@ #include "compatibility.h" #include "computer.h" #include "construction.h" +#include "coordinate_constants.h" #include "field.h" #include "game_constants.h" #include "item.h" @@ -37,7 +38,7 @@ struct furn_t; struct ter_t; struct spawn_point { - point pos; + point_sm_ms pos; int count; mtype_id type; int faction_id; @@ -45,7 +46,8 @@ struct spawn_point { bool friendly; std::optional name; spawn_data data; - explicit spawn_point( const mtype_id &T = mtype_id::NULL_ID(), int C = 0, point P = point_zero, + explicit spawn_point( const mtype_id &T = mtype_id::NULL_ID(), int C = 0, + point_sm_ms P = point_sm_ms_zero, int FAC = -1, int MIS = -1, bool F = false, const std::optional &N = std::nullopt, const spawn_data &SD = spawn_data() ) : pos( P ), count( C ), type( T ), faction_id( FAC ), @@ -63,7 +65,7 @@ struct maptile_soa { cata::mdarray trp; // Trap on each square cata::mdarray rad; // Irradiation of each square - void swap_soa_tile( const point &p1, const point &p2 ); + void swap_soa_tile( const point_sm_ms &p1, const point_sm_ms &p2 ); }; class submap @@ -90,16 +92,16 @@ class submap submap get_revert_submap() const; - trap_id get_trap( const point &p ) const { + trap_id get_trap( const point_sm_ms &p ) const { if( is_uniform() ) { return tr_null; } - return m->trp[p.x][p.y]; + return m->trp[p.x()][p.y()]; } - void set_trap( const point &p, trap_id trap ) { + void set_trap( const point_sm_ms &p, trap_id trap ) { ensure_nonuniform(); - m->trp[p.x][p.y] = trap; + m->trp[p.x()][p.y()] = trap; } void set_all_traps( const trap_id &trap ) { @@ -107,16 +109,16 @@ class submap std::uninitialized_fill_n( &m->trp[0][0], elements, trap ); } - furn_id get_furn( const point &p ) const { + furn_id get_furn( const point_sm_ms &p ) const { if( is_uniform() ) { return furn_str_id::NULL_ID(); } - return m->frn[p.x][p.y]; + return m->frn[p.x()][p.y()]; } - void set_furn( const point &p, furn_id furn ) { + void set_furn( const point_sm_ms &p, furn_id furn ) { ensure_nonuniform(); - m->frn[p.x][p.y] = furn; + m->frn[p.x()][p.y()] = furn; } void set_all_furn( const furn_id &furn ) { @@ -135,16 +137,16 @@ class submap ephemeral_data[p] = { dmg }; } - ter_id get_ter( const point &p ) const { + ter_id get_ter( const point_sm_ms &p ) const { if( is_uniform() ) { return uniform_ter; } - return m->ter[p.x][p.y]; + return m->ter[p.x()][p.y()]; } - void set_ter( const point &p, ter_id terr ) { + void set_ter( const point_sm_ms &p, ter_id terr ) { ensure_nonuniform(); - m->ter[p.x][p.y] = terr; + m->ter[p.x()][p.y()] = terr; } void set_all_ter( const ter_id &terr, bool uniform_ok = false ) { @@ -158,32 +160,28 @@ class submap } } - int get_radiation( const point &p ) const { + int get_radiation( const point_sm_ms &p ) const { if( is_uniform() ) { return 0; } - return m->rad[p.x][p.y]; + return m->rad[p.x()][p.y()]; } - void set_radiation( const point &p, const int radiation ) { + void set_radiation( const point_sm_ms &p, const int radiation ) { ensure_nonuniform(); - m->rad[p.x][p.y] = radiation; + m->rad[p.x()][p.y()] = radiation; } - uint8_t get_lum( const point &p ) const { + uint8_t get_lum( const point_sm_ms &p ) const { if( is_uniform() ) { return 0; } - return m->lum[p.x][p.y]; + return m->lum[p.x()][p.y()]; } - void set_lum( const point &p, uint8_t luminance ) { + void set_lum( const point_sm_ms &p, uint8_t luminance ) { ensure_nonuniform(); - m->lum[p.x][p.y] = luminance; - } - - void update_lum_add( const point &p, const item &i ) { - update_lum_add( point_sm_ms( p ), i ); + m->lum[p.x()][p.y()] = luminance; } void update_lum_add( const point_sm_ms &p, const item &i ) { @@ -193,14 +191,9 @@ class submap } } - void update_lum_rem( const point &p, const item &i ); + void update_lum_rem( const point_sm_ms &p, const item &i ); // TODO: Replace this as it essentially makes itm public - // TODO: Get rid of untyped overload. - cata::colony &get_items( const point &p ) { - return get_items( point_sm_ms( p ) ); - } - cata::colony &get_items( const point_sm_ms &p ) { if( is_uniform() ) { cata::colony static noitems; @@ -209,40 +202,40 @@ class submap return m->itm[p.x()][p.y()]; } - const cata::colony &get_items( const point &p ) const { + const cata::colony &get_items( const point_sm_ms &p ) const { if( is_uniform() ) { cata::colony static noitems; return noitems; } - return m->itm[p.x][p.y]; + return m->itm[p.x()][p.y()]; } // TODO: Replace this as it essentially makes fld public - field &get_field( const point &p ) { + field &get_field( const point_sm_ms &p ) { if( is_uniform() ) { field static nofield; return nofield; } - return m->fld[p.x][p.y]; + return m->fld[p.x()][p.y()]; } - const field &get_field( const point &p ) const { + const field &get_field( const point_sm_ms &p ) const { if( is_uniform() ) { field static nofield; return nofield; } - return m->fld[p.x][p.y]; + return m->fld[p.x()][p.y()]; } - void clear_fields( const point &p ); + void clear_fields( const point_sm_ms &p ); struct cosmetic_t { - point pos; + point_sm_ms pos; std::string type; std::string str; }; - void insert_cosmetic( const point &p, const std::string &type, const std::string &str ) { + void insert_cosmetic( const point_sm_ms &p, const std::string &type, const std::string &str ) { cosmetic_t ins; ins.pos = p; @@ -260,33 +253,31 @@ class submap temperature_mod = units::to_fahrenheit_delta( new_temperature_mod ); } - bool has_graffiti( const point &p ) const; - const std::string &get_graffiti( const point &p ) const; - void set_graffiti( const point &p, const std::string &new_graffiti ); - void delete_graffiti( const point &p ); + bool has_graffiti( const point_sm_ms &p ) const; + const std::string &get_graffiti( const point_sm_ms &p ) const; + void set_graffiti( const point_sm_ms &p, const std::string &new_graffiti ); + void delete_graffiti( const point_sm_ms &p ); // Signage is a pretend union between furniture on a square and stored // writing on the square. When both are present, we have signage. // Its effect is meant to be cosmetic and atmospheric only. - bool has_signage( const point &p ) const; + bool has_signage( const point_sm_ms &p ) const; // Dependent on furniture + cosmetics. - std::string get_signage( const point &p ) const; + std::string get_signage( const point_sm_ms &p ) const; // Can be used anytime (prevents code from needing to place sign first.) - void set_signage( const point &p, const std::string &s ); + void set_signage( const point_sm_ms &p, const std::string &s ); // Can be used anytime (prevents code from needing to place sign first.) - void delete_signage( const point &p ); + void delete_signage( const point_sm_ms &p ); - bool has_computer( const point &p ) const; - const computer *get_computer( const point &p ) const; - // TOD: Get rid of untyped overload. - computer *get_computer( const point &p ); + bool has_computer( const point_sm_ms &p ) const; + const computer *get_computer( const point_sm_ms &p ) const; computer *get_computer( const point_sm_ms &p ); - void set_computer( const point &p, const computer &c ); - void delete_computer( const point &p ); + void set_computer( const point_sm_ms &p, const computer &c ); + void delete_computer( const point_sm_ms &p ); bool contains_vehicle( vehicle * ); - bool is_open_air( const point & ) const; + bool is_open_air( const point_sm_ms & ) const; void rotate( int turns ); void mirror( bool horizontally ); @@ -332,7 +323,7 @@ class submap private: std::map ephemeral_data; - std::map computers; + std::map computers; std::unique_ptr m; ter_id uniform_ter = t_null; int temperature_mod = 0; // delta in F @@ -357,9 +348,9 @@ class maptile_impl friend map; // To allow "sliding" the tile in x/y without bounds checks friend submap; Submap *sm; - point pos_; + point_sm_ms pos_; - maptile_impl( Submap *sub, const point &p ) : + maptile_impl( Submap *sub, const point_sm_ms &p ) : sm( sub ), pos_( p ) { } template // NOLINTNEXTLINE(google-explicit-constructor) @@ -369,7 +360,7 @@ class maptile_impl Submap *wrapped_submap() const { return sm; } - inline point pos() const { + inline point_sm_ms pos() const { return pos_; } diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 64bf8caad8bfc..c8bec35fede9d 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -7874,8 +7874,8 @@ static bool is_sm_tile_over_water( const tripoint &real_global_pos ) } // TODO: fix point types - return ( sm->get_ter( p.raw() ).obj().has_flag( ter_furn_flag::TFLAG_CURRENT ) || - sm->get_furn( p.raw() ).obj().has_flag( ter_furn_flag::TFLAG_CURRENT ) ); + return ( sm->get_ter( p ).obj().has_flag( ter_furn_flag::TFLAG_CURRENT ) || + sm->get_furn( p ).obj().has_flag( ter_furn_flag::TFLAG_CURRENT ) ); } static bool is_sm_tile_outside( const tripoint &real_global_pos ) @@ -7896,8 +7896,8 @@ static bool is_sm_tile_outside( const tripoint &real_global_pos ) } // TODO: fix point types - return !( sm->get_ter( p.raw() ).obj().has_flag( ter_furn_flag::TFLAG_INDOORS ) || - sm->get_furn( p.raw() ).obj().has_flag( ter_furn_flag::TFLAG_INDOORS ) ); + return !( sm->get_ter( p ).obj().has_flag( ter_furn_flag::TFLAG_INDOORS ) || + sm->get_furn( p ).obj().has_flag( ter_furn_flag::TFLAG_INDOORS ) ); } void vehicle::update_time( const time_point &update_to ) diff --git a/src/visitable.cpp b/src/visitable.cpp index 9a1c9df878b2c..95a3aa78847fd 100644 --- a/src/visitable.cpp +++ b/src/visitable.cpp @@ -699,12 +699,12 @@ std::list map_cursor::remove_items_with( const // fetch the appropriate item stack point_sm_ms offset; submap *sub = here.get_submap_at( pos(), offset ); - cata::colony &stack = sub->get_items( offset.raw() ); + cata::colony &stack = sub->get_items( offset ); for( auto iter = stack.begin(); iter != stack.end(); ) { if( filter( *iter ) ) { // if necessary remove item from the luminosity map - sub->update_lum_rem( offset.raw(), *iter ); + sub->update_lum_rem( offset, *iter ); // finally remove the item res.push_back( *iter ); diff --git a/tests/map_helpers.cpp b/tests/map_helpers.cpp index 2195cedcd3298..c981b8970ec7b 100644 --- a/tests/map_helpers.cpp +++ b/tests/map_helpers.cpp @@ -94,8 +94,8 @@ void clear_fields( const int zlevel ) const int mapsize = here.getmapsize() * SEEX; for( int x = 0; x < mapsize; ++x ) { for( int y = 0; y < mapsize; ++y ) { - const tripoint p( x, y, zlevel ); - point offset; + const tripoint_bub_ms p( x, y, zlevel ); + point_sm_ms offset; submap *sm = here.get_submap_at( p, offset ); if( sm ) { diff --git a/tests/map_test.cpp b/tests/map_test.cpp index ba49e42c385d3..26ce465013f19 100644 --- a/tests/map_test.cpp +++ b/tests/map_test.cpp @@ -150,7 +150,7 @@ void map::check_submap_active_item_consistency() for( int z = -OVERMAP_DEPTH; z < OVERMAP_HEIGHT; ++z ) { for( int x = 0; x < MAPSIZE; ++x ) { for( int y = 0; y < MAPSIZE; ++y ) { - tripoint p( x, y, z ); + tripoint_rel_sm p( x, y, z ); submap *s = get_submap_at_grid( p ); REQUIRE( s != nullptr ); bool submap_has_active_items = !s->active_items.empty(); diff --git a/tests/submap_load_test.cpp b/tests/submap_load_test.cpp index 8465bdc458a1e..fde024f3bd216 100644 --- a/tests/submap_load_test.cpp +++ b/tests/submap_load_test.cpp @@ -46,11 +46,11 @@ static const ter_str_id ter_test_t_migration_new_id( "test_t_migration_new_id" ) // NOLINTNEXTLINE(cata-static-declarations) extern const int savegame_version; -static const point &corner_ne = point_zero; -static const point corner_nw( SEEX - 1, 0 ); -static const point corner_se( 0, SEEY - 1 ); -static const point corner_sw( SEEX - 1, SEEY - 1 ); -static const point random_pt( 4, 7 ); +static const point_sm_ms &corner_ne = point_sm_ms_zero; +static const point_sm_ms corner_nw( SEEX - 1, 0 ); +static const point_sm_ms corner_se( 0, SEEY - 1 ); +static const point_sm_ms corner_sw( SEEX - 1, SEEY - 1 ); +static const point_sm_ms random_pt( 4, 7 ); static std::string submap_empty_ss( "{\n" @@ -1044,7 +1044,7 @@ TEST_CASE( "submap_furniture_load", "[submap][load]" ) // Also, check we have no other furniture for( int x = 0; x < SEEX; ++x ) { for( int y = 0; y < SEEY; ++y ) { - point tested{ x, y }; + point_sm_ms tested{ x, y }; if( tested == corner_nw || tested == corner_ne || tested == corner_sw || tested == corner_se || tested == random_pt ) { continue; @@ -1085,7 +1085,7 @@ TEST_CASE( "submap_trap_load", "[submap][load]" ) // Also, check we have no other traps for( int x = 0; x < SEEX; ++x ) { for( int y = 0; y < SEEY; ++y ) { - point tested{ x, y }; + point_sm_ms tested{ x, y }; if( tested == corner_nw || tested == corner_ne || tested == corner_sw || tested == corner_se || tested == random_pt ) { continue; @@ -1133,7 +1133,7 @@ TEST_CASE( "submap_rad_load", "[submap][load]" ) rad = -1; } for( int x = 0; x < SEEX; ++x ) { - point tested{ x, y }; + point_sm_ms tested{ x, y }; if( tested == corner_nw || tested == corner_ne || tested == corner_sw || tested == corner_se || tested == random_pt ) { rads[x] = sm.get_radiation( tested ); @@ -1202,7 +1202,7 @@ TEST_CASE( "submap_item_load", "[submap][load]" ) // Also, check we have no other items for( int y = 0; y < SEEY; ++y ) { for( int x = 0; x < SEEX; ++x ) { - point tested{ x, y }; + point_sm_ms tested{ x, y }; if( tested == corner_nw || tested == corner_ne || tested == corner_sw || tested == corner_se || tested == random_pt ) { continue; @@ -1275,7 +1275,7 @@ TEST_CASE( "submap_field_load", "[submap][load]" ) // Also, check we have no other fields for( int y = 0; y < SEEY; ++y ) { for( int x = 0; x < SEEX; ++x ) { - point tested{ x, y }; + point_sm_ms tested{ x, y }; if( tested == corner_nw || tested == corner_ne || tested == corner_sw || tested == corner_se || tested == random_pt ) { continue; @@ -1382,15 +1382,15 @@ TEST_CASE( "submap_spawns_load", "[submap][load]" ) } ); // We placed a unique spawn in a couple of places. Check that those are correct - INFO( string_format( "nw: [%d, %d] %d %s %s %s", nw.pos.x, nw.pos.y, nw.count, nw.type.str(), + INFO( string_format( "nw: [%d, %d] %d %s %s %s", nw.pos.x(), nw.pos.y(), nw.count, nw.type.str(), nw.friendly ? "friendly" : "hostile", nw.name.value_or( "NONE" ) ) ); - INFO( string_format( "ne: [%d, %d] %d %s %s %s", ne.pos.x, ne.pos.y, ne.count, ne.type.str(), + INFO( string_format( "ne: [%d, %d] %d %s %s %s", ne.pos.x(), ne.pos.y(), ne.count, ne.type.str(), ne.friendly ? "friendly" : "hostile", ne.name.value_or( "NONE" ) ) ); - INFO( string_format( "sw: [%d, %d] %d %s %s %s", sw.pos.x, sw.pos.y, sw.count, sw.type.str(), + INFO( string_format( "sw: [%d, %d] %d %s %s %s", sw.pos.x(), sw.pos.y(), sw.count, sw.type.str(), sw.friendly ? "friendly" : "hostile", sw.name.value_or( "NONE" ) ) ); - INFO( string_format( "se: [%d, %d] %d %s %s %s", se.pos.x, se.pos.y, se.count, se.type.str(), + INFO( string_format( "se: [%d, %d] %d %s %s %s", se.pos.x(), se.pos.y(), se.count, se.type.str(), se.friendly ? "friendly" : "hostile", se.name.value_or( "NONE" ) ) ); - INFO( string_format( "ra: [%d, %d] %d %s %s %s", ra.pos.x, ra.pos.y, ra.count, ra.type.str(), + INFO( string_format( "ra: [%d, %d] %d %s %s %s", ra.pos.x(), ra.pos.y(), ra.count, ra.type.str(), ra.friendly ? "friendly" : "hostile", ra.name.value_or( "NONE" ) ) ); // Require to prevent the lower CHECK from being spammy CHECK( nw.count == 3 ); @@ -1464,7 +1464,7 @@ TEST_CASE( "submap_computer_load", "[submap][load]" ) REQUIRE( is_normal_submap( sm, checks ) ); // Just check there are computers in the right place // Checking more is complicated - REQUIRE( sm.has_computer( point_south ) ); + REQUIRE( sm.has_computer( point_sm_ms( point_south ) ) ); REQUIRE( sm.has_computer( {3, 5} ) ); } diff --git a/tests/submap_test.cpp b/tests/submap_test.cpp index f2af7b1beba15..8ec927f6e84a5 100644 --- a/tests/submap_test.cpp +++ b/tests/submap_test.cpp @@ -8,15 +8,15 @@ TEST_CASE( "submap_rotation", "[submap]" ) { // Corners are labelled starting from the upper-left one, clockwise. - constexpr point corner_1{}; - constexpr point corner_2 = point{ SEEX - 1, 0 }; - constexpr point corner_3 = point{ SEEX - 1, SEEY - 1 }; - constexpr point corner_4 = point{ 0, SEEY - 1 }; + constexpr point_sm_ms corner_1{}; + constexpr point_sm_ms corner_2 = { SEEX - 1, 0 }; + constexpr point_sm_ms corner_3 = { SEEX - 1, SEEY - 1 }; + constexpr point_sm_ms corner_4 = { 0, SEEY - 1 }; - constexpr point center_1 = point{ SEEX / 2 - 1, SEEY / 2 - 1 }; - constexpr point center_2 = point{ SEEX / 2, SEEY / 2 - 1 }; - constexpr point center_3 = point{ SEEX / 2, SEEY / 2 }; - constexpr point center_4 = point{ SEEX / 2 - 1, SEEY / 2 }; + constexpr point_sm_ms center_1 = { SEEX / 2 - 1, SEEY / 2 - 1 }; + constexpr point_sm_ms center_2 = { SEEX / 2, SEEY / 2 - 1 }; + constexpr point_sm_ms center_3 = { SEEX / 2, SEEY / 2 }; + constexpr point_sm_ms center_4 = { SEEX / 2 - 1, SEEY / 2 }; GIVEN( "a submap with marks" ) { submap sm; @@ -107,8 +107,8 @@ TEST_CASE( "submap_rotation2", "[submap]" ) for( int x = 0; x < SEEX; x++ ) { for( int y = 0; y < SEEY; y++ ) { - point p( x, y ); - point p_after_rotation = p.rotate( rotation_turns, {SEEX, SEEY} ); + point_sm_ms p( x, y ); + point_sm_ms p_after_rotation = point_sm_ms( p.raw().rotate( rotation_turns, {SEEX, SEEY} ) ); CAPTURE( p, p_after_rotation ); CHECK( sm.get_radiation( p_after_rotation ) == sm_copy.get_radiation( p ) );