Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made inbounds use map parameters #73503

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/editmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@
#include "vehicle.h"
#include "vpart_position.h"

static constexpr tripoint editmap_boundary_min( 0, 0, -OVERMAP_DEPTH );
static constexpr tripoint editmap_boundary_max( MAPSIZE_X, MAPSIZE_Y, OVERMAP_HEIGHT + 1 );

static constexpr half_open_cuboid<tripoint> editmap_boundaries(
editmap_boundary_min, editmap_boundary_max );

// NOLINTNEXTLINE(cata-static-int_id-constants)
static const ter_id undefined_ter_id( -1 );

Expand Down Expand Up @@ -1595,7 +1589,7 @@ void editmap::recalc_target( shapetype shape )
map &here = get_map();
for( const tripoint &p : here.points_in_radius( origin, radius ) ) {
if( rl_dist( p, origin ) <= radius ) {
if( editmap_boundaries.contains( p ) ) {
if( here.inbounds( p ) ) {
target_list.push_back( p );
}
}
Expand Down Expand Up @@ -1624,7 +1618,7 @@ void editmap::recalc_target( shapetype shape )
for( int y = s.y; y <= e.y; y++ ) {
if( shape == editmap_rect_filled || x == s.x || x == e.x || y == s.y || y == e.y ) {
const tripoint p( x, y, z );
if( editmap_boundaries.contains( p ) ) {
if( get_map().inbounds( p ) ) {
target_list.push_back( p );
}
}
Expand Down Expand Up @@ -2104,8 +2098,8 @@ void editmap::mapgen_retarget()
if( const std::optional<tripoint> vec = ctxt.get_direction( action ) ) {
point vec_ms = omt_to_ms_copy( vec->xy() );
tripoint ptarget = target + vec_ms;
if( editmap_boundaries.contains( ptarget ) &&
editmap_boundaries.contains( ptarget + point( SEEX, SEEY ) ) ) {
if( get_map().inbounds( ptarget ) &&
get_map().inbounds( ptarget + point( SEEX, SEEY ) ) ) {
target = ptarget;

target_list.clear();
Expand Down
51 changes: 16 additions & 35 deletions src/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9040,20 +9040,20 @@ const std::vector<tripoint> &map::trap_locations( const trap_id &type ) const
return traplocs[type.to_i()];
}

bool map::inbounds( const tripoint_abs_ms &p ) const
bool map::inbounds( const tripoint &p ) const
{
return inbounds( getlocal( p ) );
return p.x >= 0 && p.x < my_MAPSIZE * SEEX &&
p.y >= 0 && p.y < my_MAPSIZE * SEEY &&
p.z >= -OVERMAP_DEPTH && p.z <= OVERMAP_HEIGHT;
// && ( zlevels || p.z == get_abs_sub().z() );
// Cannot actually let inbounds check the bounds for maps not supporting Z levels, as
// tests explicitly expect other Z level coordinates to return t_null when read
// and write terrain to the Z level of the map rather than fail or do nothing.
}

bool map::inbounds( const tripoint &p ) const
bool map::inbounds( const tripoint_abs_ms &p ) const
{
static constexpr tripoint map_boundary_min( 0, 0, -OVERMAP_DEPTH );
static constexpr tripoint map_boundary_max( MAPSIZE_Y, MAPSIZE_X, OVERMAP_HEIGHT + 1 );

static constexpr half_open_cuboid<tripoint> map_boundaries(
map_boundary_min, map_boundary_max );

return map_boundaries.contains( p );
return inbounds( getlocal( p ) );
}

bool map::inbounds( const tripoint_bub_ms &p ) const
Expand All @@ -9064,31 +9064,12 @@ bool map::inbounds( const tripoint_bub_ms &p ) const
bool map::inbounds( const tripoint_abs_omt &p ) const
{
const tripoint_abs_omt map_origin = project_to<coords::omt>( abs_sub );
return inbounds_z( p.z() ) &&
p.x() >= map_origin.x() &&
p.y() >= map_origin.y() &&
p.x() <= map_origin.x() + my_HALF_MAPSIZE &&
p.y() <= map_origin.y() + my_HALF_MAPSIZE;
}

bool tinymap::inbounds( const tripoint &p ) const
{
constexpr tripoint map_boundary_min( 0, 0, -OVERMAP_DEPTH );
constexpr tripoint map_boundary_max( SEEY * 2, SEEX * 2, OVERMAP_HEIGHT + 1 );

constexpr half_open_cuboid<tripoint> map_boundaries( map_boundary_min, map_boundary_max );

return map_boundaries.contains( p );
}

bool tinymap::inbounds( const tripoint_omt_ms &p ) const
{
constexpr tripoint_omt_ms map_boundary_min( 0, 0, -OVERMAP_DEPTH );
constexpr tripoint_omt_ms map_boundary_max( SEEY * 2, SEEX * 2, OVERMAP_HEIGHT + 1 );

constexpr half_open_cuboid<tripoint_omt_ms> map_boundaries( map_boundary_min, map_boundary_max );

return map_boundaries.contains( p );
return p.z() >= -OVERMAP_DEPTH && p.z() <= OVERMAP_HEIGHT &&
( zlevels || p.z() == get_abs_sub().z() ) &&
p.x() >= map_origin.x() &&
p.y() >= map_origin.y() &&
p.x() <= map_origin.x() + my_HALF_MAPSIZE &&
p.y() <= map_origin.y() + my_HALF_MAPSIZE;
}

tripoint_range<tripoint> tinymap::points_on_zlevel() const
Expand Down
13 changes: 8 additions & 5 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -1888,16 +1888,15 @@ class map
// TODO: fix point types (remove the first overload)
tripoint_bub_ms bub_from_abs( const tripoint &p ) const;
tripoint_bub_ms bub_from_abs( const tripoint_abs_ms &p ) const;
// TODO: fix point types (remove the first overload)
virtual bool inbounds( const tripoint &p ) const;
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 {
return inbounds( project_to<coords::omt>( p ) );
}
bool inbounds( const tripoint_abs_omt &p ) const;
bool inbounds( const point &p ) const {
return inbounds( tripoint( p, 0 ) );
return inbounds( tripoint_bub_ms( p.x, p.y, 0 ) );
}

bool inbounds_z( const int z ) const {
Expand Down Expand Up @@ -2431,8 +2430,12 @@ class tinymap : private map

public:
tinymap() : map( 2, false ) {}
bool inbounds( const tripoint &p ) const override;
bool inbounds( const tripoint_omt_ms &p ) const;
bool inbounds( const tripoint &p ) const {
return map::inbounds( p );
}
bool inbounds( const tripoint_omt_ms &p ) const {
return map::inbounds( p.raw() );
}

map *cast_to_map() {
return this;
Expand Down
4 changes: 2 additions & 2 deletions src/vehicle_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ void vehicle::crash_terrain_around()
const tripoint start_pos = vp.pos();
const vpslot_terrain_transform &ttd = *vp.info().transform_terrain_info;
for( size_t i = 0; i < eight_horizontal_neighbors.size() &&
!here.inbounds_z( crush_target.z ); i++ ) {
crush_target.z == -OVERMAP_LAYERS; i++ ) {
tripoint cur_pos = start_pos + eight_horizontal_neighbors[i];
bool busy_pos = false;
for( const vpart_reference &vp_tmp : get_all_parts() ) {
Expand All @@ -979,7 +979,7 @@ void vehicle::crash_terrain_around()
}
}
//target chosen
if( here.inbounds_z( crush_target.z ) ) {
if( crush_target.z != -OVERMAP_LAYERS ) {
velocity = 0;
cruise_velocity = 0;
here.destroy( crush_target );
Expand Down
Loading