]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - phantasia/misc.c
cgram(6): use standard cursor keys, use standard shuffle algorithm
[bsdgames-darwin.git] / phantasia / misc.c
index 850b51ee50df31d3a7877df44bb0863b14d47e70..180d6137337ad8a075cf7ef1666377a1242e1782 100644 (file)
@@ -1,16 +1,32 @@
-/*     $NetBSD: misc.c,v 1.12 2004/04/11 13:35:06 he Exp $     */
+/*     $NetBSD: misc.c,v 1.22 2019/02/03 03:19:25 mrg Exp $    */
 
 /*
  * misc.c  Phantasia miscellaneous support routines
  */
 
-#include "include.h"
+#include <errno.h>
+#include <math.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "macros.h"
+#include "phantdefs.h"
+#include "phantstruct.h"
+#include "phantglobs.h"
+#include "pathnames.h"
+
 #undef bool
 #include <curses.h>
 
 
-void
-movelevel()
+static double explevel(double);
+
+static void
+movelevel(void)
 {
        const struct charstats *statptr; /* for pointing into Stattable */
        double  new;            /* new level */
@@ -63,9 +79,7 @@ movelevel()
 }
 
 const char   *
-descrlocation(playerp, shortflag)
-       struct player *playerp;
-       bool    shortflag;
+descrlocation(struct player *playerp, phbool shortflag)
 {
        double  circle;         /* corresponding circle for coordinates */
        int     quadrant;       /* quandrant of grid */
@@ -135,15 +149,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 */
@@ -400,7 +416,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",
@@ -412,7 +428,7 @@ displaystats()
 }
 
 void
-allstatslist()
+allstatslist(void)
 {
        static const char *const flags[] = /* to print value of some bools */
        {
@@ -445,9 +461,7 @@ allstatslist()
 }
 
 const char   *
-descrtype(playerp, shortflag)
-       struct player *playerp;
-       bool    shortflag;
+descrtype(struct player *playerp, phbool shortflag)
 {
        int     type;           /* for caluculating result subscript */
        static const char *const results[] =/* description table */
@@ -509,9 +523,7 @@ descrtype(playerp, shortflag)
 }
 
 long
-findname(name, playerp)
-       const char   *name;
-       struct player *playerp;
+findname(const char *name, struct player *playerp)
 {
        long    loc = 0;        /* location in the file */
 
@@ -529,7 +541,7 @@ findname(name, playerp)
 }
 
 long
-allocrecord()
+allocrecord(void)
 {
        long    loc = 0L;       /* location in file */
 
@@ -551,9 +563,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;
@@ -561,7 +571,7 @@ freerecord(playerp, loc)
 }
 
 void
-leavegame()
+leavegame(void)
 {
 
        if (Player.p_level < 1.0)
@@ -577,8 +587,7 @@ leavegame()
 }
 
 void
-death(how)
-       const char   *how;
+death(const char *how)
 {
        FILE   *fp;             /* for updating various files */
        int     ch;             /* input */
@@ -673,7 +682,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 */
        }
@@ -682,18 +691,15 @@ death(how)
 }
 
 void
-writerecord(playerp, place)
-       struct player *playerp;
-       long    place;
+writerecord(struct player *playerp, long place)
 {
        fseek(Playersfp, place, SEEK_SET);
        fwrite((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
        fflush(Playersfp);
 }
 
-double
-explevel(experience)
-       double  experience;
+static double
+explevel(double experience)
 {
        if (experience < 1.1e7)
                return (floor(pow((experience / 1000.0), 0.4875)));
@@ -702,8 +708,7 @@ explevel(experience)
 }
 
 void
-truncstring(string)
-       char   *string;
+truncstring(char *string)
 {
        int     length;         /* length of string */
 
@@ -713,10 +718,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 */
@@ -727,6 +729,7 @@ altercoordinates(xnew, ynew, operation)
                ynew = Player.p_y - ROLL(1.0, 5.0);
                /* fall through for check */
 
+               /* FALLTHROUGH */
        case A_SPECIFIC:        /* just move player */
                if (Beyond && fabs(xnew) < D_BEYOND && fabs(ynew) < D_BEYOND)
                        /*
@@ -766,16 +769,14 @@ altercoordinates(xnew, ynew, operation)
 }
 
 void
-readrecord(playerp, loc)
-       struct player *playerp;
-       long    loc;
+readrecord(struct player *playerp, long loc)
 {
        fseek(Playersfp, loc, SEEK_SET);
        fread((char *) playerp, SZ_PLAYERSTRUCT, 1, Playersfp);
 }
 
 void
-adjuststats()
+adjuststats(void)
 {
        double  dtemp;          /* for temporary calculations */
 
@@ -866,8 +867,7 @@ adjuststats()
 }
 
 void
-initplayer(playerp)
-       struct player *playerp;
+initplayer(struct player *playerp)
 {
        playerp->p_experience =
            playerp->p_level =
@@ -926,7 +926,7 @@ initplayer(playerp)
 }
 
 void
-readmessage()
+readmessage(void)
 {
        move(3, 0);
        clrtoeol();
@@ -936,8 +936,7 @@ readmessage()
 }
 
 void
-error(whichfile)
-       const char   *whichfile;
+error(const char *whichfile)
 {
        int     (*funcp)(const char *,...);
 
@@ -954,19 +953,17 @@ 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));
 }
 
 void
-ill_sig(whichsig)
-       int     whichsig;
+ill_sig(int whichsig)
 {
        clear();
        if (!(whichsig == SIGINT || whichsig == SIGQUIT))
@@ -976,8 +973,7 @@ ill_sig(whichsig)
 }
 
 const char *
-descrstatus(playerp)
-       struct player *playerp;
+descrstatus(struct player *playerp)
 {
        switch (playerp->p_status) {
        case S_PLAYING:
@@ -1013,7 +1009,7 @@ descrstatus(playerp)
 }
 
 double
-drandom()
+drandom(void)
 {
        if (sizeof(int) != 2)
                /* use only low bits */
@@ -1023,9 +1019,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 */