Fix infinite loop in makemon if no goodpos available
If the level was full of monsters, goodpos never returns TRUE, and tryct would not get incremented.
This commit is contained in:
+7
-3
@@ -967,15 +967,19 @@ register int mmflags;
|
|||||||
|
|
||||||
/* if caller wants random location, do it here */
|
/* if caller wants random location, do it here */
|
||||||
if (x == 0 && y == 0) {
|
if (x == 0 && y == 0) {
|
||||||
int tryct = 0; /* careful with bigrooms */
|
int tryct = 200; /* careful with bigrooms */
|
||||||
|
boolean good;
|
||||||
struct monst fakemon;
|
struct monst fakemon;
|
||||||
|
|
||||||
fakemon.data = ptr; /* set up for goodpos */
|
fakemon.data = ptr; /* set up for goodpos */
|
||||||
do {
|
do {
|
||||||
x = rn1(COLNO - 3, 2);
|
x = rn1(COLNO - 3, 2);
|
||||||
y = rn2(ROWNO);
|
y = rn2(ROWNO);
|
||||||
} while (!goodpos(x, y, ptr ? &fakemon : (struct monst *) 0, gpflags)
|
if (!in_mklev && cansee(x,y)) tryct--;
|
||||||
|| (!in_mklev && tryct++ < 50 && cansee(x, y)));
|
good = goodpos(x, y, ptr ? &fakemon : (struct monst *) 0, gpflags);
|
||||||
|
} while (tryct && !good);
|
||||||
|
if (!good)
|
||||||
|
return ((struct monst *) 0);
|
||||||
} else if (byyou && !in_mklev) {
|
} else if (byyou && !in_mklev) {
|
||||||
coord bypos;
|
coord bypos;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user