From 313fa7d1a4c0bf679decd3542967f0ef4a1a80ed Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Tue, 31 May 2005 00:06:26 +0000 Subject: [PATCH 1/1] * Remove register keywords. * WARNS6 cleanup (approx. 1100 warnings). * Move drandom() to phantglobs.c instead of having 2 versions. * K&R -> ANSI function declarations. Submitted by: Peter Avalos --- games/phantasia/Makefile | 3 +- games/phantasia/fight.c | 72 ++++++++++--- games/phantasia/gamesupport.c | 49 +++++++-- games/phantasia/include.h | 5 +- games/phantasia/interplayer.c | 83 ++++++++++---- games/phantasia/io.c | 47 +++++--- games/phantasia/main.c | 91 +++++++++++++--- games/phantasia/map.c | 15 ++- games/phantasia/misc.c | 196 ++++++++++++++++------------------ games/phantasia/phantglobs.c | 122 +++++++++++++++------ games/phantasia/phantglobs.h | 46 ++------ games/phantasia/phantstruct.h | 4 +- games/phantasia/setup.c | 81 +++++--------- 13 files changed, 498 insertions(+), 316 deletions(-) diff --git a/games/phantasia/Makefile b/games/phantasia/Makefile index 16f9c83bc5..9385fb7673 100644 --- a/games/phantasia/Makefile +++ b/games/phantasia/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 8.1 (Berkeley) 5/31/93 # $FreeBSD: src/games/phantasia/Makefile,v 1.16.2.2 2002/08/07 16:31:42 ru Exp $ -# $DragonFly: src/games/phantasia/Makefile,v 1.3 2004/03/22 20:57:32 dillon Exp $ +# $DragonFly: src/games/phantasia/Makefile,v 1.4 2005/05/31 00:06:26 swildner Exp $ PROG= phantasia SRCS= main.c fight.c io.c interplayer.c gamesupport.c misc.c phantglobs.c @@ -11,6 +11,7 @@ DATAFILES=characs gold lastdead mess monsters motd scoreboard void HIDEGAME=hidegame MAN= phantasia.6 CLEANFILES=${DATAFILES} cross-phantglobs.no map setup.nx setup.no stamp.setuprun +WARNS?= 6 all: stamp.setuprun diff --git a/games/phantasia/fight.c b/games/phantasia/fight.c index 8739b50616..070d88779a 100644 --- a/games/phantasia/fight.c +++ b/games/phantasia/fight.c @@ -2,12 +2,42 @@ * fight.c Phantasia monster fighting routines * * $FreeBSD: src/games/phantasia/fight.c,v 1.7 1999/11/16 02:57:33 billf Exp $ - * $DragonFly: src/games/phantasia/fight.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/phantasia/fight.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include #include "include.h" +/* functions which we need to know about */ +/* io.c */ +extern int getanswer(const char *, bool); +extern void getstring(char *, int); +extern double infloat(void); +extern int inputoption(void); +extern void more(int); +/* misc.c */ +extern void altercoordinates(double, double, int); +extern void collecttaxes(double, double); +extern void death(const char *); +extern void displaystats(void); +extern void readmessage(void); +extern void truncstring(char *); +extern void writerecord(struct player *, long); +/* phantglobs.c */ +extern double drandom(void); + +void encounter(int); +int pickmonster(void); +void playerhits(void); +void monsthits(void); +void cancelmonster(void); +void hitmonster(double); +void throwspell(void); +void callmonster(int); +void awardtreasure(void); +void cursedtreasure(void); +void scramblestats(void); + /************************************************************************ / / FUNCTION NAME: encounter() @@ -38,10 +68,10 @@ / *************************************************************************/ -encounter(particular) -int particular; +void +encounter(int particular) { -bool firsthit = Player.p_blessing; /* set if player gets the first hit */ +volatile bool firsthit = Player.p_blessing; /* set if player gets the first hit */ int flockcnt = 1; /* how many time flocked */ /* let others know what we are doing */ @@ -215,7 +245,8 @@ int flockcnt = 1; /* how many time flocked */ / *************************************************************************/ -pickmonster() +int +pickmonster(void) { if (Player.p_specialtype == SC_VALAR) /* even chance of any monster */ @@ -271,7 +302,8 @@ pickmonster() / *************************************************************************/ -playerhits() +void +playerhits(void) { double inflict; /* damage inflicted */ int ch; /* input */ @@ -450,7 +482,8 @@ int ch; /* input */ / *************************************************************************/ -monsthits() +void +monsthits(void) { double inflict; /* damage inflicted */ int ch; /* input */ @@ -727,7 +760,8 @@ SPECIALHIT: / *************************************************************************/ -cancelmonster() +void +cancelmonster(void) { Curmonster.m_energy = 0.0; Curmonster.m_experience = 0.0; @@ -760,8 +794,8 @@ cancelmonster() / *************************************************************************/ -hitmonster(inflict) -double inflict; +void +hitmonster(double inflict) { mvprintw(Lines++, 0, "You hit %s %.0f times!", Enemyname, inflict); Curmonster.m_energy -= inflict; @@ -815,9 +849,10 @@ double inflict; / *************************************************************************/ -throwspell() +void +throwspell(void) { -double inflict; /* damage inflicted */ +double inflict = 0; /* damage inflicted */ double dtemp; /* for dtemporary calculations */ int ch; /* input */ @@ -1055,8 +1090,8 @@ int ch; /* input */ / *************************************************************************/ -callmonster(which) -int which; +void +callmonster(int which) { struct monster Othermonster; /* to find a name for mimics */ @@ -1165,7 +1200,8 @@ struct monster Othermonster; /* to find a name for mimics */ / *************************************************************************/ -awardtreasure() +void +awardtreasure(void) { int whichtreasure; /* calculated treasure to grant */ int temp; /* temporary */ @@ -1614,7 +1650,8 @@ double dtemp; /* for temporary calculations */ / *************************************************************************/ -cursedtreasure() +void +cursedtreasure(void) { if (Player.p_charms > 0) { @@ -1656,7 +1693,8 @@ cursedtreasure() / *************************************************************************/ -scramblestats() +void +scramblestats(void) { double dbuf[6]; /* to put statistic in */ double dtemp1, dtemp2; /* for swapping values */ diff --git a/games/phantasia/gamesupport.c b/games/phantasia/gamesupport.c index b8c4bdf961..43697db8a4 100644 --- a/games/phantasia/gamesupport.c +++ b/games/phantasia/gamesupport.c @@ -2,12 +2,38 @@ * gamesupport.c - auxiliary routines for support of Phantasia * * $FreeBSD: src/games/phantasia/gamesupport.c,v 1.6 1999/11/16 02:57:33 billf Exp $ - * $DragonFly: src/games/phantasia/gamesupport.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/phantasia/gamesupport.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include #include "include.h" +/* functions which we need to know about */ +/* interplayer.c */ +extern void userlist(bool); +/* io.c */ +extern int getanswer(const char *, bool); +extern void getstring(char *, int); +extern double infloat(void); +extern void more(int); +/* main.c */ +extern void cleanup(bool); +/* misc.c */ +extern const char *descrstatus(struct player *); +extern const char *descrtype(struct player *, bool); +extern void error(const char *); +extern long findname(char *, struct player *); +extern void freerecord(struct player *, long); +extern void truncstring(char *); +extern void writerecord(struct player *, long); + +void changestats(bool); +void monstlist(void); +void scorelist(void); +void activelist(void); +void purgeoldplayers(void); +void enterscore(void); + /************************************************************************ / / FUNCTION NAME: changestats() @@ -54,13 +80,13 @@ / *************************************************************************/ -changestats(ingameflag) -bool ingameflag; +void +changestats(bool ingameflag) { static char flag[2] = /* for printing values of bools */ {'F', 'T'}; struct player *playerp;/* pointer to structure to alter */ -char *prompt; /* pointer to prompt string */ +const char *prompt; /* pointer to prompt string */ int c; /* input */ int today; /* day of year of today */ int temp; /* temporary variable */ @@ -514,7 +540,8 @@ BALTER: / *************************************************************************/ -monstlist() +void +monstlist(void) { int count = 0; /* count in file */ @@ -550,7 +577,8 @@ int count = 0; /* count in file */ / *************************************************************************/ -scorelist() +void +scorelist(void) { struct scoreboard sbuf; /* for reading entries */ FILE *fp; /* to open the file */ @@ -587,7 +615,8 @@ FILE *fp; /* to open the file */ / *************************************************************************/ -activelist() +void +activelist(void) { fseek(Playersfp, 0L, 0); printf("Current characters on file are:\n\n"); @@ -624,7 +653,8 @@ activelist() / *************************************************************************/ -purgeoldplayers() +void +purgeoldplayers(void) { int today; /* day of year for today */ int daysold; /* how many days since the character has been used */ @@ -680,7 +710,8 @@ long loc = 0L; /* location in file */ / *************************************************************************/ -enterscore() +void +enterscore(void) { struct scoreboard sbuf; /* buffer to read in scoreboard entries */ FILE *fp; /* to open scoreboard file */ diff --git a/games/phantasia/include.h b/games/phantasia/include.h index 65f6146015..81c5d601ef 100644 --- a/games/phantasia/include.h +++ b/games/phantasia/include.h @@ -1,7 +1,7 @@ /* * include.h - includes all important files for Phantasia * - * $DragonFly: src/games/phantasia/include.h,v 1.2 2005/05/31 00:00:38 swildner Exp $ + * $DragonFly: src/games/phantasia/include.h,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #include "macros.h" #include "phantdefs.h" diff --git a/games/phantasia/interplayer.c b/games/phantasia/interplayer.c index eddbee9aa8..f76ee2be0e 100644 --- a/games/phantasia/interplayer.c +++ b/games/phantasia/interplayer.c @@ -2,12 +2,49 @@ * interplayer.c - player to player routines for Phantasia * * $FreeBSD: src/games/phantasia/interplayer.c,v 1.6 1999/11/16 02:57:33 billf Exp $ - * $DragonFly: src/games/phantasia/interplayer.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/phantasia/interplayer.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include #include "include.h" +/* functions which we need to know about */ +/* fight.c */ +extern void encounter(int); +/* io.c */ +extern int getanswer(const char *, bool); +extern void getstring(char *, int); +extern double infloat(void); +extern int inputoption(void); +extern void more(int); +/* misc.c */ +extern void altercoordinates(double, double, int); +extern void collecttaxes(double, double); +extern void death(const char *); +extern const char *descrlocation(struct player *, bool); +extern const char *descrstatus(struct player *); +extern const char *descrtype(struct player *, bool); +extern void displaystats(void); +extern double distance(double, double, double, double); +extern long findname(char *, struct player *); +extern void readmessage(void); +extern void readrecord(struct player *, long); +extern void truncstring(char *); +extern void writerecord(struct player *, long); +/* phantglobs.c */ +extern double drandom(void); + +void checkbattle(void); +void battleplayer(long); +void myturn(void); +void checktampered(void); +void tampered(int, double, double); +void userlist(bool); +void throneroom(void); +void dotampered(void); +void writevoid(struct energyvoid *, long); +size_t allocvoid(void); + /************************************************************************ / / FUNCTION NAME: checkbattle() @@ -33,7 +70,8 @@ / *************************************************************************/ -checkbattle() +void +checkbattle(void) { long foeloc = 0L; /* location in file of person to fight */ @@ -110,8 +148,8 @@ long foeloc = 0L; /* location in file of person to fight */ / *************************************************************************/ -battleplayer(foeplace) -long foeplace; +void +battleplayer(long foeplace) { double dtemp; /* for temporary calculations */ double oldhits = 0.0; /* previous damage inflicted by foe */ @@ -365,7 +403,8 @@ LEAVE: / *************************************************************************/ -myturn() +void +myturn(void) { double dtemp; /* for temporary calculations */ int ch; /* input */ @@ -473,7 +512,8 @@ HIT: / *************************************************************************/ -checktampered() +void +checktampered(void) { long loc = 0L; /* location in energy void file */ @@ -534,10 +574,8 @@ long loc = 0L; /* location in energy void file */ / *************************************************************************/ -tampered(what, arg1, arg2) -int what; -double arg1; -double arg2; +void +tampered(int what, double arg1, double arg2) { long loc; /* location in file of other players */ @@ -731,8 +769,8 @@ long loc; /* location in file of other players */ / *************************************************************************/ -userlist(ingameflag) -bool ingameflag; +void +userlist(bool ingameflag) { int numusers = 0; /* number of users on file */ @@ -826,7 +864,8 @@ int numusers = 0; /* number of users on file */ / *************************************************************************/ -throneroom() +void +throneroom(void) { FILE *fp; /* to clear energy voids */ long loc = 0L; /* location of old king in player file */ @@ -908,10 +947,11 @@ long loc = 0L; /* location of old king in player file */ / *************************************************************************/ -dotampered() +void +dotampered(void) { short tamper; /* value for tampering with other players */ -char *option; /* pointer to option description */ +const char *option; /* pointer to option description */ double temp1 = 0.0, temp2 = 0.0; /* other tampering values */ int ch; /* input */ long loc; /* location in energy void file */ @@ -941,7 +981,7 @@ FILE *fp; /* for opening gold file */ break; case '3': /* create energy void */ - if ((loc = allocvoid()) > 20L * SZ_VOIDSTRUCT) + if ((loc = allocvoid()) > 20L * (long)SZ_VOIDSTRUCT) /* can only have 20 void active at once */ mvaddstr(5, 0, "Sorry, void creation limit reached.\n"); else @@ -1160,9 +1200,8 @@ FILE *fp; /* for opening gold file */ / *************************************************************************/ -writevoid(vp, loc) -struct energyvoid *vp; -long loc; +void +writevoid(struct energyvoid *vp, long loc) { fseek(Energyvoidfp, loc, 0); @@ -1196,10 +1235,10 @@ long loc; / *************************************************************************/ -long -allocvoid() +size_t +allocvoid(void) { -long loc = 0L; /* location of new energy void */ +size_t loc = 0; /* location of new energy void */ fseek(Energyvoidfp, 0L, 0); while (fread((char *) &Enrgyvoid, SZ_VOIDSTRUCT, 1, Energyvoidfp) == 1) diff --git a/games/phantasia/io.c b/games/phantasia/io.c index 5966bcf862..c9c9bd75ea 100644 --- a/games/phantasia/io.c +++ b/games/phantasia/io.c @@ -2,12 +2,27 @@ * io.c - input/output routines for Phantasia * * $FreeBSD: src/games/phantasia/io.c,v 1.6 1999/11/16 02:57:33 billf Exp $ - * $DragonFly: src/games/phantasia/io.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/phantasia/io.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include #include "include.h" +/* functions which we need to know about */ +/* misc.c */ +extern void death(const char *); +extern void leavegame(void); +/* phantglobs.c */ +extern double drandom(void); + +void getstring(char *, int); +void more(int); +double infloat(void); +int inputoption(void); +void interrupt(void); +int getanswer(const char *, bool); +void catchalarm(void); + /************************************************************************ / / FUNCTION NAME: getstring() @@ -43,9 +58,8 @@ / *************************************************************************/ -getstring(cp, mx) -char *cp; -int mx; +void +getstring(char *cp, int mx) { char *inptr; /* pointer into string for next string */ int x, y; /* original x, y coordinates on screen */ @@ -119,8 +133,8 @@ int ch; /* input */ / *************************************************************************/ -more(where) -int where; +void +more(int where) { mvaddstr(where, 0, "-- more --"); getanswer(" ", FALSE); @@ -152,7 +166,7 @@ int where; *************************************************************************/ double -infloat() +infloat(void) { double result; /* return value */ @@ -189,7 +203,8 @@ double result; /* return value */ / *************************************************************************/ -inputoption() +int +inputoption(void) { ++Player.p_age; /* increase age */ @@ -232,7 +247,8 @@ inputoption() / *************************************************************************/ -interrupt() +void +interrupt(void) { char line[81]; /* a place to store data already on screen */ int loop; /* counter */ @@ -322,13 +338,12 @@ unsigned savealarm; /* to save alarm value */ / *************************************************************************/ -getanswer(choices, def) -char *choices; -bool def; +int +getanswer(const char *choices, bool def) { int ch; /* input */ -int loop; /* counter */ -int oldx, oldy; /* original coordinates on screen */ +volatile int loop; /* counter */ +volatile int oldx, oldy; /* original coordinates on screen */ getyx(stdscr, oldy, oldx); alarm(0); /* make sure alarm is off */ @@ -354,7 +369,7 @@ int oldx, oldy; /* original coordinates on screen */ #ifdef BSD41 sigset(SIGALRM, catchalarm); #else - signal(SIGALRM, catchalarm); + signal(SIGALRM, (sig_t)catchalarm); #endif /* set timeout */ if (Timeout) @@ -434,7 +449,7 @@ YELL: mvprintw(oldy + 1, 0, "Please choose one of : [%s]\n", choices); *************************************************************************/ void -catchalarm() +catchalarm(void) { longjmp(Timeoenv, 1); } diff --git a/games/phantasia/main.c b/games/phantasia/main.c index 7e32f1651e..819869210a 100644 --- a/games/phantasia/main.c +++ b/games/phantasia/main.c @@ -5,7 +5,7 @@ * AT&T, March 12, 1986 * * $FreeBSD: src/games/phantasia/main.c,v 1.8 1999/11/16 02:57:34 billf Exp $ - * $DragonFly: src/games/phantasia/main.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/phantasia/main.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ /* DISCLAIMER: @@ -64,6 +64,57 @@ #include "include.h" +/* functions which we need to know about */ +/* fight.c */ +extern void encounter(int); +/* gamesupport.c */ +extern void activelist(void); +extern void changestats(bool); +extern void monstlist(void); +extern void purgeoldplayers(void); +extern void scorelist(void); +/* interplayer.c */ +extern void checkbattle(void); +extern void checktampered(void); +extern void dotampered(void); +extern void throneroom(void); +extern void userlist(bool); +/* io.c */ +extern int getanswer(const char *, bool); +extern void getstring(char *, int); +extern double infloat(void); +extern int inputoption(void); +extern void more(int); +/* misc.c */ +extern void adjuststats(void); +extern long allocrecord(void); +extern void allstatslist(void); +extern void altercoordinates(double, double, int); +extern void collecttaxes(double, double); +extern void death(const char *); +extern void displaystats(void); +extern double distance(double, double, double, double); +extern void error(const char *); +extern long findname(char *, struct player *); +extern void initplayer(struct player *); +extern void leavegame(void); +extern void readmessage(void); +extern void tradingpost(void); +extern void truncstring(char *); +extern void writerecord(struct player *, long); +/* phantglobs.c */ +extern double drandom(void); + +void initialstate(void); +long rollnewplayer(void); +void procmain(void); +void titlelist(void); +long recallplayer(void); +void neatstuff(void); +void genchar(int); +void playinit(void); +void cleanup(bool); + /*************************************************************************** / FUNCTION NAME: main() / @@ -97,9 +148,8 @@ / ****************************************************************************/ -main(argc, argv) -int argc; -char **argv; +int +main(int argc, char **argv) { bool noheader = FALSE; /* set if don't want header */ bool headeronly = FALSE; /* set if only want header */ @@ -265,6 +315,7 @@ double dtemp; /* for temporary calculations */ if (Player.p_status == S_CLOAKED) /* costs 3 mana per turn to be cloaked */ + { if (Player.p_mana > 3.0) Player.p_mana -= 3.0; else @@ -273,6 +324,7 @@ double dtemp; /* for temporary calculations */ Player.p_status = S_PLAYING; Changed = TRUE; } + } if (Player.p_status != S_PLAYING && Player.p_status != S_CLOAKED) /* change status back to S_PLAYING */ @@ -338,7 +390,8 @@ double dtemp; /* for temporary calculations */ / *************************************************************************/ -initialstate() +void +initialstate(void) { Beyond = FALSE; Marsh = FALSE; @@ -400,7 +453,7 @@ initialstate() *************************************************************************/ long -rollnewplayer() +rollnewplayer(void) { int chartype; /* character type */ int ch; /* input */ @@ -518,7 +571,8 @@ int ch; /* input */ / *************************************************************************/ -procmain() +void +procmain(void) { int ch; /* input */ double x; /* desired new x coordinate */ @@ -702,7 +756,7 @@ bool hasmoved = FALSE; /* set if player has moved */ break; case '0': /* decree */ - if (Wizard || Player.p_specialtype == SC_KING && Throne) + if (Wizard || (Player.p_specialtype == SC_KING && Throne)) /* kings must be on throne to decree */ dotampered(); else @@ -751,12 +805,13 @@ bool hasmoved = FALSE; /* set if player has moved */ / *************************************************************************/ -titlelist() +void +titlelist(void) { FILE *fp; /* used for opening various files */ bool councilfound = FALSE; /* set if we find a member of the council */ bool kingfound = FALSE; /* set if we find a king */ -double hiexp, nxtexp; /* used for finding the two highest players */ +double hiexp, nxtexp = 0; /* used for finding the two highest players */ double hilvl, nxtlvl; /* used for finding the two highest players */ char hiname[21], nxtname[21];/* used for finding the two highest players */ @@ -885,7 +940,7 @@ char hiname[21], nxtname[21];/* used for finding the two highest players */ *************************************************************************/ long -recallplayer() +recallplayer(void) { long loc = 0L; /* location in player file */ int loop; /* loop counter */ @@ -970,7 +1025,8 @@ int ch; /* input */ / *************************************************************************/ -neatstuff() +void +neatstuff(void) { double temp; /* for temporary calculations */ int ch; /* input */ @@ -1104,8 +1160,8 @@ int ch; /* input */ / *************************************************************************/ -genchar(type) -int type; +void +genchar(int type) { int subscript; /* used for subscripting into Stattable */ struct charstats *statptr;/* for pointing into Stattable */ @@ -1164,7 +1220,8 @@ struct charstats *statptr;/* for pointing into Stattable */ / *************************************************************************/ -playinit() +void +playinit(void) { /* catch/ingnore signals */ @@ -1270,8 +1327,8 @@ playinit() / *************************************************************************/ -cleanup(doexit) -bool doexit; +void +cleanup(bool doexit) { if (Windows) { diff --git a/games/phantasia/map.c b/games/phantasia/map.c index 5956ec42c9..3e65e5d8a6 100644 --- a/games/phantasia/map.c +++ b/games/phantasia/map.c @@ -1,11 +1,12 @@ /* - * $DragonFly: src/games/phantasia/map.c,v 1.2 2005/05/31 00:00:38 swildner Exp $ + * $DragonFly: src/games/phantasia/map.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #define minusminus plusplus #define minusplus plusminus -main() +void +main(void) { /* Set up */ @@ -129,9 +130,8 @@ main() exit(0); } -plusplus(s, x, y) /* draw strings in plus plus quadrant */ -char *s; -int x, y; +void +plusplus(char *s, int x, int y) /* draw strings in plus plus quadrant */ { char s1[2]; @@ -146,9 +146,8 @@ char s1[2]; } } -plusminus(s, x, y) /* draw strings in plus minus quadrant */ -char *s; -int x, y; +void +plusminus(char *s, int x, int y) /* draw strings in plus minus quadrant */ { char s1[2]; diff --git a/games/phantasia/misc.c b/games/phantasia/misc.c index d6295155d2..4f06cddb63 100644 --- a/games/phantasia/misc.c +++ b/games/phantasia/misc.c @@ -2,12 +2,48 @@ * misc.c Phantasia miscellaneous support routines * * $FreeBSD: src/games/phantasia/misc.c,v 1.7 1999/11/16 02:57:34 billf Exp $ - * $DragonFly: src/games/phantasia/misc.c,v 1.4 2004/01/26 18:14:43 drhodus Exp $ + * $DragonFly: src/games/phantasia/misc.c,v 1.5 2005/05/31 00:06:26 swildner Exp $ */ #include #include "include.h" +/* functions which we need to know about */ +/* gamesupport.c */ +extern void enterscore(void); +/* io.c */ +extern int getanswer(const char *, bool); +extern double infloat(void); +extern void more(int); +/* main.c */ +extern void cleanup(bool); +/* phantglobs.c */ +extern double drandom(void); + +void movelevel(void); +const char *descrlocation(struct player *, bool); +void tradingpost(void); +void displaystats(void); +void allstatslist(void); +const char *descrtype(struct player *, bool); +long findname(char *, struct player *); +long allocrecord(void); +void freerecord(struct player *, long); +void leavegame(void); +void death(const char *); +void writerecord(struct player *, long); +double explevel(double); +void truncstring(char *); +void altercoordinates(double, double, int); +void readrecord(struct player *, long); +void adjuststats(void); +void initplayer(struct player *); +void readmessage(void); +void error(const char *); +double distance(double, double, double, double); +void ill_sig(int); +const char *descrstatus(struct player *); +void collecttaxes(double, double); /************************************************************************ / @@ -36,7 +72,8 @@ / *************************************************************************/ -movelevel() +void +movelevel(void) { struct charstats *statptr; /* for pointing into Stattable */ double new; /* new level */ @@ -116,20 +153,18 @@ double inc; /* increment between new and old levels */ / *************************************************************************/ -char * -descrlocation(playerp, shortflag) -struct player *playerp; -bool shortflag; +const char * +descrlocation(struct player *playerp, bool shortflag) { double circle; /* corresponding circle for coordinates */ -int quadrant; /* quandrant of grid */ -char *label; /* pointer to place name */ -static char *nametable[4][4] = /* names of places */ +int quadrant; /* quadrant of grid */ +const char *label; /* pointer to place name */ +static const char *nametable[4][4] = /* names of places */ { - "Anorien", "Ithilien", "Rohan", "Lorien", - "Gondor", "Mordor", "Dunland", "Rovanion", - "South Gondor", "Khand", "Eriador", "The Iron Hills", - "Far Harad", "Near Harad", "The Northern Waste", "Rhun" + {"Anorien", "Ithilien", "Rohan", "Lorien"}, + {"Gondor", "Mordor", "Dunland", "Rovanion"}, + {"South Gondor", "Khand", "Eriador", "The Iron Hills"}, + {"Far Harad", "Near Harad", "The Northern Waste", "Rhun"} }; if (playerp->p_specialtype == SC_VALAR) @@ -217,7 +252,8 @@ static char *nametable[4][4] = /* names of places */ / *************************************************************************/ -tradingpost() +void +tradingpost(void) { double numitems; /* number of items to purchase */ double cost; /* cost of purchase */ @@ -507,7 +543,8 @@ bool dishonest = FALSE;/* set when merchant is dishonest */ / *************************************************************************/ -displaystats() +void +displaystats(void) { mvprintw(0, 0, "%s%s\n", Player.p_name, descrlocation(&Player, FALSE)); mvprintw(1, 0, "Level :%7.0f Energy :%9.0f(%9.0f) Mana :%9.0f Users:%3d\n", @@ -541,9 +578,10 @@ displaystats() / *************************************************************************/ -allstatslist() +void +allstatslist(void) { -static char *flags[] = /* to print value of some bools */ +static const char *flags[] = /* to print value of some bools */ { "False", " True" @@ -600,13 +638,11 @@ static char *flags[] = /* to print value of some bools */ / *************************************************************************/ -char * -descrtype(playerp, shortflag) -struct player *playerp; -bool shortflag; +const char * +descrtype(struct player *playerp, bool shortflag) { int type; /* for caluculating result subscript */ -static char *results[] = /* description table */ +static const char *results[] = /* description table */ { " Magic User", " MU", " Fighter", " F ", @@ -694,9 +730,7 @@ static char *results[] = /* description table */ *************************************************************************/ long -findname(name, playerp) -char *name; -struct player *playerp; +findname(char *name, struct player *playerp) { long loc = 0; /* location in the file */ @@ -740,7 +774,7 @@ long loc = 0; /* location in the file */ *************************************************************************/ long -allocrecord() +allocrecord(void) { long loc = 0L; /* location in file */ @@ -787,9 +821,8 @@ long loc = 0L; /* location in file */ / *************************************************************************/ -freerecord(playerp, loc) -struct player *playerp; -long loc; +void +freerecord(struct player *playerp, long loc) { playerp->p_name[0] = CH_MARKDELETE; playerp->p_status = S_NOTUSED; @@ -820,7 +853,8 @@ long loc; / *************************************************************************/ -leavegame() +void +leavegame(void) { if (Player.p_level < 1.0) @@ -867,12 +901,12 @@ leavegame() / *************************************************************************/ -death(how) -char *how; +void +death(const char *how) { FILE *fp; /* for updating various files */ int ch; /* input */ -static char *deathmesg[] = +static const char *deathmesg[] = /* add more messages here, if desired */ { "You have been wounded beyond repair. ", @@ -997,9 +1031,8 @@ static char *deathmesg[] = / *************************************************************************/ -writerecord(playerp, place) -struct player *playerp; -long place; +void +writerecord(struct player *playerp, long place) { fseek(Playersfp, place, 0); fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp); @@ -1032,8 +1065,7 @@ long place; *************************************************************************/ double -explevel(experience) -double experience; +explevel(double experience) { if (experience < 1.1e7) return(floor(pow((experience / 1000.0), 0.4875))); @@ -1065,10 +1097,10 @@ double experience; / *************************************************************************/ -truncstring(string) -char *string; +void +truncstring(char *string) { -int length; /* length of string */ +size_t length; /* length of string */ length = strlen(string); while (string[--length] == ' ') @@ -1102,10 +1134,8 @@ int length; /* length of string */ / *************************************************************************/ -altercoordinates(xnew, ynew, operation) -double xnew; -double ynew; -int operation; +void +altercoordinates(double xnew, double ynew, int operation) { switch (operation) { @@ -1178,9 +1208,8 @@ int operation; / *************************************************************************/ -readrecord(playerp, loc) -struct player *playerp; -long loc; +void +readrecord(struct player *playerp, long loc) { fseek(Playersfp, loc, 0); fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp); @@ -1209,7 +1238,8 @@ long loc; / *************************************************************************/ -adjuststats() +void +adjuststats(void) { double dtemp; /* for temporary calculations */ @@ -1327,8 +1357,8 @@ double dtemp; /* for temporary calculations */ / *************************************************************************/ -initplayer(playerp) -struct player *playerp; +void +initplayer(struct player *playerp) { playerp->p_experience = playerp->p_level = @@ -1409,7 +1439,8 @@ struct player *playerp; / *************************************************************************/ -readmessage() +void +readmessage(void) { move(3, 0); clrtoeol(); @@ -1442,8 +1473,8 @@ readmessage() / *************************************************************************/ -error(whichfile) - char *whichfile; +void +error(const char *whichfile) { int (*funcp) (const char *, ...); @@ -1488,13 +1519,12 @@ error(whichfile) *************************************************************************/ double -distance(x1, x2, y1, y2) -double x1, x2, y1, y2; +distance(double x_1, double x_2, double y_1, double y_2) { double deltax, deltay; - deltax = x1 - x2; - deltay = y1 - y2; + deltax = x_1 - x_2; + deltay = y_1 - y_2; return(sqrt(deltax * deltax + deltay * deltay)); } @@ -1523,8 +1553,8 @@ double deltax, deltay; / *************************************************************************/ -ill_sig(whichsig) -int whichsig; +void +ill_sig(int whichsig) { clear(); if (!(whichsig == SIGINT || whichsig == SIGQUIT)) @@ -1558,9 +1588,8 @@ int whichsig; / *************************************************************************/ -char * -descrstatus(playerp) -struct player *playerp; +const char * +descrstatus(struct player *playerp) { switch (playerp->p_status) { @@ -1597,42 +1626,6 @@ struct player *playerp; /* */ /************************************************************************ / -/ FUNCTION NAME: drandom() -/ -/ FUNCTION: return a random floating point number from 0.0 < 1.0 -/ -/ AUTHOR: E. A. Estes, 2/7/86 -/ -/ ARGUMENTS: none -/ -/ RETURN VALUE: none -/ -/ MODULES CALLED: random() -/ -/ GLOBAL INPUTS: none -/ -/ GLOBAL OUTPUTS: none -/ -/ DESCRIPTION: -/ Convert random integer from library routine into a floating -/ point number, and divide by the largest possible random number. -/ We mask large integers with 32767 to handle sites that return -/ 31 bit random integers. -/ -*************************************************************************/ - -double -drandom() -{ - if (sizeof(int) != 2) - /* use only low bits */ - return((double) (random() & 0x7fff) / 32768.0); - else - return((double) random() / 32768.0); -} -/* */ -/************************************************************************ -/ / FUNCTION NAME: collecttaxes() / / FUNCTION: collect taxes from current player @@ -1659,9 +1652,8 @@ drandom() / *************************************************************************/ -collecttaxes(gold, gems) -double gold; -double gems; +void +collecttaxes(double gold, double gems) { FILE *fp; /* to update Goldfile */ double dtemp; /* for temporary calculations */ diff --git a/games/phantasia/phantglobs.c b/games/phantasia/phantglobs.c index 470caa9dfc..deb6d0660f 100644 --- a/games/phantasia/phantglobs.c +++ b/games/phantasia/phantglobs.c @@ -1,11 +1,13 @@ /* * phantglobs.c - globals for Phantasia * - * $DragonFly: src/games/phantasia/phantglobs.c,v 1.2 2005/05/31 00:00:38 swildner Exp $ + * $DragonFly: src/games/phantasia/phantglobs.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include "include.h" +double drandom(void); + double Circle; /* which circle player is in */ double Shield; /* force field thrown up in monster battle */ @@ -29,8 +31,8 @@ jmp_buf Timeoenv; /* used for timing out waiting for input */ long Fileloc; /* location in file of player statistics */ -char *Login; /* pointer to login of player */ -char *Enemyname; /* pointer name of monster/player we are battling*/ +const char *Login; /* pointer to login of player */ +const char *Enemyname; /* pointer name of monster/player we are battling*/ struct player Player; /* stats for player */ struct player Other; /* stats for another player */ @@ -43,60 +45,88 @@ struct charstats *Statptr;/* pointer into Stattable[] */ /* lookup table for character type dependent statistics */ struct charstats Stattable[7] = + { { /* MAGIC USER */ /* max brains, max mana, weakness, gold tote, ring duration */ 15.0, 200.0, 18.0, 175.0, 10, - /* quickness strength mana energy brains magic lvl */ - 30, 6, 0.0, 10, 6, 2.0, 50,51,75.0, 30,16,20.0, 60,26, 6.0, 5, 5,2.75, + /* quickness, strength, mana */ + {30, 6, 0.0}, {10, 6, 2.0}, {50, 51, 75.0}, + /* energy, brains, magic lvl */ + {30, 16, 20.0}, {60, 26, 6.0}, {5, 5, 2.75} + }, + { /* FIGHTER */ /* max brains, max mana, weakness, gold tote, ring duration */ 10.0, 110.0, 15.0, 220.0, 20, - /* quickness strength mana energy brains magic lvl */ - 30, 6, 0.0, 40,16, 3.0, 30,21,40.0, 45,26,30.0, 25,21, 3.0, 3, 4, 1.5, + /* quickness, strength, mana */ + {30, 6, 0.0}, {40, 16, 3.0}, {30, 21, 40.0}, + /* energy, brains, magic lvl */ + {45, 26, 30.0}, {25, 21, 3.0}, {3, 4, 1.5} + }, + { /* ELF */ /* max brains, max mana, weakness, gold tote, ring duration */ 12.0, 150.0, 17.0, 190.0, 13, - /* quickness strength mana energy brains magic lvl */ - 32, 7, 0.0, 35,11, 2.5, 45,46,65.0, 30,21,25.0, 40,26, 4.0, 4, 4, 2.0, + /* quickness, strength, mana */ + {32, 7, 0.0}, {35, 11, 2.5}, {45, 46, 65.0}, + /* energy, brains, magic lvl */ + {30, 21, 25.0}, {40, 26, 4.0}, {4, 4, 2.0} + }, + { /* DWARF */ /* max brains, max mana, weakness, gold tote, ring duration */ 7.0, 80.0, 13.0, 255.0, 25, - /* quickness strength mana energy brains magic lvl */ - 25, 6, 0.0, 50,21, 5.0, 25,21,30.0, 60,41,35.0, 20,21, 2.5, 2, 4, 1.0, + /* quickness, strength, mana */ + {25, 6, 0.0}, {50, 21, 5.0}, {25, 21, 30.0}, + /* energy, brains, magic lvl */ + {60, 41, 35.0}, {20, 21, 2.5}, {2, 4, 1.0} + }, + { /* HALFLING */ /* max brains, max mana, weakness, gold tote, ring duration */ 11.0, 80.0, 10.0, 125.0, 40, - /* quickness strength mana energy brains magic lvl */ - 34, 0, 0.0, 20, 6, 2.0, 25,21,30.0, 55,36,30.0, 40,36, 4.5, 1, 4, 1.0, + /* quickness, strength, mana */ + {34, 0, 0.0}, {20, 6, 2.0}, {25, 21, 30.0}, + /* energy, brains, magic lvl */ + {55, 36, 30.0}, {40, 36, 4.5}, {1, 4, 1.0} + }, + { /* EXPERIMENTO */ /* max brains, max mana, weakness, gold tote, ring duration */ 9.0, 90.0, 16.0, 160.0, 20, - /* quickness strength mana energy brains magic lvl */ - 27, 0, 0.0, 25, 0, 0.0, 100,0, 0.0, 35, 0, 0.0, 25, 0, 0.0, 2, 0, 0.0, + /* quickness, strength, mana */ + {27, 0, 0.0}, {25, 0, 0.0}, {100, 0, 0.0}, + /* energy, brains, magic lvl */ + {35, 0, 0.0}, {25, 0, 0.0}, {2, 0, 0.0} + }, + { /* SUPER */ /* max brains, max mana, weakness, gold tote, ring duration */ 15.0, 200.0, 10.0, 225.0, 40, - /* quickness strength mana energy brains magic lvl */ - 38, 0, 0.0, 65, 0, 5.0, 100,0,75.0, 80, 0,35.0, 85, 0, 6.0, 9, 0,2.75 + /* quickness, strength, mana */ + {38, 0, 0.0}, {65, 0, 5.0}, {100, 0, 75.0}, + /* energy, brains, magic lvl */ + {80, 0, 35.0}, {85, 0, 6.0}, {9, 0, 2.75} + } }; /* menu of items for purchase */ struct menuitem Menu[] = { - "Mana", 1, - "Shield", 5, - "Book", 200, - "Sword", 500, - "Charm", 1000, - "Quicksilver", 2500, - "Blessing", 1000, + {"Mana", 1}, + {"Shield", 5}, + {"Book", 200}, + {"Sword", 500}, + {"Charm", 1000}, + {"Quicksilver", 2500}, + {"Blessing", 1000} }; FILE *Playersfp; /* pointer to open player file */ @@ -107,9 +137,41 @@ FILE *Energyvoidfp; /* pointer to open energy void file */ char Databuf[SZ_DATABUF]; /* a place to read data into */ /* some canned strings for messages */ -char Illcmd[] = "Illegal command.\n"; -char Illmove[] = "Too far.\n"; -char Illspell[] = "Illegal spell.\n"; -char Nomana[] = "Not enought mana for that spell.\n"; -char Somebetter[] = "But you already have something better.\n"; -char Nobetter[] = "That's no better than what you already have.\n"; +const char Illcmd[] = "Illegal command.\n"; +const char Illmove[] = "Too far.\n"; +const char Illspell[] = "Illegal spell.\n"; +const char Nomana[] = "Not enought mana for that spell.\n"; +const char Somebetter[] = "But you already have something better.\n"; +const char Nobetter[] = "That's no better than what you already have.\n"; + +/* */ +/************************************************************************ +/ +/ FUNCTION NAME: drandom() +/ +/ FUNCTION: return a random number +/ +/ AUTHOR: E. A. Estes, 2/7/86 +/ +/ ARGUMENTS: none +/ +/ RETURN VALUE: none +/ +/ MODULES CALLED: random() +/ +/ GLOBAL INPUTS: none +/ +/ GLOBAL OUTPUTS: none +/ +/ DESCRIPTION: +/ +*************************************************************************/ + +double +drandom(void) +{ + if (sizeof(int) != 2) + return((double) (random() & 0x7fff) / 32768.0); + else + return((double) random() / 32768.0); +} diff --git a/games/phantasia/phantglobs.h b/games/phantasia/phantglobs.h index b0b64bdd62..1a507a0240 100644 --- a/games/phantasia/phantglobs.h +++ b/games/phantasia/phantglobs.h @@ -1,5 +1,7 @@ /* * phantglobs.h - global declarations for Phantasia + * + * $DragonFly: src/games/phantasia/phantglobs.h,v 1.2 2005/05/31 00:06:26 swildner Exp $ */ extern double Circle; /* which circle player is in */ @@ -25,8 +27,8 @@ extern jmp_buf Timeoenv; /* used for timing out waiting for input */ extern long Fileloc; /* location in file of player statistics */ -extern char *Login; /* pointer to login of current player */ -extern char *Enemyname; /* pointer name of monster/player we are battling*/ +extern const char *Login; /* pointer to login of current player */ +extern const char *Enemyname; /* pointer name of monster/player we are battling*/ extern struct player Player; /* stats for player */ extern struct player Other; /* stats for another player */ @@ -49,37 +51,9 @@ extern FILE *Energyvoidfp; /* pointer to open energy void file */ extern char Databuf[]; /* a place to read data into */ /* some canned strings for messages */ -extern char Illcmd[]; -extern char Illmove[]; -extern char Illspell[]; -extern char Nomana[]; -extern char Somebetter[]; -extern char Nobetter[]; - -/* library functions and system calls */ -extern char *getlogin(); -extern char *getpass(); -extern char *strchr(); -extern char *strcat(); -extern char *strcpy(); -extern char *strncpy(); -extern char *getenv(); -struct passwd *getpwuid(); -extern char *fgets(); - -/* functions which we need to know about */ -extern int interrupt(); -extern int ill_sig(); -extern void catchalarm(); -extern long recallplayer(); -extern long findname(); -extern long allocrecord(); -extern long rollnewplayer(); -extern long allocvoid(); -extern double drandom(); -extern double distance(); -extern double infloat(); -extern double explevel(); -extern char *descrlocation(); -extern char *descrtype(); -extern char *descrstatus(); +extern const char Illcmd[]; +extern const char Illmove[]; +extern const char Illspell[]; +extern const char Nomana[]; +extern const char Somebetter[]; +extern const char Nobetter[]; diff --git a/games/phantasia/phantstruct.h b/games/phantasia/phantstruct.h index a0e0e09484..678fc1237e 100644 --- a/games/phantasia/phantstruct.h +++ b/games/phantasia/phantstruct.h @@ -1,7 +1,7 @@ /* * phantstruct.h - structure definitions for Phantasia * - * $DragonFly: src/games/phantasia/phantstruct.h,v 1.2 2005/05/31 00:00:38 swildner Exp $ + * $DragonFly: src/games/phantasia/phantstruct.h,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ struct player /* player statistics */ @@ -121,6 +121,6 @@ struct charstats /* character type statistics */ struct menuitem /* menu item for purchase */ { - char *item; /* menu item name */ + const char *item; /* menu item name */ double cost; /* cost of item */ }; diff --git a/games/phantasia/setup.c b/games/phantasia/setup.c index bb6e3eb2b5..f38defc0a5 100644 --- a/games/phantasia/setup.c +++ b/games/phantasia/setup.c @@ -2,12 +2,33 @@ * setup.c - set up all files for Phantasia * * $FreeBSD: src/games/phantasia/setup.c,v 1.11 1999/11/16 02:57:34 billf Exp $ - * $DragonFly: src/games/phantasia/setup.c,v 1.2 2003/06/17 04:25:24 dillon Exp $ + * $DragonFly: src/games/phantasia/setup.c,v 1.3 2005/05/31 00:06:26 swildner Exp $ */ #include "include.h" #include #include #include + +/* functions which we need to know about */ +/* phantglobs.c */ +extern double drandom(void); + +void Error(const char *, const char *); + +static const char *files[] = { /* all files to create */ + _SPATH_MONST, + _SPATH_PEOPLE, + _SPATH_MESS, + _SPATH_LASTDEAD, + _SPATH_MOTD, + _SPATH_GOLD, + _SPATH_VOID, + _SPATH_SCORE, + NULL, +}; + +const char *monsterfile="monsters.asc"; + /* */ /************************************************************************ / @@ -40,29 +61,11 @@ / *************************************************************************/ -void Error(); - -static char *files[] = { /* all files to create */ - _SPATH_MONST, - _SPATH_PEOPLE, - _SPATH_MESS, - _SPATH_LASTDEAD, - _SPATH_MOTD, - _SPATH_GOLD, - _SPATH_VOID, - _SPATH_SCORE, - NULL, -}; - -char *monsterfile="monsters.asc"; - int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char **argv) { - char **filename; /* for pointing to file names */ - register int fd; /* file descriptor */ + const char **filename; /* for pointing to file names */ + int fd; /* file descriptor */ FILE *fp; /* for opening files */ struct stat fbuf; /* for getting files statistics */ int ch; @@ -227,8 +230,7 @@ main(argc, argv) *************************************************************************/ void -Error(str, file) -char *str, *file; +Error(const char *str, const char *file) { fprintf(stderr, "Error: "); fprintf(stderr, str, file); @@ -236,34 +238,3 @@ char *str, *file; exit(1); /*NOTREACHED*/ } -/* */ -/************************************************************************ -/ -/ FUNCTION NAME: drandom() -/ -/ FUNCTION: return a random number -/ -/ AUTHOR: E. A. Estes, 2/7/86 -/ -/ ARGUMENTS: none -/ -/ RETURN VALUE: none -/ -/ MODULES CALLED: random() -/ -/ GLOBAL INPUTS: none -/ -/ GLOBAL OUTPUTS: none -/ -/ DESCRIPTION: -/ -*************************************************************************/ - -double -drandom() -{ - if (sizeof(int) != 2) - return((double) (random() & 0x7fff) / 32768.0); - else - return((double) random() / 32768.0); -} -- 2.41.0