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

Prevent overmap mongroups from spawning on top of faction bases #49377

Merged
merged 1 commit into from
Jul 9, 2021

Conversation

eltank
Copy link
Contributor

@eltank eltank commented Jun 20, 2021

Summary

Balance "Prevent overmap mongroups from spawning on top of faction bases"

Purpose of change

As discussed in #49322 one of the blockers for making faction bases (e.g. Refugee Center) appear only once per gameworld is the concern that a faction base may spawn in a "broken" state (in particular, overwhelmed by ants, fungaloids, triffids or blobs spawned by a nearby anthill/spire/grove/pit). While I personally believe this is extremely unlikely, I agree that we should try to prevent it from happening. This PR makes faction bases "safe" from overmap mongroups placed at worldgen time. It does not prevent mongroups from moving into these bases if "wandering hordes" is turned on and the player makes enough noise to attract nearby hordes. It also does not prevent monsters generated by mapgen (such as the Refugee Center zombies) from spawning.

Describe the solution

  • Introduce a SAFE_ZONE SAFE_AT_WORLDGEN JSON flag for overmap specials
  • Tag faction bases with the flag
  • Keep track of "safe" tiles when placing an overmap special tagged with the flag
  • Change the overmap mongroup spawn code to check if the tile is safe
  • Remove already-spawned mongroups when placing a new safe zone

Describe alternatives you've considered

Preventing monster-spawning map specials from being placed close to a faction base. That seems much more complicated to do.

I considered either persisting/reloading the overmap's safe_at_worldgen set or rebuilding it on game load using the already-persisted overmap_special_placements JSON attribute. But since safe_at_worldgen is only needed during worldgen (i.e. whenever a new overmap is generated) this is not necessary.

Instead of redirecting most of the existing add_mon_group calls to a new spawn_mon_group function, I considered adding a bool argument, i.e. changing the signature to something like add_mon_group( const mongroup &group, bool initial_spawn = false ). But I think a separate function is cleaner (easier to trace references, more intuitive invocation).

Testing

I boosted the spawn chance and area of effect of fungal towers to extreme levels, like so:

  {
    "type": "overmap_special",
    "id": "Fungal Tower",
    "overmaps": [ { "point": [ 0, 0, 0 ], "overmap": "fungal_tower" } ],
    "locations": [ "wilderness" ],
    "city_distance": [ 1, 90 ],
    "occurrences": [ 40, 100 ],
    "flags": [ "FUNGAL" ],
    "rotate": false,
    "spawns": { "group": "GROUP_FUNGI_TOWER", "population": [ 4250, 6750 ], "radius": [ 40, 50 ] }
  },

I then created a new world with default settings, used the evac shelter console to get the location of the Refugee Center and teleported there. As expected there was a fungal tower nearby.
overmap

I teleported to the south/north/west/east boundaries (where the fences are) and verified that there are plenty of fungal monsters outside the fence but none inside the fence:
minimap-south
minimap-north
minimap-west
minimap-east

In the refugee center building the only living creatures are the refugees and the back bay zombies.
minimap-middle

Additional context

The following locations have been tagged with SAFE_AT_WORLDGEN:

  • Refugee Center
  • Bandit Cabin
  • Bandit Camp
  • Tacoma Ranch
  • Hub 01
  • Isherwood Farm

Did I miss anything?

@actual-nh actual-nh added 0.F Feature Freeze <Bugfix> This is a fix for a bug (or closes open issue) Character / World Generation Issues and enhancements concerning stages of creating a character or a world Map / Mapgen Overmap, Mapgen, Map extras, Map display NPC / Factions NPCs, AI, Speech, Factions, Ownership labels Jun 20, 2021
@actual-nh actual-nh added the Game: Balance Balancing of (existing) in-game features. label Jun 20, 2021
@eltank eltank force-pushed the safe_zones branch 3 times, most recently from c6c4819 to ff48f3e Compare June 20, 2021 04:24
@Venera3
Copy link
Member

Venera3 commented Jun 20, 2021

Anthills and sewers use a hardcoded monster placement in generate_sub(), you might want to reroute that through this check as well.

@eltank
Copy link
Contributor Author

eltank commented Jun 20, 2021

Anthills and sewers use a hardcoded monster placement in generate_sub(), you might want to reroute that through this check as well.

Already done. See changes to overmap.cpp L1600-1760.

@eltank eltank force-pushed the safe_zones branch 2 times, most recently from 5cd81c6 to 58c5338 Compare July 3, 2021 20:14
@eltank
Copy link
Contributor Author

eltank commented Jul 3, 2021

Rebased after 0.F release. Could someone take a look at this change?

@esotericist
Copy link
Contributor

