CleverRaven/Cataclysm-DDA — pull request #8365 by BevapDin (2014-07-28 22:54:10+00:00)
Title: Player character gets its own id, road maps can be use by further characters, bug fixes

The code turned out to be a bit stranger than expected:

next_npc_id, next_faction_id and next_mission_id are stored in the file "save/[worldname]/master.gsav" **and** into the player specific file. And the player specific save is loaded later and therefor overrides the global values. This is only a problem when playing with several characters at the same time in the same world. This has been changed, only master.gsav will contain those next ids.

The player id is now loaded from and stored by the common load/save functions (common to npc *and* player). The player has a persistent id. The id is set upon game start, but also when load a save that did not contain a valid id for the player.

This allows the road map and similar items to store which player has used them. They can be used be each player character exactly once. Each use stores the players id in the `item_vars` of the item. Further usage looks up that entry and disallows the usage if the id the character is already contained.

That fixes #2536

----

And I should probably note the two bugs that are fixed by the first two commits. My fault, as usual. The first is simply: levx is relative to cur_om and must be updated when cur_om changes, otherwise the changes to levx accumulate.

----

And the second bug is tricky: saving monsters with `game::force_save_monster` calculates the absolute position of the monster (using `real_coords`), it uses the submap coordinates (*relative* to the overmap the monster is on) to load a tinymap. But it uses the `game::cur_om` as reference.

When the player is slightly (less than 5 submaps) south of a overmap border, cur_om will be set to the overmap to the north (not the overmap the player is actually on, but the overmap at that the reality bubble starts, in other words the overmap that contains the submap `map::grid[0]`).

Now assume a monster far to the south. When the player moves to the north, that monster leaves the reality bubble and `game::force_save_monster` is called. It calculates the position correct, the submap coordinate (`rc.om_sub.x`) will be some small value as it's near the top border of the submap, e.g. 4. That value is used to call `map::load` on a tinymap - with cur_om as overmap. But cur_om is the overmap to the north, *not* the overmap the monster is actually on. The absolute coordinates of the submaps that are loaded into the tinymap are something like -380+4, that is a whole overmap away.

I changed this to use map::getabs(monster-pos), translate this into (absolute) submap coordinates and load the tinymap with those absolute coordinates. The code sets spawnmapx to 0, not to the actual value because `map::add_spawn`, only compares it with -1 but does not use it otherwise.