CleverRaven/Cataclysm-DDA — pull request #8678 by BevapDin (2014-08-24 11:56:47+00:00)
Title: Overmap monster group bugfixes

Fixes #8593

The overmap contains a several LAB monster groups with population 2147483648. That's an interesting challenge for the survivor, but the game tries to put all those monsters into the available map space and they won't fit. That's causing a (nearly) infinite loop and finally the crash.

The source of this bug is the splitting of the huge (multi-tile) monster groups into smaller groups. The functions `overmap::build_lab` / `overmap::build_ice_lab` create monster groups with a radius of `rng(1, 5 + z)`. The radius can be 0 (if z is -5), which leads to a division by zero (population of the group / area of the group), resulting in a `NaN` value. This would than through a cast to unsigned int (`mongroup::population`) became 2147483648.

I added code that catches this number when loading the old saves (it seems to only apply to lab monster groups below z-level -4, so many players might have this number in their save files, but as long as they don't visit the labs it will not show up).

-----

To avoid this trouble with other monster groups, with groups with a small radius, and to fix the "wildlife spawns inside" problem, I added spawn definitions to overmap terrain. This will put monster from that monster groups on the submaps created for that overmap terrain. Currently this is used for forest/field and labs.

The format is this:
```
{
"type" : "overmap_terrain",
"id" : "field",
"name" : "field",
"spawns" : {
"group": "GROUP_FOREST",
"population": [2, 4],
"chance": 20
},
...
}
```
The `spawns` entry is optional, `group` is a monster groups, `population` is the minimal/maximal population here, `chance` is a chance that monsters are placed at all (in percent, 100 means all the time). If the chance test fails, no monsters are placed here at all, otherwise a number from min-population to max-population is chosen and monsters from the group are added to the submaps.

There is *no* inside-outside check upon spawn, that means if for example one adds the spawn entry above to the mansion overmap terrain, wildlife will spawn *inside* the mansion.

It should work fine in its current form as the GROUP_FOREST is only used for overmap terrain that contains only outside area, so regardless where the monsters is placed, it's outside.

I changed the lab spawns to use this this system as well, because currently the lab spawns a single monster groups with variable radius (from 5 to 0), and a *fixed* population of 400 monsters. 400 monsters cramped onto 1 submap won't work ever.

----

Fixes #8598 as it was very confusing when testing the monster spawn.

Also the monster from the overmap groups are now spawned from within `map::spawn_monsters` which is called after loading / shifting the map, this will make groups that have moved spawn on the map again (previously they would only spawn upon mapgen, if the group wandered onto a already created submap, they would not spawn again).

----

This is technically ready, but it might need some balancing (the spawn rates), could also be extended to swamp/river groups. Or to worms (they are currently placed randomly anywhere on the overmap), or to sewer creatures (could spawn from any sewer overmap terrain).

Currently I get about one wildlife creature per forest tile and about one creature per 3 field tiles.