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

Redo the level if stairs cannot be placed #635

Merged
merged 1 commit into from
Dec 21, 2023
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
34 changes: 24 additions & 10 deletions src/brogue/Architect.c
Original file line number Diff line number Diff line change
Expand Up @@ -3669,15 +3669,10 @@ static void prepareForStairs(short x, short y, char grid[DCOLS][DROWS]) {
}
}

// Places the player, monsters, items and stairs.
void initializeLevel() {
short i, j, dir;
short **mapToStairs, **mapToPit;
boolean placeStairs(pos *upStairsLoc) {
char grid[DCOLS][DROWS];
short n = rogue.depthLevel - 1;

// Place the stairs.

for (int i=0; i < DCOLS; i++) {
for (int j=0; j < DROWS; j++) {
grid[i][j] = validStairLoc(i, j);
Expand All @@ -3694,9 +3689,12 @@ void initializeLevel() {
if (getQualifyingGridLocNear(&downLoc, levels[n].downStairsLoc, grid, false)) {
prepareForStairs(downLoc.x, downLoc.y, grid);
} else {
getQualifyingLocNear(&downLoc, levels[n].downStairsLoc, false, 0,
(T_OBSTRUCTS_PASSABILITY | T_OBSTRUCTS_ITEMS | T_AUTO_DESCENT | T_IS_DEEP_WATER | T_LAVA_INSTA_DEATH | T_IS_DF_TRAP),
(HAS_MONSTER | HAS_ITEM | HAS_STAIRS | IS_IN_MACHINE), true, false);
boolean hasQualifyingLoc = getQualifyingLocNear(&downLoc, levels[n].downStairsLoc, false, 0,
(T_OBSTRUCTS_PASSABILITY | T_OBSTRUCTS_ITEMS | T_AUTO_DESCENT | T_IS_DEEP_WATER | T_LAVA_INSTA_DEATH | T_IS_DF_TRAP),
(HAS_MONSTER | HAS_ITEM | HAS_STAIRS | IS_IN_MACHINE), true, false);
if (!hasQualifyingLoc) {
return false;
}
}

if (rogue.depthLevel == gameConst->deepestLevel) {
Expand All @@ -3716,9 +3714,13 @@ void initializeLevel() {
if (getQualifyingGridLocNear(&upLoc, levels[n].upStairsLoc, grid, false)) {
prepareForStairs(upLoc.x, upLoc.y, grid);
} else { // Hopefully this never happens.
getQualifyingLocNear(&upLoc, levels[n].upStairsLoc, false, 0,
boolean hasQualifyingLoc;
hasQualifyingLoc = getQualifyingLocNear(&upLoc, levels[n].upStairsLoc, false, 0,
(T_OBSTRUCTS_PASSABILITY | T_OBSTRUCTS_ITEMS | T_AUTO_DESCENT | T_IS_DEEP_WATER | T_LAVA_INSTA_DEATH | T_IS_DF_TRAP),
(HAS_MONSTER | HAS_ITEM | HAS_STAIRS | IS_IN_MACHINE), true, false);
if (!hasQualifyingLoc) {
return false;
}
}

levels[n].upStairsLoc = upLoc;
Expand All @@ -3736,6 +3738,18 @@ void initializeLevel() {
rogue.upLoc = upLoc;
pmapAt(upLoc)->flags |= HAS_STAIRS;

*upStairsLoc = upLoc;
return true;
}

// Places the player, monsters, items and stairs.
void initializeLevel(pos upStairsLoc) {
short i, j, dir;
short **mapToStairs, **mapToPit;
char grid[DCOLS][DROWS];

pos upLoc = upStairsLoc;

if (!levels[rogue.depthLevel-1].visited) {

// Run a field of view check from up stairs so that monsters do not spawn within sight of it.
Expand Down
3 changes: 2 additions & 1 deletion src/brogue/Rogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2982,7 +2982,8 @@ extern "C" {
void nextBrogueEvent(rogueEvent *returnEvent, boolean textInput, boolean colorsDance, boolean realInputEvenInPlayback);
void executeMouseClick(rogueEvent *theEvent);
void executeKeystroke(signed long keystroke, boolean controlKey, boolean shiftKey);
void initializeLevel(void);
boolean placeStairs(pos *upStairsLoc);
void initializeLevel(pos upStairsLoc);
void startLevel (short oldLevelNumber, short stairDirection);
void updateMinersLightRadius(void);
void freeCreature(creature *monst);
Expand Down
15 changes: 13 additions & 2 deletions src/brogue/RogueMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,19 @@ void startLevel(short oldLevelNumber, short stairDirection) {

levels[rogue.depthLevel-1].items = NULL;

digDungeon();
initializeLevel();
pos upStairLocation;
int failsafe;
for (failsafe = 50; failsafe; failsafe--) {
digDungeon();
if (placeStairs(&upStairLocation)) {
break;
}
}
if (!failsafe) {
printf("\nFailed to place stairs for level %d! Please report this error\n", rogue.depthLevel);
exit(1);
}
initializeLevel(upStairLocation);
setUpWaypoints();

shuffleTerrainColors(100, false);
Expand Down