v10i016: xtrek, Part05/11
Dan A. Dickey
ddickey at aspen.cray.com
Wed Oct 24 18:33:54 AEST 1990
Submitted-by: ddickey at aspen.cray.com (Dan A. Dickey)
Posting-number: Volume 10, Issue 16
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
# If this archive is complete, you will see the following message at the end:
# "End of archive 5 (of 11)."
#
# Contents:
# Makefile minisubs.c struct.h xtrekb.c
#
# Wrapped by ddickey at cray.com on Thu Oct 11 11:43:53 1990
#
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(13139 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X# Makefile generated by imake - do not edit!
X# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
X#
X# The cpp used on this machine replaces all newlines and multiple tabs and
X# spaces in a macro expansion with a single space. Imake tries to compensate
X# for this, but is not always successful.
X#
X
X###########################################################################
X# Makefile generated from "Imake.tmpl" and <Imakefile>
X# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
X#
X# Platform-specific parameters may be set in the appropriate .cf
X# configuration files. Site-wide parameters may be set in the file
X# site.def. Full rebuilds are recommended if any parameters are changed.
X#
X# If your C preprocessor doesn't define any unique symbols, you'll need
X# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
X# "make Makefile", "make Makefiles", or "make World").
X#
X# If you absolutely can't get imake to work, you'll need to set the
X# variables at the top of each Makefile as well as the dependencies at the
X# bottom (makedepend will do this automatically).
X#
X
X###########################################################################
X# platform-specific configuration parameters - edit sun.cf to change
X
X# platform: $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
X# operating system: SunOS 4.1
X
X###########################################################################
X# site-specific configuration parameters - edit site.def to change
X
X# site: $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
X
X SHELL = /bin/sh
X
X TOP = .
X CURRENT_DIR = .
X
X AR = ar cq
X BOOTSTRAPCFLAGS =
X CC = cc
X
X COMPRESS = compress
X CPP = /lib/cpp $(STD_CPP_DEFINES)
X PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
X INSTALL = install
X LD = ld
X LINT = lint
X LINTLIBFLAG = -C
X LINTOPTS = -axz
X LN = ln -s
X MAKE = make
X MV = mv
X CP = cp
X RANLIB = ranlib
X RANLIBINSTFLAGS =
X RM = rm -f
X STD_INCLUDES =
X STD_CPP_DEFINES =
X STD_DEFINES =
X EXTRA_LOAD_FLAGS =
X EXTRA_LIBRARIES =
X TAGS = ctags
X
X SHAREDCODEDEF = -DSHAREDCODE
X SHLIBDEF = -DSUNSHLIB
X
X PROTO_DEFINES =
X
X INSTPGMFLAGS =
X
X INSTBINFLAGS = -m 0755
X INSTUIDFLAGS = -m 4755
X INSTLIBFLAGS = -m 0664
X INSTINCFLAGS = -m 0444
X INSTMANFLAGS = -m 0444
X INSTDATFLAGS = -m 0444
X INSTKMEMFLAGS = -m 4755
X
X DESTDIR =
X
X TOP_INCLUDES = -I$(INCROOT)
X
X CDEBUGFLAGS = -O
X CCOPTIONS = -n
X COMPATFLAGS = -DXAW_BC
X
X ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
X ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
X CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
X LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
X LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
X LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
X LDCOMBINEFLAGS = -X -r
X
X MACROFILE = sun.cf
X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
X
X IMAKE_DEFINES =
X
X IRULESRC = $(CONFIGDIR)
X IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
X
X ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
X $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
X $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
X
X###########################################################################
X# X Window System Build Parameters
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X###########################################################################
X# X Window System make variables; this need to be coordinated with rules
X# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
X
X PATHSEP = /
X USRLIBDIR = $(DESTDIR)/usr/lib
X BINDIR = $(DESTDIR)/usr/bin/X11
X INCROOT = $(DESTDIR)/usr/include
X BUILDINCROOT = $(TOP)
X BUILDINCDIR = $(BUILDINCROOT)/X11
X BUILDINCTOP = ..
X INCDIR = $(INCROOT)/X11
X ADMDIR = $(DESTDIR)/usr/adm
X LIBDIR = $(USRLIBDIR)/X11
X CONFIGDIR = $(LIBDIR)/config
X LINTLIBDIR = $(USRLIBDIR)/lint
X
X FONTDIR = $(LIBDIR)/fonts
X XINITDIR = $(LIBDIR)/xinit
X XDMDIR = $(LIBDIR)/xdm
X AWMDIR = $(LIBDIR)/awm
X TWMDIR = $(LIBDIR)/twm
X GWMDIR = $(LIBDIR)/gwm
X MANPATH = $(DESTDIR)/usr/man
X MANSOURCEPATH = $(MANPATH)/man
X MANDIR = $(MANSOURCEPATH)n
X LIBMANDIR = $(MANSOURCEPATH)3
X XAPPLOADDIR = $(LIBDIR)/app-defaults
X
X SOXLIBREV = 4.2
X SOXTREV = 4.0
X SOXAWREV = 4.0
X SOOLDXREV = 4.0
X SOXMUREV = 4.0
X SOXEXTREV = 4.0
X
X FONTCFLAGS = -t
X
X INSTAPPFLAGS = $(INSTDATFLAGS)
X
X IMAKE = imake
X DEPEND = makedepend
X RGB = rgb
X FONTC = bdftosnf
X MKFONTDIR = mkfontdir
X MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
X
X CONFIGSRC = $(TOP)/config
X CLIENTSRC = $(TOP)/clients
X DEMOSRC = $(TOP)/demos
X LIBSRC = $(TOP)/lib
X FONTSRC = $(TOP)/fonts
X INCLUDESRC = $(TOP)/X11
X SERVERSRC = $(TOP)/server
X UTILSRC = $(TOP)/util
X SCRIPTSRC = $(UTILSRC)/scripts
X EXAMPLESRC = $(TOP)/examples
X CONTRIBSRC = $(TOP)/../contrib
X DOCSRC = $(TOP)/doc
X RGBSRC = $(TOP)/rgb
X DEPENDSRC = $(UTILSRC)/makedepend
X IMAKESRC = $(CONFIGSRC)
X XAUTHSRC = $(LIBSRC)/Xau
X XLIBSRC = $(LIBSRC)/X
X XMUSRC = $(LIBSRC)/Xmu
X TOOLKITSRC = $(LIBSRC)/Xt
X AWIDGETSRC = $(LIBSRC)/Xaw
X OLDXLIBSRC = $(LIBSRC)/oldX
X XDMCPLIBSRC = $(LIBSRC)/Xdmcp
X BDFTOSNFSRC = $(FONTSRC)/bdftosnf
X MKFONTDIRSRC = $(FONTSRC)/mkfontdir
X EXTENSIONSRC = $(TOP)/extensions
X
X DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
X EXTENSIONLIB = -lXext
X
X DEPXLIB = $(DEPEXTENSIONLIB)
X XLIB = $(EXTENSIONLIB) -lX11
X
X DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
X XAUTHLIB = -lXau
X
X DEPXMULIB =
X XMULIB = -lXmu
X
X DEPOLDXLIB =
X OLDXLIB = -loldX
X
X DEPXTOOLLIB =
X XTOOLLIB = -lXt
X
X DEPXAWLIB =
X XAWLIB = -lXaw
X
X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
X LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
X LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
X LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
X LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
X
X DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
X
X DEPLIBS1 = $(DEPLIBS)
X DEPLIBS2 = $(DEPLIBS)
X DEPLIBS3 = $(DEPLIBS)
X
X###########################################################################
X# Imake rules for building libraries, programs, scripts, and data files
X# rules: $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
X
X###########################################################################
X# start of Imakefile
X
X XTREKD = in.xtrekd
X
X XTREKDIR = /usr/lib/X11/xtrek
X DEFINES = -DNEWINET -DSUN40 -DCUSTOMSHIP -DEXCLUDE -DNDBM
X LOCALINC = bitmaps.h data.h defs.h planets.h struct.h xtrekfont.h \
X clock.bitmap
X SRCS1 = bitmaps.c colors.c coup.c data.c death.c detonate.c dmessage.c \
X enter.c getship.c inform.c input.c interface.c main.c \
X newwin.c orbit.c phaser.c planetlist.c playerlist.c \
X pstats.c redraw.c smessage.c subdaemon.c stats.c torp.c \
X util.c warning.c random.c rmove.c scorelist.c \
X trigtab.c itoa.c minisubs.c war.c DBG.c
X OBJS1 = bitmaps.o colors.o coup.o data.o death.o detonate.o dmessage.o \
X enter.o getship.o inform.o input.o interface.o main.o \
X newwin.o orbit.o phaser.o planetlist.o playerlist.o \
X pstats.o redraw.o smessage.o subdaemon.o stats.o torp.o \
X util.o warning.o random.o rmove.o scorelist.o \
X trigtab.o itoa.o minisubs.o war.o DBG.o
X LINTFILES = bitmaps.ln colors.ln coup.ln data.ln death.ln detonate.ln \
X dmessage.ln enter.ln getship.ln inform.ln input.ln \
X interface.ln main.ln newwin.ln orbit.ln phaser.ln \
X planetlist.ln playerlist.ln pstats.ln redraw.ln smessage.ln \
X subdaemon.ln stats.ln torp.ln util.ln warning.ln random.ln \
X rmove.ln scorelist.ln trigtab.ln itoa.ln minisubs.ln \
X war.ln DBG.ln
X SRCS2 = xtrek.c
X OBJS2 = xtrek.o
X SRCS3 = xtrekb.c
X OBJS3 = xtrekb.o
X SRCS = $(SRCS1) $(SRCS2) $(SRCS3)
X SRCSF = xtrek.bdf
X OBJSF = xtrek.snf
X OBJS = $(OBJSF)
X PROGRAMS = bitmaps.h xtrek $(XTREKD) xtrekb
X INCLUDES = -I$(TOP)
X LINTOPTS = -iabchu
X LIBS = -ldbm -Bstatic $(XLIB) -lm
X FC = bdftosnf
X
X.SUFFIXES: .ln
X
Xall:: $(PROGRAMS)
X
Xxtrek: $(OBJS2)
X $(RM) $@
X $(CC) -o $@ $(OBJS2) $(LDOPTIONS) $(LDLIBS) -ldbm -Bstatic $(EXTRA_LOAD_FLAGS)
X
Xclean::
X $(RM) xtrek
X
X$(XTREKD): $(OBJS1)
X $(RM) $@
X $(CC) -o $@ $(OBJS1) $(LDOPTIONS) $(LDLIBS) $(LIBS) $(EXTRA_LOAD_FLAGS)
X
Xclean::
X $(RM) $(XTREKD)
X
Xxtrekb: $(OBJS3)
X $(RM) $@
X $(CC) -o $@ $(OBJS3) $(LDOPTIONS) $(LDLIBS) $(LIBS) $(EXTRA_LOAD_FLAGS)
X
Xclean::
X $(RM) xtrekb
X
Xall:: $(OBJS) fonts.dir
X
Xfonts.dir: $(OBJS)
X $(MKFONTDIR) .
X
Xclean::
X $(RM) *.snf fonts.dir
X
Xxtrek.snf: xtrek.bdf
X $(FONTC) $(FONTCFLAGS) $? >$@
X
Xall:: $(OBJSF)
X
Xdepend::
X $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
X
Xinstall:: $(XTREKD)
X $(INSTALL) -c $(INSTPGMFLAGS) $(XTREKD) $(XTREKDIR)
X
Xinstall:: xtrek
X $(INSTALL) -c $(INSTPGMFLAGS) xtrek $(BINDIR)
X
Xinstall:: xtrekb
X $(INSTALL) -c $(INSTPGMFLAGS) xtrekb $(BINDIR)
X
Xinstall.man:: xtrek.man
X $(INSTALL) -c $(INSTMANFLAGS) xtrek.man $(MANDIR)/xtrek.n
X
Xinstall.man:: xtrekb.man
X $(INSTALL) -c $(INSTMANFLAGS) xtrekb.man $(MANDIR)/xtrekb.n
X
Xinstall.man:: xtrek_ship.man
X $(INSTALL) -c $(INSTMANFLAGS) xtrek_ship.man $(MANDIR)/xtrek_ship.n
X
Xinstall:: $(OBJS)
X @case '${MFLAGS}' in *[i]*) set +e;; esac; \
X for i in $(OBJS); do \
X (set -x; $(INSTALL) -c $(INSTDATFLAGS) $$i $(XTREKDIR)); \
X done
X
Xinstall:: fonts.dir
X $(INSTALL) -c $(INSTDATFLAGS) fonts.dir $(XTREKDIR)
X
Xbitmaps.h: bitmaps.c
X sed -e '1i\
X /* DO NOT EDIT THIS FILE. It is machine generated. */'\
X -e 's/[ ]*=[ ]*{[ ]*$$/;\
X %MARKTEXT%/'\
X bitmaps.c |\
X sed -e 's/^char/extern char/'\
X -e 's/^Pixmap/extern Pixmap/'\
X -e '/[ ]*%MARKTEXT%[ ]*$$/,/[ ]*}[ ]*;[ ]*$$/d'\
X > bitmaps.h
X
Xinstall::
X -mkdir $(XTREKDIR)
X touch $(XTREKDIR)/planets $(XTREKDIR)/motd
X touch $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
X chmod 600 $(XTREKDIR)/planets $(XTREKDIR)/motd
X chmod 644 $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
X chmod u+s $(XTREKDIR)/$(XTREKD)
X -chmod u+w $(XTREKDIR)/xtrek.doc
X -cp doc $(XTREKDIR)/xtrek.doc
X chmod 444 $(XTREKDIR)/xtrek.doc
X
X -(convertfont xtrek.bdf; bldfamily)
X -cp xtrek.ff xtrek31.fb Families.list Synonyms.list $(XTREKDIR)
X -chmod 444 $(XTREKDIR)/xtrek.ff $(XTREKDIR)/xtrek31.fb
X -chmod 444 $(XTREKDIR)/Families.list $(XTREKDIR)/Synonyms.list
X
Xlint: $(LINTFILES)
X $(LINT) $(LINTXLIB) *.ln > xtrek.lint 2>&1
X
Xkludge.X11.a: /usr/lib/libX11.a
X cp /usr/lib/libX11.a kludge.libX11.a # Copy X11 lib
X chmod u+w kludge.libX11.a # make our copy writeable
X ar xv kludge.libX11.a Berklib.o # Copy offending module
X ld -r -o templib.o -h bcopy -h random -h srandom Berklib.o # Hide syms
X ar dv kludge.libX11.a Berklib.o # Remove offending module
X ar rv kludge.libX11.a templib.o # Add fixed module
X /bin/rm templib.o # Remove temp file
X
Xshar:
X makekit -s50k -oMANIFEST READ* INSTALL* TODO xtrek.man xtrek_ship.man xtrekb.man Imakefile Makefile doc *.h *.c xtrek.bdf clock.bitmap
X
Xcpio:
X for i in READ* INSTALL* TODO xtrek.man xtrek_ship.man xtrekb.man Imakefile Makefile doc *.h *.c xtrek.bdf clock.bitmap; do /bin/echo $$i; done | cpio -ocB > xtrek.cpio
X
Xtar:
X tar cf xtrek.tar READ* TODO xtrek.man xtrek_ship.man xtrekb.man Imakefile Makefile doc *.h *.c xtrek.bdf clock.bitmap
X
X.c.ln:
X $(LINT) $(LINTFLAGS) $< > $*.p1 2>&1
X
X###########################################################################
X# common rules for all Makefiles - do not edit
X
Xemptyrule::
X
Xclean::
X $(RM_CMD) \#*
X
XMakefile::
X - at if [ -f Makefile ]; then \
X echo " $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
X $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
X else exit 0; fi
X $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
X
Xtags::
X $(TAGS) -w *.[ch]
X $(TAGS) -xw *.[ch] > TAGS
X
X###########################################################################
X# empty rules for directories that do not have SUBDIRS - do not edit
X
Xinstall::
X @echo "install in $(CURRENT_DIR) done"
X
Xinstall.man::
X @echo "install.man in $(CURRENT_DIR) done"
X
XMakefiles::
X
Xincludes::
X
X###########################################################################
X# dependencies generated by makedepend
X
END_OF_Makefile
if test 13139 -ne `wc -c <Makefile`; then
echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f minisubs.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"minisubs.c\"
else
echo shar: Extracting \"minisubs.c\" \(13867 characters\)
sed "s/^X//" >minisubs.c <<'END_OF_minisubs.c'
Xstatic char sccsid[] = "@(#)minisubs.c 3.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 if (isGod(who)) {
X who->p_ship->s_wtemp = 0;
X who->p_ship->s_flags &= ~SFWEP;
X return;
X }
X who->p_ship->s_wtemp -= who->p_ship->s_wcool;
X if (who->p_ship->s_wtemp < 0)
X who->p_ship->s_wtemp = 0;
X if (who->p_ship->s_flags & SFWEP) {
X if (--who->p_ship->s_wtime <= 0) {
X who->p_ship->s_flags &= ~SFWEP;
X warning(who, "Weapons are back on-line.");
X }
X } else if (who->p_ship->s_wtemp > 1000) {
X if (!(random() % 40)) {
X who->p_ship->s_flags |= SFWEP;
X who->p_ship->s_wtime = (random() % PWEAPLOCKVAR) + PWEAPLOCKMIN;
X warning(who, "Weapons overload.");
X }
X }
X}
X
Xcool_engines(who)
Xregister struct player *who;
X{
X if (isGod(who)) {
X who->p_ship->s_etemp = 0;
X who->p_ship->s_flags &= ~SFENG;
X return;
X }
X who->p_ship->s_etemp -= who->p_ship->s_ecool;
X if (who->p_ship->s_etemp < 0)
X who->p_ship->s_etemp = 0;
X if (who->p_ship->s_flags & SFENG) {
X if (--who->p_ship->s_etime <= 0) {
X who->p_ship->s_flags &= ~SFENG;
X warning(who, "Engines are now functional.");
X }
X } else if (who->p_ship->s_etemp > 1000) {
X if (!(random() % 40)) {
X who->p_ship->s_flags |= SFENG;
X who->p_ship->s_etime = (random() % PENGLOCKVAR) + PENGLOCKMIN;
X who->p_ship->s_desspeed = 0;
X warning(who, "Engines super-heated.");
X }
X }
X}
X
Xadd_fuel(who)
Xregister struct player *who;
X{
X int amt;
X
X if (isGod(who)) {
X who->p_ship->s_fuel = who->p_ship->s_maxfuel;
X return;
X }
X amt = who->p_ship->s_recharge;
X
X /* You get 25% more for having shields down. */
X if (!(who->p_ship->s_flags & SFSHIELD))
X amt += (who->p_ship->s_recharge / 4);
X
X /* You get more fuel for orbiting friendly, populated class M planets */
X /* with shields down. */
X if ((who->p_ship->s_flags & SFORBIT) &&
X (planets[who->p_ship->s_planet].pl_type == CLASSM) &&
X !((1 << planets[who->p_ship->s_planet].pl_owner) & (who->p_ship->s_swar | who->p_ship->s_hostile)) &&
X (planets[who->p_ship->s_planet].pl_armies > 0) &&
X !(who->p_ship->s_flags & SFSHIELD)) {
X amt *= 8;
X } else
X amt *= 2;
X
X who->p_ship->s_fuel += amt;
X if (who->p_ship->s_fuel > who->p_ship->s_maxfuel)
X who->p_ship->s_fuel = who->p_ship->s_maxfuel;
X}
X
Xrepair_shields(who)
Xregister struct player *who;
X{
X if (isGod(who)) {
X who->p_ship->s_shield = who->p_ship->s_maxshields;
X return;
X }
X /* NOTE: Shields repair twice as fast when they are down. */
X
X if (who->p_ship->s_shield < who->p_ship->s_maxshields) {
X if ((who->p_ship->s_flags & SFREPAIR) && (who->p_ship->s_speed == 0)) {
X if (who->p_ship->s_flags & SFSHIELD)
X who->p_ship->s_subshield += who->p_ship->s_repair * 4;
X else
X who->p_ship->s_subshield += who->p_ship->s_repair * 8;
X if ((who->p_ship->s_flags & SFORBIT) &&
X (planets[who->p_ship->s_planet].pl_armies > 0) &&
X (!((1 << planets[who->p_ship->s_planet].pl_owner)
X & (who->p_ship->s_swar | who->p_ship->s_hostile)))) {
X if (who->p_ship->s_flags & SFSHIELD)
X who->p_ship->s_subshield += who->p_ship->s_repair * 4;
X else
X who->p_ship->s_subshield += who->p_ship->s_repair * 8;
X }
X } else {
X if (who->p_ship->s_flags & SFSHIELD)
X who->p_ship->s_subshield += who->p_ship->s_repair * 2;
X else
X who->p_ship->s_subshield += who->p_ship->s_repair * 4;
X }
X
X if (who->p_ship->s_subshield / 1000) {
X who->p_ship->s_shield += who->p_ship->s_subshield / 1000;
X who->p_ship->s_subshield %= 1000;
X }
X if (who->p_ship->s_shield > who->p_ship->s_maxshields) {
X who->p_ship->s_shield = who->p_ship->s_maxshields;
X who->p_ship->s_subshield = 0;
X }
X }
X}
X
Xrepair_damage(who)
Xregister struct player *who;
X{
X if (isGod(who)) {
X who->p_ship->s_flags &= ~SFREPAIR;
X who->p_ship->s_damage = 0;
X return;
X }
X if (who->p_ship->s_damage && !(who->p_ship->s_flags & SFSHIELD)) {
X if ((who->p_ship->s_flags & SFREPAIR) && (who->p_ship->s_speed == 0)) {
X who->p_ship->s_subdamage += who->p_ship->s_repair * 2;
X if ((who->p_ship->s_flags & SFORBIT) && /* orbiting */
X (planets[who->p_ship->s_planet].pl_armies > 0) && /* a populated*/
X (!((1 << planets[who->p_ship->s_planet].pl_owner) /* friendly */
X & (who->p_ship->s_swar | who->p_ship->s_hostile)))) { /* planet */
X who->p_ship->s_subdamage += who->p_ship->s_repair * 2;
X }
X } else
X who->p_ship->s_subdamage += who->p_ship->s_repair;
X if (who->p_ship->s_subdamage / 1000) {
X who->p_ship->s_damage -= who->p_ship->s_subdamage / 1000;
X who->p_ship->s_subdamage %= 1000;
X }
X if (who->p_ship->s_damage < 0) {
X who->p_ship->s_flags &= ~SFREPAIR;
X who->p_ship->s_damage = 0;
X who->p_ship->s_subdamage = 0;
X }
X }
X}
X
Xcheck_dcloak(who)
Xregister struct player *who;
X{
X if (isGod(who)) {
X /* Never... */
X return;
X }
X if ((!(who->p_ship->s_flags & SFCLOAK)) || who->p_ship->s_damage < who->p_ship->s_dcloak) {
X who->p_ship->s_flags &= ~SFDCLOAK;
X return;
X }
X /* Ok, we are over the threshold... */
X if (who->p_ship->s_flags & SFDCLOAK) {
X /* The cloaks are damaged, see if they should become "undamaged" */
X if ((random() % 100) < who->p_ship->s_dcloak_off) {
X who->p_ship->s_flags &= ~SFDCLOAK;
X }
X } else {
X /* The cloaks are good, see if they should become "damaged" */
X if ((random() % 100) < who->p_ship->s_dcloak_on) {
X who->p_ship->s_flags |= SFDCLOAK;
X }
X }
X}
X
Xcloak_charge(who)
Xregister struct player *who;
X{
X if (isGod(who)) {
X return;
X }
X if (who->p_ship->s_flags & SFCLOAK) {
X who->p_ship->s_fuel -= (who->p_ship->s_cloakcost * (who->p_ship->s_speed+1));
X }
X
X if (who->p_ship->s_fuel <= 0) {
X who->p_ship->s_fuel = 0;
X tow_off(who);
X who->p_ship->s_desspeed = 0;
X cloak_off(who);
X }
X}
X
Xplayer_orbit(who)
Xregister struct player *who;
X{
X if (who->p_ship->s_flags & SFORBIT) {
X who->p_ship->s_dir += 2;
X who->p_ship->s_desdir = who->p_ship->s_dir;
X who->p_ship->s_x = planets[who->p_ship->s_planet].pl_x +
X ((ORBDIST * icos[(unsigned char) (who->p_ship->s_dir - (unsigned char) 64)])
X >> TRIGSCALE);
X who->p_ship->s_y = planets[who->p_ship->s_planet].pl_y +
X ((ORBDIST * isin[(unsigned char) (who->p_ship->s_dir - (unsigned char) 64)])
X >> TRIGSCALE);
X }
X}
X
Xspace_move(who)
Xregister struct player *who;
X{
X register struct ship *ship, *towee;
X int delta_x, delta_y;
X unsigned char dir_of_pull;
X extern unsigned char iatan2();
X extern double hypot();
X
X ship = who->p_ship;
X
X /* Don't move ships that are orbitting */
X if (!(ship->s_flags & SFORBIT)) {
X if (ship->s_dir != ship->s_desdir)
X changedir(who);
X
X /* Alter speed */
X alter_speed(who);
X
X /* Charge for speed */
X charge_speed(who);
X
X /* For ships that are being towed, don't move them. */
X /* They get moved by ships that are towing them. */
X if (ship->s_flags & SFTOWED)
X return;
X
X /* Move them... */
X delta_x = (ship->s_speed * icos[ship->s_dir] * WARP1) >> TRIGSCALE;
X ship->s_x += delta_x;
X delta_y = (ship->s_speed * isin[ship->s_dir] * WARP1) >> TRIGSCALE;
X ship->s_y += delta_y;
X
X check_sides(ship);
X
X /* If towing someone, move the ship */
X if (ship->s_flags & SFTOWING) {
X towee = &ships[ship->s_towing];
X dir_of_pull = iatan2((ship->s_x - towee->s_x) - who->p_xwinsize / 2, who->p_ywinsize / 2 - (ship->s_y - towee->s_y));
X towee->s_desdir = dir_of_pull;
X
X delta_x = (ship->s_speed * icos[dir_of_pull] * WARP1) >> TRIGSCALE;
X delta_y = (ship->s_speed * isin[dir_of_pull] * WARP1) >> TRIGSCALE;
X towee->s_x += delta_x;
X towee->s_y += delta_y;
X check_sides(towee);
X }
X }
X}
X
Xcheck_sides(ship)
Xregister struct ship *ship;
X{
X if (universe.flags & WRAPAROUND) {
X /*
X * jas (Jeff Schmidt) Let the ships wrap around the universe.
X */
X
X if (ship->s_x < 0)
X ship->s_x = GWIDTH;
X else if (ship->s_x > GWIDTH)
X ship->s_x = 0;
X
X if (ship->s_y < 0)
X ship->s_y = GWIDTH;
X else if (ship->s_y > GWIDTH)
X ship->s_y = 0;
X } else {
X /* Bounce off the side of the galaxy */
X if (ship->s_x < 0) {
X ship->s_x = -ship->s_x;
X if (ship->s_dir == 192)
X ship->s_dir = ship->s_desdir = 64;
X else
X ship->s_dir = ship->s_desdir = 64 - (ship->s_dir - 192);
X } else if (ship->s_x > GWIDTH) {
X ship->s_x = GWIDTH - (ship->s_x - GWIDTH);
X if (ship->s_dir == 64)
X ship->s_dir = ship->s_desdir = 192;
X else
X ship->s_dir = ship->s_desdir = 192 - (ship->s_dir - 64);
X }
X
X if (ship->s_y < 0) {
X ship->s_y = -ship->s_y;
X if (ship->s_dir == 0)
X ship->s_dir = ship->s_desdir = 128;
X else
X ship->s_dir = ship->s_desdir = 128 - ship->s_dir;
X } else if (ship->s_y > GWIDTH) {
X ship->s_y = GWIDTH - (ship->s_y - GWIDTH);
X if (ship->s_dir == 128)
X ship->s_dir = ship->s_desdir = 0;
X else
X ship->s_dir = ship->s_desdir = 0 - (ship->s_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 register struct player *j;
X
X who->p_ship->s_flags |= SFGREEN;
X who->p_ship->s_flags &= ~(SFRED|SFYELLOW);
X for (k = 0, j = &players[0]; k < MAXPLAYER; k++, j++) {
X if (j == who) /* Don't count yourself in the alert status */
X continue;
X if ((j->p_status == PALIVE) &&
X (((who->p_ship->s_swar | who->p_ship->s_hostile) & (1 << j->p_ship->s_team)) ||
X ((j->p_ship->s_swar | j->p_ship->s_hostile) & (1 << who->p_ship->s_team)))) {
X dx = who->p_ship->s_x - j->p_ship->s_x;
X dy = who->p_ship->s_y - j->p_ship->s_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_ship->s_flags |= SFRED;
X who->p_ship->s_flags &= ~(SFGREEN|SFYELLOW);
X } else if ((dist < YRANGE * YRANGE) &&
X (!(who->p_ship->s_flags & SFRED))) {
X who->p_ship->s_flags |= SFYELLOW;
X who->p_ship->s_flags &= ~(SFGREEN|SFRED);
X }
X }
X }
X}
X
Xalter_speed(who)
Xregister struct player *who;
X{
X register int maxspeed;
X
X if (isGod(who)) {
X who->p_ship->s_speed = who->p_ship->s_desspeed;
X return;
X }
X maxspeed = who->p_ship->s_maxspeed;
X maxspeed = maxspeed - ((who->p_ship->s_damage * maxspeed) /
X (who->p_ship->s_maxdamage));
X
X if (maxspeed > who->p_ship->s_maxspeed)
X maxspeed = who->p_ship->s_maxspeed;
X
X /* At this point...it no longer is "maxspeed", but "desspeed" */
X if (maxspeed > who->p_ship->s_desspeed)
X maxspeed = who->p_ship->s_desspeed;
X
X if (maxspeed > who->p_ship->s_speed) {
X who->p_ship->s_subspeed += who->p_ship->s_accint * (10 / UPS);
X }
X if (maxspeed < who->p_ship->s_speed) {
X who->p_ship->s_subspeed -= who->p_ship->s_decint * (10 / UPS);
X }
X if (who->p_ship->s_subspeed / 1000) {
X who->p_ship->s_speed += who->p_ship->s_subspeed / 1000;
X who->p_ship->s_subspeed /= 1000;
X if (who->p_ship->s_speed < 0)
X who->p_ship->s_speed = 0;
X if (who->p_ship->s_speed > who->p_ship->s_maxspeed)
X who->p_ship->s_speed = who->p_ship->s_maxspeed;
X }
X}
X
Xcharge_speed(who)
Xregister struct player *who;
X{
X register struct player *towee;
X int amt;
X
X if (isGod(who)) {
X return;
X }
X amt = who->p_ship->s_warpcost * who->p_ship->s_speed;
X who->p_ship->s_etemp += who->p_ship->s_speed;
X
X /* Shields up cost 50% more */
X if (who->p_ship->s_flags & SFSHIELD) {
X amt += ((who->p_ship->s_warpcost * who->p_ship->s_speed) / 2);
X who->p_ship->s_etemp += (who->p_ship->s_speed / 2);
X }
X /* Add in some for each army on board. */
X amt += ((who->p_ship->s_armies * who->p_ship->s_warpcost) / 2);
X who->p_ship->s_etemp += (who->p_ship->s_armies / 2);
X
X /* If they are towing someone, that costs too. */
X if (who->p_ship->s_flags & SFTOWING) {
X towee = &players[who->p_ship->s_towing];
X amt += ((towee->p_ship->s_warpcost * who->p_ship->s_speed) / 2);
X who->p_ship->s_etemp += (who->p_ship->s_speed / 2);
X
X /* Shields up cost 50% more */
X if (who->p_ship->s_flags & SFSHIELD) {
X amt += ((towee->p_ship->s_warpcost * who->p_ship->s_speed) / 2);
X who->p_ship->s_etemp += (who->p_ship->s_speed / 2);
X }
X /* Add in some for each army on board. */
X amt += ((towee->p_ship->s_armies * towee->p_ship->s_warpcost) / 2);
X who->p_ship->s_etemp += (towee->p_ship->s_armies / 2);
X }
X
X who->p_ship->s_fuel -= amt;
X
X if (who->p_ship->s_fuel <= 0) {
X who->p_ship->s_fuel = 0;
X tow_off(who);
X who->p_ship->s_desspeed = 0;
X cloak_off(who);
X }
X}
X
Xchangedir(sp)
Xstruct player *sp;
X{
X int ticks;
X
X if (isGod(sp)) {
X sp->p_ship->s_dir = sp->p_ship->s_desdir;
X sp->p_ship->s_subdir = 0;
X return;
X }
X if (sp->p_ship->s_speed == 0) {
X sp->p_ship->s_dir = sp->p_ship->s_desdir;
X sp->p_ship->s_subdir = 0;
X }
X else {
X sp->p_ship->s_subdir += sp->p_ship->s_turns / (1 << sp->p_ship->s_speed);
X ticks = sp->p_ship->s_subdir / 1000;
X if (ticks) {
X if (ticks > dirdiff(sp->p_ship->s_dir, sp->p_ship->s_desdir))
X sp->p_ship->s_dir = sp->p_ship->s_desdir;
X else if ((unsigned char) (sp->p_ship->s_dir - sp->p_ship->s_desdir) > 127)
X sp->p_ship->s_dir += ticks;
X else
X sp->p_ship->s_dir -= ticks;
X sp->p_ship->s_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_minisubs.c
if test 13867 -ne `wc -c <minisubs.c`; then
echo shar: \"minisubs.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f struct.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"struct.h\"
else
echo shar: Extracting \"struct.h\" \(10899 characters\)
sed "s/^X//" >struct.h <<'END_OF_struct.h'
X/* static char sccsid[] = "@(#)struct.h 3.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#define PFREE 0
X#define POUTFIT 1
X#define PALIVE 2
X#define PDEAD 3
X#define PSETUP 4
X#define PMAP 5
X
X/* Return values from newwin(): */
X#define OK 1
X#define NODISPLAY 2
X#define NOFONTS 3
X
X#define EXPLODE (PSETUP+1) /* for s_status */
X#define SFSHIELD 0x0001
X#define SFREPAIR 0x0002
X#define SFBOMB 0x0004
X#define SFORBIT 0x0008
X#define SFCLOAK 0x0010
X#define SFWEP 0x0020
X#define SFENG 0x0040
X#define SFBEAMUP 0x0100
X#define SFBEAMDOWN 0x0200
X#define SFSELFDEST 0x0400
X#define SFGREEN 0x0800
X#define SFYELLOW 0x1000
X#define SFRED 0x2000
X#define SFSLOCK 0x4000 /* Locked on a ship */
X#define SFPLLOCK 0x8000 /* Locked on a planet */
X#define SFWAR 0x200000 /* computer reprogramming for war */
X#define SFTOWING 0x800000 /* towing a ship */
X#define SFTOWED 0x1000000 /* being towed */
X#define SFDCLOAK 0x2000000 /* "damaged" - cloak is off */
X#define SFPLANETPROT 0x4000000 /* Go protect a planet */
X
X#define PFNOMAPMODE 0x0010 /* No map mode */
X#define PFROBOT 0x0080 /* Robot player */
X#define PFPRACTICER 0x0100 /* Practice robot */
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 PFRVHARD 0x100000 /* very hard robot */
X#define PFSHOWSTATS 0x200000 /* show player statistics */
X#define PFRSHOWSTATS 0x400000 /* Resource set - show player statistics */
X#define PFSHOWSHIELDS 0x800000 /* show player shields */
X#define PFENTER 0x1000000 /* entry windows showing */
X#define PFNOTSHOWING 0x2000000 /* Players windows are not visible */
X
X#define KQUIT 1 /* Player quit */
X#define KTORP 2 /* killed by torp */
X#define KPHASER 3 /* killed by phaser */
X#define KPLANET 4 /* killed by planet */
X#define KSHIP 5 /* killed by other ship */
X#define KDAEMON 6 /* killed by dying daemon */
X#define KWINNER 7 /* killed by a winner */
X#define KNEGENB 8 /* negative energy barrier */
X#define KNEWGAME 9 /* new game */
X#define KEVICT 10 /* game closed for repairs */
X#define KDOOMSDAY 11 /* planet eater got you */
X#define KGDOOMSDAY 12 /* you got the planet eater */
X#define KGOD 13 /* killed by the Lord */
X#define KLIGHTNING 14 /* killed by a lightning bolt from God */
X#define KVAPOR 15 /* vaporized - SIGPIPE on display */
X
X#define UMSGADDRLEN 10 /* user message address length */
X#define UMSGLEN 80 /* user message length */
X
Xstruct universe {
X int flags;
X char *god_names[MAXPLAYER];
X};
X#define WRAPAROUND 0x0001 /* allow ships to wrap around */
X
Xstruct stats {
X int st_id; /* identifier for this stats record */
X int st_time; /* real 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
Xstruct ship {
X int s_no;
X int s_updates; /* Number of updates ship has survived */
X int s_delay; /* Number of updates ship has to delay */
X int s_status;
X int s_flags;
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 short s_dcloak;
X short s_dcloak_on;
X short s_dcloak_off;
X
X int s_x;
X int s_y;
X unsigned char s_dir; /* Real direction */
X unsigned char s_desdir; /* desired direction */
X int s_subdir; /* fraction direction change */
X short s_speed; /* Real speed */
X short s_desspeed; /* Desired speed */
X int s_subspeed; /* Fractional speed */
X short s_team; /* Team I'm on */
X short s_damage; /* Current damage */
X int s_subdamage; /* Fractional damage repair */
X short s_shield; /* Current shield power */
X int s_subshield; /* Fractional shield recharge */
X short s_ntorp; /* Number of torps flying */
X int s_hostile; /* Who my torps will hurt */
X int s_swar; /* Who am I at sticky war with */
X short s_planet; /* Planet orbiting or locked onto */
X short s_shipl; /* Ship locked onto */
X short s_armies;
X short s_fuel;
X short s_explode; /* Keeps track of final explosion */
X short s_etemp;
X short s_etime;
X short s_wtemp;
X short s_wtime;
X short s_timer; /* General purpose timer */
X short s_rmode; /* Robot attack mode */
X short s_whydead; /* Tells you why you died */
X short s_whodead; /* Tells you who killed you */
X int s_selfdest; /* How long until I die. */
X int s_towing; /* Ship number we are towing */
X int s_towed; /* Ship we are being towed by */
X int s_newhostile;
X int s_reprogram;
X int s_oldalert;
X int s_Ten; /* Prepare for warp Ten+ */
X int s_numpilots; /* Number of pilots - normally one */
X int s_planetprot; /* Number of planet to protect */
X struct stats s_stats;
X};
X
Xtypedef struct record {
X short *data;
X short last_value;
X} RECORD;
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 int o_dist;
X};
X
Xstruct player {
X int p_no;
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 char p_shipname[32]; /* Name of ship to search for in .Xdefaults */
X int p_pick; /* Teams I can pick from */
X
X int p_lastm;
X int p_mdisplayed;
X int p_lastcount;
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 p_warntimer;
X int p_warncount;
X
X int p_mapmode;
X int p_namemode;
X int p_redrawall;
X int p_statmode;
X int p_infomapped;
X struct obtype p_info_target;
X int p_ts_offset;
X RECORD *p_rp;
X struct stats p_stats; /* player statistics */
X int p_copilot; /* Which ship are we copiloting. */
X long p_start_time;
X
X int p_xwinsize;
X int p_ywinsize;
X int p_border;
X int p_messagesize; /* Height of message windows */
X
X struct ship *p_ship; /* Personal ship statistics */
X
X /* X11 stuff: */
X Display *display;
X int focus; /* Has focus or not... */
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, tbgc, dimgc;
X unsigned long borderColor, backColor, textColor, myColor,
X warningColor, shipCol[MAXTEAM+1], rColor, yColor, gColor, unColor;
X unsigned long moonColor, sunColor;
X Atom wm_delete_window;
X Atom wm_change_state;
X
X XRectangle clearzone[(MAXTORP + 1) * MAXPLAYER + MAXPLANETS];
X int clearcount;
X int clearline[4][MAXPLAYER];
X int clearlcount;
X XRectangle mclearzone[MAXPLAYER];
X int mclearcount;
X XRectangle mpzone[MAXPLANETS * 2];
X int mpzset[MAXPLANETS];
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 int t_war; /* enemies */
X int 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/* the lower bits represent the original owning team */
X#define PLHOME 0x080 /* home planet for a given team */
X#define PLCOUP 0x100 /* Coup has occured */
X#define PLINVIS 0x200 /* planet is invisible */
X
X/* planet types: */
X#define CLASSM 1
X#define DEAD 2
X#define SUN 3
X#define MOON 4
X#define GHOST 5
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 int pl_drawtime; /* Time when map should be redrawn */
X
X char pl_tname[10]; /* Type name */
X int pl_tnamelen;
X int pl_primary; /* planet this planet orbits */
X int pl_orbrad; /* radius of the orbit */
X int pl_orbvel; /* velocity of the orbit */
X int pl_type; /* planet type */
X int pl_orbang; /* current angle of the orbit */
X int pl_suborbang; /* amount of a partial angle we've orbitted */
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};
END_OF_struct.h
if test 10899 -ne `wc -c <struct.h`; then
echo shar: \"struct.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f xtrekb.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"xtrekb.c\"
else
echo shar: Extracting \"xtrekb.c\" \(11175 characters\)
sed "s/^X//" >xtrekb.c <<'END_OF_xtrekb.c'
Xstatic char sccsid[] = "@(#)xtrekb.c 3.1";
X
X#include <stdio.h>
X#include <X11/Xos.h>
X#include <X11/Xlib.h>
X#include <X11/cursorfont.h> /* for cursor constants */
X#include <X11/Xutil.h>
X#if !defined(cray)
X#include <sys/types.h> /* for stat() */
X#endif
X#include <sys/stat.h> /* for stat() */
X#if !defined(cray)
X#include <sys/wait.h>
X#endif
X#include "defs.h"
X
X
X#define min(a,b) ((a) < (b) ? (a) : (b))
X#define max(a,b) ((a) > (b) ? (a) : (b))
X
X
Xextern void exit();
Xextern char *getenv();
Xextern int errno;
X
Xchar *ProgramName;
Xchar *host;
Xchar *bgcolor;
Xchar *displayname;
Xchar *geometry;
Xchar *fontname, *sfontname;
Xint cmdlnfont = 0;
Xint cmdlnrv = 0;
Xint cmdlngeom = 0;
Xint cmdlnserv = 0;
Xint update = 60;
Xint reverse = 0;
Xint got_xtrekfont;
Xint exposed = 0;
Xint width;
Xint height;
Xint tbool[4] = { -1, -1, -1, -1 };
X
Xtypedef unsigned long Pixel;
X
XXFontStruct *xfont, *sxfont;
XDisplay *display;
Xint screen;
XPixel foreground_pixel, background_pixel;
XPixel fedcolor, romcolor, klicolor, oricolor;
XColormap default_colormap;
Xint depth;
XGC gc, cleargc, sgc;
XWindow win;
X
X#define XDEFAULT "Xtrekb"
X
X#define VIEWS 16 /* for rosette() */
X#define ship_width 16
X#define ship_height 16
X
Xstatic void init();
Xstatic void redraw_xtrek();
X
X
Xstatic void
XUsage ()
X{
X static char *help_message[] = {
X "where options include:",
X " -update seconds how often to check for players",
X " -bg color background color",
X " -rv reverse video",
X " -s xtrekhost xtrek server to watch",
X " -geometry geom size of icon",
X " -display host:dpy X server to display on",
X " -font fontname font to use",
X NULL };
X char **cpp;
X
X fprintf (stderr, "usage: %s [-options ...]\n", ProgramName);
X for (cpp = help_message; *cpp; cpp++) {
X fprintf (stderr, "%s\n", *cpp);
X }
X fprintf (stderr, "\n");
X exit (1);
X}
X
X
Xvoid
Xmain (ac, av)
Xint ac;
Xchar **av;
X{
X register char *s;
X char c;
X XEvent data;
X int setupsleep;
X
X ProgramName = av[0];
X ac--;
X av++;
X
X bgcolor = "black";
X displayname = ":0";
X geometry = "";
X host = "xtrek-server";
X fontname = "xtrek";
X sfontname = "6x10";
X cmdlnfont = 0;
X cmdlnrv = 0;
X cmdlngeom = 0;
X if (s = getenv("XTREKSERVER"))
X host = s;
X if (s = getenv("DISPLAY"))
X displayname = s;
X
X while (ac) {
X if (**av != '-')
X break;
X if (strcmp(*av, "-s") == 0) {
X if (ac < 2) Usage();
X ac--; av++;
X host = *av;
X cmdlnserv = 1;
X } else if (strcmp(*av, "-bg") == 0) {
X if (ac < 2) Usage();
X ac--; av++;
X bgcolor = *av;
X } else if (strcmp(*av, "-display") == 0) {
X if (ac < 2) Usage();
X ac--; av++;
X displayname = *av;
X } else if (strcmp(*av, "-font") == 0) {
X if (ac < 2) Usage();
X ac--; av++;
X sfontname = *av;
X cmdlnfont = 1;
X } else if (strcmp(*av, "-geometry") == 0) {
X if (ac < 2) Usage();
X ac--; av++;
X geometry = *av;
X cmdlngeom = 1;
X } else if (strcmp(*av, "-rv") == 0) {
X reverse = !reverse;
X cmdlnrv = 1;
X } else if (strcmp(*av, "-update") == 0) {
X if (ac < 2) Usage();
X ac--; av++;
X update = atoi(*av);
X if (update <= 1)
X update = 1;
X } else
X Usage();
X ac--; av++;
X }
X
X close(0);
X close(1);
X
X exposed = 0;
X init();
X
X setupsleep = 1;
X while (1) {
X if (XPending(display) || !exposed) {
X XNextEvent(display, &data);
X switch (data.type) {
X case Expose:
X exposed = 1;
X setupsleep = update;
X tbool[0] = -1;
X tbool[1] = -1;
X tbool[2] = -1;
X tbool[3] = -1;
X break;
X case NoExpose:
X exposed = 0;
X break;
X }
X }
X /* Don't draw until we are exposed. */
X if (exposed)
X redraw_xtrek();
X /* NOTE: This would work much better with an interval timer. */
X sleep(setupsleep);
X }
X}
X
X/*
X * private procedures
X */
X
Xstatic void
Xinit ()
X{
X XSizeHints wininfo;
X XGCValues xgcv;
X long valuemask;
X register char *s;
X int X, Y;
X XColor def;
X int uspec;
X XFontStruct *XLoadQueryFont();
X
X if ((display = XOpenDisplay(displayname)) == NULL) {
X perror(displayname);
X exit(1);
X }
X screen = XDefaultScreen(display);
X depth = DefaultDepth(display, screen);
X
X /* Lookup black & white pixels. */
X foreground_pixel = XWhitePixel(display, screen);
X background_pixel = XBlackPixel(display, screen);
X
X if (!cmdlnserv && (s = XGetDefault(display, XDEFAULT, "server")) == NULL) {
X host = s;
X }
X if ((s = XGetDefault(display, XDEFAULT, "reverseVideo")) != NULL) {
X if (strcmp(s, "on") == 0 || strcmp(s, "true") == 0 || strcmp(s, "1") == 0)
X reverse = 1;
X else if (strcmp(s, "off") == 0 || strcmp(s, "false") == 0 || strcmp(s, "0") == 0)
X reverse = 0;
X }
X if (cmdlnrv)
X reverse = !reverse;
X
X if (reverse) {
X Pixel tmp;
X
X tmp = foreground_pixel;
X foreground_pixel = background_pixel;
X background_pixel = tmp;
X }
X
X if (!cmdlnfont && (s = XGetDefault(display, XDEFAULT, "font")) != NULL)
X sfontname = s;
X
X sxfont = XLoadQueryFont(display, sfontname);
X
X xfont = XLoadQueryFont(display, fontname);
X if (xfont == (XFontStruct *) NULL) {
X fprintf(stderr, "Xtrek font not available.\n");
X fontname = "6x10";
X xfont = XLoadQueryFont(display, fontname);
X if (xfont == (XFontStruct *) NULL) {
X fprintf(stderr, "default font (6x10) not available.\n");
X XCloseDisplay(display);
X exit(1);
X /*NOTREACHED*/
X }
X }
X got_xtrekfont = (strcmp(fontname, "xtrek") == 0);
X
X if (!cmdlngeom && (s = XGetDefault(display, XDEFAULT, "geometry")) != NULL) {
X geometry = s;
X cmdlngeom = 1; /* Not really, but do uspec stuff below. */
X }
X width = ship_width * 2;
X height = ship_height * 2;
X X = Y = 0;
X if (cmdlngeom) {
X uspec = XParseGeometry(geometry, &X, &Y, &width, &height);
X if ((uspec & (XValue|XNegative)) == (XValue|XNegative))
X X = -X;
X if ((uspec & (YValue|YNegative)) == (YValue|YNegative))
X Y = -Y;
X if ((uspec & WidthValue) == 0)
X width = ship_width * 2;
X if ((uspec & HeightValue) == 0)
X height = ship_height * 2;
X }
X if (sxfont) {
X if (XTextWidth(sxfont, host, strlen(host)) > width)
X width = XTextWidth(sxfont, host, strlen(host));
X height += (4 + (sxfont->ascent + sxfont->descent));
X }
X
X win = XCreateWindow(display, RootWindow(display, screen), X, Y,
X width, height, 1, depth, InputOutput,
X (Visual *)CopyFromParent, 0L, (XSetWindowAttributes *) NULL);
X wininfo.x = X;
X wininfo.y = Y;
X wininfo.width = width;
X wininfo.height = height;
X wininfo.min_width = ship_width * 2;
X wininfo.min_height = ship_height * 2;
X wininfo.max_width = ship_width * 2;
X wininfo.max_height = ship_height * 2;
X wininfo.flags = PMinSize | PMaxSize;
X if (uspec & (XValue|YValue))
X wininfo.flags |= USPosition;
X else
X wininfo.flags |= PPosition;
X if (uspec & (WidthValue|HeightValue))
X wininfo.flags |= USSize;
X else
X wininfo.flags |= PSize;
X
X XSetWindowBackground(display, win, background_pixel);
X XSetStandardProperties(display, win, XDEFAULT, XDEFAULT, NULL, NULL, 0, &wininfo);
X XSelectInput(display, win, ExposureMask);
X
X valuemask = GCForeground | GCBackground | GCFunction | GCFont;
X xgcv.foreground = foreground_pixel;
X xgcv.background = background_pixel;
X xgcv.function = GXcopy;
X xgcv.font = xfont->fid;
X gc = XCreateGC(display, win, valuemask, &xgcv);
X if (sxfont) {
X xgcv.font = sxfont->fid;
X sgc = XCreateGC(display, win, valuemask, &xgcv);
X }
X xgcv.foreground = background_pixel;
X xgcv.function = GXcopy;
X cleargc = XCreateGC(display, win, GCForeground|GCFunction, &xgcv);
X
X /* Setup colors */
X if (depth <= 2) {
X fedcolor = romcolor = klicolor = oricolor = foreground_pixel;
X } else {
X default_colormap = XDefaultColormap(display, screen);
X def.pixel = 0;
X XParseColor(display, default_colormap, "yellow", &def);
X XAllocColor(display, default_colormap, &def);
X fedcolor = def.pixel;
X XParseColor(display, default_colormap, "red", &def);
X XAllocColor(display, default_colormap, &def);
X romcolor = def.pixel;
X XParseColor(display, default_colormap, "green", &def);
X XAllocColor(display, default_colormap, &def);
X klicolor = def.pixel;
X XParseColor(display, default_colormap, "#0ff", &def);
X XAllocColor(display, default_colormap, &def);
X oricolor = def.pixel;
X }
X
X XMapWindow(display, win);
X /* Reset height */
X height = ship_height * 2;
X return;
X}
X
X/*
X * drawing code
X */
X
Xstatic void
Xredraw_xtrek()
X{
X register int x, y;
X int child, pid;
X#if !defined(cray)
X union wait status;
X#else
X int status;
X#endif
X int ntbool[4];
X char glyph;
X int hx, hy;
X int dohost;
X static XRectangle kliarea, oriarea, romarea, fedarea;
X static int areainit = 0;
X
X child = fork();
X if (child < 0)
X return;
X
X if (child == 0) {
X execlp("xtrek", "xtrek", "-q", "-s", host, 0);
X exit(-1);
X } else {
X /* Wait for child to exit. */
X do {
X pid = wait(&status);
X } while (pid >= 0 && pid != child);
X }
X
X#if !defined(cray)
X if (status.w_retcode == 0xFF) {
X exit(-1);
X }
X
X ntbool[0] = status.w_retcode & (1<<3);
X ntbool[1] = status.w_retcode & (1<<2);
X ntbool[2] = status.w_retcode & (1<<1);
X ntbool[3] = status.w_retcode & (1<<0);
X#else
X if ((status & 0xFF) != 0) {
X exit(-1);
X }
X
X status >>= 8;
X status &= 0xFF;
X ntbool[0] = status & (1<<3);
X ntbool[1] = status & (1<<2);
X ntbool[2] = status & (1<<1);
X ntbool[3] = status & (1<<0);
X#endif
X
X dohost = 0;
X hx = x = (width / 2);
X hy = y = (height / 2);
X x = (x - ship_width) / 2;
X y = (y - ship_height) / 2;
X if (sxfont) {
X y += (2 + (sxfont->ascent + sxfont->descent));
X }
X
X if (!areainit) {
X areainit++;
X kliarea.x = x; kliarea.y = y;
X kliarea.width = ship_width; kliarea.height = ship_height;
X oriarea.x = x + hx; oriarea.y = y;
X oriarea.width = ship_width; oriarea.height = ship_height;
X romarea.x = x; romarea.y = y + hy;
X romarea.width = ship_width; romarea.height = ship_height;
X fedarea.x = x + hx; fedarea.y = y + hy;
X fedarea.width = ship_width; fedarea.height = ship_height;
X }
X
X if (ntbool[2] != tbool[2]) {
X XFillRectangles(display, win, cleargc, &kliarea, 1);
X XSetForeground(display, gc, klicolor);
X if (got_xtrekfont)
X glyph = KLI_GLYPHS + rosette(ntbool[2] ? 0 : 128);
X else
X glyph = ntbool[2] + '0';
X XDrawString(display, win, gc, x + 0, y + 0, &glyph, 1);
X dohost++;
X }
X tbool[2] = ntbool[2];
X
X if (ntbool[3] != tbool[3]) {
X XFillRectangles(display, win, cleargc, &oriarea, 1);
X XSetForeground(display, gc, oricolor);
X if (got_xtrekfont)
X glyph = ORI_GLYPHS + rosette(ntbool[3] ? 0 : 128);
X else
X glyph = ntbool[3] + '0';
X XDrawString(display, win, gc, x + hx, y + 0, &glyph, 1);
X dohost++;
X }
X tbool[3] = ntbool[3];
X
X if (ntbool[1] != tbool[1]) {
X XFillRectangles(display, win, cleargc, &romarea, 1);
X XSetForeground(display, gc, romcolor);
X if (got_xtrekfont)
X glyph = ROM_GLYPHS + rosette(ntbool[1] ? 0 : 128);
X else
X glyph = ntbool[1] + '0';
X XDrawString(display, win, gc, x + 0, y + hy, &glyph, 1);
X dohost++;
X }
X tbool[1] = ntbool[1];
X
X if (ntbool[0] != tbool[0]) {
X XFillRectangles(display, win, cleargc, &fedarea, 1);
X XSetForeground(display, gc, fedcolor);
X if (got_xtrekfont)
X glyph = FED_GLYPHS + rosette(ntbool[0] ? 0 : 128);
X else
X glyph = ntbool[0] + '0';
X XDrawString(display, win, gc, x + hx, y + hy, &glyph, 1);
X dohost++;
X }
X tbool[0] = ntbool[0];
X
X if (dohost && sxfont) {
X XDrawImageString(display, win, sgc, 1, 1 + sxfont->ascent, host, strlen(host));
X }
X XFlush(display);
X return;
X}
END_OF_xtrekb.c
if test 11175 -ne `wc -c <xtrekb.c`; then
echo shar: \"xtrekb.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 5 \(of 11\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 11 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
dan
----------------------------------------------------
O'Reilly && Associates argv at sun.com / argv at ora.com
Opinions expressed reflect those of the author only.
More information about the Comp.sources.x
mailing list