ANSI function declarations.
Staticize functions.
Rename local variables that shadow globals.
Use string functions from libc instead of creating our own.
Remove void casts for unchecked function returns.
Spell parameter correctly.
Don't try to return a value from void functions.
Remove compat library requirement (gtty -> ioctl).
Add new function "dowarp" that calls warp() from play.c. (Taken from
NetBSD).
Change chars that are used for numeric values to shorts so they can be
properly used as array indexes.
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD: src/games/trek/Makefile,v 1.1.1.1.14.1 2001/04/25 09:29:03 ru Exp $
-# $DragonFly: src/games/trek/Makefile,v 1.2 2003/06/17 04:25:25 dillon Exp $
+# $DragonFly: src/games/trek/Makefile,v 1.3 2006/09/07 21:19:44 pavalos Exp $
PROG= trek
SRCS= abandon.c attack.c autover.c capture.c check_out.c checkcond.c \
shield.c snova.c srscan.c systemname.c torped.c utility.c \
visual.c warp.c win.c cgetc.c
MAN= trek.6
-DPADD= ${LIBM} ${LIBCOMPAT}
-LDADD= -lm -lcompat
+DPADD= ${LIBM}
+LDADD= -lm
HIDEGAME=hidegame
+WARNS?= 6
.include <bsd.prog.mk>
*
* @(#)abandon.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/abandon.c,v 1.4 1999/11/30 03:49:43 billf Exp $
- * $DragonFly: src/games/trek/abandon.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/abandon.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** Uses trace flag 40
*/
-abandon()
+void
+abandon(__unused int unused)
{
struct quad *q;
int i;
int j;
struct event *e;
- if (Ship.ship == QUEENE)
- return (printf("You may not abandon ye Faire Queene\n"));
+ if (Ship.ship == QUEENE) {
+ printf("You may not abandon ye Faire Queene\n");
+ return;
+ }
if (Ship.cond != DOCKED)
{
- if (damaged(SHUTTLE))
- return (out(SHUTTLE));
+ if (damaged(SHUTTLE)) {
+ out(SHUTTLE);
+ return;
+ }
printf("Officers escape in shuttlecraft\n");
/* decide on fate of crew */
q = &Quad[Ship.quadx][Ship.quady];
if (Sect[Ship.sectx][Ship.secty] == EMPTY)
{
Sect[Ship.sectx][Ship.secty] = QUEENE;
- dock();
+ dock(0);
compkldist(0);
return;
}
*
* @(#)attack.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/attack.c,v 1.4 1999/11/30 03:49:43 billf Exp $
- * $DragonFly: src/games/trek/attack.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/attack.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** Casualties can also occur.
*/
-attack(resting)
-int resting; /* set if attack while resting */
+void
+attack(int resting)
+/* resting: set if attack while resting */
{
int hit, i, l;
int maxhit, tothit, shldabsb;
*
* @(#)autover.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/autover.c,v 1.4 1999/11/30 03:49:43 billf Exp $
- * $DragonFly: src/games/trek/autover.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/autover.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** quadrants, since that is all that is needed.
*/
-autover()
+void
+autover(void)
{
double dist;
int course;
*
* @(#)capture.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/capture.c,v 1.4 1999/11/30 03:49:43 billf Exp $
- * $DragonFly: src/games/trek/capture.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/capture.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
+static struct kling *selectklingon(void);
+
/*
** Ask a Klingon To Surrender
**
** etc.
*/
-capture()
+void
+capture(__unused int unused)
{
int i;
struct kling *k;
double x;
- extern struct kling *selectklingon();
/* check for not cloaked */
if (Ship.cloaked)
** Cruddy, just takes one at random. Should ask the captain.
*/
-struct kling *selectklingon()
+static struct kling *
+selectklingon(void)
{
int i;
*
* @(#)cgetc.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/cgetc.c,v 1.2 1999/11/30 03:49:44 billf Exp $
- * $DragonFly: src/games/trek/cgetc.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/cgetc.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
-# include <stdio.h>
+# include "trek.h"
-char cgetc(i)
-int i;
+int
+cgetc(__unused int i)
{
return ( getchar() );
}
*
* @(#)check_out.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/check_out.c,v 1.4 1999/11/30 03:49:44 billf Exp $
- * $DragonFly: src/games/trek/check_out.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/check_out.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** It prints appropriate messages too.
*/
-check_out(device)
-int device;
+bool
+check_out(int device)
{
int dev;
*
* @(#)checkcond.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/checkcond.c,v 1.4 1999/11/30 03:49:44 billf Exp $
- * $DragonFly: src/games/trek/checkcond.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/checkcond.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** and battle conditions.
*/
-checkcond()
+void
+checkcond(void)
{
- int i, j;
-
/* see if we are still alive and well */
if (Ship.reserves < 0.0)
lose(L_NOLIFE);
*
* @(#)compkl.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/compkl.c,v 1.4 1999/11/30 03:49:44 billf Exp $
- * $DragonFly: src/games/trek/compkl.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/compkl.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
+static void sortkl(void);
+
/*
** compute klingon distances
**
** move.
*/
-compkldist(f)
-int f; /* set if new quadrant */
+void
+compkldist(bool f)
{
int i, dx, dy;
double d;
** bubble sort on ascending distance
*/
-sortkl()
+static void
+sortkl(void)
{
struct kling t;
int f, i, m;
*
* @(#)computer.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/computer.c,v 1.5 1999/11/30 03:49:45 billf Exp $
- * $DragonFly: src/games/trek/computer.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/computer.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
# include "getpar.h"
-# include <stdio.h>
+
+static int kalc(int, int, int, int, double *);
+static void prkalc(int, double);
+
/*
** On-Board Computer
**
struct cvntab Cputab[] =
{
- "ch", "art", (int (*)())1, 0,
- "t", "rajectory", (int (*)())2, 0,
- "c", "ourse", (int (*)())3, 0,
- "m", "ove", (int (*)())3, 1,
- "s", "core", (int (*)())4, 0,
- "p", "heff", (int (*)())5, 0,
- "w", "arpcost", (int (*)())6, 0,
- "i", "mpcost", (int (*)())7, 0,
- "d", "istresslist", (int (*)())8, 0,
- 0
+ { "ch", "art", (void (*)(int))1, 0 },
+ { "t", "rajectory", (void (*)(int))2, 0 },
+ { "c", "ourse", (void (*)(int))3, 0 },
+ { "m", "ove", (void (*)(int))3, 1 },
+ { "s", "core", (void (*)(int))4, 0 },
+ { "p", "heff", (void (*)(int))5, 0 },
+ { "w", "arpcost", (void (*)(int))6, 0 },
+ { "i", "mpcost", (void (*)(int))7, 0 },
+ { "d", "istresslist", (void (*)(int))8, 0 },
+ { NULL, NULL, NULL, 0 }
};
-computer()
+void
+computer(__unused int unused)
{
int ix, iy;
int i, j;
- int numout;
int tqx, tqy;
struct cvntab *r;
int cost;
int course;
- double dist, time;
+ double dist, p_time;
double warpfact;
struct quad *q;
struct event *e;
if (warpfact <= 0.0)
warpfact = Ship.warp;
cost = (dist + 0.05) * warpfact * warpfact * warpfact;
- time = Param.warptime * dist / (warpfact * warpfact);
+ p_time = Param.warptime * dist / (warpfact * warpfact);
printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
- warpfact, dist, time, cost, cost + cost);
+ warpfact, dist, p_time, cost, cost + cost);
break;
case 7: /* impulse cost */
if (dist < 0.0)
break;
cost = 20 + 100 * dist;
- time = dist / 0.095;
+ p_time = dist / 0.095;
printf("Distance %.2f cost %.2f stardates %d units\n",
- dist, time, cost);
+ dist, p_time, cost);
break;
case 8: /* distresslist */
** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
*/
-kalc(tqx, tqy, tsx, tsy, dist)
-int tqx;
-int tqy;
-int tsx;
-int tsy;
-double *dist;
+static int
+kalc(int tqx, int tqy, int tsx, int tsy, double *dist)
{
double dx, dy;
double quadsize;
return (course);
}
-
-prkalc(course, dist)
-int course;
-double dist;
+static void
+prkalc(int course, double dist)
{
printf(": course %d dist %.3f\n", course, dist);
}
*
* @(#)damage.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/damage.c,v 1.4 1999/11/30 03:49:45 billf Exp $
- * $DragonFly: src/games/trek/damage.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/damage.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** that the dock() and undock() have to reschedule the event.
*/
-damage(dev1, dam)
-int dev1; /* device index */
-double dam; /* time to repair */
+void
+damage(int dev1, double dam)
{
int i;
struct event *e;
*
* @(#)damaged.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/damaged.c,v 1.4 1999/11/30 03:49:45 billf Exp $
- * $DragonFly: src/games/trek/damaged.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/damaged.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** event list for a "device fix" action on that device.
*/
-damaged(dev)
-int dev;
+bool
+damaged(int dev)
{
int d;
struct event *e;
*
* @(#)dcrept.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/dcrept.c,v 1.4 1999/11/30 03:49:46 billf Exp $
- * $DragonFly: src/games/trek/dcrept.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/dcrept.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** fix things if you are docked.
*/
-dcrept()
+void
+dcrept(__unused int unused)
{
int i, f;
double x;
*
* @(#)destruct.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/destruct.c,v 1.4 1999/11/30 03:49:46 billf Exp $
- * $DragonFly: src/games/trek/destruct.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/destruct.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
/*
** Uses trace flag 41
*/
-destruct()
+void
+destruct(__unused int unused)
{
char checkpass[15];
int i, j;
double zap;
- if (damaged(COMPUTER))
- return (out(COMPUTER));
+ if (damaged(COMPUTER)) {
+ out(COMPUTER);
+ return;
+ }
printf("\n\07 --- WORKING ---\07\n");
sleep(3);
/* output the count 10 9 8 7 6 */
skiptonl(0);
getstrpar("Enter password verification", checkpass, 14, 0);
sleep(2);
- if (!sequal(checkpass, Game.passwd))
- return (printf("Self destruct sequence aborted\n"));
+ if (!sequal(checkpass, Game.passwd)) {
+ printf("Self destruct sequence aborted\n");
+ return;
+ }
printf("Password verified; self destruct sequence continues:\n");
sleep(2);
/* output count 5 4 3 2 1 0 */
*
* @(#)dock.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/dock.c,v 1.4 1999/11/30 03:49:46 billf Exp $
- * $DragonFly: src/games/trek/dock.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/dock.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** are docked.
*/
-dock()
+void
+dock(__unused int unused)
{
int i, j;
int ok;
struct event *e;
if (Ship.cond == DOCKED)
- return (printf("Chekov: But captain, we are already docked\n"));
+ {
+ printf("Chekov: But captain, we are already docked\n");
+ return;
+ }
/* check for ok to dock, i.e., adjacent to a starbase */
ok = 0;
for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++)
}
}
if (!ok)
- return (printf("Chekov: But captain, we are not adjacent to a starbase.\n"));
+ {
+ printf("Chekov: But captain, we are not adjacent to a starbase.\n");
+ return;
+ }
/* restore resources */
Ship.energy = Param.energy;
** is to reschedule any damages so that they will take longer.
*/
-undock()
+void
+undock(__unused int unused)
{
struct event *e;
int i;
*
* @(#)dumpgame.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/dumpgame.c,v 1.6 1999/11/30 03:49:46 billf Exp $
- * $DragonFly: src/games/trek/dumpgame.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/dumpgame.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
#include <fcntl.h>
struct dump Dump_template[] =
{
- (char *)&Ship, sizeof (Ship),
- (char *)&Now, sizeof (Now),
- (char *)&Param, sizeof (Param),
- (char *)&Etc, sizeof (Etc),
- (char *)&Game, sizeof (Game),
- (char *)Sect, sizeof (Sect),
- (char *)Quad, sizeof (Quad),
- (char *)&Move, sizeof (Move),
- (char *)Event, sizeof (Event),
- 0
+ { (char *)&Ship, sizeof (Ship) },
+ { (char *)&Now, sizeof (Now) },
+ { (char *)&Param, sizeof (Param) },
+ { (char *)&Etc, sizeof (Etc) },
+ { (char *)&Game, sizeof (Game) },
+ { (char *)Sect, sizeof (Sect) },
+ { (char *)Quad, sizeof (Quad) },
+ { (char *)&Move, sizeof (Move) },
+ { (char *)Event, sizeof (Event) },
+ { NULL, 0 }
};
+static bool readdump(int);
+
/*
** DUMP GAME
**
** output change.
*/
-dumpgame()
+void
+dumpgame(__unused int unused)
{
int version;
int fd;
struct dump *d;
int i;
- if ((fd = creat("trek.dump", 0644)) < 0)
- return (printf("cannot dump\n"));
+ if ((fd = creat("trek.dump", 0644)) < 0) {
+ printf("cannot dump\n");
+ return;
+ }
version = VERSION;
write(fd, &version, sizeof version);
** Return value is zero for success, one for failure.
*/
-restartgame()
+bool
+restartgame(void)
{
int fd;
int version;
** Returns zero for success, one for failure.
*/
-readdump(fd1)
-int fd1;
+static bool
+readdump(int fd1)
{
int fd;
struct dump *d;
*
* @(#)dumpme.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/dumpme.c,v 1.4 1999/11/30 03:49:47 billf Exp $
- * $DragonFly: src/games/trek/dumpme.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/dumpme.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** Repair of devices must be deferred.
*/
-dumpme(flag)
-int flag;
+void
+dumpme(int flag)
{
int f;
- double x;
+ double x = 0;
struct event *e;
int i;
*
* @(#)dumpssradio.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/dumpssradio.c,v 1.4 1999/11/30 03:49:47 billf Exp $
- * $DragonFly: src/games/trek/dumpssradio.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/dumpssradio.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** output hidden distress calls
**/
-dumpssradio()
+int
+dumpssradio(void)
{
struct event *e;
int j;
{
unschedule(e);
printf("Starsystem %s in quadrant %d,%d is no longer distressed\n",
- systemname(e), e->x, e->y);
+ systemname(&Quad[e->x][e->y]), e->x, e->y);
continue;
}
case E_ENSLV:
case E_REPRO:
printf("Starsystem %s in quadrant %d,%d is distressed\n",
- systemname(e), e->x, e->y);
+ systemname(&Quad[e->x][e->y]), e->x, e->y);
chkrest++;
break;
*
* @(#)events.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/events.c,v 1.4 1999/11/30 03:49:47 billf Exp $
- * $DragonFly: src/games/trek/events.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/events.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
/*
** and so on.
*/
-
-events(warp)
-int warp; /* set if called in a time warp */
+void
+events(int t_warp)
+/* t_warp: set if called in a time warp */
{
int i;
- int j;
+ int j = 0;
struct kling *k;
double rtime;
double xdate;
double idate;
- struct event *ev, *xsched(), *schedule();
+ struct event *ev = NULL;
+ char *s;
int ix, iy;
struct quad *q;
struct event *e;
if (Move.time <= 0.0)
{
Now.time = Now.resource / Now.klings;
- return (0);
+ return;
}
/* indicate that the cloaking device is now working */
case E_SNOVA: /* supernova */
/* cause the supernova to happen */
- snova(-1);
+ snova(-1, 0);
/* and schedule the next one */
xresched(e, E_SNOVA, 1);
break;
case E_SNAP: /* take a snapshot of the galaxy */
xresched(e, E_SNAP, 1);
- i = (int) Etc.snapshot;
- i = bmove(Quad, i, sizeof (Quad));
- i = bmove(Event, i, sizeof (Event));
- i = bmove(&Now, i, sizeof (Now));
+ s = Etc.snapshot;
+ s = bmove(Quad, s, sizeof (Quad));
+ s = bmove(Event, s, sizeof (Event));
+ s = bmove(&Now, s, sizeof (Now));
Game.snap = 1;
break;
}
/* unschedule an attack during a rest period */
- if (e = Now.eventptr[E_ATTACK])
+ if ((e = Now.eventptr[E_ATTACK]))
unschedule(e);
- if (!warp)
+ if (!t_warp)
{
/* eat up energy if cloaked */
if (Ship.cloaked)
if (damaged(LIFESUP) && Ship.cond != DOCKED)
Ship.reserves -= Move.time;
}
- return (0);
+ return;
}
*
* @(#)externs.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/externs.c,v 1.2 1999/11/30 03:49:47 billf Exp $
- * $DragonFly: src/games/trek/externs.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/externs.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
struct device Device[NDEV] =
{
- "warp drive", "Scotty",
- "S.R. scanners", "Scotty",
- "L.R. scanners", "Scotty",
- "phasers", "Sulu",
- "photon tubes", "Sulu",
- "impulse engines", "Scotty",
- "shield control", "Sulu",
- "computer", "Spock",
- "subspace radio", "Uhura",
- "life support", "Scotty",
- "navigation system", "Chekov",
- "cloaking device", "Scotty",
- "transporter", "Scotty",
- "shuttlecraft", "Scotty",
- "*ERR 14*", "Nobody",
- "*ERR 15*", "Nobody"
+ { "warp drive", "Scotty" },
+ { "S.R. scanners", "Scotty" },
+ { "L.R. scanners", "Scotty" },
+ { "phasers", "Sulu" },
+ { "photon tubes", "Sulu" },
+ { "impulse engines", "Scotty" },
+ { "shield control", "Sulu" },
+ { "computer", "Spock" },
+ { "subspace radio", "Uhura" },
+ { "life support", "Scotty" },
+ { "navigation system", "Chekov" },
+ { "cloaking device", "Scotty" },
+ { "transporter", "Scotty" },
+ { "shuttlecraft", "Scotty" },
+ { "*ERR 14*", "Nobody" },
+ { "*ERR 15*", "Nobody" }
};
-char *Systemname[NINHAB] =
+const char *Systemname[NINHAB] =
{
"ERROR",
"Talos IV",
*
* @(#)getcodi.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/getcodi.c,v 1.2 1999/11/30 03:49:48 billf Exp $
- * $DragonFly: src/games/trek/getcodi.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/getcodi.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "getpar.h"
+# include "trek.h"
/*
** get course and distance
** (meaning to drop the request).
*/
-getcodi(co, di)
-int *co;
-double *di;
+bool
+getcodi(int *co, double *di)
{
*co = getintpar("Course");
*
* @(#)getpar.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/getpar.c,v 1.5 1999/11/30 03:49:48 billf Exp $
- * $DragonFly: src/games/trek/getpar.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/getpar.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
-# include <stdio.h>
# include "getpar.h"
+# include "trek.h"
+
+static bool testterm(void);
/**
** get integer parameter
**/
-getintpar(s)
-char *s;
+int
+getintpar(const char *s)
{
int i;
int n;
** get floating parameter
**/
-double getfltpar(s)
-char *s;
+double
+getfltpar(const char *s)
{
int i;
double d;
struct cvntab Yntab[] =
{
- "y", "es", (int (*)())1, 0,
- "n", "o", (int (*)())0, 0,
- 0
+ { "y", "es", (void (*)(int))1, 0 },
+ { "n", "o", (void (*)(int))0, 0 },
+ { NULL, NULL, NULL, 0 }
};
-getynpar(s)
-char *s;
+long
+getynpar(const char *s)
{
struct cvntab *r;
** get coded parameter
**/
-struct cvntab *getcodpar(s, tab)
-char *s;
-struct cvntab tab[];
+struct cvntab *
+getcodpar(const char *s, struct cvntab tab[])
{
char input[100];
struct cvntab *r;
int flag;
- char *p, *q;
+ char *p;
+ const char *q;
int c;
int f;
c = 4;
for (r = tab; r->abrev; r++)
{
- concat(r->abrev, r->full, input);
+ strcpy(input, r->abrev);
+ strcat(input, r->full);
printf("%14.14s", input);
if (--c > 0)
continue;
** get string parameter
**/
-getstrpar(s, r, l, t)
-char *s;
-char *r;
-int l;
-char *t;
+void
+getstrpar(const char *s, char *r, int l, const char *t)
{
int i;
char format[20];
if (t == 0)
t = " \t\n;";
- (void)sprintf(format, "%%%d[^%s]", l, t);
+ sprintf(format, "%%%d[^%s]", l, t);
while (1)
{
if ((f = testnl()) && s)
** test if newline is next valid character
**/
-testnl()
+bool
+testnl(void)
{
char c;
** scan for newline
**/
-skiptonl(c)
-char c;
+void
+skiptonl(char c)
{
while (c != '\n')
if (!(c = cgetc(0)))
** test for valid terminator
**/
-testterm()
+static bool
+testterm(void)
{
char c;
** zero is returned.
*/
-readdelim(d)
-char d;
+bool
+readdelim(char d)
{
char c;
- while (c = cgetc(0))
+ while ((c = cgetc(0)))
{
if (c == d)
return (1);
* SUCH DAMAGE.
*
* @(#)getpar.h 8.1 (Berkeley) 5/31/93
+ * $DragonFly: src/games/trek/getpar.h,v 1.2 2006/09/07 21:19:44 pavalos Exp $
*/
-struct cvntab /* used for getcodpar() paramater list */
+#include <stdbool.h>
+
+struct cvntab /* used for getcodpar() parameter list */
{
- char *abrev;
- char *full;
- int (*value)();
+ const char *abrev;
+ const char *full;
+ void (*value)(int);
int value2;
};
-extern double getfltpar();
-extern struct cvntab *getcodpar();
+extern struct cvntab Lentab[];
+extern struct cvntab Skitab[];
+
+int getintpar(const char *);
+double getfltpar(const char *);
+long getynpar(const char *);
+struct cvntab *getcodpar(const char *, struct cvntab *);
+void getstrpar(const char *, char *, int, const char *);
+bool testnl(void);
+void skiptonl(char);
+bool readdelim(char);
*
* @(#)help.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/help.c,v 1.4 1999/11/30 03:49:48 billf Exp $
- * $DragonFly: src/games/trek/help.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/help.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** to drop you. After that, it's your problem.
*/
-char *Cntvect[3] =
+const char *Cntvect[3] =
{"first", "second", "third"};
-help()
+void
+help(__unused int unused)
{
int i;
double dist, x;
int dx, dy;
- int j, l;
+ int j, l = 0;
/* check to see if calling for help is reasonable ... */
- if (Ship.cond == DOCKED)
- return (printf("Uhura: But Captain, we're already docked\n"));
-
+ if (Ship.cond == DOCKED) {
+ printf("Uhura: But Captain, we're already docked\n");
+ return;
+ }
/* or possible */
- if (damaged(SSRADIO))
- return (out(SSRADIO));
- if (Now.bases <= 0)
- return (printf("Uhura: I'm not getting any response from starbase\n"));
-
+ if (damaged(SSRADIO)) {
+ out(SSRADIO);
+ return;
+ }
+ if (Now.bases <= 0) {
+ printf("Uhura: I'm not getting any response from starbase\n");
+ return;
+ }
/* tut tut, there goes the score */
Game.helps += 1;
Ship.sectx = dx;
Ship.secty = dy;
Sect[dx][dy] = Ship.ship;
- dock();
+ dock(0);
compkldist(0);
return;
}
*
* @(#)impulse.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/impulse.c,v 1.4 1999/11/30 03:49:48 billf Exp $
- * $DragonFly: src/games/trek/impulse.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/impulse.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
/**
** move under impulse power
**/
-impulse()
+void
+impulse(__unused int unused)
{
int course;
int power;
- double dist, time;
+ double dist, p_time;
int percent;
- extern double move();
- if (Ship.cond == DOCKED)
- return (printf("Scotty: Sorry captain, but we are still docked.\n"));
- if (damaged(IMPULSE))
- return (out(IMPULSE));
+ if (Ship.cond == DOCKED) {
+ printf("Scotty: Sorry captain, but we are still docked.\n");
+ return;
+ }
+ if (damaged(IMPULSE)) {
+ out(IMPULSE);
+ return;
+ }
if (getcodi(&course, &dist))
return;
power = 20 + 100 * dist;
return;
printf("Aye aye, sir\n");
}
- time = dist / 0.095;
- percent = 100 * time / Now.time + 0.5;
+ p_time = dist / 0.095;
+ percent = 100 * p_time / Now.time + 0.5;
if (percent >= 85)
{
printf("Spock: That would take %d%% of our remaining time.\n",
return;
printf("(He's finally gone mad)\n");
}
- Move.time = move(0, course, time, 0.095);
+ Move.time = move(0, course, p_time, 0.095);
Ship.energy -= 20 + 100 * Move.time * 0.095;
}
*
* @(#)initquad.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/initquad.c,v 1.4 1999/11/30 03:49:49 billf Exp $
- * $DragonFly: src/games/trek/initquad.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/initquad.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** to be docked, i.e., abandon() and help().
*/
-initquad(f)
-int f;
+void
+initquad(int f)
{
int i, j;
int rx, ry;
Move.newquad = 1;
}
-
-sector(x, y)
-int *x, *y;
+void
+sector(int *x, int *y)
{
int i, j;
*
* @(#)kill.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/kill.c,v 1.4 1999/11/30 03:49:49 billf Exp $
- * $DragonFly: src/games/trek/kill.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/kill.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** and the game is won if that was the last klingon.
*/
-killk(ix, iy)
-int ix, iy;
+void
+killk(int ix, int iy)
{
- int i, j;
+ int i;
printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy);
** handle a starbase's death
*/
-killb(qx, qy)
-int qx, qy;
+void
+killb(int qx, int qy)
{
struct quad *q;
struct xy *b;
if (q->bases <= 0)
return;
if (!damaged(SSRADIO))
+ {
/* then update starchart */
if (q->scanned < 1000)
q->scanned -= 10;
else
if (q->scanned > 1000)
q->scanned = -1;
+ }
q->bases = 0;
Now.bases -= 1;
for (b = Now.base; ; b++)
{
Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
if (Ship.cond == DOCKED)
- undock();
+ undock(0);
printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y);
}
else
** kill an inhabited starsystem
**/
-kills(x, y, f)
-int x, y; /* quad coords if f == 0, else sector coords */
-int f; /* f != 0 -- this quad; f < 0 -- Enterprise's fault */
+void
+kills(int x, int y, int f)
+/* x,y: quad coords if f == 0, else sector coords */
+/* f != 0 -- this quad; f < 0 -- Enterprise's fault */
{
struct quad *q;
struct event *e;
- char *name;
- char *systemname();
+ const char *name;
if (f)
{
** "kill" a distress call
**/
-killd(x, y, f)
-int x, y; /* quadrant coordinates */
-int f; /* set if user is to be informed */
+void
+killd(int x, int y, int f)
+/* x,y: quadrant coordinates */
+/* f: set if user is to be informed */
{
struct event *e;
int i;
*
* @(#)klmove.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/klmove.c,v 1.4 1999/11/30 03:49:49 billf Exp $
- * $DragonFly: src/games/trek/klmove.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/klmove.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** course around stars.
*/
-klmove(fl)
-int fl;
+void
+klmove(int fl)
{
int n;
struct kling *k;
*
* @(#)lose.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/lose.c,v 1.2 1999/11/30 03:49:49 billf Exp $
- * $DragonFly: src/games/trek/lose.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/lose.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
-# include <setjmp.h>
/*
** PRINT OUT LOSER MESSAGES
** actions which need be taken are taken.
*/
-char *Losemsg[] =
+const char *Losemsg[] =
{
"You ran out of time",
"You ran out of energy",
"Your last crew member died",
};
-lose(why)
-int why;
+void
+lose(int why)
{
- extern jmp_buf env;
-
Game.killed = 1;
sleep(1);
printf("\n%s\n", Losemsg[why - 1]);
*
* @(#)lrscan.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/lrscan.c,v 1.4 1999/11/30 03:49:50 billf Exp $
- * $DragonFly: src/games/trek/lrscan.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/lrscan.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** for future use by the "chart" option of the computer.
*/
-lrscan()
+void
+lrscan(__unused int unused)
{
int i, j;
struct quad *q;
* @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved.
* @(#)main.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/main.c,v 1.7.2.1 2001/03/05 12:11:14 kris Exp $
- * $DragonFly: src/games/trek/main.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/main.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
-# include <stdio.h>
# include <sgtty.h>
-# include <setjmp.h>
-# include <stdlib.h>
# define PRIO 00 /* default priority */
-int Mother = 51 + (51 << 8);
+unsigned int Mother = 51 + (51 << 8);
/*
** #### ##### # #### ##### #### ##### # #
jmp_buf env;
-main(argc, argv)
-int argc;
-char **argv;
+int
+main(int argc, char **argv)
{
/* extern FILE *f_log; */
char opencode;
srandomdev();
opencode = 'w';
prio = PRIO;
- if (gtty(1, &argp) == 0)
+ if (ioctl(1, TIOCGETP, &argp) == 0)
{
if ((argp.sg_ispeed ) < B1200)
Etc.fast++;
} while (getynpar("Another game"));
fflush(stdout);
+ return(0);
}
*
* @(#)move.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/move.c,v 1.6 1999/11/30 03:49:50 billf Exp $
- * $DragonFly: src/games/trek/move.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/move.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** Klingons, etc. This is passed from warp(), which gets it from
** either play() or ram(). Course is the course (0 -> 360) at
** which we want to move. `Speed' is the speed we
-** want to go, and `time' is the expected time. It
+** want to go, and `p_time' is the expected time. It
** can get cut short if a long range tractor beam is to occur. We
** cut short the move so that the user doesn't get docked time and
** energy for distance which he didn't travel.
** Uses trace flag 4.
*/
-double move(ramflag, course, time, speed)
-int ramflag;
-int course;
-double time;
-double speed;
+double
+move(int ramflag, int course, double p_time, double speed)
{
double angle;
double x, y, dx, dy;
double xn;
double evtime;
+ ix = iy = 0;
# ifdef xTRACE
if (Trace)
printf("move: ramflag %d course %d time %.2f speed %.2f\n",
- ramflag, course, time, speed);
+ ramflag, course, p_time, speed);
# endif
sectsize = NSECTS;
/* initialize delta factors for move */
Now.eventptr[E_LRTB]->evcode,
Now.eventptr[E_LRTB]->date, evtime);
# endif
- if (time > evtime && Etc.nkling < 3)
+ if (p_time > evtime && Etc.nkling < 3)
{
/* then we got a LRTB */
evtime += 0.005;
- time = evtime;
+ p_time = evtime;
}
else
evtime = -1.0e50;
- dist = time * speed;
+ dist = p_time * speed;
/* move within quadrant */
Sect[Ship.sectx][Ship.secty] = EMPTY;
dx = Ship.sectx - ix;
dy = Ship.secty - iy;
dist = sqrt(dx * dx + dy * dy) / NSECTS;
- time = dist / speed;
- if (evtime > time)
- time = evtime; /* spring the LRTB trap */
+ p_time = dist / speed;
+ if (evtime > p_time)
+ p_time = evtime; /* spring the LRTB trap */
Ship.sectx = ix;
Ship.secty = iy;
}
Sect[Ship.sectx][Ship.secty] = Ship.ship;
compkldist(0);
- return (time);
+ return (p_time);
}
*
* @(#)nova.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/nova.c,v 1.4 1999/11/30 03:49:52 billf Exp $
- * $DragonFly: src/games/trek/nova.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/nova.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** If the zap is too much, it gets destroyed.
*/
-nova(x, y)
-int x, y;
+void
+nova(int x, int y)
{
int i, j;
int se;
case QUEENE:
se = 2000;
if (Ship.shldup)
+ {
if (Ship.shield >= se)
{
Ship.shield -= se;
se -= Ship.shield;
Ship.shield = 0;
}
+ }
Ship.energy -= se;
if (Ship.energy <= 0)
lose(L_SUICID);
*
* @(#)out.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/out.c,v 1.4 1999/11/30 03:49:52 billf Exp $
- * $DragonFly: src/games/trek/out.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/out.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** Announce Device Out
*/
-out(dev)
-int dev;
+void
+out(int dev)
{
struct device *d;
d = &Device[dev];
printf("%s reports %s ", d->person, d->name);
- if (d->name[length(d->name) - 1] == 's')
+ if (d->name[strlen(d->name) - 1] == 's')
printf("are");
else
printf("is");
*
* @(#)phaser.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/phaser.c,v 1.5.2.1 2000/07/20 10:35:07 kris Exp $
- * $DragonFly: src/games/trek/phaser.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/phaser.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
struct cvntab Matab[] =
{
- "m", "anual", (int (*)())1, 0,
- "a", "utomatic", 0, 0,
- 0
+ { "m", "anual", (void (*)(int))1, 0 },
+ { "a", "utomatic", (void (*)(int))0, 0 },
+ { NULL, NULL, NULL, 0 }
};
struct banks
};
-
-phaser()
+void
+phaser(__unused int unused)
{
int i;
int j;
double dx, dy;
double anglefactor, distfactor;
struct banks *b;
- int manual, flag, extra;
+ int manual, flag, extra = 0;
int hit;
double tot;
int n;
struct banks bank[NBANKS];
struct cvntab *ptr;
- if (Ship.cond == DOCKED)
- return(printf("Phasers cannot fire through starbase shields\n"));
- if (damaged(PHASER))
- return (out(PHASER));
- if (Ship.shldup)
- return (printf("Sulu: Captain, we cannot fire through shields.\n"));
+ if (Ship.cond == DOCKED) {
+ printf("Phasers cannot fire through starbase shields\n");
+ return;
+ }
+ if (damaged(PHASER)) {
+ out(PHASER);
+ return;
+ }
+ if (Ship.shldup) {
+ printf("Sulu: Captain, we cannot fire through shields.\n");
+ return;
+ }
if (Ship.cloaked)
{
printf("Sulu: Captain, surely you must realize that we cannot fire\n");
else
{
/* automatic distribution of power */
- if (Etc.nkling <= 0)
- return (printf("Sulu: But there are no Klingons in this quadrant\n"));
+ if (Etc.nkling <= 0) {
+ printf("Sulu: But there are no Klingons in this quadrant\n");
+ return;
+ }
printf("Phasers locked on target. ");
while (flag)
{
*
* @(#)play.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/play.c,v 1.2 1999/11/30 03:49:52 billf Exp $
- * $DragonFly: src/games/trek/play.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/play.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
# include "getpar.h"
-# include <setjmp.h>
+static void myreset(int);
/*
** INSTRUCTION READ AND MAIN PLAY LOOP
**
** attack if the move was not free, and checkcond() to check up
** on how we are doing after the move.
*/
-extern int abandon(), capture(), shield(), computer(), dcrept(),
- destruct(), dock(), help(), impulse(), lrscan(),
- warp(), dumpgame(), rest(), srscan(),
- myreset(), torped(), visual(), setwarp(), undock(), phaser();
struct cvntab Comtab[] =
{
- "abandon", "", abandon, 0,
- "ca", "pture", capture, 0,
- "cl", "oak", shield, -1,
- "c", "omputer", computer, 0,
- "da", "mages", dcrept, 0,
- "destruct", "", destruct, 0,
- "do", "ck", dock, 0,
- "help", "", help, 0,
- "i", "mpulse", impulse, 0,
- "l", "rscan", lrscan, 0,
- "m", "ove", warp, 0,
- "p", "hasers", phaser, 0,
- "ram", "", warp, 1,
- "dump", "", dumpgame, 0,
- "r", "est", rest, 0,
- "sh", "ield", shield, 0,
- "s", "rscan", srscan, 0,
- "st", "atus", srscan, -1,
- "terminate", "", myreset, 0,
- "t", "orpedo", torped, 0,
- "u", "ndock", undock, 0,
- "v", "isual", visual, 0,
- "w", "arp", setwarp, 0,
- 0
+ { "abandon", "", abandon, 0 },
+ { "ca", "pture", capture, 0 },
+ { "cl", "oak", shield, -1 },
+ { "c", "omputer", computer, 0 },
+ { "da", "mages", dcrept, 0 },
+ { "destruct", "", destruct, 0 },
+ { "do", "ck", dock, 0 },
+ { "help", "", help, 0 },
+ { "i", "mpulse", impulse, 0 },
+ { "l", "rscan", lrscan, 0 },
+ { "m", "ove", dowarp, 0 },
+ { "p", "hasers", phaser, 0 },
+ { "ram", "", dowarp, 1 },
+ { "dump", "", dumpgame, 0 },
+ { "r", "est", rest, 0 },
+ { "sh", "ield", shield, 0 },
+ { "s", "rscan", srscan, 0 },
+ { "st", "atus", srscan, -1 },
+ { "terminate", "", myreset, 0 },
+ { "t", "orpedo", torped, 0 },
+ { "u", "ndock", undock, 0 },
+ { "v", "isual", visual, 0 },
+ { "w", "arp", setwarp, 0 },
+ { NULL, NULL, NULL, 0 }
};
-myreset()
+static void
+myreset(__unused int unused)
{
- extern jmp_buf env;
-
longjmp(env, 1);
}
-play()
+void
+play(void)
{
struct cvntab *r;
*
* @(#)ram.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/ram.c,v 1.4 1999/11/30 03:49:53 billf Exp $
- * $DragonFly: src/games/trek/ram.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/ram.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** also rack up incredible damages.
*/
-ram(ix, iy)
-int ix, iy;
+void
+ram(int ix, int iy)
{
int i;
char c;
*
* @(#)ranf.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/ranf.c,v 1.3 1999/11/30 03:49:53 billf Exp $
- * $DragonFly: src/games/trek/ranf.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/ranf.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
-# include <stdio.h>
-# include <stdlib.h>
+#include "trek.h"
-ranf(max)
-int max;
+int
+ranf(int max)
{
if (max <= 0)
return (0);
return (random() % max);
}
-
-double franf()
+double
+franf(void)
{
double t;
t = random() & 077777;
*
* @(#)rest.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/rest.c,v 1.4 1999/11/30 03:49:53 billf Exp $
- * $DragonFly: src/games/trek/rest.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/rest.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** rest period if anything momentous happens.
*/
-rest()
+void
+rest(__unused int unused)
{
double t;
int percent;
*
* @(#)schedule.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/schedule.c,v 1.4 1999/11/30 03:49:53 billf Exp $
- * $DragonFly: src/games/trek/schedule.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/schedule.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** The address of the slot is returned.
*/
-struct event *schedule(type, offset, x, y, z)
-int type;
-double offset;
-char x, y;
-char z;
+struct event *
+schedule(int type, double offset, char x, char y, char z)
{
struct event *e;
int i;
return (e);
}
syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z);
+ /* NOTREACHED */
+ return(NULL);
}
** time plus 'offset'.
*/
-reschedule(e1, offset)
-struct event *e1;
-double offset;
+void
+reschedule(struct event *e1, double offset)
{
double date;
struct event *e;
** The event at slot 'e' is deleted.
*/
-unschedule(e1)
-struct event *e1;
+void
+unschedule(struct event *e1)
{
struct event *e;
** figure.
*/
-struct event *xsched(ev1, factor, x, y, z)
-int ev1;
-int factor;
-int x, y, z;
+struct event *
+xsched(int ev1, int factor, int x, int y, int z)
{
int ev;
** division factor. Look at the code to see what really happens.
*/
-xresched(e1, ev1, factor)
-struct event *e1;
-int ev1;
-int factor;
+void
+xresched(struct event *e1, int ev1, int factor)
{
int ev;
struct event *e;
*
* @(#)score.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/score.c,v 1.4 1999/11/30 03:49:53 billf Exp $
- * $DragonFly: src/games/trek/score.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/score.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** PRINT OUT THE CURRENT SCORE
*/
-long score()
+long
+score(void)
{
int u;
int t;
long s;
double r;
- extern struct cvntab Skitab[];
printf("\n*** Your score:\n");
s = t = Param.klingpwr / 4 * (u = Game.killk);
*
* @(#)setup.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/setup.c,v 1.6 1999/11/30 03:49:54 billf Exp $
- * $DragonFly: src/games/trek/setup.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/setup.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
-# include <stdlib.h>
# include "trek.h"
# include "getpar.h"
struct cvntab Lentab[] =
{
- "s", "hort", (int (*)())1, 0,
- "m", "edium", (int (*)())2, 0,
- "l", "ong", (int (*)())4, 0,
- "restart", "", 0, 0,
- 0
+ { "s", "hort", (void (*)(int))1, 0 },
+ { "m", "edium", (void (*)(int))2, 0 },
+ { "l", "ong", (void (*)(int))4, 0 },
+ { "restart", "", NULL, 0 },
+ { NULL, NULL, NULL, 0 }
};
struct cvntab Skitab[] =
{
- "n", "ovice", (int (*)())1, 0,
- "f", "air", (int (*)())2, 0,
- "g", "ood", (int (*)())3, 0,
- "e", "xpert", (int (*)())4, 0,
- "c", "ommodore", (int (*)())5, 0,
- "i", "mpossible", (int (*)())6, 0,
- 0
+ { "n", "ovice", (void (*)(int))1, 0 },
+ { "f", "air", (void (*)(int))2, 0 },
+ { "g", "ood", (void (*)(int))3, 0 },
+ { "e", "xpert", (void (*)(int))4, 0 },
+ { "c", "ommodore", (void (*)(int))5, 0 },
+ { "i", "mpossible", (void (*)(int))6, 0 },
+ { NULL, NULL, NULL, 0 }
};
-setup()
+void
+setup(void)
{
struct cvntab *r;
int i, j;
double f;
int d;
- int fd;
int klump;
int ix, iy;
struct quad *q;
*
* @(#)setwarp.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/setwarp.c,v 1.2 1999/11/30 03:49:54 billf Exp $
- * $DragonFly: src/games/trek/setwarp.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/setwarp.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** checked for consistancy.
*/
-setwarp()
+void
+setwarp(__unused int unused)
{
double warpfac;
warpfac = getfltpar("Warp factor");
if (warpfac < 0.0)
return;
- if (warpfac < 1.0)
- return (printf("Minimum warp speed is 1.0\n"));
- if (warpfac > 10.0)
- return (printf("Maximum speed is warp 10.0\n"));
+ if (warpfac < 1.0) {
+ printf("Minimum warp speed is 1.0\n");
+ return;
+ }
+ if (warpfac > 10.0) {
+ printf("Maximum speed is warp 10.0\n");
+ return;
+ }
if (warpfac > 6.0)
printf("Damage to warp engines may occur above warp 6.0\n");
Ship.warp = warpfac;
*
* @(#)shield.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/shield.c,v 1.5 1999/11/30 03:49:54 billf Exp $
- * $DragonFly: src/games/trek/shield.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/shield.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
struct cvntab Udtab[] =
{
- "u", "p", (int (*)())1, 0,
- "d", "own", 0, 0,
- 0
+ { "u", "p", (void (*)(int))1, 0 },
+ { "d", "own", (void (*)(int))0, 0 },
+ { NULL, NULL, NULL, 0 }
};
-shield(f)
-int f;
+void
+shield(int f)
{
int i;
- char c;
struct cvntab *r;
char s[100];
- char *device, *dev2, *dev3;
+ const char *device, *dev2, *dev3;
int ind;
char *stat;
if (f < 0)
{
/* cloaking device */
- if (Ship.ship == QUEENE)
- return (printf("Ye Faire Queene does not have the cloaking device.\n"));
+ if (Ship.ship == QUEENE) {
+ printf("Ye Faire Queene does not have the cloaking device.\n");
+ return;
+ }
device = "Cloaking device";
dev2 = "is";
ind = CLOAK;
else
{
if (*stat)
- (void)sprintf(s, "%s %s up. Do you want %s down", device, dev2, dev3);
+ sprintf(s, "%s %s up. Do you want %s down", device, dev2, dev3);
else
- (void)sprintf(s, "%s %s down. Do you want %s up", device, dev2, dev3);
+ sprintf(s, "%s %s down. Do you want %s up", device, dev2, dev3);
if (!getynpar(s))
return;
i = !*stat;
return;
}
if (i)
+ {
if (f >= 0)
Ship.energy -= Param.shupengy;
else
Ship.cloakgood = 0;
+ }
Move.free = 0;
if (f >= 0)
Move.shldchg = 1;
*
* @(#)snova.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/snova.c,v 1.4 1999/11/30 03:49:54 billf Exp $
- * $DragonFly: src/games/trek/snova.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/snova.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** override mode.
*/
-snova(x, y)
-int x, y;
+void
+snova(int x, int y)
{
int qx, qy;
- int ix, iy;
+ int ix, iy = 0;
int f;
int dx, dy;
int n;
/* Enterprise caused supernova */
Game.kills += dy;
if (q->bases)
- killb(qx, qy, -1);
+ killb(qx, qy);
Game.killk += dx;
}
else
if (q->bases)
- killb(qx, qy, 0);
+ killb(qx, qy);
killd(qx, qy, (x >= 0));
q->stars = -1;
q->klings = 0;
*
* @(#)srscan.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/srscan.c,v 1.4 1999/11/30 03:49:55 billf Exp $
- * $DragonFly: src/games/trek/srscan.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/srscan.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** The current quadrant is filled in on the computer chart.
*/
-char *Color[4] =
+const char *Color[4] =
{
"GREEN",
"DOCKED",
"RED"
};
-srscan(f)
-int f;
+void
+srscan(int f)
{
int i, j;
int statinfo;
- char *s;
+ const char *s;
int percent;
- struct quad *q;
- extern struct cvntab Skitab[];
- extern struct cvntab Lentab[];
+ struct quad *q = NULL;
struct cvntab *p;
if (f >= 0 && check_out(SRSCAN))
*
* @(#)systemname.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/systemname.c,v 1.4 1999/11/30 03:49:55 billf Exp $
- * $DragonFly: src/games/trek/systemname.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/systemname.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
# include "trek.h"
** starsystems, etc.
*/
-char *systemname(q1)
-struct quad *q1;
+const char *
+systemname(struct quad *q1)
{
struct quad *q;
int i;
*
* @(#)torped.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/torped.c,v 1.5 1999/11/30 03:49:55 billf Exp $
- * $DragonFly: src/games/trek/torped.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/torped.c,v 1.3 2006/09/07 21:19:44 pavalos Exp $
*/
-# include <stdio.h>
+# include "getpar.h"
# include "trek.h"
+static int randcourse(int);
+
/*
** PHOTON TORPEDO CONTROL
**
** the misfire damages your torpedo tubes.
*/
-
-torped()
+void
+torped(__unused int unused)
{
int ix, iy;
double x, y, dx, dy;
if (Ship.cloaked)
{
- return (printf("Federation regulations do not permit attack while cloaked.\n"));
+ printf("Federation regulations do not permit attack while cloaked.\n");
+ return;
}
if (check_out(TORPED))
return;
if (Ship.torped <= 0)
{
- return (printf("All photon torpedos expended\n"));
+ printf("All photon torpedos expended\n");
+ return;
}
/* get the course */
burst = getintpar("burst angle");
if (burst <= 0)
return;
- if (burst > 15)
- return (printf("Maximum burst angle is 15 degrees\n"));
+ if (burst > 15) {
+ printf("Maximum burst angle is 15 degrees\n");
+ return;
+ }
}
sectsize = NSECTS;
n = -1;
** to the tubes, etc.
*/
-randcourse(n)
-int n;
+static int
+randcourse(int n)
{
double r;
int d;
* SUCH DAMAGE.
*
* @(#)trek.h 8.1 (Berkeley) 5/31/93
+ * $DragonFly: src/games/trek/trek.h,v 1.2 2006/09/07 21:19:44 pavalos Exp $
*/
+#include <math.h>
+#include <setjmp.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
/*
** Global Declarations
**
** actually allocate stuff in "externs.c"
*/
-/* external function definitions */
-extern double franf(); /* floating random number function */
-extern double sqrt(); /* square root */
-extern double sin(), cos(); /* trig functions */
-extern double atan2(); /* fancy arc tangent function */
-extern double log(); /* log base e */
-extern double pow(); /* power function */
-extern double fabs(); /* absolute value function */
-extern double exp(); /* exponential function */
-
+extern jmp_buf env;
/********************* GALAXY **************************/
/* galactic parameters */
*/
/* ascii names of systems */
-extern char *Systemname[NINHAB];
+extern const char *Systemname[NINHAB];
/* quadrant definition */
struct quad Quad[NQUADS][NQUADS];
/* device names */
struct device
{
- char *name; /* device name */
- char *person; /* the person who fixes it */
+ const char *name; /* device name */
+ const char *person; /* the person who fixes it */
};
-struct device Device[NDEV];
+extern struct device Device[NDEV];
/*************************** EVENTS ****************************/
struct event
{
- char x, y; /* coordinates */
+ short x, y; /* coordinates */
double date; /* trap stardate */
char evcode; /* event type */
- char systemname; /* starsystem name */
+ short systemname; /* starsystem name */
};
/* systemname conventions:
* 1 -> NINHAB index into Systemname table for reported distress calls
struct kling
{
- char x, y; /* coordinates */
+ short x, y; /* coordinates */
int power; /* power left */
double dist; /* distance to Enterprise */
double avgdist; /* average over this move */
struct xy
{
- char x, y; /* coordinates */
+ short x, y; /* coordinates */
};
int quady; /* quadrant y coord */
int sectx; /* sector x coord */
int secty; /* sector y coord */
- char cond; /* condition code */
+ short cond; /* condition code */
char sinsbad; /* Space Inertial Navigation System condition */
- char *shipname; /* name of current starship */
+ const char *shipname; /* name of current starship */
char ship; /* current starship */
int distressed; /* number of distress calls */
} Ship;
/* other information kept in a snapshot */
struct
{
- char bases; /* number of starbases */
+ short bases; /* number of starbases */
char klings; /* number of klingons */
double date; /* stardate */
double time; /* time left */
struct
{
struct kling klingon[MAXKLQUAD]; /* sorted Klingon list */
- char nkling; /* number of Klingons in this sector */
+ int nkling; /* number of Klingons in this sector */
/* < 0 means automatic override mode */
char fast; /* set if speed > 300 baud */
struct xy starbase; /* starbase in current quadrant */
# define xTRACE 1
int Trace;
-extern char *systemname();
+/* external function definitions */
+void abandon(int);
+void attack(int);
+void autover(void);
+void capture(int);
+int cgetc(int);
+bool check_out(int);
+void checkcond(void);
+void compkldist(bool);
+void computer(int);
+void damage(int, double);
+bool damaged(int);
+void dcrept(int);
+void destruct(int);
+void dock(int);
+void undock(int);
+void dumpgame(int);
+bool restartgame(void);
+void dumpme(int);
+int dumpssradio(void);
+void events(int);
+bool getcodi(int *, double *);
+void help(int);
+void impulse(int);
+void initquad(int);
+void sector(int *, int *);
+void killk(int, int);
+void killb(int, int);
+void kills(int, int, int);
+void killd(int, int, int);
+void klmove(int);
+void lose(int);
+void lrscan(int);
+double move(int, int, double, double);
+void nova(int, int);
+void out(int);
+void phaser(int);
+void play(void);
+void ram(int, int);
+int ranf(int);
+double franf(void);
+void rest(int);
+struct event *schedule(int, double, char, char, char);
+void reschedule(struct event *, double);
+void unschedule(struct event *);
+struct event *xsched(int, int, int, int, int);
+void xresched(struct event *, int, int);
+long score(void);
+void setup(void);
+void setwarp(int);
+void shield(int);
+void snova(int, int);
+void srscan(int);
+const char *systemname(struct quad *);
+void torped(int);
+char *bmove(const void *, void *, size_t);
+bool sequal(const char *, const char *);
+void syserr(const char *, ...);
+void visual(int);
+void warp(int, int, double);
+void dowarp(int);
+void win(void);
*
* @(#)utility.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/utility.c,v 1.5 1999/11/30 03:49:55 billf Exp $
- * $DragonFly: src/games/trek/utility.c,v 1.3 2005/04/29 09:22:57 joerg Exp $
+ * $DragonFly: src/games/trek/utility.c,v 1.4 2006/09/07 21:19:45 pavalos Exp $
*/
#include <errno.h>
+#include <stdarg.h>
+#include "trek.h"
/*
** ASSORTED UTILITY ROUTINES
** Overflow of `b' is not tested.
*/
-char *bmove(a, b, l)
-char *a, *b;
-int l;
+char *
+bmove(const void *a, void *b, size_t l)
{
- int n;
- char *p, *q;
-
- p = a;
- q = b;
- n = l;
- while (n--)
- *q++ = *p++;
- return (q);
+ return((char *)memcpy(b, a, l) + l);
}
** returns one if equal, zero otherwise.
*/
-sequal(a, b)
-char *a, *b;
+bool
+sequal(const char *a, const char *b)
{
- char *p, *q;
-
- p = a;
- q = b;
- while (*p || *q)
- if (*p++ != *q++)
- return(0);
- return(1);
-}
-
-
-/*
-** STRING CONCATENATE
-**
-** The strings `s1' and `s2' are concatenated and stored into
-** `s3'. It is ok for `s1' to equal `s3', but terrible things
-** will happen if `s2' equals `s3'. The return value is is a
-** pointer to the end of `s3' field.
-*/
-
-char *concat(s1, s2, s3)
-char *s1, *s2, *s3;
-{
- char *p;
- char *q;
-
- p = s3;
- q = s1;
- while (*q)
- *p++ = *q++;
- q = s2;
- while (*q)
- *p++ = *q++;
- *p = 0;
- return (p);
-}
-
-
-/*
-** FIND STRING LENGTH
-**
-** The length of string `s' (excluding the null byte which
-** terminates the string) is returned.
-*/
-
-length(s)
-char *s;
-{
- int l;
- char *p;
-
- l = 0;
- p = s;
- while (*p++)
- l++;
- return(l);
+ return(!strcmp(a, b));
}
** SYSTEM ERROR
*/
-syserr(p0, p1, p2, p3, p4, p5)
+void
+syserr(const char *fmt, ...)
{
+ va_list ap;
+
+ va_start(ap, fmt);
printf("\n\07TREK SYSERR: ");
- printf(p0, p1, p2, p3, p4, p5);
+ vprintf(fmt, ap);
printf("\n");
if (errno)
printf("\tsystem error %d\n", errno);
+ va_end(ap);
exit(1);
}
*
* @(#)visual.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/visual.c,v 1.4 1999/11/30 03:49:56 billf Exp $
- * $DragonFly: src/games/trek/visual.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/visual.c,v 1.3 2006/09/07 21:19:45 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
/*
/* This struct[] has the delta x, delta y for particular directions */
struct xy Visdelta[11] =
{
- -1, -1,
- -1, 0,
- -1, 1,
- 0, 1,
- 1, 1,
- 1, 0,
- 1, -1,
- 0, -1,
- -1, -1,
- -1, 0,
- -1, 1
+ { -1, -1 },
+ { -1, 0 },
+ { -1, 1 },
+ { 0, 1 },
+ { 1, 1 },
+ { 1, 0 },
+ { 1, -1 },
+ { 0, -1 },
+ { -1, -1 },
+ { -1, 0 },
+ { -1, 1 }
};
-visual()
+void
+visual(__unused int unused)
{
int ix, iy;
int co;
*
* @(#)warp.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/warp.c,v 1.4 1999/11/30 03:49:56 billf Exp $
- * $DragonFly: src/games/trek/warp.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/warp.c,v 1.3 2006/09/07 21:19:45 pavalos Exp $
*/
+# include "getpar.h"
# include "trek.h"
/*
** case, there is code to handle time warps, etc.
*/
-warp(fl, c, d)
-int fl, c;
-double d;
+void
+warp(int fl, int c, double d)
{
int course;
double power;
double dist;
- double time;
+ double p_time;
double speed;
double frac;
int percent;
int i;
- extern double move();
+ char *s;
- if (Ship.cond == DOCKED)
- return (printf("%s is docked\n", Ship.shipname));
- if (damaged(WARP))
- {
- return (out(WARP));
+ if (Ship.cond == DOCKED) {
+ printf("%s is docked\n", Ship.shipname);
+ return;
}
- if (fl < 0)
+ if (damaged(WARP))
{
- course = c;
- dist = d;
+ out(WARP);
+ return;
}
- else
- if (getcodi(&course, &dist))
- return;
+ course = c;
+ dist = d;
/* check to see that we are not using an absurd amount of power */
power = (dist + 0.05) * Ship.warp3;
/* compute the speed we will move at, and the time it will take */
speed = Ship.warp2 / Param.warptime;
- time = dist / speed;
+ p_time = dist / speed;
/* check to see that that value is not ridiculous */
- percent = 100 * time / Now.time + 0.5;
+ percent = 100 * p_time / Now.time + 0.5;
if (percent >= 85)
{
printf("Spock: That would take %d%% of our remaining time.\n",
{
frac = franf();
dist *= frac;
- time *= frac;
+ p_time *= frac;
damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
}
/* do the move */
- Move.time = move(fl, course, time, speed);
+ Move.time = move(fl, course, p_time, speed);
/* see how far we actually went, and decrement energy appropriately */
dist = Move.time * speed;
sleep(4);
if (ranf(100) >= 100 * dist)
{
- return (printf("Equilibrium restored -- all systems normal\n"));
+ printf("Equilibrium restored -- all systems normal\n");
+ return;
}
/* select a bizzare thing to happen to us */
if (percent < 35 || !Game.snap)
{
/* positive time warp */
- time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
- Now.date += time;
+ p_time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
+ Now.date += p_time;
printf("Positive time portal entered -- it is now Stardate %.2f\n",
Now.date);
for (i = 0; i < MAXEVENTS; i++)
{
percent = Event[i].evcode;
if (percent == E_FIXDV || percent == E_LRTB)
- Event[i].date += time;
+ Event[i].date += p_time;
}
return;
}
/* s/he got lucky: a negative time portal */
- time = Now.date;
- i = (int) Etc.snapshot;
- bmove(i, Quad, sizeof Quad);
- bmove(i += sizeof Quad, Event, sizeof Event);
- bmove(i += sizeof Event, &Now, sizeof Now);
+ p_time = Now.date;
+ s = Etc.snapshot;
+ bmove(s, Quad, sizeof Quad);
+ bmove(s += sizeof Quad, Event, sizeof Event);
+ bmove(s += sizeof Event, &Now, sizeof Now);
printf("Negative time portal entered -- it is now Stardate %.2f\n",
Now.date);
for (i = 0; i < MAXEVENTS; i++)
if (Event[i].evcode == E_FIXDV)
- reschedule(&Event[i], Event[i].date - time);
+ reschedule(&Event[i], Event[i].date - p_time);
return;
}
damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
Ship.shldup = 0;
}
+
+/*
+ * dowarp() is used in a struct cvntab to call warp(). Since it is always ram
+ * or move, fl is never < 0, so ask the user for course and distance, then pass
+ * that to warp().
+ */
+void
+dowarp(int fl)
+{
+ int c;
+ double d;
+
+ if(getcodi(&c, &d))
+ return;
+ warp(fl, c, d);
+}
*
* @(#)win.c 8.1 (Berkeley) 5/31/93
* $FreeBSD: src/games/trek/win.c,v 1.4 1999/11/30 03:49:56 billf Exp $
- * $DragonFly: src/games/trek/win.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
+ * $DragonFly: src/games/trek/win.c,v 1.3 2006/09/07 21:19:45 pavalos Exp $
*/
# include "trek.h"
# include "getpar.h"
-# include <setjmp.h>
/*
** Signal game won
** pretty off the wall.
*/
-win()
+void
+win(void)
{
long s;
- extern jmp_buf env;
- extern long score();
- extern struct cvntab Skitab[];
struct cvntab *p;
sleep(1);