From f2e3ee4988be1574a0c5f7774e541ff073c14eaa Mon Sep 17 00:00:00 2001 From: PatrikLundell Date: Sun, 12 Jan 2025 14:43:40 +0100 Subject: [PATCH] typified map.h and dependents --- src/avatar_action.cpp | 2 +- src/cata_tiles.cpp | 6 +- src/creature_tracker.cpp | 4 +- src/iuse.cpp | 8 +- src/lightmap.cpp | 21 ++-- src/map.cpp | 86 +--------------- src/map.h | 108 +------------------- src/map_extras.cpp | 2 +- src/mapgen.cpp | 161 ++++++++++++++---------------- src/mapgen.h | 17 ++-- src/pathfinding.cpp | 61 +++++------ src/pixel_minimap.cpp | 77 +++++++------- src/pixel_minimap.h | 20 ++-- src/savegame_json.cpp | 25 ++--- src/veh_appliance.cpp | 2 +- src/vehicle.h | 3 +- src/vehicle_use.cpp | 4 +- tests/degradation_test.cpp | 4 +- tests/map_test.cpp | 10 +- tests/mapgen_remove_npcs_test.cpp | 18 ++-- tests/vehicle_part_test.cpp | 2 +- 21 files changed, 226 insertions(+), 415 deletions(-) diff --git a/src/avatar_action.cpp b/src/avatar_action.cpp index 5b62b52d7a2c8..c6eb53adde084 100644 --- a/src/avatar_action.cpp +++ b/src/avatar_action.cpp @@ -241,7 +241,7 @@ bool avatar_action::move( avatar &you, map &m, const tripoint_rel_ms &d ) get_option( "AUTO_FEATURES" ) && get_option( "AUTO_MINING" ) && !m.veh_at( dest_loc ) && !you.is_underwater() && !you.has_effect( effect_stunned ) && !you.has_effect( effect_psi_stunned ) && !is_riding && !you.has_effect( effect_incorporeal ) && - !m.impassable_field_at( d.raw() ) && !you.has_flag( json_flag_CANNOT_MOVE ) ) { + !m.impassable_field_at( dest_loc ) && !you.has_flag( json_flag_CANNOT_MOVE ) ) { if( weapon && weapon->has_flag( flag_DIG_TOOL ) ) { if( weapon->type->can_use( "JACKHAMMER" ) && weapon->ammo_sufficient( &you ) ) { diff --git a/src/cata_tiles.cpp b/src/cata_tiles.cpp index 27519e9133321..d41340f30a466 100644 --- a/src/cata_tiles.cpp +++ b/src/cata_tiles.cpp @@ -1521,7 +1521,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms ¢er, int wid invisible[0] = true; } else { if( would_apply_vision_effects( offscreen_type ) ) { - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0}, + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0}, tile_render_info::vision_effect{ offscreen_type } ); } break; @@ -1690,7 +1690,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms ¢er, int wid || you.sees_with_specials( *critter ) ) ) ) { invisible[0] = true; } else { - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0}, + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0}, tile_render_info::vision_effect{ vis_type } ); break; } @@ -1701,7 +1701,7 @@ void cata_tiles::draw( const point &dest, const tripoint_bub_ms ¢er, int wid invisible[1 + i] = apply_visible( np, ch2, here ); } - here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos.raw(), 0}, + here.draw_points_cache[zlevel][row].emplace_back( tile_render_info::common{ pos, 0}, tile_render_info::sprite{ ll, invisible } ); // Stop building draw points below when floor reached if( here.dont_draw_lower_floor( pos ) ) { diff --git a/src/creature_tracker.cpp b/src/creature_tracker.cpp index 9b6cebceababe..a2de1616cd238 100644 --- a/src/creature_tracker.cpp +++ b/src/creature_tracker.cpp @@ -297,7 +297,7 @@ void creature_tracker::remove_dead() template T *creature_tracker::creature_at( const tripoint &p, bool allow_hallucination ) { - return creature_at( get_map().getglobal( p ), allow_hallucination ); + return creature_at( get_map().getglobal( tripoint_bub_ms( p ) ), allow_hallucination ); } template @@ -423,7 +423,7 @@ void creature_tracker::flood_fill_zone( const Creature &origin ) template const T *creature_tracker::creature_at( const tripoint &p, bool allow_hallucination ) const { - return creature_at( get_map().getglobal( p ), allow_hallucination ); + return creature_at( get_map().getglobal( tripoint_bub_ms( p ) ), allow_hallucination ); } template diff --git a/src/iuse.cpp b/src/iuse.cpp index ab4558608c10e..e8e7d85cf3c0d 100644 --- a/src/iuse.cpp +++ b/src/iuse.cpp @@ -901,7 +901,7 @@ std::optional iuse::meth( Character *p, item *, const tripoint_bub_ms & ) map &here = get_map(); // breathe out some smoke for( int i = 0; i < 3; i++ ) { - point offset( rng( -2, 2 ), rng( -2, 2 ) ); + point_rel_ms offset( rng( -2, 2 ), rng( -2, 2 ) ); here.add_field( p->pos_bub() + offset, field_type_id( "fd_methsmoke" ), 2 ); } } else { @@ -8229,7 +8229,7 @@ heating_requirements heating_requirements_for_weight( const units::mass &frozen, return {volume, ammo, time}; } -static std::optional> appliance_heater_selector( Character *p ) +static std::optional> appliance_heater_selector( Character *p ) { const std::optional pt = choose_adjacent_highlight( _( "Select an appliance." ), _( "There is no appliance nearby." ), ACTION_EXAMINE, false ); @@ -8264,7 +8264,7 @@ static std::optional> appliance_heater_selector( C p->add_msg_if_player( m_info, _( "You haven't selected any heater." ) ); return std::nullopt; } else { - return std::make_pair( pt.value().raw(), pseudo_tools[app_menu.ret] ); + return std::make_pair( pt.value(), pseudo_tools[app_menu.ret] ); } } @@ -8322,7 +8322,7 @@ heater find_heater( Character *p, item *it ) 1, _( "You don't have a proper heating tool. Try selecting an appliance with a heater." ) ); if( !loc ) { - std::optional> app = appliance_heater_selector( p ); + std::optional> app = appliance_heater_selector( p ); if( !app ) { return {loc, true, -1, 0, vpt, pseudo_flag}; } else { diff --git a/src/lightmap.cpp b/src/lightmap.cpp index e02b5a7af3685..f5665f81e64b0 100644 --- a/src/lightmap.cpp +++ b/src/lightmap.cpp @@ -672,11 +672,6 @@ void map::add_light_source( const tripoint_bub_ms &p, float luminance ) // Tile light/transparency: 3D -lit_level map::light_at( const tripoint &p ) const -{ - return map::light_at( tripoint_bub_ms( p ) ); -} - lit_level map::light_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { @@ -1432,21 +1427,21 @@ void map::apply_light_arc( const tripoint_bub_ms &p, const units::angle &angle, void map::apply_light_ray( cata::mdarray &lit, - const tripoint &s, const tripoint &e, float luminance ) + const tripoint_bub_ms &s, const tripoint_bub_ms &e, float luminance ) { - point a( std::abs( e.x - s.x ) * 2, std::abs( e.y - s.y ) * 2 ); - point d( ( s.x < e.x ) ? 1 : -1, ( s.y < e.y ) ? 1 : -1 ); + point a( std::abs( e.x() - s.x() ) * 2, std::abs( e.y() - s.y() ) * 2 ); + point d( ( s.x() < e.x() ) ? 1 : -1, ( s.y() < e.y() ) ? 1 : -1 ); point_bub_ms p( s.xy() ); quadrant quad = quadrant_from_x_y( d.x, d.y ); // TODO: Invert that z comparison when it's sane - if( s.z != e.z || ( s.x == e.x && s.y == e.y ) ) { + if( s.z() != e.z() || ( s.x() == e.x() && s.y() == e.y() ) ) { return; } - auto &lm = get_cache( s.z ).lm; - auto &transparency_cache = get_cache( s.z ).transparency_cache; + auto &lm = get_cache( s.z() ).lm; + auto &transparency_cache = get_cache( s.z() ).transparency_cache; float distance = 1.0f; float transparency = LIGHT_TRANSPARENCY_OPEN_AIR; @@ -1485,7 +1480,7 @@ void map::apply_light_ray( } distance += scaling_factor; - } while( !( p.x() == e.x && p.y() == e.y ) ); + } while( !( p.x() == e.x() && p.y() == e.y() ) ); } else { int t = a.x - ( a.y / 2 ); do { @@ -1517,6 +1512,6 @@ void map::apply_light_ray( } distance += scaling_factor; - } while( !( p.x() == e.x && p.y() == e.y ) ); + } while( !( p.x() == e.x() && p.y() == e.y() ) ); } } diff --git a/src/map.cpp b/src/map.cpp index 6811171bfdf45..d3085e07c8583 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1250,7 +1250,7 @@ std::set map::get_moving_vehicle_targets( const Creature &z, in if( !v.v->is_moving() ) { continue; } - if( std::abs( v.pos.z - zpos.z() ) > fov_3d_z_range ) { + if( std::abs( v.pos.z() - zpos.z() ) > fov_3d_z_range ) { continue; } if( rl_dist( zpos, tripoint_bub_ms( v.pos ) ) > max_range + 40 ) { @@ -1301,7 +1301,7 @@ VehicleList map::get_vehicles( const tripoint_bub_ms &start, const tripoint_bub_ elem->sm_pos.z = cz; wrapped_vehicle w; w.v = elem.get(); - w.pos = w.v->pos_bub().raw(); + w.pos = w.v->pos_bub(); vehs.push_back( w ); } } @@ -1316,11 +1316,6 @@ optional_vpart_position map::veh_at( const tripoint_abs_ms &p ) const return veh_at( bub_from_abs( p ) ); } -optional_vpart_position map::veh_at( const tripoint &p ) const -{ - return veh_at( tripoint_bub_ms( p ) ); -} - optional_vpart_position map::veh_at( const tripoint_bub_ms &p ) const { if( !inbounds( p ) || !const_cast( this )->get_cache( p.z() ).get_veh_in_active_range() ) { @@ -1707,11 +1702,6 @@ bool map::has_furn( const tripoint_bub_ms &p ) const return furn( p ) != furn_str_id::NULL_ID(); } -furn_id map::furn( const tripoint &p ) const -{ - return furn( tripoint_bub_ms( p ) ); -} - furn_id map::furn( const tripoint_bub_ms p ) const { if( !inbounds( p ) ) { @@ -1898,10 +1888,6 @@ std::string map::furnname( const tripoint_bub_ms &p ) * retained for high performance comparisons, save/load, and gradual transition * to string terrain.id */ -ter_id map::ter( const tripoint p ) const -{ - return ter( tripoint_bub_ms( p ) ); -} ter_id map::ter( const tripoint_bub_ms &p ) const { if( !inbounds( p ) ) { @@ -2643,11 +2629,6 @@ int map::climb_difficulty( const tripoint_bub_ms &p ) const return std::max( 0, best_difficulty - blocks_movement ); } -bool map::has_floor( const tripoint &p ) const -{ - return map::has_floor( tripoint_bub_ms( p ) ); -} - bool map::has_floor( const tripoint_bub_ms &p ) const { if( !zlevels || p.z() < -OVERMAP_DEPTH + 1 || p.z() > OVERMAP_HEIGHT ) { @@ -2660,11 +2641,6 @@ bool map::has_floor( const tripoint_bub_ms &p ) const !has_flag( ter_furn_flag::TFLAG_NO_FLOOR_WATER, p ); } -bool map::has_floor_or_water( const tripoint &p ) const -{ - return map::has_floor_or_water( tripoint_bub_ms( p ) ); -} - bool map::has_floor_or_water( const tripoint_bub_ms &p ) const { if( !zlevels || p.z() < -OVERMAP_DEPTH + 1 || p.z() > OVERMAP_HEIGHT ) { @@ -2695,22 +2671,12 @@ bool map::supports_above( const tripoint_bub_ms &p ) const return veh_at( p ).has_value(); } -bool map::has_floor_or_support( const tripoint &p ) const -{ - return map::has_floor_or_support( tripoint_bub_ms( p ) ); -} - bool map::has_floor_or_support( const tripoint_bub_ms &p ) const { const tripoint_bub_ms below( p.xy(), p.z() - 1 ); return !valid_move( p, below, false, true ); } -bool map::has_vehicle_floor( const tripoint &p ) const -{ - const tripoint_bub_ms p_bub( p ); - return has_vehicle_floor( p_bub ); -} bool map::has_vehicle_floor( const tripoint_bub_ms &p ) const { return veh_at( p ).part_with_feature( "BOARDABLE", false ) || @@ -3076,11 +3042,6 @@ bool map::can_put_items_ter_furn( const tripoint_bub_ms &p ) const return !has_flag( ter_furn_flag::TFLAG_NOITEM, p ) && !has_flag( ter_furn_flag::TFLAG_SEALED, p ); } -bool map::has_flag_ter( const std::string &flag, const tripoint &p ) const -{ - return ter( tripoint_bub_ms( p ) ).obj().has_flag( flag ); -} - bool map::has_flag_ter( const std::string &flag, const tripoint_bub_ms &p ) const { return ter( p ).obj().has_flag( flag ); @@ -5353,7 +5314,7 @@ void map::make_active( item_location &loc ) item *target = loc.get_item(); point_sm_ms l; - submap *const current_submap = get_submap_at( loc.position(), l.raw() ); + submap *const current_submap = get_submap_at( loc.pos_bub(), l ); if( current_submap == nullptr ) { debugmsg( "Tried to make active at (%d,%d) but the submap is not loaded", l.x(), l.y() ); return; @@ -6439,11 +6400,6 @@ std::optional map::get_impassable_field_at( const tripoint_bub_ms & return potential_field; } -bool map::impassable_field_at( const tripoint &p ) -{ - return impassable_field_at( tripoint_bub_ms( p ) ); -} - bool map::impassable_field_at( const tripoint_bub_ms &p ) { for( auto &pr : field_at( p ) ) { @@ -6455,11 +6411,6 @@ bool map::impassable_field_at( const tripoint_bub_ms &p ) return false; } -std::vector map::get_impassable_field_type_ids_at( const tripoint &p ) -{ - return get_impassable_field_type_ids_at( tripoint_bub_ms( p ) ); -} - std::vector map::get_impassable_field_type_ids_at( const tripoint_bub_ms &p ) { std::vector fields; @@ -9045,11 +8996,6 @@ const std::vector &map::trap_locations( const trap_id &type ) c return traplocs[type.to_i()]; } -bool map::inbounds( const tripoint &p ) const -{ - return inbounds( tripoint_bub_ms( p ) ); -} - bool map::inbounds( const tripoint_abs_ms &p ) const { return inbounds( bub_from_abs( p ) ); @@ -9625,11 +9571,6 @@ void map::build_map_cache( const int zlev, bool skip_lightmap ) ////////// ///// coordinate helpers -tripoint_abs_ms map::getglobal( const tripoint &p ) const -{ - return map::getglobal( tripoint_bub_ms( p ) ); -} - tripoint_abs_ms map::getglobal( const tripoint_bub_ms &p ) const { return tripoint_abs_ms{ p.x() + abs_ms.x(), p.y() + abs_ms.y(), p.z() }; @@ -10242,17 +10183,6 @@ tripoint_range map::points_in_rectangle( const tripoint_bub_ms return tripoint_range( min, max ); } -tripoint_range map::points_in_radius( const tripoint ¢er, size_t radius, - size_t radiusz ) const -{ - const tripoint min( std::max( 0, center.x - radius ), std::max( 0, center.y - radius ), - clamp( center.z - radiusz, -OVERMAP_DEPTH, OVERMAP_HEIGHT ) ); - const tripoint max( std::min( SEEX * my_MAPSIZE - 1, center.x + radius ), - std::min( SEEX * my_MAPSIZE - 1, center.y + radius ), clamp( center.z + radiusz, - -OVERMAP_DEPTH, OVERMAP_HEIGHT ) ); - return tripoint_range( min, max ); -} - tripoint_range map::points_in_radius( const tripoint_bub_ms ¢er, size_t radius, size_t radiusz ) const { @@ -10552,11 +10482,6 @@ void map::update_pathfinding_cache( int zlev ) const cache.dirty_points.clear(); } -void map::clip_to_bounds( tripoint &p ) const -{ - clip_to_bounds( p.x, p.y, p.z ); -} - void map::clip_to_bounds( tripoint_bub_ms &p ) const { clip_to_bounds( p.x(), p.y(), p.z() ); @@ -10689,11 +10614,6 @@ bool map::has_haulable_items( const tripoint_bub_ms &pos ) return false; } -std::vector map::get_haulable_items( const tripoint &pos ) -{ - return map::get_haulable_items( tripoint_bub_ms( pos ) ); -} - std::vector map::get_haulable_items( const tripoint_bub_ms &pos ) { std::vector target_items; diff --git a/src/map.h b/src/map.h index 2421eb8e0d7f5..359ec7c29f237 100644 --- a/src/map.h +++ b/src/map.h @@ -88,7 +88,7 @@ struct projectile; struct veh_collision; struct wrapped_vehicle { - tripoint pos; + tripoint_bub_ms pos; vehicle *v; }; @@ -308,7 +308,7 @@ struct tile_render_info { // accumulator for 3d tallness of sprites rendered here so far; int height_3d = 0; - common( const tripoint &pos, const int height_3d ) + common( const tripoint_bub_ms &pos, const int height_3d ) : pos( pos ), height_3d( height_3d ) {} }; @@ -779,8 +779,6 @@ class map * * @param p Tile to check for vehicle */ - // TODO: fix point types (remove the first overload) - optional_vpart_position veh_at( const tripoint &p ) const; optional_vpart_position veh_at( const tripoint_abs_ms &p ) const; optional_vpart_position veh_at( const tripoint_bub_ms &p ) const; vehicle *veh_at_internal( const tripoint_bub_ms &p, int &part_num ); @@ -842,8 +840,6 @@ class map bool has_furn( const point_bub_ms &p ) const { return has_furn( tripoint_bub_ms( p, abs_sub.z() ) ); } - // TODO: fix point types (remove the first overload) - furn_id furn( const tripoint &p ) const; furn_id furn( tripoint_bub_ms p ) const; furn_id furn( const point_bub_ms &p ) const { return furn( tripoint_bub_ms( p, abs_sub.z() ) ); @@ -869,8 +865,6 @@ class map bool can_move_furniture( const tripoint_bub_ms &pos, Character *you = nullptr ) const; // Terrain - // TODO: fix point types (remove the first overload) - ter_id ter( tripoint p ) const; ter_id ter( const tripoint_bub_ms &p ) const; ter_id ter( const point_bub_ms &p ) const { return ter( tripoint_bub_ms( p, abs_sub.z() ) ); @@ -926,9 +920,6 @@ class map } std::string tername( const tripoint_bub_ms &p ) const; - std::string tername( const point &p ) const { - return tername( tripoint_bub_ms( p.x, p.y, abs_sub.z() ) ); - } // Check for terrain/furniture/field that provide a // "fire" item to be used for example when crafting or when @@ -993,7 +984,6 @@ class map // True if items can be placed in this tile bool can_put_items_ter_furn( const tripoint_bub_ms &p ) const; // Checks terrain - bool has_flag_ter( const std::string &flag, const tripoint &p ) const; bool has_flag_ter( const std::string &flag, const tripoint_bub_ms &p ) const; bool has_flag_ter( const std::string &flag, const point_bub_ms &p ) const { return has_flag_ter( flag, tripoint_bub_ms( p, abs_sub.z() ) ); @@ -1254,15 +1244,6 @@ class map // FIXME: remove these overloads and require spawn_item to take an // itype_id - void spawn_item( const tripoint &p, const std::string &type_id, - unsigned quantity = 1, int charges = 0, - const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0, - const std::set &flags = {}, const std::string &variant = "", - const std::string &faction = "" ) { - spawn_item( tripoint_bub_ms( p ), itype_id( type_id ), quantity, charges, birthday, damlevel, flags, - variant, - faction ); - } void spawn_item( const tripoint_bub_ms &p, const std::string &type_id, unsigned quantity = 1, int charges = 0, const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0, @@ -1538,7 +1519,6 @@ class map // returns the a field entry that is impassable at the given point if it exists std::optional get_impassable_field_at( const tripoint_bub_ms &p ); - std::vector get_impassable_field_type_ids_at( const tripoint &p ); std::vector get_impassable_field_type_ids_at( const tripoint_bub_ms &p ); /** @@ -1548,7 +1528,6 @@ class map field_entry *get_field( const tripoint_bub_ms &p, const field_type_id &type ); const field_entry *get_field( const tripoint_bub_ms &p, const field_type_id &type ) const; bool dangerous_field_at( const tripoint_bub_ms &p ); - bool impassable_field_at( const tripoint &p ); bool impassable_field_at( const tripoint_bub_ms &p ); // Check if player can move on top of it during mopping zone activity @@ -1656,19 +1635,11 @@ class map // Returns true if terrain at p has NO flag ter_furn_flag::TFLAG_NO_FLOOR // and ter_furn_flag::TFLAG_NO_FLOOR_WATER, // if we're not in z-levels mode or if we're at lowest level - // 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_bub_ms &p ) const; - // TODO: Get rid of untyped overload - bool has_floor_or_support( const tripoint &p ) const; bool has_floor_or_support( const tripoint_bub_ms &p ) const; - // TODO: Get rid of untyped overload - bool has_vehicle_floor( const tripoint &p ) const; bool has_vehicle_floor( const tripoint_bub_ms &p ) const; private: /** @@ -1709,10 +1680,9 @@ class map void place_vending( const tripoint_bub_ms &p, const item_group_id &type, bool reinforced = false, bool lootable = false, bool powered = false ); // places an NPC, if static NPCs are enabled or if force is true - // TODO: Get rid of untyped overload - character_id place_npc( const point &p, const string_id &type ); character_id place_npc( const point_bub_ms &p, const string_id &type ); - void apply_faction_ownership( const point &p1, const point &p2, const faction_id &id ); + void apply_faction_ownership( const point_bub_ms &p1, const point_bub_ms &p2, + const faction_id &id ); void add_spawn( const mtype_id &type, int count, const tripoint_bub_ms &p, bool friendly = false, int faction_id = -1, int mission_id = -1, const std::optional &name = std::nullopt ); @@ -1744,10 +1714,6 @@ class map // can be overriden by VEHICLE_STATUS_AT_SPAWN EXTERNAL_OPTION // @param merge_wrecks if true and vehicle overlaps another then both turn into wrecks // if false and vehicle will overlap aborts and returns nullptr - // TODO: Get rid of untyped overload - vehicle *add_vehicle( const vproto_id &type, const tripoint &p, const units::angle &dir, - int init_veh_fuel = -1, int init_veh_status = -1, bool merge_wrecks = true, - bool force_status = false ); vehicle *add_vehicle( const vproto_id &type, const tripoint_bub_ms &p, const units::angle &dir, int init_veh_fuel = -1, int init_veh_status = -1, bool merge_wrecks = true, bool force_status = false ); @@ -1755,8 +1721,6 @@ class map // Light/transparency float light_transparency( const tripoint_bub_ms &p ) const; // Assumes 0,0 is light map center - // TODO: Get rid of untyped overload. - lit_level light_at( const tripoint &p ) const; lit_level light_at( const tripoint_bub_ms &p ) const; // Raw values for tilesets float ambient_light_at( const tripoint_bub_ms &p ) const; @@ -1786,8 +1750,6 @@ class map * Coordinates is in the system that is used by the ter/furn/i_at functions. * Output is in the same scale, but in global system. */ - // TODO: fix point types (remove the first overload) - tripoint_abs_ms getglobal( const tripoint &p ) const; tripoint_abs_ms getglobal( const tripoint_bub_ms &p ) const; /** * Inverse of @ref getglobal @@ -1796,7 +1758,6 @@ class map point_bub_ms bub_from_abs( const point_abs_ms &p ) const { return bub_from_abs( tripoint_abs_ms( p, abs_sub.z() ) ).xy(); } - bool inbounds( const tripoint &p ) const; bool inbounds( const tripoint_bub_ms &p ) const; bool inbounds( const tripoint_abs_ms &p ) const; bool inbounds( const tripoint_abs_sm &p ) const { @@ -1812,8 +1773,6 @@ class map } /** Clips the coordinates of p to fit the map bounds */ - // TODO: Get rid of untyped overload. - void clip_to_bounds( tripoint &p ) const; void clip_to_bounds( tripoint_bub_ms &p ) const; void clip_to_bounds( int &x, int &y ) const; void clip_to_bounds( int &x, int &y, int &z ) const; @@ -2016,12 +1975,6 @@ class map std::tie( sm, offset_p ) = project_remain( p ); return unsafe_get_submap_at( p ); } - // TODO: Get rid of untyped overload - submap *get_submap_at( const tripoint &p, point &offset_p ) { - offset_p.x = p.x % SEEX; - offset_p.y = p.y % SEEY; - return get_submap_at( tripoint_bub_ms( p ) ); - } submap *get_submap_at( const tripoint_bub_ms &p, point_sm_ms &offset_p ) { offset_p.x() = p.x() % SEEX; offset_p.y() = p.y() % SEEY; @@ -2032,9 +1985,6 @@ class map offset_p.y() = p.y() % SEEY; return get_submap_at( p ); } - submap *get_submap_at( const point &p, point &offset_p ) { - return get_submap_at( { p, abs_sub.z() }, offset_p ); - } /** * Get submap pointer in the grid at given grid coordinates. Grid coordinates must * be valid: 0 <= x < my_MAPSIZE, same for y. @@ -2107,7 +2057,7 @@ class map void apply_light_arc( const tripoint_bub_ms &p, const units::angle &angle, float luminance, const units::angle &wideangle = 30_degrees ); void apply_light_ray( cata::mdarray &lit, - const tripoint &s, const tripoint &e, float luminance ); + const tripoint_bub_ms &s, const tripoint_bub_ms &e, float luminance ); void add_light_from_items( const tripoint_bub_ms &p, const item_stack &items ); void add_item_light_recursive( const tripoint_bub_ms &p, const item &it ); std::unique_ptr add_vehicle_to_map( std::unique_ptr veh, bool merge_wrecks ); @@ -2249,9 +2199,6 @@ class map // Clips the area to map bounds tripoint_range points_in_rectangle( const tripoint_bub_ms &from, const tripoint_bub_ms &to ) const; - // TODO: fix point types (remove the first overload) - tripoint_range points_in_radius( - const tripoint ¢er, size_t radius, size_t radiusz = 0 ) const; tripoint_range points_in_radius( const tripoint_bub_ms ¢er, size_t radius, size_t radiusz = 0 ) const; @@ -2287,8 +2234,6 @@ class map bool dont_draw_lower_floor( const tripoint_bub_ms &p ) const; bool has_haulable_items( const tripoint_bub_ms &pos ); - // TODO: Get rid of untyped overload - std::vector get_haulable_items( const tripoint &pos ); std::vector get_haulable_items( const tripoint_bub_ms &pos ); #if defined(TILES) @@ -2365,17 +2310,9 @@ class tinymap : private map } using map::translate; - // TODO: Get rid of untyped overload. - ter_id ter( const tripoint &p ) const { - return map::ter( tripoint_bub_ms( p ) ); - } ter_id ter( const tripoint_omt_ms &p ) const { return map::ter( rebase_bub( p ) ); } - // TODO: Get rid of untyped overload. - bool ter_set( const tripoint &p, const ter_id &new_terrain, bool avoid_creatures = false ) { - return map::ter_set( tripoint_bub_ms( p ), new_terrain, avoid_creatures ); - } bool ter_set( const tripoint_omt_ms &p, const ter_id &new_terrain, bool avoid_creatures = false ) { return map::ter_set( rebase_bub( p ), new_terrain, avoid_creatures ); } @@ -2393,17 +2330,9 @@ class tinymap : private map furn_id furn( const point_omt_ms &p ) const { return map::furn( rebase_bub( p ) ); } - // TODO: Get rid of untyped overload. - furn_id furn( const tripoint &p ) const { - return map::furn( tripoint_bub_ms( p ) ); - } furn_id furn( const tripoint_omt_ms &p ) const { return map::furn( rebase_bub( p ) ); } - // TODO: Get rid of untyped overload. - bool has_furn( const tripoint &p ) const { - return map::has_furn( tripoint_bub_ms( p ) ); - } bool has_furn( const tripoint_omt_ms &p ) const { return map::has_furn( rebase_bub( p ) ); } @@ -2413,11 +2342,6 @@ class tinymap : private map void set( const tripoint_omt_ms &p, const ter_id &new_terrain, const furn_id &new_furniture ) { map::set( rebase_bub( p ), new_terrain, new_furniture ); } - // TODO: Get rid of untyped overload. - bool furn_set( const tripoint &p, const furn_id &new_furniture, bool furn_reset = false, - bool avoid_creatures = false ) { - return map::furn_set( tripoint_bub_ms( p ), new_furniture, furn_reset, avoid_creatures ); - } bool furn_set( const tripoint_omt_ms &p, const furn_id &new_furniture, bool furn_reset = false, bool avoid_creatures = false ) { return map::furn_set( rebase_bub( p ), new_furniture, furn_reset, avoid_creatures ); @@ -2448,23 +2372,9 @@ class tinymap : private map const tripoint_omt_ms &from, const tripoint_omt_ms &to ) const; tripoint_range points_in_radius( const tripoint_omt_ms ¢er, size_t radius, size_t radiusz = 0 ) const; - // TODO: Get rid of untyped overload. - map_stack i_at( const tripoint &p ) { - return map::i_at( tripoint_bub_ms( p ) ); - } map_stack i_at( const tripoint_omt_ms &p ) { return map::i_at( rebase_bub( p ) ); } - // TODO: Get rid of untyped overload. - void spawn_item( const tripoint &p, const itype_id &type_id, - unsigned quantity = 1, int charges = 0, - const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0, - const std::set &flags = {}, const std::string &variant = "", - const std::string &faction = "" ) { - map::spawn_item( tripoint_bub_ms( p ), type_id, quantity, charges, birthday, damlevel, flags, - variant, - faction ); - } void spawn_item( const tripoint_omt_ms &p, const itype_id &type_id, unsigned quantity = 1, int charges = 0, const time_point &birthday = calendar::start_of_cataclysm, int damlevel = 0, @@ -2512,10 +2422,6 @@ class tinymap : private map void i_rem( const tripoint_omt_ms &p, item *it ) { map::i_rem( rebase_bub( p ), it ); } - // TODO: Get rid of untyped overload. - void i_clear( const tripoint &p ) { - return map::i_clear( tripoint_bub_ms( p ) ); - } void i_clear( const tripoint_omt_ms &p ) { return map::i_clear( rebase_bub( p ) ); } @@ -2574,10 +2480,6 @@ class tinymap : private map tripoint_omt_ms omt_from_abs( const tripoint_abs_ms &p ) const { return rebase_omt( map::bub_from_abs( p ) ); }; - // TODO: Get rid of untyped overload. - bool is_outside( const tripoint &p ) const { - return map::is_outside( tripoint_bub_ms( p ) ); - } bool is_outside( const tripoint_omt_ms &p ) const { return map::is_outside( rebase_bub( p ) ); } diff --git a/src/map_extras.cpp b/src/map_extras.cpp index 3bc55b0c7c7f8..09b7489d3c81e 100644 --- a/src/map_extras.cpp +++ b/src/map_extras.cpp @@ -387,7 +387,7 @@ static bool mx_helicopter( map &m, const tripoint_abs_sm &abs_sub ) wreckage_pos = { clamp( c.x() + offset.x(), min.x(), x_max ), clamp( c.y() + offset.y(), min.y(), y_max ), abs_sub.z()}; } - vehicle *wreckage = m.add_vehicle( crashed_hull, wreckage_pos.raw(), dir1, rng( 1, 33 ), 1 ); + vehicle *wreckage = m.add_vehicle( crashed_hull, wreckage_pos, dir1, rng( 1, 33 ), 1 ); const auto controls_at = []( vehicle * wreckage, const tripoint_bub_ms & pos ) { return !wreckage->get_parts_at( pos, "CONTROLS", part_status_flag::any ).empty() || diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 7bda14723641d..528f6e3fac0bd 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -899,20 +899,20 @@ void reset_mapgens() size_t mapgen_function_json_base::calc_index( const point &p ) const { - if( p.x >= mapgensize.x ) { + if( p.x >= mapgensize.x() ) { debugmsg( "invalid value %zu for x in calc_index", p.x ); } - if( p.y >= mapgensize.y ) { + if( p.y >= mapgensize.y() ) { debugmsg( "invalid value %zu for y in calc_index", p.y ); } - return p.y * mapgensize.y + p.x; + return p.y * mapgensize.y() + p.x; } static bool common_check_bounds( const jmapgen_int &x, const jmapgen_int &y, const jmapgen_int &z, - const point &mapgensize, const JsonObject &jso ) + const point_rel_ms &mapgensize, const JsonObject &jso ) { - half_open_rectangle bounds( point::zero, mapgensize ); - if( !bounds.contains( point( x.val, y.val ) ) ) { + half_open_rectangle bounds( point_rel_ms::zero, mapgensize ); + if( !bounds.contains( point_rel_ms( x.val, y.val ) ) ) { return false; } @@ -928,11 +928,11 @@ static bool common_check_bounds( const jmapgen_int &x, const jmapgen_int &y, con jso.throw_error( "z maximum has to be identical to z minimum" ); } - if( x.valmax > mapgensize.x - 1 ) { + if( x.valmax > mapgensize.x() - 1 ) { jso.throw_error_at( "x", "coordinate range cannot cross grid boundaries" ); } - if( y.valmax > mapgensize.y - 1 ) { + if( y.valmax > mapgensize.y() - 1 ) { jso.throw_error_at( "y", "coordinate range cannot cross grid boundaries" ); } @@ -975,11 +975,11 @@ mapgen_function_json::mapgen_function_json( const JsonObject &jsobj, , rotation( 0 ) , fallback_predecessor_mapgen_( oter_str_id::NULL_ID() ) { - m_offset.x() = grid_offset.x * mapgensize.x; - m_offset.y() = grid_offset.y * mapgensize.y; + m_offset.x() = grid_offset.x * mapgensize.x(); + m_offset.y() = grid_offset.y * mapgensize.y(); m_offset.z() = 0; - total_size.x = grid_total.x * mapgensize.x; - total_size.y = grid_total.y * mapgensize.y; + total_size.x() = grid_total.x * mapgensize.x(); + total_size.y() = grid_total.y * mapgensize.y(); objects = jmapgen_objects( m_offset, mapgensize, total_size ); } @@ -2068,7 +2068,7 @@ class jmapgen_faction : public jmapgen_piece return; } // TODO: Make apply_faction_ownership 3D aware. - dat.m.apply_faction_ownership( point( x.val, y.val ), point( x.valmax, y.valmax ), + dat.m.apply_faction_ownership( point_bub_ms( x.val, y.val ), point_bub_ms( x.valmax, y.valmax ), chosen_id ); } @@ -3935,14 +3935,14 @@ class jmapgen_nested : public jmapgen_piece // Check whether any of the nests can attempt to place stuff out of // bounds - std::unordered_map nest_placement_coords; + std::unordered_map nest_placement_coords; auto add_coords_from = [&]( const mapgen_value &nest_id_val ) { for( const nested_mapgen_id &nest_id : nest_id_val.all_possible_results( parameters ) ) { if( nest_id.is_null() ) { continue; } - for( const point &p : nest_id->all_placement_coords() ) { + for( const point_rel_ms &p : nest_id->all_placement_coords() ) { nest_placement_coords.emplace( p, nest_id ); } } @@ -3958,13 +3958,13 @@ class jmapgen_nested : public jmapgen_piece nested_mapgen_id offending_nest_x; nested_mapgen_id offending_nest_y; - for( const std::pair &p : nest_placement_coords ) { - if( p.first.x > max_relative.x ) { - max_relative.x = p.first.x; + for( const std::pair &p : nest_placement_coords ) { + if( p.first.x() > max_relative.x ) { + max_relative.x = p.first.x(); offending_nest_x = p.second; } - if( p.first.y > max_relative.y ) { - max_relative.y = p.first.y; + if( p.first.y() > max_relative.y ) { + max_relative.y = p.first.y(); offending_nest_y = p.second; } } @@ -4022,8 +4022,8 @@ class jmapgen_nested : public jmapgen_piece } }; -jmapgen_objects::jmapgen_objects( const tripoint_rel_ms &offset, const point &mapsize, - const point &tot_size ) +jmapgen_objects::jmapgen_objects( const tripoint_rel_ms &offset, const point_rel_ms &mapsize, + const point_rel_ms &tot_size ) : m_offset( offset ) , mapgensize( mapsize ) , total_size( tot_size ) @@ -4543,8 +4543,8 @@ bool mapgen_function_json_nested::setup_internal( const JsonObject &jo ) // Mandatory - nested mapgen must be explicitly sized if( jo.has_array( "mapgensize" ) ) { JsonArray jarr = jo.get_array( "mapgensize" ); - mapgensize = point( jarr.get_int( 0 ), jarr.get_int( 1 ) ); - if( mapgensize.x == 0 || mapgensize.x != mapgensize.y ) { + mapgensize = point_rel_ms( jarr.get_int( 0 ), jarr.get_int( 1 ) ); + if( mapgensize.x() == 0 || mapgensize.x() != mapgensize.y() ) { // Non-square sizes not implemented yet jo.throw_error( "\"mapgensize\" must be an array of two identical, positive numbers" ); } @@ -4645,21 +4645,21 @@ bool mapgen_function_json_base::setup_common( const JsonObject &jo ) // mandatory: mapgensize rows of mapgensize character lines, each of which must have a // matching key in "terrain", unless fill_ter is set // "rows:" [ "aaaajustlikeinmapgen.cpp", "this.must!be!exactly.24!", "and_must_match_terrain_", .... ] - point expected_dim = mapgensize + m_offset.xy().raw(); - cata_assert( expected_dim.x >= 0 ); - cata_assert( expected_dim.y >= 0 ); - const std::string default_row( expected_dim.x, ' ' ); + point_rel_ms expected_dim = mapgensize + m_offset.xy(); + cata_assert( expected_dim.x() >= 0 ); + cata_assert( expected_dim.y() >= 0 ); + const std::string default_row( expected_dim.x(), ' ' ); const bool default_rows = !jo.has_array( "rows" ); if( !default_rows ) { parray = jo.get_array( "rows" ); - if( static_cast( parray.size() ) < expected_dim.y ) { + if( static_cast( parray.size() ) < expected_dim.y() ) { parray.throw_error( string_format( "format: rows: must have at least %d rows, not %d", - expected_dim.y, parray.size() ) ); + expected_dim.y(), parray.size() ) ); } - if( static_cast( parray.size() ) != total_size.y ) { + if( static_cast( parray.size() ) != total_size.y() ) { parray.throw_error( string_format( "format: rows: must have %d rows, not %d; check mapgensize if applicable", - total_size.y, parray.size() ) ); + total_size.y(), parray.size() ) ); } } @@ -4674,25 +4674,25 @@ bool mapgen_function_json_base::setup_common( const JsonObject &jo ) parameters = palette.get_parameters(); - for( int c = m_offset.y(); c < expected_dim.y; c++ ) { + for( int c = m_offset.y(); c < expected_dim.y(); c++ ) { const std::string row = default_rows ? default_row : parray.get_string( c ); static std::vector row_keys; row_keys.clear(); - row_keys.reserve( total_size.x ); + row_keys.reserve( total_size.x() ); utf8_display_split_into( row, row_keys ); - if( row_keys.size() < static_cast( expected_dim.x ) ) { + if( row_keys.size() < static_cast( expected_dim.x() ) ) { cata_assert( !default_rows ); parray.throw_error( string_format( "format: row %d must have at least %d columns, not %d", - c + 1, expected_dim.x, row_keys.size() ) ); + c + 1, expected_dim.x(), row_keys.size() ) ); } - if( row_keys.size() != static_cast( total_size.x ) ) { + if( row_keys.size() != static_cast( total_size.x() ) ) { cata_assert( !default_rows ); parray.throw_error( string_format( "format: row %d must have %d columns, not %d; check mapgensize if applicable", - c + 1, total_size.x, row_keys.size() ) ); + c + 1, total_size.x(), row_keys.size() ) ); } - for( int i = m_offset.x(); i < expected_dim.x; i++ ) { + for( int i = m_offset.x(); i < expected_dim.x(); i++ ) { const tripoint_rel_ms p = tripoint_rel_ms( i, c, 0 ) - m_offset; const map_key key{ std::string( row_keys[i] ) }; const auto iter_ter = keys_with_terrain.find( key ); @@ -4864,14 +4864,15 @@ void mapgen_function_json_base::check_common() const objects.check( context_, parameters ); } -void mapgen_function_json_base::add_placement_coords_to( std::unordered_set &result ) const +void mapgen_function_json_base::add_placement_coords_to( std::unordered_set &result ) +const { objects.add_placement_coords_to( result ); } -std::unordered_set nested_mapgen::all_placement_coords() const +std::unordered_set nested_mapgen::all_placement_coords() const { - std::unordered_set result; + std::unordered_set result; for( const weighted_object> &o : funcs_ ) { o.obj->add_placement_coords_to( result ); } @@ -4911,7 +4912,7 @@ void jmapgen_objects::merge_parameters_into( mapgen_parameters ¶ms, } } -void jmapgen_objects::add_placement_coords_to( std::unordered_set &result ) const +void jmapgen_objects::add_placement_coords_to( std::unordered_set &result ) const { for( const jmapgen_obj &obj : objects ) { const jmapgen_place &where = obj.first; @@ -5187,11 +5188,11 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const tripoint_rel_ms &offset } break; case JMAPGEN_SETMAP_SQUARE_TRAP: { - const point c( x_get(), y_get() ); + const point_rel_ms c( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = c.x; tx <= cx2; tx++ ) { - for( int ty = c.y; ty <= cy2; ty++ ) { + for( int tx = c.x(); tx <= cx2; tx++ ) { + for( int ty = c.y(); ty <= cy2; ty++ ) { // TODO: the trap_id should be stored separately and not be wrapped in an jmapgen_int mtrap_set( &m, tripoint_bub_ms( tx, ty, z_level ), trap_id( val.get() ), dat.has_flag( jmapgen_flags::avoid_creatures ) ); @@ -5200,11 +5201,11 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const tripoint_rel_ms &offset } break; case JMAPGEN_SETMAP_SQUARE_TRAP_REMOVE: { - const point c( x_get(), y_get() ); + const point_rel_ms c( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = c.x; tx <= cx2; tx++ ) { - for( int ty = c.y; ty <= cy2; ty++ ) { + for( int tx = c.x(); tx <= cx2; tx++ ) { + for( int ty = c.y(); ty <= cy2; ty++ ) { // TODO: the trap_id should be stored separately and not be wrapped in an jmapgen_int mremove_trap( &m, tripoint_bub_ms( tx, ty, z_level ), trap_id( val.get() ).id() ); } @@ -5212,11 +5213,11 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const tripoint_rel_ms &offset } break; case JMAPGEN_SETMAP_SQUARE_CREATURE_REMOVE: { - const point c( x_get(), y_get() ); + const point_rel_ms c( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = c.x; tx <= cx2; tx++ ) { - for( int ty = c.y; ty <= cy2; ty++ ) { + for( int tx = c.x(); tx <= cx2; tx++ ) { + for( int ty = c.y(); ty <= cy2; ty++ ) { Creature *tmp_critter = get_creature_tracker().creature_at( tripoint_abs_ms( m.getglobal( tripoint_bub_ms( tx, ty, z_level ) ) ), true ); @@ -5228,33 +5229,33 @@ bool jmapgen_setmap::apply( const mapgendata &dat, const tripoint_rel_ms &offset } break; case JMAPGEN_SETMAP_SQUARE_ITEM_REMOVE: { - const point c( x_get(), y_get() ); + const point_rel_ms c( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = c.x; tx <= cx2; tx++ ) { - for( int ty = c.y; ty <= cy2; ty++ ) { + for( int tx = c.x(); tx <= cx2; tx++ ) { + for( int ty = c.y(); ty <= cy2; ty++ ) { m.i_clear( tripoint_bub_ms( tx, ty, z_level ) ); } } } break; case JMAPGEN_SETMAP_SQUARE_FIELD_REMOVE: { - const point c( x_get(), y_get() ); + const point_rel_ms c( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = c.x; tx <= cx2; tx++ ) { - for( int ty = c.y; ty <= cy2; ty++ ) { + for( int tx = c.x(); tx <= cx2; tx++ ) { + for( int ty = c.y(); ty <= cy2; ty++ ) { mremove_fields( &m, tripoint_bub_ms( tx, ty, z_level ) ); } } } break; case JMAPGEN_SETMAP_SQUARE_RADIATION: { - const point c2( x_get(), y_get() ); + const point_rel_ms c2( x_get(), y_get() ); const int cx2 = x2_get(); const int cy2 = y2_get(); - for( int tx = c2.x; tx <= cx2; tx++ ) { - for( int ty = c2.y; ty <= cy2; ty++ ) { + for( int tx = c2.x(); tx <= cx2; tx++ ) { + for( int ty = c2.y(); ty <= cy2; ty++ ) { m.set_radiation( tripoint_bub_ms( tx, ty, z_level ), static_cast( val.get() ) ); } } @@ -6687,11 +6688,6 @@ void map::place_vending( const tripoint_bub_ms &p, const item_group_id &type, bo } } -character_id map::place_npc( const point &p, const string_id &type ) -{ - return map::place_npc( point_bub_ms( p ), type ); -} - character_id map::place_npc( const point_bub_ms &p, const string_id &type ) { shared_ptr_fast temp = make_shared_fast(); @@ -6703,12 +6699,13 @@ character_id map::place_npc( const point_bub_ms &p, const string_idgetID(); } -void map::apply_faction_ownership( const point &p1, const point &p2, const faction_id &id ) +void map::apply_faction_ownership( const point_bub_ms &p1, const point_bub_ms &p2, + const faction_id &id ) { - for( const tripoint_bub_ms &p : points_in_rectangle( tripoint_bub_ms( p1.x, p1.y, abs_sub.z() ), - tripoint_bub_ms( p2.x, p2.y, + for( const tripoint_bub_ms &p : points_in_rectangle( tripoint_bub_ms( p1, abs_sub.z() ), + tripoint_bub_ms( p2, abs_sub.z() ) ) ) { - map_stack items = i_at( point_bub_ms( p.xy() ) ); + map_stack items = i_at( p.xy() ); for( item &elem : items ) { elem.set_owner( id ); } @@ -6870,14 +6867,6 @@ void map::add_spawn( data ); } -vehicle *map::add_vehicle( const vproto_id &type, const tripoint &p, const units::angle &dir, - const int veh_fuel, const int veh_status, const bool merge_wrecks, - const bool force_status/* = false*/ ) -{ - return map::add_vehicle( type, tripoint_bub_ms( p ), dir, veh_fuel, veh_status, merge_wrecks, - force_status ); -} - vehicle *map::add_vehicle( const vproto_id &type, const tripoint_bub_ms &p, const units::angle &dir, const int veh_fuel, const int veh_status, const bool merge_wrecks, const bool force_status/* = false*/ ) @@ -7179,17 +7168,17 @@ void map::rotate( int turns ) std::swap( *pz, *pse ); std::swap( *pe, *ps ); } else { - point p; + point_rel_sm p; submap tmp; std::swap( *pse, tmp ); 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_rel_sm( tmpp.x, tmpp.y, z_level ) ); + point_rel_sm tmpp = point_rel_sm::south_east - p; + submap *psep = get_submap_at_grid( tripoint_rel_sm( tmpp, z_level ) ); if( psep == nullptr ) { - debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", tmpp.x, tmpp.y ); + debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", tmpp.x(), tmpp.y() ); continue; } std::swap( *psep, tmp ); @@ -7199,17 +7188,17 @@ void map::rotate( int turns ) // Then rotate them and recalculate vehicle positions. 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_rel_sm( p.x, p.y, z_level ) ); + point_rel_sm p( i, j ); + submap *sm = get_submap_at_grid( tripoint_rel_sm( p, z_level ) ); if( sm == nullptr ) { - debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", p.x, p.y ); + debugmsg( "Tried to rotate map at (%d,%d) but the submap is not loaded", p.x(), p.y() ); continue; } sm->rotate( turns ); for( auto &veh : sm->vehicles ) { - veh->sm_pos = tripoint( p, z_level ); + veh->sm_pos = tripoint( p.raw(), z_level ); } update_vehicle_list( sm, z_level ); diff --git a/src/mapgen.h b/src/mapgen.h index bd907759a0ae2..f332022cc177d 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -398,7 +398,8 @@ class mapgen_palette struct jmapgen_objects { - jmapgen_objects( const tripoint_rel_ms &offset, const point &mapsize, const point &tot_size ); + jmapgen_objects( const tripoint_rel_ms &offset, const point_rel_ms &mapsize, + const point_rel_ms &tot_size ); bool check_bounds( const jmapgen_place &place, const JsonObject &jso ); @@ -425,7 +426,7 @@ struct jmapgen_objects { void merge_parameters_into( mapgen_parameters &, const std::string &outer_context ) const; - void add_placement_coords_to( std::unordered_set & ) const; + void add_placement_coords_to( std::unordered_set & ) const; void apply( const mapgendata &dat, mapgen_phase, const std::string &context ) const; void apply( const mapgendata &dat, mapgen_phase, const tripoint_rel_ms &offset, @@ -444,8 +445,8 @@ struct jmapgen_objects { using jmapgen_obj = std::pair >; std::vector objects; tripoint_rel_ms m_offset; - point mapgensize; - point total_size; + point_rel_ms mapgensize; + point_rel_ms total_size; }; class mapgen_function_json_base @@ -458,7 +459,7 @@ class mapgen_function_json_base size_t calc_index( const point &p ) const; ret_val has_vehicle_collision( const mapgendata &dat, const tripoint_rel_ms &offset ) const; - void add_placement_coords_to( std::unordered_set & ) const; + void add_placement_coords_to( std::unordered_set & ) const; const mapgen_parameters &get_parameters() const { return parameters; @@ -486,9 +487,9 @@ class mapgen_function_json_base enum_bitset flags_; bool is_ready; - point mapgensize; + point_rel_ms mapgensize; tripoint_rel_ms m_offset; - point total_size; + point_rel_ms total_size; std::vector setmap_points; jmapgen_objects objects; @@ -574,7 +575,7 @@ class nested_mapgen void add( const std::shared_ptr &p, int weight ); // Returns a set containing every relative coordinate of a point that // might have something placed by this mapgen - std::unordered_set all_placement_coords() const; + std::unordered_set all_placement_coords() const; private: weighted_int_list> funcs_; }; diff --git a/src/pathfinding.cpp b/src/pathfinding.cpp index a1239e427cd3d..d9db720469098 100644 --- a/src/pathfinding.cpp +++ b/src/pathfinding.cpp @@ -28,9 +28,9 @@ #include "vpart_position.h" // Turns two indexed to a 2D array into an index to equivalent 1D array -static constexpr int flat_index( const point &p ) +static constexpr int flat_index( const point_bub_ms &p ) { - return ( p.x * MAPSIZE_Y ) + p.y; + return ( p.x() * MAPSIZE_Y ) + p.y(); } // Flattened 2D array representing a single z-level worth of pathfinding data @@ -40,7 +40,7 @@ struct path_data_layer { std::bitset< MAPSIZE_X *MAPSIZE_Y > open; std::array< int, MAPSIZE_X *MAPSIZE_Y > score; std::array< int, MAPSIZE_X *MAPSIZE_Y > gscore; - std::array< tripoint, MAPSIZE_X *MAPSIZE_Y > parent; + std::array< tripoint_bub_ms, MAPSIZE_X *MAPSIZE_Y > parent; void reset() { closed.reset(); @@ -50,7 +50,7 @@ struct path_data_layer { struct pathfinder { using queue_type = - std::priority_queue< std::pair, std::vector< std::pair >, pair_greater_cmp_first >; + std::priority_queue< std::pair, std::vector< std::pair >, pair_greater_cmp_first >; queue_type open; std::array< std::unique_ptr< path_data_layer >, OVERMAP_LAYERS > path_data; @@ -77,14 +77,15 @@ struct pathfinder { return open.empty(); } - tripoint get_next() { + tripoint_bub_ms get_next() { const auto pt = open.top(); open.pop(); return pt.second; } - void add_point( const int gscore, const int score, const tripoint &from, const tripoint &to ) { - path_data_layer &layer = get_layer( to.z ); + void add_point( const int gscore, const int score, const tripoint_bub_ms &from, + const tripoint_bub_ms &to ) { + path_data_layer &layer = get_layer( to.z() ); const int index = flat_index( to.xy() ); if( layer.closed[index] ) { return; @@ -100,14 +101,14 @@ struct pathfinder { open.emplace( score, to ); } - void close_point( const tripoint &p ) { - path_data_layer &layer = get_layer( p.z ); + void close_point( const tripoint_bub_ms &p ) { + path_data_layer &layer = get_layer( p.z() ); const int index = flat_index( p.xy() ); layer.closed[index] = true; } - void unclose_point( const tripoint &p ) { - path_data_layer &layer = get_layer( p.z ); + void unclose_point( const tripoint_bub_ms &p ) { + path_data_layer &layer = get_layer( p.z() ); const int index = flat_index( p.xy() ); layer.closed[index] = false; } @@ -118,14 +119,14 @@ static pathfinder pf; // Modifies `t` to point to a tile with `flag` in a 1-submap radius of `t`'s original value, // searching nearest points first (starting with `t` itself). // return false if it could not find a suitable point -static bool vertical_move_destination( const map &m, ter_furn_flag flag, tripoint &t ) +static bool vertical_move_destination( const map &m, ter_furn_flag flag, tripoint_bub_ms &t ) { - const pathfinding_cache &pf_cache = m.get_pathfinding_cache_ref( t.z ); - for( const point &p : closest_points_first( t.xy(), SEEX ) ) { - if( pf_cache.special[p.x][p.y] & ( PathfindingFlag::GoesDown | PathfindingFlag::GoesUp ) ) { - const tripoint_bub_ms t2( p.x, p.y, t.z ); + const pathfinding_cache &pf_cache = m.get_pathfinding_cache_ref( t.z() ); + for( const point_bub_ms &p : closest_points_first( t.xy(), SEEX ) ) { + if( pf_cache.special[p.x()][p.y()] & ( PathfindingFlag::GoesDown | PathfindingFlag::GoesUp ) ) { + const tripoint_bub_ms t2( p, t.z() ); if( m.has_flag( flag, t2 ) ) { - t = t2.raw(); + t = t2; return true; } } @@ -422,14 +423,14 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin pf.reset( min.z(), max.z() ); - pf.add_point( 0, 0, f.raw(), f.raw() ); + pf.add_point( 0, 0, f, f ); bool done = false; do { tripoint_bub_ms cur( pf.get_next() ); - const int parent_index = flat_index( cur.xy().raw() ); + const int parent_index = flat_index( cur.xy() ); path_data_layer &layer = pf.get_layer( cur.z() ); if( layer.closed[parent_index] ) { continue; @@ -457,7 +458,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin constexpr std::array y_offset{ { 0, 0, -1, 1, -1, 1, -1, 1 } }; for( size_t i = 0; i < 8; i++ ) { const tripoint_bub_ms p( cur.x() + x_offset[i], cur.y() + y_offset[i], cur.z() ); - const int index = flat_index( p.xy().raw() ); + const int index = flat_index( p.xy() ); // TODO: Remove this and instead have sentinels at the edges if( p.x() < min.x() || p.x() >= max.x() || p.y() < min.y() || p.y() >= max.y() ) { @@ -504,7 +505,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin // From cur, not p, because we won't be walking on air pf.add_point( layer.gscore[parent_index] + 10, layer.score[parent_index] + 10 + 2 * rl_dist( below, t ), - cur.raw(), below.raw() ); + cur, below ); } // Close p, because we won't be walking on it @@ -514,7 +515,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin } } - pf.add_point( newg, newg + 2 * rl_dist( p, t ), cur.raw(), p.raw() ); + pf.add_point( newg, newg + 2 * rl_dist( p, t ), cur, p ); } // TODO: We should be able to go up ramps even if we can't climb stairs. @@ -535,14 +536,14 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin continue; } tripoint_bub_ms dest( opt_dest.value() ); - if( vertical_move_destination( *this, ter_furn_flag::TFLAG_GOES_UP, dest.raw() ) ) { + if( vertical_move_destination( *this, ter_furn_flag::TFLAG_GOES_UP, dest ) ) { if( !inbounds( dest ) ) { continue; } path_data_layer &layer = pf.get_layer( dest.z() ); pf.add_point( layer.gscore[parent_index] + 2, layer.score[parent_index] + 2 * rl_dist( dest, t ), - cur.raw(), dest.raw() ); + cur, dest ); } } if( settings.allow_climb_stairs && cur.z() < max.z() && @@ -553,14 +554,14 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin continue; } tripoint_bub_ms dest( opt_dest.value() ); - if( vertical_move_destination( *this, ter_furn_flag::TFLAG_GOES_DOWN, dest.raw() ) ) { + if( vertical_move_destination( *this, ter_furn_flag::TFLAG_GOES_DOWN, dest ) ) { if( !inbounds( dest ) ) { continue; } path_data_layer &layer = pf.get_layer( dest.z() ); pf.add_point( layer.gscore[parent_index] + 2, layer.score[parent_index] + 2 * rl_dist( dest, t ), - cur.raw(), dest.raw() ); + cur, dest ); } } if( cur.z() < max.z() && parent_terrain.has_flag( ter_furn_flag::TFLAG_RAMP ) && @@ -573,7 +574,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin } pf.add_point( layer.gscore[parent_index] + 4, layer.score[parent_index] + 4 + 2 * rl_dist( above, t ), - cur.raw(), above.raw() ); + cur, above ); } } if( cur.z() < max.z() && parent_terrain.has_flag( ter_furn_flag::TFLAG_RAMP_UP ) && @@ -586,7 +587,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin } pf.add_point( layer.gscore[parent_index] + 4, layer.score[parent_index] + 4 + 2 * rl_dist( above, t ), - cur.raw(), above.raw() ); + cur, above ); } } if( cur.z() > min.z() && parent_terrain.has_flag( ter_furn_flag::TFLAG_RAMP_DOWN ) && @@ -599,7 +600,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin } pf.add_point( layer.gscore[parent_index] + 4, layer.score[parent_index] + 4 + 2 * rl_dist( below, t ), - cur.raw(), below.raw() ); + cur, below ); } } @@ -610,7 +611,7 @@ std::vector map::route( const tripoint_bub_ms &f, const tripoin tripoint_bub_ms cur = t; // Just to limit max distance, in case something weird happens for( int fdist = max_length; fdist != 0; fdist-- ) { - const int cur_index = flat_index( cur.raw().xy() ); + const int cur_index = flat_index( cur.xy() ); const path_data_layer &layer = pf.get_layer( cur.z() ); const tripoint_bub_ms &par = tripoint_bub_ms( layer.parent[cur_index] ); if( cur == f ) { diff --git a/src/pixel_minimap.cpp b/src/pixel_minimap.cpp index 7d64b3cfb5d11..87bcfb3b5b803 100644 --- a/src/pixel_minimap.cpp +++ b/src/pixel_minimap.cpp @@ -83,7 +83,7 @@ SDL_Texture_Ptr create_cache_texture( const SDL_Renderer_Ptr &renderer, int tile tile_height ); } -SDL_Color get_map_color_at( const tripoint &p ) +SDL_Color get_map_color_at( const tripoint_bub_ms &p ) { const map &here = get_map(); if( const optional_vpart_position vp = here.veh_at( p ) ) { @@ -226,11 +226,12 @@ void pixel_minimap::set_settings( const pixel_minimap_settings &settings ) reset(); } -void pixel_minimap::prepare_cache_for_updates( const tripoint ¢er ) +void pixel_minimap::prepare_cache_for_updates( const tripoint_bub_ms ¢er ) { - const tripoint_abs_sm new_center_sm = get_map().get_abs_sub() + coords::project_to - ( tripoint_bub_ms( center ) ).raw(); - const tripoint_rel_sm center_sm_diff = tripoint_abs_sm( cached_center_sm ) - new_center_sm; + const tripoint_abs_sm new_center_sm = get_map().get_abs_sub() + rebase_rel( + coords::project_to + ( center ) ); + const tripoint_rel_sm center_sm_diff = cached_center_sm - new_center_sm; //invalidate the cache if the game shifted more than one submap in the last update, or if z-level changed. if( std::abs( center_sm_diff.x() ) > 1 || @@ -243,7 +244,7 @@ void pixel_minimap::prepare_cache_for_updates( const tripoint ¢er ) } } - cached_center_sm = new_center_sm.raw(); + cached_center_sm = new_center_sm; } //deletes the mapping of unused submap caches from the main map @@ -300,22 +301,21 @@ void pixel_minimap::flush_cache_updates() } } -void pixel_minimap::update_cache_at( const tripoint &sm_pos ) +void pixel_minimap::update_cache_at( const tripoint_bub_sm &sm_pos ) { const map &here = get_map(); - const level_cache &access_cache = here.access_cache( sm_pos.z ); + const level_cache &access_cache = here.access_cache( sm_pos.z() ); const bool nv_goggle = get_player_character().get_vision_modes()[NV_GOGGLES]; - // TODO: fix point types - submap_cache &cache_item = get_cache_at( here.get_abs_sub().raw() + sm_pos ); - const tripoint_bub_ms ms_pos = coords::project_to( tripoint_bub_sm( sm_pos ) ); + submap_cache &cache_item = get_cache_at( here.get_abs_sub() + rebase_rel( sm_pos ) ); + const tripoint_bub_ms ms_pos = coords::project_to( sm_pos ); cache_item.touched = true; for( int y = 0; y < SEEY; ++y ) { for( int x = 0; x < SEEX; ++x ) { - const tripoint p = ms_pos.raw() + tripoint{x, y, 0}; - const lit_level lighting = access_cache.visibility_cache[p.x][p.y]; + const tripoint_bub_ms p = ms_pos + tripoint{x, y, 0}; + const lit_level lighting = access_cache.visibility_cache[p.x()][p.y()]; SDL_Color color; @@ -349,7 +349,7 @@ void pixel_minimap::update_cache_at( const tripoint &sm_pos ) } } -pixel_minimap::submap_cache &pixel_minimap::get_cache_at( const tripoint &abs_sm_pos ) +pixel_minimap::submap_cache &pixel_minimap::get_cache_at( const tripoint_abs_sm &abs_sm_pos ) { auto it = cache.find( abs_sm_pos ); @@ -360,13 +360,13 @@ pixel_minimap::submap_cache &pixel_minimap::get_cache_at( const tripoint &abs_sm return it->second; } -void pixel_minimap::process_cache( const tripoint ¢er ) +void pixel_minimap::process_cache( const tripoint_bub_ms ¢er ) { prepare_cache_for_updates( center ); for( int y = 0; y < MAPSIZE; ++y ) { for( int x = 0; x < MAPSIZE; ++x ) { - update_cache_at( { x, y, center.z } ); + update_cache_at( { x, y, center.z()} ); } } @@ -436,7 +436,7 @@ void pixel_minimap::reset() tex_pool.reset(); } -void pixel_minimap::render( const tripoint ¢er ) +void pixel_minimap::render( const tripoint_bub_ms ¢er ) { SetRenderTarget( renderer, main_tex ); SetRenderDrawColor( renderer, pixel_minimap_r, pixel_minimap_g, pixel_minimap_b, pixel_minimap_a ); @@ -451,48 +451,48 @@ void pixel_minimap::render( const tripoint ¢er ) RenderCopy( renderer, main_tex, &main_tex_clip_rect, &screen_clip_rect ); } -void pixel_minimap::render_cache( const tripoint ¢er ) +void pixel_minimap::render_cache( const tripoint_bub_ms ¢er ) { - // TODO: fix point types - const tripoint_abs_sm sm_center = get_map().get_abs_sub() + coords::project_to - ( tripoint_bub_ms( center ) ).raw(); + const tripoint_abs_sm sm_center = get_map().get_abs_sub() + rebase_rel( + coords::project_to + ( center ) ); const tripoint_rel_sm sm_offset { total_tiles_count.x / SEEX / 2, total_tiles_count.y / SEEY / 2, 0 }; - point ms_offset; + point_rel_ms ms_offset; tripoint_bub_sm quotient; point_sm_ms remainder; - std::tie( quotient, remainder ) = coords::project_remain( tripoint_bub_ms( center ) ); + std::tie( quotient, remainder ) = coords::project_remain( center ); - point ms_base_offset = point( ( total_tiles_count.x / 2 ) % SEEX, - ( total_tiles_count.y / 2 ) % SEEY ); - ms_offset = ms_base_offset - remainder.raw(); + point_sm_ms ms_base_offset = point_sm_ms( ( total_tiles_count.x / 2 ) % SEEX, + ( total_tiles_count.y / 2 ) % SEEY ); + ms_offset = ms_base_offset - remainder; for( const auto &elem : cache ) { if( !elem.second.touched ) { continue; // What you gonna do with all that junk? } - const tripoint rel_pos = elem.first - sm_center.raw(); + const tripoint_rel_sm rel_pos = elem.first - sm_center; - if( std::abs( rel_pos.x ) > sm_offset.x() + 1 || - std::abs( rel_pos.y ) > sm_offset.y() + 1 || - rel_pos.z != 0 ) { + if( std::abs( rel_pos.x() ) > sm_offset.x() + 1 || + std::abs( rel_pos.y() ) > sm_offset.y() + 1 || + rel_pos.z() != 0 ) { continue; } const tripoint_rel_sm sm_pos = tripoint_rel_sm( rel_pos ) + sm_offset; - const tripoint ms_pos = coords::project_to( sm_pos ).raw() + ms_offset; + const tripoint_rel_ms ms_pos = coords::project_to( sm_pos ) + ms_offset; - const SDL_Rect chunk_rect = projector->get_chunk_rect( ms_pos.xy(), { SEEX, SEEY } ); + const SDL_Rect chunk_rect = projector->get_chunk_rect( ms_pos.xy().raw(), {SEEX, SEEY} ); RenderCopy( renderer, elem.second.chunk_tex, nullptr, &chunk_rect ); } } -void pixel_minimap::render_critters( const tripoint ¢er ) +void pixel_minimap::render_critters( const tripoint_bub_ms ¢er ) { //handles the enemy faction red highlights //this value should be divisible by 200 @@ -510,9 +510,10 @@ void pixel_minimap::render_critters( const tripoint ¢er ) } const map &m = get_map(); - const level_cache &access_cache = m.access_cache( center.z ); + const level_cache &access_cache = m.access_cache( center.z() ); - const point start( center.x - total_tiles_count.x / 2, center.y - total_tiles_count.y / 2 ); + const point_rel_ms start( center.x() - total_tiles_count.x / 2, + center.y() - total_tiles_count.y / 2 ); const point beacon_size = { std::max( projector->get_tile_size().x *settings.beacon_size / 2, 2 ), std::max( projector->get_tile_size().y *settings.beacon_size / 2, 2 ) @@ -521,7 +522,7 @@ void pixel_minimap::render_critters( const tripoint ¢er ) creature_tracker &creatures = get_creature_tracker(); for( int y = 0; y < total_tiles_count.y; y++ ) { for( int x = 0; x < total_tiles_count.x; x++ ) { - const tripoint_bub_ms p = start + tripoint_bub_ms( x, y, center.z ); + const tripoint_bub_ms p = start + tripoint_bub_ms( x, y, center.z() ); if( !m.inbounds( p ) ) { // p might be out-of-bounds when peeking at submap boundary. Example: center=(64,59,-5), start=(4,-1) -> p=(4,-1,-5) continue; @@ -559,8 +560,8 @@ void pixel_minimap::draw( const SDL_Rect &screen_rect, const tripoint_bub_ms &ce } set_screen_rect( screen_rect ); - process_cache( center.raw() ); - render( center.raw() ); + process_cache( center ); + render( center ); } void pixel_minimap::draw_beacon( const SDL_Rect &rect, const SDL_Color &color ) diff --git a/src/pixel_minimap.h b/src/pixel_minimap.h index a4333ed0fb8a3..9e38b4a66d9ca 100644 --- a/src/pixel_minimap.h +++ b/src/pixel_minimap.h @@ -5,7 +5,7 @@ #include #include -#include "coords_fwd.h" +#include "coordinates.h" #include "point.h" #include "sdl_wrappers.h" #include "sdl_geometry.h" @@ -46,23 +46,23 @@ class pixel_minimap private: struct submap_cache; - submap_cache &get_cache_at( const tripoint &abs_sm_pos ); + submap_cache &get_cache_at( const tripoint_abs_sm &abs_sm_pos ); void set_screen_rect( const SDL_Rect &screen_rect ); void reset(); void draw_beacon( const SDL_Rect &rect, const SDL_Color &color ); - void process_cache( const tripoint ¢er ); + void process_cache( const tripoint_bub_ms ¢er ); void flush_cache_updates(); - void update_cache_at( const tripoint &pos ); - void prepare_cache_for_updates( const tripoint ¢er ); + void update_cache_at( const tripoint_bub_sm &pos ); + void prepare_cache_for_updates( const tripoint_bub_ms ¢er ); void clear_unused_cache(); - void render( const tripoint ¢er ); - void render_cache( const tripoint ¢er ); - void render_critters( const tripoint ¢er ); + void render( const tripoint_bub_ms ¢er ); + void render_cache( const tripoint_bub_ms ¢er ); + void render_critters( const tripoint_bub_ms ¢er ); std::unique_ptr create_projector( const SDL_Rect &max_screen_rect ) const; @@ -75,7 +75,7 @@ class pixel_minimap point pixel_size; //track the previous viewing area to determine if the minimap cache needs to be cleared - tripoint cached_center_sm; + tripoint_abs_sm cached_center_sm; SDL_Rect screen_rect; SDL_Rect main_tex_clip_rect; @@ -89,7 +89,7 @@ class pixel_minimap class shared_texture_pool; std::unique_ptr tex_pool; - std::map cache; + std::map cache; }; #endif // CATA_SRC_PIXEL_MINIMAP_H diff --git a/src/savegame_json.cpp b/src/savegame_json.cpp index d15271307e596..25f20ab543296 100644 --- a/src/savegame_json.cpp +++ b/src/savegame_json.cpp @@ -218,10 +218,11 @@ static void deserialize( weak_ptr_fast &obj, const JsonObject &data ) // } } -static tripoint read_legacy_creature_pos( const JsonObject &data ) +static tripoint_bub_ms read_legacy_creature_pos( const JsonObject &data ) { - tripoint pos; - if( !data.read( "posx", pos.x ) || !data.read( "posy", pos.y ) || !data.read( "posz", pos.z ) ) { + tripoint_bub_ms pos; + if( !data.read( "posx", pos.x() ) || !data.read( "posy", pos.y() ) || + !data.read( "posz", pos.z() ) ) { debugmsg( R"(Bad Creature JSON: neither "location" nor "posx", "posy", "posz" found)" ); } return pos; @@ -2059,15 +2060,15 @@ void npc::load( const JsonObject &data ) if( !data.has_member( "location" ) ) { point submap_coords; data.read( "submap_coords", submap_coords ); - const tripoint pos = read_legacy_creature_pos( data ); + const tripoint_bub_ms pos = read_legacy_creature_pos( data ); set_location( tripoint_abs_ms( project_to( point_abs_sm( submap_coords ) ), - 0 ) + tripoint( pos.x % SEEX, pos.y % SEEY, pos.z ) ); - std::optional opt; + 0 ) + tripoint( pos.x() % SEEX, pos.y() % SEEY, pos.z() ) ); + std::optional opt; if( data.read( "last_player_seen_pos", opt ) && opt ) { - last_player_seen_pos = get_location() + *opt - pos; + last_player_seen_pos = get_location() + ( *opt - pos ); } if( data.read( "pulp_location", opt ) && opt ) { - pulp_location = get_location() + *opt - pos; + pulp_location = get_location() + ( *opt - pos ); } tripoint tmp; if( data.read( "guardx", tmp.x ) && data.read( "guardy", tmp.y ) && data.read( "guardz", tmp.z ) && @@ -2434,10 +2435,10 @@ void monster::load( const JsonObject &data ) // TEMPORARY until 0.G if( !data.has_member( "location" ) ) { set_location( get_map().getglobal( read_legacy_creature_pos( data ) ) ); - tripoint wand; - data.read( "wandx", wand.x ); - data.read( "wandy", wand.y ); - data.read( "wandz", wand.z ); + tripoint_bub_ms wand; + data.read( "wandx", wand.x() ); + data.read( "wandy", wand.y() ); + data.read( "wandz", wand.z() ); wander_pos = get_map().getglobal( wand ); tripoint destination; data.read( "destination", destination ); diff --git a/src/veh_appliance.cpp b/src/veh_appliance.cpp index bb1c99669c663..663842cb306f0 100644 --- a/src/veh_appliance.cpp +++ b/src/veh_appliance.cpp @@ -617,7 +617,7 @@ void veh_app_interact::populate_app_actions() /*************** Get part-specific actions ***************/ veh_menu menu( veh, "IF YOU SEE THIS IT IS A BUG" ); - veh->build_interact_menu( menu, veh->mount_to_tripoint( a_point ).raw(), false ); + veh->build_interact_menu( menu, veh->mount_to_tripoint( a_point ), false ); const std::vector items = menu.get_items(); for( size_t i = 0; i < items.size(); i++ ) { const veh_menu_item &it = items[i]; diff --git a/src/vehicle.h b/src/vehicle.h index 0a680fa1b7634..f73e4540e6f70 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -2160,8 +2160,7 @@ class vehicle void build_electronics_menu( veh_menu &menu ); void build_bike_rack_menu( veh_menu &menu, int part ); - // TODO: Make it typed. One call uses bubble coordinates, the other untyped veh_app_interact::a_point - void build_interact_menu( veh_menu &menu, const tripoint &p, bool with_pickup ); + void build_interact_menu( veh_menu &menu, const tripoint_bub_ms &p, bool with_pickup ); void interact_with( const tripoint_bub_ms &p, bool with_pickup = false ); std::string disp_name() const; diff --git a/src/vehicle_use.cpp b/src/vehicle_use.cpp index 1e98023c8c9b7..c7e452bd61e21 100644 --- a/src/vehicle_use.cpp +++ b/src/vehicle_use.cpp @@ -1825,7 +1825,7 @@ bool vehicle::use_vehicle_tool( vehicle &veh, const tripoint_bub_ms &vp_pos, return true; } -void vehicle::build_interact_menu( veh_menu &menu, const tripoint &p, bool with_pickup ) +void vehicle::build_interact_menu( veh_menu &menu, const tripoint_bub_ms &p, bool with_pickup ) { const optional_vpart_position ovp = get_map().veh_at( p ); if( !ovp ) { @@ -2448,6 +2448,6 @@ void vehicle::interact_with( const tripoint_bub_ms &p, bool with_pickup ) veh_menu menu( *this, _( "Select an action" ) ); do { menu.reset(); - build_interact_menu( menu, p.raw(), with_pickup ); + build_interact_menu( menu, p, with_pickup ); } while( menu.query() ); } diff --git a/tests/degradation_test.cpp b/tests/degradation_test.cpp index 5d806a574153c..791d3c673753c 100644 --- a/tests/degradation_test.cpp +++ b/tests/degradation_test.cpp @@ -268,7 +268,7 @@ TEST_CASE( "Repairing_degraded_items", "[item][degradation]" ) // Setup map clear_map(); set_time_to_day(); - REQUIRE( static_cast( get_map().light_at( spawn_pos.raw() ) ) > 2 ); + REQUIRE( static_cast( get_map().light_at( spawn_pos ) ) > 2 ); GIVEN( "Item with normal degradation" ) { Character &u = get_player_character(); @@ -663,7 +663,7 @@ TEST_CASE( "refit_item_inside_spillable_container", "[item][repair][container]" clear_avatar(); clear_map(); set_time_to_day(); - REQUIRE( static_cast( get_map().light_at( spawn_pos.raw() ) ) > 2 ); + REQUIRE( static_cast( get_map().light_at( spawn_pos ) ) > 2 ); Character &u = get_player_character(); u.set_skill_level( skill_tailor, 10 ); diff --git a/tests/map_test.cpp b/tests/map_test.cpp index 08d81f551f8fe..299f24d806286 100644 --- a/tests/map_test.cpp +++ b/tests/map_test.cpp @@ -29,8 +29,10 @@ TEST_CASE( "map_coordinate_conversion_functions" ) here.vertical_shift( 0 ); } ); - tripoint test_point = - GENERATE( tripoint::zero, tripoint::south, tripoint::east, tripoint::above, tripoint::below ); + tripoint_bub_ms test_point = + GENERATE( tripoint_bub_ms::zero, tripoint_bub_ms::zero + tripoint::south, + tripoint_bub_ms::zero + tripoint::east, tripoint_bub_ms::zero + tripoint::above, + tripoint_bub_ms::zero + tripoint::below ); tripoint_bub_ms test_bub( test_point ); int z = GENERATE( 0, 1, -1, OVERMAP_HEIGHT, -OVERMAP_DEPTH ); @@ -51,7 +53,7 @@ TEST_CASE( "map_coordinate_conversion_functions" ) point_abs_ms map_origin_ms = project_to( here.get_abs_sub().xy() ); - tripoint_abs_ms test_abs = map_origin_ms + test_point; + tripoint_abs_ms test_abs = map_origin_ms + rebase_rel( test_point ); if( test_abs.z() > OVERMAP_HEIGHT || test_abs.z() < -OVERMAP_DEPTH ) { return; @@ -62,7 +64,7 @@ TEST_CASE( "map_coordinate_conversion_functions" ) // Verify round-tripping CHECK( here.getglobal( here.bub_from_abs( test_abs ) ) == test_abs ); - CHECK( here.bub_from_abs( here.getglobal( test_point ) ).raw() == test_point ); + CHECK( here.bub_from_abs( here.getglobal( test_point ) ) == test_point ); } TEST_CASE( "destroy_grabbed_furniture" ) diff --git a/tests/mapgen_remove_npcs_test.cpp b/tests/mapgen_remove_npcs_test.cpp index fcbfb52169c26..c84c180080d98 100644 --- a/tests/mapgen_remove_npcs_test.cpp +++ b/tests/mapgen_remove_npcs_test.cpp @@ -19,7 +19,7 @@ static const update_mapgen_id update_mapgen_test_update_remove_npc( "test_update namespace { -void check_creature( tripoint const &loc, string_id const &id, bool state ) +void check_creature( tripoint_bub_ms const &loc, string_id const &id, bool state ) { Creature *critter = get_creature_tracker().creature_at( loc, true ); if( state ) { @@ -30,7 +30,7 @@ void check_creature( tripoint const &loc, string_id const &id, boo } } -void place_npc_and_check( map &m, tripoint const &loc, update_mapgen_id const &id, +void place_npc_and_check( map &m, tripoint_bub_ms const &loc, update_mapgen_id const &id, string_id const &nid ) { check_creature( loc, nid, false ); @@ -40,7 +40,7 @@ void place_npc_and_check( map &m, tripoint const &loc, update_mapgen_id const &i g->mon_info_update(); } -void remove_npc_and_check( map &m, tripoint const &loc, update_mapgen_id const &id, +void remove_npc_and_check( map &m, tripoint_bub_ms const &loc, update_mapgen_id const &id, string_id const &nid ) { check_creature( loc, nid, true ); @@ -74,16 +74,16 @@ TEST_CASE( "mapgen_remove_npcs" ) tripoint_bub_ms const loc2 = here.bub_from_abs( project_to( omt2 ) ); tripoint_bub_ms const loc3 = loc2 + tripoint::east; REQUIRE( get_map().inbounds( loc ) ); - place_npc_and_check( here, loc.raw(), update_mapgen_test_update_place_npc, + place_npc_and_check( here, loc, update_mapgen_test_update_place_npc, npc_template_test_npc_trader ); REQUIRE( overmap_buffer.get_npcs_near_omt( omt, 0 ).size() == 1 ); - place_npc_and_check( here, loc2.raw(), update_mapgen_test_update_place_npc, + place_npc_and_check( here, loc2, update_mapgen_test_update_place_npc, npc_template_test_npc_trader ); REQUIRE( overmap_buffer.get_npcs_near_omt( omt2, 0 ).size() == 1 ); REQUIRE( get_avatar().sees( loc, true ) ); WHEN( "removing NPC" ) { - remove_npc_and_check( here, loc.raw(), update_mapgen_test_update_remove_npc, + remove_npc_and_check( here, loc, update_mapgen_test_update_remove_npc, npc_template_test_npc_trader ); THEN( "NPC of same class on different submap not affected" ) { REQUIRE( overmap_buffer.get_npcs_near_omt( omt, 0 ).empty() ); @@ -91,13 +91,13 @@ TEST_CASE( "mapgen_remove_npcs" ) } THEN( "NPC of different class on same submap not affected" ) { - place_npc_and_check( here, loc3.raw(), update_mapgen_test_update_place_npc_thug, + place_npc_and_check( here, loc3, update_mapgen_test_update_place_npc_thug, npc_template_thug ); REQUIRE( overmap_buffer.get_npcs_near_omt( omt2, 0 ).size() == 2 ); - remove_npc_and_check( here, loc2.raw(), update_mapgen_test_update_remove_npc, + remove_npc_and_check( here, loc2, update_mapgen_test_update_remove_npc, npc_template_test_npc_trader ); REQUIRE( overmap_buffer.get_npcs_near_omt( omt2, 0 ).size() == 1 ); - check_creature( loc3.raw(), npc_template_thug, true ); + check_creature( loc3, npc_template_thug, true ); } } } diff --git a/tests/vehicle_part_test.cpp b/tests/vehicle_part_test.cpp index 323d0eec48784..b3916b51e38f0 100644 --- a/tests/vehicle_part_test.cpp +++ b/tests/vehicle_part_test.cpp @@ -240,7 +240,7 @@ TEST_CASE( "faucet_offers_cold_water", "[vehicle][vehicle_parts]" ) for( int i = 0; i < water_charges; i++ ) { CAPTURE( i, veh.fuel_left( itype_water_clean ) ); menu.reset(); - veh.build_interact_menu( menu, faucet->pos_bub().raw(), false ); + veh.build_interact_menu( menu, faucet->pos_bub(), false ); const std::vector items = menu.get_items(); const bool stomach_should_be_full = i == water_charges - 1; const auto drink_item_it = std::find_if( items.begin(), items.end(),