perf: specials placement optimizations #3729
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.
Purpose of change
Better performance
Describe the solution
Added two more placement overlays. River overlay prevents attempting of placing river specials on ground and vice versa. Underground overlay allows placing underground special(microlabs in vanilla game) within range of surface specials without conflicts.
Added locations check to land overlay to prevent expensive attempts of placing specials over existing cities.
Limited max amount of attempts to build connections. It could been terribly slow - i've seen minute long hangs during placing of single special, when it physically can't be connected anywhere, due to being on unreachable island, or fully surrounded by other buildings.
With all that generation speed of crowded maps with big cities will be magnitude faster than before. On default settings with plenty of empty space difference isn't that drastic.
As for result - with dedicated overlays land specials won't interfere with river and underground ones, which is nicer, but there isn't a lot of them to benefit from it, so produced overmaps looks pretty much same.
Describe alternatives you've considered
Code would look a bit more consistent with six overlays, land\lake\river plus their underground counterparts. But since we don't have any underwater specials it would just increase operational costs for nothing.
Adding "RIVER" and "UNDERGROUND" specials flags, forcing them to respective overlays. First one would allow less hacky detection of river special(but would break all river specials in old mods), second one could be useful for thing like mining mod(but don't have any use in vanilla).
It might be beneficial to skip land locations check when map generated with no cities, but this case is already fast enough to bother too much.
Testing
Maps are generating, tests are passing.
Additional context
Checklist