Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #21: segfault on going downstairs #22

Merged
merged 1 commit into from
Jan 26, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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