Fixes for degenerate RNG
Assume a degenerate RNG that always returns the same number. With these fixes, the game starts and is almost playable. There are still some places that will go into infinite loop, eg. the mines level generation.
This commit is contained in:
@@ -812,6 +812,7 @@ makelevel()
|
|||||||
|
|
||||||
/* for each room: put things inside */
|
/* for each room: put things inside */
|
||||||
for (croom = g.rooms; croom->hx > 0; croom++) {
|
for (croom = g.rooms; croom->hx > 0; croom++) {
|
||||||
|
int trycnt = 0;
|
||||||
if (croom->rtype != OROOM)
|
if (croom->rtype != OROOM)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -833,7 +834,7 @@ makelevel()
|
|||||||
x = 8 - (level_difficulty() / 6);
|
x = 8 - (level_difficulty() / 6);
|
||||||
if (x <= 1)
|
if (x <= 1)
|
||||||
x = 2;
|
x = 2;
|
||||||
while (!rn2(x))
|
while (!rn2(x) && (++trycnt < 1000))
|
||||||
mktrap(0, 0, croom, (coord *) 0);
|
mktrap(0, 0, croom, (coord *) 0);
|
||||||
if (!rn2(3))
|
if (!rn2(3))
|
||||||
(void) mkgold(0L, somex(croom), somey(croom));
|
(void) mkgold(0L, somex(croom), somey(croom));
|
||||||
@@ -1121,6 +1122,7 @@ coord *mp;
|
|||||||
if (g.nroom == 0) {
|
if (g.nroom == 0) {
|
||||||
mazexy(mp); /* already verifies location */
|
mazexy(mp); /* already verifies location */
|
||||||
} else {
|
} else {
|
||||||
|
int cnt = 0;
|
||||||
/* not perfect - there may be only one stairway */
|
/* not perfect - there may be only one stairway */
|
||||||
if (g.nroom > 2) {
|
if (g.nroom > 2) {
|
||||||
int tryct = 0;
|
int tryct = 0;
|
||||||
@@ -1135,9 +1137,9 @@ coord *mp;
|
|||||||
do {
|
do {
|
||||||
if (!somexy(croom, mp))
|
if (!somexy(croom, mp))
|
||||||
impossible("Can't place branch!");
|
impossible("Can't place branch!");
|
||||||
} while (occupied(mp->x, mp->y)
|
} while ((occupied(mp->x, mp->y)
|
||||||
|| (levl[mp->x][mp->y].typ != CORR
|
|| (levl[mp->x][mp->y].typ != CORR
|
||||||
&& levl[mp->x][mp->y].typ != ROOM));
|
&& levl[mp->x][mp->y].typ != ROOM)) && (++cnt < 1000));
|
||||||
}
|
}
|
||||||
return croom;
|
return croom;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1035,6 +1035,7 @@ const char *s;
|
|||||||
mazexy(&mm);
|
mazexy(&mm);
|
||||||
mkstairs(mm.x, mm.y, 0, (struct mkroom *) 0); /* down */
|
mkstairs(mm.x, mm.y, 0, (struct mkroom *) 0); /* down */
|
||||||
} else { /* choose "vibrating square" location */
|
} else { /* choose "vibrating square" location */
|
||||||
|
int trycnt = 0;
|
||||||
#define x_maze_min 2
|
#define x_maze_min 2
|
||||||
#define y_maze_min 2
|
#define y_maze_min 2
|
||||||
/*
|
/*
|
||||||
@@ -1064,6 +1065,8 @@ const char *s;
|
|||||||
y = rn1(y_range, y_maze_min + INVPOS_Y_MARGIN + 1);
|
y = rn1(y_range, y_maze_min + INVPOS_Y_MARGIN + 1);
|
||||||
/* we don't want it to be too near the stairs, nor
|
/* we don't want it to be too near the stairs, nor
|
||||||
to be on a spot that's already in use (wall|trap) */
|
to be on a spot that's already in use (wall|trap) */
|
||||||
|
if (++trycnt > 1000)
|
||||||
|
break;
|
||||||
} while (x == xupstair || y == yupstair /*(direct line)*/
|
} while (x == xupstair || y == yupstair /*(direct line)*/
|
||||||
|| abs(x - xupstair) == abs(y - yupstair)
|
|| abs(x - xupstair) == abs(y - yupstair)
|
||||||
|| distmin(x, y, xupstair, yupstair) <= INVPOS_DISTANCE
|
|| distmin(x, y, xupstair, yupstair) <= INVPOS_DISTANCE
|
||||||
|
|||||||
12
src/role.c
12
src/role.c
@@ -2028,9 +2028,19 @@ role_init()
|
|||||||
|
|
||||||
/* Fix up the god names */
|
/* Fix up the god names */
|
||||||
if (flags.pantheon == -1) { /* new game */
|
if (flags.pantheon == -1) { /* new game */
|
||||||
|
int trycnt = 0;
|
||||||
flags.pantheon = flags.initrole; /* use own gods */
|
flags.pantheon = flags.initrole; /* use own gods */
|
||||||
while (!roles[flags.pantheon].lgod) /* unless they're missing */
|
/* unless they're missing */
|
||||||
|
while (!roles[flags.pantheon].lgod && ++trycnt < 100)
|
||||||
flags.pantheon = randrole(FALSE);
|
flags.pantheon = randrole(FALSE);
|
||||||
|
if (!roles[flags.pantheon].lgod) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < SIZE(roles) - 1; i++)
|
||||||
|
if (roles[i].lgod) {
|
||||||
|
flags.pantheon = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!g.urole.lgod) {
|
if (!g.urole.lgod) {
|
||||||
g.urole.lgod = roles[flags.pantheon].lgod;
|
g.urole.lgod = roles[flags.pantheon].lgod;
|
||||||
|
|||||||
@@ -979,6 +979,7 @@ register struct trobj *trop;
|
|||||||
if (otyp != UNDEF_TYP) {
|
if (otyp != UNDEF_TYP) {
|
||||||
obj = mksobj(otyp, TRUE, FALSE);
|
obj = mksobj(otyp, TRUE, FALSE);
|
||||||
} else { /* UNDEF_TYP */
|
} else { /* UNDEF_TYP */
|
||||||
|
int trycnt = 0;
|
||||||
/*
|
/*
|
||||||
* For random objects, do not create certain overly powerful
|
* For random objects, do not create certain overly powerful
|
||||||
* items: wand of wishing, ring of levitation, or the
|
* items: wand of wishing, ring of levitation, or the
|
||||||
@@ -1019,6 +1020,8 @@ register struct trobj *trop;
|
|||||||
dealloc_obj(obj);
|
dealloc_obj(obj);
|
||||||
obj = mkobj(trop->trclass, FALSE);
|
obj = mkobj(trop->trclass, FALSE);
|
||||||
otyp = obj->otyp;
|
otyp = obj->otyp;
|
||||||
|
if (++trycnt > 1000)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't start with +0 or negative rings */
|
/* Don't start with +0 or negative rings */
|
||||||
|
|||||||
Reference in New Issue
Block a user