Basement crashing bug and solution

There are actually two bugs, two ways this bug can manifest. More obvious one is that monsters will not follow the character down and up the basement stairs, but instead spawn at seemingly random place. And more rarely, mostly when the house is facing East, simply going up the stairs will crash the game.

Why? Because while houses are rotated to face one of four compass directions the basements all have one orientation where the stairs are placed at the South end of it. To fix all this simply put this piece of code at the end of ‘case ot_basement:’ block.

case ot_basement:
.
.
.

//CAT-mgs: prevent crashing bug
  if(t_above == ot_house_east || t_above == ot_house_base_east)
   rotate(1);
  if(t_above == ot_house_south || t_above == ot_house_base_south)
   rotate(2);
  if(t_above == ot_house_west  || t_above == ot_house_base_west)
   rotate(3);

break;

This will also bring a little variety to how basements look like. Unfortunately it doesn’t quite fix monsters using stairs, but it’s much better, and what’s really important the game will not crash. I think monsters not using stairs has to do with random placement of stairs leading down and the problem seem proportional to the difference in position of down-stairs and up-stairs. Ideally down-stairs should be right on top of up-stairs.

Actually it’s “void game::update_stair_monsters()” in game.cpp that is flawed and responsible for monsters not always using the stairs. That a little bit more complicated to fix than just with a few lines of code, let me know if you are interested.