Skip to content

Commit

Permalink
fix bias in L4RoomGen
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Aug 30, 2024
1 parent 34c6642 commit 8daebbd
Showing 1 changed file with 54 additions and 20 deletions.
74 changes: 54 additions & 20 deletions Source/drlg_l4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,6 @@ static bool L4CheckHHall(int y, int left, int w)
static void L4RoomGen(int x, int y, int w, int h, bool dir)
{
int dirProb, i, width, height, rx, ry, rxy2;
bool ran2;

dirProb = random_(0, 4);

Expand All @@ -1377,23 +1376,40 @@ static void L4RoomGen(int x, int y, int w, int h, bool dir)
ry = h / 2u + y - height / 2u;
rx = x - width;
if (L4CheckVHall(x, ry - 1, height + 2)
&& L4CheckRoom(rx - 1, ry - 1, width + 1, height + 2)) /// BUGFIX: swap args 3 and 4 ("ch+2" and "cw+1") (fixed)
&& L4CheckRoom(rx - 1, ry - 1, width + 1, height + 2)) { /// BUGFIX: swap args 3 and 4 ("ch+2" and "cw+1") (fixed)
// - add room to the left
L4DrawRoom(rx, ry, width, height);
break;
}
}
if (i != 0) {
// room added to the left -> force similar room on the right side
i = 1;
} else {
// room was not added to the left -> try more options on the right
rx = -1;
i = 20;
}

if (i != 0)
L4DrawRoom(rx, ry, width, height);
// try to place a room to the right
rxy2 = x + w;
ran2 = L4CheckVHall(rxy2 - 1, ry - 1, height + 2)
&& L4CheckRoom(rxy2, ry - 1, width + 1, height + 2);
if (ran2)
L4DrawRoom(rxy2, ry, width, height);
while(true) {
if (L4CheckVHall(rxy2 - 1, ry - 1, height + 2)
&& L4CheckRoom(rxy2, ry - 1, width + 1, height + 2)) {
// - add room to the right
L4DrawRoom(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;
}
// proceed with the placed a room on the left
if (i != 0)
if (rx >= 0)
L4RoomGen(rx, ry, width, height, true);
// proceed with the placed a room on the right
if (ran2)
if (i != 0)
L4RoomGen(rxy2, ry, width, height, true);
} else {
// try to place a room to the top
Expand All @@ -1403,23 +1419,41 @@ static void L4RoomGen(int x, int y, int w, int h, bool dir)
rx = w / 2u + x - width / 2u;
ry = y - height;
if (L4CheckHHall(y, rx - 1, width + 2)
&& L4CheckRoom(rx - 1, ry - 1, width + 2, height + 1))
&& L4CheckRoom(rx - 1, ry - 1, width + 2, height + 1)) {
// - add room to the top
L4DrawRoom(rx, ry, width, height);
break;
}
}

if (i != 0)
L4DrawRoom(rx, ry, width, height);
if (i != 0) {
// room added to the top -> force similar room on the bottom side
i = 1;
} else {
// room was not added to the top -> try more options on the bottom
ry = -1;
i = 20;
}
// try to place a room to the bottom
rxy2 = y + h;
ran2 = L4CheckHHall(rxy2 - 1, rx - 1, width + 2)
&& L4CheckRoom(rx - 1, rxy2, width + 2, height + 1);
if (ran2)
L4DrawRoom(rx, rxy2, width, height);
while(true) {
if (L4CheckHHall(rxy2 - 1, rx - 1, width + 2)
&& L4CheckRoom(rx - 1, rxy2, width + 2, height + 1)) {
// - add room to the bottom
L4DrawRoom(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;
}
// proceed with the placed a room on the top
if (i != 0)
if (ry >= 0)
L4RoomGen(rx, ry, width, height, false);
// proceed with the placed a room on the bottom
if (ran2)
if (i != 0)
L4RoomGen(rx, rxy2, width, height, false);
}
}
Expand Down

0 comments on commit 8daebbd

Please sign in to comment.