[comp.sources.games] v01i077: xtrek - mulitplayer space war for X-windows, Part05/06

games-request@tekred.TEK.COM (07/02/87)

Submitted by: Chris Guthrie <chris%ic.Berkeley.EDU@ucbvax.berkeley.edu>
Comp.sources.games: Volume 1, Issue 77
Archive-name: xtrek/Part05


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 5 (of 6)."
# Contents:  clock.bitmap colors.c coup.c data.c data.h death.c defs.h
#   dmessage.c enter.c interface.c orbit.c phaser.c planetlist.c
#   planets.h robot.c scores.c startdaemon.c torp.c util.c
# Wrapped by billr@tekred on Thu Jul  2 10:26:34 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f clock.bitmap -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"clock.bitmap\"
else
echo shar: Extracting \"clock.bitmap\" \(1338 characters\)
sed "s/^X//" >clock.bitmap <<'END_OF_clock.bitmap'
X#define clock_width 48
X#define clock_height 48
Xstatic short clock_bits[] = {
X   0x0000, 0x0ff8, 0x0000, 0x8000,
X   0xf087, 0x0000, 0x6000, 0x0080,
X   0x0003, 0x1800, 0x0080, 0x000c,
X   0x1400, 0x0000, 0x0010, 0x2300,
X   0x0000, 0x0068, 0x0080, 0x0000,
X   0x0084, 0x0040, 0x0000, 0x0100,
X   0x0020, 0x0000, 0x0200, 0x0020,
X   0x0000, 0x0200, 0x0010, 0x0000,
X   0x0400, 0x0018, 0x0000, 0x0800,
X   0x0028, 0x0000, 0x0c00, 0x0004,
X   0x0000, 0x1200, 0x0004, 0x0000,
X   0x1000, 0x0002, 0x0000, 0x2000,
X   0x0002, 0x0000, 0x2000, 0x0002,
X   0x0000, 0x2000, 0x0002, 0x0000,
X   0x2000, 0x0001, 0x0000, 0x4000,
X   0x0001, 0x0000, 0x4000, 0x0001,
X   0x0000, 0x4000, 0x0001, 0x0000,
X   0x4000, 0x000f, 0x0080, 0x7800,
X   0x0001, 0x0000, 0x4000, 0x0001,
X   0x0000, 0x4000, 0x0001, 0x0000,
X   0x4000, 0x0001, 0x0000, 0x4000,
X   0x0002, 0x0000, 0x2000, 0x0002,
X   0x0000, 0x2000, 0x4002, 0x5ddd,
X   0x2001, 0x8002, 0xccc8, 0x2000,
X   0x4004, 0x5d49, 0x1001, 0x0004,
X   0x0000, 0x1000, 0x0028, 0x0000,
X   0x0a00, 0x0018, 0x0000, 0x0c00,
X   0x0010, 0x0000, 0x0400, 0x0020,
X   0x0000, 0x0200, 0x0020, 0x0000,
X   0x0200, 0x0040, 0x0000, 0x0100,
X   0x0080, 0x0000, 0x0080, 0x2300,
X   0x0000, 0x0062, 0x1400, 0x0000,
X   0x0014, 0x1800, 0x0080, 0x000c,
X   0x6000, 0x0080, 0x0003, 0x8000,
X   0xf087, 0x0000, 0x0000, 0x0ff8,
X   0x0000, 0x0000, 0x0000, 0x0000};
END_OF_clock.bitmap
if test 1338 -ne `wc -c <clock.bitmap`; then
    echo shar: \"clock.bitmap\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f colors.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"colors.c\"
else
echo shar: Extracting \"colors.c\" \(2570 characters\)
sed "s/^X//" >colors.c <<'END_OF_colors.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <stdio.h>
X#include <X/Xlib.h>
X#include <string.h>
X#include "data.h"
X
Xtypedef struct assoc {
X	char	*str;
X	int	*colorp;
X	int	bWDef;
X	char	*colorDef;
X} ASSOC;
X
XASSOC	assoc[] = {
X	{ "border",	&borderColor,	WhitePixel,	"blue"		},
X	{ "background",	&backColor,	BlackPixel,	"black"		},
X	{ "text",	&textColor,	WhitePixel,	"white"		},
X	{ "nobody",	&shipCol[0],	WhitePixel,	"blue"	},
X	{ "fed",	&shipCol[1],	WhitePixel,	"yellow",	},
X	{ "rom",	&shipCol[2],	WhitePixel,	"red",		},
X	{ "kli",	&shipCol[3],	WhitePixel,	"green",	},
X	{ "ori",	&shipCol[4],	WhitePixel,	"#0ff",	},
X	{ "warning",	&warningColor,	WhitePixel,	"red"		},
X	{ "unknown",	&unColor,	WhitePixel,	"light grey"	},
X	{ "ralert",	&rColor,	WhitePixel,	"red"		},
X	{ "yalert",	&yColor,	WhitePixel,	"yellow"	},
X	{ "galert",	&gColor,	WhitePixel,	"green"		},
X	{ "me",		&myColor,	WhitePixel,	"white"		}
X};
X
XgetColorDefs(prog)
X	char	*prog;
X{
X	int	i, invert = 0;
X	char	*color;
X	Color	def;
X
X	if (DisplayCells() <= 2) {	/* b & w */
X		invert = booleanDefault(prog, "reverseVideo");
X		for (i = 0; i < sizeof (assoc) / sizeof (*assoc); i++)
X			*assoc[i].colorp = 
X				invert ? !assoc[i].bWDef : assoc[i].bWDef;
X	} else {
X		for (i = 0; i < sizeof (assoc) / sizeof (*assoc); i++) {
X			if ((color = XGetDefault(prog, assoc[i].str)) == NULL)
X				color = assoc[i].colorDef;
X			XParseColor(color, &def);
X			XGetHardwareColor(&def);
X			*assoc[i].colorp = def.pixel;
X		}
X	}
X}
X
XbooleanDefault(prog, def)
X	char	*prog, *def;
X{
X	char	*str;
X
X	if ((str = XGetDefault(prog, def)) != NULL && strcmp(str, "on") == 0)
X		return (1);
X	else
X		return (0);
X}
X
X#define iswhite(c)	((c) == ' ' || c == '\t' || (c) == ',')
X
XarrayDefault(prog, def, sizeP, sp)
X	char	*prog, *def;
X	int	*sizeP;
X	short	*sp;
X{
X	int	max;
X	char	*str;
X
X	str = XGetDefault(prog, def);
X	if (str == NULL)
X		return (-1);
X	max = *sizeP;
X	*sizeP = 0;
X
X	for (;;) {
X		while (iswhite(*str))
X			str++;
X		if (*str == '\0')
X			break;
X		if (++(*sizeP) > max)
X			return (-1);
X		if (sscanf(str, "0x%hx", &sp[*sizeP]) != 1)
X			return (-1);
X		while (!iswhite(*str) && *str != '\0')
X			str++;
X	}
X	return (0);
X}
END_OF_colors.c
if test 2570 -ne `wc -c <colors.c`; then
    echo shar: \"colors.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f coup.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"coup.c\"
