]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - phantasia/misc.c
sprinkle static and prune some dead code
[bsdgames-darwin.git] / phantasia / misc.c
index f741d7f159aab17c9a094abae6a51d2989afaef6..881f4cc4f3eca461cf940964b09cdc49b3b7fb42 100644 (file)
@@ -1,16 +1,18 @@
-/*     $NetBSD: misc.c,v 1.3 1997/10/13 02:18:30 lukem Exp $   */
+/*     $NetBSD: misc.c,v 1.17 2009/05/25 23:14:33 dholland Exp $       */
 
 /*
  * misc.c  Phantasia miscellaneous support routines
  */
 
 #include "include.h"
+#undef bool
+#include <curses.h>
 
 
 void
-movelevel()
+movelevel(void)
 {
-       struct charstats *statptr;      /* for pointing into Stattable */
+       const struct charstats *statptr; /* for pointing into Stattable */
        double  new;            /* new level */
        double  inc;            /* increment between new and old levels */
 
@@ -60,15 +62,13 @@ movelevel()
                death("Old age");
 }
 
-char   *
-descrlocation(playerp, shortflag)
-       struct player *playerp;
-       bool    shortflag;
+const char   *
+descrlocation(struct player *playerp, phbool 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 */
+       const char   *label;    /* pointer to place name */
+       static const char *const nametable[4][4] =      /* names of places */
        {
                {"Anorien", "Ithilien", "Rohan", "Lorien"},
                {"Gondor", "Mordor", "Dunland", "Rovanion"},
@@ -133,15 +133,17 @@ descrlocation(playerp, shortflag)
                                                        }
 
        if (shortflag)
-               sprintf(Databuf, "%.29s", label);
+               snprintf(Databuf, SZ_DATABUF, "%.29s", label);
        else
-               sprintf(Databuf, " is in %s  (%.0f,%.0f)", label, playerp->p_x, playerp->p_y);
+               snprintf(Databuf, SZ_DATABUF, 
+                       " is in %s  (%.0f,%.0f)",
+                       label, playerp->p_x, playerp->p_y);
 
        return (Databuf);
 }
 
 void
-tradingpost()
+tradingpost(void)
 {
        double  numitems;       /* number of items to purchase */
        double  cost;           /* cost of purchase */
@@ -343,7 +345,7 @@ tradingpost()
                                        printw("A blessing requires a %.0f gp donation.  Still want one ? ", blessingcost);
                                        ch = getanswer("NY", FALSE);
 
-                                       if (ch == 'Y')
+                                       if (ch == 'Y') {
                                                if (Player.p_gold < blessingcost)
                                                        ++cheat;
                                                else {
@@ -354,6 +356,7 @@ tradingpost()
                                                        else
                                                                Player.p_blessing = TRUE;
                                                }
+                                       }
                                        break;
                                }
                        break;
@@ -397,7 +400,7 @@ tradingpost()
 }
 
 void
-displaystats()
+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",
@@ -409,9 +412,9 @@ displaystats()
 }
 
 void
-allstatslist()
+allstatslist(void)
 {
-       static char *flags[] =  /* to print value of some bools */
+       static const char *const flags[] = /* to print value of some bools */
        {
                "False",
                " True"
@@ -425,7 +428,7 @@ allstatslist()
        mvprintw(13, 0, "Sin       : %9.5f", Player.p_sin);
        mvprintw(14, 0, "Poison    : %9.5f", Player.p_poison);
        mvprintw(15, 0, "Gems      : %9.0f", Player.p_gems);
-       mvprintw(16, 0, "Age       : %9d", Player.p_age);
+       mvprintw(16, 0, "Age       : %9ld", Player.p_age);
        mvprintw(10, 40, "Holy Water: %9d", Player.p_holywater);
        mvprintw(11, 40, "Amulets   : %9d", Player.p_amulets);
        mvprintw(12, 40, "Charms    : %9d", Player.p_charms);
@@ -441,13 +444,11 @@ allstatslist()
            flags[(int)Player.p_palantir]);
 }
 
