-/* $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 */
}
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 */
}
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 */
}
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",
}
void
-allstatslist()
+allstatslist(void)
{
static const char *const flags[] = /* to print value of some bools */
{
}
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 */
}
long
-findname(name, playerp)
- const char *name;
- struct player *playerp;
+findname(const char *name, struct player *playerp)
{
long loc = 0; /* location in the file */
}
long
-allocrecord()
+allocrecord(void)
{
long loc = 0L; /* location in file */
}
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;
}
void
-leavegame()
+leavegame(void)
{
if (Player.p_level < 1.0)
}
void
-death(how)
- const char *how;
+death(const char *how)
{
FILE *fp; /* for updating various files */
int ch; /* input */
if (ch == 'Y') {
cleanup(FALSE);
execl(_PATH_GAMEPROG, "phantasia", "-s",
- (Wizard ? "-S" : (char *) NULL), 0);
+ (Wizard ? "-S" : (char *) NULL), (char *) NULL);
exit(0);
/* NOTREACHED */
}
}
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)));
}
void
-truncstring(string)
- char *string;
+truncstring(char *string)
{
int length; /* length of 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 */
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)
/*
}
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 */
}
void
-initplayer(playerp)
- struct player *playerp;
+initplayer(struct player *playerp)
{
playerp->p_experience =
playerp->p_level =
}
void
-readmessage()
+readmessage(void)
{
move(3, 0);
clrtoeol();
}
void
-error(whichfile)
- const char *whichfile;
+error(const char *whichfile)
{
int (*funcp)(const char *,...);
}
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))
}
const char *
-descrstatus(playerp)
- struct player *playerp;
+descrstatus(struct player *playerp)
{
switch (playerp->p_status) {
case S_PLAYING:
}
double
-drandom()
+drandom(void)
{
if (sizeof(int) != 2)
/* use only low bits */
}
void
-collecttaxes(gold, gems)
- double gold;
- double gems;
+collecttaxes(double gold, double gems)
{
FILE *fp; /* to update Goldfile */
double dtemp; /* for temporary calculations */