[comp.sources.games] v03i026: trek73 - computer simulated Star Trek battles, Part05/06

games-request@tekred.TEK.COM (12/18/87)

Submitted by: Jeff Okamoto <okamoto%hpccc@hplabs.HP.COM>
Comp.sources.games: Volume 3, Issue 26
Archive-name: trek73/Part05



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 5 (of 6)."
# Contents:  man/03.t man/10.t man/Makefile man/header man/trek73.6
#   src/Makefile src/defines.h src/dist.c src/endgame.c src/mission.c
#   src/parsit.c src/save.c src/subs.c
# Wrapped by billr@tekred on Thu Dec 17 11:43:38 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f man/03.t -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/03.t\"
else
echo shar: Extracting \"man/03.t\" \(3279 characters\)
sed "s/^X//" >man/03.t <<'END_OF_man/03.t'
X.sp
X.LP
X21.  Detonate Engineering.
X.PP
X[nothing | [y | n]]
X.PP
XThis order, issued after the previous one, manually detonates
Xyour engineering section.
XIt may also be issued without the previous order, in
Xwhich case you will be asked to confirm your (suicidal) order.
X.sp
X.LP
X22.  Alter Torpedo And Phaser Firing Parameters.
X.PP
X[[y [Launch Speed] [Time Delay] [Proximity Fuse]] | n]
X[[y [Firing Percentage]] | n]
X.PP
XThis option allows you to change the launch speeds, time and
Xproximity delays of your torpedos.
XAt the beginning of play, torpedos are launched at warp
Xtwelve, have ten second time fuses, and 200M proximity
Xfuses.
XAny vessel or engineering section which comes within the
Xproximity range will cause the torpedo to explode.
X.sp
X.PP
XPhaser firing percentages can also be altered.
XA phaser bank need not fire its full charge.
X.sp
X.LP
X23.  Defenseless Ruse.
X.PP
X[e | p]
X.PP
XAnother name for this tactic is `playing dead'.
XWhen issued, your shields are dropped to zero, and power is
Xdiverted to your engines or phaser banks.
XHopefully, the enemy will believe you dead and come too
Xclose or break off their attack.
XYou should then be able to fire or run in the opposite
Xdirection.
X.sp
X.LP
X24.  Attempt Corbomite Bluff(s).
X.PP
XThere were two corbomite bluffs in the television series;
Xone was against an alien operating a huge space vessel the
Xother was against Romulan attackers.
XBoth have been incorporated into this game.
XWhichever bluff issued is selected randomly.
X.sp
X.LP
X25.  Surrender.
X.PP
XThis order sends a message to the enemy, saying that you
Xwish to surrender.
XThe enemy will then decide whether or not take you alive.
XYou will have difficulty surrendering to Romulans, who have
Xnever accepted one.
X.sp
X.LP
X26.  Ask Enemy To Surrender.
X.PP
XThis order ends a message to the enemy demanding that they
Xsurrender.
XPlease bear in mind that Romulans and Orions are the most suicidal.
X.sp
X.LP
X27.  Initiate Self-Destruct.
X.PP
XThis order activates a twenty-second self-destruct sequence.
XBecause final destruct does not occur until ten turns after
Xinitialization, it is best to start it early, if at all.
XWhen you do explode, hopefully the force of your explosion will
Xalso destroy your attackers.
X.sp
X.LP
X28.  Abort Self-Destruct.
X.PP
XThis order, issued after the previous one, halts the
Xdestruct sequence.
XSelf-destruct cannot be aborted within five seconds to
Xdetonation.
X.sp
X.LP
X29.  Survivors Report.
X.PP
XThis order prints out the number of survivors on board all the ships.
XThis order does not use a turn.
XCloaked ships are reported as having `???' survivors.
X.sp
X.LP
X30.  Print version number
X.PP
XThis command, which does not use a turn, prints the current version
Xof TREK73.
X.sp
X.LP
X31.  Save game
X.PP
XThis command saves the current game into a file.
XIt can be restarted later by using the command line option `-R'.
X.sp
X.LP
X32.  Reprint Above List.
X.PP
XThis command, which does not use a turn, lists code numbers
Xand associated descriptions of each.
X.sp
X.LP
X33 And Up.
X.PP
XFuture options, currently being designed in Trek74, will
Xinclude Dr. Daystrom's paranoid, M5 multi-tronics computer
Xwhich will take over while you relax; or battle someone else
Xwho is on another terminal; or battle in teams; or have a
Xfree-for-all against nine other players.
X.sp
X.bp
END_OF_man/03.t
if test 3279 -ne `wc -c <man/03.t`; then
    echo shar: \"man/03.t\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f man/10.t -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/10.t\"
else
echo shar: Extracting \"man/10.t\" \(3527 characters\)
sed "s/^X//" >man/10.t <<'END_OF_man/10.t'
X.bp
X.ce
XAPPENDIX 5
X.sp 2
X.ce
XDesigner's Notes
X.sp 2
X.PP
XWhen I was about 10 or 11, I would go to the Lawrence Hall of Science
Xquite frequently.
XThere, on their time-sharing system, I would sit at a Teletype Model 33
Xand play $TREK.
X(Does anyone out there remember XEQ-$TREK?)
X.PP
XSadly, LHS replaced their system and $TREK went away.
XIt was my intention that it should not be forgotten.
XI had had a copy of a slightly different version of $TREK written in
XBASIC, but it was sadly unimplementable on my Apple ][+ computer.
X.PP
XWhen I learned of an implementation of $TREK called trek73 that was
Xwritten in C, I jumped at the chance to bring it to the systems
Xat UC Berkeley.
XAt that time, the game was mostly a direct translation of the original
XBASIC source.
XMany of the commands and routines were either missing or faulty.
XWith Peter Yee, we worked together to fix up the program and managed
Xto get it running.
X.PP
XOnce it was running, the time came for improvements.
XI admit to pulling many concepts from the game Star Fleet Battles, most
Xnotably the different races (Hydrans, Lyrans, etc.) and the ship names.
X.PP
XThis version of the game represents many hours of thinking
Xand debugging.
XI hope you enjoy playing it as much as I did coding it.
X.sp
X.IP " " 30
X-Jeff Okamoto
X.sp 2
X.PP
XMy first experience with TREK73 was also at the Lawrence Hall
Xof Science.
XI had been taking classes in Time-Sharing Basic and noticed that other
Xpeople always talked about a game called $TREK that was a real CPU hog
Xand was usually turned off.
XNaturally I was intrigued.
XSoon I was paying $2.00 an hour for the chance to play that game.
XMany long hours and quite a few dollars went into playing $TREK,
Xso it was with a certain sadness that I learned that the DG Eclipse on
Xwhich $TREK ran was being phased out.
XI made several attempts to obtain the source before it went away, but
XI was unable to get it.
X.PP
XFortunately for me, Dave Pare at UC San Diego was also a fan
Xof the game, and more importantly, he had an outdated copy
Xof the source from an HP 2000.
XDave had started to implement the game in C to run under 4.2 BSD UNIX.
XExpressing my interest to Dave, I was able to get a copy of Dave's code
Xand thus the TREK Project at Berkeley was started.
XI spent endless hours tweaking with Dave's code, implementing some of
Xthe fifteen or so commands that he had not yet translated.
X.PP
XAt about this time, I learned that Christopher Williams, here at
XBerkeley, had also tried to implement the game in C.
XWhat is more, he had a copy of the source (in BASIC) from Berkeley
XHigh School, and had implemented most of the commands.
XMerging the work that Chris had done into my copy of Dave's work led
Xto a fairly complete version of the game.
XThere still remained a large number of bugs, poor ideas, and outright
Xmistakes in the code, but it ran.
X.PP
XJeff Okamoto, being a fan of the game and a Star Fleet Battles
Xplayer, was greatly interested in hacking on the game to bring up to
Xpar with the version that ran at LHS and to extend it even beyond
Xthat.
XThus our partnership was formed and the current version of the game
Xrepresents several hundred hours of our joint work (and play).
XAlso represented are the suggestions, modifications and bug fixes
Xwe received from numerous people, including (to name a few)
XMatt Dillon, David Sharnoff, Joel Duisman, and Roger Noe.
X.PP
XIt is hoped that this implementation of a classic game will bring joy
X(and perhaps fond remembrances) to all who play.
X.sp
X.IP " " 30
XLive Long and Prosper,
X.br
X-Peter Yee
END_OF_man/10.t
if test 3527 -ne `wc -c <man/10.t`; then
    echo shar: \"man/10.t\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f man/Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/Makefile\"
else
echo shar: Extracting \"man/Makefile\" \(1365 characters\)
sed "s/^X//" >man/Makefile <<'END_OF_man/Makefile'
X#
X# Makefile for TREK73 documentation
X#
X
X#
X# Select destination directory for manuals and documents
XMANDIR = /usr/local/man6
XCATDIR = /usr/local/cat6
XDOCDIR = /usr/local/doc
X
XTEXT = header 00.t 01.t 02.t 03.t 04.t 04.5.t 05.t 06.t 07.t 08dd.t\
X       08cl.t 08ca.t 08dn.t 09dd.t 09cl.t 09ca.t 09dn.t 10.t
XTREKDOC = trek73.doc
X
XTREKSRC= trek73.6
XTREKMAN = trek73.man
XPRTSRC = bpv.6
XPRTMAN = bpv.man
XSHIPSRC = shipyard.6
XSHIPMAN = shipyard.man
X
XSHAR1 = 00.t 01.t 02.t 03.t 04.t 04.5.t 05.t 06.t 07.t 08dd.t
XSHAR2 = 08cl.t 08ca.t 08dn.t 09dd.t 09cl.t 09ca.t 09dn.t 10.t
XSHAR3 = Makefile header trek73.6 bpv.6 shipyard.6
XSHARFL = -c
X
Xall: $(TREKDOC) $(TREKMAN) $(PRTMAN) $(SHIPMAN)
X
Xinstall: $(TREKDOC) $(TREKMAN) $(PRTMAN) $(SHIPMAN)
X	cp $(TREKSRC) $(MANDIR)
X	cp $(PRTSRC) $(MANDIR)
X	cp $(SHIPSRC) $(MANDIR)
X	cp $(TREKDOC) $(DOCDIR)
X	cp $(TREKMAN) $(CATDIR)
X	cp $(PRTMAN) $(CATDIR)
X	cp $(SHIPMAN) $(CATDIR)
X
X$(TREKDOC): $(TEXT)
X	nroff -ms $(TEXT) > $@
X
X$(TREKMAN): $(TREKSRC)
X	nroff -man $(TREKSRC) > $@
X
X$(PRTMAN): $(PRTSRC)
X	nroff -man $(PRTSRC) > $@
X
X$(SHIPMAN): $(SHIPSRC)
X	nroff -man $(SHIPSRC) > $@
X
Xclean:
X	\rm -f shar.doc1 shar.doc2 shar.doc3 make.out $(TREKMAN) \
X	$(TREKDOC) $(PRTMAN) $(SHIPMAN)
X
Xshar: shar.doc1 shar.doc2 shar.doc3
X
Xshar.doc1:
X	shar $(SHARFL) $(SHAR1) > $@
Xshar.doc2:
X	shar $(SHARFL) $(SHAR2) > $@ 
Xshar.doc3:
X	shar $(SHARFL) $(SHAR3) > $@
END_OF_man/Makefile
if test 1365 -ne `wc -c <man/Makefile`; then
    echo shar: \"man/Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f man/header -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/header\"
else
echo shar: Extracting \"man/header\" \(58 characters\)
sed "s/^X//" >man/header <<'END_OF_man/header'
X.ND
X.ds CF - % -
X.ds CH 
X.nr PO 0.5i
X.nr LL 6.5i
X.nr PD 0
END_OF_man/header
if test 58 -ne `wc -c <man/header`; then
    echo shar: \"man/header\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f man/trek73.6 -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/trek73.6\"
else
echo shar: Extracting \"man/trek73.6\" \(3395 characters\)
sed "s/^X//" >man/trek73.6 <<'END_OF_man/trek73.6'
X.TH TREK73 6 "04 Mar 1986"
X.UC 4
X.SH NAME
Xtrek73 - A Star Trek simulation
X.SH SYNOPSIS
Xtrek73 [-tcsSECNHfrdyTnFl]
X.SH DESCRIPTION
X.PP
X.I Trek73
Xis one of many Star Trek simulations now available.
XIn its time, it was considered one of the best.
X.PP
XThe player takes on the role of a starship commander
Xwho is involved in a battle against enemy alien ships.
X.PP
XYour starship can be one of four classes, or it can
Xeven be a ship of your own design -- see 
X.I shipyard
X(6).
X.PP
XAt your control are the ships' massive warp engines,
Xits main weapons, the phaser banks and photon torpedos,
Xand its defensive set of shields.
XUsing these and your own ingenuity, you must form and
Ximplement a strategy that will lead you to victory.
X.PP
XAlso at your disposal are such tactics as the defenseless ruse,
Xand the corbomite bluff.
X.PP
XReminiscent of
X.I ls
X(1),
X.I trek73
Xhas a large number of options:
X.TP
X.B \-t
XTurns on terse mode.
XNo initial scenario description is given.
XThis is useful for terminals running at low baud rates.
XThis option is normally off.
X.TP
X.B \-c
XAllows the specification of the Federation captain's name.
X.TP
X.B \-s
XSpecify the sex of the captain of the Federation vessel.
X.TP
X.B \-S
XSpecify the name of the Science Officer of the Federation vessel.
XBy default the Science Officer is Mr. Spock.
X.TP
X.B \-E
XSpecify the name of the Chief Engineer of the Federation vessel.
XBy default the Chief Engineer is Mr. Scott.
X.TP
X.B \-C
XSpecify the name of the Communications Officer of the Federation vessel.
XBy default the Communications Officer is Lieutenant Uhura.
X.TP
X.B \-N
XSpecify the name of the Navigator of the Federation vessel.
XBy default the Navigator is Ensign Chekov.
X.TP
X.B \-H
XSpecify the name of the Helmsman of the Federation vessel.
XBy default the Helmsman is Lieutenant Sulu.
X.TP
X.B \-f
XSpecify the name of the enemy commanding officer.
X.TP
X.B \-r
XSpecify the race of the enemy.
XThe race should be one of the following:
XKlingon, Romulan, Kzinti, Gorn, Hydran, Lyran, Tholian, Orion,
Xor Monty Python.
X.TP
X.B \-d
XSet the delay time for command entry.
XHigher times can be useful for novices or for playing on very slow
Xterminals.
X.TP
X.B \-y
XSilly option.
XAdds the Monty Pythons as a possible enemy race.
XThis option is normally off.
X.TP
X.B \-T
XTeletype option.
XCauses certain parts of the output to come out as they did on the
Xoriginal teletype implementation.
XDoesn't do much for the game on crts.
XThis option is normally off.
X.TP
X.B \-n
XSpecify the name of the Federation vessel.
XThe default name for the Federation vessel is randomly chosen from a
Xset of names.
X.TP
X.B \-F
XSpecify the class of the enemy vessel(s).
XAllowable classes are Destroyer (DD), Light Cruiser (CL),
XHeavy Cruiser (CA), and Dreadnought (DN).
XIf the argument is none of the above, the program assumes that this is
Xthe name of a file where a player-designed ship is stored.
X.TP
X.B \-l
XSpecify the class of the Federation vessel.
XClasses available are the same as the enemy's.
X.SH FILES
X.TP
X$HOME/.trek??	Non-standard class ship
X.SH SEE ALSO
XJeff Okamoto,
X.I "The Star Trek Battle Manual"
X.SH AUTHORS
XWilliam K. Char, Perry Lee, and Dan Gee 
Xwrote the initial TREK73 in BASIC.
XDave Pare and Chris Williams translated the BASIC into C.
XJeff Okamoto, Peter Yee, and others corrected and enhanced the code.
X.SH BUGS
XHopefully none.
XBug reports should be sent to: ..!hplabs!hpccc!okamoto and ..!ucbvax!yee.
END_OF_man/trek73.6
if test 3395 -ne `wc -c <man/trek73.6`; then
    echo shar: \"man/trek73.6\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/Makefile\"
else
echo shar: Extracting \"src/Makefile\" \(5046 characters\)
sed "s/^X//" >src/Makefile <<'END_OF_src/Makefile'
X#
X# Makefile for TREK73
X#
X
X#
X# Select which operating system you are using.
X# Acceptable flags are BSD and SYSV.
X#OS =	-DBSD
XOS =	-DSYSV
X
X#
X# Select whether you wish to use symbolic debugger or not.
X# NOTE: UNIX System V Release 2.0 cannot do profiling on programs
X# compiled with -g.  Also, sdb will not be very useful if the
X# symbols are stripped from the load module. (See STRIP)
X#SDB =	-g
XSDB =
X
X#
X# Select whether code optimization is to be done.
XOPT =	-O
X#OPT =
X
X#
X# Select whether profiling is to be done.
X# NOTE: In System V Relase 2.0, this is incompatible with
X# both SDB and STRIP.
X# PROF =	-p
XPROF =
X
X#
X# Select whether or not the load module is to be stripped.
X# This is incompatible with both SDB and PROF.
X# Note: In BSD Unix, this option should always be blank
X# STRIP =	-s
XSTRIP =
X
X#
X# Select the method by which the binaries are to be installed.
X# Install is better if you have it.
X# INSTALL = install
XINSTALL = cp
X
X#
X# Select whether or not tracing mode is to be turned on.
X# This is useful when testing new strategies.
X#TRACE =	-DTRACE
X
X#
X# Select whether or not you want the command line parser.
X# This may slow the game down, since lex/yacc is inefficient.
XPARSER = -DPARSER
X
X#
X# Select whether or not to include the getopt.o module.
X# Generally, AT&T-derived systems will have getopt.o already
X# included in libc.  This may not be true of BSD UNIX.
X#GETOPT = getopt.o
X
X#
X# Select the destination directory for the game.
XDESTDIR = /usr/local/bin
X
X#
X# Select flags for shar
XSHARFL = -c
X
X#
X# Options that you should think about setting
X#
X# SHOWTORP: When set, the player decides whether or not photon
X#     torpedos should show up on a position display (command 13)
X#     If not set, torpedos will automatically be displayed.
X#
X# PARANOID: If you want ALL the checking of a save file that rogue
X#     provides, set this.  If you want to be cool, don't set it.
X#
X# NOTDEF: This option only makes sense if you have also set PARANOID.
X#     This option defeats making a link to a save file and then
X#     restarting the game from the link.
X#
X# HISTORICAL: If this option is set, then any ship which takes more
X#     than 43 points of actual damage would explode.  This led to
X#     much abuse of high-pod probes.  For more details, cf damage.c
X#
XOPTIONS =
X
XDEFINES = $(OS) $(PARSER) $(TRACE)
XCFLAGS = $(DEFINES) $(SDB) $(OPT) $(PROF) $(STRIP) $(OPTIONS)
X
XT73OBJECTS = cmds1.o cmds2.o cmds3.o cmds4.o damage.o dist.o endgame.o\
X	enemycom.o firing.o globals.o init.o main.o misc.o mission.o\
X	moveships.o parseopts.o save.o ships.o special.o strat1.o\
X	subs.o vers.o $(GETOPT)
X
XT73CFILES = cmds1.c cmds2.c cmds3.c cmds4.c damage.c dist.c endgame.c\
X	enemycom.c firing.c globals.c init.c main.c misc.c mission.c\
X	moveships.c parseopts.c save.c ships.c special.c strat1.c\
X	subs.c vers.c
X
XPARSEFILES = command.l grammar.y
X
XPRTOBJECTS = bpv.o ships.o printships.o
X
XPRTFILES = bpv.c ships.c printships.c
X
XDYOOBJECTS = shipyard.o bpv.o
X
XDYOFILES = shipyard.c bpv.c
X
XHEADS= defines.h externs.h structs.h union.h
X
XRDIST = $(T73CFILES) $(PARSEFILES) $(PRTFILES) $(DYOFILES) $(HEADS)
X
X#
X# If you are not using the parser, you do not need the lex and yacc libs
X#
X# Note: Some systems have all the lex and yacc modules in either libl
X# or liby.  If your linker complains, try removing one or the other
XLIBS= -lm -ll -ly
X
XFLUFF = parsit.o lex.yy.c y.tab.c grammar.c grammar.o\
X	make.out errs core lint.errs a.out tags\
X	shar.1 shar.2 shar.3 shar.4 shar.5 shar.6
X
XSHAR1 = Makefile defines.h externs.h structs.h cmds1.c
XSHAR2 = cmds2.c cmds3.c cmds4.c damage.c
XSHAR3 = dist.c endgame.c enemycom.c firing.c globals.c
XSHAR4 = init.c main.c misc.c mission.c moveships.c
XSHAR5 =	parseopts.c parsit.c save.c ships.c special.c strat1.c subs.c vers.c 
XSHAR6 = bpv.c printships.c shipyard.c command.l grammar.y union.h getopt.c
X
XBINS = trek73 printships shipyard
X
Xall:	trek73 printships shipyard
X
Xtrek73:	$(T73OBJECTS) grammar.o parsit.o
X	cc $(CFLAGS) -o $@ $(T73OBJECTS) grammar.o parsit.o $(LIBS)
X
Xprintships:	$(PRTOBJECTS)
X	cc $(CFLAGS) -o $@ $(PRTOBJECTS) -lm
X
Xshipyard:	$(DYOOBJECTS)
X	cc $(CFLAGS) -o $@ $(DYOOBJECTS) -lm
X
Xinstall: trek73 printships shipyard
X	$(INSTALL) trek73 $(DESTDIR)
X	$(INSTALL) printships $(DESTDIR)
X	$(INSTALL) shipyard $(DESTDIR)
X
X$(T73OBJECTS): $(HEADS)
X
X$(PRTOBJECTS): $(HEADS)
X
X$(DYOOBJECTS): $(HEADS)
X
Xgrammar.o: grammar.y union.h command.l
X	lex command.l
X	yacc grammar.y
X	mv y.tab.c grammar.c
X	cc -c $(CFLAGS) grammar.c
X
Xparsit.o: parsit.c
X	cc -c $(CFLAGS) parsit.c
X
Xtags: $(T73CFILES)
X	ctags $(T73CFILES) $(HEADS)
X
Xcount:
X	wc $(T73CFILES) $(HEADS)
X
X#
X# Flags for your lint may need to be changed
X#
Xlint:
X	lint -bx $(DEFINES) $(T73CFILES) > lint.errs
X
Xclean:
X	\rm -f $(BINS) $(T73OBJECTS) $(DYOOBJECTS) $(PRTOBJECTS) $(FLUFF)
X
Xshar: shar1 shar2 shar3 shar4 shar5 shar6
X
Xshar1:
X	shar $(SHARFL) $(SHAR1) > shar.1
Xshar2:
X	shar $(SHARFL) $(SHAR2) > shar.2
Xshar3:
X	shar $(SHARFL) $(SHAR3) > shar.3
Xshar4:
X	shar $(SHARFL) $(SHAR4) > shar.4
Xshar5:
X	shar $(SHARFL) $(SHAR5) > shar.5
Xshar6:
X	shar $(SHARFL) $(SHAR6) > shar.6
END_OF_src/Makefile
if test 5046 -ne `wc -c <src/Makefile`; then
    echo shar: \"src/Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/defines.h -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/defines.h\"
else
echo shar: Extracting \"src/defines.h\" \(4998 characters\)
sed "s/^X//" >src/defines.h <<'END_OF_src/defines.h'
X#ident "@(#) TREK73 $Header: defines.h,v 1.2 87/11/23 09:19:04 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/defines.h,v $
X *
X * $Header: defines.h,v 1.2 87/11/23 09:19:04 okamoto Exp $
X *
X * $Log:	defines.h,v $
X * Revision 1.2  87/11/23  09:19:04  09:19:04  okamoto (Jeff Okamoto)
X * Moved parse_opts flags here and removed parseopts.h
X * 
X * Revision 1.1  87/10/09  11:04:17  11:04:17  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: defines.h
X *
X * Defines for TREK73
X *
X */
X
X/* Globals externals */
Xextern char *strcpy(), *gets();
Xextern char *Gets();
Xextern float rectify(), bearing(), round();
X
X
X#ifdef BSD
Xextern long random();
X#endif
X#ifdef SYSV
X#define random()	((long)(rand()))
X#define srandom(seed)	(srand((unsigned)(seed)))
X#endif
X
X#define is_dead(sp, sys)	((sp)->status[sys] == 100)
X#define randm(x)		((int)random() % (x) + 1)
X#define syswork(sp, sys)	(randm(100) > (sp)->status[sys])
X#define toradians(x)		((double)(x)*.0174533)
X#define todegrees(x)		((double)(x)*57.2958)
X
X#define betw(i, j, k)	(((j) < (i)) && ((i) < (k)))
X#define min(x, y)	((x) < (y) ? (x) : (y))
X#define max(x, y)	((x) > (y) ? (x) : (y))
X
X#define cansee(x)	((x)->cloaking != C_ON)
X#define cantsee(x)	((x)->cloaking == C_ON)
X
X#define plural(n)	(((n) > 1) ? "s" : "")
X
X#ifndef NULL
X#define NULL	0
X#endif
X
X/*
X * for the item linked list
X */
X#define I_UNDEFINED	0
X#define I_SHIP		1
X#define I_TORPEDO	2
X#define I_PROBE		3
X#define I_ENG		4
X
X/*
X * for the ship status word
X */
X#define S_COMP		0
X#define S_SENSOR	1
X#define S_PROBE		2
X#define S_WARP		3
X#define S_ENG		4
X#define S_DEAD		5
X#define S_SURRENDER	6
X/* The following define must also be in structs.h */
X#define S_NUMSYSTEMS	4	/* Number of systems with damage descriptions */
X#define MAXSYSTEMS	7
X
X/*
X * for the status message turn off array (shutup[])
X */
X#define DISENGAGE	1		/* Autopilot disengaging */
X#define SHIELDSF	2		/* Shields fluctuating */
X#define PHASERS		3		/* Phasers disengaging */
X#define TUBES		(PHASERS + MAXPHASERS)	/* Tubes disengaging */
X#define SURRENDER	(TUBES + MAXTUBES)	/* Flag for enemy surrender */
X#define SURRENDERP	20		/* Flag for our surrender */
X#define PLAYDEAD	21		/* Flag for playing dead */
X#define CORBOMITE	22		/* Flag for corbomite bluff */
X#define BURNOUT		23		/* Flag for warp burnout */
X#define HIGHSHUTUP	(BURNOUT + 10)	/* Burnout + 10 */
X
X/*
X * Multiplier for shield 1
X */
X#define SHIELD1		1.5
X
X/*
X * Defines for the play status word
X */
X#define NORMAL		000
X#define F_SURRENDER	001
X#define E_SURRENDER	002
X
X/*
X * Phaser statuses
X */
X#define P_NORMAL	000
X#define P_DAMAGED	001
X#define P_FIRING	002
X
X/*
X * Tube statuses
X */
X#define T_NORMAL	000
X#define T_DAMAGED	001
X#define T_FIRING	002
X
X/*
X * Probe launcher status
X */
X#define PR_NORMAL	000
X#define PR_LAUNCHING	001
X#define PR_DETONATE	002
X#define PR_LOCK		004
X
X/*
X * Cloaking device status / capability
X */
X#define C_NONE		000
X#define C_OFF		001
X#define C_ON		002
X#define CLOAK_DELAY	2	/*
X				 * Number of turns after cloak is
X				 * dropped before it can be reactivated
X				 */
X
X/*
X * For the damage routine
X */
X#define D_PHASER	0
X#define D_ANTIMATTER	1
X
X/*
X * Some necessary constants
X */
X#define HIT_PER_POD	5
X#define PROX_PER_POD	50
X
X/*
X * A handy little routine
X */
X#define MKNODE(cast, star, number) (cast star)malloc(sizeof(cast) * number)
X
X/*
X * Definitions for the bad guys
X */
X#define MAXESHIPS	9
X#define MAXFEDS		9
X#define MAXECAPS	8
X#define MAXFOERACES	9
X
X/*
X * For the different ship classes
X */
X#define MAXSHIPCLASS	4
X#define MAXPHASERS	11
X#define MAXTUBES	11
X
X/*
X * Turn costs (either takes a turn or is a free command)
X */
X#define TURN	1
X#define	FREE	0
X
X/*
X * Type of torpedo object (can be probe, torpedo, or engineering)
X */
X#define TP_TORPEDO	0
X#define	TP_PROBE	1
X#define	TP_ENGINEERING	2
X
X/*
X * Defines for the end of game calls to warn and final
X */
X#define FIN_F_LOSE	0
X#define FIN_E_LOSE	1
X#define FIN_TACTICAL	2
X#define FIN_F_SURRENDER	3
X#define FIN_E_SURRENDER	4
X#define FIN_COMPLETE	5
X#define QUIT		6
X
X/*
X * Number of items we allow in space.
X */
X#define HIGHSLOT	300
X
X/*
X * Trace flags
X */
X#define TR_OFF		0
X#define TR_ON		1
X
X/*
X * Flags for parse_opts
X */
X#define	BOOLEAN	0
X#define STRING 1
X
X/*
X * Some hard constants
X */
X#define MIN_PHASER_SPREAD	10
X#define MAX_PHASER_SPREAD	45
X#define MAX_PHASER_RANGE	1000
X#define MAX_PHASER_CHARGE	10.
X#define MIN_PHASER_DRAIN	-MAX_PHASER_CHARGE
X#define MAX_PHASER_DRAIN	MAX_PHASER_CHARGE
X#define MAX_TUBE_CHARGE		10
X#define MAX_TUBE_PROX		500	/* 50 times the number of pods */
X#define MAX_TUBE_SPEED		12
X#define MAX_TUBE_TIME		10.
X#define MAX_PROBE_DELAY		15
X#define MIN_PROBE_CHARGE	10
X#define MIN_PROBE_PROX		50
X#define MIN_SENSOR_RANGE	100
X#define MAX_SENSOR_RANGE	50000
X
X#define INIT_P_SPREAD		MIN_PHASER_SPREAD
X#define INIT_P_LOAD		MAX_PHASER_CHARGE
X#define INIT_P_DRAIN		MAX_PHASER_DRAIN
X#define INIT_P_PERCENT		100
X#define INIT_T_LOAD		0
X#define INIT_T_PROX		200
X#define INIT_T_TIME		MAX_TUBE_TIME
X#define INIT_T_SPEED		MAX_TUBE_SPEED
X
X#define DEFAULT_TIME		30
END_OF_src/defines.h
if test 4998 -ne `wc -c <src/defines.h`; then
    echo shar: \"src/defines.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/dist.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/dist.c\"
else
echo shar: Extracting \"src/dist.c\" \(3415 characters\)
sed "s/^X//" >src/dist.c <<'END_OF_src/dist.c'
X#ident "@(#) TREK73 $Header: dist.c,v 1.1 87/10/09 11:04:52 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/dist.c,v $
X *
X * $Header: dist.c,v 1.1 87/10/09 11:04:52 okamoto Exp $
X *
X * $Log:	dist.c,v $
X * Revision 1.1  87/10/09  11:04:52  11:04:52  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: dist.c
X *
X * Power distribution routines
X *
X * distribute
X *
X */
X
X#include "externs.h"
X
X
Xdistribute(sp)
Xstruct ship *sp;
X{
X	register int i;
X	register float fuel;
X	register int load;
X	register int effload;
X	register int drain;
X	register int loop;
X	float shield;
X	struct ship *fed;
X
X	fed = shiplist[0];
X	/*
X	 * Granularity of 1 second as far as this loop is concerned
X	 */
X	for (loop = 0; loop < (int)timeperturn; loop++) {
X
X		fuel = sp->energy + sp->regen;	/* Slightly unrealistic */
X		/*
X		 * Calculate negative phaser drains
X		 */
X		for (i=0; i<sp->num_phasers; i++) {
X			load = sp->phasers[i].load;
X			drain = sp->phasers[i].drain;
X			if ((sp->phasers[i].status & P_DAMAGED)
X			    || (drain >= 0) || (load <= 0))
X				continue;
X			/*
X			 * Drain the lesser of either the current load if the
X			 * load is less than the drain, or the drain value
X			 */
X			effload = max(load + drain, 0);
X			fuel += load - effload;
X			sp->phasers[i].load = effload;
X		}
X		/*
X		 * Calculate shield drains
X		 */
X		shield = 0.0;
X		for (i=0; i<SHIELDS; i++)
X			shield += sp->shields[i].attemp_drain;
X		drain = ceil((double) shield);
X		/*
X		 * If all attempted drains are zero, or we have no
X		 * fuel, our shields are down!
X		 */
X		if ((shield * fuel == 0) && !shutup[SHIELDSF]
X		    && sp == shiplist[0]) {
X			printf("%s: %s, our shields are down!\n",engineer, title);
X			shutup[SHIELDSF]++;
X		}
X		/*
X		 * If there's not enough fuel to sustain the drains, then
X		 * ration it out in proportion to the attempted drains and
X		 * say that shields are fluctuating.
X		 */
X		if (drain <= fuel) {
X			fuel -= drain;
X			for (i=0; i<SHIELDS; i++)
X				sp->shields[i].drain = sp->shields[i].attemp_drain;
X		} else {
X			if (!shutup[SHIELDSF] && sp == shiplist[0]) {
X				printf("%s: %s, our shields are fluctuating!\n",
X				    engineer, title);
X				shutup[SHIELDSF]++;
X			}
X			for (i=0; i<SHIELDS; i++)
X				sp->shields[i].drain =
X				    sp->shields[i].attemp_drain *
X				    fuel / drain;
X			fuel = 0.;
X		}
X		/*
X		 * Calculate cloaking device drains.  If there is
X		 * in sufficient energy to run the device, then
X		 * it is turned off completely
X		 */
X		if (cantsee(sp)) {
X			if (fuel < sp->cloak_energy) {
X				if (sp == shiplist[0]) {
X					sp->cloaking = C_OFF;
X					printf("%s:  %s, there's not enough energy to",
X					    engineer, title);
X					puts("    keep our cloaking device activated.");
X				} else
X					(void) e_cloak_off(sp, fed);
X			} else
X				fuel -= sp->cloak_energy;
X		}
X		/*
X		 * Calculate positive phaser drains
X		 */
X		for (i=0; i<sp->num_phasers && fuel > 0; i++) {
X			if (fuel <=0.)
X				break;
X			load = sp->phasers[i].load;
X			drain = sp->phasers[i].drain;
X			if ((sp->phasers[i].status & P_DAMAGED)
X			    || load >= MAX_PHASER_CHARGE || drain <= 0)
X				continue;
X			/*
X			 * Load phasers either enough to top them off, or
X			 * the full drain
X			 */
X			effload = min(MAX_PHASER_CHARGE,
X			    load + min(drain, fuel));
X			fuel -= effload - load;
X			sp->phasers[i].load = effload;
X		}
X		/*
X		 * Now balance the level of energy with the numer of pods
X		 */
X		sp->energy = min(fuel, sp->pods);
X	}
X}
END_OF_src/dist.c
if test 3415 -ne `wc -c <src/dist.c`; then
    echo shar: \"src/dist.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/endgame.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/endgame.c\"
else
echo shar: Extracting \"src/endgame.c\" \(5052 characters\)
sed "s/^X//" >src/endgame.c <<'END_OF_src/endgame.c'
X#ident "@(#) TREK73 $Header: endgame.c,v 1.1 87/10/09 11:05:18 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/endgame.c,v $
X *
X * $Header: endgame.c,v 1.1 87/10/09 11:05:18 okamoto Exp $
X *
X * $Log:	endgame.c,v $
X * Revision 1.1  87/10/09  11:05:18  11:05:18  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: endgame.c
X *
X * prints end-of-game messages and warnings
X *
X * leftovers, final, warn
X *
X */
X
X#ifdef BSD
X#include <sys/file.h>
X#endif
X
X#include "externs.h"
X
X
Xleftovers()
X{
X	register struct list *lp;
X
X	for (lp = &head; lp != tail; lp = lp->fwd) {
X		if (lp->type == 0)
X			continue;
X		if (lp->type != I_SHIP)
X			return 1;
X	}
X	return 0;
X}
X
X
Xfinal(mesg)
Xint mesg;
X{
X	register int i;
X	register int j;
X	struct	ship *sp;
X	struct	ship *ep;
X	char buf[80];
X
X
X	sp = shiplist[0];
X	/* If we're getting that message again, ignore it. */
X	if ((mesg == 2) && (reengaged))
X		return;
X	switch (mesg) {
X	case FIN_F_LOSE:
X		starfleet();
X		printf("We have recieved confirmation that the U.S.S. %s,\n",
X			sp->name);
X		printf("   captained by %s, was destroyed by %s%s\n",
X		    captain, shipnum==1 ?"a ":"", foerace);
X		printf("   %s%s.  May future Federation officers\n",
X		    foestype, plural(shipnum));
X		printf("   perform better in their duties.\n\n");
X		break;
X	case FIN_E_LOSE:
X		starfleet();
X		printf("We commend Captain %s and the crew of the %s on their\n",
X		    captain, shipname);
X		printf("   fine performance against the %ss.  They are\n",
X		    foerace);
X		puts("   an inspiration to all Starfleet personnel.\n");
X		break;
X	case FIN_TACTICAL:
X		/*
X		 * Give him a chance to re-engage if he wants to.  If he does,
X		 * he has to get within a range of 3500 before he can again
X		 * try to dis-engage
X		 */
X		if (!reengaged) {
X			printf("%s:  %s, we are in a position to either disengage from the\n",
X			    science, title);
X			printf("   %ss, or re-engage them in combat.\n",
X			    foerace);
X			printf("   Do you wish to re-engage?\n");
X			printf("%s: [y or n] ", captain);
X			(void) Gets(buf, sizeof(buf));
X			if ((*buf == NULL) || (*buf == 'y') || (*buf == 'Y')) {
X				reengaged = 1;
X				return;
X			}
X		}
X		starfleet();
X		printf("Captain %s of the starship %s has\n",captain,sp->name);
X		printf("   out-maneuvered %s aggressors.  We commend\n",foerace);
X		printf("   his tactical ability.\n");
X		break;
X	case FIN_F_SURRENDER:
X		starfleet();
X		printf("Captain %s has surrendered the U.S.S. %s \n",
X		    captain, sp->name);
X		printf("   to the %ss.  May Captain Donsell be remembered.\n",
X		    foerace);
X		break;
X	case FIN_E_SURRENDER:
X		starfleet();
X		printf("We have recieved word from the %s that the\n",sp->name);
X		printf("   %ss have surrendered.\n",foerace);
X		break;
X	case FIN_COMPLETE:
X		starfleet();
X		puts("One of our scout vessels has encountered the wreckage of");
X		printf("   the %s and %d other %s vessel%s.\n", sp->name,
X			shipnum, foerace, plural(shipnum));
X		break;
X	case QUIT:
X		starfleet();
X		printf("We have received word that Captain %s of the\n",
X		    captain);
X		printf("  starship %s has sold out to the %ss.\n",sp->name,
X		    foerace);
X		printf("  May he soon be court-martialled.\n");
X		break;
X	default:
X		printf("How did we get here? final(%d)\n", mesg);
X		break;
X	}
X	puts("\n\n");
X	j = 0;
X	for (i=0; i<=shipnum; i++) {
X		ep = shiplist[i];
X		if (is_dead(ep, S_DEAD))
X			continue;
X		if (!j)
X			puts("Survivors Reported:\n");
X		j++;
X	}
X	if (j) {
X		for (i=0; i<=shipnum; i++) {
X			ep = shiplist[i];
X			if ((is_dead(ep, S_DEAD)) || (ep->complement <= 0))
X				printf("   %s -- destroyed\n",
X				    ep->name);
X			else
X				printf("   %s -- %d\n",
X				    ep->name, ep->complement);
X		}
X	} else
X		puts("*** No survivors reported ***\n");
X	exit (1);
X}
X
X
X
Xwarn(mesg)
Xint mesg;
X{
X	static	int beenhere[5] = {0, 0, 0, 0, 0};
X	struct	ship *sp;
X
X	if ((reengaged) && (mesg == 2)) {
X		return 0;
X	}
X	if (beenhere[mesg])
X		return 0;
X	sp = shiplist[0];
X	switch (mesg) {
X	case FIN_F_LOSE:
X		printf("Message to the Federation:  This is Commander\n");
X		printf("   %s of the %s %s.  We have defeated\n",
X		    foename, foerace, empire);
X		printf("   the %s and are departing the quadrant.\n", sp->name);
X		break;
X	case FIN_E_LOSE:
X		printf("%s: All %s vessels have been either\n",
X		    science, foerace);
X		printf("   destroyed or crippled.  We still, however, have\n");
X		printf("   antimatter devices to avoid.\n");
X		break;
X	case FIN_TACTICAL:
X		printf("%s: The %ss are falling behind and seem to\n",
X		    helmsman, foerace);
X		printf("   be breaking off their attack.\n");
X		break;
X	case FIN_F_SURRENDER:
X		printf("%s: I'm informing Starfleet Command of our \n", com);
X		printf("   disposition.\n");
X		break;
X	case FIN_E_SURRENDER:
X		printf("%s: Although the %ss have surrendered,\n",
X		    science, foerace);
X		printf("   there are still antimatter devices floating\n");
X		printf("   around us.\n");
X		break;
X	default:
X		printf("How did we get here? final(%d)\n", mesg);
X		break;
X	}
X	beenhere[mesg]++;
X	return 0;
X}
X
Xstarfleet()
X{
X	puts("\n\nStarfleet Command: \n");
X	(void) sleep(3);
X	putchar('\n');
X}
END_OF_src/endgame.c
if test 5052 -ne `wc -c <src/endgame.c`; then
    echo shar: \"src/endgame.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/mission.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/mission.c\"
else
echo shar: Extracting \"src/mission.c\" \(4937 characters\)
sed "s/^X//" >src/mission.c <<'END_OF_src/mission.c'
X#ident "@(#) TREK73 $Header: mission.c,v 1.1 87/10/09 11:08:31 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/mission.c,v $
X *
X * $Header: mission.c,v 1.1 87/10/09 11:08:31 okamoto Exp $
X *
X * $Log:	mission.c,v $
X * Revision 1.1  87/10/09  11:08:31  11:08:31  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: mission.c
X *
X * Mission Assignment Routines
X *
X * mission, alert, missionlog
X */
X
X#ifdef BSD
X#include <sys/time.h>
X#endif
X#ifdef SYSV
X#include <time.h>
X#endif
X
X#include "externs.h"
X
X
Xmission()
X{
X	int onef;
X	char temp[3];
X
X	if (terse)
X		return;
X	onef = (shipnum == 1);
X	puts("\n\n\nSpace, the final frontier.");
X	printf("These are the voyages of the starship %s.\n", shiplist[0]->name);
X	puts("Its five year mission: to explore strange new worlds,");
X	puts("to seek out new life and new civilizations,");
X	puts("to boldly go where no man has gone before!");
X	puts("\n                    S T A R    T R E K\n");
X	missionlog();
X	if (onef)
X		strcpy(temp, "a");
X	else
X		sprintf(temp,"%d", shipnum);
X	printf("%s:  %s, I'm picking up %s vessel%s on an interception\n",
X	    helmsman, title, temp, plural(shipnum));
X	printf("   course with the %s.\n", shiplist[0]->name);
X	printf("%s:  Sensors identify %s as ", science, onef ? "it" : "them");
X	if (onef)
X		printf("a%s ", vowelstr(foerace));
X	printf("%s %s%s,\n", foerace, foestype, plural(shipnum));
X	printf("   probably under the command of Captain %s.\n", foename);
X	printf("%s:  Sound general quarters, Lieutenant!\n", captain);
X	printf("%s:  Aye, %s!\n", com,  title);
X}
X
Xalert()
X{
X	register int i;
X
X	printf("Computer: The %ss are attacking the %s with the ",
X	    foerace, shiplist[0]->name);
X	if (shipnum == 1) {
X		printf("%s", shiplist[1]->name);
X	} else {
X		for (i = 1; i <= shipnum; i++) {
X			if (i == shipnum)
X				printf("and the ");
X			printf("%s", shiplist[i]->name);
X			if (i == shipnum)
X				continue;
X			printf(", ");
X			if (i == 1 || i == 6)
X				printf("\n   ");
X		}
X	}
X	printf(".\n");
X}
X
Xmissionlog()
X{
X	static char *missiontab[] = {
X
X	/* "The Trouble with Tribbles" */
X	"   We are acting in response to a Priority 1 distress call from",
X	"space station K7.",
X
X	/* "The Gamesters of Triskelion" */
X	"   We are orbiting Gamma 2 to make a routine check of automatic",
X	"communications and astrogation stations.",
X
X	/* "Metamorphosis" */
X	"   We are on course for Epsilon Canares 3 to treat Commissioner",
X	"Headford for Sukaro's disease.",
X
X	/* "Journey to Babel" */
X	"   We have been assigned to transport ambassadors to a diplomatic",
X	"conference on the planet code named Babel.",
X
X	/* ?? */
X	"   Our mission is to investigate a find of tritanium on Beta 7.",
X	0,
X
X	/* "Shore Leave" */
X	"   We are orbiting Rigel 4 for therapeutic shore leave.",
X	0,
X
X	/* "A Piece of the Action" */
X	"   We are orbiting Sigma Iota 2 to study the effects of",
X	"contamination upon a developing culture.",
X
X	/* "The Immunity Syndrome" */
X	"   We have altered course for a resue mission on the Gamma 7A",
X	"system.",
X
X	/* "Amok Time" */
X	"   We are presently on course for Altair 6 to attend inauguration",
X	"cermonies on the planet.",
X
X	/* "Who Mourns for Adonis?" */
X	"   We are on a cartographic mission to Pollux 9.",
X	0,
X
X	/* "The Changeling" */
X	"   We are headed for Malurian in response to a distress call",
X	"from that system.",
X
X	/* "Mirror, Mirror" */
X	"   We are to negotiate a treaty to mine dilithium crystals from",
X	"the Halkans.",
X
X	/* "The Apple" */
X	"   We are to investigate strange sensor readings reported by a",
X	"scoutship investigating Gamma Triangula 6.",
X
X	/* "The Doomsday Machine" */
X	"   We are headed for planets L370 and L374 to investigate the",
X	"disappearance of the starship Constellation in that vincinity.",
X
X	/* "The Ultimate Computer" */
X	"   We are ordered, with a skeleton crew, to proceed to Space",
X	"Station K2 to test Dr. Richard Daystrom's computer M5.",
X
X	/* "Bread and Circuses" */
X	"   We have encountered debris from the SS Beagle and are",
X	"proceeding to investigate.",
X
X	/* "Patterns of Force" */
X	"   We are on course for Ekos to locate John Gill.",
X	0,
X
X	/* "The Paradise Syndrome" */
X	"   We are to divert an asteroid from destroying an inhabited",
X	"planet.",
X
X	/* "And The Children Shall Lead" */
X	"   We are responding to a distresss call form the scientific",
X	"expedition on Triacus.",
X
X	/* "Is There in Truth No Beauty?" */
X	"   We have been assigned to transport the Medusan Ambassador to",
X	"to his home planet.",
X
X	/* "Star Trek II -- The Wrath of Khan" */
X	"   We are within the Neutral Zone on a mission to rescue the",
X	"Kobayashi Maru.",
X
X	};
X	long t1;
X	struct tm *localtime(), *date;
X
X	t1 = time(0);
X	date = localtime(&t1);
X	printf("%s:  Captain's log, stardate %02d%02d.%02d\n",
X	    captain, date->tm_year, date->tm_mon+1, date->tm_mday);
X	t1 = (randm(sizeof missiontab / sizeof (char *)) - 1) & ~01;
X	puts(missiontab[t1]);
X	if (missiontab[++t1])
X		printf("   %s\n", missiontab[t1]);
X}
END_OF_src/mission.c
if test 4937 -ne `wc -c <src/mission.c`; then
    echo shar: \"src/mission.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/parsit.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/parsit.c\"
else
echo shar: Extracting \"src/parsit.c\" \(3289 characters\)
sed "s/^X//" >src/parsit.c <<'END_OF_src/parsit.c'
X#ident "@(#) TREK73 $Header: parsit.c,v 1.1 87/10/09 11:10:13 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/parsit.c,v $
X *
X * $Header: parsit.c,v 1.1 87/10/09 11:10:13 okamoto Exp $
X *
X * $Log:	parsit.c,v $
X * Revision 1.1  87/10/09  11:10:13  11:10:13  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: parsit.c
X *
X * Parse and get input
X *
X * Gets, parsit (courtesy, P. Lapsley)
X *
X */
X
X#ifdef SYSV
X#define index strchr
X#endif
X
X#include <stdio.h>
Xextern void free();
Xextern char *gets(), *malloc(), *strcpy(), *index();
X
Xstatic int gindx;
Xstatic char **argv;
X
Xchar *
XGets(buf, len)
Xchar *buf;
Xint len;
X{
X	register char *tmp;
X
X	if ((argv == NULL) || (argv[gindx] == NULL)) {
X		(void) fgets(buf, len, stdin);
X		if (tmp = index(buf, '\n'))
X			*tmp = '\0';
X		return(buf);
X	}
X	++gindx;
X	if ((argv == NULL) || (argv[gindx] == NULL)) {
X		(void) fgets(buf, len, stdin);
X		if (tmp = index(buf, '\n'))
X			*tmp = '\0';
X		return (buf);
X	}
X	(void) strcpy (buf, argv[gindx]);
X	puts (buf);
X	return (buf);
X}
X
X/*
X** parsit.c  23 September 1984  P. Lapsley (phil@Berkeley.ARPA)
X**
X** Parse a string of words separated by spaces into an
X** array of pointers to characters, just like good ol' argv[]
X** and argc.
X**
X** Usage:
X**
X** char line[132];
X** char **argv;
X** int argc;
X**
X**	argv = (char **) NULL;
X**	argc = parsit(line, &argv);
X**
X** returns the number of words parsed in argc.  argv[argc] will
X** be (char *) NULL to indicate end of list, if you're not
X** happy with just knowing how many words you have.
X**
X** Note that setting argv = (char **) NULL is only done the first
X** time the routine is called with a new "argv" -- it tells
X** parsit that "argv" is a new array, and parsit shouldn't free
X** up the elements (as it would do if it were an old array).
X*/
X
X
Xparsit(line, array)
Xchar *line;
Xchar ***array;
X{
X	char *malloc();
X	char word[132];
X	char *linecp;
X	int i, j, num_words;
X
X	gindx = 0;
X	argv = *array;
X	if (argv != (char **) NULL) {  /* Check to see if we should */
X		/* free up the old array */
X		for (i=0; argv[i] != (char *) NULL; i++) {
X			free(argv[i]);	/* If so, free each member */
X		}
X		free((char *)argv);		/* and then free the ptr itself */
X	}
X
X	linecp = line;
X	num_words = 0;
X	while (1) {	/* count words in input */
X		for (; *linecp == ' ' || *linecp == '\t'; ++linecp)
X			;
X		if (*linecp == '\0')
X			break;
X
X		for (; *linecp != ' ' && *linecp != '\t' && *linecp != '\0'; ++linecp)
X			;
X		++num_words;
X		if (*linecp == '\0')
X			break;
X	}
X
X	/* Then malloc enough for that many words plus 1 (for null) */
X
X	if ((argv = (char **) malloc((unsigned)((num_words + 1) * sizeof(char *)))) ==
X		(char **) NULL) {
X		fprintf(stderr, "parsit: malloc out of space!\n");
X		return(0);
X	}
X
X	j = i = 0;
X	while (1) {	/* Now build the list of words */
X		for (; *line == ' ' || *line == '\t'; ++line)
X			;
X		if (*line == '\0')
X			break;
X
X		i = 0;
X		for (; *line != ' ' && *line != '\t' && *line != '\0'; ++line)
X			word[i++] =  *line;
X		word[i] = '\0';
X		argv[j] = malloc(strlen(word) + 1);
X		if (argv[j] == (char *) NULL) {
X			fprintf(stderr, "parsit: malloc out of space!\n");
X			return(0);
X		}
X
X		(void) strcpy(argv[j], word);
X		++j;
X		if (*line == '\0')
X			break;
X	}
X	argv[j] = (char *) NULL;  /* remember null at end of list */
X	*array = argv;
X	return(j);
X}
X
X
END_OF_src/parsit.c
if test 3289 -ne `wc -c <src/parsit.c`; then
    echo shar: \"src/parsit.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/save.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/save.c\"
else
echo shar: Extracting \"src/save.c\" \(5523 characters\)
sed "s/^X//" >src/save.c <<'END_OF_src/save.c'
X#ident "@(#) TREK73 $Header: save.c,v 1.1 87/10/09 11:10:52 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/save.c,v $
X *
X * $Header: save.c,v 1.1 87/10/09 11:10:52 okamoto Exp $
X *
X * $Log:	save.c,v $
X * Revision 1.1  87/10/09  11:10:52  11:10:52  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: save.c
X *
X * save and restore routines
X *
X * @(#)save.c	4.15 (Berkeley) 5/10/82
X */
X
X#include <stdio.h>
X#ifdef BSD
X#include <strings.h>
X#endif
X#ifdef SYSV
X#include <string.h>
X#endif
X#include <pwd.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <signal.h>
X
X#define MAXSTR	256
X
Xtypedef struct stat STAT;
X
Xextern char *sys_errlist[], version[], encstr[];
Xextern int errno;
X
Xchar *sbrk();
X
XSTAT sbuf;
X
Xextern void exit();
X
Xset_save()
X{
X	register char		*env;
X	register struct passwd	*pw;
X	struct passwd		*getpwuid();
X	char			*getpass();
X	unsigned short		getuid();
X	extern char		home[];
X	extern char		savefile[];
X	char			*getenv();
X
X	if ((env = getenv("HOME")) != NULL)
X		strcpy(home, env);
X	else if ((pw = (struct passwd *)getpwuid((int)getuid()))
X	    != NULL)
X		strcpy(home, pw->pw_dir);
X	else
X		home[0] = '\0';
X	strcat(home, "/");
X
X	strcpy(savefile, home);
X	strcat(savefile, "trek73.save");
X}
X
X/*
X * save_game:
X *	Implement the "save game" command
X */
Xsave_game()
X{
X    register FILE *savef;
X    register int c;
X    char buf[MAXSTR];
X    extern char savefile[];
X    void perror();
X
X    /*
X     * get file name
X     */
X
Xover:
X    if (savefile[0] != '\0')
X    {
X	for (;;)
X	{
X	    printf("Save file (%s)? ", savefile);
X	    c = getchar();
X	    if (c == 'n' || c == 'N' || c == 'y' || c == 'Y')
X		break;
X	    else
X		printf("\nPlease answer Yes or No");
X	}
X	if (c == 'y' || c == 'Y')
X	{
X	    strcpy(buf, savefile);
X	    goto gotfile;
X	}
X    }
X
X    do
X    {
X	stdin->_cnt = 0;
X	printf("File name: ");
X	buf[0] = '\0';
X	gets(buf);
Xgotfile:
X	/*
X	 * test to see if the file exists
X	 */
X	if (stat(buf, &sbuf) >= 0)
X	{
X	    for (;;)
X	    {
X		stdin->_cnt = 0;
X		printf("\nFile exists.  Do you wish to overwrite it?");
X		if (c == 'y' || c == 'Y')
X		    break;
X		else if (c == 'n' || c == 'N')
X		    goto over;
X		else
X		    printf("\nPlease answer Y or N");
X	    }
X	}
X	strcpy(savefile, buf);
X	if ((savef = fopen(savefile, "w")) == NULL)
X	    perror("Trek73: Save problems");
X    } while (savef == NULL);
X
X    /*
X     * write out encrpyted file (after a stat)
X     * The fwrite is to force allocation of the buffer before the write
X     */
X    save_file(savef);
X    exit(0);
X}
X
X/*
X * save_file:
X *	Write the saved game on the file
X */
Xsave_file(savef)
Xregister FILE *savef;
X{
X    /*
X     * close any open save file
X     */
X    (void) fstat(fileno(savef), &sbuf);
X    /*
X     * DO NOT DELETE.  This forces stdio to allocate the output buffer
X     * so that malloc doesn't get confused on restart
X     */
X    fwrite("junk", 1, 5, savef);
X
X    fseek(savef, 0L, 0);
X    encwrite(version, (unsigned int) (sbrk(0) - version), savef);
X    fclose(savef);
X    exit(0);
X}
X
X/*
X * restore:
X *	Restore a saved game from a file with elaborate checks for file
X *	integrity from cheaters
X */
Xrestore(file, envp)
Xchar *file;
Xchar **envp;
X{
X    register int inf;
X#ifdef PARANOID
X    register char syml;
X#endif PARANOID
X    extern char **environ;
X    char buf[MAXSTR];
X    long lseek();
X    STAT sbuf2;
X    void perror();
X
X#ifdef BSD
X    (void) signal(SIGTSTP, SIG_IGN);
X#endif
X#ifdef SYSV
X    (void) signal(SIGQUIT, SIG_IGN);
X#endif
X
X    if ((inf = open(file, 0)) < 0)
X    {
X	perror(file);
X	return 0;
X    }
X    (void) fstat(inf, &sbuf2);
X#ifdef PARANOID
X#ifdef BSD
X    syml = symlink(file);
X#endif
X#ifdef SYSV
X    syml = link(file);
X#endif
X    if (unlink(file) < 0)
X    {
X	printf("Cannot unlink file\n");
X	return 0;
X    }
X#endif PARANOID
X
X    fflush(stdout);
X    encread(buf, (unsigned int) (strlen(version) + 1), inf);
X    if (strcmp(buf, version) != 0)
X    {
X	printf("Sorry, saved game is out of date.\n");
X	return 0;
X    }
X
X    fflush(stdout);
X    brk(version + sbuf2.st_size);
X    lseek(inf, 0L, 0);
X    encread(version, (unsigned int) sbuf2.st_size, inf);
X#ifdef PARANOID
X    /*
X     * we do not close the file so that we will have a hold of the
X     * inode for as long as possible
X     */
X	if (sbuf2.st_ino != sbuf.st_ino || sbuf2.st_dev != sbuf.st_dev)
X	{
X	    printf("Sorry, saved game is not in the same file.\n");
X	    return 0;
X	}
X#ifdef NOTDEF
X    /*
X     * defeat multiple restarting from the same place
X     */
X	if (sbuf2.st_nlink != 1 || syml)
X	{
X	    printf("Cannot restore from a linked file %d %d\n", sbuf2.st_nlink, syml);
X	    exit(1);
X	}
X#endif
X#endif PARANOID
X#ifdef BSD
X    (void) signal(SIGTSTP, SIG_DFL);
X#endif
X#ifdef SYSV
X    (void) signal(SIGQUIT, SIG_DFL);
X#endif
X
X    environ = envp;
X    stdin->_cnt = 0;
X    playit();
X#ifdef PARANOID
X    syml = syml;		/* LINT */
X#endif PARANOID
X    /*NOTREACHED*/
X}
X
X/*
X * encwrite:
X *	Perform an encrypted write
X */
Xencwrite(start, size, outf)
Xregister char *start;
Xunsigned int size;
Xregister FILE *outf;
X{
X    register char *ep;
X
X    ep = encstr;
X
X    while (size--)
X    {
X	putc(*start++ ^ *ep++, outf);
X	if (*ep == '\0')
X	    ep = encstr;
X    }
X}
X
X/*
X * encread:
X *	Perform an encrypted read
X */
Xencread(start, size, inf)
Xregister char *start;
Xunsigned int size;
Xregister int inf;
X{
X    register char *ep;
X    register int read_size;
X
X    if ((read_size = read(inf, start, size)) == -1 || read_size == 0)
X	return read_size;
X
X    ep = encstr;
X
X    while (size--)
X    {
X	*start++ ^= *ep++;
X	if (*ep == '\0')
X	    ep = encstr;
X    }
X    return read_size;
X}
X
END_OF_src/save.c
if test 5523 -ne `wc -c <src/save.c`; then
    echo shar: \"src/save.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/subs.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/subs.c\"
else
echo shar: Extracting \"src/subs.c\" \(5499 characters\)
sed "s/^X//" >src/subs.c <<'END_OF_src/subs.c'
X#ident "@(#) TREK73 $Header: subs.c,v 1.1 87/10/09 11:13:01 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/subs.c,v $
X *
X * $Header: subs.c,v 1.1 87/10/09 11:13:01 okamoto Exp $
X *
X * $Log:	subs.c,v $
X * Revision 1.1  87/10/09  11:13:01  11:13:01  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: subs.c
X *
X * Miscellaneous Subroutines
X *
X * ship_name, newitem, delitem, rangefind, bearing, phaser_hit,
X * torpedo_hit, antimatter_hit, round, rectify
X */
X
X#include "externs.h"
X#include <ctype.h>
X
X
Xstruct ship *
Xship_name(name)
Xchar *name;
X{
X	register int i;
X	register int j;
X	register int len;
X
X	if (isascii(*name) && islower(*name))
X		*name = toupper(*name);
X	j = shipnum;
X	len = strlen(name);
X	for (i=1; i<=j; i++) {
X		if (shiplist[i]->complement < 0)
X			continue;
X		if (!strncmp(name, shiplist[i]->name, len))
X			return shiplist[i];
X	}
X	printf("%s: I am unable to find the %s\n", science, name);
X	return NULL;
X}
X
X
Xstruct list *
Xnewitem(item)
Xint item;
X{
X	register struct	list *new;
X	register struct	list *newtail;
X
X	/*
X	 * if there's no "tail" node, make one (only happens at init)
X	 */
X	if (tail == NULL) {
X		new = MKNODE(struct list, *, 1);
X		if (new == (struct list *)NULL) {
X			fprintf(stderr, "newitem: malloc failed\n");
X			exit(2);
X		}
X		new->back = &head;
X		new->fwd = NULL;
X		new->data.tp = NULL;
X		head.fwd = new;
X		tail = new;
X	}
X	new = tail;
X	/*
X	 * now make the new tail node
X	 */
X	newtail = MKNODE(struct list, *, 1);
X	if (newtail == (struct list *)NULL) {
X		fprintf(stderr, "newitem: malloc failed\n");
X		exit(2);
X	}
X	newtail->back = new;
X	newtail->fwd = NULL;
X	newtail->data.tp = NULL;
X	newtail->type = 0;
X	tail = newtail;
X	/*
X	 * link the old tail node to the new one
X	 */
X	new->type = item;
X	new->fwd = newtail;
X	return new;
X}
X
X
Xint
Xdelitem(item)
Xstruct list *item;
X{
X	register struct list *bp;
X	register struct list *fp;
X
X	bp = item->back;
X	fp = item->fwd;
X	if (item->data.tp != NULL)
X		free((char *) item->data.tp);
X	/*
X	 * re-arrange pointers on both the next and the previous
X	 * nodes; if no forward pointer, we were the tail so make
X	 * the bp the new tail node.
X	 */
X	if (fp != NULL) {
X		bp->fwd = fp;
X		fp->back = bp;
X	} else {
X		tail = bp;
X		bp->fwd = NULL;
X	}
X	free((char *) item);
X}
X
Xint
Xrangefind(xfrom, xto, yfrom, yto)
Xint xfrom;
Xint xto;
Xint yfrom;
Xint yto;
X{
X	register double x, y;
X
X	x = xto - xfrom;
X	y = yto - yfrom;
X	if (x == 0.0 && y == 0.0)
X		return 0;
X	else
X	return (int) hypot(x, y);
X}
X
X/*
X * This routine finds the bearing of (xto,yto) from (xfrom,yfrom)
X */
Xfloat
Xbearing(xfrom, xto, yfrom, yto)
Xint xfrom;
Xint xto;
Xint yfrom;
Xint yto;
X{
X	register double x, y;
X	register float bear;
X
X	x = xto - xfrom;
X	y = yto - yfrom;
X	if (x == 0.0 && y == 0.0)
X		bear = 0.0;
X	else
X		bear = todegrees(atan2(y, x));
X	bear = rectify(bear);
X	return bear;
X}
X
Xint
Xphaser_hit(sp, x, y, bank, true_bear)
Xstruct ship *sp;
Xint x;
Xint y;
Xstruct phaser *bank;
Xfloat true_bear;
X{
X	register int hit;
X	int	i;
X	float	spread;
X	float	bear;
X	double	d1;
X	double	d2;
X
X	hit = 0;
X	i = rangefind(sp->x, x, sp->y, y);
X	if (i < MAX_PHASER_RANGE) {
X		bear = bearing(sp->x, x, sp->y, y);
X		spread = rectify(true_bear - bear);
X		/*
X		 * Check if a target is within the phaser spread
X		 */
X		if (betw(spread, sp->p_spread, 360-spread))
X			return 0;
X		d1 = 1.0 - (float)i/MAX_PHASER_RANGE;
X		d2 = (float)bank->load * sqrt(d1) * sp->p_percent / 100;
X		/* XXXX */
X		/*
X		 * This may have to be changed if phaser spread or maximum
X		 * phaser load is changed
X		 */
X		d2 = (float)bank->load * d2 * 45.0/(float)sp->p_spread * sp->p_percent / 100;
X		hit = d2/10.0;
X	}
X	return hit;
X}
X
Xint
Xtorpedo_hit(fuel, x, y, tx, ty)
Xint fuel;
Xint x;
Xint y;
Xint tx;
Xint ty;
X{
X	register int hit;
X	int	i;
X	double	d1;
X	double	d2;
X	float	f1;
X	float	f2;
X
X	hit = 0;
X	i = rangefind(x, tx, y, ty);
X	f1 = fuel * HIT_PER_POD;
X	f2 = fuel * PROX_PER_POD;
X	if (i < f2) {
X		d1 = 1.0 - (float)i/f2;
X		d2 = (float)f1 * sqrt(d1);
X		hit = d2;
X	}
X	return hit;
X}
X
X
Xint
Xantimatter_hit(ptr, x, y, fuel)
Xchar *ptr;
Xint x;
Xint y;
Xint fuel;
X{
X	register struct list *lp;
X	register int hit;
X	int	tarx, tary;
X	int	s;
X	float	bear;
X	struct 	torpedo *tp;
X	struct	ship *sp;
X
X	for (lp = &head; lp != tail; lp = lp->fwd) {
X		if (lp->type == 0)
X			continue;
X		sp = NULL;
X		tp = NULL;
X		if (lp->type == I_SHIP) {
X			sp = lp->data.sp;
X			tarx = sp->x;
X			tary = sp->y;
X		} else {
X			tp = lp->data.tp;
X			tarx = tp->x;
X			tary = tp->y;
X		}
X		if (sp == (struct ship *) ptr || tp == (struct torpedo *) ptr)
X			continue;
X		hit = torpedo_hit(fuel, x, y, tarx, tary);
X		if (hit <= 0)
X			continue;
X		if (sp) {
X			/* 
X			 * Determine which shield is hit
X			 */
X			bear = rectify(bearing(tarx, x, tary, y) - sp->course);
X			if (bear <= 45.0 || bear >= 315.0)
X				s = 1;
X			else if (bear <= 135.0)
X				s = 2;
X			else if (bear < 225.0)
X				s = 3;
X			else
X				s = 4;
X			(void) damage(hit, sp, s, &a_damage, D_ANTIMATTER);
X		} else {
X			if (tp->timedelay <= segment)
X				continue;
X			tp->timedelay = segment;
X			switch (lp->type) {
X				case I_TORPEDO:
X					printf("hit on torpedo %d\n", 
X						tp->id);
X					break;
X				case I_PROBE:
X					printf("hit on probe %d\n", 
X						tp->id);
X					break;
X				case I_ENG:
X					printf("hit on %s engineering\n",
X						tp->from->name);
X					break;
X				default:
X					printf("hit on unknown item %d\n",
X					    tp->id);
X			}
X		}
X	}
X}
X
Xfloat
Xround(x)
Xfloat x;
X{
X	return(floor(x + 0.5));
X}
X
Xfloat
Xrectify(x)
Xfloat x;
X{
X	while (x < 0.0) {
X		x += 360.0;
X	}
X	while (x >= 360.0){
X		x -= 360.0;
X	}
X	return x;
X}
END_OF_src/subs.c
if test 5499 -ne `wc -c <src/subs.c`; then
    echo shar: \"src/subs.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 5 \(of 6\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0