Skip to content

Commit

Permalink
fix bias in L4ConnectBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
pionere committed Aug 31, 2024
1 parent 17c6df9 commit dd0e1b8
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions Source/drlg_l4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,22 @@ static void L4Block2Dungeon()
}
}

static int L4SelectPos(const BYTE (&hall)[20])
{
int i, n, rv;
BYTE match[20];
n = 0;
for (i = 20 - 2; i > 0; i--) {
if (hall[i] != 0 && hall[i] == hall[i + 1]) {
match[n] = i;
n++;
}
}
// assert(n != 0);
rv = random_low(0, n);
return match[rv];
}

/*
* Create link between the quarters (blocks) of the dungeon.
*/
Expand All @@ -1216,21 +1232,12 @@ static void L4ConnectBlock()
}
hallok[j] = i;
}
// select a position with matching 2 tiles-wide ending
rv = L4SelectPos(hallok);
// connect to the right side of the dungeon
rv = RandRange(1, L4BLOCKY - 1);
while (true) {
if (hallok[rv] != 0 && hallok[rv] == hallok[rv + 1]) {
for (i = L4BLOCKX - 1; i > hallok[rv]; i--) {
drlg.dungBlock[i][rv] = 1;
drlg.dungBlock[i][rv + 1] = 1;
}
break;
} else {
rv++;
if (rv == L4BLOCKY - 1) {
rv = 1;
}
}
for (i = L4BLOCKX - 1; i > hallok[rv]; i--) {
drlg.dungBlock[i][rv] = 1;
drlg.dungBlock[i][rv + 1] = 1;
}

// find the bottom side of the rooms
Expand All @@ -1242,21 +1249,12 @@ static void L4ConnectBlock()
}
hallok[i] = j;
}
// select a position with matching 2 tiles-wide ending
rv = L4SelectPos(hallok);
// connect to the bottom side of the dungeon
rv = RandRange(1, L4BLOCKX - 1);
while (true) {
if (hallok[rv] != 0 && hallok[rv] == hallok[rv + 1]) {
for (j = L4BLOCKY - 1; j > hallok[rv]; j--) {
drlg.dungBlock[rv][j] = 1;
drlg.dungBlock[rv + 1][j] = 1;
}
break;
} else {
rv++;
if (rv == L4BLOCKX - 1) {
rv = 1;
}
}
for (j = L4BLOCKY - 1; j > hallok[rv]; j--) {
drlg.dungBlock[rv][j] = 1;
drlg.dungBlock[rv + 1][j] = 1;
}
}

Expand Down

0 comments on commit dd0e1b8

Please sign in to comment.