v02i039: multiplayer startrek game, Part05/07

Mike Wexler mikew at wyse.wyse.com
Fri Dec 9 12:00:53 AEST 1988


Submitted-by: ddickey at gonzo.eta.com (Dan A. Dickey)
Posting-number: Volume 2, Issue 39
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 7)."
# Contents:  defs.h inform.c minisubs.c sintab.c smessage.c struct.h
#   trigtab.c
# Wrapped by mikew at wyse on Thu Dec  8 17:51:42 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'defs.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'defs.h'\"
else
echo shar: Extracting \"'defs.h'\" \(5962 characters\)
sed "s/^X//" >'defs.h' <<'END_OF_FILE'
X/* static char sccsid[] = "@(#)defs.h	1.1"; */
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 "xtrekfont.h"
X
X#define	PROGRAM_NAME	"xtrek"
X
X#define MAXPLAYER 16
X#define MAXPLANETS 40
X#define MAXTORP 12
X
X/* These are configuration definitions */
X
X/* Timing */
X#define UPDATE 200000			/* Update time is 200000 us */
X#define UPS (1000000/UPDATE)
X#define WARP1 (200 / UPS) 		/* warp 1 moves 200 spaces per sec */
X#define DEATHTIME (6 * UPS) 		/* Player is dead for 6 seconds */
X#define PFIRETIME (1 * UPS) 		/* Phaser fires for 1 second */
X#define TFIREMIN (3 * UPS) 		/* Torp lives at least 3 sec */
X#define TFIREVAR (6 * UPS)		/* Torp may live up to 6 more sec */
X#define TEXPTIME (1 * UPS)		/* Torp explodes for 1 sec */
X#define PEXPTIME (1 * UPS)		/* Player explodes for 1 sec */
X#define PWEAPCOOL (20 / UPS)		/* Weapons cool 20 per sec */
X#define PWEAPLOCKMIN (10 * UPS)		/* Weapons lock for at least 10 sec */
X#define PWEAPLOCKVAR (15 * UPS)		/* Weapons may lock for 15 sec more */
X#define PENGCOOL (50 / UPS)		/* Engines cool 50 per sec */
X#define PENGLOCKMIN (10 * UPS) 		/* Engines lock for at least 10 sec */
X#define PENGLOCKVAR (15 * UPS) 		/* Engines may lock for 15 sec more */
X#define PREFUEL (20 / UPS)		/* Fuel recharges per sec */
X#define PREPAIR (10 / UPS)		/* Repairs per sec */
X#define PCLOAKRATE (10 / UPS)		/* Cloak cost per sec */
X#define PFUELRATE (10 / UPS)		/* Engine cost per sec */
X#define PTURNRATE (10 / UPS)		/* Turns per sec */
X#define PACCELRATE (10 / UPS)		/* Accelerations per sec */
X#define PSELFDESTTIME (10 * UPS)	/* Self destruct in 10 sec */
X#define RGIVEUPTIME (60 * UPS)		/* Robot gives up in 60 sec */
X#define ORBSPEED 2	/* This is the fastest a person can go into orbit */
X
X/* Space */
X#define GWIDTH 100000   /* galaxy is 100000 spaces on a side */
X#define SCALE 40	/* Window will be one pixel for this many 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 TDAMDIST 1500   /* At this range a torp does damage when it explodes */
X#define ORBDIST 900	/* At this range a player can orbit a planet */
X#define PFIREDIST 1500	/* At this range a planet will shoot at a player */
X#define PHITANG 5       /*<not used> Number of degrees that a phaser will hit*/
X#define PHITDIST 400	/* Perpendicular distance at which phaser will hit */
X
X#define AUTOQUIT 60	/* auto logout in 60 secs */
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#define	TARG_MYSELF	0x8	/* Allow myself */
X
X/* Data files to make the game play across daemon restarts. */
X
X#define DIR		"/usr/games/lib/xtrek"
X
X#define PLFILE		"/usr/games/lib/xtrek/.planets"
X#define SCOREFILE	"/usr/games/lib/xtrek/scores"
X#define MOTD		"/usr/games/lib/xtrek/.motd"
X
X#include "struct.h"
X
X/* Other stuff that Ed added */
X
X#define ABS(a)			/* abs(a) */ (((a) < 0) ? -(a) : (a))
X
X#define myTorp(t)		(p->p_no == (t)->t_owner)
X#define friendlyTorp(t)		((!(p->p_team & (t)->t_war)) || (myTorp(t)))
X#define myPhaser(x)		(&phasers[p->p_no] == (x))
X#define friendlyPhaser(x)	(p->p_team == players[(x) - phasers].p_team)
X#define myPlayer(x)		(p == (x))
X#define myPlanet(x)		(p->p_team == (x)->pl_owner)
X#define friendlyPlayer(x)	((!(p->p_team & \
X				    ((x)->p_swar | (x)->p_hostile))) && \
X				    (!((x)->p_team & \
X				    (p->p_swar | p->p_hostile))))
X#define isAlive(x)		((x)->p_status == PALIVE)
X#define friendlyPlanet(x)	((x)->pl_info & p->p_team && \
X			     !((x)->pl_owner & (p->p_swar | p->p_hostile)))
X
X#define torpColor(t)		\
X	(myTorp(t) ? p->myColor : p->shipCol[remap[players[(t)->t_owner].p_team]])
X#define phaserColor(x)		\
X	(myPhaser(x) ? p->myColor : p->shipCol[remap[players[(x) - phasers].p_team]])
X#define playerColor(x)		\
X	(myPlayer(x) ? p->myColor : p->shipCol[remap[(x)->p_team]])
X#define planetColor(x)		\
X	(((x)->pl_info & p->p_team) ? p->shipCol[remap[(x)->pl_owner]] : p->unColor)
X#define mplanetGlyph(x)		\
X	((((x)->pl_info & p->p_team) ? \
X	( p->mono ? remap[(x)->pl_owner] : 0 ) : 0)+MPLANET_GLYPHS)
X#define planetGlyph(x)		\
X	((((x)->pl_info & p->p_team) ? \
X	( p->mono ? remap[(x)->pl_owner] : 0 ) : 0)+PLANET_GLYPHS)
X
X#define planetFont(x)		\
X	(myPlanet(x) ? p->bfont : friendlyPlanet(x) ? p->ifont : p->dfont)
X#define shipFont(x)		\
X	(myPlayer(x) ? p->bfont : friendlyPlayer(x) ? p->ifont : p->dfont)
X
X/* Macros for X11 (nurk) */
X#define fontWidth(f)	((f)->max_bounds.width)
X#define fontHeight(f)	((f)->max_bounds.ascent + (f)->max_bounds.descent)
X
X#define	TRIGSCALE	13	/* trig values are multiplied by 8K */
END_OF_FILE
if test 5962 -ne `wc -c <'defs.h'`; then
    echo shar: \"'defs.h'\" unpacked with wrong size!