else
echo shar: Extracting \"coup.c\" \(1691 characters\)
sed "s/^X//" >coup.c <<'END_OF_coup.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include <X/Xlib.h>
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#include <sys/shm.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
X/* throw a coup */
X
Xcoup()
X{
X    register int i;
X    register struct planet *l;
X
X    if (me->p_kills < 1.0) {
X	warning("You must have one kill to throw a coup");
X	return;
X    }
X    if (!(me->p_flags & PFORBIT)) {
X	warning("You must orbit your home planet to throw a coup");
X	return;
X    }
X    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
X	if ((l->pl_owner == me->p_team) && (l->pl_armies > 0)) {
X	    warning("You already own a planet!!!");
X	    return;
X	}
X    }
X    l = &planets[me->p_planet];
X
X    if ((!(l->pl_flags & PLHOME)) || ((l->pl_flags & ALLTEAM) != me->p_team)) {
X	warning("You must orbit your home planet to throw a coup");
X	return;
X    }
X
X    if (l->pl_armies > 4) {
X	warning("Too many armies on planet to throw a coup");
X	return;
X    }
X
X    if (l->pl_couptime > 0) {
X	warning("Planet not yet ready for a coup");
X	return;
X    }
X
X    if (l->pl_flags & PLCOUP) { /* Avoid race conditions */
X	return;
X    }
X
X    /* the cases are now met.  We can have a coup. */
X
X    l->pl_flags |= PLCOUP;
X    mystats->st_coups++;
X}
END_OF_coup.c
if test 1691 -ne `wc -c <coup.c`; then
    echo shar: \"coup.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f data.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"data.c\"
else
echo shar: Extracting \"data.c\" \(1881 characters\)
sed "s/^X//" >data.c <<'END_OF_data.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xstruct player *players;
Xstruct player *me;
Xstruct torp *torps;
Xstruct status *status;
Xstruct ship *myship;
Xstruct stats *mystats;
Xstruct planet *planets;
Xstruct phaser *phasers;
Xstruct message *messages;
Xstruct mctl *mctl;
X
Xint	oldalert = PFGREEN;	/* Avoid changing more than we have to */
Xint 	remap[9] = { 0, 1, 2, -1, 3, -1, -1, -1, 4 };
Xint	messpend;
Xint	lastcount;
Xint	mdisplayed;
Xint	redrawall;
Xint	copilot = 0;
Xint	nopilot = 1;
Xint	watch = 0;
Xint	selfdest;
Xint	udcounter;
Xint	lastm;
Xint	delay;
Xint	mapmode = 1; 
Xint	namemode = 1; 
Xint	statmode = 1;
Xint	showStats;
Xint	showShields;
Xint	warncount = 0;
Xint	warntimer = -1;
Xint	infomapped = 0;
Xint	mustexit = 0;
X
Xlong	start_time;
X
Xdouble	oldmax = 0.0;
X
Xdouble	Sin[], Cos[];		 /* Initialized in sintab.c */
X
XPixmap	foreTile, backTile, rTile, yTile, gTile, stippleTile;
X
Xint	borderColor, backColor, textColor, myColor, warningColor, shipCol[5],
X	rColor, yColor, gColor, unColor;
X
Xchar teamlet[] = {'I', 'F', 'R', 'X', 'K', 'X', 'X', 'X', 'O'};
Xchar *teamshort[9] = {"IND", "FED", "ROM", "X", "KLI", "X", "X", "X", "ORI"};
X
XDisplay		*display;
X
XFont 		dfont, bfont, ifont;
XFontInfo 	*dfontinfo, *bfontinfo, *ifontinfo;
X
XWindow	w, mapw, statwin, baseWin, messagew, infow, iconWin, tstatw,
X	war, warf, warr, wark, waro, wargo, warno, warnw, helpWin,
X	planetw, playerw;
END_OF_data.c
if test 1881 -ne `wc -c <data.c`; then
    echo shar: \"data.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f data.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"data.h\"
else
echo shar: Extracting \"data.h\" \(1830 characters\)
sed "s/^X//" >data.h <<'END_OF_data.h'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
Xextern struct player *players;
Xextern struct player *me;
Xextern struct torp *torps;
Xextern struct status *status;
Xextern struct ship *myship;
Xextern struct stats *mystats;
Xextern struct planet *planets;
Xextern struct phaser *phasers;
Xextern struct message *messages;
Xextern struct mctl *mctl;
X
Xextern int oldalert;
Xextern int remap[];
Xextern int udcounter;
Xextern int messpend;
Xextern int lastcount;
Xextern int mdisplayed;
Xextern int redrawall;
Xextern int copilot;
Xextern int nopilot;
Xextern int watch;
Xextern int selfdest;
Xextern int lastm;
Xextern int delay;
Xextern int mapmode; 
Xextern int namemode; 
Xextern int statmode;
Xextern int showShields;
Xextern int showStats;
Xextern int warncount;
Xextern int warntimer;
Xextern int infomapped;
Xextern int mustexit;
X
Xextern long	start_time;
X
Xextern double	oldmax;
Xextern double	Sin[], Cos[];
X
Xextern Pixmap	foreTile, backTile, rTile, yTile, gTile, stippleTile;
X
Xextern int	borderColor, backColor, textColor, myColor, 
X		warningColor, shipCol[5], rColor, yColor,
X		gColor, unColor;
X
Xextern char teamlet[];
Xextern char *teamshort[];
X
Xextern Display	*display;
X
Xextern Font dfont, bfont, ifont;
Xextern FontInfo *dfontinfo, *bfontinfo, *ifontinfo;
X
Xextern Window	w, mapw, statwin, baseWin, messagew, infow, iconWin, tstatw,
X		war, warf, warr, wark, waro, wargo, warno, warnw, helpWin,
X		planetw, playerw;
END_OF_data.h
if test 1830 -ne `wc -c <data.h`; then
    echo shar: \"data.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f death.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"death.c\"
else
echo shar: Extracting \"death.c\" \(4146 characters\)
sed "s/^X//" >death.c <<'END_OF_death.c'
X
X/*
X
X#ifdef HPUX
X#include <time.h>
X#else HPUX
X#include <sys/time.h>
X#endif HPUX
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <signal.h>
X#include <setjmp.h>
X#include <sys/types.h>
X#ifdef hpux
X#include <time.h>
X#else hpux
X#include <sys/time.h>
X#endif hpux
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xextern jmp_buf env;
X
Xstatic struct itimerval udt;
X
Xdeath()
X{
X    char buf[80];
X
X    signal(SIGALRM, SIG_IGN);
X    udt.it_interval.tv_sec = 0;
X    udt.it_interval.tv_usec = 0;
X    udt.it_value.tv_sec = 0;
X    udt.it_value.tv_usec = 0;
X    setitimer(ITIMER_REAL, &udt, 0);
X    signal(SIGALRM, SIG_DFL);
X
X    me->p_status = POUTFIT;		/* Stop the ghost buster */
X
X    XClear(w);
X    XChangeBorder(baseWin, gTile);
X    if (showStats)
X	closeStats(statwin);
X    if (infomapped)
X	destroyInfo();
X    if (ismapped(playerw))
X	XUnmapWindow(playerw);
X    if (ismapped(planetw))
X	XUnmapWindow(planetw);
X    if (ismapped(war))
X	XUnmapWindow(war);
X
X    switch (me->p_whydead) {
X	case KQUIT:
X	    sprintf(buf, "You have self-destructed");
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    mustexit = 1;  /* Hey!  If you quit, you quit */
X	    break;
X	case KTORP:
X	    sprintf(buf, "You were killed by a torp from %s (%c%x)",
X		players[me->p_whodead].p_name,
X		teamlet[players[me->p_whodead].p_team],
X		me->p_whodead);
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    sprintf(buf, "who was %d%% damaged",
X		players[me->p_whodead].p_damage);
X	    XText(w, 50, 260, buf, strlen(buf), dfont, textColor, backColor);
X	    break;
X	case KPHASER:
X	    sprintf(buf, "You were killed by a phaser shot from %s (%c%x)",
X		players[me->p_whodead].p_name,
X		teamlet[players[me->p_whodead].p_team],
X		me->p_whodead);
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    sprintf(buf, "who was %d%% damaged",
X		players[me->p_whodead].p_damage);
X	    XText(w, 50, 260, buf, strlen(buf), dfont, textColor, backColor);
X	    break;
X	case KPLANET:
X	    sprintf(buf, "You were killed by planetary fire from %s (%c)",
X		planets[me->p_whodead].pl_name,
X		teamlet[planets[me->p_whodead].pl_owner]);
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    break;
X	case KSHIP:
X	    sprintf(buf, "You were killed by an exploding ship formerly owned by %s (%c%x)",
X		players[me->p_whodead].p_name,
X		teamlet[players[me->p_whodead].p_team],
X		me->p_whodead);
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    sprintf(buf, "who was %d%% damaged",
X		players[me->p_whodead].p_damage);
X	    XText(w, 50, 260, buf, strlen(buf), dfont, textColor, backColor);
X	    break;
X	case KDAEMON:
X	    sprintf(buf, "You were killed by a dying daemon");
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    mustexit = 1;
X	    break;
X	case KWINNER:
X	    sprintf(buf, "Galaxy has been conquered by %s (%c%x)",
X		players[me->p_whodead].p_name,
X		teamlet[players[me->p_whodead].p_team],
X		players[me->p_whodead].p_no);
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    mustexit = 1;
X	    break;
X	case KGHOST:
X	    sprintf(buf, "You were killed by a confused daemon");
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    mustexit = 1;
X	    break;
X	default:
X	    sprintf(buf, "You were killed by something unknown to this game?");
X	    XText(w, 50, 250, buf, strlen(buf), dfont, textColor, backColor);
X	    mustexit = 1;
X	    break;
X	}
X    if (oldmax < me->p_kills)
X	oldmax = me->p_kills;
X    mystats->st_kills += me->p_kills;
X    /* the exit routine in 'entryWindow' handles reentry now */
X    XSync(1);
X    longjmp(env, 0);
X}
END_OF_death.c
if test 4146 -ne `wc -c <death.c`; then
    echo shar: \"death.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f defs.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"defs.h\"
else
echo shar: Extracting \"defs.h\" \(3997 characters\)
sed "s/^X//" >defs.h <<'END_OF_defs.h'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#define MAXPLAYER 16
X#define MAXPLANETS 40
X#define MAXTORP 12
X#define PKEY 257
X
X/* These are configuration definitions */
X
X#define GWIDTH 100000   /* galaxy is 100000 spaces on a side */
X#define WARP1 20	/* warp one will move 20 spaces per update */
X#define SCALE 40	/* Window will be one pixel for 20 spaces */
X#define EXPDIST 400	/* At this range a torp will explode */
X#define DETDIST 2500	/* At this range a player can detonate a torp */
X#define PHASEDIST 6000	/* At this range a player can do damage with phasers */
X#define ENTORBDIST 900	/* At this range a player can orbit a planet */
X#define ORBDIST 800	/* A player will orbit at this radius */
X#define ORBSPEED 2	/* This is the fastest a person can go into orbit */
X#define PFIREDIST 1500	/* At this range a planet will shoot at a player */
X#define UPDATE 100000	/* Update time is 100000 micro-seconds */
X#define AUTOQUIT 60	/* auto logout in 60 secs */
X
X
X/* These are memory sections */
X#define PLAYER 1
X#define MAXMESSAGE 50
X
X#define rosette(x)	((((x) + 256/VIEWS/2) / (256/VIEWS)) % VIEWS)
X
X/* These are the teams */
X/* Note that I used bit types for these mostly for messages and
X   war status.  This was probably a mistake.  It meant that Ed
X   had to add the 'remap' area to map these (which are used throughout
X   the code as the proper team variable) into a nice four team deep
X   array for his color stuff.  Oh well.
X*/
X#define NOBODY 0x0
X#define FED 0x1
X#define ROM 0x2
X#define KLI 0x4
X#define ORI 0x8
X#define ALLTEAM (FED|ROM|KLI|ORI)
X#define MAXTEAM (ORI)
X#define NUMTEAM 4
X/*
X** These are random configuration variables
X*/
X#define VICTORY 30	/* Number of planets needed to conquer the galaxy */
X#define WARNTIME 30	/* Number of updates to have a warning on the screen */
X#define MESSTIME 30	/* Number of updates to have a message on the screen */
X
X#define TARG_PLAYER	0x1	/* Flags for gettarget */
X#define TARG_PLANET	0x2
X#define TARG_CLOAK	0x4	/* Include cloaked ships in search */
X
X/* Data files to make the game play across daemon restarts. */
X
X/* #define DIR		"/eros/staff/chris/nt */
X#define DIR		"/usr/games/lib/xtrek
X
X#define PLFILE		DIR/.planets"
X#define SCOREFILE	DIR/.scores"
X#define MOTD		DIR/.motd"
X#define DAEMON		DIR/daemon"
X#define ROBOT		DIR/robot"
X
X/* Other stuff that Ed added */
X
X#define ABS(a)			/* abs(a) */ (((a) < 0) ? -(a) : (a))
X
X#define myTorp(t)		(me->p_no == (t)->t_owner)
X#define friendlyTorp(t)		((!(me->p_team & (t)->t_war)) || (myTorp(t)))
X#define myPhaser(p)		(&phasers[me->p_no] == (p))
X#define friendlyPhaser(p)	(me->p_team == players[(p) - phasers].p_team)
X#define myPlayer(p)		(me == (p))
X#define myPlanet(p)		(me->p_team == (p)->pl_owner)
X#define friendlyPlayer(p)	((!(me->p_team & \
X				    ((p)->p_swar | (p)->p_hostile))) && \
X				    (!((p)->p_team & \
X				    (me->p_swar | me->p_hostile))))
X#define isAlive(p)		((p)->p_status == PALIVE)
X#define friendlyPlanet(p)	((p)->pl_info & me->p_team && \
X			     !((p)->pl_owner & (me->p_swar | me->p_hostile)))
X
X#define torpColor(t)		\
X	(myTorp(t) ? myColor : shipCol[remap[players[(t)->t_owner].p_team]])
X#define phaserColor(p)		\
X	(myPhaser(p) ? myColor : shipCol[remap[players[(p) - phasers].p_team]])
X#define playerColor(p)		\
X	(myPlayer(p) ? myColor : shipCol[remap[(p)->p_team]])
X#define planetColor(p)		\
X	(((p)->pl_info & me->p_team) ? shipCol[remap[(p)->pl_owner]] : unColor)
X
X#define planetFont(p)		\
X	(myPlanet(p) ? bfont : friendlyPlanet(p) ? ifont : dfont)
X#define shipFont(p)		\
X	(myPlayer(p) ? bfont : friendlyPlayer(p) ? ifont : dfont)
END_OF_defs.h
if test 3997 -ne `wc -c <defs.h`; then
    echo shar: \"defs.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f dmessage.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"dmessage.c\"
else
echo shar: Extracting \"dmessage.c\" \(1623 characters\)
sed "s/^X//" >dmessage.c <<'END_OF_dmessage.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xdmessage()
X{
X    struct message *cur;
X    char buf[80];
X
X    if (messpend)
X	return;
X    if (mctl->mc_current == lastm) {
X	if (mdisplayed) {
X	    XPixSet(messagew, 5, 5, dfontinfo->width * lastcount,
X		dfontinfo->height, backColor);
X	    mdisplayed = 0;
X	}
X	return;
X    }
X    do {
X	if (++lastm >= MAXMESSAGE)
X	    lastm = 0;
X	cur = &messages[lastm];
X	if (cur->m_flags & MVALID) {
X	    if ((cur->m_flags & MALL) ||
X		((cur->m_flags & MTEAM) && (cur->m_recpt & me->p_team)) ||
X		((cur->m_flags & MINDIV) && (cur->m_recpt == me->p_no))) {
X		    if (mdisplayed) {
X			XPixSet(messagew, 5, 5, dfontinfo->width * lastcount,
X			    dfontinfo->height, backColor);
X			mdisplayed = 0;
X		    }
X		    (void) sprintf(buf, "%s", cur->m_data);
X		    lastcount = strlen(buf);
X		    if (lastcount > 80)
X			lastcount = 80;
X		    XText(messagew, 5, 5, buf, lastcount, dfont,
X			textColor, backColor);
X		    XFeep(0);
X		    mdisplayed = 1;
X		    XFlush();
X		    return;
X	    }
X	}
X    } while (lastm != mctl->mc_current);
X}
END_OF_dmessage.c
if test 1623 -ne `wc -c <dmessage.c`; then
    echo shar: \"dmessage.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f enter.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"enter.c\"
else
echo shar: Extracting \"enter.c\" \(3429 characters\)
sed "s/^X//" >enter.c <<'END_OF_enter.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#include <sys/shm.h>
X#include <errno.h>
X#include <pwd.h>
X#include <string.h>
X#include <ctype.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
X/* Enter the game */
X
Xlong random();
X
Xenter(tno, disp, pno)
Xint tno;
Xchar	*disp;
Xint pno;
X{
X    struct passwd	*pwent, *getpwuid();
X    char	 	*pseudo;
X    char		buf[80];
X
X    if ((pwent = getpwuid(getuid())) == NULL)
X	(void) strncpy(me->p_login, "Bozo", sizeof (me->p_login));
X    else
X	(void) strncpy(me->p_login, pwent->pw_name, sizeof (me->p_login));
X    pseudo = XGetDefault("xtrek", "name");
X    if (pseudo == NULL)
X	(void) strncpy(me->p_name, me->p_login, sizeof (me->p_name));
X    else
X	(void) strncpy(me->p_name, pseudo, sizeof (me->p_name));
X    me->p_no = pno;
X    me->p_updates = 0;
X    me->p_flags = PFSHIELD;
X    (void) strncpy(me->p_monitor, disp, sizeof (me->p_monitor));
X    me->p_dir = 0;
X    me->p_desdir = 0;
X    me->p_speed = 0;
X    me->p_desspeed = 0;
X    me->p_subspeed = 0;
X    me->p_team = (1 << tno);
X    me->p_x = planets[tno * 10].pl_x + (random() % 10000) - 5000;
X    me->p_y = planets[tno * 10].pl_y + (random() % 10000) - 5000;
X    me->p_ntorp = 0;
X    me->p_damage = 0;
X    me->p_subdamage = 0;
X    me->p_etemp = 0;
X    me->p_etime = 0;
X    me->p_wtemp = 0;
X    me->p_wtime = 0;
X    me->p_shield = 100;
X    me->p_subshield = 0;
X    me->p_swar = 0;
X    me->p_hostile = (FED|ROM|KLI|ORI);
X    me->p_hostile &= ~me->p_team;
X    me->p_kills = 0.0;
X    me->p_armies = 0;
X
X    sprintf(buf, "%c%x", teamlet[me->p_team], me->p_no);
X    strncpy(me->p_mapchars, buf, 2);
X
X    getship(myship);
X    mystats->st_entries++;
X    me->p_fuel = myship->s_maxfuel;
X    delay = 0;
X}
X
Xopenmem()
X{
X    extern int errno;
X    int	shmemKey = PKEY;
X    int	shmid;
X    struct memory	*sharedMemory;
X
X    errno = 0;
X    shmid = shmget(shmemKey, 0, 0);
X    if (shmid < 0) {
X	if (errno != ENOENT) {
X	    perror("shmget");
X	    exit(1);
X	}
X	startdaemon();
X	sleep(2);
X	shmid = shmget(shmemKey, 0, 0);
X	if (shmid < 0) {
X	    fprintf(stderr, "Daemon not running\n");
X	    exit (1);
X	}
X    }
X    sharedMemory = (struct memory *) shmat(shmid, 0, 0);
X    if (sharedMemory == (struct memory *) -1) {
X	perror("shared memory");
X	exit (1);
X    }
X    players = sharedMemory->players;
X    torps = sharedMemory->torps;
X    status = sharedMemory->status;
X    planets = sharedMemory->planets;
X    phasers = sharedMemory->phasers;
X    mctl = sharedMemory->mctl;
X    messages = sharedMemory->messages;
X}
X
Xfindslot()
X{
X    register int i;
X
X    for (i = 0; i < MAXPLAYER; i++) {
X	if (players[i].p_status == PFREE) {	/* We have a free slot */
X	    players[i].p_status = POUTFIT;	/* possible race code */
X	    break;
X	}
X    }
X    if (i == MAXPLAYER) {
X	fprintf(stderr, "No more room in game\n");
X	exit (0);
X    }
X    bzero(&players[i].p_stats, sizeof(struct stats));  /* Slight problem for
X							  copilot */
X    return(i);
X}
END_OF_enter.c
if test 3429 -ne `wc -c <enter.c`; then
    echo shar: \"enter.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f interface.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"interface.c\"
else
echo shar: Extracting \"interface.c\" \(2542 characters\)
sed "s/^X//" >interface.c <<'END_OF_interface.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X/* This file will include all the interfaces between the input routines
X    and the daemon.  They should be useful for writing robots and the
X    like */
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xset_speed(speed)
Xint speed;
X{
X    me->p_desspeed = speed;
X    me->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
X}
X
Xset_course(dir)
Xunsigned char dir;
X{
X    me->p_desdir = dir;
X    me->p_flags &= ~(PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
X}
X
Xshield_up()
X{
X    me->p_flags |= PFSHIELD;
X    me->p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
X}
X
Xshield_down()
X{
X    me->p_flags &= ~PFSHIELD;
X}
X
Xshield_tog()
X{
X    me->p_flags ^= PFSHIELD;
X    me->p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
X}
X
Xbomb_planet()
X{
X    if (!(me->p_flags & PFORBIT)) {
X	warning("Must be orbiting to bomb");
X	return;
X    }
X    me->p_flags |= PFBOMB;
X    me->p_flags &= ~(PFSHIELD | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
X}
X
Xbeam_up()
X{
X    if (!(me->p_flags & PFORBIT)) {
X	warning("Must be orbiting to beam up.");
X	return;
X    }
X    if (me->p_team != planets[me->p_planet].pl_owner) {
X	warning("Those aren't our men.");
X	return;
X    }
X    me->p_flags |= PFBEAMUP;
X    me->p_flags &= ~(PFSHIELD | PFREPAIR | PFBOMB | PFBEAMDOWN);
X}
X
Xbeam_down()
X{
X    if (!(me->p_flags & PFORBIT)) {
X	warning("Must be orbiting to beam down.");
X	return;
X    }
X    me->p_flags |= PFBEAMDOWN;
X    me->p_flags &= ~(PFSHIELD | PFREPAIR | PFBOMB | PFBEAMUP);
X}
X
Xrepair()
X{
X    me->p_desspeed = 0;
X    me->p_flags |= PFREPAIR;
X    me->p_flags &= ~(PFSHIELD | PFBOMB | PFBEAMUP | PFBEAMDOWN);
X}
X
Xrepair_off()
X{
X    me->p_flags &= ~PFREPAIR;
X}
X
X/*
Xcase 'Q':
X    me->p_flags |= PFSELFDEST;
X    selfdest = me->p_updates + 100;
X    warning("Self destruct initiated");
X    return;
X*/
X
Xrepeat_message()
X{
X    if (++lastm == MAXMESSAGE) ;
X	lastm = 0;
X}
X
Xcloak()
X{
X    me->p_flags ^= PFCLOAK;
X}
X
Xcloak_on()
X{
X    me->p_flags |= PFCLOAK;
X}
X
Xcloak_off()
X{
X    me->p_flags &= ~PFCLOAK;
X}
END_OF_interface.c
if test 2542 -ne `wc -c <interface.c`; then
    echo shar: \"interface.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f orbit.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"orbit.c\"
else
echo shar: Extracting \"orbit.c\" \(1552 characters\)
sed "s/^X//" >orbit.c <<'END_OF_orbit.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X
X#include <stdio.h>
X#include <math.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#include <sys/shm.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
X/* orbit a planet */
X
Xorbit()
X{
X    register int i;
X    register struct planet *l;
X    unsigned char dir;
X    int dx, dy;
X
X    if (me->p_speed > ORBSPEED) {
X	warning("Speed must be less than two to orbit");
X	return;
X    }
X    for (i = 0, l = &planets[i]; i < MAXPLANETS; i++, l++) {
X	dx = ABS(l->pl_x - me->p_x);
X	dy = ABS(l->pl_y - me->p_y);
X	if (dx > ENTORBDIST || dy > ENTORBDIST)		/*XXX*/
X	    continue;
X	if (dx * dx + dy * dy > ENTORBDIST * ENTORBDIST)
X	    continue;
X
X	dir = (unsigned char) (atan2((double) (me->p_x - l->pl_x),
X	    (double) (l->pl_y - me->p_y))
X	    / 3.14159 * 128.);
X	l->pl_info |= me->p_team;
X	me->p_dir = dir + 64;
X	me->p_flags |= PFORBIT;
X	me->p_x = l->pl_x + ORBDIST * Cos[dir];
X	me->p_y = l->pl_y + ORBDIST * Sin[dir];
X	me->p_speed = me->p_desspeed = 0;
X	me->p_planet = l->pl_no;
X	return;
X    }
X    warning("Not close enough to any planet to orbit");
X}
END_OF_orbit.c
if test 1552 -ne `wc -c <orbit.c`; then
    echo shar: \"orbit.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f phaser.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"phaser.c\"
else
echo shar: Extracting \"phaser.c\" \(2487 characters\)
sed "s/^X//" >phaser.c <<'END_OF_phaser.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xphaser(course)
Xunsigned char course;
X{
X    register int i;
X    register struct player *j, *target;
X    register struct phaser *mine;
X    unsigned char dir;
X    int range, trange;
X    char buf[80];
X
X    mine = &phasers[me->p_no];
X
X    if (mine->ph_status != PHFREE) {
X	warning("Phasers have not recharged");
X	return;
X    }
X    if (me->p_fuel < myship->s_phasercost) {
X	warning("Not enough fuel for phaser");
X	return;
X    }
X    if (me->p_flags & PFREPAIR) {
X	warning("Can't fire while repairing");
X	return;
X    }
X    if (me->p_flags & PFWEP) {
X	warning("Weapons overheated");
X	return;
X    }
X    if (me->p_flags & PFCLOAK) {
X	warning("Cannot fire while cloaked");
X	return;
X    }
X
X    me->p_fuel -= myship->s_phasercost;
X    me->p_wtemp += myship->s_phasercost / 10;
X    target = (struct player *) 0;
X    mine->ph_dir = course;
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	if ((j->p_status != PALIVE) || (j == me))
X	    continue;
X	if ((!((j->p_swar | j->p_hostile) & me->p_team)) &&
X	    (!((me->p_swar | me->p_hostile) & j->p_team)))
X		continue;
X	dir = (unsigned char) (atan2((double) (j->p_x - me->p_x),
X	    (double) (me->p_y - j->p_y))
X	    / 3.14159 * 128.);
X	if (angdist(dir, course) < 5) {
X	    trange = (int) hypot((double) (j->p_x - me->p_x),
X		(double) (j->p_y - me->p_y));
X	    if (target == 0) {
X		target = j;
X		range = trange;
X	    }
X	    else if (range > trange) {
X		target = j;
X		range = trange;
X	    }
X	}
X    }
X    if ((target == 0) || (range > PHASEDIST)) {
X	mine->ph_fuse = 10;
X	mine->ph_status = PHMISS;
X	warning("Phaser missed!!!");
X    }
X    else {
X	mine->ph_fuse = 10;
X	mine->ph_target = target->p_no;
X	mine->ph_damage = (PHASEDIST- range) * 100 / PHASEDIST;
X	mine->ph_status = PHHIT;
X	(void) sprintf(buf, "Phaser hit %s for %d points",
X	    target->p_name,
X	    mine->ph_damage);
X	warning(buf);
X    }
X    mystats->st_phasers++;
X}
END_OF_phaser.c
if test 2487 -ne `wc -c <phaser.c`; then
    echo shar: \"phaser.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f planetlist.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"planetlist.c\"
else
echo shar: Extracting \"planetlist.c\" \(1791 characters\)
sed "s/^X//" >planetlist.c <<'END_OF_planetlist.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xstatic char *teamname[9] = {
X    "IND",
X    "FED",
X    "ROM",
X    "",
X    "KLI",
X    "",
X    "",
X    "",
X    "ORI"
X};
X
X/*
X** Open a window which contains all the planets and their current
X** statistics.  Players will not know about planets that their team
X** has not orbited.
X*/
X
Xplanetlist()
X{
X    register int i;
X    register int k = 0;
X    char buf[BUFSIZ];
X    register struct planet *j;
X
X    (void) sprintf(buf, "  # Planet Name      own armies REPAIR FUEL");
X    XText(planetw, 0, dfontinfo->height, buf,
X       strlen(buf), dfont, textColor, backColor);
X    k = 2;
X    for (i = 0, j = &planets[i]; i < MAXPLANETS; i++, j++) {
X	if (j->pl_info & me->p_team) {
X	    (void) sprintf(buf, " %2d %-16s %3s %3d    %6s %4s",
X		j->pl_no,
X		j->pl_name,
X		teamname[j->pl_owner],
X		j->pl_armies,
X		(j->pl_flags & PLREPAIR ? "REPAIR" : "      "),
X		(j->pl_flags & PLFUEL ? "FUEL" : "    "));
X	    XText(planetw, 0, dfontinfo->height * k++, buf, strlen(buf),
X	       planetFont(j), planetColor(j), backColor);
X	}
X	else {
X	    (void) sprintf(buf, " %2d %-16s",
X		j->pl_no,
X		j->pl_name);
X	    XText(planetw, 0, dfontinfo->height * k++, buf, strlen(buf),
X	       dfont, unColor, backColor);
X	}
X    }
X    XFlush();
X}
END_OF_planetlist.c
if test 1791 -ne `wc -c <planetlist.c`; then
    echo shar: \"planetlist.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f planets.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"planets.h\"
else
echo shar: Extracting \"planets.h\" \(3119 characters\)
sed "s/^X//" >planets.h <<'END_OF_planets.h'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X/*
X
Xstruct planet {
X    int pl_no;
X    int pl_status;
X    int pl_owner;
X    int pl_x;
X    int pl_y;
X    char pl_name[16];
X    pl_namelen
X    int pl_armies;
X}
X*/
X
Xstruct planet pdata[MAXPLANETS] = {
X    {  0, (FED|PLHOME|PLFUEL|PLREPAIR), FED, 20000, 80000, "Earth", 5, 30, FED },
X    {  1, FED, FED, 10000, 60000, "Sasus", 5, 30, FED },
X    {  2, FED, FED, 25000, 60000, "Candeleron", 10, 30, FED },
X    {  3, FED, FED, 44000, 81000, "Beta III", 8, 30, FED },
X    {  4, FED, FED, 33000, 55000, "Janus", 5, 30, FED },
X    {  5, FED, FED, 30000, 90000, "Deneb VI", 8, 30, FED },
X    {  6, FED, FED, 45000, 66000, "Ceti IV", 7, 30, FED },
X    {  7, FED, FED, 11000, 75000, "Altar", 5, 30, FED },
X    {  8, FED, FED,  8000, 93000, "Dekar", 5, 30, FED },
X    {  9, FED, FED, 32000, 74000, "Daltus", 6, 30, FED },
X    { 10, (ROM|PLHOME|PLFUEL|PLREPAIR), ROM, 20000, 20000, "Romulus", 7, 30, ROM },
X    { 11, ROM, ROM, 45000,  7000, "Ethen", 5, 30, ROM },
X    { 12, ROM, ROM,  4000, 12000, "Amur", 4, 30, ROM },
X    { 13, ROM, ROM, 42000, 44000, "Remus", 5, 30, ROM },
X    { 14, ROM, ROM, 13000, 45000, "Bal", 3, 30, ROM },
X    { 15, ROM, ROM, 28000,  8000, "Tahndar", 7, 30, ROM },
X    { 16, ROM, ROM, 28000, 23000, "Dact", 4, 30, ROM },
X    { 17, ROM, ROM, 40000, 25000, "Sirius II", 9, 30, ROM },
X    { 18, ROM, ROM, 25000, 44000, "Rakhir", 6, 30, ROM },
X    { 19, ROM, ROM,  8000, 29000, "Rus", 3, 30, ROM },
X    { 20, (KLI|PLHOME|PLFUEL|PLREPAIR), KLI, 80000, 20000, "Klingus", 7, 30, KLI },
X    { 21, KLI, KLI, 70000, 40000, "Malatrakir", 10, 30, KLI },
X    { 22, KLI, KLI, 60000, 10000, "Amakron", 7, 30, KLI },
X    { 23, KLI, KLI, 54000, 40000, "Laltir", 6, 30, KLI },
X    { 24, KLI, KLI, 93000,  8000, "Khartair", 8, 30, KLI },
X    { 25, KLI, KLI, 90000, 37000, "Monpur III", 10, 30, KLI },
X    { 26, KLI, KLI, 69000, 31000, "Sectus", 6, 30, KLI },
X    { 27, KLI, KLI, 83000, 48000, "Makus", 5, 30, KLI },
X    { 28, KLI, KLI, 54000, 21000, "Jakar", 5, 30, KLI },
X    { 29, KLI, KLI, 73000,  5000, "Gendus", 6, 30, KLI },
X    { 30, (ORI|PLHOME|PLFUEL|PLREPAIR), ORI, 80000, 80000, "Orion", 5, 30, ORI },
X    { 31, ORI, ORI, 92000, 59000, "Amterion", 8, 30, ORI },
X    { 32, ORI, ORI, 65000, 55000, "Lumecis", 7, 30, ORI },
X    { 33, ORI, ORI, 52000, 60000, "Bitar V", 7, 30, ORI },
X    { 34, ORI, ORI, 72000, 69000, "Prastan", 7, 30, ORI },
X    { 35, ORI, ORI, 64000, 80000, "Sorlen", 6, 30, ORI },
X    { 36, ORI, ORI, 56000, 89000, "Zetus", 5, 30, ORI },
X    { 37, ORI, ORI, 91000, 94000, "Jih", 3, 30, ORI },
X    { 38, ORI, ORI, 70000, 93000, "Markus II", 9, 30, ORI },
X    { 39, ORI, ORI, 85000, 70000, "Oren", 4, 30, ORI }
X};
END_OF_planets.h
if test 3119 -ne `wc -c <planets.h`; then
    echo shar: \"planets.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f robot.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"robot.c\"
else
echo shar: Extracting \"robot.c\" \(4260 characters\)
sed "s/^X//" >robot.c <<'END_OF_robot.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#ifdef hpux
X#include <time.h>
X#else hpux
X#include <sys/time.h>
X#endif hpux
X#include <signal.h>
X#include <setjmp.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
XWindow mapw;				/* XXX */
X
Xstruct itimerval udt;
Xint redrawall;
Xint lastm;
X
X/* lots of neat flags */
Xint hostile;
Xint debug;
Xint level;
Xint fleet;
Xint sticky;
Xint berserk;
Xint practice;
X
Xchar *rnames[4] = { "M5", "Colossus", "Guardian", "HAL"};
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X    register int i;
X    int rmove();
X    int team = -1;
X    int bteam;
X    int pno;
X    char str[80];
X
X    for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) {
X	switch(argv[1][1]) {
X	    case 'f':
X		fleet++;
X		break;
X	    case 's':
X		sticky++;
X		break;
X	    case 'd':
X		debug++;
X		break;
X	    case 'h':
X		hostile++;
X		break;
X	    case 'p':
X		practice++;
X		break;
X	    case 'b':
X		berserk++;
X		break;
X	    case 'l':
X		if (argv[1][2] != NULL)
X		    level = atoi(&argv[1][2]);
X		else
X		    level = 0;
X		break;
X	    case 'T':
X		switch (argv[1][2]) {
X		    case 'f':
X			team = 0;
X			bteam = FED;
X			break;
X		    case 'r':
X			team = 1;
X			bteam = ROM;
X			break;
X		    case 'k':
X			team = 2;
X			bteam = KLI;
X			break;
X		    case 'o':
X			team = 3;
X			bteam = ORI;
X			break;
X		    default:
X			fprintf(stderr, "Unknown team type.  Usage -Tx where x is [frko]\n");
X			exit(1);
X		}
X		break;
X	    default:
X		fprintf(stderr, "Unknown option '%c'\n", argv[1][1]);
X		exit(1);
X	}
X
X
X    }
X    srandom(getpid() * time((long *) 0));
X    if (team < 0 || team >= 4) {
X	if (debug)
X	    fprintf(stderr, "Choosing random team.\n");
X	team = random() % 4;
X    }
X    openmem();
X    pno = findslot();
X    me = &players[pno];
X    myship = &me->p_ship;
X    mystats = &me->p_stats;
X    lastm = mctl->mc_current;
X    /* At this point we have memory set up.  If we aren't a fleet, we don't
X       want to replace any other robots on this team, so we'll check the
X       other players and get out if there are any on our team.
X    */
X
X    if (!fleet) {
X	for (i = 0; i < MAXPLAYER; i++) {
X	    if ((players[i].p_status == PALIVE) && (players[i].p_team == bteam)) {
X		if (debug)
X		    fprintf(stderr, "Galaxy already defended\n");
X		players[pno].p_status = PFREE;
X		exit(1);
X	    }
X	}
X    }
X    enter(team, "Nowhere", pno);
X    if (berserk)
X	me->p_hostile = (FED|ROM|KLI|ORI);	/* unless they are berserk */
X    else if (practice)
X	me->p_hostile = bteam;			/* or practice */
X    else
X	me->p_hostile = 0;			/* robots are peaceful */
X
X    signal(SIGALRM, rmove);
X    me->p_flags |= PFROBOT;			/* Mark as a robot */
X    if (practice)
X	me->p_flags |= PFPRACTR;		/* Mark as a practice robot */
X    if (practice) {
X	strncpy(me->p_name, "Hoser", strlen("Hoser"));
X	me->p_name[strlen("Hoser")] = NULL;
X    }
X    else {
X	strncpy(me->p_name, rnames[team], strlen(rnames[team]));
X	me->p_name[strlen(rnames[team])] = NULL;
X    }
X    strncpy(me->p_login, "Robot", strlen("Robot"));
X    me->p_login[strlen("Robot")] = NULL;
X    myship->s_phasercost = 0;
X    myship->s_torpcost = 0;
X    myship->s_cloakcost = 0;
X    if (practice) {
X	udt.it_interval.tv_sec = 1;		/* Robots get to move 1/sec */
X	udt.it_interval.tv_usec = 000000;
X    }
X    else {
X	udt.it_interval.tv_sec = 0;		/* Robots get to move 2/sec */
X	udt.it_interval.tv_usec = 500000;
X    }
X    udt.it_value.tv_sec = 1;
X    udt.it_value.tv_usec = 0;
X    if (setitimer(ITIMER_REAL, &udt, 0) < 0) {
X	perror("setitimer");
X	me->p_status = PFREE;		/* Put robot in game */
X	exit(1);
X    }
X    /* allows robots to be forked by the daemon -- Evil ultrix bullshit */
X    sigsetmask(0);
X
X    me->p_status = PALIVE;		/* Put robot in game */
X    while (1) {
X	pause();
X    }
X}
X
Xwarning(mess)
Xint mess;
X{
X    if (debug)
X	fprintf(stderr, "warning: %s\n", mess);
X}
END_OF_robot.c
if test 4260 -ne `wc -c <robot.c`; then
    echo shar: \"robot.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f scores.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"scores.c\"
else
echo shar: Extracting \"scores.c\" \(1606 characters\)
sed "s/^X//" >scores.c <<'END_OF_scores.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/file.h>
X#include <pwd.h>
X#include "defs.h"
X#include "struct.h"
X
X#define MAXENT 2000
X
Xstruct stats old;
X
Xmain()
X{
X    int fd;
X    register int i;
X    struct passwd *buf;
X
X    fd = open(SCOREFILE, O_RDONLY, 0777);
X    if (fd < 0) {
X	perror(SCOREFILE);
X	exit(1);
X    }
X    fprintf(stdout, "Name      rtime             cpu       kills  maxkills    losses  entries conqs coups     torps  phasers    abomb aship planets gens ratio Name\n");
X
X    for (i = 0; i < MAXENT; i++) {
X	if (read(fd, &old, sizeof(struct stats)) == 0)
X	    break;
X	if (old.st_entries > 0) {
X	    buf = getpwuid(i);
X	    if (buf <= 0)
X		continue;
X	    fprintf(stdout, "%-8s %15d %6d %11.2f    %6.2f %9d %8d %5d %5d %9d %8d %8d %5d %7d %4d %5.3f %-8s\n",
X		buf->pw_name,
X		old.st_time,
X		old.st_cpu,
X		old.st_kills,
X		old.st_maxkills,
X		old.st_losses,
X		old.st_entries,
X		old.st_conqs,
X		old.st_coups,
X		old.st_torps,
X		old.st_phasers,
X		old.st_armsbomb,
X		old.st_armsship,
X		old.st_planets,
X		old.st_genocides,
X		(old.st_losses ? old.st_kills / old.st_losses : 0.0),
X		buf->pw_name);
X
X	}
X    }
X}
END_OF_scores.c
if test 1606 -ne `wc -c <scores.c`; then
    echo shar: \"scores.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f startdaemon.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"startdaemon.c\"
else
echo shar: Extracting \"startdaemon.c\" \(1571 characters\)
sed "s/^X//" >startdaemon.c <<'END_OF_startdaemon.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include <stdio.h>
X#include <X/Xlib.h>
X#include <sys/types.h>
X#include <signal.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
Xstartdaemon()
X{
X    int i;
X
X    i = fork();
X    if (i == 0) {
X	XCloseDisplay(display);
X	execl(DAEMON, "daemon", 0);
X	perror(DAEMON);
X	fprintf(stderr, "Couldn't start daemon!!!\n");
X	_exit(1);
X    }
X}
X
Xpractice_robo()
X{
X    char *arg1;
X    register int i;
X    register struct player *j;
X
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	if (j->p_status != PALIVE)
X	    continue;
X	if (j == me)
X	    continue;
X	warning("Can't send in practice robot with other players in the game.");
X	return;
X    }
X
X    if (fork() == 0) {
X	(void) signal(SIGALRM, SIG_DFL);
X	(void) close(0);
X	(void) close(1);
X	(void) close(2);
X	(void) close(dpyno());
X	switch (me->p_team) {
X	    case FED:
X		arg1 = "-Tf";
X		break;
X	    case ROM:
X		arg1 = "-Tr";
X		break;
X	    case KLI:
X		arg1 = "-Tk";
X		break;
X	    case ORI:
X		arg1 = "-To";
X		break;
X	}
X	execl(ROBOT, "robot", arg1, "-p", "-f", "-h", 0);
X	/* If we get here, we are hosed anyway */
X	_exit(1);
X    }
X}
END_OF_startdaemon.c
if test 1571 -ne `wc -c <startdaemon.c`; then
    echo shar: \"startdaemon.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f torp.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"torp.c\"
else
echo shar: Extracting \"torp.c\" \(2629 characters\)
sed "s/^X//" >torp.c <<'END_OF_torp.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ipc.h>
X#include <sys/shm.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
X/* Launch torp */
X
X/*
X** If a set of given conditions are met, fire a single torp in direction
X** course.  Type is used because robots are allowed to shoot straight.
X** Torps sent with status TMOVE wobble a bit.  TSTRAIGHT torps (fired
X** by robots) move in a straight line.
X**
X** torp->t_fuse is the life of the torpedo.  It is set here based on
X** a random function.  Torps currently live two to five seconds.
X*/
X
Xstatic unsigned short lasttime;
X#define GAP 10
Xlong random();
X
Xntorp(course, type, curtime)
Xunsigned char course;
Xint type;
Xunsigned short curtime;
X{
X    register int i;
X    register struct torp *k;
X
X/* Hose people who use the 't' key bursts.  */
X/* Boy will they be surprised!!! */
X
X    if (me->p_flags & PFWEP) {
X	warning("Weapons overheated");
X	return;
X    }
X    if ((curtime - lasttime) < GAP) {
X	me->p_wtemp += 20;		/* Heat weapons */
X	return;
X    }
X    else {
X	lasttime = curtime;
X    }
X
X    if (me->p_ntorp == MAXTORP) {
X	me->p_wtemp += 10;		/* Heat weapons */
X	warning("Torps limited to 12");
X	return;
X    }
X    if (me->p_fuel < myship->s_torpcost) {
X	warning("Not enough fuel for torp");
X	return;
X    }
X    if (me->p_flags & PFREPAIR) {
X	warning("Can't fire while repairing");
X	return;
X    }
X    if (me->p_flags & PFCLOAK) {
X	warning("Cannot fire while cloaked");
X	return;
X    }
X    me->p_ntorp++;
X    me->p_fuel -= myship->s_torpcost;
X    me->p_wtemp += (myship->s_torpcost / 10) - 10;	/* Heat weapons */
X    for (i = me->p_no * MAXTORP, k = &torps[i];		/* Find a free torp */
X	i < me->p_no * MAXTORP + MAXTORP; i++, k++) {
X	    if (k->t_status == TFREE)
X		break;
X    }
X
X    /* Setup data in new torp */
X
X    k->t_no = i;
X    k->t_status = type;
X    k->t_owner = me->p_no;
X    k->t_team = me->p_team;
X    k->t_x = me->p_x;
X    k->t_y = me->p_y;
X    k->t_dir = course;
X    k->t_damage = myship->s_torpdamage;
X    k->t_speed = myship->s_torpspeed;
X    k->t_war = me->p_hostile | me->p_swar;
X    k->t_fuse = (random() % 30) + 20;
X    mystats->st_torps++;
X}
END_OF_torp.c
if test 2629 -ne `wc -c <torp.c`; then
    echo shar: \"torp.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f util.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"util.c\"
else
echo shar: Extracting \"util.c\" \(3209 characters\)
sed "s/^X//" >util.c <<'END_OF_util.c'
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "struct.h"
X#include "data.h"
X
X/*
X** Provide the angular distance between two angles.
X*/
Xangdist(x, y)
Xunsigned char x, y;
X{
X    register unsigned char res;
X
X    res = ABS(x - y);
X    if (res > 128)
X	return(256 - (int) res);
X    return((int) res);
X}
X
X#define WINSIDE 500
X
X/*
X** Find the object nearest mouse.  Returns a pointer to an
X** obtype structure.  This is used for info and locking on.
X**
X** Because we are never interested in it, this function will
X** never return your own ship as the target.
X**
X** Finally, this only works on the two main windows
X*/
X
Xstatic struct obtype _target;
X
Xstruct obtype *
Xgettarget(ww, x, y, targtype)
XWindow ww;
Xint x, y;
Xint targtype;
X{
X    register int i;
X    register struct player *j;
X    register struct planet *k;
X    int	g_x, g_y;
X    double dist, closedist;
X
X    if (ww == mapw) {
X	g_x = x * GWIDTH / WINSIDE;
X	g_y = y * GWIDTH / WINSIDE;
X    }
X    else {
X	g_x = me->p_x + ((x - WINSIDE/2) * SCALE);
X	g_y = me->p_y + ((y - WINSIDE/2) * SCALE);
X    }
X    closedist = GWIDTH;
X
X    if (targtype & TARG_PLANET) {
X	for (i = 0, k = &planets[i]; i < MAXPLANETS; i++, k++) {
X	    dist = hypot((double) (g_x - k->pl_x), (double) (g_y - k->pl_y));
X	    if (dist < closedist) {
X		_target.o_type = PLANETTYPE;
X		_target.o_num = i;
X		closedist = dist;
X	    }
X
X	}
X    }
X
X    if (targtype & TARG_PLAYER) {
X	for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	    if (j->p_status != PALIVE)
X		continue;
X	    if ((j->p_flags & PFCLOAK) && (!(targtype & TARG_CLOAK)))
X		continue;
X	    if (j == me)
X		continue;
X	    dist = hypot((double) (g_x - j->p_x), (double) (g_y - j->p_y));
X	    if (dist < closedist) {
X		_target.o_type = PLAYERTYPE;
X		_target.o_num = i;
X		closedist = dist;
X	    }
X	}
X    }
X
X    if (closedist == GWIDTH) {		/* Didn't get one.  bad news */
X	_target.o_type = PLAYERTYPE;
X	_target.o_num = me->p_no;	/* Return myself.  Oh well... */
X	return(&_target);
X    }
X    else {
X	return(&_target);
X    }
X}
X
X/*
X** Tell us if a window is currently visible on the screen
X*/
X
Xismapped(win)
XWindow win;
X{
X    WindowInfo info;
X    
X    XQueryWindow(win, &info);
X
X    return (info.mapped == IsMapped);
X}
X
X#ifdef hpux
X
Xsrandom(foo)
Xint foo;
X{
X    rand(foo);
X}
X
Xrandom()
X{
X    return(rand());
X}
X
X#include <time.h>
X#include <sys/resource.h>
X
Xgetrusage(foo, buf)
Xint foo;
Xstruct rusage *buf;
X{
X    buf->ru_utime.tv_sec = 0;
X    buf->ru_stime.tv_sec = 0;
X}
X
X#include <sys/signal.h>
X
Xint (*
Xsignal(sig, funct))()
Xint sig;
Xint (*funct)();
X{
X    struct sigvec vec, oldvec;
X
X    sigvector(sig, 0, &vec);
X    vec.sv_handler = funct;
X    sigvector(sig, &vec, (struct sigvec *) 0);
X}
X#endif hpux
END_OF_util.c
if test 3209 -ne `wc -c <util.c`; then
    echo shar: \"util.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 5 \(of 6\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0