From 0054e1972f2767e2cbacf6887e096312919b6be5 Mon Sep 17 00:00:00 2001 From: Volch Date: Tue, 21 Nov 2023 23:50:17 +0300 Subject: [PATCH 1/3] Specials spawned for missions will respect min range --- src/mission_util.cpp | 2 +- src/overmapbuffer.cpp | 23 ++++++++--------------- src/overmapbuffer.h | 5 +++-- src/start_location.cpp | 2 +- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/mission_util.cpp b/src/mission_util.cpp index 3e4798c55da4..82b6cf49ca28 100644 --- a/src/mission_util.cpp +++ b/src/mission_util.cpp @@ -193,7 +193,7 @@ static std::optional find_or_create_om_terrain( if( params.overmap_special ) { // ...then attempt to place the whole special. const bool placed = overmap_buffer.place_special( *params.overmap_special, origin_pos, - params.search_range ); + params.min_distance, params.search_range ); // If we succeeded in placing the special, then try and find the particular location // we're interested in. if( placed ) { diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index e47d13471500..e27866af645a 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -1594,27 +1594,19 @@ std::optional> overmapbuffer::place_special( } bool overmapbuffer::place_special( const overmap_special_id &special_id, - const tripoint_abs_omt ¢er, int radius ) + const tripoint_abs_omt ¢er, + int min_radius, int max_radius ) { // First find the requested special. If it doesn't exist, we're done here. - bool found = false; - overmap_special special; - for( const auto &elem : overmap_specials::get_all() ) { - if( elem.id == special_id ) { - special = elem; - found = true; - break; - } - } - if( !found ) { + if( !special_id.is_valid() ) { return false; } - + const overmap_special &special = *special_id; const int longest_side = special.longest_side(); // Get all of the overmaps within the defined radius of the center. for( const auto &om : get_overmaps_near( - project_to( center ), omt_to_sm_copy( radius ) ) ) { + project_to( center ), omt_to_sm_copy( max_radius ) ) ) { // We'll include points that within our radius. We reduce the radius by // the length of the longest side of our special so that we don't end up in a @@ -1622,9 +1614,10 @@ bool overmapbuffer::place_special( const overmap_special_id &special_id, // rest of it is outside the radius (due to size, rotation, etc), which would // then result in us placing the special but then not finding it later if we // search using the same radius value we used in placing it. + std::vector points_in_range; - for( const tripoint_abs_omt &p : points_in_radius( center, std::max( 1, - radius - longest_side ) ) ) { + for( const tripoint_abs_omt &p : closest_points_first( center, min_radius, + std::max( 1, max_radius - longest_side ) ) ) { point_abs_om overmap; tripoint_om_omt omt_within_overmap; std::tie( overmap, omt_within_overmap ) = project_remain( p ); diff --git a/src/overmapbuffer.h b/src/overmapbuffer.h index e1f75dd1fb15..d63ab910a39c 100644 --- a/src/overmapbuffer.h +++ b/src/overmapbuffer.h @@ -516,11 +516,12 @@ class overmapbuffer * @param special_id The id of overmap special to place. * @param center Used in conjunction with radius to search the specified and adjacent overmaps for * a valid placement location. Absolute overmap terrain coordinates. - * @param radius Used in conjunction with center. Absolute overmap terrain units. + * @param min_radius Used in conjunction with center. Absolute overmap terrain units. + * @param max_radius Used in conjunction with center. Absolute overmap terrain units. * @returns True if the special was placed, else false. */ bool place_special( const overmap_special_id &special_id, const tripoint_abs_omt ¢er, - int radius ); + int min_radius, int max_radius ); private: /** diff --git a/src/start_location.cpp b/src/start_location.cpp index 3e2eb41571aa..ddcbe28d3f3c 100644 --- a/src/start_location.cpp +++ b/src/start_location.cpp @@ -248,7 +248,7 @@ tripoint_abs_omt start_location::find_player_initial_location() const // that special is bad, no need to check all other overmaps for same thing const point_abs_om &omp = random_entry( overmaps ); const tripoint_abs_omt abs_mid = project_combine( omp, om_mid ); - if( overmap_buffer.place_special( special.id, abs_mid, OMAPX / 2 ) ) { + if( overmap_buffer.place_special( special.id, abs_mid, 0, OMAPX / 2 ) ) { // Now try to find what we spawned const tripoint_abs_omt start = overmap_buffer.find_closest( abs_mid, loc.first, From 031e4bd0558992af7b1136214c046f51a7b9fed7 Mon Sep 17 00:00:00 2001 From: Volch Date: Wed, 22 Nov 2023 02:18:50 +0300 Subject: [PATCH 2/3] Safer min range --- src/overmapbuffer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index e27866af645a..423d11744087 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -1616,8 +1616,9 @@ bool overmapbuffer::place_special( const overmap_special_id &special_id, // search using the same radius value we used in placing it. std::vector points_in_range; - for( const tripoint_abs_omt &p : closest_points_first( center, min_radius, - std::max( 1, max_radius - longest_side ) ) ) { + int max = std::max( 1, max_radius - longest_side ); + int min = std::min( max, min_radius + longest_side ); + for( const tripoint_abs_omt &p : closest_points_first( center, min, max ) ) { point_abs_om overmap; tripoint_om_omt omt_within_overmap; std::tie( overmap, omt_within_overmap ) = project_remain( p ); From 6ba9341913c2f721999a46bebf2571f77c42f3b3 Mon Sep 17 00:00:00 2001 From: Vollch Date: Wed, 22 Nov 2023 02:39:04 +0300 Subject: [PATCH 3/3] Update src/overmapbuffer.cpp Co-authored-by: scarf --- src/overmapbuffer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overmapbuffer.cpp b/src/overmapbuffer.cpp index 423d11744087..e0493b9559fe 100644 --- a/src/overmapbuffer.cpp +++ b/src/overmapbuffer.cpp @@ -1616,8 +1616,8 @@ bool overmapbuffer::place_special( const overmap_special_id &special_id, // search using the same radius value we used in placing it. std::vector points_in_range; - int max = std::max( 1, max_radius - longest_side ); - int min = std::min( max, min_radius + longest_side ); + const int max = std::max( 1, max_radius - longest_side ); + const int min = std::min( max, min_radius + longest_side ); for( const tripoint_abs_omt &p : closest_points_first( center, min, max ) ) { point_abs_om overmap; tripoint_om_omt omt_within_overmap;