-char   *
-descrtype(playerp, shortflag)
-       struct player *playerp;
-       bool    shortflag;
+const char   *
+descrtype(struct player *playerp, phbool shortflag)
 {
        int     type;           /* for caluculating result subscript */
-       static char *results[] =/* description table */
+       static const char *const results[] =/* description table */
        {
                " Magic User", " MU",
                " Fighter", " F ",
@@ -506,13 +507,11 @@ descrtype(playerp, shortflag)
 }
 
 long
-findname(name, playerp)
-       char   *name;
-       struct player *playerp;
+findname(const char *name, struct player *playerp)
 {
        long    loc = 0;        /* location in the file */
 
-       fseek(Playersfp, 0L, 0);
+       fseek(Playersfp, 0L, SEEK_SET);
        while (fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
                if (strcmp(playerp->p_name, name) == 0) {
                        if (playerp->p_status != S_NOTUSED || Wizard)
@@ -526,11 +525,11 @@ findname(name, playerp)
 }
 
 long
-allocrecord()
+allocrecord(void)
 {
        long    loc = 0L;       /* location in file */
 
-       fseek(Playersfp, 0L, 0);
+       fseek(Playersfp, 0L, SEEK_SET);
        while (fread((char *) &Other, SZ_PLAYERSTRUCT, 1, Playersfp) == 1) {
                if (Other.p_status == S_NOTUSED)
                        /* found an empty record */
@@ -548,9 +547,7 @@ allocrecord()
 }
 
 void
-freerecord(playerp, loc)
-       struct player *playerp;
-       long    loc;
+freerecord(struct player *playerp, long loc)
 {
        playerp->p_name[0] = CH_MARKDELETE;
        playerp->p_status = S_NOTUSED;
@@ -558,7 +555,7 @@ freerecord(playerp, loc)
 }
 
 void
-leavegame()
+leavegame(void)
 {
 
        if (Player.p_level < 1.0)
@@ -574,12 +571,11 @@ leavegame()
 }
 
 void
-death(how)
-       char   *how;
+death(const char *how)
 {
        FILE   *fp;             /* for updating various files */
        int     ch;             /* input */
-       static char *deathmesg[] =
+       static const char *const deathmesg[] =
        /* add more messages here, if desired */
        {
                "You have been wounded beyond repair.  ",
@@ -637,10 +633,10 @@ death(how)
                                                {
                                                        mvaddstr(4, 0,
                                                            "Your ring has taken control of you and turned you into a monster!\n");
-                                                       fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0);
+                                                       fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, SEEK_SET);
                                                        fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
                                                        strcpy(Curmonster.m_name, Player.p_name);
-                                                       fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, 0);
+                                                       fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, SEEK_SET);
                                                        fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
                                                        fflush(Monstfp);
                                                }
@@ -670,7 +666,7 @@ death(how)
        if (ch == 'Y') {
                cleanup(FALSE);
                execl(_PATH_GAMEPROG, "phantasia", "-s",
-                   (Wizard ? "-S" : (char *) NULL), 0);
+                   (Wizard ? "-S" : (char *) NULL), (char *) NULL);
                exit(0);
                /* NOTREACHED */
        }
@@ -679,18 +675,15 @@ death(how)
 }
 
 void
-writerecord(playerp, place)
-       struct player *playerp;
-       long    place;
+writerecord(struct player *playerp, long place)
 {
-       fseek(Playersfp, place, 0);
+       fseek(Playersfp, place, SEEK_SET);
        fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
        fflush(Playersfp);
 }
 
 double
-explevel(experience)
-       double  experience;
+explevel(double experience)
 {
        if (experience < 1.1e7)
                return (floor(pow((experience / 1000.0), 0.4875)));
@@ -699,8 +692,7 @@ explevel(experience)
 }
 
 void
-truncstring(string)
-       char   *string;
+truncstring(char *string)
 {
        int     length;         /* length of string */
 
@@ -710,10 +702,7 @@ truncstring(string)
 }
 
 void
