Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(port): mutable specials and unhardcored labs and anthills (#3520)
* Support for mutable overmap specials and unhardcode anthills Co-authored-by: John Bytheway <[email protected]> * Better error for missing json mapgen object Previously this would fail with an error which didn't explain where the problem was. * Support JSON-defined linear terrain Linear terrain (roads, ant tunnels, sewers, etc.) was not previously possible to define in JSON. This was because the rotation wasn't correctly calculated for linear terrain. Make it be. * Unhardcode anthill mapgen Co-authored-by: John Bytheway <[email protected]> * Define std::hash specialization for cube_direction * Explicit return value construction * Better debugging for mutable special placement (#51504) When placement of mutable overmap specials fails, it's hard to figure out why. The small amount of context previously given in the debugmsg wasn't enough. I did have some further debug printfs in non-compiled code behind a #if, but that's no use to people who can't compile the game themselves, nor does it help debug failures in CI. Reformulate the code so that these more detailed messages are always saved (rather than printed) and when a placement error occurs, it includes a full history of the placement to allow for debugging. * Putative fix for mutable special placement (#51574) I think I figured out why mutable special placement was sometimes failing. Some joins could be postponed but others could appear pointing at the same tile and be satisfied in the absence of the postponed joins. Then, when the postponed joins are restored they cannot be satisfied. Avoid this by keeping track of the tiles with postponed joins and ensuring that they new joins pointing at the same tiles are added directly to the postponed list rather than the unresolved list. * Actually fix rare anthill placement errors (#51611) The previous attempt to fix the rare anthill placement errors did not work. I now know this was due to a simple typo, but tracking down the issue took a lot of refactoring. That refactoring improved the code, so I'm including it here. Changes include: * The previous fix was that new unresolved joins that might conflict with postponed joins would themselves be automatically postponed. We have now reversed this logic so the postponed joins are restored. This allows another chance for the current phase to satisfy the joins, now that might be possible. * Postponed joins now need to have their positions indexed for efficient access, so I factored out that indexing capability into a new struct indexed_joins. * Removed the list of orphaned joins. They should no longer ever occur. * Added a bunch of calls to a consistency_check function that verifies the class invariants (except it's disabled for now, with the code left in case it's useful for future debugging). * The order of unresolved joins used to depend on their addresses in memory, which made the tests non-reproducible. Change that to be deterministic. * Add unit test which places ~100k anthills to more easily observe placement errors. * Improve the debugging output for failed placements to make it easier to see what happened (add phase boundary markers and capitalize FAILED). * Allow random number of overmaps in mutable special Rather than always having a fixed number of overmaps for a particular rule during placement, allow a random number. Currently this can only be a poisson-distributed number (or a fixed value, as was already supported). * Document distribution feature for mutable specials Explain how to specify that the max number of instances should be drawn from a Poisson distribution. * Optional joins for mutable specials To add more flexibility to the layout of mutable specials it is convenient to allow some joins for particular overmaps to be optional. This helps in particular with the final phase when you want to clean up all the leftover unresolved joins. Generalize the definition of joins to allow this in the JSON, and handle appropriately in the code. Convert craters to use this feature. Extend the unit tests to spawn a test crater to exercise this feature. * Document the optional joins feature * Document join prioritization (#51661) * Support asymmetric joins for mutable specials Sometimes it's important for the two sides of a join to be different, for example a hallway_to_room join should not join two hallways. It is also be important if the set of locations is different for the two sides. Add support for this type of asymmetry, and use it to allow anthills to have multiple entrances. Update test anthill also. * Document asymmetric joins * Avoid large stack object The Windows stack size limit is smaller than Linux, so need to tweak this test to avoid a stack overflow. * Move cube_direction, pos_dir to header To be able to use these types in regular mapgen they need to be promoted to headers. * Record joins from mutable special placement When a mutable special is placed, keep a record of every join used and store that in the overmap. Display this information in the overmap editor to aid with debugging. * Allow mapgen values to check joins Similarly to neighbourhood checks in chunk placement, add join checks to chunk placement. * Document join testing for chunk placement * Acid Anthills (#60095) * Acid Anthills * Update ants.json * Update ants.json * Debug note on overmap when mutable placement fails (#51878) When placement fails for a mutable overmap special, add a note to the overmap with some details to assist debugging. * displace and displace_XY for direction There used to be a function called direction_XY that converted a direction to a point. This didn't match the naming scheme used for analogous functions for om_direction and cube_direction. Rename it to displace_XY and also create a tripoint version displace. * Set neighbours according to oter rotation Previously the mapgen feature of placing chunks based on neighbours used the absolute cardinal directions on the map. This is unhelpful when the map is rotated. Rotate the neighbours to match the rotation of the map so that these checks make sense for the mapgen. * Add + overload for cube_direction and int For symmetry with the - overload. * Fix join direction checks Previously these checks were based on absolute map directions. After this change they are instead rotated with the map, so that they are easier to use logically within the map. * Add tile rotation to debug overmap ui It can be useful to know the rotation of a particular tile for debugging purposes. This may not be obvious for linear terrain. Add it to the debugging output in the overmap editor. * Add support for mutable overmap chunks It will help a lot with mutable overmap special design if a rule can place multiple overmaps together in a chunk. This attempts to implement that. It entails a significant rewrite of the guts of overmap special placement. Add a test_microlab special to test this new feature. * Document mutable overmap chunks * Fix some debug / error messages A couple of these messages were unhelpful or invalid (e.g. passing the wrong number of args for a format string). Fix that. * Support alternative joins in mutable specials Alternative joins allow an overmap in a mutable special to match an existing join that they would not otherwise, without affecting the requirement for onwards matching on other unresolved edges. This is particularly useful when spawning a collections of 'clumpy' overmaps around some existing ones. For example, the mutable microlab has a hallway and then microlab terrains. The microlab terrains should match the hallway, but their unresolved edges should only match more microlabs. * Document alternative joins * Remove unused field * Fix road mapgen to check the correct neighbours The changes in #51913 altered how neighbours were entered into the mapgendata context. For JSON mapgen this fixed issues, but for hardcoded mapgen it could break things. In particular, for road mapgen it caused problems. Add a new flag to allow specific oter_ts to opt out of this new behaviour, and apply it to roads. * Support mismatched available joins There was a bug in the mutable special placement code whereby it would refuse to place two mismatched available joins pointing at each other, even though that is perfectly reasonable. Attempt a fix for this. * Document trick for testing mutable specials Explain how to tweak the placement test to test placement for your special when you're designing a new one. * Area check Co-authored-by: George Karfakis <[email protected]> * Restored interaction between anthills, and labs * Restored blob crater * Restored anthills IDs, and obsolete dedicated ants lab * Mutables expansion, added mutable lab * Added escape cells to mutable lab * Connections support for mutable specials * Mutable central lab * No more hardcoded labs * Restored hidden labs, merged z-4 subways * Mutables can be generated as start location * Fixed styling and warnings * Nested specials * Faster pos check in mutables * Less hacky lab stairs connections * Option to configure spacing between specials * Specials density adjustment for high spacing * Spread specials between different cities * Polishing * Documented specials palcement * Clean up * Fixed neighbor check type * Changed match type * More polishing * Better check for neighbour connection * Documented connection check * Fixed old issue where no-city connection fallback could build a tangled mess of multiple roads * Revert type check fix in mapgen - it breaks central labs * p2p connections for subways --------- Co-authored-by: John Bytheway <[email protected]> Co-authored-by: eltank <[email protected]> Co-authored-by: Maleclypse <[email protected]> Co-authored-by: George Karfakis <[email protected]>
- Loading branch information