Break out of infinite loops!

This commit is contained in:
jl777
2019-03-01 02:40:17 -11:00
parent 0b23f62737
commit 4744a6f6c3
10 changed files with 70 additions and 64 deletions

View File

@@ -124,7 +124,7 @@ wanderer(struct rogue_state *rs)
tp = new_item(); tp = new_item();
do do
{ {
find_floor((struct room *) NULL, &cp, FALSE, TRUE); find_floor(rs,(struct room *) NULL, &cp, FALSE, TRUE);
} while (roomin(rs,&cp) == proom); } while (roomin(rs,&cp) == proom);
new_monster(rs,tp, randmonster(TRUE), &cp); new_monster(rs,tp, randmonster(TRUE), &cp);
if (on(player, SEEMONST)) if (on(player, SEEMONST))

View File

@@ -74,7 +74,7 @@ new_level(struct rogue_state *rs)
*/ */
do do
{ {
find_floor((struct room *) NULL, &stairs, FALSE, FALSE); find_floor(rs,(struct room *) NULL, &stairs, FALSE, FALSE);
} while (chat(stairs.y, stairs.x) != FLOOR); } while (chat(stairs.y, stairs.x) != FLOOR);
sp = &flat(stairs.y, stairs.x); sp = &flat(stairs.y, stairs.x);
*sp &= ~F_REAL; *sp &= ~F_REAL;
@@ -84,14 +84,14 @@ new_level(struct rogue_state *rs)
/* /*
* Place the staircase down. * Place the staircase down.
*/ */
find_floor((struct room *) NULL, &stairs, FALSE, FALSE); find_floor(rs,(struct room *) NULL, &stairs, FALSE, FALSE);
chat(stairs.y, stairs.x) = STAIRS; chat(stairs.y, stairs.x) = STAIRS;
seenstairs = FALSE; seenstairs = FALSE;
for (tp = mlist; tp != NULL; tp = next(tp)) for (tp = mlist; tp != NULL; tp = next(tp))
tp->t_room = roomin(rs,&tp->t_pos); tp->t_room = roomin(rs,&tp->t_pos);
find_floor((struct room *) NULL, &hero, FALSE, TRUE); find_floor(rs,(struct room *) NULL, &hero, FALSE, TRUE);
enter_room(rs,&hero); enter_room(rs,&hero);
mvaddch(hero.y, hero.x, PLAYER); mvaddch(hero.y, hero.x, PLAYER);
if (on(player, SEEMONST)) if (on(player, SEEMONST))
@@ -153,7 +153,7 @@ put_things(struct rogue_state *rs)
/* /*
* Put it somewhere * Put it somewhere
*/ */
find_floor((struct room *) NULL, &obj->o_pos, FALSE, FALSE); find_floor(rs,(struct room *) NULL, &obj->o_pos, FALSE, FALSE);
chat(obj->o_pos.y, obj->o_pos.x) = (char) obj->o_type; chat(obj->o_pos.y, obj->o_pos.x) = (char) obj->o_type;
} }
/* /*
@@ -173,7 +173,7 @@ put_things(struct rogue_state *rs)
/* /*
* Put it somewhere * Put it somewhere
*/ */
find_floor((struct room *) NULL, &obj->o_pos, FALSE, FALSE); find_floor(rs,(struct room *) NULL, &obj->o_pos, FALSE, FALSE);
chat(obj->o_pos.y, obj->o_pos.x) = AMULET; chat(obj->o_pos.y, obj->o_pos.x) = AMULET;
} }
} }
@@ -201,7 +201,7 @@ treas_room(struct rogue_state *rs)
num_monst = nm = rnd(spots) + MINTREAS; num_monst = nm = rnd(spots) + MINTREAS;
while (nm--) while (nm--)
{ {
find_floor(rp, &mp, 2 * MAXTRIES, FALSE); find_floor(rs,rp, &mp, 2 * MAXTRIES, FALSE);
//fprintf(stderr,"treas_room\n"); //fprintf(stderr,"treas_room\n");
tp = new_thing(rs); tp = new_thing(rs);
tp->o_pos = mp; tp->o_pos = mp;
@@ -222,7 +222,7 @@ treas_room(struct rogue_state *rs)
while (nm--) while (nm--)
{ {
spots = 0; spots = 0;
if (find_floor(rp, &mp, MAXTRIES, TRUE)) if (find_floor(rs,rp, &mp, MAXTRIES, TRUE))
{ {
tp = new_item(); tp = new_item();
new_monster(rs,tp, randmonster(FALSE), &mp); new_monster(rs,tp, randmonster(FALSE), &mp);

View File

@@ -422,6 +422,8 @@ get_item(struct rogue_state *rs,char *purpose, int type)
{ {
for (;;) for (;;)
{ {
if ( rs->replaydone != 0 )
return(NULL);
if (!terse) if (!terse)
addmsg(rs,"which object do you want to "); addmsg(rs,"which object do you want to ");
addmsg(rs,purpose); addmsg(rs,purpose);

View File

@@ -130,24 +130,26 @@ int
gethand(struct rogue_state *rs) gethand(struct rogue_state *rs)
{ {
int c; int c;
for (;;) for (;;)
{ {
if (terse) if ( rs->replaydone != 0 )
msg(rs,"left or right ring? "); return(-1);
else if (terse)
msg(rs,"left hand or right hand? "); msg(rs,"left or right ring? ");
if ((c = readchar(rs)) == ESCAPE) else
return -1; msg(rs,"left hand or right hand? ");
mpos = 0; if ((c = readchar(rs)) == ESCAPE)
if (c == 'l' || c == 'L') return -1;
return LEFT; mpos = 0;
else if (c == 'r' || c == 'R') if (c == 'l' || c == 'L')
return RIGHT; return LEFT;
if (terse) else if (c == 'r' || c == 'R')
msg(rs,"L or R"); return RIGHT;
else if (terse)
msg(rs,"please type L or R"); msg(rs,"L or R");
else
msg(rs,"please type L or R");
} }
} }

View File

@@ -612,7 +612,7 @@ void current(struct rogue_state *rs,THING *cur, char *how, char *where);
void d_level(struct rogue_state *rs); void d_level(struct rogue_state *rs);
void death(struct rogue_state *rs,char monst); void death(struct rogue_state *rs,char monst);
char death_monst(void); char death_monst(void);
void dig(int y, int x); void dig(struct rogue_state *rs,int y, int x);
void discard(THING *item); void discard(THING *item);
void discovered(struct rogue_state *rs); void discovered(struct rogue_state *rs);
int dist(int y1, int x1, int y2, int x2); int dist(int y1, int x1, int y2, int x2);
@@ -620,7 +620,7 @@ int dist_cp(coord *c1, coord *c2);
int do_chase(struct rogue_state *rs,THING *th); int do_chase(struct rogue_state *rs,THING *th);
void do_daemons(struct rogue_state *rs,int flag); void do_daemons(struct rogue_state *rs,int flag);
void do_fuses(struct rogue_state *rs,int flag); void do_fuses(struct rogue_state *rs,int flag);
void do_maze(struct room *rp); void do_maze(struct rogue_state *rs,struct room *rp);
void do_motion(struct rogue_state *rs,THING *obj, int ydelta, int xdelta); void do_motion(struct rogue_state *rs,THING *obj, int ydelta, int xdelta);
void do_move(struct rogue_state *rs,int dy, int dx); void do_move(struct rogue_state *rs,int dy, int dx);
void do_passages(struct rogue_state *rs); void do_passages(struct rogue_state *rs);
@@ -632,7 +632,7 @@ void doadd(struct rogue_state *rs,char *fmt, va_list args);
void door(struct room *rm, coord *cp); void door(struct room *rm, coord *cp);
void door_open(struct rogue_state *rs,struct room *rp); void door_open(struct rogue_state *rs,struct room *rp);
void drain(struct rogue_state *rs); void drain(struct rogue_state *rs);
void draw_room(struct room *rp); void draw_room(struct rogue_state *rs,struct room *rp);
void drop(struct rogue_state *rs); void drop(struct rogue_state *rs);
void eat(struct rogue_state *rs); void eat(struct rogue_state *rs);
size_t encread(char *start, size_t size, FILE *inf); size_t encread(char *start, size_t size, FILE *inf);
@@ -761,7 +761,7 @@ bool chase(THING *tp, coord *ee);
bool diag_ok(coord *sp, coord *ep); bool diag_ok(coord *sp, coord *ep);
bool dropcheck(struct rogue_state *rs,THING *obj); bool dropcheck(struct rogue_state *rs,THING *obj);
bool fallpos(coord *pos, coord *newpos); bool fallpos(coord *pos, coord *newpos);
bool find_floor(struct room *rp, coord *cp, int limit, bool monst); bool find_floor(struct rogue_state *rs,struct room *rp, coord *cp, int limit, bool monst);
bool is_magic(THING *obj); bool is_magic(THING *obj);
bool is_symlink(char *sp); bool is_symlink(char *sp);
bool levit_check(struct rogue_state *rs); bool levit_check(struct rogue_state *rs);

View File

@@ -112,7 +112,7 @@ do_rooms(struct rogue_state *rs)
rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x); rp->r_pos.x = top.x + rnd(bsze.x - rp->r_max.x);
rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y); rp->r_pos.y = top.y + rnd(bsze.y - rp->r_max.y);
} until (rp->r_pos.y != 0); } until (rp->r_pos.y != 0);
draw_room(rp); draw_room(rs,rp);
/* /*
* Put the gold in * Put the gold in
*/ */
@@ -122,7 +122,7 @@ do_rooms(struct rogue_state *rs)
gold = new_item(); gold = new_item();
gold->o_goldval = rp->r_goldval = GOLDCALC; gold->o_goldval = rp->r_goldval = GOLDCALC;
find_floor(rp, &rp->r_gold, FALSE, FALSE); find_floor(rs,rp, &rp->r_gold, FALSE, FALSE);
gold->o_pos = rp->r_gold; gold->o_pos = rp->r_gold;
chat(rp->r_gold.y, rp->r_gold.x) = GOLD; chat(rp->r_gold.y, rp->r_gold.x) = GOLD;
gold->o_flags = ISMANY; gold->o_flags = ISMANY;
@@ -136,7 +136,7 @@ do_rooms(struct rogue_state *rs)
if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25)) if (rnd(100) < (rp->r_goldval > 0 ? 80 : 25))
{ {
tp = new_item(); tp = new_item();
find_floor(rp, &mp, FALSE, TRUE); find_floor(rs,rp, &mp, FALSE, TRUE);
new_monster(rs,tp, randmonster(FALSE), &mp); new_monster(rs,tp, randmonster(FALSE), &mp);
give_pack(rs,tp); give_pack(rs,tp);
} }
@@ -150,12 +150,12 @@ do_rooms(struct rogue_state *rs)
*/ */
void void
draw_room(struct room *rp) draw_room(struct rogue_state *rs,struct room *rp)
{ {
int y, x; int y, x;
if (rp->r_flags & ISMAZE) if (rp->r_flags & ISMAZE)
do_maze(rp); do_maze(rs,rp);
else else
{ {
vert(rp, rp->r_pos.x); /* Draw left side */ vert(rp, rp->r_pos.x); /* Draw left side */
@@ -211,7 +211,7 @@ static SPOT maze[NUMLINES/3+1][NUMCOLS/3+1];
void void
do_maze(struct room *rp) do_maze(struct rogue_state *rs,struct room *rp)
{ {
SPOT *sp; SPOT *sp;
int starty, startx; int starty, startx;
@@ -232,7 +232,7 @@ do_maze(struct room *rp)
pos.y = starty + Starty; pos.y = starty + Starty;
pos.x = startx + Startx; pos.x = startx + Startx;
putpass(&pos); putpass(&pos);
dig(starty, startx); dig(rs,starty, startx);
} }
/* /*
@@ -241,7 +241,7 @@ do_maze(struct room *rp)
*/ */
void void
dig(int y, int x) dig(struct rogue_state *rs,int y, int x)
{ {
coord *cp; coord *cp;
int cnt, newy, newx, nexty = 0, nextx = 0; int cnt, newy, newx, nexty = 0, nextx = 0;
@@ -252,6 +252,8 @@ dig(int y, int x)
for (;;) for (;;)
{ {
if ( rs->replaydone != 0 )
return;
cnt = 0; cnt = 0;
for (cp = del; cp <= &del[3]; cp++) for (cp = del; cp <= &del[3]; cp++)
{ {
@@ -291,7 +293,7 @@ dig(int y, int x)
pos.y = nexty + Starty; pos.y = nexty + Starty;
pos.x = nextx + Startx; pos.x = nextx + Startx;
putpass(&pos); putpass(&pos);
dig(nexty, nextx); dig(rs,nexty, nextx);
} }
} }
@@ -332,7 +334,7 @@ rnd_pos(struct room *rp, coord *cp)
* pick a new room each time around the loop. * pick a new room each time around the loop.
*/ */
bool bool
find_floor(struct room *rp, coord *cp, int limit, bool monst) find_floor(struct rogue_state *rs,struct room *rp, coord *cp, int limit, bool monst)
{ {
PLACE *pp; PLACE *pp;
int cnt; int cnt;
@@ -346,6 +348,8 @@ find_floor(struct room *rp, coord *cp, int limit, bool monst)
cnt = limit; cnt = limit;
for (;;) for (;;)
{ {
if ( rs->replaydone != 0 )
return(FALSE);
if (limit && cnt-- == 0) if (limit && cnt-- == 0)
return FALSE; return FALSE;
if (pickroom) if (pickroom)

View File

@@ -158,7 +158,7 @@ do_zap(struct rogue_state *rs)
{ {
do do
{ {
find_floor(NULL, &new_pos, FALSE, TRUE); find_floor(rs,NULL, &new_pos, FALSE, TRUE);
} while (ce(new_pos, hero)); } while (ce(new_pos, hero));
} }
else else

View File

@@ -81,6 +81,8 @@ do_motion(struct rogue_state *rs,THING *obj, int ydelta, int xdelta)
obj->o_pos = hero; obj->o_pos = hero;
for (;;) for (;;)
{ {
if ( rs->replaydone != 0 )
return;
/* /*
* Erase the old one * Erase the old one
*/ */

View File

@@ -35,19 +35,21 @@ whatis(struct rogue_state *rs,bool insist, int type)
for (;;) for (;;)
{ {
obj = get_item(rs,"identify", type); if ( rs->replaydone != 0 )
if (insist) return;
{ obj = get_item(rs,"identify", type);
if (n_objs == 0) if (insist)
return; {
else if (obj == NULL) if (n_objs == 0)
msg(rs,"you must identify something"); return;
else if (type && obj->o_type != type && else if (obj == NULL)
!(type == R_OR_S && (obj->o_type == RING || obj->o_type == STICK)) ) msg(rs,"you must identify something");
msg(rs,"you must identify a %s", type_name(type)); else if (type && obj->o_type != type &&
else !(type == R_OR_S && (obj->o_type == RING || obj->o_type == STICK)) )
break; msg(rs,"you must identify a %s", type_name(type));
} else
break;
}
else else
break; break;
} }
@@ -202,7 +204,7 @@ teleport(struct rogue_state *rs)
static coord c; static coord c;
mvaddch(hero.y, hero.x, floor_at()); mvaddch(hero.y, hero.x, floor_at());
find_floor((struct room *) NULL, &c, FALSE, TRUE); find_floor(rs,(struct room *) NULL, &c, FALSE, TRUE);
if (roomin(rs,&c) != proom) if (roomin(rs,&c) != proom)
{ {
leave_room(rs,&hero); leave_room(rs,&hero);

View File

@@ -588,19 +588,18 @@ int32_t rogue_playersalive(int32_t &openslots,int32_t &numplayers,uint256 gametx
numplayers = openslots = 0; numplayers = openslots = 0;
if ( komodo_nextheight() <= gameht+ROGUE_MAXKEYSTROKESGAP ) if ( komodo_nextheight() <= gameht+ROGUE_MAXKEYSTROKESGAP )
registration_open = 1; registration_open = 1;
fprintf(stderr,"players alive\n");
for (i=0; i<maxplayers; i++) for (i=0; i<maxplayers; i++)
{ {
fprintf(stderr,"players alive %d of %d\n",i,maxplayers); //fprintf(stderr,"players alive %d of %d\n",i,maxplayers);
if ( CCgettxout(gametxid,1+i,1,0) < 0 ) if ( CCgettxout(gametxid,1+i,1,0) < 0 )
{ {
numplayers++; numplayers++;
fprintf(stderr,"players alive %d spent baton\n",i); //fprintf(stderr,"players alive %d spent baton\n",i);
if ( CCgettxout(gametxid,1+maxplayers+i,1,0) == txfee ) if ( CCgettxout(gametxid,1+maxplayers+i,1,0) == txfee )
{ {
txid = gametxid; txid = gametxid;
vout = 1+i; vout = 1+i;
fprintf(stderr,"rogue_playersalive scan forward active.%s spenttxid.%s\n",gametxid.GetHex().c_str(),txid.GetHex().c_str()); //fprintf(stderr,"rogue_playersalive scan forward active.%s spenttxid.%s\n",gametxid.GetHex().c_str(),txid.GetHex().c_str());
n = 0; n = 0;
while ( CCgettxout(txid,vout,1,0) < 0 ) while ( CCgettxout(txid,vout,1,0) < 0 )
{ {
@@ -615,34 +614,29 @@ int32_t rogue_playersalive(int32_t &openslots,int32_t &numplayers,uint256 gametx
} }
txid = spenttxid; txid = spenttxid;
vout = 0; vout = 0;
fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini); //fprintf(stderr,"n.%d next txid.%s/v%d\n",n,txid.GetHex().c_str(),spentvini);
if ( spentvini != 0 ) if ( spentvini != 0 )
break; break;
if ( n++ > ROGUE_MAXITERATIONS ) if ( n++ > ROGUE_MAXITERATIONS )
break; break;
} }
fprintf(stderr,"out of while\n");
if ( txid != zeroid ) if ( txid != zeroid )
{ {
fprintf(stderr,"get height of %s\n",txid.GetHex().c_str());
if ( myGetTransaction(txid,tx,hashBlock) != 0 ) if ( myGetTransaction(txid,tx,hashBlock) != 0 )
{ {
fprintf(stderr,"got tx %s\n",txid.GetHex().c_str());
if ( (pindex= komodo_blockindex(hashBlock)) != 0 ) if ( (pindex= komodo_blockindex(hashBlock)) != 0 )
{ {
fprintf(stderr,"got pindex %s\n",hashBlock.GetHex().c_str());
if ( pindex->GetHeight() <= gameht+ROGUE_MAXKEYSTROKESGAP ) if ( pindex->GetHeight() <= gameht+ROGUE_MAXKEYSTROKESGAP )
alive++; alive++;
} }
} }
fprintf(stderr,"got height of %s\n",txid.GetHex().c_str());
} }
} }
} }
else if ( registration_open != 0 ) else if ( registration_open != 0 )
openslots++; openslots++;
} }
fprintf(stderr,"numalive.%d openslots.%d\n",alive,openslots); //fprintf(stderr,"numalive.%d openslots.%d\n",alive,openslots);
return(alive); return(alive);
} }