Morph static variables

This commit is contained in:
jl777
2019-03-19 01:35:15 -11:00
parent f58655b1cd
commit 0322f2d98c
10 changed files with 80 additions and 104 deletions

View File

@@ -24,7 +24,7 @@ command(struct rogue_state *rs)
register int ntimes = 1; /* Number of player moves */ register int ntimes = 1; /* Number of player moves */
char *fp; char *fp;
THING *mp; THING *mp;
static char countch, direction, newcount = FALSE; //static char countch, direction, newcount = FALSE;
if (on(player, ISHASTE)) if (on(player, ISHASTE))
ntimes++; ntimes++;
/* /*
@@ -74,7 +74,7 @@ command(struct rogue_state *rs)
if (running || to_death) if (running || to_death)
ch = runch; ch = runch;
else if (count) else if (count)
ch = countch; ch = rs->countch;
else else
{ {
ch = readchar(rs); ch = readchar(rs);
@@ -98,11 +98,11 @@ command(struct rogue_state *rs)
/* /*
* check for prefixes * check for prefixes
*/ */
newcount = FALSE; rs->newcount = FALSE;
if (isdigit(ch)) if (isdigit(ch))
{ {
count = 0; count = 0;
newcount = TRUE; rs->newcount = TRUE;
while (isdigit(ch)) while (isdigit(ch))
{ {
count = count * 10 + (ch - '0'); count = count * 10 + (ch - '0');
@@ -110,7 +110,7 @@ command(struct rogue_state *rs)
count = 255; count = 255;
ch = readchar(rs); ch = readchar(rs);
} }
countch = ch; rs->countch = ch;
/* /*
* turn off count for commands which don't make sense * turn off count for commands which don't make sense
* to repeat * to repeat
@@ -205,12 +205,12 @@ over:
door_stop = TRUE; door_stop = TRUE;
firstmove = TRUE; firstmove = TRUE;
} }
if (count && !newcount) if (count && !rs->newcount)
ch = direction; ch = rs->direction;
else else
{ {
ch += ('A' - CTRL('A')); ch += ('A' - CTRL('A'));
direction = ch; rs->direction = ch;
} }
goto over; goto over;
} }
@@ -372,7 +372,7 @@ over:
else else
{ {
ch = dir_ch; ch = dir_ch;
countch = dir_ch; rs->countch = dir_ch;
goto over; goto over;
} }
when ')': current(rs,cur_weapon, "wielding", NULL); when ')': current(rs,cur_weapon, "wielding", NULL);

View File

@@ -369,7 +369,7 @@ init_materials()
{ {
register int i, j; register int i, j;
register const char *str; register const char *str;
static bool metused[NMETAL]; bool metused[NMETAL];
memset(metused,0,sizeof(metused)); memset(metused,0,sizeof(metused));
for (i = 0; i < NWOOD; i++) for (i = 0; i < NWOOD; i++)
used[i] = FALSE; used[i] = FALSE;

View File

@@ -18,12 +18,12 @@
/* /*
* List of monsters in rough order of vorpalness * List of monsters in rough order of vorpalness
*/ */
static char lvl_mons[] = { static const char lvl_mons[] = {
'K', 'E', 'B', 'S', 'H', 'I', 'R', 'O', 'Z', 'L', 'C', 'Q', 'A', 'K', 'E', 'B', 'S', 'H', 'I', 'R', 'O', 'Z', 'L', 'C', 'Q', 'A',
'N', 'Y', 'F', 'T', 'W', 'P', 'X', 'U', 'M', 'V', 'G', 'J', 'D' 'N', 'Y', 'F', 'T', 'W', 'P', 'X', 'U', 'M', 'V', 'G', 'J', 'D'
}; };
static char wand_mons[] = { static const char wand_mons[] = {
'K', 'E', 'B', 'S', 'H', 0, 'R', 'O', 'Z', 0, 'C', 'Q', 'A', 'K', 'E', 'B', 'S', 'H', 0, 'R', 'O', 'Z', 0, 'C', 'Q', 'A',
0, 'Y', 0, 'T', 'W', 'P', 0, 'U', 'M', 'V', 'G', 'J', 0 0, 'Y', 0, 'T', 'W', 'P', 0, 'U', 'M', 'V', 'G', 'J', 0
}; };
@@ -119,27 +119,27 @@ void
wanderer(struct rogue_state *rs) wanderer(struct rogue_state *rs)
{ {
THING *tp; THING *tp;
static coord cp; coord cp;
memset(&cp,0,sizeof(cp));
tp = new_item(); tp = new_item();
do do
{ {
find_floor(rs,(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))
{ {
standout(); standout();
if (!on(player, ISHALU)) if (!on(player, ISHALU))
addch(tp->t_type); addch(tp->t_type);
else else
addch(rnd(26) + 'A'); addch(rnd(26) + 'A');
standend(); standend();
} }
runto(rs,&tp->t_pos); runto(rs,&tp->t_pos);
#ifdef MASTER #ifdef MASTER
if (wizard) if (wizard)
msg(rs,"started a wandering %s", monsters[tp->t_type-'A'].m_name); msg(rs,"started a wandering %s", monsters[tp->t_type-'A'].m_name);
#endif #endif
} }

View File

@@ -22,7 +22,7 @@ typedef struct
char *pa_high, *pa_straight; char *pa_high, *pa_straight;
} PACT; } PACT;
static PACT p_actions[] = static const PACT p_actions[] =
{ {
{ ISHUH, unconfuse, HUHDURATION, /* P_CONFUSE */ { ISHUH, unconfuse, HUHDURATION, /* P_CONFUSE */
"what a tripy feeling!", "what a tripy feeling!",

View File

@@ -366,6 +366,7 @@ struct rogue_state
uint32_t needflush,replaydone; uint32_t needflush,replaydone;
int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum; int32_t numkeys,ind,num,guiflag,counter,sleeptime,playersize,restoring,lastnum;
FILE *logfp; FILE *logfp;
char countch, direction, newcount;
struct rogue_player P; struct rogue_player P;
char buffered[10000]; char buffered[10000];
uint8_t playerdata[10000]; uint8_t playerdata[10000];

View File

@@ -30,14 +30,10 @@ typedef struct spot { /* position matrix for maze positions */
void void
do_rooms(struct rogue_state *rs) do_rooms(struct rogue_state *rs)
{ {
int i; int i,left_out; struct room *rp; THING *tp;
struct room *rp; //static coord top;
THING *tp; coord mp,bsze,top; /* maximum room size */
int left_out; memset(&top,0,sizeof(top));
static coord top;
coord bsze; /* maximum room size */
coord mp;
bsze.x = NUMCOLS / 3; bsze.x = NUMCOLS / 3;
bsze.y = NUMLINES / 3; bsze.y = NUMLINES / 3;
/* /*
@@ -206,23 +202,18 @@ horiz(struct room *rp, int starty)
*/ */
static int Maxy, Maxx, Starty, Startx; static int Maxy, Maxx, Starty, Startx;
static SPOT maze[NUMLINES/3+1][NUMCOLS/3+1]; static SPOT maze[NUMLINES/3+1][NUMCOLS/3+1];
void do_maze(struct rogue_state *rs,struct room *rp)
void
do_maze(struct rogue_state *rs,struct room *rp)
{ {
SPOT *sp; SPOT *sp; int starty, startx;
int starty, startx; coord pos;
static coord pos; memset(&pos,0,sizeof(pos));
for (sp = &maze[0][0]; sp <= &maze[NUMLINES / 3][NUMCOLS / 3]; sp++) for (sp = &maze[0][0]; sp <= &maze[NUMLINES / 3][NUMCOLS / 3]; sp++)
{ {
sp->used = FALSE; sp->used = FALSE;
sp->nexits = 0; sp->nexits = 0;
} }
Maxy = rp->r_max.y; Maxy = rp->r_max.y;
Maxx = rp->r_max.x; Maxx = rp->r_max.x;
Starty = rp->r_pos.y; Starty = rp->r_pos.y;
@@ -245,11 +236,11 @@ 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;
static coord pos; coord pos;
static coord del[4] = { static const coord del[4] = {
{2, 0}, {-2, 0}, {0, 2}, {0, -2} {2, 0}, {-2, 0}, {0, 2}, {0, -2}
}; };
memset(&pos,0,sizeof(pos));
for (;;) for (;;)
{ {
if ( rs->replaydone != 0 ) if ( rs->replaydone != 0 )

View File

@@ -22,26 +22,19 @@
void void
read_scroll(struct rogue_state *rs) read_scroll(struct rogue_state *rs)
{ {
THING *obj; THING *obj,*orig_obj; PLACE *pp; int i, y, x; char ch;
PLACE *pp; bool discardit = FALSE; struct room *cur_room; coord mp;
int y, x; memset(&mp,0,sizeof(mp));
char ch;
int i;
bool discardit = FALSE;
struct room *cur_room;
THING *orig_obj;
static coord mp;
obj = get_item(rs,"read", SCROLL); obj = get_item(rs,"read", SCROLL);
if (obj == NULL) if (obj == NULL)
return; return;
if (obj->o_type != SCROLL) if (obj->o_type != SCROLL)
{ {
if (!terse) if (!terse)
msg(rs,"there is nothing on it to read"); msg(rs,"there is nothing on it to read");
else else
msg(rs,"nothing to read"); msg(rs,"nothing to read");
return; return;
} }
/* /*
* Calculate the effect it has on the poor guy. * Calculate the effect it has on the poor guy.
@@ -149,7 +142,7 @@ read_scroll(struct rogue_state *rs)
case S_ID_ARMOR: case S_ID_ARMOR:
case S_ID_R_OR_S: case S_ID_R_OR_S:
{ {
static char id_type[S_ID_R_OR_S + 1] = static const char id_type[S_ID_R_OR_S + 1] =
{ 0, 0, 0, 0, 0, POTION, SCROLL, WEAPON, ARMOR, R_OR_S }; { 0, 0, 0, 0, 0, POTION, SCROLL, WEAPON, ARMOR, R_OR_S };
/* /*
* Identify, let him figure something out * Identify, let him figure something out

View File

@@ -245,35 +245,29 @@ do_zap(struct rogue_state *rs)
* Do drain hit points from player shtick * Do drain hit points from player shtick
*/ */
void void drain(struct rogue_state *rs)
drain(struct rogue_state *rs)
{ {
THING *mp; THING *mp,**dp; struct room *corp; int cnt; bool inpass; THING *drainee[40];
struct room *corp; memset(drainee,0,sizeof(drainee));
THING **dp;
int cnt;
bool inpass;
static THING *drainee[40];
/* /*
* First cnt how many things we need to spread the hit points among * First cnt how many things we need to spread the hit points among
*/ */
cnt = 0; cnt = 0;
if (chat(hero.y, hero.x) == DOOR) if (chat(hero.y, hero.x) == DOOR)
corp = &passages[flat(hero.y, hero.x) & F_PNUM]; corp = &passages[flat(hero.y, hero.x) & F_PNUM];
else else
corp = NULL; corp = NULL;
inpass = (bool)(proom->r_flags & ISGONE); inpass = (bool)(proom->r_flags & ISGONE);
dp = drainee; dp = drainee;
for (mp = mlist; mp != NULL; mp = next(mp)) for (mp = mlist; mp != NULL; mp = next(mp))
if (mp->t_room == proom || mp->t_room == corp || if (mp->t_room == proom || mp->t_room == corp ||
(inpass && chat(mp->t_pos.y, mp->t_pos.x) == DOOR && (inpass && chat(mp->t_pos.y, mp->t_pos.x) == DOOR &&
&passages[flat(mp->t_pos.y, mp->t_pos.x) & F_PNUM] == proom)) &passages[flat(mp->t_pos.y, mp->t_pos.x) & F_PNUM] == proom))
*dp++ = mp; *dp++ = mp;
if ((cnt = (int)(dp - drainee)) == 0) if ((cnt = (int)(dp - drainee)) == 0)
{ {
msg(rs,"you have a tingling feeling"); msg(rs,"you have a tingling feeling");
return; return;
} }
*dp = NULL; *dp = NULL;
pstats.s_hpt /= 2; pstats.s_hpt /= 2;
@@ -283,11 +277,11 @@ drain(struct rogue_state *rs)
*/ */
for (dp = drainee; *dp; dp++) for (dp = drainee; *dp; dp++)
{ {
mp = *dp; mp = *dp;
if ((mp->t_stats.s_hpt -= cnt) <= 0) if ((mp->t_stats.s_hpt -= cnt) <= 0)
killed(rs,mp, see_monst(mp)); killed(rs,mp, see_monst(mp));
else else
runto(rs,&mp->t_pos); runto(rs,&mp->t_pos);
} }
} }
@@ -423,10 +417,10 @@ charge_str(THING *obj)
static char buf[20]; static char buf[20];
if (!(obj->o_flags & ISKNOW)) if (!(obj->o_flags & ISKNOW))
buf[0] = '\0'; buf[0] = '\0';
else if (terse) else if (terse)
sprintf(buf, " [%d]", obj->o_charges); sprintf(buf, " [%d]", obj->o_charges);
else else
sprintf(buf, " [%d charges]", obj->o_charges); sprintf(buf, " [%d charges]", obj->o_charges);
return buf; return buf;
} }

View File

@@ -334,12 +334,9 @@ pick_one(struct rogue_state *rs,struct obj_info *info, int nitems)
* list what the player has discovered in this game of a certain type * list what the player has discovered in this game of a certain type
*/ */
static int line_cnt = 0; static int line_cnt = 0;
static bool newpage = FALSE; static bool newpage = FALSE;
static char *lastfmt, *lastarg; static char *lastfmt, *lastarg;
void void
discovered(struct rogue_state *rs) discovered(struct rogue_state *rs)
{ {
@@ -480,16 +477,16 @@ add_line(struct rogue_state *rs,char *fmt, char *arg)
if (line_cnt == 0) if (line_cnt == 0)
{ {
wclear(hw); wclear(hw);
if (inv_type == INV_SLOW) if (inv_type == INV_SLOW)
mpos = 0; mpos = 0;
} }
if (inv_type == INV_SLOW) if (inv_type == INV_SLOW)
{ {
if (*fmt != '\0') if (*fmt != '\0')
if (msg(rs,fmt, arg) == ESCAPE) if (msg(rs,fmt, arg) == ESCAPE)
return ESCAPE; return ESCAPE;
line_cnt++; line_cnt++;
} }
else else
{ {

View File

@@ -19,7 +19,7 @@
int group = 2; int group = 2;
static struct init_weaps { static const struct init_weaps {
char *iw_dam; /* Damage when wielded */ char *iw_dam; /* Damage when wielded */
char *iw_hrl; /* Damage when thrown */ char *iw_hrl; /* Damage when thrown */
char iw_launch; /* Launching weapon */ char iw_launch; /* Launching weapon */
@@ -125,8 +125,8 @@ void
fall(struct rogue_state *rs,THING *obj, bool pr) fall(struct rogue_state *rs,THING *obj, bool pr)
{ {
PLACE *pp; PLACE *pp;
static coord fpos; coord fpos;
memset(&fpos,0,sizeof(fpos));
if (fallpos(&obj->o_pos, &fpos)) if (fallpos(&obj->o_pos, &fpos))
{ {
pp = INDEX(fpos.y, fpos.x); pp = INDEX(fpos.y, fpos.x);
@@ -197,8 +197,8 @@ init_weapon(THING *weap, int which)
int int
hit_monster(struct rogue_state *rs,int y, int x, THING *obj) hit_monster(struct rogue_state *rs,int y, int x, THING *obj)
{ {
static coord mp; coord mp;
memset(&mp,0,sizeof(mp));
mp.y = y; mp.y = y;
mp.x = x; mp.x = x;
return fight(rs,&mp, obj, TRUE); return fight(rs,&mp, obj, TRUE);