fi
# end of 'defs.h'
fi
if test -f 'inform.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'inform.c'\"
else
echo shar: Extracting \"'inform.c'\" \(6803 characters\)
sed "s/^X//" >'inform.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)inform.c	1.1";
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 <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "data.h"
X
X#define WINSIDE 500
X
X/* Display information about the nearest objext to mouse */
X
X/*
X** When the player asks for info, this routine finds the object
X** nearest the mouse, either player or planet, and pop up a window
X** with the desired information in it.
X** 
X** We intentionally provide less information than is actually
X** available.  Keeps the fog of war up.
X**
X** There is a different sized window for each type player/planet
X** and we take care to keep it from extending beyond the main
X** window boundaries.
X*/
X
Xinform(p, ww, x, y)
Xregister struct player	*p;
XWindow ww;
Xint x, y;
X{
X    char buf[BUFSIZ*2];
X    int line = 0;
X    register struct player *j;
X    register struct planet *k;
X    int mx, my;
X    int rx, ry;
X    int		maskr;
X    double dist;
X    Window subw;
X    struct obtype *gettarget(), *target;
X    XWindowAttributes	wa;
X
X    p->infomapped = 1;
X    target = gettarget(p, ww, x, y, TARG_PLAYER|TARG_PLANET|TARG_MYSELF);
X
X    XGetWindowAttributes(p->display, ww, &wa);
X
X    XQueryPointer(p->display, ww, &subw, &subw, &rx, &ry, &mx, &my, &maskr);
X/*    XQueryMouse(ww, &mx, &my, &subw);*/
X
X    if (target->o_type == PLAYERTYPE) {
X	/* Too close to the edge? */
X	if (mx + 23 * fontWidth(p->dfont) + 2 > wa.width)
X	    mx = wa.width - 23 * fontWidth(p->dfont) - 2;
X	if (my + 7 * fontHeight(p->dfont) + 2 > wa.height)
X	    my = wa.height - 7 * fontHeight(p->dfont) - 2;
X
X	p->infow = XCreateWindow(p->display, ww, mx, my, (unsigned) 23 * fontWidth(p->dfont),
X	    (unsigned) 7 * fontHeight(p->dfont), 2, DefaultDepth(p->display, p->screen), InputOutput, (Visual *)CopyFromParent, 0L, (XSetWindowAttributes *)0);
X	XSetWindowBackground(p->display, p->infow, p->backColor);
X	XClearWindow(p->display, p->infow);
X	XMapWindow(p->display, p->infow);
X	j = &players[target->o_num];
X	dist = hypot((double) (p->p_x - j->p_x),
X	    (double) (p->p_y - j->p_y));
X	(void) sprintf(buf, "%s (%c%1x):", j->p_name, 
X		teamlet[j->p_team], j->p_no);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	(void) sprintf(buf, "Login   %-s", j->p_login);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	(void) sprintf(buf, "Display %-s", j->p_monitor);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	(void) sprintf(buf, "Speed   %-d", j->p_speed);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X
X	/*  Too much information.  Let 'em wonder	NOTE: Give info to team members
X	(void) sprintf(buf, "Damage  %-d", j->p_damage);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	(void) sprintf(buf, "Shields %-d", j->p_shield);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	*/
X
X	(void) sprintf(buf, "kills   %-4.2f", j->p_kills);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	(void) sprintf(buf, "dist    %-d", (int) dist);
X	XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	if (j->p_swar & p->p_team)
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, "WAR", 3);
X	else if (j->p_hostile & p->p_team)
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, "HOSTILE", 7);
X	else
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, "PEACEFUL", 8);
X    }
X    else {  /* Planet */
X	/* Too close to the edge? */
X	if (mx + 20 * fontWidth(p->dfont) + 2 > wa.width)
X	    mx = wa.width - 20 * fontWidth(p->dfont) - 2;
X	if (my + 3 * fontHeight(p->dfont) + 2 > wa.height)
X	    my = wa.height - 3 * fontHeight(p->dfont) - 2;
X
X	p->infow = XCreateWindow(p->display, ww, mx, my, (unsigned) 20 * fontWidth(p->dfont),
X	    (unsigned) 3 * fontHeight(p->dfont), 2, DefaultDepth(p->display, p->screen), InputOutput, (Visual *)CopyFromParent, 0L, (XSetWindowAttributes *)0);
X	XSetWindowBackground(p->display, p->infow, p->backColor);
X	XClearWindow(p->display, p->infow);
X	XMapWindow(p->display, p->infow);
X	k = &planets[target->o_num];
X	dist = hypot((double) (p->p_x - k->pl_x),
X	    (double) (p->p_y - k->pl_y));
X	if (k->pl_info & p->p_team) {
X	    (void) sprintf(buf, "%s (%c)", k->pl_name, teamlet[k->pl_owner]);
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	    (void) sprintf(buf, "Armies %d", k->pl_armies);
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	    (void) sprintf(buf, "%s %s  %c%c%c%c",
X		(k->pl_flags & PLREPAIR ? "REPAIR" : "      "),
X		(k->pl_flags & PLFUEL ? "FUEL" : "    "),
X		(k->pl_info & FED ? 'F' : ' '),
X		(k->pl_info & ROM ? 'R' : ' '),
X		(k->pl_info & KLI ? 'K' : ' '),
X		(k->pl_info & ORI ? 'O' : ' '));
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	}
X	else {
X	    (void) sprintf(buf, "%s", k->pl_name);
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	    (void) sprintf(buf, "No other info");
X	    XDrawImageString(p->display, p->infow, p->dfgc, fontWidth(p->dfont),
X		p->dfont->ascent + fontHeight(p->dfont) * line++, buf, strlen(buf));
X	}
X	XFlush(p->display);
X    }
X}
X
X
XdestroyInfo(p)
Xregister struct player	*p;
X{
X    XDestroyWindow(p->display, p->infow);
X    p->infomapped = 0;
X    p->redrawall = 1;
X}
END_OF_FILE
if test 6803 -ne `wc -c <'inform.c'`; then
    echo shar: \"'inform.c'\" unpacked with wrong size!
