From be7a0d3c323b6abccb48ecae134b30f8099a8e6d Mon Sep 17 00:00:00 2001 From: Zach Morgan Date: Sat, 26 Jan 2013 10:05:10 -0500 Subject: [PATCH] descending stairs, using an elevator, and debug-teleporting no longer crash when right next to overmap borders. stuff was only being dynamically generated for one of the overmaps. --- game.cpp | 3 +++ game.h | 2 +- map.cpp | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/game.cpp b/game.cpp index c957a2963d20a..f5487e2e9a228 100644 --- a/game.cpp +++ b/game.cpp @@ -2041,6 +2041,7 @@ void game::debug() z.clear(); levx = tmp.x * 2 - int(MAPSIZE / 2); levy = tmp.y * 2 - int(MAPSIZE / 2); + set_adjacent_overmaps(true); m.load(this, levx, levy); } } break; @@ -4426,6 +4427,7 @@ void game::examine() //m.save(&cur_om, turn, levx, levy); overmap(this, cur_om.posx, cur_om.posy, -1); cur_om = overmap(this, cur_om.posx, cur_om.posy, cur_om.posz + movez); + set_adjacent_overmaps(true); m.load(this, levx, levy); update_map(u.posx, u.posy); for (int x = 0; x < SEEX * MAPSIZE; x++) { @@ -6908,6 +6910,7 @@ void game::vertical_move(int movez, bool force) cur_om.save(u.name); //m.save(&cur_om, turn, levx, levy); cur_om = overmap(this, cur_om.posx, cur_om.posy, cur_om.posz + movez); + set_adjacent_overmaps(true); map tmpmap(&itypes, &mapitems, &traps); tmpmap.load(this, levx, levy, false); cur_om = overmap(this, cur_om.posx, cur_om.posy, original_z); diff --git a/game.h b/game.h index 79da1eb985120..6e66247e752b6 100644 --- a/game.h +++ b/game.h @@ -237,6 +237,7 @@ class game WINDOW *w_messages; WINDOW *w_location; WINDOW *w_status; + overmap *om_hori, *om_vert, *om_diag; // Adjacent overmaps private: // Game-start procedures @@ -388,7 +389,6 @@ class game calendar nextspawn; // The turn on which monsters will spawn next. calendar nextweather; // The turn on which weather will shift next. - overmap *om_hori, *om_vert, *om_diag; // Adjacent overmaps int next_npc_id, next_faction_id, next_mission_id; // Keep track of UIDs std::vector messages; // Messages to be printed int curmes; // The last-seen message. diff --git a/map.cpp b/map.cpp index 2e4349ab95be1..ffcf3060a3d48 100644 --- a/map.cpp +++ b/map.cpp @@ -2784,11 +2784,28 @@ bool map::loadn(game *g, int worldx, int worldy, int gridx, int gridy, bool upda // squares divisible by 2. int newmapx = worldx + gridx - ((worldx + gridx) % 2); int newmapy = worldy + gridy - ((worldy + gridy) % 2); + overmap* this_om = &(g->cur_om); + + // slightly out of bounds? to the east, south, or both? + // cur_om is the one containing the upper-left corner of the map + if (newmapx >= OMAPX*2){ + newmapx -= OMAPX*2; + this_om = g->om_hori; + if (newmapy >= OMAPY*2){ + newmapy -= OMAPY*2; + this_om = g->om_diag; + } + } + else if (newmapy >= OMAPY*2){ + newmapy -= OMAPY*2; + this_om = g->om_vert; + } + if (worldx + gridx < 0) newmapx = worldx + gridx; if (worldy + gridy < 0) newmapy = worldy + gridy; - tmp_map.generate(g, &(g->cur_om), newmapx, newmapy, int(g->turn)); + tmp_map.generate(g, this_om, newmapx, newmapy, int(g->turn)); return false; } return true;