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

Mongroup: subgroup spawning fixes #59281

Merged
merged 3 commits into from
Jul 19, 2022

Conversation

dseguin
Copy link
Member

@dseguin dseguin commented Jul 15, 2022

Summary

None

Purpose of change

Describe the solution

When spawning from a monster group, evaluate subgroups at the top level for validating spawn conditions (start/end dates, weight, season, etc.)

(Note: pack_size)

Pack size is a bit of a special case. The pack sizes in monster groups are deliberately weighted:

{
"type": "monstergroup",
"name": "GROUP_TRIFFID_HEARTGUARDS",
"default": "mon_triffid",
"monsters": [
{ "monster": "mon_triffid", "weight": 280, "cost_multiplier": 0 },
{ "monster": "mon_triffid", "weight": 300, "cost_multiplier": 0, "pack_size": [ 4, 6 ] },
{ "monster": "mon_vinebeast", "weight": 260, "cost_multiplier": 2 },
{ "monster": "mon_triffid_queen", "weight": 160, "cost_multiplier": 5 }
]
},

So a parent group defining a pack size for this subgroup would select that many sub-entries.

{
  "type": "monstergroup",
  "name": "GROUP_TRIFFID_HEART",
  "monsters": [ { "group": "GROUP_TRIFFID_HEARTGUARDS", "pack_size": [ 10, 12 ] } ]
}

In this case, 10-12 entries from GROUP_TRIFFID_HEARTGUARDS will spawn here


Describe alternatives you've considered

Testing

Added a unit test to check the spawn probabilities of monster groups at different levels of nesting:

./tests/cata_test --rng-seed time "Nested monster groups spawn chance"

Additional context

This was an implementation bug from #52323 (yes, it's been broken for that long)

@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` [JSON] Changes (can be) made in JSON Code: Tests Measurement, self-control, statistics, balancing. labels Jul 15, 2022
@dseguin dseguin added Spawn Creatures, items, vehicles, locations appearing on map Monsters Monsters both friendly and unfriendly. labels Jul 15, 2022
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Jul 15, 2022
@Venera3
Copy link
Member

Venera3 commented Jul 15, 2022

Took it for a test ride - start/end and conditions definitely work, weights seemed to as well (but those are a bit harder to check). One thing I ran into is that the top-level pack size definition doesn't seem to do anything, with the group-level pack size carrying over.

@dseguin
Copy link
Member Author

dseguin commented Jul 15, 2022

Ah, I see what's wrong with pack size. I'll add a test case for that as well.

Thanks for checking!

@dseguin dseguin marked this pull request as draft July 15, 2022 19:53
@dseguin dseguin force-pushed the fix_mongroup_subgrouping branch from d23bbc1 to fa006d0 Compare July 16, 2022 19:21
@dseguin dseguin marked this pull request as ready for review July 16, 2022 19:22
@dseguin dseguin force-pushed the fix_mongroup_subgrouping branch from fa006d0 to 5c86e98 Compare July 17, 2022 05:19
@Venera3
Copy link
Member

Venera3 commented Jul 18, 2022

Pack size works, however do you think it would be possible to instead of multiplying the rolled mob with the top-level pack size you'd get pack_size rolls on the nested group?
Ex:

  {
    "type": "monstergroup",
    "name": "GROUP_ZOMBIE_TEST",
    "monsters": [
      { "group": "GROUP_ZOMBIE_FAMILY", "pack_size": [ 1, 5 ], "weight": 1000 }
    ]
  },
  {
    "type": "monstergroup",
    "name": "GROUP_ZOMBIE_FAMILY",
    "monsters": [
      { "monster": "mon_zombie", "weight": 200 },
      { "monster": "mon_zombie_fat", "weight": 100 },
      { "monster": "mon_zombie_child", "weight": 300 },
      { "monster": "mon_zombie_dog", "weight": 100, "pack_size": [ 1, 2 ] }
    ]
  },

As it stands, this spawns either 1-5 zombies/fat zeds/zed kids or 1-10 dogs (but only one type at a time). However, if the top-level pack size would instead count as the number of entries to roll you potentially could place a whole family with one spawn - and one spawn is all you'll get for overmap_terrain level spawns (like random monsters). For the mapgen-level it's less of a problem since you can just repeat the group spawn without pack size.

@dseguin dseguin force-pushed the fix_mongroup_subgrouping branch from 5c86e98 to b715708 Compare July 18, 2022 18:53
@dseguin
Copy link
Member Author

dseguin commented Jul 18, 2022

do you think it would be possible to instead of multiplying the rolled mob with the top-level pack size you'd get pack_size rolls on the nested group?

Done, just needed a bit of refactoring to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Tests Measurement, self-control, statistics, balancing. [JSON] Changes (can be) made in JSON json-styled JSON lint passed, label assigned by github actions Monsters Monsters both friendly and unfriendly. Spawn Creatures, items, vehicles, locations appearing on map
Projects
None yet
3 participants