fi
# end of 'inform.c'
fi
if test -f 'minisubs.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'minisubs.c'\"
else
echo shar: Extracting \"'minisubs.c'\" \(8055 characters\)
sed "s/^X//" >'minisubs.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)minisubs.c	1.1";
X#include <X11/Xlib.h>
X#include "defs.h"
X#include "data.h"
X
Xextern long isin[], icos[];
X
Xcool_weapons(who)
Xregister struct player	*who;
X{
X	who->p_wtemp -= PWEAPCOOL;
X	if (who->p_wtemp < 0)
X		who->p_wtemp = 0;
X	if (who->p_flags & PFWEP) {
X		if (--who->p_wtime <= 0)
X			who->p_flags &= ~PFWEP;
X	} else if (who->p_wtemp > 1000) {
X		if (!(random() % 40)) {
X			who->p_flags |= PFWEP;
X			who->p_wtime = (random() % PWEAPLOCKVAR) + PWEAPLOCKMIN;
X		}
X	}
X}
X
Xcool_engines(who)
Xregister struct player	*who;
X{
X	who->p_etemp -= PENGCOOL;
X	if (who->p_etemp < 0)
X		who->p_etemp = 0;
X	if (who->p_flags & PFENG) {
X		if (--who->p_etime <= 0)
X			who->p_flags &= ~PFENG;
X	} else if (who->p_etemp > 1000) {
X		if (!(random() % 40)) {
X			who->p_flags |= PFENG;
X			who->p_etime = (random() % PENGLOCKVAR) + PENGLOCKMIN;
X			who->p_desspeed = 0;
X		}
X	}
X}
X
Xadd_fuel(who)
Xregister struct player *who;
X{
X	if ((who->p_flags & PFORBIT) && (planets[who->p_planet].pl_flags & PLFUEL) &&
X	    (!(planets[who->p_planet].pl_owner & (who->p_swar | who->p_hostile)))) {
X		who->p_fuel += PREFUEL * 4 * who->p_ship.s_recharge;
X	} else
X		who->p_fuel += PREFUEL * who->p_ship.s_recharge;
X
X	if (who->p_fuel > who->p_ship.s_maxfuel)
X		who->p_fuel = who->p_ship.s_maxfuel;
X	
X	if (who->p_fuel < 0) {
X		who->p_desspeed = 0;
X		who->p_flags &= ~PFCLOAK;	/* should be cloak_off(). */
X	}
X}
X
Xrepair_shields(who)
Xregister struct player *who;
X{
X        if (who->p_shield < 100) {
X          if ((who->p_flags & PFREPAIR) && (who->p_speed == 0)) {
X            who->p_subshield += who->p_ship.s_repair * PREPAIR * 4;
X            if ((who->p_flags & PFORBIT) &&
X                (planets[who->p_planet].pl_flags & PLREPAIR) &&
X                (!(planets[who->p_planet].pl_owner
X                   & (who->p_swar | who->p_hostile)))) {
X                who->p_subshield += who->p_ship.s_repair * PREPAIR * 4;
X              }
X          }
X          else
X            who->p_subshield += who->p_ship.s_repair * PREPAIR * 2;
X
X          if (who->p_subshield / 1000) {
X            who->p_shield += who->p_subshield / 1000;
X            who->p_subshield %= 1000;
X          }
X          if (who->p_shield > 100) {
X            who->p_shield = 100;
X            who->p_subshield = 0;
X          }
X        }
X}
X
Xrepair_damage(who)
Xregister struct player *who;
X{
X        if (who->p_damage && !(who->p_flags & PFSHIELD)) {
X          if ((who->p_flags & PFREPAIR) && (who->p_speed == 0)) {
X            who->p_subdamage += who->p_ship.s_repair * PREPAIR * 2;
X            if ((who->p_flags & PFORBIT) &&
X                (planets[who->p_planet].pl_flags & PLREPAIR) &&
X                (!(planets[who->p_planet].pl_owner
X                   & (who->p_swar | who->p_hostile)))) {
X                who->p_subdamage += who->p_ship.s_repair * PREPAIR * 2;
X              }
X          }
X          else
X            who->p_subdamage += who->p_ship.s_repair * PREPAIR;
X          if (who->p_subdamage / 1000) {
X            who->p_damage -= who->p_subdamage / 1000;
X            who->p_subdamage %= 1000;
X          }
X          if (who->p_damage < 0) {
X            who->p_damage = 0;
X            who->p_subdamage = 0;
X          }
X        }
X}
X
Xcloak_charge(who)
Xregister struct player *who;
X{
X        if (who->p_flags & PFCLOAK) {
X          who->p_fuel -= who->p_ship.s_cloakcost * PCLOAKRATE;
X        }
X}
X
Xplayer_orbit(who)
Xregister struct player *who;
X{
X        if (who->p_flags & PFORBIT) {
X          who->p_dir += 2;
X          who->p_desdir = who->p_dir;
X          who->p_x = planets[who->p_planet].pl_x +
X            ((ORBDIST * icos[(unsigned char) (who->p_dir - (unsigned char) 64)])
X                                                >> TRIGSCALE);
X          who->p_y = planets[who->p_planet].pl_y + 
X            ((ORBDIST * isin[(unsigned char) (who->p_dir - (unsigned char) 64)])
X                                                >> TRIGSCALE);
X        }
X}
X
Xspace_move(who)
Xregister struct player *who;
X{
X	if (!(who->p_flags & PFORBIT)) {
X          if (who->p_dir != who->p_desdir)
X            changedir(who);
X
X          /* Alter speed */
X	  alter_speed(who);
X
X          /* Charge for speed */
X	  charge_speed(who);
X
X	  /* Move them... */
X          who->p_x += (who->p_speed * icos[who->p_dir] * WARP1) >> TRIGSCALE;
X          who->p_y += (who->p_speed * isin[who->p_dir] * WARP1) >> TRIGSCALE;
X
X          /* Bounce off the side of the galaxy */
X          if (who->p_x < 0) {
X            who->p_x = -who->p_x;
X            if (who->p_dir == 192)
X              who->p_dir = who->p_desdir = 64;
X            else
X              who->p_dir = who->p_desdir = 64 - (who->p_dir - 192);
X          } else if (who->p_x > GWIDTH) {
X            who->p_x = GWIDTH - (who->p_x - GWIDTH);
X            if (who->p_dir == 64)
X              who->p_dir = who->p_desdir = 192;
X            else
X              who->p_dir = who->p_desdir = 192 - (who->p_dir - 64);
X          }
X          if (who->p_y < 0) {
X            who->p_y = -who->p_y;
X            if (who->p_dir == 0)
X              who->p_dir = who->p_desdir = 128;
X            else
X              who->p_dir = who->p_desdir = 128 - who->p_dir;
X          } else if (who->p_y > GWIDTH) {
X            who->p_y = GWIDTH - (who->p_y - GWIDTH);
X            if (who->p_dir == 128)
X              who->p_dir = who->p_desdir = 0;
X            else
X              who->p_dir = who->p_desdir = 0 - (who->p_dir - 128);
X          }
X	}
X}
X
X#define YRANGE ((GWIDTH)/5)
X#define RRANGE ((GWIDTH)/10)
X
Xadjust_alert(who)
Xregister struct player *who;
X{
X	register int	k;
X	register int	dx, dy, dist;
X
X        who->p_flags |= PFGREEN;
X        who->p_flags &= ~(PFRED|PFYELLOW);
X        for (k = 0; k < MAXPLAYER; k++) {
X          if ((players[k].p_status != PALIVE) ||
X              (!((who->p_swar | who->p_hostile) & players[k].p_team))) {
X              continue;
X	  } else {
X            dx = who->p_x - players[k].p_x;
X            dy = who->p_y - players[k].p_y;
X            if (ABS(dx) > YRANGE || ABS(dy) > YRANGE)
X              continue;
X            dist = dx * dx + dy * dy;
X            if (dist <  RRANGE * RRANGE) {
X              who->p_flags |= PFRED;
X              who->p_flags &= ~(PFGREEN|PFYELLOW);
X            } else if ((dist <  YRANGE * YRANGE) &&
X                     (!(who->p_flags & PFRED))) {
X                     who->p_flags |= PFYELLOW;
X                     who->p_flags &= ~(PFGREEN|PFRED);
X	    }
X          }
X        }
X}
X
Xalter_speed(who)
Xregister struct player *who;
X{
X	register int	maxspeed;
X
X          maxspeed = 10 - who->p_damage/10;
X          if (who->p_speed > maxspeed && who->p_desspeed > maxspeed)
X            who->p_desspeed = maxspeed;
X          if (who->p_flags & PFENG)
X            who->p_desspeed = 0;
X
X          if (who->p_desspeed > who->p_speed) {
X            who->p_subspeed += who->p_ship.s_accint * PACCELRATE;
X          }
X          if (who->p_desspeed < who->p_speed) {
X            who->p_subspeed -= who->p_ship.s_decint * PACCELRATE;
X          }
X          if (who->p_subspeed / 1000) {
X            who->p_speed += who->p_subspeed / 1000;
X            who->p_subspeed /= 1000;
X            if (who->p_speed < 0)
X              who->p_speed = 0;
X            if (who->p_speed > who->p_ship.s_maxspeed)
X              who->p_speed = who->p_ship.s_maxspeed;
X          }
X}
X
Xcharge_speed(who)
Xregister struct player *who;
X{
X          who->p_fuel -= who->p_ship.s_warpcost * who->p_speed * PFUELRATE;
X          who->p_etemp += who->p_speed * PFUELRATE;
X}
X
Xchangedir(sp)
Xstruct player *sp;
X{
X    int ticks;
X
X    if (sp->p_speed == 0) {
X	sp->p_dir = sp->p_desdir;
X	sp->p_subdir = 0;
X    }
X    else {
X	sp->p_subdir += (sp->p_ship.s_turns * PTURNRATE) / (1 << sp->p_speed);
X	ticks = sp->p_subdir / 1000;
X	if (ticks) {
X	    if (ticks > dirdiff(sp->p_dir, sp->p_desdir))
X		sp->p_dir = sp->p_desdir;
X	    else if ((unsigned char) (sp->p_dir - sp->p_desdir) > 127)
X		sp->p_dir += ticks;
X	    else 
X		sp->p_dir -= ticks;
X	    sp->p_subdir %= 1000;
X	}
X    }
X}
X
Xdirdiff(a, b)
Xunsigned char a, b;
X{
X  unsigned char diff = ABS(a - b);
X  return(diff > 128 ? 256 - diff : diff);
X}
END_OF_FILE
if test 8055 -ne `wc -c <'minisubs.c'`; then
    echo shar: \"'minisubs.c'\" unpacked with wrong size!
fi
# end of 'minisubs.c'
fi
if test -f 'sintab.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'sintab.c'\"
else
echo shar: Extracting \"'sintab.c'\" \(6968 characters\)
sed "s/^X//" >'sintab.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)sintab.c	1.1";
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
Xdouble Sin[] = {
X    -1.0000,
X    -0.9997,
X    -0.9988,
X    -0.9973,
X    -0.9952,
X    -0.9925,
X    -0.9892,
X    -0.9853,
X    -0.9808,
X    -0.9757,
X    -0.9701,
X    -0.9638,
X    -0.9570,
X    -0.9496,
X    -0.9416,
X    -0.9330,
X    -0.9239,
X    -0.9143,
X    -0.9040,
X    -0.8933,
X    -0.8820,
X    -0.8701,
X    -0.8578,
X    -0.8449,
X    -0.8315,
X    -0.8176,
X    -0.8033,
X    -0.7884,
X    -0.7731,
X    -0.7573,
X    -0.7410,
X    -0.7243,
X    -0.7072,
X    -0.6896,
X    -0.6716,
X    -0.6533,
X    -0.6345,
X    -0.6153,
X    -0.5958,
X    -0.5759,
X    -0.5557,
X    -0.5351,
X    -0.5142,
X    -0.4930,
X    -0.4715,
X    -0.4497,
X    -0.4277,
X    -0.4054,
X    -0.3828,
X    -0.3600,
X    -0.3370,
X    -0.3138,
X    -0.2904,
X    -0.2668,
X    -0.2431,
X    -0.2192,
X    -0.1952,
X    -0.1711,
X    -0.1469,
X    -0.1225,
X    -0.0982,
X    -0.0737,
X    -0.0492,
X    -0.0247,
X    -0.0001,
X    0.0244,
X    0.0489,
X    0.0734,
X    0.0979,
X    0.1223,
X    0.1466,
X    0.1708,
X    0.1949,
X    0.2190,
X    0.2428,
X    0.2666,
X    0.2901,
X    0.3135,
X    0.3367,
X    0.3598,
X    0.3825,
X    0.4051,
X    0.4274,
X    0.4495,
X    0.4713,
X    0.4928,
X    0.5140,
X    0.5349,
X    0.5554,
X    0.5757,
X    0.5956,
X    0.6151,
X    0.6343,
X    0.6531,
X    0.6714,
X    0.6894,
X    0.7070,
X    0.7241,
X    0.7408,
X    0.7571,
X    0.7729,
X    0.7882,
X    0.8031,
X    0.8175,
X    0.8314,
X    0.8448,
X    0.8576,
X    0.8700,
X    0.8818,
X    0.8931,
X    0.9039,
X    0.9141,
X    0.9238,
X    0.9329,
X    0.9415,
X    0.9495,
X    0.9569,
X    0.9637,
X    0.9700,
X    0.9757,
X    0.9808,
X    0.9852,
X    0.9891,
X    0.9925,
X    0.9952,
X    0.9973,
X    0.9988,
X    0.9997,
X    1.0000,
X    0.9997,
X    0.9988,
X    0.9973,
X    0.9952,
X    0.9925,
X    0.9892,
X    0.9853,
X    0.9808,
X    0.9757,
X    0.9700,
X    0.9638,
X    0.9569,
X    0.9495,
X    0.9415,
X    0.9330,
X    0.9239,
X    0.9142,
X    0.9040,
X    0.8932,
X    0.8819,
X    0.8701,
X    0.8577,
X    0.8449,
X    0.8315,
X    0.8176,
X    0.8032,
X    0.7884,
X    0.7730,
X    0.7572,
X    0.7410,
X    0.7243,
X    0.7071,
X    0.6896,
X    0.6716,
X    0.6532,
X    0.6344,
X    0.6153,
X    0.5957,
X    0.5758,
X    0.5556,
X    0.5350,
X    0.5141,
X    0.4929,
X    0.4714,
X    0.4496,
X    0.4276,
X    0.4053,
X    0.3827,
X    0.3599,
X    0.3369,
X    0.3137,
X    0.2903,
X    0.2667,
X    0.2430,
X    0.2191,
X    0.1951,
X    0.1710,
X    0.1468,
X    0.1225,
X    0.0981,
X    0.0736,
X    0.0491,
X    0.0246,
X    0.0000,
X    -0.0245,
X    -0.0490,
X    -0.0735,
X    -0.0980,
X    -0.1224,
X    -0.1467,
X    -0.1709,
X    -0.1950,
X    -0.2190,
X    -0.2429,
X    -0.2667,
X    -0.2902,
X    -0.3136,
X    -0.3368,
X    -0.3598,
X    -0.3826,
X    -0.4052,
X    -0.4275,
X    -0.4496,
X    -0.4713,
X    -0.4928,
X    -0.5140,
X    -0.5349,
X    -0.5555,
X    -0.5758,
X    -0.5956,
X    -0.6152,
X    -0.6343,
X    -0.6531,
X    -0.6715,
X    -0.6895,
X    -0.7071,
X    -0.7242,
X    -0.7409,
X    -0.7572,
X    -0.7730,
X    -0.7883,
X    -0.8032,
X    -0.8175,
X    -0.8314,
X    -0.8448,
X    -0.8577,
X    -0.8700,
X    -0.8819,
X    -0.8932,
X    -0.9040,
X    -0.9142,
X    -0.9238,
X    -0.9330,
X    -0.9415,
X    -0.9495,
X    -0.9569,
X    -0.9638,
X    -0.9700,
X    -0.9757,
X    -0.9808,
X    -0.9853,
X    -0.9892,
X    -0.9925,
X    -0.9952,
X    -0.9973,
X    -0.9988,
X    -0.9997
X};
Xdouble Cos[] = {
X    0.0000,
X    0.0245,
X    0.0491,
X    0.0736,
X    0.0980,
X    0.1224,
X    0.1467,
X    0.1710,
X    0.1951,
X    0.2191,
X    0.2430,
X    0.2667,
X    0.2903,
X    0.3137,
X    0.3369,
X    0.3599,
X    0.3827,
X    0.4052,
X    0.4275,
X    0.4496,
X    0.4714,
X    0.4929,
X    0.5141,
X    0.5350,
X    0.5556,
X    0.5758,
X    0.5957,
X    0.6152,
X    0.6344,
X    0.6532,
X    0.6715,
X    0.6895,
X    0.7071,
X    0.7242,
X    0.7409,
X    0.7572,
X    0.7730,
X    0.7883,
X    0.8032,
X    0.8176,
X    0.8315,
X    0.8448,
X    0.8577,
X    0.8701,
X    0.8819,
X    0.8932,
X    0.9040,
X    0.9142,
X    0.9239,
X    0.9330,
X    0.9415,
X    0.9495,
X    0.9569,
X    0.9638,
X    0.9700,
X    0.9757,
X    0.9808,
X    0.9853,
X    0.9892,
X    0.9925,
X    0.9952,
X    0.9973,
X    0.9988,
X    0.9997,
X    1.0000,
X    0.9997,
X    0.9988,
X    0.9973,
X    0.9952,
X    0.9925,
X    0.9892,
X    0.9853,
X    0.9808,
X    0.9757,
X    0.9700,
X    0.9638,
X    0.9570,
X    0.9495,
X    0.9416,
X    0.9330,
X    0.9239,
X    0.9142,
X    0.9040,
X    0.8933,
X    0.8819,
X    0.8701,
X    0.8578,
X    0.8449,
X    0.8315,
X    0.8176,
X    0.8032,
X    0.7884,
X    0.7731,
X    0.7573,
X    0.7410,
X    0.7243,
X    0.7072,
X    0.6896,
X    0.6716,
X    0.6532,
X    0.6344,
X    0.6153,
X    0.5958,
X    0.5759,
X    0.5556,
X    0.5351,
X    0.5142,
X    0.4930,
X    0.4715,
X    0.4497,
X    0.4276,
X    0.4053,
X    0.3828,
X    0.3600,
X    0.3370,
X    0.3138,
X    0.2904,
X    0.2668,
X    0.2431,
X    0.2192,
X    0.1952,
X    0.1710,
X    0.1468,
X    0.1225,
X    0.0981,
X    0.0737,
X    0.0492,
X    0.0246,
X    0.0001,
X    -0.0244,
X    -0.0490,
X    -0.0735,
X    -0.0979,
X    -0.1223,
X    -0.1466,
X    -0.1709,
X    -0.1950,
X    -0.2190,
X    -0.2429,
X    -0.2666,
X    -0.2902,
X    -0.3136,
X    -0.3368,
X    -0.3598,
X    -0.3826,
X    -0.4051,
X    -0.4275,
X    -0.4495,
X    -0.4713,
X    -0.4928,
X    -0.5140,
X    -0.5349,
X    -0.5555,
X    -0.5757,
X    -0.5956,
X    -0.6151,
X    -0.6343,
X    -0.6531,
X    -0.6715,
X    -0.6895,
X    -0.7070,
X    -0.7242,
X    -0.7409,
X    -0.7571,
X    -0.7729,
X    -0.7883,
X    -0.8031,
X    -0.8175,
X    -0.8314,
X    -0.8448,
X    -0.8577,
X    -0.8700,
X    -0.8819,
X    -0.8932,
X    -0.9039,
X    -0.9142,
X    -0.9238,
X    -0.9329,
X    -0.9415,
X    -0.9495,
X    -0.9569,
X    -0.9637,
X    -0.9700,
X    -0.9757,
X    -0.9808,
X    -0.9853,
X    -0.9892,
X    -0.9925,
X    -0.9952,
X    -0.9973,
X    -0.9988,
X    -0.9997,
X    -1.0000,
X    -0.9997,
X    -0.9988,
X    -0.9973,
X    -0.9952,
X    -0.9925,
X    -0.9892,
X    -0.9853,
X    -0.9808,
X    -0.9757,
X    -0.9701,
X    -0.9638,
X    -0.9570,
X    -0.9496,
X    -0.9416,
X    -0.9330,
X    -0.9239,
X    -0.9143,
X    -0.9041,
X    -0.8933,
X    -0.8820,
X    -0.8702,
X    -0.8578,
X    -0.8449,
X    -0.8316,
X    -0.8177,
X    -0.8033,
X    -0.7884,
X    -0.7731,
X    -0.7573,
X    -0.7411,
X    -0.7244,
X    -0.7072,
X    -0.6897,
X    -0.6717,
X    -0.6533,
X    -0.6345,
X    -0.6154,
X    -0.5958,
X    -0.5759,
X    -0.5557,
X    -0.5351,
X    -0.5142,
X    -0.4930,
X    -0.4715,
X    -0.4498,
X    -0.4277,
X    -0.4054,
X    -0.3828,
X    -0.3601,
X    -0.3371,
X    -0.3138,
X    -0.2905,
X    -0.2669,
X    -0.2432,
X    -0.2193,
X    -0.1953,
X    -0.1711,
X    -0.1469,
X    -0.1226,
X    -0.0982,
X    -0.0737,
X    -0.0493,
X    -0.0247
X};
END_OF_FILE
if test 6968 -ne `wc -c <'sintab.c'`; then
    echo shar: \"'sintab.c'\" unpacked with wrong size!
fi
# end of 'sintab.c'
fi
if test -f 'smessage.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'smessage.c'\"
else
echo shar: Extracting \"'smessage.c'\" \(6205 characters\)
sed "s/^X//" >'smessage.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)smessage.c	1.1";
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 <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include <ctype.h>
X#include "defs.h"
X#include "data.h"
X
X
Xsmessage(p, ichar)
Xregister struct player	*p;
Xchar ichar;
X{
X    register int i;
X
X    if (p->p_umsg.m_pending == 0) {
X	p->p_umsg.m_pending = 1;
X	if (p->mdisplayed) {
X		XFillRectangle(p->display, p->messagew, p->cleargc, 5 + fontWidth(p->dfont), 5,
X		    fontWidth(p->dfont) * p->lastcount, fontHeight(p->dfont));
X	    p->mdisplayed = 0;
X	}
X	/* Put the proper recipient in the window */
X	if (getaddr(p, ichar) < 0) {
X	    /* print error message */
X	    p->p_umsg.m_pending = 0;
X	    return;
X	}
X	XDrawImageString(p->display, p->messagew, p->dfgc, 5 + fontWidth(p->dfont), 5 + p->dfont->ascent,
X	    p->p_umsg.m_addrmsg, UMSGADDRLEN);
X	p->p_umsg.m_lcount = UMSGADDRLEN;
X	return;
X    }
X    switch (ichar) {
X	case '\b':
X	case '\177':
X	    if (--p->p_umsg.m_lcount < UMSGADDRLEN) {
X		p->p_umsg.m_lcount = UMSGADDRLEN;
X		break;
X	    }
X		XFillRectangle(p->display, p->messagew, p->cleargc, 5 + fontWidth(p->dfont) * p->p_umsg.m_lcount, 5,
X		    fontWidth(p->dfont), fontHeight(p->dfont));
X	    break;
X	case '\027':	/* CTRL-w */
X	    i = 0;
X	    /* back up over blanks */
X	    while (--p->p_umsg.m_lcount >= UMSGADDRLEN && isspace(p->p_umsg.m_buf[p->p_umsg.m_lcount - UMSGADDRLEN]))
X		i++;
X	    p->p_umsg.m_lcount++;
X	    /* back up over non-blanks */
X	    while (--p->p_umsg.m_lcount >= UMSGADDRLEN && !isspace(p->p_umsg.m_buf[p->p_umsg.m_lcount - UMSGADDRLEN]))
X		i++;
X	    p->p_umsg.m_lcount++;
X
X	    if (i > 0) {
X		XFillRectangle(p->display, p->messagew, p->cleargc, 5 + fontWidth(p->dfont) * p->p_umsg.m_lcount, 5,
X		    fontWidth(p->dfont) * i, fontHeight(p->dfont));
X	    }
X	    break;
X	case '\025':	/* CTRL-u */
X	case '\030':	/* CTRL-x */
X		    while (--p->p_umsg.m_lcount >= UMSGADDRLEN)
X			XFillRectangle(p->display, p->messagew, p->cleargc, 5 + fontWidth(p->dfont) * UMSGADDRLEN, 5,
X			    fontWidth(p->dfont) * (p->p_umsg.m_lcount - UMSGADDRLEN), fontHeight(p->dfont));
X	       p->p_umsg.m_pending = 0;
X	    break;
X	case '\033':	/* ESC */
X		XFillRectangle(p->display, p->messagew, p->cleargc, 5, 5,
X		    fontWidth(p->dfont) * p->p_umsg.m_lcount,
X		    fontHeight(p->dfont));
X		p->mdisplayed = 0;
X		p->p_umsg.m_pending = 0;
X	    break;
X	case '\r':
X	    p->p_umsg.m_buf[p->p_umsg.m_lcount - UMSGADDRLEN] = 0;
X	    p->p_umsg.m_pending = 0;
X	    switch (p->p_umsg.m_addr) {
X		case 'A':
X		    pmessage(p->p_umsg.m_buf, 0, MALL, p->p_umsg.m_addrmsg);
X		    break;
X		case 'F':
X		case 'f':
X		    pmessage(p->p_umsg.m_buf, FED, MTEAM, p->p_umsg.m_addrmsg);
X		    break;
X		case 'R':
X		case 'r':
X		    pmessage(p->p_umsg.m_buf, ROM, MTEAM, p->p_umsg.m_addrmsg);
X		    break;
X		case 'K':
X		case 'k':
X		    pmessage(p->p_umsg.m_buf, KLI, MTEAM, p->p_umsg.m_addrmsg);
X		    break;
X		case 'O':
X		case 'o':
X		    pmessage(p->p_umsg.m_buf, ORI, MTEAM, p->p_umsg.m_addrmsg);
X		    break;
X		case '0':
X		case '1':
X		case '2':
X		case '3':
X		case '4':
X		case '5':
X		case '6':
X		case '7':
X		case '8':
X		case '9':
X		    pmessage(p->p_umsg.m_buf, p->p_umsg.m_addr - '0', MINDIV, p->p_umsg.m_addrmsg);
X		    break;
X		case 'a':
X		case 'b':
X		case 'c':
X		case 'd':
X		case 'e':
X		    pmessage(p->p_umsg.m_buf, p->p_umsg.m_addr - 'a' - 10, MINDIV, p->p_umsg.m_addrmsg);
X		    break;
X		default:
X		    warning(p, "Not legal recipient");
X	    }
X		XFillRectangle(p->display, p->messagew, p->cleargc, 5, 5,
X		    fontWidth(p->dfont) * p->p_umsg.m_lcount, fontHeight(p->dfont));
X		p->mdisplayed = 0;
X	    p->p_umsg.m_lcount = 0;
X	    break;
X	default:
X	    if (p->p_umsg.m_lcount == UMSGLEN) {
X		XBell(p->display, p->screen);
X		break;
X	    }
X	    if (iscntrl(ichar))
X		break;
X	    XDrawImageString(p->display, p->messagew, p->dfgc, 5 + fontWidth(p->dfont) * p->p_umsg.m_lcount, 5 + p->dfont->ascent,
X			&ichar, 1);
X	    p->p_umsg.m_buf[(p->p_umsg.m_lcount++) - UMSGADDRLEN] = ichar;
X	    break;
X    }
X}
X
Xpmessage(str, recip, group, address)
Xchar *str;
Xint recip;
Xint group;
Xchar *address;
X{
X    struct message *cur;
X    if (++(mctl->mc_current) >= MAXMESSAGE)
X	mctl->mc_current = 0;
X    cur = &messages[mctl->mc_current];
X    cur->m_no = mctl->mc_current;
X    cur->m_flags = group;
X    cur->m_time = 0;
X    cur->m_recpt = recip;
X    (void) sprintf(cur->m_data, "%-9s %s", address, str);
X    cur->m_flags |= MVALID;
X}
X
Xgetaddr(p, who)
Xregister struct player	*p;
Xchar who;
X{
X    p->p_umsg.m_addr = who;
X    (void) sprintf(p->p_umsg.m_addrmsg, " %c%x->", teamlet[p->p_team], p->p_no);
X    switch (who) {
X	case 'A':
X	    (void) sprintf(&p->p_umsg.m_addrmsg[5], "ALL");
X	    break;
X	case 'F':
X	case 'f':
X	    (void) sprintf(&p->p_umsg.m_addrmsg[5], "FED");
X	    break;
X	case 'R':
X	case 'r':
X	    (void) sprintf(&p->p_umsg.m_addrmsg[5], "ROM");
X	    break;
X	case 'K':
X	case 'k':
X	    (void) sprintf(&p->p_umsg.m_addrmsg[5], "KLI");
X	    break;
X	case 'O':
X	case 'o':
X	    (void) sprintf(&p->p_umsg.m_addrmsg[5], "ORI");
X	    break;
X	case '0':
X	case '1':
X	case '2':
X	case '3':
X	case '4':
X	case '5':
X	case '6':
X	case '7':
X	case '8':
X	case '9':
X	    if (isAlive(&players[who - '0'])) {
X		(void) sprintf(&p->p_umsg.m_addrmsg[5], "%c%x ",
X		    teamlet[players[who - '0'].p_team], who - '0');
X	    }
X	    else {
X		warning(p, "Player is not in game");
X		return(-1);
X	    }
X	    break;
X	case 'a':
X	case 'b':
X	case 'c':
X	case 'd':
X	case 'e':
X	    if (isAlive(&players[who - 'a' + 10])) {
X		(void) sprintf(&p->p_umsg.m_addrmsg[5], "%c%x ",
X		    teamlet[players[who - 'a' + 10].p_team], who - 'a' + 10);
X	    }
X	    else {
X		warning(p, "Player is not in game");
X		return(-1);
X	    }
X	    break;
X	default:
X	    warning(p, "Not legal recipient");
X	    return(-1);
X    }
X    return(0);
X}
END_OF_FILE
if test 6205 -ne `wc -c <'smessage.c'`; then
    echo shar: \"'smessage.c'\" unpacked with wrong size!
fi
# end of 'smessage.c'
fi
if test -f 'struct.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'struct.h'\"
else
echo shar: Extracting \"'struct.h'\" \(8746 characters\)
sed "s/^X//" >'struct.h' <<'END_OF_FILE'
X/* static char sccsid[] = "@(#)struct.h	1.1"; */
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
Xstruct status {
X    int active;
X};
X
X#define PFREE 0
X#define POUTFIT 1
X#define PALIVE 2
X#define PEXPLODE 3
X#define PDEAD 4
X#define	PSETUP 5
X
X/* Return values from newwin(): */
X#define	OK		1
X#define	NODISPLAY	2
X#define	NOFONTS		3
X
X#define PFSHIELD	0x0001
X#define PFREPAIR	0x0002
X#define PFBOMB		0x0004
X#define PFORBIT		0x0008
X#define PFCLOAK		0x0010
X#define PFWEP		0x0020
X#define PFENG		0x0040
X#define PFROBOT		0x0080
X#define PFBEAMUP	0x0100
X#define PFBEAMDOWN	0x0200
X#define PFSELFDEST	0x0400
X#define PFGREEN		0x0800
X#define PFYELLOW	0x1000
X#define PFRED		0x2000
X#define PFPLOCK		0x4000		/* Locked on a player */
X#define PFPLLOCK	0x8000		/* Locked on a planet */
X#define PFCOPILOT	0x10000		/* Allow copilots */
X#define PFRHOSTILE	0x20000		/* Hostile robot */
X#define PFRHARD		0x40000		/* hard robot */
X#define	PFRSTICKY	0x80000		/* sticky robot */
X#define	PFSHOWSTATS	0x100000	/* show player statistics */
X#define	PFWAR		0x200000	/* computer reprogramming for war */
X#define	PFENTER		0x400000	/* entry windows showing */
X
X#define KQUIT		0x01		/* Player quit */
X#define KTORP		0x02		/* killed by torp */
X#define KPHASER		0x03		/* killed by phaser */
X#define KPLANET		0x04		/* killed by planet */
X#define KSHIP		0x05		/* killed by other ship */
X#define KDAEMON		0x06		/* killed by dying daemon */
X#define KWINNER		0x07		/* killed by a winner */
X
X#define	UMSGADDRLEN	10		/* user message address length */
X#define	UMSGLEN		80		/* user message length */
X
Xstruct ship {
X    int s_turns;
X    short s_accs;
X    short s_torpdamage;
X    short s_phaserdamage;
X    short s_phasedist;
X    short s_torpspeed;
X    short s_maxspeed;
X    short s_repair;
X    short s_maxfuel;
X    short s_torpcost;
X    short s_phasercost;
X    short s_detcost;
X    short s_warpcost;
X    short s_cloakcost;
X    short s_recharge;
X    int s_accint;
X    int s_decint;
X    short s_maxarmies;
X
X    short s_wcool;
X    short s_ecool;
X    short s_maxdamage;
X    short s_maxshields;
X};
X
Xstruct stats {
X    int st_id;			/* identifier for this stats record */
X    int st_time;		/* real time in game */
X    int st_cpu;			/* cpu time in game */
X    double st_kills;		/* how many kills */
X    int st_losses;		/* times killed */
X    double st_maxkills;		/* times killed */
X    int st_entries;		/* times in game */
X    int st_conqs;		/* times galaxy taken over */
X    int st_coups;		/* retaken home planet */
X    int st_torps;		/* torps launched */
X    int st_phasers;		/* phasers fired */
X    int st_armsbomb;		/* armies bombed */
X    int st_armsship;		/* ship board armies killed */
X    int st_planets;		/* planets conquered */
X    int st_genocides;		/* races genocided */
X};
X
Xtypedef struct record {
X	short	*data;
X	short	last_value;
X} RECORD;
X
Xstruct player {
X    int p_no;
X    int p_updates;		/* Number of updates ship has survived */
X    int p_status;		/* Player status */
X    unsigned long p_flags;	/* Player flags */
X    char p_name[16];
X    char p_login[16];
X    char p_monitor[16];		/* Monitor being played on */
X    char p_mapchars[2];		/* Cache for map window image */
X    struct ship p_ship;		/* Personal ship statistics */
X    int p_x;
X    int p_y;
X    unsigned char p_dir;	/* Real direction */
X    unsigned char p_desdir;	/* desired direction */
X    int p_subdir;		/* fraction direction change */
X    short p_speed;		/* Real speed */
X    short p_desspeed;		/* Desired speed */
X    int p_subspeed;		/* Fractional speed */
X    short p_team;			/* Team I'm on */
X    short p_damage;		/* Current damage */
X    int p_subdamage;		/* Fractional damage repair */
X    short p_shield;		/* Current shield power */
X    int p_subshield;		/* Fractional shield recharge */
X    short p_ntorp;		/* Number of torps flying */
X    char p_hostile;		/* Who my torps will hurt */
X    char p_swar;		/* Who am I at sticky war with */
X    float p_kills;		/* Enemies killed */
X    short p_planet;		/* Planet orbiting or locked onto */
X    short p_playerl;		/* Player locked onto */
X    short p_armies;
X    short p_fuel;
X    short p_explode;		/* Keeps track of final explosion */
X    short p_etemp;
X    short p_etime;
X    short p_wtemp;
X    short p_wtime;
X    short p_timer;		/* General purpose timer */
X    short p_rmode;		/* Robot attack mode */
X    short p_whydead;		/* Tells you why you died */
X    short p_whodead;		/* Tells you who killed you */
X    int p_selfdest;		/* How long until I die. */
X    int mapmode;
X    int namemode;
X    int oldalert;
X    int messpend;
X    int lastcount;
X    int mdisplayed;
X    int redrawall;
X    int watch;
X    int selfdest;
X    int statmode;
X    int showShields;
X    int showStats;
X    int infomapped;	/* NOTE: Only use one of these? */
X    int	infow_on;	/* NOTE: Only use one of these? */
X    int ts_offset;
X    int lastm;
X    int	warntimer;
X    int	warncount;
X    int	newhostile;
X    int	reprogram;
X    int	delay;
X    RECORD	*rp;
X    struct stats p_stats;	/* player statistics */
X    struct usermsg {		/* User message */
X	char m_pending;
X	char m_addr;
X	char m_addrmsg[UMSGADDRLEN];
X	char m_buf[UMSGLEN];
X	int m_lcount;
X    } p_umsg;
X    int	copilot;
X    long	start_time;
X
X    /* X11 stuff: */
X    Display	*display;
X    int		screen;
X    int		xcn;	/* XConnectionNumber() */
X    int		mono;
X    XFontStruct	*dfont, *bfont, *ifont, *xfont, *bigFont;
X    Window	w, mapw, statwin, baseWin, messagew, infow, iconWin, tstatw,
X		war, warf, warr, wark, waro, wargo, warno, warnw, helpWin,
X		planetw, playerw, fwin, rwin, kwin, owin, qwin;
X    GC		gc, bmgc, cleargc, dfgc, bfgc, ifgc, bFgc, xfgc;
X    unsigned long borderColor, backColor, textColor, myColor,
X		warningColor, shipCol[5], rColor, yColor, gColor, unColor;
X    XRectangle	clearzone[(MAXTORP + 1) * MAXPLAYER + MAXPLANETS];
X    int		clearcount;
X    int		clearline[4][MAXPLAYER];
X    int		clearlcount;
X    XRectangle	mclearzone[MAXPLAYER + MAXPLANETS * 2];
X    int		mclearcount;
X    int		textWidth;
X    int		statX;
X    int		statY;
X    int		uspec;
X    GC		sgc;
X    Pixmap	foreTile, backTile, rTile, yTile, gTile, stippleTile;
X    Pixmap	ibm;	/* Icon bitmap */
X    Pixmap	tbm;
X    Window	clockw;
X    int		once;
X    int		oldtime;
X    long	startTime;
X    int		mustexit;
X};
X
X/* Torpedo states */
X
X#define TFREE 0
X#define TMOVE 1
X#define TEXPLODE 2
X#define TDET 3
X#define TOFF 4
X#define TSTRAIGHT 5		/* Non-wobbling torp */
X
Xstruct torp {
X    int t_no;
X    int t_status;		/* State information */
X    int t_owner;
X    int t_x;
X    int t_y;
X    unsigned char t_dir;	/* direction */
X    int t_damage;		/* damage for direct hit */
X    int t_speed;		/* Moving speed */
X    int t_fuse;			/* Life left in current state */
X    char t_war;			/* enemies */
X    char t_team;		/* launching team */
X};
X
X#define PHFREE 0x00
X#define PHHIT  0x01
X#define PHMISS 0x02
X
Xstruct phaser {
X    int ph_status;		/* What it's up to */
X    unsigned char ph_dir;	/* direction */
X    int ph_target;		/* Who's being hit (for drawing) */
X    int ph_fuse;		/* Life left for drawing */
X    int ph_damage;		/* Damage inflicted on victim */
X};
X
X/* An important note concerning planets:  The game assumes that
X    the planets are in a 'known' order.  Ten planets per team,
X    the first being the home planet.
X*/
X
X/* the lower bits represent the original owning team */
X#define PLREPAIR 0x010
X#define PLFUEL 0x020
X#define PLREDRAW 0x040		/* Player close for redraw */
X#define PLHOME 0x080		/* home planet for a given team */
X#define PLCOUP 0x100		/* Coup has occured */
X
Xstruct planet {
X    int pl_no;
X    int pl_flags;		/* State information */
X    int pl_owner;
X    int pl_x;
X    int pl_y;
X    char pl_name[16];
X    int pl_namelen;		/* Cuts back on strlen's */
X    int pl_armies;
X    int pl_info;		/* Teams which have info on planets */
X    int pl_deadtime;		/* Time before planet will support life */
X    int pl_couptime;		/* Time before coup may take place */
X};
X
X#define MVALID 0x01
X#define MINDIV 0x02
X#define MTEAM  0x04
X#define MALL   0x08
X
Xstruct message {
X    int m_no;
X    int m_flags;
X    int m_time;
X    int m_recpt;
X    char m_from[3];
X    char m_to[3];
X    char m_data[80];
X};
X
X/* message control structure */
X
Xstruct mctl {
X    int mc_current;
X};
X
X/* This is a structure used for objects returned by mouse pointing */
X
X#define PLANETTYPE 0x1
X#define PLAYERTYPE 0x2
X
Xstruct obtype {
X    int o_type;
X    int o_num;
X};
END_OF_FILE
if test 8746 -ne `wc -c <'struct.h'`; then
    echo shar: \"'struct.h'\" unpacked with wrong size!
