Skip to content

Commit

Permalink
Merge pull request #22 from zpmorgan/master
Browse files Browse the repository at this point in the history
fix for #21: segfault on going downstairs
  • Loading branch information
TheDarklingWolf committed Jan 26, 2013
2 parents 31fed07 + be7a0d3 commit e1ac6ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <game_message> messages; // Messages to be printed
int curmes; // The last-seen message.
Expand Down
19 changes: 18 additions & 1 deletion map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e1ac6ac

Please sign in to comment.