X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/e30950ccc7c7c31c69f1d31c16b0212bbf168ceb..HEAD:/larn/monster.c diff --git a/larn/monster.c b/larn/monster.c index fd5c942d..1b325170 100644 --- a/larn/monster.c +++ b/larn/monster.c @@ -1,4 +1,4 @@ -/* $NetBSD: monster.c,v 1.13 2008/01/28 05:38:54 dholland Exp $ */ +/* $NetBSD: monster.c,v 1.20 2021/05/02 12:50:45 rillig Exp $ */ /* * monster.c Larn is copyrighted 1986 by Noah Morgan. @@ -100,11 +100,12 @@ */ #include #ifndef lint -__RCSID("$NetBSD: monster.c,v 1.13 2008/01/28 05:38:54 dholland Exp $"); +__RCSID("$NetBSD: monster.c,v 1.20 2021/05/02 12:50:45 rillig Exp $"); #endif /* not lint */ #include #include +#include #include "header.h" #include "extern.h" @@ -114,7 +115,24 @@ struct isave { /* used for altar reality */ short arg; /* the type of item or hitpoints of monster */ }; +static int cgood(int, int, int, int); +static void speldamage(int); +static void loseint(void); +static int isconfuse(void); +static int nospell(int, int); +static int fullhit(int); +static void direct(int, int, const char *, int); +static void ifblind(int, int); +static void tdirect(int); +static void omnidirect(int, int, const char *); static int dirsub(int *, int *); +static void dirpoly(int); +static int hitm(int, int, int); +static void dropsomething(int); +static int spattack(int, int, int); +static void sphboom(int, int); +static void genmonst(void); + /* * createmonster(monstno) Function to create a monster next to the player * int monstno; @@ -123,8 +141,7 @@ static int dirsub(int *, int *); * Returns no value. */ void -createmonster(mon) - int mon; +createmonster(int mon) { int x, y, k, i; if (mon < 1 || mon > MAXMONST + 8) { /* check for monster number @@ -168,7 +185,7 @@ createmonster(mon) * if monst==TRUE check for no monster at this location * This routine will return FALSE if at a wall or the dungeon exit on level 1 */ -int +static int cgood(int x, int y, int theitem, int monst) { #define itm __lose @@ -194,8 +211,7 @@ cgood(int x, int y, int theitem, int monst) * Returns no value, thus we don't know about createitem() failures. */ void -createitem(it, arg) - int it, arg; +createitem(int it, int arg) { int x, y, k, i; if (it >= MAXOBJ) @@ -222,7 +238,7 @@ createitem(it, arg) */ static char eys[] = "\nEnter your spell: "; void -cast() +cast(void) { int i, j, a, b, d; cursors(); @@ -232,16 +248,16 @@ cast() } lprcat(eys); --c[SPELLS]; - while ((a = lgetchar()) == 'D') { + while ((a = ttgetch()) == 'D') { seemagic(-1); cursors(); lprcat(eys); } if (a == '\33') goto over; /* to escape casting a spell */ - if ((b = lgetchar()) == '\33') + if ((b = ttgetch()) == '\33') goto over; /* to escape casting a spell */ - if ((d = lgetchar()) == '\33') { + if ((d = ttgetch()) == '\33') { over: lprcat(aborted); c[SPELLS]++; return; @@ -269,7 +285,7 @@ over: lprcat(aborted); * Enter with the spell number, returns no value. * Please insure that there are 2 spaces before all messages here */ -void +static void speldamage(int x) { int i, j, clev; @@ -634,8 +650,8 @@ speldamage(int x) * * No arguments and no return value */ -void -loseint() +static void +loseint(void) { if (--c[INTELLIGENCE] < 3) c[INTELLIGENCE] = 3; @@ -647,8 +663,8 @@ loseint() * This routine prints out a message saying "You can't aim your magic!" * returns 0 if not confused, non-zero (time remaining confused) if confused */ -int -isconfuse() +static int +isconfuse(void) { if (c[CONFUSE]) { lprcat(" You can't aim your magic!"); @@ -665,9 +681,8 @@ isconfuse() * otherwise returns 0 * Enter with the spell number in x, and the monster number in monst. */ -int -nospell(x, monst) - int x, monst; +static int +nospell(int x, int monst) { int tmp; if (x >= SPNUM || monst >= MAXMONST + 8 || monst < 0 || x < 0) @@ -687,9 +702,8 @@ nospell(x, monst) * Function to return hp damage to monster due to a number of full hits * Enter with the number of full hits being done */ -int -fullhit(xx) - int xx; +static int +fullhit(int xx) { int i; if (xx < 0 || xx > 20) @@ -710,10 +724,8 @@ fullhit(xx) * lprintf format string in str, and lprintf's argument in arg. * Returns no value. */ -void -direct(spnum, dam, str, arg) - int spnum, dam, arg; - const char *str; +static void +direct(int spnum, int dam, const char *str, int arg) { int x, y; int m; @@ -773,13 +785,16 @@ direct(spnum, dam, str, arg) * Returns no value. */ void -godirect(spnum, dam, str, delay, cshow) - int spnum, dam, delay; - const char *str, cshow; +godirect(int spnum, int dam, const char *str, int delay, int cshow_i) { u_char *p; int x, y, m; int dx, dy; + char cshow; + + /* truncate to char width in case it matters */ + cshow = (char)cshow_i; + if (spnum < 0 || spnum >= SPNUM || str == 0 || delay < 0) return; /* bad args */ if (isconfuse()) @@ -896,7 +911,7 @@ godirect(spnum, dam, str, delay, cshow) * Enter with the coordinates (x,y) of the monster * Returns no value. */ -void +static void ifblind(int x, int y) { const char *p; @@ -920,9 +935,8 @@ ifblind(int x, int y) * Enter with the spell number that wants to teleport away * Returns no value. */ -void -tdirect(spnum) - int spnum; +static void +tdirect(int spnum) { int x, y; int m; @@ -955,7 +969,7 @@ tdirect(spnum) * and the lprintf string to identify the spell in str. * Returns no value. */ -void +static void omnidirect(int spnum, int dam, const char *str) { int x, y, m; @@ -989,29 +1003,36 @@ omnidirect(int spnum, int dam, const char *str) * Returns index into diroffx[] (0-8). */ static int -dirsub(x, y) - int *x, *y; +dirsub(int *x, int *y) { int i; lprcat("\nIn What Direction? "); for (i = 0;;) - switch (lgetchar()) { + switch (ttgetch()) { case 'b': i++; + /* FALLTHROUGH */ case 'n': i++; + /* FALLTHROUGH */ case 'y': i++; + /* FALLTHROUGH */ case 'u': i++; + /* FALLTHROUGH */ case 'h': i++; + /* FALLTHROUGH */ case 'k': i++; + /* FALLTHROUGH */ case 'l': i++; + /* FALLTHROUGH */ case 'j': i++; + /* FALLTHROUGH */ goto out; }; out: @@ -1032,8 +1053,7 @@ out: * routine are affected. */ int -vxy(x, y) - int *x, *y; +vxy(int *x, int *y) { int flag = 0; if (*x < 0) { @@ -1063,9 +1083,8 @@ vxy(x, y) * Enter with the spell number in spmun. * Returns no value. */ -void -dirpoly(spnum) - int spnum; +static void +dirpoly(int spnum) { int x, y, m; if (spnum < 0 || spnum >= SPNUM) @@ -1097,8 +1116,7 @@ dirpoly(spnum) * Returns no value. */ void -hitmonster(x, y) - int x, y; +hitmonster(int x, int y) { int tmp, monst, damag = 0, flag; if (c[TIMESTOP]) @@ -1149,10 +1167,8 @@ hitmonster(x, y) * This routine is used to specifically damage a monster at a location (x,y) * Called by hitmonster(x,y) */ -int -hitm(x, y, amt) - int x, y; - int amt; +static int +hitm(int x, int y, int amt) { int monst; int hpoints, amt2; @@ -1207,8 +1223,7 @@ hitm(x, y, amt) * Returns nothing of value. */ void -hitplayer(x, y) - int x, y; +hitplayer(int x, int y) { int dam, tmp, mster, bias; vxy(&x, &y); /* verify coordinates are within range */ @@ -1283,9 +1298,8 @@ hitplayer(x, y) * Enter with the monster number * Returns nothing of value. */ -void -dropsomething(monst) - int monst; +static void +dropsomething(int monst) { switch (monst) { case ORC: @@ -1318,8 +1332,7 @@ dropsomething(monst) * Returns nothing of value. */ void -dropgold(amount) - int amount; +dropgold(int amount) { if (amount > 250) createitem(OMAXGOLD, amount / 100); @@ -1366,8 +1379,7 @@ static char nobjtab[] = { OLONGSWORD}; int -newobject(lev, i) - int lev, *i; +newobject(int lev, int *i) { int tmp = 32, j; if (level < 0 || level > MAXLEVEL + MAXVLEVEL) @@ -1499,9 +1511,8 @@ static char rustarm[ARMORTYPES][2] = { { OPLATEARMOR, -9} }; static char spsel[] = {1, 2, 3, 5, 6, 8, 9, 11, 13, 14}; -int -spattack(x, xx, yy) - int x, xx, yy; +static int +spattack(int x, int xx, int yy) { int i, j = 0, k, m; const char *p = NULL; @@ -1688,8 +1699,7 @@ spout3: p = "\nThe %s bit you!"; * Note: if x > c[HP] this routine could kill the player! */ void -checkloss(x) - int x; +checkloss(int x) { if (x > 0) { losehp(x); @@ -1704,7 +1714,7 @@ checkloss(x) * Returns the experience gained from all monsters killed */ int -annihilate() +annihilate(void) { int i, j; long k; @@ -1739,8 +1749,7 @@ annihilate() * Returns the number of spheres currently in existence */ int -newsphere(x, y, dir, life) - int x, y, dir, life; +newsphere(int x, int y, int dir, int life) { int m; struct sphere *sp; @@ -1829,8 +1838,7 @@ boom: sphboom(x, y); /* blow up stuff around sphere */ * Returns the number of spheres currently in existence */ int -rmsphere(x, y) - int x, y; +rmsphere(int x, int y) { struct sphere *sp, *sp2 = 0; for (sp = spheres; sp; sp2 = sp, sp = sp->p) @@ -1862,9 +1870,8 @@ rmsphere(x, y) * * Enter with the coordinates of the blast, Returns no value */ -void -sphboom(x, y) - int x, y; +static void +sphboom(int x, int y) { int i, j; if (c[HOLDMONST]) @@ -1890,13 +1897,13 @@ sphboom(x, y) * * This is done by setting a flag in the monster[] structure */ -void -genmonst() +static void +genmonst(void) { int i, j; cursors(); lprcat("\nGenocide what monster? "); - for (i = 0; (!isalpha(i)) && (i != ' '); i = lgetchar()); + for (i = 0; (!isalpha(i)) && (i != ' '); i = ttgetch()); lprc(i); for (j = 0; j < MAXMONST; j++) /* search for the monster type */ if (monstnamelist[j] == i) { /* have we found it? */