esotericist commented Jul 5, 2021

sorry for delay, health has been terrible on my end, but since i'm the one who asked for this i definitely meant to respond sooner.

at a glance the code looks the right shape. i'm not sure if safe_zone is quite the right term for this (to me that phrasing implies a degree of persistence beyond mere worldgen time), but i also can't come up with anything better offhand and i definitely don't want quibbling over the label to delay this.

i wish i could provide a more concrete approval, but all i can do right now is say "i see nothing that concretely should prevent this from being merged"

edit: if someone else doesn't get to it first, i'm going to try to review it properly in the coming days, but i have prior commitments (like hopefully helping korggent fix the mouse support for the new graphical overmap tech)

@ifffrt
Copy link

ifffrt commented Jul 8, 2021

at a glance the code looks the right shape. i'm not sure if safe_zone is quite the right term for this (to me that phrasing implies a degree of persistence beyond mere worldgen time), but i also can't come up with anything better offhand and i definitely don't want quibbling over the label to delay this.

Maybe it could be renamed to 'safe_at_worldgen', or 'cleared_at_worldgen' since that's basically what the process does, i.e. it sees that a group of spawned enemies is somewhere they shouldn't be and it erases them out of existence.

@eltank
Copy link
Contributor Author

eltank commented Jul 8, 2021

at a glance the code looks the right shape. i'm not sure if safe_zone is quite the right term for this (to me that phrasing implies a degree of persistence beyond mere worldgen time), but i also can't come up with anything better offhand and i definitely don't want quibbling over the label to delay this.

Maybe it could be renamed to 'safe_at_worldgen', or 'cleared_at_worldgen' since that's basically what the process does, i.e. it sees that a group of spawned enemies is somewhere they shouldn't be and it erases them out of existence.

'safe_at_worldgen' sounds good to me (if a bit verbose). 'cleared_at_worldgen' could be interpreted as removing all creatures or items or something else. [Done]

@I-am-Erk I-am-Erk merged commit 6262480 into CleverRaven:master Jul 9, 2021
@eltank eltank deleted the safe_zones branch July 9, 2021 18:02
@jbytheway
Copy link
Contributor

(Coming from #49980 where I made a similar mistake) It looks like you forgot to add serialization for the new safe_at_worldgen member, so it won't work after the game's first save/load cycle.

(This is an easy mistake to make, so I'm prioritizing my plan to add a clang-tidy check looking for missed serializations)

@eltank
Copy link
Contributor Author

eltank commented Jul 18, 2021

(Coming from #49980 where I made a similar mistake) It looks like you forgot to add serialization for the new safe_at_worldgen member, so it won't work after the game's first save/load cycle.

(This is an easy mistake to make, so I'm prioritizing my plan to add a clang-tidy check looking for missed serializations)

That was intentional. safe_at_worldgen is only needed during the generation of a new overmap. There's no need to persist it after that. [This is also mentioned in alternatives considered]

@jbytheway
Copy link
Contributor

That was intentional. safe_at_worldgen is only needed during the generation of a new overmap. There's no need to persist it after that. [This is also mentioned in alternatives considered]

Cool. Sorry for the noise.

@esotericist
Copy link
Contributor

(Coming from #49980 where I made a similar mistake) It looks like you forgot to add serialization for the new safe_at_worldgen member, so it won't work after the game's first save/load cycle.
(This is an easy mistake to make, so I'm prioritizing my plan to add a clang-tidy check looking for missed serializations)

That was intentional. safe_at_worldgen is only needed during the generation of a new overmap. There's no need to persist it after that. [This is also mentioned in alternatives considered]

does this mean if something with that tag generates at the edge of an overmap, then it won't be protected against things that generate in that next overmap over if there's a save/load cycle in between?

@eltank
Copy link
Contributor Author

eltank commented Jul 19, 2021

That was intentional. safe_at_worldgen is only needed during the generation of a new overmap. There's no need to persist it after that. [This is also mentioned in alternatives considered]

does this mean if something with that tag generates at the edge of an overmap, then it won't be protected against things that generate in that next overmap over if there's a save/load cycle in between?

Hmm, yes that is a thing that could happen with very low probability. Alright then, take a look at #50046 for a fix.

ZhilkinSerg added a commit to ZhilkinSerg/Cataclysm-DDA that referenced this pull request Aug 12, 2021
ZhilkinSerg added a commit that referenced this pull request Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
<Bugfix> This is a fix for a bug (or closes open issue) Character / World Generation Issues and enhancements concerning stages of creating a character or a world Game: Balance Balancing of (existing) in-game features. Map / Mapgen Overmap, Mapgen, Map extras, Map display NPC / Factions NPCs, AI, Speech, Factions, Ownership
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants