Skip to content

Commit

Permalink
sync L1RoomGen with L4RoomGen
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Sep 25, 2024
1 parent 6030fe5 commit f94034b
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Source/drlg_l1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1111,32 +1111,36 @@ static void L1RoomGen(int x, int y, int w, int h, bool dir)
ry = h / 2u + y - height / 2u;
rx = x - width;
if (L1CheckVHall(x, ry - 1, height + 2)
&& L1CheckRoom(rx - 1, ry - 1, width + 1, height + 2)) // BUGFIX: swap args 3 and 4 ("height+2" and "width+1") (fixed)
&& L1CheckRoom(rx - 1, ry - 1, width + 1, height + 2)) { // BUGFIX: swap args 3 and 4 ("height+2" and "width+1") (fixed)
// - add room to the left
L1DrawRoom(rx, ry, width, height);
break;
}
}
// - add room to the left
if (i != 0) {
L1DrawRoom(rx, ry, width, height);
// room added to the left -> force similar room on the right side
i = 1;
} else {
// room was not added to the left -> try to more options on the right
rx = -1;
i = 20;
}
// try to place a room to the right
rxy2 = x + w;
while (true) {
if (L1CheckVHall(rxy2 - 1, ry - 1, height + 2)
&& L1CheckRoom(rxy2, ry - 1, width + 1, height + 2))
&& L1CheckRoom(rxy2, ry - 1, width + 1, height + 2)) {
// - add room to the right
L1DrawRoom(rxy2, ry, width, height);
break;
}
if (--i == 0)
break;
width = RandRange(2, 6) & ~1;
height = RandRange(2, 6) & ~1;
ry = h / 2u + y - height / 2u;
}
// - add room to the right
if (i != 0)
L1DrawRoom(rxy2, ry, width, height);
// proceed with the placed a room on the left
if (rx >= 0)
L1RoomGen(rx, ry, width, height, true);
Expand All @@ -1151,32 +1155,35 @@ static void L1RoomGen(int x, int y, int w, int h, bool dir)
rx = w / 2u + x - width / 2u;
ry = y - height;
if (L1CheckHHall(y, rx - 1, width + 2)
&& L1CheckRoom(rx - 1, ry - 1, width + 2, height + 1))
&& L1CheckRoom(rx - 1, ry - 1, width + 2, height + 1)) {
// - add room to the top
L1DrawRoom(rx, ry, width, height);
break;
}
}
// - add room to the top
if (i != 0) {
L1DrawRoom(rx, ry, width, height);
// room added to the top -> force similar room on the bottom side
i = 1;
} else {
// room was not added to the top -> try to more options on the bottom
ry = -1;
i = 20;
}
// try to place a room to the bottom
rxy2 = y + h;
while (true) {
if (L1CheckHHall(rxy2 - 1, rx - 1, width + 2)
&& L1CheckRoom(rx - 1, rxy2, width + 2, height + 1))
&& L1CheckRoom(rx - 1, rxy2, width + 2, height + 1)) {
// - add room to the bottom
L1DrawRoom(rx, rxy2, width, height);
break;
}
if (--i == 0)
break;
width = RandRange(2, 6) & ~1;
height = RandRange(2, 6) & ~1;
rx = w / 2u + x - width / 2u;
}
// - add room to the bottom
if (i != 0)
L1DrawRoom(rx, rxy2, width, height);
// proceed with the placed a room on the top
if (ry >= 0)
L1RoomGen(rx, ry, width, height, false);
Expand Down

0 comments on commit f94034b

Please sign in to comment.