CleverRaven/Cataclysm-DDA — pull request #9321 by BevapDin (2014-09-29 17:13:40+00:00)
Title: Fix monster spawn inside

This should fix #8638 - thanks to kevingranade for the reminder, I had indeed somehow lost the no-inside spawn check.

This also should fix the monsters spawn inside the visible area bug.

I've added a dedicated function for spawning monster of a overmap monster group, it checks the inside of the area and the visibility to the player.

However, `game::plmove` calls `game::update_map`, which calls `map::spawn_monsters`. But at this point the player coordinates are still as before the movement, they are changed in `game::plmove` *after* the `update_map` call. This means the submaps that have been loaded are already visible to the player:

In `plmove`: current position: `u.posx = SEEX * (1 + (MAPSIZE / 2)) - 1`
new position after movement: `x = SEEX * (1 + (MAPSIZE / 2))`

The new position needs shifting, so `update_map` is called, the shift is done, `x` is changed to `SEEX * (MAPSIZE / 2)` but the player position is changed only *after* that call to `update_map`. So `map::spawn_monsters` sees the player still at `SEEX * (1 + (MAPSIZE / 2)) - 1 == 12 * (1 + 5) - 1 == 71`.

Now add the maximal view range 60 (DAYLIGHT_LEVEL, sometimes it's actually more) and the player can see up to `x = 131`, the maximal x value that the map allows is `MAPSIZE * SEEX - 1 == 11 * 12 - 1 == 131`, so the player can see all of the newly loaded submaps and there is no place to put the monsters.

Therefor monsters are spawned on the outermost submaps whether the player can see that place or not.

----

I also added monster spawning after the hordes have moved. This call (in `game::do_turn`) will usually do nothing as all monster on the map have already been spawned. Only when a monster group on the overmap has moved into the reality bubble it will spawn that group.