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

fix: specials spawned for missions will respect min range #3732

Merged
merged 3 commits into from
Nov 23, 2023
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
2 changes: 1 addition & 1 deletion src/mission_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static std::optional<tripoint_abs_omt> 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 ) {
Expand Down
24 changes: 9 additions & 15 deletions src/overmapbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1594,37 +1594,31 @@ std::optional<std::vector<tripoint_abs_omt>> overmapbuffer::place_special(
}

bool overmapbuffer::place_special( const overmap_special_id &special_id,
const tripoint_abs_omt &center, int radius )
const tripoint_abs_omt &center,
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<coords::sm>( center ), omt_to_sm_copy( radius ) ) ) {
project_to<coords::sm>( 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
// scenario where one overmap terrain of the special is within the radius but the
// 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<tripoint_om_omt> points_in_range;
for( const tripoint_abs_omt &p : points_in_radius( center, std::max( 1,
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;
std::tie( overmap, omt_within_overmap ) = project_remain<coords::om>( p );
Expand Down
5 changes: 3 additions & 2 deletions src/overmapbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 &center,
int radius );
int min_radius, int max_radius );

private:
/**
Expand Down
2 changes: 1 addition & 1 deletion src/start_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading