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

Support for mutable overmap specials and unhardcode anthills #51317

Merged
merged 13 commits into from
Sep 9, 2021

Conversation

jbytheway
Copy link
Contributor

@jbytheway jbytheway commented Sep 2, 2021

Summary

Infrastructure "Support for mutable overmap specials"

Purpose of change

We still have several hardcoded overmap specials which we would like to unhardcode, such as anthills and classic labs. One of the reasons these have been difficult to convert to JSON is that their layout on the overmap is randomized. Currently JSON special definitions must have a fixed layout.

Describe the solution

Split overmap specials into two subtypes: fixed and mutable.

Fixed specials are what we already had. Mutable specials are a new concept that allows randomized layout on the overmap.

In short, mutable overmaps specials work like a jigsaw puzzle, where each OMT is a piece, and you define how the pieces can fit together.

Use this to define a mutable special for anthills. Note that I haven't actually removed hardcoded anthills yet because this only works for regular ants, not acid ants (so far).

Document the new feature in OVERMAP.md, using the anthill as an example.

Describe alternatives you've considered

This is a minimal viable initial implementation. I can already see various refinements that will be needed, but this was sufficient to allow anthills to be reliably generated, so I stopped here to make the initial PR as small as possible with a meaningful proof of concept.

My new anthills are smaller than the old ones, but I think that's reasonable. They are really rather boring mostly-empty tunnels (in both cases), so I don't think they should take up too much overmap space.

A bigger issue is that the new anthills don't have any ants in them (except for queens and larvae). This is not really fixable until we also un-hardcode the lower-level anthill mapgen, because those spawns ought to be linked to the OMT definitions, which are hardcoded. I plan to do that in a follow-up PR. This one was already adding a lot of stuff and I didn't want it to grow further.

Testing

The new docs can be viewed here.

Generated a lot of anthills.

Here's what old-style hardcoded anthills tend to look like:
old-anthill

Here's an example of the new-style JSON anthill, as it naturally spawns:
new-anthill

Here's the result of me debug-spawning many anthills close to each other to verify that they can spawn without error even in constrained situations:
anthills-many

Additional context

It seems like there are issues with the regular (non-overmap) generation of anthills, because none of them spawn with a way to get out to the surface. But this is a problem with old and new anthills, so out of scope for this PR.

@actual-nh actual-nh added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Map / Mapgen Overmap, Mapgen, Map extras, Map display labels Sep 2, 2021
@Night-Pryanik
Copy link
Contributor

Well, that looks way too difficult (for me) to comprehend at glance. It would require thorough examination for proper use.

@lgtm-com
Copy link

lgtm-com bot commented Sep 2, 2021

This pull request introduces 3 alerts when merging e577f98 into acde44f - view on LGTM.com

new alerts:

  • 3 for Declaration hides parameter

@jbytheway jbytheway force-pushed the overmap_mutable branch 2 times, most recently from 8b9adae to 2a65b1f Compare September 4, 2021 19:23
@jbytheway
Copy link
Contributor Author

I believe the LGTM warning is resolved.

@jbytheway
Copy link
Contributor Author

Remaining CI failure appears to be unrelated.

@actual-nh
Copy link
Contributor

Remaining CI failure appears to be unrelated.

Correct; see #51377.

I am trying to add a new variant of overmap special.  As a precursor to
that, I wanted to refactor a bunch of the overmap_special code so that
more of it is contained within the overmap_special class rather than
other code messing with its internals directly.

Thus, made most of its member variables private and moved various chunks
of code to member functions.
This feature already existed for some specific enums, but we can
implement a generic version.
Mutable overmap specials are a new type of special where you do not
define a specific layout, but rather a collection of rules about what
OMTs are permissible and how they link together.

Add this as a new subtype of overmap special, with all the associated
code to support it.

This is only an initial, limited, implementation.
A first step towards un-hardcoding anthills, make a mutable overmap
special to represent them.

In this first iteration, it's nothing more than a single crossroads with
some variable-length straight tunnels extending in each compass
direction.
When growing a mutable overmap special, actually respect the location
restrictions set by the JSON.
The JSON anthill now spawns food, larvae, and queen rooms in addition to
just tunnels.
When placing an OMT as part of a mutable overmap special, previously it
was possible for it to be placed in such a way that it had a connection
into some terrain that could not permit that connection.  For example, a
tunnel that would have to lead into another tunnel.

Now, when satisfying a constraint, we also verify that the adjacent
terrains fall into the into_locations member of the respective
connections.

If not otherwise set, those locations are the default locations of the
special.
Allow a mutable overmap special to specify some location constraints for
its initial placement.  This prevents some types of placement errors
(such as an anthill over a sewer tunnel that prevents the underground
part being placed).
The term 'connection' already had a meaning in the context of overmap
generation, so I should not have reused it.  Switch to 'join' instead.
@jbytheway
Copy link
Contributor Author

Note that I've opened a follow-up PR #51474 that includes this one with further changes (in particular, it adds the ant spawns back to the ant tunnels that were missing in this version).

@kevingranade kevingranade merged commit 9856bb8 into CleverRaven:master Sep 9, 2021
@eltank
Copy link
Contributor

eltank commented Sep 9, 2021

There's a CI error in "GCC, Ubuntu cross-compile to MinGW-Win64, Tiles, Sound". It doesn't like the debugmsg call in your constexpr functions. Unfortunately this is also failing the cross-compile build in other PRs.

overmap.cpp: In function 'constexpr cube_direction operator-(cube_direction, int)':
Error: src/debug.h:69:35: error: call to non-constexpr function 'void realDebugmsg(const char*, const char*, const char*, const char*, Args&& ...) [with Args = {}]'
 #define debugmsg(...) realDebugmsg(__FILE__, STRING(__LINE__), __FUNCTION_NAME__, __VA_ARGS__)

@actual-nh
Copy link
Contributor

actual-nh commented Sep 9, 2021

It isn't just the cross-compile, looks like - GCC is objecting on Linux also. Ping: @jbytheway?

@eltank
Copy link
Contributor

eltank commented Sep 10, 2021

In case it helps, here is another anthill spawn failure on Ubuntu Clang:
https://github.com/CleverRaven/Cataclysm-DDA/pull/51450/checks?check_run_id=3562890826

@jbytheway
Copy link
Contributor Author

In case it helps, here is another anthill spawn failure on Ubuntu Clang:
https://github.com/CleverRaven/Cataclysm-DDA/pull/51450/checks?check_run_id=3562890826

Thanks, but it looks like that log has already vanished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style [JSON] Changes (can be) made in JSON Map / Mapgen Overmap, Mapgen, Map extras, Map display
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants