Allow find_or_create_om_terrain to make new overmaps #36009
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Bugfixes "Allow find_or_create_om_terrain to make new overmaps"
Purpose of change
Fixes #35994
When searching for a mission target, we currently search existing overmaps within the specified range, and if we don't find the target and the parameters allow it, we'll try to create the target within the same overmaps.
This generally has worked, but if we can't place the target in any of the existing overmaps, we currently just error out. This updates it to then allow the creation of new overmaps within the range, which gives us more opportunities to find the target either naturally spawned or to attempt to create it.
Describe the solution
Push the existing logic for finding and creating the target into a lambda unchanged, call it once as we did previously, and if that fails to find a target, flip the flag that allows it to create new overmaps and run it again.
Describe alternatives you've considered
Specifically regarding this mission, the Refugee Center is very hard to place on an existing overmap because it occupies so much space--it's 15x15 overmap terrains in width and height, which is pretty rough but not insurmountable, but then it also extends from z+2 to z-4, and almost always ends up in a collision with some subsurface feature (e.g. sewers, subways, ant tunnels), particularly given that we don't try every single one of the 32400 possible points in a overmap z0 for placement, but instead divide it up into sectors. You can see this in the save from the related issue--I've rendered out z0 to z-4 in this image below:
Testing
Loaded the save from #35994, nuked the existing mission via debug, and then replicated the error using the steps from the issue. Then applied the changes here, repeated the process, and had it succeed.
Also replicated the issue in my own saves, and confirmed they're resolved after applying the changes.
There is still always going to be the chance that it fails to find or place the target within the radius, but in this particular case it ends up searching and creating up to 25 overmaps for the target, so failure is unlikely unless the world settings extremely reduce available space for placement.