worm.c cleanup
Mostly removing 'register', but also clear stale wgrowtime[] values at the time they become obsolete instead of waiting for initworm() to replace them when eventually re-used.
This commit is contained in:
96
src/worm.c
96
src/worm.c
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.6 worm.c $NHDT-Date: 1579616437 2020/01/21 14:20:37 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.40 $ */
|
/* NetHack 3.6 worm.c $NHDT-Date: 1579990313 2020/01/25 22:11:53 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.41 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/*-Copyright (c) Robert Patrick Rankin, 2009. */
|
/*-Copyright (c) Robert Patrick Rankin, 2009. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
@@ -66,8 +66,12 @@ static struct wseg *FDECL(create_worm_tail, (int));
|
|||||||
* segment, and remove hit points from the worm.
|
* segment, and remove hit points from the worm.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct wseg *wheads[MAX_NUM_WORMS] = DUMMY, *wtails[MAX_NUM_WORMS] = DUMMY;
|
/* restart: worm removal resets these so they don't need to be incorporated
|
||||||
long wgrowtime[MAX_NUM_WORMS] = DUMMY;
|
into 'struct instance_globals g' for potential reinitialization provided
|
||||||
|
that old game disposes of monsters properly before starting a new one */
|
||||||
|
static struct wseg *wheads[MAX_NUM_WORMS] = DUMMY,
|
||||||
|
*wtails[MAX_NUM_WORMS] = DUMMY;
|
||||||
|
static long wgrowtime[MAX_NUM_WORMS] = DUMMY;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get_wormno()
|
* get_wormno()
|
||||||
@@ -85,7 +89,7 @@ long wgrowtime[MAX_NUM_WORMS] = DUMMY;
|
|||||||
int
|
int
|
||||||
get_wormno()
|
get_wormno()
|
||||||
{
|
{
|
||||||
register int new_wormno = 1;
|
int new_wormno = 1;
|
||||||
|
|
||||||
while (new_wormno < MAX_NUM_WORMS) {
|
while (new_wormno < MAX_NUM_WORMS) {
|
||||||
if (!wheads[new_wormno])
|
if (!wheads[new_wormno])
|
||||||
@@ -111,15 +115,13 @@ initworm(worm, wseg_count)
|
|||||||
struct monst *worm;
|
struct monst *worm;
|
||||||
int wseg_count;
|
int wseg_count;
|
||||||
{
|
{
|
||||||
register struct wseg *seg, *new_tail = create_worm_tail(wseg_count);
|
struct wseg *seg, *new_tail = create_worm_tail(wseg_count);
|
||||||
register int wnum = worm->wormno;
|
int wnum = worm->wormno;
|
||||||
|
|
||||||
/* if (!wnum) return; bullet proofing */
|
|
||||||
|
|
||||||
if (new_tail) {
|
if (new_tail) {
|
||||||
wtails[wnum] = new_tail;
|
wtails[wnum] = new_tail;
|
||||||
for (seg = new_tail; seg->nseg; seg = seg->nseg)
|
for (seg = new_tail; seg->nseg; seg = seg->nseg)
|
||||||
;
|
continue;
|
||||||
wheads[wnum] = seg;
|
wheads[wnum] = seg;
|
||||||
} else {
|
} else {
|
||||||
wtails[wnum] = wheads[wnum] = seg = newseg();
|
wtails[wnum] = wheads[wnum] = seg = newseg();
|
||||||
@@ -139,10 +141,10 @@ int wseg_count;
|
|||||||
static
|
static
|
||||||
void
|
void
|
||||||
toss_wsegs(curr, display_update)
|
toss_wsegs(curr, display_update)
|
||||||
register struct wseg *curr;
|
struct wseg *curr;
|
||||||
register boolean display_update;
|
boolean display_update;
|
||||||
{
|
{
|
||||||
register struct wseg *seg;
|
struct wseg *seg;
|
||||||
|
|
||||||
while (curr) {
|
while (curr) {
|
||||||
seg = curr->nseg;
|
seg = curr->nseg;
|
||||||
@@ -196,10 +198,8 @@ void
|
|||||||
worm_move(worm)
|
worm_move(worm)
|
||||||
struct monst *worm;
|
struct monst *worm;
|
||||||
{
|
{
|
||||||
register struct wseg *seg, *new_seg; /* new segment */
|
struct wseg *seg, *new_seg; /* new segment */
|
||||||
register int wnum = worm->wormno; /* worm number */
|
int wnum = worm->wormno; /* worm number */
|
||||||
|
|
||||||
/* if (!wnum) return; bullet proofing */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Place a segment at the old worm head. The head has already moved.
|
* Place a segment at the old worm head. The head has already moved.
|
||||||
@@ -249,7 +249,7 @@ struct monst *worm;
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
worm_nomove(worm)
|
worm_nomove(worm)
|
||||||
register struct monst *worm;
|
struct monst *worm;
|
||||||
{
|
{
|
||||||
shrink_worm((int) worm->wormno); /* shrink */
|
shrink_worm((int) worm->wormno); /* shrink */
|
||||||
|
|
||||||
@@ -268,11 +268,9 @@ register struct monst *worm;
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
wormgone(worm)
|
wormgone(worm)
|
||||||
register struct monst *worm;
|
struct monst *worm;
|
||||||
{
|
{
|
||||||
register int wnum = worm->wormno;
|
int wnum = worm->wormno;
|
||||||
|
|
||||||
/* if (!wnum) return; bullet proofing */
|
|
||||||
|
|
||||||
worm->wormno = 0;
|
worm->wormno = 0;
|
||||||
|
|
||||||
@@ -282,6 +280,7 @@ register struct monst *worm;
|
|||||||
toss_wsegs(wtails[wnum], TRUE);
|
toss_wsegs(wtails[wnum], TRUE);
|
||||||
|
|
||||||
wheads[wnum] = wtails[wnum] = (struct wseg *) 0;
|
wheads[wnum] = wtails[wnum] = (struct wseg *) 0;
|
||||||
|
wgrowtime[wnum] = 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -293,12 +292,10 @@ register struct monst *worm;
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
wormhitu(worm)
|
wormhitu(worm)
|
||||||
register struct monst *worm;
|
struct monst *worm;
|
||||||
{
|
{
|
||||||
register int wnum = worm->wormno;
|
int wnum = worm->wormno;
|
||||||
register struct wseg *seg;
|
struct wseg *seg;
|
||||||
|
|
||||||
/* if (!wnum) return; bullet proofing */
|
|
||||||
|
|
||||||
/* This does not work right now because mattacku() thinks that the head
|
/* This does not work right now because mattacku() thinks that the head
|
||||||
* is out of range of the player. We might try to kludge, and bring
|
* is out of range of the player. We might try to kludge, and bring
|
||||||
@@ -325,8 +322,8 @@ struct monst *worm;
|
|||||||
xchar x, y;
|
xchar x, y;
|
||||||
boolean cuttier; /* hit is by wielded blade or axe or by thrown axe */
|
boolean cuttier; /* hit is by wielded blade or axe or by thrown axe */
|
||||||
{
|
{
|
||||||
register struct wseg *curr, *new_tail;
|
struct wseg *curr, *new_tail;
|
||||||
register struct monst *new_worm;
|
struct monst *new_worm;
|
||||||
int wnum = worm->wormno;
|
int wnum = worm->wormno;
|
||||||
int cut_chance, new_wnum;
|
int cut_chance, new_wnum;
|
||||||
|
|
||||||
@@ -441,8 +438,6 @@ struct monst *worm;
|
|||||||
{
|
{
|
||||||
struct wseg *curr = wtails[worm->wormno];
|
struct wseg *curr = wtails[worm->wormno];
|
||||||
|
|
||||||
/* if (!mtmp->wormno) return; bullet proofing */
|
|
||||||
|
|
||||||
while (curr != wheads[worm->wormno]) {
|
while (curr != wheads[worm->wormno]) {
|
||||||
newsym(curr->wx, curr->wy);
|
newsym(curr->wx, curr->wy);
|
||||||
curr = curr->nseg;
|
curr = curr->nseg;
|
||||||
@@ -461,8 +456,6 @@ boolean use_detection_glyph;
|
|||||||
{
|
{
|
||||||
int num;
|
int num;
|
||||||
struct wseg *curr = wtails[worm->wormno];
|
struct wseg *curr = wtails[worm->wormno];
|
||||||
|
|
||||||
/* if (!mtmp->wormno) return; bullet proofing */
|
|
||||||
int what_tail = what_mon(PM_LONG_WORM_TAIL, newsym_rn2);
|
int what_tail = what_mon(PM_LONG_WORM_TAIL, newsym_rn2);
|
||||||
|
|
||||||
while (curr != wheads[worm->wormno]) {
|
while (curr != wheads[worm->wormno]) {
|
||||||
@@ -496,19 +489,21 @@ NHFILE *nhfp;
|
|||||||
count++;
|
count++;
|
||||||
/* Save number of segments */
|
/* Save number of segments */
|
||||||
if (nhfp->structlevel)
|
if (nhfp->structlevel)
|
||||||
bwrite(nhfp->fd, (genericptr_t) &count, sizeof(int));
|
bwrite(nhfp->fd, (genericptr_t) &count, sizeof count);
|
||||||
/* Save segment locations of the monster. */
|
/* Save segment locations of the monster. */
|
||||||
if (count) {
|
if (count) {
|
||||||
for (curr = wtails[i]; curr; curr = curr->nseg) {
|
for (curr = wtails[i]; curr; curr = curr->nseg) {
|
||||||
if (nhfp->structlevel) {
|
if (nhfp->structlevel) {
|
||||||
bwrite(nhfp->fd, (genericptr_t) &(curr->wx), sizeof(xchar));
|
bwrite(nhfp->fd, (genericptr_t) &(curr->wx),
|
||||||
bwrite(nhfp->fd, (genericptr_t) &(curr->wy), sizeof(xchar));
|
sizeof curr->wx);
|
||||||
|
bwrite(nhfp->fd, (genericptr_t) &(curr->wy),
|
||||||
|
sizeof curr->wy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nhfp->structlevel) {
|
if (nhfp->structlevel) {
|
||||||
bwrite(nhfp->fd, (genericptr_t) wgrowtime, sizeof(wgrowtime));
|
bwrite(nhfp->fd, (genericptr_t) wgrowtime, sizeof wgrowtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,6 +520,7 @@ NHFILE *nhfp;
|
|||||||
curr = temp;
|
curr = temp;
|
||||||
}
|
}
|
||||||
wheads[i] = wtails[i] = (struct wseg *) 0;
|
wheads[i] = wtails[i] = (struct wseg *) 0;
|
||||||
|
wgrowtime[i] = 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -543,15 +539,15 @@ NHFILE *nhfp;
|
|||||||
|
|
||||||
for (i = 1; i < MAX_NUM_WORMS; i++) {
|
for (i = 1; i < MAX_NUM_WORMS; i++) {
|
||||||
if (nhfp->structlevel)
|
if (nhfp->structlevel)
|
||||||
mread(nhfp->fd, (genericptr_t) &count, sizeof(int));
|
mread(nhfp->fd, (genericptr_t) &count, sizeof count);
|
||||||
|
|
||||||
/* Get the segments. */
|
/* Get the segments. */
|
||||||
for (curr = (struct wseg *) 0, j = 0; j < count; j++) {
|
for (curr = (struct wseg *) 0, j = 0; j < count; j++) {
|
||||||
temp = newseg();
|
temp = newseg();
|
||||||
temp->nseg = (struct wseg *) 0;
|
temp->nseg = (struct wseg *) 0;
|
||||||
if (nhfp->structlevel) {
|
if (nhfp->structlevel) {
|
||||||
mread(nhfp->fd, (genericptr_t) &(temp->wx), sizeof(xchar));
|
mread(nhfp->fd, (genericptr_t) &(temp->wx), sizeof temp->wx);
|
||||||
mread(nhfp->fd, (genericptr_t) &(temp->wy), sizeof(xchar));
|
mread(nhfp->fd, (genericptr_t) &(temp->wy), sizeof temp->wy);
|
||||||
}
|
}
|
||||||
if (curr)
|
if (curr)
|
||||||
curr->nseg = temp;
|
curr->nseg = temp;
|
||||||
@@ -562,7 +558,7 @@ NHFILE *nhfp;
|
|||||||
wheads[i] = curr;
|
wheads[i] = curr;
|
||||||
}
|
}
|
||||||
if (nhfp->structlevel) {
|
if (nhfp->structlevel) {
|
||||||
mread(nhfp->fd, (genericptr_t) wgrowtime, sizeof(wgrowtime));
|
mread(nhfp->fd, (genericptr_t) wgrowtime, sizeof wgrowtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -579,8 +575,6 @@ struct monst *worm, *oldworm;
|
|||||||
{
|
{
|
||||||
struct wseg *curr = wtails[worm->wormno];
|
struct wseg *curr = wtails[worm->wormno];
|
||||||
|
|
||||||
/* if (!mtmp->wormno) return; bullet proofing */
|
|
||||||
|
|
||||||
while (curr != wheads[worm->wormno]) {
|
while (curr != wheads[worm->wormno]) {
|
||||||
xchar x = curr->wx;
|
xchar x = curr->wx;
|
||||||
xchar y = curr->wy;
|
xchar y = curr->wy;
|
||||||
@@ -630,11 +624,9 @@ struct monst *worm;
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
remove_worm(worm)
|
remove_worm(worm)
|
||||||
register struct monst *worm;
|
struct monst *worm;
|
||||||
{
|
{
|
||||||
register struct wseg *curr = wtails[worm->wormno];
|
struct wseg *curr = wtails[worm->wormno];
|
||||||
|
|
||||||
/* if (!mtmp->wormno) return; bullet proofing */
|
|
||||||
|
|
||||||
while (curr) {
|
while (curr) {
|
||||||
if (curr->wx) {
|
if (curr->wx) {
|
||||||
@@ -663,9 +655,7 @@ xchar x, y;
|
|||||||
int wnum = worm->wormno;
|
int wnum = worm->wormno;
|
||||||
struct wseg *curr = wtails[wnum];
|
struct wseg *curr = wtails[wnum];
|
||||||
struct wseg *new_tail;
|
struct wseg *new_tail;
|
||||||
register xchar ox = x, oy = y;
|
xchar ox = x, oy = y;
|
||||||
|
|
||||||
/* if (!wnum) return; bullet proofing */
|
|
||||||
|
|
||||||
if (wnum && (!wtails[wnum] || !wheads[wnum])) {
|
if (wnum && (!wtails[wnum] || !wheads[wnum])) {
|
||||||
impossible("place_worm_tail_randomly: wormno is set without a tail!");
|
impossible("place_worm_tail_randomly: wormno is set without a tail!");
|
||||||
@@ -750,8 +740,8 @@ int
|
|||||||
count_wsegs(mtmp)
|
count_wsegs(mtmp)
|
||||||
struct monst *mtmp;
|
struct monst *mtmp;
|
||||||
{
|
{
|
||||||
register int i = 0;
|
int i = 0;
|
||||||
register struct wseg *curr;
|
struct wseg *curr;
|
||||||
|
|
||||||
if (mtmp->wormno) {
|
if (mtmp->wormno) {
|
||||||
for (curr = wtails[mtmp->wormno]->nseg; curr; curr = curr->nseg)
|
for (curr = wtails[mtmp->wormno]->nseg; curr; curr = curr->nseg)
|
||||||
@@ -768,8 +758,8 @@ struct wseg *
|
|||||||
create_worm_tail(num_segs)
|
create_worm_tail(num_segs)
|
||||||
int num_segs;
|
int num_segs;
|
||||||
{
|
{
|
||||||
register int i = 0;
|
int i = 0;
|
||||||
register struct wseg *new_tail, *curr;
|
struct wseg *new_tail, *curr;
|
||||||
|
|
||||||
if (!num_segs)
|
if (!num_segs)
|
||||||
return (struct wseg *) 0;
|
return (struct wseg *) 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user