-altercoordinates(xnew, ynew, operation)
-       double  xnew;
-       double  ynew;
-       int     operation;
+altercoordinates(double xnew, double ynew, int operation)
 {
        switch (operation) {
        case A_FORCED:          /* move with no checks */
@@ -763,16 +752,14 @@ altercoordinates(xnew, ynew, operation)
 }
 
 void
-readrecord(playerp, loc)
-       struct player *playerp;
-       long    loc;
+readrecord(struct player *playerp, long loc)
 {
-       fseek(Playersfp, loc, 0);
+       fseek(Playersfp, loc, SEEK_SET);
        fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
 }
 
 void
-adjuststats()
+adjuststats(void)
 {
        double  dtemp;          /* for temporary calculations */
 
@@ -789,7 +776,7 @@ adjuststats()
 
        /* calculate effective quickness */
        dtemp = ((Player.p_gold + Player.p_gems / 2.0) - 1000.0) / Statptr->c_goldtote
-           - Player.p_level;;
+           - Player.p_level;
        dtemp = MAX(0.0, dtemp);/* gold slows player down */
        Player.p_speed = Player.p_quickness + Player.p_quksilver - dtemp;
 
@@ -863,8 +850,7 @@ adjuststats()
 }
 
 void
-initplayer(playerp)
-       struct player *playerp;
+initplayer(struct player *playerp)
 {
        playerp->p_experience =
            playerp->p_level =
@@ -923,20 +909,19 @@ initplayer(playerp)
 }
 
 void
-readmessage()
+readmessage(void)
 {
        move(3, 0);
        clrtoeol();
-       fseek(Messagefp, 0L, 0);
+       fseek(Messagefp, 0L, SEEK_SET);
        if (fgets(Databuf, SZ_DATABUF, Messagefp) != NULL)
                addstr(Databuf);
 }
 
 void
-error(whichfile)
-       char   *whichfile;
+error(const char *whichfile)
 {
-       int     (*funcp) __P((const char *,...));
+       int     (*funcp)(const char *,...);
 
        if (Windows) {
                funcp = printw;
@@ -944,26 +929,24 @@ error(whichfile)
        } else
                funcp = printf;
 
-       (*funcp) ("An unrecoverable error has occurred reading %s.  (errno = %d)\n", whichfile, errno);
+       (*funcp) ("An unrecoverable error has occurred reading %s.  (%s)\n", whichfile, strerror(errno));
        (*funcp) ("Please run 'setup' to determine the problem.\n");
        cleanup(TRUE);
        /* NOTREACHED */
 }
 
 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));
 }
 
 void
-ill_sig(whichsig)
-       int     whichsig;
+ill_sig(int whichsig)
 {
        clear();
        if (!(whichsig == SIGINT || whichsig == SIGQUIT))
@@ -972,9 +955,8 @@ ill_sig(whichsig)
        /* NOTREACHED */
 }
 
-char *
-descrstatus(playerp)
-       struct player *playerp;
+const char *
+descrstatus(struct player *playerp)
 {
        switch (playerp->p_status) {
        case S_PLAYING:
@@ -1010,7 +992,7 @@ descrstatus(playerp)
 }
 
 double
-drandom()
+drandom(void)
 {
        if (sizeof(int) != 2)
                /* use only low bits */
@@ -1020,9 +1002,7 @@ drandom()
 }
 
 void
-collecttaxes(gold, gems)
-       double  gold;
-       double  gems;
+collecttaxes(double gold, double gems)
 {
        FILE   *fp;             /* to update Goldfile */
        double  dtemp;          /* for temporary calculations */
@@ -1063,7 +1043,7 @@ collecttaxes(gold, gems)
                dtemp = 0.0;
                fread((char *) &dtemp, sizeof(double), 1, fp);
                dtemp += floor(taxes);
-               fseek(fp, 0L, 0);
+               fseek(fp, 0L, SEEK_SET);
                fwrite((char *) &dtemp, sizeof(double), 1, fp);
                fclose(fp);
        }