fi
# end of 'struct.h'
fi
if test -f 'trigtab.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'trigtab.c'\"
else
echo shar: Extracting \"'trigtab.c'\" \(7990 characters\)
sed "s/^X//" >'trigtab.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)trigtab.c	1.1";
Xlong isin[] = {
X    -8192,
X    -8189,
X    -8182,
X    -8169,
X    -8152,
X    -8130,
X    -8103,
X    -8071,
X    -8034,
X    -7992,
X    -7947,
X    -7895,
X    -7839,
X    -7779,
X    -7713,
X    -7643,
X    -7568,
X    -7489,
X    -7405,
X    -7317,
X    -7225,
X    -7127,
X    -7027,
X    -6921,
X    -6811,
X    -6697,
X    -6580,
X    -6458,
X    -6333,
X    -6203,
X    -6070,
X    -5933,
X    -5793,
X    -5649,
X    -5501,
X    -5351,
X    -5197,
X    -5040,
X    -4880,
X    -4717,
X    -4552,
X    -4383,
X    -4212,
X    -4038,
X    -3862,
X    -3683,
X    -3503,
X    -3321,
X    -3135,
X    -2949,
X    -2760,
X    -2570,
X    -2378,
X    -2185,
X    -1991,
X    -1795,
X    -1599,
X    -1401,
X    -1203,
X    -1003,
X    -804,
X    -603,
X    -403,
X    -202,
X    0,
X    199,
X    400,
X    601,
X    801,
X    1001,
X    1200,
X    1399,
X    1596,
X    1794,
X    1989,
X    2183,
X    2376,
X    2568,
X    2758,
X    2947,
X    3133,
X    3318,
X    3501,
X    3682,
X    3860,
X    4037,
X    4210,
X    4381,
X    4549,
X    4716,
X    4879,
X    5038,
X    5196,
X    5350,
X    5500,
X    5647,
X    5791,
X    5931,
X    6068,
X    6202,
X    6331,
X    6456,
X    6578,
X    6696,
X    6810,
X    6920,
X    7025,
X    7127,
X    7223,
X    7316,
X    7404,
X    7488,
X    7567,
X    7642,
X    7712,
X    7778,
X    7838,
X    7894,
X    7946,
X    7992,
X    8034,
X    8070,
X    8102,
X    8130,
X    8152,
X    8169,
X    8182,
X    8189,
X    8192,
X    8189,
X    8182,
X    8169,
X    8152,
X    8130,
X    8103,
X    8071,
X    8034,
X    7992,
X    7946,
X    7895,
X    7838,
X    7778,
X    7712,
X    7643,
X    7568,
X    7489,
X    7405,
X    7317,
X    7224,
X    7127,
X    7026,
X    6921,
X    6811,
X    6697,
X    6579,
X    6458,
X    6332,
X    6202,
X    6070,
X    5933,
X    5792,
X    5649,
X    5501,
X    5351,
X    5197,
X    5040,
X    4879,
X    4716,
X    4551,
X    4382,
X    4211,
X    4037,
X    3861,
X    3683,
X    3502,
X    3320,
X    3135,
X    2948,
X    2759,
X    2569,
X    2378,
X    2184,
X    1990,
X    1794,
X    1598,
X    1400,
X    1202,
X    1003,
X    803,
X    602,
X    402,
X    201,
X    0,
X    -200,
X    -401,
X    -602,
X    -802,
X    -1002,
X    -1201,
X    -1400,
X    -1597,
X    -1794,
X    -1989,
X    -2184,
X    -2377,
X    -2569,
X    -2759,
X    -2947,
X    -3134,
X    -3319,
X    -3502,
X    -3683,
X    -3860,
X    -4037,
X    -4210,
X    -4381,
X    -4550,
X    -4716,
X    -4879,
X    -5039,
X    -5196,
X    -5350,
X    -5500,
X    -5648,
X    -5792,
X    -5932,
X    -6069,
X    -6202,
X    -6332,
X    -6457,
X    -6579,
X    -6696,
X    -6810,
X    -6920,
X    -7026,
X    -7127,
X    -7224,
X    -7317,
X    -7405,
X    -7489,
X    -7567,
X    -7643,
X    -7712,
X    -7778,
X    -7838,
X    -7895,
X    -7946,
X    -7992,
X    -8034,
X    -8071,
X    -8103,
X    -8130,
X    -8152,
X    -8169,
X    -8182,
X    -8189
X};
Xlong icos[] = {
X    0,
X    200,
X    402,
X    602,
X    802,
X    1002,
X    1201,
X    1400,
X    1598,
X    1794,
X    1990,
X    2184,
X    2378,
X    2569,
X    2759,
X    2948,
X    3135,
X    3319,
X    3502,
X    3683,
X    3861,
X    4037,
X    4211,
X    4382,
X    4551,
X    4716,
X    4879,
X    5039,
X    5197,
X    5351,
X    5500,
X    5648,
X    5792,
X    5932,
X    6069,
X    6202,
X    6332,
X    6457,
X    6579,
X    6697,
X    6811,
X    6920,
X    7026,
X    7127,
X    7224,
X    7317,
X    7405,
X    7489,
X    7568,
X    7643,
X    7712,
X    7778,
X    7838,
X    7895,
X    7946,
X    7992,
X    8034,
X    8071,
X    8103,
X    8130,
X    8152,
X    8169,
X    8182,
X    8189,
X    8192,
X    8189,
X    8182,
X    8169,
X    8152,
X    8130,
X    8103,
X    8071,
X    8034,
X    7992,
X    7946,
X    7895,
X    7839,
X    7778,
X    7713,
X    7643,
X    7568,
X    7489,
X    7405,
X    7317,
X    7224,
X    7127,
X    7027,
X    6921,
X    6811,
X    6697,
X    6579,
X    6458,
X    6333,
X    6203,
X    6070,
X    5933,
X    5793,
X    5649,
X    5501,
X    5351,
X    5197,
X    5040,
X    4880,
X    4717,
X    4551,
X    4383,
X    4212,
X    4038,
X    3862,
X    3683,
X    3502,
X    3320,
X    3135,
X    2949,
X    2760,
X    2570,
X    2378,
X    2185,
X    1991,
X    1795,
X    1599,
X    1400,
X    1202,
X    1003,
X    803,
X    603,
X    403,
X    201,
X    0,
X    -199,
X    -401,
X    -602,
X    -801,
X    -1001,
X    -1200,
X    -1400,
X    -1597,
X    -1794,
X    -1989,
X    -2183,
X    -2377,
X    -2569,
X    -2759,
X    -2947,
X    -3134,
X    -3318,
X    -3502,
X    -3682,
X    -3860,
X    -4037,
X    -4210,
X    -4381,
X    -4550,
X    -4716,
X    -4879,
X    -5038,
X    -5196,
X    -5350,
X    -5500,
X    -5648,
X    -5791,
X    -5932,
X    -6069,
X    -6202,
X    -6331,
X    -6457,
X    -6578,
X    -6696,
X    -6810,
X    -6920,
X    -7026,
X    -7127,
X    -7224,
X    -7317,
X    -7404,
X    -7489,
X    -7567,
X    -7642,
X    -7712,
X    -7778,
X    -7838,
X    -7894,
X    -7946,
X    -7992,
X    -8034,
X    -8071,
X    -8103,
X    -8130,
X    -8152,
X    -8169,
X    -8182,
X    -8189,
X    -8192,
X    -8189,
X    -8182,
X    -8169,
X    -8152,
X    -8130,
X    -8103,
X    -8071,
X    -8034,
X    -7992,
X    -7947,
X    -7895,
X    -7839,
X    -7779,
X    -7713,
X    -7643,
X    -7568,
X    -7489,
X    -7406,
X    -7317,
X    -7225,
X    -7128,
X    -7027,
X    -6921,
X    -6812,
X    -6698,
X    -6580,
X    -6458,
X    -6333,
X    -6203,
X    -6071,
X    -5934,
X    -5793,
X    -5650,
X    -5502,
X    -5351,
X    -5197,
X    -5041,
X    -4880,
X    -4717,
X    -4552,
X    -4383,
X    -4212,
X    -4038,
X    -3862,
X    -3684,
X    -3503,
X    -3321,
X    -3135,
X    -2949,
X    -2761,
X    -2570,
X    -2379,
X    -2186,
X    -1992,
X    -1796,
X    -1599,
X    -1401,
X    -1203,
X    -1004,
X    -804,
X    -603,
X    -403,
X    -202
X};
X
X
X/*
X** table for computing inverse tangent values
X*/
X
X
Xlong iatan[] = {
X0,
X201,
X402,
X604,
X806,
X1010,
X1215,
X1421,
X1629,
X1839,
X2051,
X2267,
X2485,
X2706,
X2931,
X3160,
X3393,
X3631,
X3874,
X4123,
X4378,
X4640,
X4910,
X5187,
X5473,
X5769,
X6075,
X6393,
X6723,
X7066,
X7424,
X7799,
X8192,
X8604,
X9038,
X9496,
X9981,
X10497,
X11045,
X11631,
X12260,
X12936,
X13667,
X14460,
X15326,
X16274,
X17320,
X18480,
X19777,
X21236,
X22895,
X24797,
X27005,
X29602,
X32704,
X36480,
X41183,
X47211,
X55225,
X66418,
X83174,
X111056,
X166751,
X333705
X};
X
X#include <X11/Xlib.h>
X#include "defs.h"
X
Xunsigned char iatan2(y, x)
Xint x, y;
X{
X  int bottom, top, i;
X  long z, scaled_y;
X
X  scaled_y = y << TRIGSCALE;
X  if (x == 0) i = (y >= 0 ? 64 : 192);
X  else {
X    z = abs(scaled_y/x);
X
X#ifdef DEBUG
X    printf("Looking for closest table value to %ld\n", z);
X#endif DEBUG
X
X    bottom = 0;
X    top = sizeof(iatan)/sizeof(long) - 1;
X
X/*-------------------------------------------------------------------------
X * Loop Invariant: top - bottom > 1    &&   iatan[bottom] < z <= iatan[top]
X * 
X * At end of loop this guarantees:
X * top-bottom <= 1 && top-prev_bottom > 1  ==> top-bottom = 1
X * Also iatan[bottom] < z <= iatan[top].  So we will return the closer of
X * these two values.
X *-------------------------------------------------------------------------
X */
X    while (top-bottom > 1) {
X      i = bottom + ((top-bottom)>>1);
X      if (iatan[i] < z) bottom = i;
X      else top = i;
X    }
X
X    /* Choose the closer of the two values */
X    i = (abs(iatan[top] - z) < abs(iatan[bottom] - z)) ? top : bottom;
X  } /* else */
X 
X#ifdef DEBUG
X      printf("original i: %d; ", i);
X#endif DEBUG
X  if (y == 0) i = (x >= 0) ? 0 : 128;
X  else if (x < 0 && y > 0) i = 128-i;
X  else if (x < 0 && y < 0) i += 128;
X  else if (x > 0 && y < 0) i = 256-i;
X  
X#ifdef DEBUG
X  printf("iatan2(%d, %d) = %d\n", y, x, i);
X#endif DEBUG
X
X  return(i);
X}
X
X/*
X * The isin and icos routines in trigtab.c are made to work in the obscure
X * coordinate system used by xtrek (angles measured from the positive y axis).
X * This routine snags out 1/4 of the isin table and uses it to produce
X * values of the sin function from the normal coordinate system.  This
X * has the advantage of making things like the law of sines work.
X */
Xint
Xnormal_isin(in_angle)
Xunsigned char in_angle;
X{
X  int minus = 1;
X  unsigned char angle = in_angle;
X
X  /* sin(a) = -sin(a-pi) */
X  if (angle > 128) {
X    angle = angle - 128;
X    minus *= -1;
X  }
X  /* sin(a) = sin(pi-a) */
X  if (angle > 64) {
X    angle = 128 - angle;
X  }
X
X  angle = angle + 64; /* stupid isin table is broken */
X  return(isin[angle]);
X}
X
X
X
X
END_OF_FILE
if test 7990 -ne `wc -c <'trigtab.c'`; then
    echo shar: \"'trigtab.c'\" unpacked with wrong size!
fi
# end of 'trigtab.c'
fi
echo shar: End of archive 5 \(of 7\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 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
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x



More information about the Comp.sources.x mailing list