CleverRaven/Cataclysm-DDA — pull request #8346 by BevapDin (2014-07-27 12:33:47+00:00)
Title: Use global coordinates for npcs/factions/events and fix bugs

This changes some structures to use global, absolute coordinates instead of separate coordinates of a overmap and local coordinates on that overmap)

Sadly this overlaps with the newest 3D-map PR, I'm sorry. It also conflicts with the Small fixes PR.

----

The npc's position uses absolute submap coordinates. This removes the `npc::omx`, `npc::omy` and renames `npc::omz` to `mapz` (to be consistent with `mapx`, `mapy` - overmaps don't have a z-coordinate anyway).

The position of npcs is now simply `mapx * SEEX + posx`, instead of `(omx * OMAPX * 2 + mapx) * SEEX + posx`. `mapx`/`mapy` are global coordinates, but they still refer to a submap position. This means no value changes as long as the the npc is on the overmap (0,0). It gets rid of the overmap pointer parameters to `npc::spawn_at` and on other places. The change is save compatible, loading old saves with om[xyz] will convert the coordinates.

The same change has been made to factions and events, they store their location in absolute submap coordinates now.

I added a wrapper to get the absolute values of `game::levx`/`game::levy` (include the offset from `game::cur_om`). Some code referred to `lev[xy]`, when it should actually refer to absolute coordinates (the number that is displayed in the mine computer, ...).

Some functions still "assume" `lev[xy]` refers to the player position, while they actually refer to the position (top left corner) of the reality bubble. Example: `npc::perform_mission` (rescuers move to the top left of the reality bubble), `npc::minutes_to_u` (distance to top left of the reality bubble is used), `monster::die` (should probably kill monster groups around the dead monster), events (new events used `lev[xy]` (now `get_abs_lev[xy]`) and the comparison for player being near does so), `iuse::directional_antenna`, `find_radio_station`, checking for monster groups in game.cpp, faction::response_time, ...

----

Vehicle tracking across overmaps works better now. It does not refer to `game::cur_om` anymore. Also the members `vehicle::levx`/`vehicle::levy` have been removed. Instead the vehicle tracker is only updated when the vehicle is actually moved (with `map::displace_vehicle`), there is currently no other place that moves vehicles.

All other changes to `vehicle::smx`/`vehicle::smy` don't indicate an actual movement, but a shift of the main map. This does not change the vehicle's position on the overmap and does not trigger an update there. `vehicle::sm[xy]` still refers to the grid coordinates in the map (that is into `map::grid`). They still have to change whenever the map is shifted.

I moved the tracking code into `overmapbuffer`. It gets the real global coordinates of the vehicle (in map squares, using `map::getabs`) and translates them into the overmap terrain coordinates that are stored in the overmap. There are two vehicle function `vehicle::global_[y]()` which actually return coordinates that are relative to the main map (same coordinate system as `player::posx`), they are not really global at all. I added some comments to them. `map::getabs` is a quite useful functions in combination with the `overmapbuffer` coordinate translation functions. I used it in `iuse::fishing_rod_basic` or `player::knows_trap`, too.

----

@CIB A small change, that conflicts with the Map-3D PR: I removed the need to call `map::loadn` when the submaps have been generated. Instead that function calls itself in that situation.

----

The bug from http://smf.cataclysmdda.com/index.php?topic=7103 is fixed. @acidia you might want to enable the two-way radio again. It' should work now.

The created npc what not placed on the overmap, (compare the old code with the code in `game::debug` that create a new npcs, or with the code in `map::place_npc`). There was no `npc::spawn_at` call at all and the npc was created on the stack instead of the heap anyway.

----

I moved the generation of the tutorial overmap into the tutorial class (was in overmap) because the overmap simply should not know about special game modes.

----

Open questions:
1. What about `npc::perform_mission`? It is not used (the last reference (a commented call) to it was removed by b3c93c246e6a688fbf4264b24d6040ca0146a6b8). That function moves non-active npcs around the overmap. Currently only npcs that are in the reality bubble of the player are moving at all. Should it be enabled?
2. I suggest changing all or at least some of the coordinates to (tri)points. That makes them easier to transport between functions and keeps the xy(z) values together. It also makes porting them to 3D way easier. How about that?