♻️Clean up variable initialization

This commit is contained in:
Anders Jenbo 2021-06-27 19:33:47 +02:00
commit 0f2ad469ea
29 changed files with 737 additions and 901 deletions

View file

@ -63,11 +63,10 @@ int trm3y[] = {
bool TFit_Shrine(int i)
{
int xp, yp, found;
int xp = 0;
int yp = 0;
int found = 0;
xp = 0;
yp = 0;
found = 0;
while (found == 0) {
if (dTransVal[xp][yp] == themes[i].ttval) {
if (nTrapTable[dPiece[xp][yp - 1]]
@ -108,19 +107,16 @@ bool TFit_Shrine(int i)
bool TFit_Obj5(int t)
{
int xp, yp;
int i, r, rs;
bool found;
int xp = 0;
int yp = 0;
int r = GenerateRnd(5) + 1;
int rs = r;
xp = 0;
yp = 0;
r = GenerateRnd(5) + 1;
rs = r;
while (r > 0) {
found = false;
bool found = false;
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
found = true;
for (i = 0; found && i < 25; i++) {
for (int i = 0; found && i < 25; i++) {
if (nSolidTable[dPiece[xp + trm5x[i]][yp + trm5y[i]]]) {
found = false;
}
@ -208,11 +204,10 @@ bool CheckThemeObj3(int xp, int yp, int t, int f)
bool TFit_Obj3(int t)
{
int xp, yp;
char objrnd[4] = { 4, 4, 3, 5 };
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (CheckThemeObj3(xp, yp, t, objrnd[leveltype - 1])) {
themex = xp;
themey = yp;
@ -226,57 +221,54 @@ bool TFit_Obj3(int t)
bool CheckThemeReqs(theme_id t)
{
bool rv;
rv = true;
switch (t) {
case THEME_SHRINE:
case THEME_SKELROOM:
case THEME_LIBRARY:
if (leveltype == DTYPE_CAVES || leveltype == DTYPE_HELL) {
rv = false;
return false;
}
break;
case THEME_BLOODFOUNTAIN:
if (!bFountainFlag) {
rv = false;
return false;
}
break;
case THEME_PURIFYINGFOUNTAIN:
if (!pFountainFlag) {
rv = false;
return false;
}
break;
case THEME_ARMORSTAND:
if (leveltype == DTYPE_CATHEDRAL) {
rv = false;
return false;
}
break;
case THEME_CAULDRON:
if (leveltype != DTYPE_HELL || !cauldronFlag) {
rv = false;
return false;
}
break;
case THEME_MURKYFOUNTAIN:
if (!mFountainFlag) {
rv = false;
return false;
}
break;
case THEME_TEARFOUNTAIN:
if (!tFountainFlag) {
rv = false;
return false;
}
break;
case THEME_WEAPONRACK:
if (leveltype == DTYPE_CATHEDRAL) {
rv = false;
return false;
}
break;
default:
break;
}
return rv;
return true;
}
static bool SpecialThemeFit(int i, theme_id t)
@ -365,16 +357,14 @@ static bool SpecialThemeFit(int i, theme_id t)
bool CheckThemeRoom(int tv)
{
int i, j, tarea;
for (i = 0; i < numtrigs; i++) {
for (int i = 0; i < numtrigs; i++) {
if (dTransVal[trigs[i].position.x][trigs[i].position.y] == tv)
return false;
}
tarea = 0;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
int tarea = 0;
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dTransVal[i][j] != tv)
continue;
if ((dFlags[i][j] & BFLAG_POPULATED) != 0)
@ -387,8 +377,8 @@ bool CheckThemeRoom(int tv)
if (leveltype == DTYPE_CATHEDRAL && (tarea < 9 || tarea > 100))
return false;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) {
if (dTransVal[i][j] != tv || nSolidTable[dPiece[i][j]])
continue;
if (dTransVal[i - 1][j] != tv && !nSolidTable[dPiece[i - 1][j]])
@ -467,23 +457,22 @@ void InitThemes()
*/
void HoldThemeRooms()
{
int i, x, y;
char v;
if (currlevel == 16)
return;
if (currlevel != 16) {
if (leveltype == DTYPE_CATHEDRAL) {
for (i = 0; i < numthemes; i++) {
v = themes[i].ttval;
for (y = 0; y < MAXDUNY; y++) {
for (x = 0; x < MAXDUNX; x++) {
if (dTransVal[x][y] == v) {
dFlags[x][y] |= BFLAG_POPULATED;
}
}
if (leveltype != DTYPE_CATHEDRAL) {
DRLG_HoldThemeRooms();
return;
}
for (int i = 0; i < numthemes; i++) {
uint8_t v = themes[i].ttval;
for (int y = 0; y < MAXDUNY; y++) {
for (int x = 0; x < MAXDUNX; x++) {
if (dTransVal[x][y] == v) {
dFlags[x][y] |= BFLAG_POPULATED;
}
}
} else {
DRLG_HoldThemeRooms();
}
}
}
@ -496,20 +485,18 @@ void HoldThemeRooms()
*/
void PlaceThemeMonsts(int t, int f)
{
int xp, yp;
int scattertypes[138];
int numscattypes, mtype, i;
numscattypes = 0;
for (i = 0; i < nummtypes; i++) {
int numscattypes = 0;
for (int i = 0; i < nummtypes; i++) {
if ((Monsters[i].mPlaceFlags & PLACE_SCATTER) != 0) {
scattertypes[numscattypes] = i;
numscattypes++;
}
}
mtype = scattertypes[GenerateRnd(numscattypes)];
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
int mtype = scattertypes[GenerateRnd(numscattypes)];
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]] && dItem[xp][yp] == 0 && dObject[xp][yp] == 0) {
if (GenerateRnd(f) == 0) {
AddMonster({ xp, yp }, static_cast<Direction>(GenerateRnd(8)), mtype, true);
@ -526,12 +513,11 @@ void PlaceThemeMonsts(int t, int f)
*/
void Theme_Barrel(int t)
{
int xp, yp;
char barrnd[4] = { 2, 6, 4, 8 };
char monstrnd[4] = { 5, 7, 3, 9 };
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (GenerateRnd(barrnd[leveltype - 1]) == 0) {
_object_id r = OBJ_BARREL;
@ -575,13 +561,11 @@ void Theme_Shrine(int t)
*/
void Theme_MonstPit(int t)
{
int r;
int ixp, iyp;
char monstrnd[4] = { 6, 7, 3, 9 };
uint8_t monstrnd[4] = { 6, 7, 3, 9 };
r = GenerateRnd(100) + 1;
ixp = 0;
iyp = 0;
int r = GenerateRnd(100) + 1;
int ixp = 0;
int iyp = 0;
while (r > 0) {
if (dTransVal[ixp][iyp] == themes[t].ttval && !nSolidTable[dPiece[ixp][iyp]]) {
--r;
@ -609,56 +593,59 @@ void Theme_MonstPit(int t)
*/
void Theme_SkelRoom(int t)
{
int xp, yp, i;
char monstrnd[4] = { 6, 7, 3, 9 };
TFit_SkelRoom(t);
xp = themex;
yp = themey;
int xp = themex;
int yp = themey;
AddObject(OBJ_SKFIRE, xp, yp);
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp - 1, yp - 1 });
} else {
AddObject(OBJ_BANNERL, xp - 1, yp - 1);
}
i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp - 1 });
{
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp - 1 });
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp + 1, yp - 1 });
} else {
AddObject(OBJ_BANNERR, xp + 1, yp - 1);
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp - 1, yp });
} else {
AddObject(OBJ_BANNERM, xp - 1, yp);
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp + 1, yp });
} else {
AddObject(OBJ_BANNERM, xp + 1, yp);
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp - 1, yp + 1 });
} else {
AddObject(OBJ_BANNERR, xp - 1, yp + 1);
}
i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp + 1 });
{
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp, yp + 1 });
}
if (GenerateRnd(monstrnd[leveltype - 1]) != 0) {
i = PreSpawnSkeleton();
int i = PreSpawnSkeleton();
SpawnSkeleton(i, { xp + 1, yp + 1 });
} else {
AddObject(OBJ_BANNERL, xp + 1, yp + 1);
@ -679,14 +666,12 @@ void Theme_SkelRoom(int t)
*/
void Theme_Treasure(int t)
{
int xp, yp;
int i;
char treasrnd[4] = { 4, 9, 7, 10 };
char monstrnd[4] = { 6, 8, 3, 7 };
AdvanceRndSeed();
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
int rv = GenerateRnd(treasrnd[leveltype - 1]);
// BUGFIX: the `2*` in `2*GenerateRnd(treasrnd...) == 0` has no effect, should probably be `GenerateRnd(2*treasrnd...) == 0`
@ -699,7 +684,7 @@ void Theme_Treasure(int t)
ItemNoFlippy();
}
if (rv == 0 || rv >= treasrnd[leveltype - 1] - 2) {
i = ItemNoFlippy();
int i = ItemNoFlippy();
if (rv >= treasrnd[leveltype - 1] - 2 && leveltype != DTYPE_CATHEDRAL) {
items[i]._ivalue /= 2;
}
@ -717,7 +702,6 @@ void Theme_Treasure(int t)
*/
void Theme_Library(int t)
{
int xp, yp, oi;
char librnd[4] = { 1, 2, 2, 5 };
char monstrnd[4] = { 5, 7, 3, 9 };
@ -733,12 +717,12 @@ void Theme_Library(int t)
AddObject(OBJ_BOOKCANDLE, themex, themey + 1);
}
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (CheckThemeObj3(xp, yp, t, -1) && dMonster[xp][yp] == 0 && GenerateRnd(librnd[leveltype - 1]) == 0) {
AddObject(OBJ_BOOKSTAND, xp, yp);
if (GenerateRnd(2 * librnd[leveltype - 1]) != 0 && dObject[xp][yp] != 0) { /// BUGFIX: check dObject[xp][yp] was populated by AddObject (fixed)
oi = dObject[xp][yp] - 1;
int oi = dObject[xp][yp] - 1;
object[oi]._oSelFlag = 0;
object[oi]._oAnimFrame += 2;
}
@ -763,12 +747,11 @@ void Theme_Library(int t)
*/
void Theme_Torture(int t)
{
int xp, yp;
char tortrnd[4] = { 6, 8, 3, 8 };
char monstrnd[4] = { 6, 8, 3, 9 };
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(tortrnd[leveltype - 1]) == 0) {
@ -801,12 +784,11 @@ void Theme_BloodFountain(int t)
*/
void Theme_Decap(int t)
{
int xp, yp;
char decaprnd[4] = { 6, 8, 3, 8 };
char monstrnd[4] = { 6, 8, 3, 9 };
for (yp = 1; yp < MAXDUNY - 1; yp++) {
for (xp = 1; xp < MAXDUNX - 1; xp++) {
for (int yp = 1; yp < MAXDUNY - 1; yp++) {
for (int xp = 1; xp < MAXDUNX - 1; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(decaprnd[leveltype - 1]) == 0) {
@ -840,7 +822,6 @@ void Theme_PurifyingFountain(int t)
*/
void Theme_ArmorStand(int t)
{
int xp, yp;
char armorrnd[4] = { 6, 8, 3, 8 };
char monstrnd[4] = { 6, 7, 3, 9 };
@ -848,8 +829,8 @@ void Theme_ArmorStand(int t)
TFit_Obj3(t);
AddObject(OBJ_ARMORSTAND, themex, themey);
}
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(armorrnd[leveltype - 1]) == 0) {
@ -870,12 +851,10 @@ void Theme_ArmorStand(int t)
*/
void Theme_GoatShrine(int t)
{
int xx, yy;
TFit_GoatShrine(t);
AddObject(OBJ_GOATSHRINE, themex, themey);
for (yy = themey - 1; yy <= themey + 1; yy++) {
for (xx = themex - 1; xx <= themex + 1; xx++) {
for (int yy = themey - 1; yy <= themey + 1; yy++) {
for (int xx = themex - 1; xx <= themex + 1; xx++) {
if (dTransVal[xx][yy] == themes[t].ttval && !nSolidTable[dPiece[xx][yy]] && (xx != themex || yy != themey)) {
AddMonster({ xx, yy }, DIR_SW, themeVar1, true);
}
@ -932,12 +911,11 @@ void Theme_TearFountain(int t)
*/
void Theme_BrnCross(int t)
{
int xp, yp;
char monstrnd[4] = { 6, 8, 3, 9 };
char bcrossrnd[4] = { 5, 7, 3, 8 };
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(bcrossrnd[leveltype - 1]) == 0) {
@ -958,7 +936,6 @@ void Theme_BrnCross(int t)
*/
void Theme_WeaponRack(int t)
{
int xp, yp;
char weaponrnd[4] = { 6, 8, 5, 8 };
char monstrnd[4] = { 6, 7, 3, 9 };
@ -966,8 +943,8 @@ void Theme_WeaponRack(int t)
TFit_Obj3(t);
AddObject(OBJ_WEAPONRACK, themex, themey);
}
for (yp = 0; yp < MAXDUNY; yp++) {
for (xp = 0; xp < MAXDUNX; xp++) {
for (int yp = 0; yp < MAXDUNY; yp++) {
for (int xp = 0; xp < MAXDUNX; xp++) {
if (dTransVal[xp][yp] == themes[t].ttval && !nSolidTable[dPiece[xp][yp]]) {
if (CheckThemeObj3(xp, yp, t, -1)) {
if (GenerateRnd(weaponrnd[leveltype - 1]) == 0) {
@ -986,10 +963,8 @@ void Theme_WeaponRack(int t)
*/
void UpdateL4Trans()
{
int i, j;
for (j = 0; j < MAXDUNY; j++) {
for (i = 0; i < MAXDUNX; i++) {
for (int j = 0; j < MAXDUNY; j++) {
for (int i = 0; i < MAXDUNX; i++) { // NOLINT(modernize-loop-convert)
if (dTransVal[i][j] != 0) {
dTransVal[i][j] = 1;
}
@ -1002,13 +977,11 @@ void UpdateL4Trans()
*/
void CreateThemeRooms()
{
int i;
if (currlevel == 16) {
return;
}
InitObjFlag = true;
for (i = 0; i < numthemes; i++) {
for (int i = 0; i < numthemes; i++) {
themex = 0;
themey = 0;
switch (themes[i].ttype) {