summaryrefslogtreecommitdiffstats
path: root/trek
diff options
context:
space:
mode:
authorcgd <cgd@NetBSD.org>1993-03-21 09:45:37 +0000
committercgd <cgd@NetBSD.org>1993-03-21 09:45:37 +0000
commit77e3814f0c0e3dea4d0032e25666f77e6f83bfff (patch)
tree7eddfcbf3dd12089e71dc3fafb0a106c5c5766c7 /trek
parente81d63576b2e46ab90da7d75fa155ea57ee4d32e (diff)
downloadbsdgames-darwin-77e3814f0c0e3dea4d0032e25666f77e6f83bfff.tar.gz
bsdgames-darwin-77e3814f0c0e3dea4d0032e25666f77e6f83bfff.tar.zst
bsdgames-darwin-77e3814f0c0e3dea4d0032e25666f77e6f83bfff.zip
initial import of 386bsd-0.1 sources
Diffstat (limited to 'trek')
-rw-r--r--trek/DOC/read_me.nr251
-rw-r--r--trek/DOC/things10
-rw-r--r--trek/DOC/trekmanual.nr895
-rw-r--r--trek/Makefile17
-rw-r--r--trek/abandon.c157
-rw-r--r--trek/attack.c188
-rw-r--r--trek/autover.c77
-rw-r--r--trek/board.x59
-rw-r--r--trek/capture.c128
-rw-r--r--trek/cgetc.c44
-rw-r--r--trek/check_out.c70
-rw-r--r--trek/checkcond.c104
-rw-r--r--trek/compkl.c112
-rw-r--r--trek/computer.c343
-rw-r--r--trek/damage.c91
-rw-r--r--trek/damaged.c67
-rw-r--r--trek/dcrept.c99
-rw-r--r--trek/destruct.c110
-rw-r--r--trek/dock.c144
-rw-r--r--trek/dumpgame.c161
-rw-r--r--trek/dumpme.c88
-rw-r--r--trek/dumpssradio.c85
-rw-r--r--trek/events.c463
-rw-r--r--trek/externs.c98
-rw-r--r--trek/getcodi.c68
-rw-r--r--trek/getpar.c297
-rw-r--r--trek/getpar.h45
-rw-r--r--trek/help.c157
-rw-r--r--trek/impulse.c80
-rw-r--r--trek/initquad.c152
-rw-r--r--trek/kill.c227
-rw-r--r--trek/klmove.c182
-rw-r--r--trek/lose.c85
-rw-r--r--trek/lrscan.c107
-rw-r--r--trek/main.c235
-rw-r--r--trek/move.c230
-rw-r--r--trek/nova.c141
-rw-r--r--trek/out.c56
-rw-r--r--trek/phaser.c369
-rw-r--r--trek/play.c110
-rw-r--r--trek/ram.c101
-rw-r--r--trek/ranf.c57
-rw-r--r--trek/rest.c80
-rw-r--r--trek/schedule.c173
-rw-r--r--trek/score.c104
-rw-r--r--trek/setup.c303
-rw-r--r--trek/setwarp.c64
-rw-r--r--trek/shield.c143
-rw-r--r--trek/snova.c158
-rw-r--r--trek/srscan.c190
-rw-r--r--trek/systemname.c67
-rw-r--r--trek/torped.c247
-rw-r--r--trek/trek.690
-rw-r--r--trek/trek.h380
-rw-r--r--trek/utility.c150
-rw-r--r--trek/visual.c101
-rw-r--r--trek/warp.c182
-rw-r--r--trek/win.c89
58 files changed, 9081 insertions, 0 deletions
diff --git a/trek/DOC/read_me.nr b/trek/DOC/read_me.nr
new file mode 100644
index 00000000..226b8ffd
--- /dev/null
+++ b/trek/DOC/read_me.nr
@@ -0,0 +1,251 @@
+.de @h
+'sp 4
+'tl 'TREK SETUP INSTRUCTIONS''%'
+'sp 2
+.ns
+..
+.de @f
+'bp
+..
+.wh 0 @h
+.wh -6 @f
+.de pp
+.sp
+.ne 2
+.ti +5
+..
+.de s1
+.sp 2
+.nr S1 +1
+.nr S2 0
+.ne 5
+.in 4
+.ti 0
+\\n(S1.\ \ \c
+..
+.de s2
+.sp 1
+.nr S2 +1
+.ne 3
+.in 8
+.ti 4
+\\n(S2.\ \ \c
+..
+.br
+.ce
+TREK SETUP INSTRUCTIONS
+.sp 2
+.pp
+This document describes all sorts of nifty things
+you should know
+before you start to muck around
+with the trek source code.
+Please read them carefully.
+.s1
+MAINTENANCE
+.s2
+There are a number of shell files
+which you may use to maintain the system.
+"Prtrek" produces a copy of the source code.
+It pipes its output to lpr
+and runs in background.
+"Comp" compiles up to nine source modules
+and leaves them in .o files.
+"Compile" is the same as "comp"
+except that it loads after compiling.
+If stated without any arguments,
+it loads from .o files.
+"Compall" compiles all the .c files
+into .o files,
+but does not load.
+It redirects its output to the file "output".
+To recompile the entire system,
+type
+.ti +8
+compall
+.ti +8
+compile
+.br
+.s2
+Main.c contains a variable called "Mother".
+This is initialized to the result of the
+"getuid()" call for the maintainer of trek
+at your installation.
+Only Mother is allowed to set trace flags
+and run the game at other than the default priority.
+.s2
+Speaking of priorities,
+trek eats up a lot of system resources.
+Hence, it normally runs at a very low priority.
+This makes it almost impossible to play
+if the system is loaded.
+However,
+the -pN flag sets the priority to N,
+which makes it possible to debug
+when the system is loaded.
+The default priority is set by a #define of
+PRIO,
+which is set to 10 in the default system.
+.s2
+Trace information is provided
+which may be useful in debugging things in the system.
+If you are in a bad way for space,
+comment out the #define xTRACE
+which appears in trek.h.
+This will cause the trace stuff to not occur
+in the object.
+.s2
+The version of trek released to you
+is compiled with the -f flag (for no floating point)
+and should work without problems on your machine.
+You can edit out the -f flag
+in "compile" if you have floating point hardware
+on your machine
+so that it will take less space.
+.s1
+THE PORTABLE C LIBRARY
+.pp
+The portable C library was used
+to do I/O in trek.
+Unfortunately,
+the version which we had at Berkeley
+had a number of small bugs
+which caused trek to do bad things at times.
+For some unknown reason
+(temporary insanity perhaps)
+I rewrote the portable C library.
+This version is much smaller than the old version
+and has cleaner code.
+It also works right
+(???).
+However, there are a few minor differences
+which you should be aware of.
+.s2
+Scanf no longer ignores the noise characters "\\n",
+"\\t", and space in the format string;
+i.e.,
+these characters now require a match
+in the input stream.
+.s2
+A variable
+f_log
+has been added
+which is the file descriptor
+of a "log" file.
+If f_log is greater than zero
+a copy of everything read from
+the standard input
+and written to
+the standard output
+is written in the file f_log.
+.s1
+DISCLAIMERS
+.s2
+Frankly,
+I am getting pretty sick of playing this game.
+Hence,
+the version which you get may have several bugs
+in it;
+I freely admit
+that it is probably buggier
+than some previous versions.
+Sorry about that.
+.s2
+Along with being buggy,
+the game never had quite everything implemented
+that was originally intended.
+If you see things that look weird,
+that may be why.
+There are even some features which I have taken out
+(like ghost starsystems)
+upon deciding that I didn't have the energy
+to implement them correctly.
+.s1
+REQUESTS
+.pp
+There are several things that I would like to ask of anyone
+who does work on the source code.
+.s2
+Please let me know of any bugs which you find
+in the code,
+and any fixes which you may have.
+Other copies will probably be going out to other people later,
+and it would be nice if those copies where less buggy.
+Also,
+I would be interested in hearing about any
+enhancements of the game which you might install.
+.s2
+Please note that I have a distinct coding style.
+I feel that it is cleaner
+and easier to read than a more
+casual style.
+If possible,
+please stick to it,
+especially if you end up sending tapes back to me.
+This goes along with my whole belief in clean code:
+I ask you to please avoid obscure code
+whenever possible.
+If you throw some in,
+please don't let me see it.
+It just depresses me.
+.s2
+Unfortunately,
+the game is huge.
+There are many neat things
+which could go in,
+if there were only enough space.
+However,
+I have specifically not gone to seperated I/D
+space.
+The main reason is that I would like future versions
+of the game
+to be 11/40 compatible.
+.s1
+SUGGESTIONS FOR THE FUTURE
+.pp
+If you happen to have more energy than I do,
+you may want to examine the following areas.
+These are things that I may get to,
+but don't hold your breath.
+.s2
+Frankly,
+making the portable C library work
+(even without bugs)
+was a bitch.
+I should have done the I/O in a more
+ad hoc manner.
+It is my intent to rewrite the I/O
+routines to bypass the portable C library entirely.
+.s2
+The routine "capture" is quite unclean.
+First, it should have a manner of selecting Klingons
+other than random,
+either selecting the most likely
+or asking the captain (probably best).
+It should either be fully implemented,
+which includes adding a "board" routine
+(half written,
+on some tapes as board.x)
+which sends a boarding party to forcefully
+take over the Klingon,
+or it should go out completely,
+which is probably what I will end up doing.
+When this happens,
+the transporter will go completely.
+It seems that the space may be better used
+for something which more directly enhances the game.
+.sp 3
+.in 0
+Well, that's about it.
+To get hold of me,
+write to:
+.nf
+.sp
+Eric P Allman
+Electronics Research Laboratory
+University of California
+Berkeley, California 94720
+.fi
+
+Happy trekking!!
+.pp
diff --git a/trek/DOC/things b/trek/DOC/things
new file mode 100644
index 00000000..535a0c97
--- /dev/null
+++ b/trek/DOC/things
@@ -0,0 +1,10 @@
+* tractor beams
+* power distribution
+* Romulans:
+- plasma bolts
+- neutral zone
+- cloaking device
+* the thing
+* ion storms
+* torpedoes with time delays
+* Put removal from event list into killk
diff --git a/trek/DOC/trekmanual.nr b/trek/DOC/trekmanual.nr
new file mode 100644
index 00000000..33ead488
--- /dev/null
+++ b/trek/DOC/trekmanual.nr
@@ -0,0 +1,895 @@
+.br
+.po 10
+.if n \!.
+.sp 15
+.tr ^ \"
+.ce 88
+^****^^^^*****^^^^^^*^^^^^^****^
+*^^^^^^^^^^*^^^^^^^*^*^^^^^*^^^*
+^***^^^^^^^*^^^^^^*****^^^^****^
+^^^^*^^^^^^*^^^^^^*^^^*^^^^*^^*^
+****^^^^^^^*^^^^^^*^^^*^^^^*^^^*
+
+
+*****^^^^****^^^^^*****^^^^*^^^*
+^^*^^^^^^*^^^*^^^^*^^^^^^^^*^^*^
+^^*^^^^^^****^^^^^***^^^^^^***^^
+^^*^^^^^^*^^*^^^^^*^^^^^^^^*^^*^
+^^*^^^^^^*^^^*^^^^*****^^^^*^^^*
+
+
+by
+
+Eric Allman
+University of California
+Berkeley
+.ce 0
+.tr ^^
+.de HE
+'sp 4
+'tl 'STAR TREK''%'
+'sp 3
+..
+.de FO
+'bp
+..
+.wh 0 HE
+.wh -5 FO
+.de pp
+.sp
+.ti +4
+..
+.bp 1
+.ce
+INTRODUCTION
+.pp
+Well, the federation is once again at war with the Klingon empire.
+It is up to you,
+as captain of the U.S.S. Enterprise,
+to wipe out the invasion fleet and save the Federation.
+.pp
+For the purposes of the game
+the galaxy is divided into 64 quadrants
+on an eight by eight grid,
+with quadrant 0,0 in the upper left hand corner.
+Each quadrant is divided into 100 sectors
+on a ten by ten grid.
+Each sector contains one object
+(e.g., the Enterprise, a Klingon, or a star).
+.pp
+Navigation is handled in degrees,
+with zero being straight up
+and ninty being to the right.
+Distances are measured in quadrants.
+One tenth quadrant is one sector.
+.pp
+The galaxy contains starbases,
+at which you can dock to refuel,
+repair damages, etc.
+The galaxy also contains stars.
+Stars usually have a knack for getting in your way,
+but they can be triggered into going nova
+by shooting a photon torpedo at one,
+thereby (hopefully) destroying any adjacent Klingons.
+This is not a good practice however,
+because you are penalized for destroying stars.
+Also, a star will sometimes go supernova,
+which obliterates an entire quadrant.
+You must never stop in a supernova quadrant,
+although you may "jump over" one.
+.pp
+Some starsystems
+have inhabited planets.
+Klingons can attack inhabited planets
+and enslave the populace,
+which they then put to work building more Klingon battle cruisers.
+.bp
+.ce
+STARTING UP THE GAME
+.pp
+To request the game, issue the command
+.sp
+.ti +12
+/usr/games/trek
+.sp
+from the shell.
+If a filename is stated,
+a log of the game is written
+onto that file.
+If omitted,
+the file is not written.
+If the "-a" flag is stated before the filename,
+that file is appended to
+rather than created.
+.pp
+The game will ask you what length game
+you would like.
+Valid responses are "short", "medium", and "long".
+Ideally the length of the game does not
+affect the difficulty,
+but currently the shorter games
+tend to be harder than the longer ones.
+You may also type "restart",
+which restarts a previously saved game.
+.pp
+You will then be prompted for the skill,
+to which you must respond
+"novice", "fair", "good", "expert",
+"commadore", or "impossible".
+You should start out with a novice
+and work up,
+but if you really want to see how fast
+you can be slaughtered,
+start out with an impossible game.
+.pp
+In general,
+throughout the game,
+if you forget what is appropriate
+the game will tell you what it expects
+if you just type in
+a question mark.
+.pp
+To get a copy of these rules,
+execute the command
+.sp
+.ti +12
+nroff /usr/games/trekmanual.nr
+.sp
+.bp
+.ce
+ISSUING COMMANDS
+.pp
+If the game expects you to enter a command,
+.hc ^
+it will say ^"Command:\ "
+and wait for your response.
+Most commands can be abbreviated.
+.pp
+At almost any time you can type more than one thing on a line.
+For example,
+to move straight up one quadrant,
+you can type
+.ti +12
+move 0 1
+.br
+or you could just type
+.ti +12
+move
+.br
+and the game would prompt you with
+.ti +12
+Course:
+.br
+to which you could type
+.ti +12
+0 1
+.br
+The "1" is the distance,
+which could be put on still another line.
+Also, the "move" command
+could have been abbreviated
+"mov", "mo", or just "m".
+.pp
+If you are partway through a command
+and you change your mind,
+you can usually type "-1"
+to cancel the command.
+.pp
+Klingons generally cannot hit you
+if you don't consume anything
+(e.g., time or energy),
+so some commands are considered "free".
+As soon as you consume anything though -- POW!
+.bp
+.de **
+.if \\n+l .**
+.as x *
+..
+.de bl
+.nr l \\w'\\$1' -\\w'*'
+.ds x ****
+.**
+.sp 3
+.ne 3
+\\*x
+.br
+.if t *\h'\w'*'u'\fB\\$1\fP\h'\w'*'u'*
+.if n * \\$1 *
+.br
+\\*x
+.sp
+.in +8
+.nf
+..
+.de FF
+.in -8
+.fi
+..
+.if !\n(.V .ta \w'Full Commands: '+1
+.if \n(.V .ta \w'Full Commands: 'u
+.ce
+THE COMMANDS
+.bl "Short Range Scan"
+Mnemonic: srscan
+Shortest Appreviation: s
+Full Commands: srscan
+ srscan yes/no
+Consumes: nothing
+.FF
+.pp
+The short range scan
+gives you a picture
+of the quadrant you are in,
+and (if you say "yes")
+a status report
+which tells you
+a whole bunch
+of interesting stuff.
+You can get a status report alone
+by using the
+.ul
+status
+command.
+An example follows:
+.sp
+.nf
+.in +4
+Short range sensor scan
+ 0 1 2 3 4 5 6 7 8 9
+0 . . . . . . . * . * 0 stardate 3702.16
+1 . . E . . . . . . . 1 condition RED
+2 . . . . . . . . . * 2 position 0,3/1,2
+3 * . . . . # . . . . 3 warp factor 5.0
+4 . . . . . . . . . . 4 total energy 4376
+5 . . * . * . . . . . 5 torpedoes 9
+6 . . . @ . . . . . 6 shields down, 78%
+7 . . . . . . . . . . 7 Klingons left 3
+8 . . . K . . . . . . 8 time left 6.43
+9 . . . . . . * . . . 9 life support damaged, reserves = 2.4
+ 0 1 2 3 4 5 6 7 8 9
+Distressed Starsystem Marcus XII
+
+.in +8
+.ti -8
+The cast of characters is as follows:
+E the hero
+K the villain
+# the starbase
+* stars
+@ inhabited starsystem
+\&. empty space
+ a black hole
+.in -12
+.fi
+.pp
+The name of the starsystem is listed underneath
+the short range scan.
+The word "distressed", if present,
+means that the starsystem
+is under attack.
+.pp
+Short range scans are absolutely free.
+They use no time, no energy,
+and they don't give the Klingons
+another chance to hit you.
+.bl "Status Report"
+Mnemonic: status
+Shortest Abbreviation: st
+Consumes: nothing
+.FF
+.pp
+This command gives you information
+about the current status
+of the game and your ship, as follows:
+.in +8
+.de qq
+.sp
+.ti -4
+..
+.qq
+Stardate -- The current stardate.
+.qq
+Condition -- as follows:
+.in +4
+.nf
+RED -- in battle
+YELLOW -- low on energy
+GREEN -- normal state
+DOCKED -- docked at starbase
+CLOAKED -- the cloaking device is activated
+.fi
+.in -4
+.qq
+Position -- Your current quadrant and sector.
+.qq
+Warp Factor -- The speed you will move at
+when you move under warp power
+(with the
+.ul
+move
+command).
+.qq
+Total Energy -- Your energy reserves.
+If they drop to zero,
+you die.
+Energy regenerates,
+but the higher the skill of the game,
+the slower it regenerates.
+.qq
+Torpedoes -- How many photon torpedoes you have left.
+.qq
+Shields -- Whether your shields are up or down,
+and how effective they are if up
+(what percentage of a hit they will absorb).
+.qq
+Klingons Left -- Guess.
+.qq
+Time Left -- How long the Federation can hold out
+if you sit on your fat ass and do nothing.
+If you kill Klingons quickly,
+this number goes up,
+otherwise,
+it goes down.
+If it hits zero,
+the Federation is conquered.
+.qq
+Life Support -- If "active", everything is fine.
+If "damaged", your reserves tell you
+how long you have
+to repair your life support
+or get to a starbase
+before you starve, suffocate,
+or something equally unpleasant.
+.qq
+Current Crew -- The number of crew members
+left.
+This figures does not include officers.
+.qq
+Brig Space -- The space left in your brig
+for Klingon captives.
+.qq
+Klingon Power -- The number of units
+needed to kill a Klingon.
+Remember, as Klingons fire at you
+they use up their own energy,
+so you probably need somewhat less
+than this.
+.qq
+Skill, Length -- The skill and length
+of the game you are playing.
+.in -8
+.pp
+Status information is absolutely free.
+.bl "Long Range Scan"
+Mnemonic: lrscan
+Shortest Abbreviation: l
+Consumes: nothing
+.FF
+.pp
+Long range scan gives you information about the
+eight quadrants
+that surround the quadrant
+you're in.
+A sample long range scan follows:
+.sp
+.in +12
+.nf
+Long range scan for quadrant 0,3
+
+ 2 3 4
+ -------------------
+ ! * ! * ! * !
+ -------------------
+0 ! 108 ! 6 ! 19 !
+ -------------------
+1 ! 9 ! /// ! 8 !
+ -------------------
+.sp
+.in -12
+.fi
+.pp
+The three digit numbers
+tell the number of objects
+in the quadrants.
+The units digit tells the number of stars,
+the tens digit the number of starbases,
+and the hundreds digit is the number of Klingons.
+"*" indicates the negative energy barrier
+at the edge of the galaxy,
+which you cannot enter.
+"///" means that that is a supernova quadrant
+and must not be entered.
+.bl "Damage Report"
+Mnemonic: damages
+Shortest Abbreviation: da
+Consumes: nothing
+.FF
+.pp
+A damage report tells you what devices are damaged
+and how long it will take to repair them.
+Repairs proceed faster
+when you are docked
+at a starbase.
+.bl "Set Warp Factor"
+Mnemonic: warp
+Shortest Abbreviation: w
+Full Command: warp factor
+Consumes: nothing
+.FF
+.pp
+The warp factor tells the speed of your starship
+when you move under warp power
+(with the
+.ul
+move
+command).
+The higher the warp factor,
+the faster you go,
+and the more energy you use.
+.pp
+The minimum warp factor is 1.0
+and the maximum is 10.0.
+At speeds above warp 6
+there is danger of the warp engines
+being damaged.
+The probability of this
+increases at higher warp speeds.
+Above warp 9.0 there is a chance of entering
+a time warp.
+.bl "Move Under Warp Power"
+Mnemonic: move
+Shortest Abbreviation: m
+Full Command: move course distance
+Consumes: time and energy
+.FF
+.pp
+This is the usual way of moving.
+The course is in degrees and the distance is in quadrants.
+To move one sector specify a distance of 0.1.
+.pp
+Time is consumed proportionately to
+the inverse of the warp factor squared,
+and directly to the distance.
+Energy is consumed as the warp factor cubed,
+and directly to the distance.
+If you move with your shields up
+it doubles the amount of energy consumed.
+.pp
+When you move in a quadrant containing Klingons,
+they get a chance to attack you.
+.pp
+The computer detects navigation errors.
+If the computer is out,
+you run the risk of running into things.
+.pp
+The course is determined by the
+Space Inertial Navigation System
+[SINS].
+As described in
+Star Fleet Technical Order TO:02:06:12,
+the SINS is calibrated,
+after which it becomes the base for navigation.
+If damaged,
+navigation becomes inaccurate.
+When it is fixed,
+Spock recalibrates it,
+however,
+it cannot be calibrated extremely accurately
+until you dock at starbase.
+.bl "Move Under Impulse Power"
+Mnemonic: impulse
+Shortest Abbreviation: i
+Full Command: impulse course distance
+Consumes: time and energy
+.FF
+.pp
+The impulse engines give you a chance to maneuver
+when your warp engines are damaged;
+however, they are incredibly slow
+(0.095 quadrants/stardate).
+They require 20 units of energy to engage,
+and ten units per sector to move.
+.pp
+The same comments about the computer and the SINS
+apply as above.
+.pp
+There is no penalty to move under impulse power
+with shields up.
+.bl "Deflector Shields"
+Mnemonic: shields
+Shortest Abbreviation: sh
+Full Command: shields up/down
+Consumes: energy
+.FF
+.pp
+Shields protect you from Klingon attack
+and nearby novas.
+As they protect you,
+they weaken.
+A shield which is 78% effective
+will absorb 78% of a hit
+and let 22% in to hurt you.
+.pp
+The Klingons have a chance to attack you
+every time you raise or lower shields.
+Shields do not rise and lower
+instantaneously,
+so the hit you receive
+will be computed with the shields
+at an intermediate effectiveness.
+.pp
+It takes energy to raise shields,
+but not to drop them.
+.bl "Cloaking Device"
+Mnemonic: cloak
+Shortest Abbreviation: cl
+Full Command: cloak up/down
+Consumes: energy
+.FF
+.pp
+When you are cloaked,
+Klingons cannot see you,
+and hence they do not fire at you.
+They are useful for entering
+a quadrant
+and selecting a good position,
+however,
+weapons cannot be fired through
+the cloak
+due to the huge energy drain
+that it requires.
+.pp
+The cloak up command
+only starts the cloaking process;
+Klingons will continue
+to fire at you
+until you do something
+which consumes time.
+.bl "Fire Phasers"
+Mnmemonic: phasers
+Shortest Abbreviation: p
+Full Commands: phasers automatic amount
+ phasers manual amt1 course1 spread1 ...
+Consumes: energy
+.FF
+.pp
+Phasers are energy weapons;
+the energy comes from your ship's reserves
+("total energy" on a srscan).
+It takes about 250 units of hits
+to kill a Klingon.
+Hits are cumulative as long as you stay
+in the quadrant.
+.pp
+Phasers become less effective
+the further from a Klingon you are.
+Adjacent Klingons receive about
+90% of what you fire,
+at five sectors about 60%,
+and at ten sectors about 35%.
+They have no effect outside of the quadrant.
+.pp
+Phasers cannot be fired while shields are up;
+to do so would fry you.
+They have no effect on starbases or stars.
+.pp
+In automatic mode
+the computer decides how to divide up the energy
+among the Klingons present;
+in manual mode you do that yourself.
+.pp
+In manual mode firing
+you specify a direction,
+amount (number of units to fire)
+and spread (0 -> 1.0)
+for each of the six phaser banks.
+A zero amount
+terminates the manual input.
+.bl "Fire Photon Torpedoes"
+Mnemonic: torpedo
+Shortest Abbreviation: t
+Full Command: torpedo course [yes/no] [burst angle]
+Consumes: torpedoes
+.FF
+.pp
+Torpedoes are projectile weapons -- there are no partial hits.
+You either hit your target or you don't.
+A hit on a Klingon destroys him.
+A hit on a starbase destroys that starbase
+(woops!).
+Hitting a star usually causes it to go nova,
+and occasionally supernova.
+.pp
+Photon torpedoes cannot be aimed precisely.
+They can be fired with shields up,
+but they get even more random
+as they pass through the shields.
+.pp
+Torpedoes may be fired in bursts of three.
+If this is desired,
+the burst angle is the angle
+between the three shots,
+which may vary from one to fifteen.
+The word "no"
+says that a burst is not wanted;
+the word "yes"
+(which may be omitted
+if stated on the same line as the course)
+says that a burst is wanted.
+.pp
+Photon torpedoes
+have no effect
+outside the quadrant.
+.bl "Onboard Computer Request"
+Mnemonic: computer
+Shortest Abbreviation: c
+Full Command: computer request; request;...
+Consumes: nothing
+.FF
+.pp
+The computer command gives you access to the facilities
+of the onboard computer,
+which allows you to do all sorts of fascinating stuff.
+Computer requests are:
+.in +8
+.qq
+score -- Shows your current score.
+.qq
+course quad/sect -- Computes the course and distance from whereever
+you are to the given location.
+If you type "course /x,y"
+you will be given the course
+to sector x,y in the current quadrant.
+.qq
+move quad/sect -- Identical to the course
+request,
+except that the move is executed.
+.qq
+chart -- prints a chart of the known galaxy,
+i.e.,
+everything that you have seen with a long range scan.
+The format is the same as on a long range scan,
+except that "..." means
+that you don't yet know what is there,
+and ".1." means that you know that a starbase
+exists, but you don't know anything else.
+"$$$" mans the quadrant
+that you are currently in.
+.qq
+trajectory -- prints the course and distance
+to all the Klingons in the quadrant.
+.qq
+warpcost dist warp_factor -- computes the cost in time and energy
+to move `dist' quadrants at warp `warp_factor'.
+.qq
+impcost dist -- same as warpcost for impulse engines.
+.qq
+pheff range -- tells how effective your phasers are
+at a given range.
+.qq
+distresslist -- gives a list of currently distressed
+starbases
+and starsystems.
+.in -8
+.pp
+More than one request may be stated
+on a line
+by seperating them
+with semicolons.
+.bl "Dock at Starbase"
+Mnemonic: dock
+Shortest Abbreviation: do
+Consumes: nothing
+.FF
+.pp
+You may dock at a starbase
+when you are in one of the eight
+adjacent sectors.
+.pp
+When you dock you are resupplied
+with energy, photon torpedoes, and life support reserves.
+Repairs are also done faster at starbase.
+Any prisoners you have taken
+are unloaded.
+You do not recieve points
+for taking prisoners
+until this time.
+.pp
+Starbases have their own deflector shields,
+so you are safe from attack while docked.
+.bl "Undock from Starbase"
+Mnemonic: undock
+Shortest Abbreviation: u
+Consumes: nothing
+.FF
+.pp
+This just allows you to leave starbase
+so that you may proceed on your way.
+.bl "Rest"
+Mnemonic: rest
+Shortest Abbreviation: r
+Full Command: rest time
+Consumes: time
+.FF
+.pp
+This command allows you to rest to repair damages.
+It is not advisable to rest while under attack.
+.bl "Call Starbase For Help"
+Mnemonic: help
+Shortest Abbreviation: help
+Consumes: nothing
+.FF
+.pp
+You may call starbase for help via your subspace radio.
+Starbase has long range transporter beams to get you.
+Problem is,
+they can't always rematerialize you.
+.pp
+You should avoid using this command unless absolutely necessary,
+for the above reason and because it counts heavily against you
+in the scoring.
+.bl "Capture Klingon"
+Mnemonic: capture
+Shortest Abbreviation: ca
+Consumes: time
+.FF
+.pp
+You may request that a Klingon surrender
+to you.
+If he accepts,
+you get to take captives
+(but only as many as your brig
+can hold).
+It is good if you do this,
+because you get points for captives.
+Also,
+if you ever get captured,
+you want to be sure that the Federation
+has prisoners to exchange for you.
+.pp
+You must go to a starbase
+to turn over your prisoners
+to Federation authorities.
+.bl "Visual Scan"
+Mnemonic: visual
+Shortest Abbreviation: v
+Full Command: visual course
+Consumes: time
+.FF
+.pp
+When your short range scanners are out,
+you can still see what is out "there"
+by doing a visual scan.
+Unfortunately,
+you can only see three sectors at one time,
+and it takes 0.005 stardates to perform.
+.pp
+The three sectors in the general direction
+of the course specified
+are examined
+and displayed.
+.bl "Abandon Ship"
+Mnemonic: abandon
+Shortest Abbreviation: abandon
+Consumes: nothing
+.FF
+.pp
+The officers escape the Enterprise in the shuttlecraft.
+If the transporter is working
+and there is an inhabitable starsystem
+in the area,
+the crew beams down,
+otherwise you leave them to die.
+You are given an old but still usable ship,
+the Faire Queene.
+.bl "Ram"
+Mnemonic: ram
+Shortest Abbreviation: ram
+Full Command: ram course distance
+Consumes: time and energy
+.FF
+.pp
+This command is identical to "move",
+except that the computer
+doesn't stop you
+from making navigation errors.
+.pp
+You get very nearly slaughtered
+if you ram anything.
+.bl "Self Destruct"
+Mnemonic: destruct
+Shortest Abbreviation: destruct
+Consumes: everything
+.FF
+.pp
+Your starship is self-destructed.
+Chances are you will destroy
+any Klingons
+(and stars,
+and starbases)
+left in your quadrant.
+.bl "Terminate the Game"
+Mnemonic: terminate
+Shortest Abbreviation: terminate
+Full Command: terminate yes/no
+.FF
+.pp
+Cancels the current game.
+No score is computed.
+If you answer yes,
+a new game will be started,
+otherwise trek exits.
+.bl "Call the Shell"
+Mnemonic: shell
+Shortest Abbreviation: shell
+.FF
+.pp
+Temporarily escapes to the shell.
+When you log out of the shell
+you will return to the game.
+.bp
+.ce
+SCORING
+.in +4
+.pp
+The scoring algorithm is rather complicated.
+Basically,
+you get points for each Klingon you kill,
+for your Klingon per stardate kill rate,
+and a bonus if you win the game.
+You lose
+points for the number of Klingons left
+in the galaxy
+at the end of the game,
+for getting killed,
+for each star, starbase, or inhabited starsystem
+you destroy,
+for calling for help,
+and for each casualty you incur.
+.pp
+You will be promoted
+if you play very well.
+You will never get a promotion if you
+call for help,
+abandon the Enterprise,
+get killed,
+destroy a starbase or inhabited starsystem,
+or destroy too many stars.
+.bp
+.ce
+REFERENCE PAGE
+.sp 2
+.ta 36 56
+.nf
+.ul
+Command Uses Consumes
+
+ABANDON shuttlecraft, -
+ transporter
+CApture subspace radio time
+CLoak Up/Down cloaking device energy
+Computer request; request;... computer -
+DAmages - -
+DESTRUCT computer -
+DOck - -
+HELP subspace radio -
+Impulse course distance impulse engines, time, energy
+ computer, SINS
+Lrscan L.R. sensors -
+Move course distance warp engines, time, energy
+ computer, SINS
+Phasers Automatic amount phasers, computer energy
+Phasers Manual amt1 course1 spread1 ... phasers energy
+Torpedo course [Yes] angle/No torpedo tubes torpedoes
+RAM course distance warp engines, time, energy
+ computer, SINS
+Rest time - time
+SHELL - -
+SHields Up/Down shields energy
+Srscan [Yes/No] S.R. sensors -
+STatus - -
+TERMINATE Yes/No - -
+Undock - -
+Visual course - time
+Warp warp_factor - -
+.fi
diff --git a/trek/Makefile b/trek/Makefile
new file mode 100644
index 00000000..02754f37
--- /dev/null
+++ b/trek/Makefile
@@ -0,0 +1,17 @@
+# @(#)Makefile 5.8 (Berkeley) 5/11/90
+
+PROG= trek
+SRCS= abandon.c attack.c autover.c capture.c check_out.c checkcond.c \
+ compkl.c computer.c damage.c damaged.c dcrept.c destruct.c \
+ dock.c dumpgame.c dumpme.c dumpssradio.c events.c externs.c \
+ getcodi.c getpar.c help.c impulse.c initquad.c kill.c klmove.c \
+ lose.c lrscan.c main.c move.c nova.c out.c phaser.c play.c ram.c \
+ ranf.c rest.c schedule.c score.c setup.c setwarp.c \
+ shield.c snova.c srscan.c systemname.c torped.c utility.c \
+ visual.c warp.c win.c cgetc.c
+MAN6= trek.0
+DPADD= ${LIBM} ${LIBCOMPAT}
+LDADD= -lm -lcompat
+HIDEGAME=hidegame
+
+.include <bsd.prog.mk>
diff --git a/trek/abandon.c b/trek/abandon.c
new file mode 100644
index 00000000..431726ea
--- /dev/null
+++ b/trek/abandon.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)abandon.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Abandon Ship
+**
+** The ship is abandoned. If your current ship is the Faire
+** Queene, or if your shuttlecraft is dead, you're out of
+** luck. You need the shuttlecraft in order for the captain
+** (that's you!!) to escape.
+**
+** Your crew can beam to an inhabited starsystem in the
+** quadrant, if there is one and if the transporter is working.
+** If there is no inhabited starsystem, or if the transporter
+** is out, they are left to die in outer space.
+**
+** These currently just count as regular deaths, but they
+** should count very heavily against you.
+**
+** If there are no starbases left, you are captured by the
+** Klingons, who torture you mercilessly. However, if there
+** is at least one starbase, you are returned to the
+** Federation in a prisoner of war exchange. Of course, this
+** can't happen unless you have taken some prisoners.
+**
+** Uses trace flag 40
+*/
+
+abandon()
+{
+ register struct quad *q;
+ register int i;
+ int j;
+ register struct event *e;
+
+ if (Ship.ship == QUEENE)
+ return (printf("You may not abandon ye Faire Queene\n"));
+ if (Ship.cond != DOCKED)
+ {
+ if (damaged(SHUTTLE))
+ return (out(SHUTTLE));
+ printf("Officers escape in shuttlecraft\n");
+ /* decide on fate of crew */
+ q = &Quad[Ship.quadx][Ship.quady];
+ if (q->qsystemname == 0 || damaged(XPORTER))
+ {
+ printf("Entire crew of %d left to die in outer space\n",
+ Ship.crew);
+ Game.deaths += Ship.crew;
+ }
+ else
+ {
+ printf("Crew beams down to planet %s\n", systemname(q));
+ }
+ }
+ /* see if you can be exchanged */
+ if (Now.bases == 0 || Game.captives < 20 * Game.skill)
+ lose(L_CAPTURED);
+ /* re-outfit new ship */
+ printf("You are hereby put in charge of an antiquated but still\n");
+ printf(" functional ship, the Fairie Queene.\n");
+ Ship.ship = QUEENE;
+ Ship.shipname = "Fairie Queene";
+ Param.energy = Ship.energy = 3000;
+ Param.torped = Ship.torped = 6;
+ Param.shield = Ship.shield = 1250;
+ Ship.shldup = 0;
+ Ship.cloaked = 0;
+ Ship.warp = 5.0;
+ Ship.warp2 = 25.0;
+ Ship.warp3 = 125.0;
+ Ship.cond = GREEN;
+ /* clear out damages on old ship */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV)
+ continue;
+ unschedule(e);
+ }
+ /* get rid of some devices and redistribute probabilities */
+ i = Param.damprob[SHUTTLE] + Param.damprob[CLOAK];
+ Param.damprob[SHUTTLE] = Param.damprob[CLOAK] = 0;
+ while (i > 0)
+ for (j = 0; j < NDEV; j++)
+ {
+ if (Param.damprob[j] != 0)
+ {
+ Param.damprob[j] += 1;
+ i--;
+ if (i <= 0)
+ break;
+ }
+ }
+ /* pick a starbase to restart at */
+ i = ranf(Now.bases);
+ Ship.quadx = Now.base[i].x;
+ Ship.quady = Now.base[i].y;
+ /* setup that quadrant */
+ while (1)
+ {
+ initquad(1);
+ Sect[Ship.sectx][Ship.secty] = EMPTY;
+ for (i = 0; i < 5; i++)
+ {
+ Ship.sectx = Etc.starbase.x + ranf(3) - 1;
+ if (Ship.sectx < 0 || Ship.sectx >= NSECTS)
+ continue;
+ Ship.secty = Etc.starbase.y + ranf(3) - 1;
+ if (Ship.secty < 0 || Ship.secty >= NSECTS)
+ continue;
+ if (Sect[Ship.sectx][Ship.secty] == EMPTY)
+ {
+ Sect[Ship.sectx][Ship.secty] = QUEENE;
+ dock();
+ compkldist(0);
+ return;
+ }
+ }
+ }
+}
diff --git a/trek/attack.c b/trek/attack.c
new file mode 100644
index 00000000..61c23ed0
--- /dev/null
+++ b/trek/attack.c
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)attack.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Klingon Attack Routine
+**
+** This routine performs the Klingon attack provided that
+** (1) Something happened this move (i.e., not free), and
+** (2) You are not cloaked. Note that if you issue the
+** cloak command, you are not considered cloaked until you
+** expend some time.
+**
+** Klingons are permitted to move both before and after the
+** attack. They will tend to move toward you before the
+** attack and away from you after the attack.
+**
+** Under certain conditions you can get a critical hit. This
+** sort of hit damages devices. The probability that a given
+** device is damaged depends on the device. Well protected
+** devices (such as the computer, which is in the core of the
+** ship and has considerable redundancy) almost never get
+** damaged, whereas devices which are exposed (such as the
+** warp engines) or which are particularly delicate (such as
+** the transporter) have a much higher probability of being
+** damaged.
+**
+** The actual amount of damage (i.e., how long it takes to fix
+** it) depends on the amount of the hit and the "damfac[]"
+** entry for the particular device.
+**
+** Casualties can also occur.
+*/
+
+attack(resting)
+int resting; /* set if attack while resting */
+{
+ register int hit, i, l;
+ int maxhit, tothit, shldabsb;
+ double chgfac, propor, extradm;
+ double dustfac, tothe;
+ int cas;
+ int hitflag;
+
+ if (Move.free)
+ return;
+ if (Etc.nkling <= 0 || Quad[Ship.quadx][Ship.quady].stars < 0)
+ return;
+ if (Ship.cloaked && Ship.cloakgood)
+ return;
+ /* move before attack */
+ klmove(0);
+ if (Ship.cond == DOCKED)
+ {
+ if (!resting)
+ printf("Starbase shields protect the %s\n", Ship.shipname);
+ return;
+ }
+ /* setup shield effectiveness */
+ chgfac = 1.0;
+ if (Move.shldchg)
+ chgfac = 0.25 + 0.50 * franf();
+ maxhit = tothit = 0;
+ hitflag = 0;
+
+ /* let each Klingon do his damndest */
+ for (i = 0; i < Etc.nkling; i++)
+ {
+ /* if he's low on power he won't attack */
+ if (Etc.klingon[i].power < 20)
+ continue;
+ if (!hitflag)
+ {
+ printf("\nStardate %.2f: Klingon attack:\n",
+ Now.date);
+ hitflag++;
+ }
+ /* complete the hit */
+ dustfac = 0.90 + 0.01 * franf();
+ tothe = Etc.klingon[i].avgdist;
+ hit = Etc.klingon[i].power * pow(dustfac, tothe) * Param.hitfac;
+ /* deplete his energy */
+ dustfac = Etc.klingon[i].power;
+ Etc.klingon[i].power = dustfac * Param.phasfac * (1.0 + (franf() - 0.5) * 0.2);
+ /* see how much of hit shields will absorb */
+ shldabsb = 0;
+ if (Ship.shldup || Move.shldchg)
+ {
+ propor = Ship.shield;
+ propor /= Param.shield;
+ shldabsb = propor * chgfac * hit;
+ if (shldabsb > Ship.shield)
+ shldabsb = Ship.shield;
+ Ship.shield -= shldabsb;
+ }
+ /* actually do the hit */
+ printf("HIT: %d units", hit);
+ if (!damaged(SRSCAN))
+ printf(" from %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
+ cas = (shldabsb * 100) / hit;
+ hit -= shldabsb;
+ if (shldabsb > 0)
+ printf(", shields absorb %d%%, effective hit %d\n",
+ cas, hit);
+ else
+ printf("\n");
+ tothit += hit;
+ if (hit > maxhit)
+ maxhit = hit;
+ Ship.energy -= hit;
+ /* see if damages occurred */
+ if (hit >= (15 - Game.skill) * (25 - ranf(12)))
+ {
+ printf("CRITICAL HIT!!!\n");
+ /* select a device from probability vector */
+ cas = ranf(1000);
+ for (l = 0; cas >= 0; l++)
+ cas -= Param.damprob[l];
+ l -= 1;
+ /* compute amount of damage */
+ extradm = (hit * Param.damfac[l]) / (75 + ranf(25)) + 0.5;
+ /* damage the device */
+ damage(l, extradm);
+ if (damaged(SHIELD))
+ {
+ if (Ship.shldup)
+ printf("Sulu: Shields knocked down, captain.\n");
+ Ship.shldup = 0;
+ Move.shldchg = 0;
+ }
+ }
+ if (Ship.energy <= 0)
+ lose(L_DSTRYD);
+ }
+
+ /* see what our casualities are like */
+ if (maxhit >= 200 || tothit >= 500)
+ {
+ cas = tothit * 0.015 * franf();
+ if (cas >= 2)
+ {
+ printf("McCoy: we suffered %d casualties in that attack.\n",
+ cas);
+ Game.deaths += cas;
+ Ship.crew -= cas;
+ }
+ }
+
+ /* allow Klingons to move after attacking */
+ klmove(1);
+
+ return;
+}
diff --git a/trek/autover.c b/trek/autover.c
new file mode 100644
index 00000000..3a0f67e6
--- /dev/null
+++ b/trek/autover.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)autover.c 5.5 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Automatic Override
+**
+** If we should be so unlucky as to be caught in a quadrant
+** with a supernova in it, this routine is called. It is
+** called from checkcond().
+**
+** It sets you to a random warp (guaranteed to be over 6.0)
+** and starts sending you off "somewhere" (whereever that is).
+**
+** Please note that it is VERY important that you reset your
+** warp speed after the automatic override is called. The new
+** warp factor does not stay in effect for just this routine.
+**
+** This routine will never try to send you more than sqrt(2)
+** quadrants, since that is all that is needed.
+*/
+
+autover()
+{
+ double dist;
+ register int course;
+
+ printf("\07RED ALERT: The %s is in a supernova quadrant\n", Ship.shipname);
+ printf("*** Emergency override attempts to hurl %s to safety\n", Ship.shipname);
+ /* let's get our ass out of here */
+ Ship.warp = 6.0 + 2.0 * franf();
+ Ship.warp2 = Ship.warp * Ship.warp;
+ Ship.warp3 = Ship.warp2 * Ship.warp;
+ dist = 0.75 * Ship.energy / (Ship.warp3 * (Ship.shldup + 1));
+ if (dist > 1.4142)
+ dist = 1.4142;
+ course = ranf(360);
+ Etc.nkling = -1;
+ Ship.cond = RED;
+ warp(-1, course, dist);
+ attack(0);
+}
diff --git a/trek/board.x b/trek/board.x
new file mode 100644
index 00000000..0892a6da
--- /dev/null
+++ b/trek/board.x
@@ -0,0 +1,59 @@
+# include "trek.h"
+
+/*
+** BOARD A KLINGON
+**
+** A Klingon battle cruiser is boarded. If the boarding party
+** is successful, they take over the vessel, otherwise, you
+** have wasted a move. Needless to say, this move is not free.
+**
+** User parameters are the Klingon to be boarded and the size of
+** the boarding party.
+**
+** Three things are computed. The first is the probability that
+** the party takes over the Klingon. This is dependent on the
+** size of the party, the condition of the Klingon (for which
+** the energy left is used, which is definately incorrect), and
+** the number of losses that the boarding party sustains. If too
+** many of the boarding party are killed, the probability drops
+** to zero. The second quantity computed is the losses that the
+** boarding party sustains. This counts in your score. It
+** depends on the absolute and relative size of the boarding
+** party and the strength of the Klingon. The third quantity
+** computed is the number of Klingon captives you get to take.
+** It is actually computed as the number of losses they sustain
+** subtracted from the size of their crew. It depends on the
+** relative size of the party. All of these quantities are
+** randomized in some fashion.
+*/
+
+board()
+{
+ int prob;
+ int losses;
+ int captives;
+ float t;
+ int party;
+
+ if (checkout(XPORTER))
+ return;
+
+ k = selectklingon();
+ if (!k->srndreq)
+ {
+ return (printf("But captain! You must request surrender first\n"));
+ }
+
+ t = party / Param.crew;
+
+ prob = 1000 * t;
+ prob =- 500 * k->power / Param.klingpwr;
+
+ losses = party * k->power * t * 0.5 / Param.klingpwr * (franf() + 1.0);
+ if (losses * 4 > party)
+ prob = 0;
+
+ captives = %%% * (1.0 - t) * 0.5 * (franf() + 1.0);
+
+ if (prob > ranf(1000))
+ success!!!;
diff --git a/trek/capture.c b/trek/capture.c
new file mode 100644
index 00000000..77881b9b
--- /dev/null
+++ b/trek/capture.c
@@ -0,0 +1,128 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)capture.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Ask a Klingon To Surrender
+**
+** (Fat chance)
+**
+** The Subspace Radio is needed to ask a Klingon if he will kindly
+** surrender. A random Klingon from the ones in the quadrant is
+** chosen.
+**
+** The Klingon is requested to surrender. The probability of this
+** is a function of that Klingon's remaining power, our power,
+** etc.
+*/
+
+capture()
+{
+ register int i;
+ register struct kling *k;
+ double x;
+ extern struct kling *selectklingon();
+
+ /* check for not cloaked */
+ if (Ship.cloaked)
+ {
+ printf("Ship-ship communications out when cloaked\n");
+ return;
+ }
+ if (damaged(SSRADIO))
+ return (out(SSRADIO));
+ /* find out if there are any at all */
+ if (Etc.nkling <= 0)
+ {
+ printf("Uhura: Getting no response, sir\n");
+ return;
+ }
+
+ /* if there is more than one Klingon, find out which one */
+ k = selectklingon();
+ Move.free = 0;
+ Move.time = 0.05;
+
+ /* check out that Klingon */
+ k->srndreq++;
+ x = Param.klingpwr;
+ x *= Ship.energy;
+ x /= k->power * Etc.nkling;
+ x *= Param.srndrprob;
+ i = x;
+# ifdef xTRACE
+ if (Trace)
+ printf("Prob = %d (%.4f)\n", i, x);
+# endif
+ if (i > ranf(100))
+ {
+ /* guess what, he surrendered!!! */
+ printf("Klingon at %d,%d surrenders\n", k->x, k->y);
+ i = ranf(Param.klingcrew);
+ if ( i > 0 )
+ printf("%d klingons commit suicide rather than be taken captive\n", Param.klingcrew - i);
+ if (i > Ship.brigfree)
+ i = Ship.brigfree;
+ Ship.brigfree -= i;
+ printf("%d captives taken\n", i);
+ killk(k->x, k->y);
+ return;
+ }
+
+ /* big surprise, he refuses to surrender */
+ printf("Fat chance, captain\n");
+ return;
+}
+
+
+/*
+** SELECT A KLINGON
+**
+** Cruddy, just takes one at random. Should ask the captain.
+*/
+
+struct kling *selectklingon()
+{
+ register int i;
+
+ if (Etc.nkling < 2)
+ i = 0;
+ else
+ i = ranf(Etc.nkling);
+ return (&Etc.klingon[i]);
+}
diff --git a/trek/cgetc.c b/trek/cgetc.c
new file mode 100644
index 00000000..cde6250d
--- /dev/null
+++ b/trek/cgetc.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)cgetc.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include <stdio.h>
+
+char cgetc(i)
+int i;
+{
+ return ( getchar() );
+}
diff --git a/trek/check_out.c b/trek/check_out.c
new file mode 100644
index 00000000..ded9eaba
--- /dev/null
+++ b/trek/check_out.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)check_out.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** CHECK IF A DEVICE IS OUT
+**
+** The indicated device is checked to see if it is disabled. If
+** it is, an attempt is made to use the starbase device. If both
+** of these fails, it returns non-zero (device is REALLY out),
+** otherwise it returns zero (I can get to it somehow).
+**
+** It prints appropriate messages too.
+*/
+
+check_out(device)
+int device;
+{
+ register int dev;
+
+ dev = device;
+
+ /* check for device ok */
+ if (!damaged(dev))
+ return (0);
+
+ /* report it as being dead */
+ out(dev);
+
+ /* but if we are docked, we can go ahead anyhow */
+ if (Ship.cond != DOCKED)
+ return (1);
+ printf(" Using starbase %s\n", Device[dev].name);
+ return (0);
+}
diff --git a/trek/checkcond.c b/trek/checkcond.c
new file mode 100644
index 00000000..e490c9bf
--- /dev/null
+++ b/trek/checkcond.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)checkcond.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Check for Condition After a Move
+**
+** Various ship conditions are checked. First we check
+** to see if we have already lost the game, due to running
+** out of life support reserves, running out of energy,
+** or running out of crew members. The check for running
+** out of time is in events().
+**
+** If we are in automatic override mode (Etc.nkling < 0), we
+** don't want to do anything else, lest we call autover
+** recursively.
+**
+** In the normal case, if there is a supernova, we call
+** autover() to help us escape. If after calling autover()
+** we are still in the grips of a supernova, we get burnt
+** up.
+**
+** If there are no Klingons in this quadrant, we nullify any
+** distress calls which might exist.
+**
+** We then set the condition code, based on the energy level
+** and battle conditions.
+*/
+
+checkcond()
+{
+ register int i, j;
+
+ /* see if we are still alive and well */
+ if (Ship.reserves < 0.0)
+ lose(L_NOLIFE);
+ if (Ship.energy <= 0)
+ lose(L_NOENGY);
+ if (Ship.crew <= 0)
+ lose(L_NOCREW);
+ /* if in auto override mode, ignore the rest */
+ if (Etc.nkling < 0)
+ return;
+ /* call in automatic override if appropriate */
+ if (Quad[Ship.quadx][Ship.quady].stars < 0)
+ autover();
+ if (Quad[Ship.quadx][Ship.quady].stars < 0)
+ lose(L_SNOVA);
+ /* nullify distress call if appropriate */
+ if (Etc.nkling <= 0)
+ killd(Ship.quadx, Ship.quady, 1);
+
+ /* set condition code */
+ if (Ship.cond == DOCKED)
+ return;
+
+ if (Etc.nkling > 0)
+ {
+ Ship.cond = RED;
+ return;
+ }
+ if (Ship.energy < Param.energylow)
+ {
+ Ship.cond = YELLOW;
+ return;
+ }
+ Ship.cond = GREEN;
+ return;
+}
diff --git a/trek/compkl.c b/trek/compkl.c
new file mode 100644
index 00000000..ad1d61cf
--- /dev/null
+++ b/trek/compkl.c
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)compkl.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** compute klingon distances
+**
+** The klingon list has the distances for all klingons recomputed
+** and sorted. The parameter is a Boolean flag which is set if
+** we have just entered a new quadrant.
+**
+** This routine is used every time the Enterprise or the Klingons
+** move.
+*/
+
+compkldist(f)
+int f; /* set if new quadrant */
+{
+ register int i, dx, dy;
+ double d;
+ double temp;
+
+ if (Etc.nkling == 0)
+ return;
+ for (i = 0; i < Etc.nkling; i++)
+ {
+ /* compute distance to the Klingon */
+ dx = Ship.sectx - Etc.klingon[i].x;
+ dy = Ship.secty - Etc.klingon[i].y;
+ d = dx * dx + dy * dy;
+ d = sqrt(d);
+
+ /* compute average of new and old distances to Klingon */
+ if (!f)
+ {
+ temp = Etc.klingon[i].dist;
+ Etc.klingon[i].avgdist = 0.5 * (temp + d);
+ }
+ else
+ {
+ /* new quadrant: average is current */
+ Etc.klingon[i].avgdist = d;
+ }
+ Etc.klingon[i].dist = d;
+ }
+
+ /* leave them sorted */
+ sortkl();
+}
+
+
+/*
+** sort klingons
+**
+** bubble sort on ascending distance
+*/
+
+sortkl()
+{
+ struct kling t;
+ register int f, i, m;
+
+ m = Etc.nkling - 1;
+ f = 1;
+ while (f)
+ {
+ f = 0;
+ for (i = 0; i < m; i++)
+ if (Etc.klingon[i].dist > Etc.klingon[i+1].dist)
+ {
+ bmove(&Etc.klingon[i], &t, sizeof t);
+ bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof t);
+ bmove(&t, &Etc.klingon[i+1], sizeof t);
+ f = 1;
+ }
+ }
+}
diff --git a/trek/computer.c b/trek/computer.c
new file mode 100644
index 00000000..178d29b7
--- /dev/null
+++ b/trek/computer.c
@@ -0,0 +1,343 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)computer.c 4.8 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+# include <stdio.h>
+/*
+** On-Board Computer
+**
+** A computer request is fetched from the captain. The requests
+** are:
+**
+** chart -- print a star chart of the known galaxy. This includes
+** every quadrant that has ever had a long range or
+** a short range scan done of it, plus the location of
+** all starbases. This is of course updated by any sub-
+** space radio broadcasts (unless the radio is out).
+** The format is the same as that of a long range scan
+** except that ".1." indicates that a starbase exists
+** but we know nothing else.
+**
+** trajectory -- gives the course and distance to every know
+** Klingon in the quadrant. Obviously this fails if the
+** short range scanners are out.
+**
+** course -- gives a course computation from whereever you are
+** to any specified location. If the course begins
+** with a slash, the current quadrant is taken.
+** Otherwise the input is quadrant and sector coordi-
+** nates of the target sector.
+**
+** move -- identical to course, except that the move is performed.
+**
+** score -- prints out the current score.
+**
+** pheff -- "PHaser EFFectiveness" at a given distance. Tells
+** you how much stuff you need to make it work.
+**
+** warpcost -- Gives you the cost in time and units to move for
+** a given distance under a given warp speed.
+**
+** impcost -- Same for the impulse engines.
+**
+** distresslist -- Gives a list of the currently known starsystems
+** or starbases which are distressed, together with their
+** quadrant coordinates.
+**
+** If a command is terminated with a semicolon, you remain in
+** the computer; otherwise, you escape immediately to the main
+** command processor.
+*/
+
+struct cvntab Cputab[] =
+{
+ "ch", "art", (int (*)())1, 0,
+ "t", "rajectory", (int (*)())2, 0,
+ "c", "ourse", (int (*)())3, 0,
+ "m", "ove", (int (*)())3, 1,
+ "s", "core", (int (*)())4, 0,
+ "p", "heff", (int (*)())5, 0,
+ "w", "arpcost", (int (*)())6, 0,
+ "i", "mpcost", (int (*)())7, 0,
+ "d", "istresslist", (int (*)())8, 0,
+ 0
+};
+
+computer()
+{
+ int ix, iy;
+ register int i, j;
+ int numout;
+ int tqx, tqy;
+ struct cvntab *r;
+ int cost;
+ int course;
+ double dist, time;
+ double warpfact;
+ struct quad *q;
+ register struct event *e;
+
+ if (check_out(COMPUTER))
+ return;
+ while (1)
+ {
+ r = getcodpar("\nRequest", Cputab);
+ switch ((int)r->value)
+ {
+
+ case 1: /* star chart */
+ printf("Computer record of galaxy for all long range sensor scans\n\n");
+ printf(" ");
+ /* print top header */
+ for (i = 0; i < NQUADS; i++)
+ printf("-%d- ", i);
+ printf("\n");
+ for (i = 0; i < NQUADS; i++)
+ {
+ printf("%d ", i);
+ for (j = 0; j < NQUADS; j++)
+ {
+ if (i == Ship.quadx && j == Ship.quady)
+ {
+ printf("$$$ ");
+ continue;
+ }
+ q = &Quad[i][j];
+ /* 1000 or 1001 is special case */
+ if (q->scanned >= 1000)
+ if (q->scanned > 1000)
+ printf(".1. ");
+ else
+ printf("/// ");
+ else
+ if (q->scanned < 0)
+ printf("... ");
+ else
+ printf("%3d ", q->scanned);
+ }
+ printf("%d\n", i);
+ }
+ printf(" ");
+ /* print bottom footer */
+ for (i = 0; i < NQUADS; i++)
+ printf("-%d- ", i);
+ printf("\n");
+ break;
+
+ case 2: /* trajectory */
+ if (check_out(SRSCAN))
+ {
+ break;
+ }
+ if (Etc.nkling <= 0)
+ {
+ printf("No Klingons in this quadrant\n");
+ break;
+ }
+ /* for each Klingon, give the course & distance */
+ for (i = 0; i < Etc.nkling; i++)
+ {
+ printf("Klingon at %d,%d", Etc.klingon[i].x, Etc.klingon[i].y);
+ course = kalc(Ship.quadx, Ship.quady, Etc.klingon[i].x, Etc.klingon[i].y, &dist);
+ prkalc(course, dist);
+ }
+ break;
+
+ case 3: /* course calculation */
+ if (readdelim('/'))
+ {
+ tqx = Ship.quadx;
+ tqy = Ship.quady;
+ }
+ else
+ {
+ ix = getintpar("Quadrant");
+ if (ix < 0 || ix >= NSECTS)
+ break;
+ iy = getintpar("q-y");
+ if (iy < 0 || iy >= NSECTS)
+ break;
+ tqx = ix;
+ tqy = iy;
+ }
+ ix = getintpar("Sector");
+ if (ix < 0 || ix >= NSECTS)
+ break;
+ iy = getintpar("s-y");
+ if (iy < 0 || iy >= NSECTS)
+ break;
+ course = kalc(tqx, tqy, ix, iy, &dist);
+ if (r->value2)
+ {
+ warp(-1, course, dist);
+ break;
+ }
+ printf("%d,%d/%d,%d to %d,%d/%d,%d",
+ Ship.quadx, Ship.quady, Ship.sectx, Ship.secty, tqx, tqy, ix, iy);
+ prkalc(course, dist);
+ break;
+
+ case 4: /* score */
+ score();
+ break;
+
+ case 5: /* phaser effectiveness */
+ dist = getfltpar("range");
+ if (dist < 0.0)
+ break;
+ dist *= 10.0;
+ cost = pow(0.90, dist) * 98.0 + 0.5;
+ printf("Phasers are %d%% effective at that range\n", cost);
+ break;
+
+ case 6: /* warp cost (time/energy) */
+ dist = getfltpar("distance");
+ if (dist < 0.0)
+ break;
+ warpfact = getfltpar("warp factor");
+ if (warpfact <= 0.0)
+ warpfact = Ship.warp;
+ cost = (dist + 0.05) * warpfact * warpfact * warpfact;
+ time = Param.warptime * dist / (warpfact * warpfact);
+ printf("Warp %.2f distance %.2f cost %.2f stardates %d (%d w/ shlds up) units\n",
+ warpfact, dist, time, cost, cost + cost);
+ break;
+
+ case 7: /* impulse cost */
+ dist = getfltpar("distance");
+ if (dist < 0.0)
+ break;
+ cost = 20 + 100 * dist;
+ time = dist / 0.095;
+ printf("Distance %.2f cost %.2f stardates %d units\n",
+ dist, time, cost);
+ break;
+
+ case 8: /* distresslist */
+ j = 1;
+ printf("\n");
+ /* scan the event list */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ /* ignore hidden entries */
+ if (e->evcode & E_HIDDEN)
+ continue;
+ switch (e->evcode & E_EVENT)
+ {
+
+ case E_KDESB:
+ printf("Klingon is attacking starbase in quadrant %d,%d\n",
+ e->x, e->y);
+ j = 0;
+ break;
+
+ case E_ENSLV:
+ case E_REPRO:
+ printf("Starsystem %s in quadrant %d,%d is distressed\n",
+ Systemname[e->systemname], e->x, e->y);
+ j = 0;
+ break;
+ }
+ }
+ if (j)
+ printf("No known distress calls are active\n");
+ break;
+
+ }
+
+ /* skip to next semicolon or newline. Semicolon
+ * means get new computer request; newline means
+ * exit computer mode. */
+ while ((i = cgetc(0)) != ';')
+ {
+ if (i == '\0')
+ exit(1);
+ if (i == '\n')
+ {
+ ungetc(i, stdin);
+ return;
+ }
+ }
+ }
+}
+
+
+/*
+** Course Calculation
+**
+** Computes and outputs the course and distance from position
+** sqx,sqy/ssx,ssy to tqx,tqy/tsx,tsy.
+*/
+
+kalc(tqx, tqy, tsx, tsy, dist)
+int tqx;
+int tqy;
+int tsx;
+int tsy;
+double *dist;
+{
+ double dx, dy;
+ double quadsize;
+ double angle;
+ register int course;
+
+ /* normalize to quadrant distances */
+ quadsize = NSECTS;
+ dx = (Ship.quadx + Ship.sectx / quadsize) - (tqx + tsx / quadsize);
+ dy = (tqy + tsy / quadsize) - (Ship.quady + Ship.secty / quadsize);
+
+ /* get the angle */
+ angle = atan2(dy, dx);
+ /* make it 0 -> 2 pi */
+ if (angle < 0.0)
+ angle += 6.283185307;
+ /* convert from radians to degrees */
+ course = angle * 57.29577951 + 0.5;
+ dx = dx * dx + dy * dy;
+ *dist = sqrt(dx);
+ return (course);
+}
+
+
+prkalc(course, dist)
+int course;
+double dist;
+{
+ printf(": course %d dist %.3f\n", course, dist);
+}
diff --git a/trek/damage.c b/trek/damage.c
new file mode 100644
index 00000000..b467f732
--- /dev/null
+++ b/trek/damage.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)damage.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Schedule Ship.damages to a Device
+**
+** Device `dev1' is damaged in an amount `dam'. Dam is measured
+** in stardates, and is an additional amount of damage. It should
+** be the amount to occur in non-docked mode. The adjustment
+** to docked mode occurs automatically if we are docked.
+**
+** Note that the repair of the device occurs on a DATE, meaning
+** that the dock() and undock() have to reschedule the event.
+*/
+
+damage(dev1, dam)
+int dev1; /* device index */
+double dam; /* time to repair */
+{
+ register int i;
+ register struct event *e;
+ int f;
+ register int dev;
+
+ /* ignore zero damages */
+ if (dam <= 0.0)
+ return;
+ dev = dev1;
+
+ printf("\t%s damaged\n", Device[dev].name);
+
+ /* find actual length till it will be fixed */
+ if (Ship.cond == DOCKED)
+ dam *= Param.dockfac;
+ /* set the damage flag */
+ f = damaged(dev);
+ if (!f)
+ {
+ /* new damages -- schedule a fix */
+ schedule(E_FIXDV, dam, 0, 0, dev);
+ return;
+ }
+ /* device already damaged -- add to existing damages */
+ /* scan for old damages */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV || e->systemname != dev)
+ continue;
+ /* got the right one; add on the new damages */
+ reschedule(e, e->date - Now.date + dam);
+ return;
+ }
+ syserr("Cannot find old damages %d\n", dev);
+}
diff --git a/trek/damaged.c b/trek/damaged.c
new file mode 100644
index 00000000..cf3ec080
--- /dev/null
+++ b/trek/damaged.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)damaged.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/* DAMAGED -- check for device damaged
+**
+** This is a boolean function which returns non-zero if the
+** specified device is broken. It does this by checking the
+** event list for a "device fix" action on that device.
+*/
+
+damaged(dev)
+int dev;
+{
+ register int d;
+ register struct event *e;
+ register int i;
+
+ d = dev;
+
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV)
+ continue;
+ if (e->systemname == d)
+ return (1);
+ }
+
+ /* device fix not in event list -- device must not be broken */
+ return (0);
+}
diff --git a/trek/dcrept.c b/trek/dcrept.c
new file mode 100644
index 00000000..3a59fe62
--- /dev/null
+++ b/trek/dcrept.c
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dcrept.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** damage control report
+**
+** Print damages and time to fix. This is taken from the event
+** list. A couple of factors are set up, based on whether or not
+** we are docked. (One of these factors will always be 1.0.)
+** The event list is then scanned for damage fix events, the
+** time until they occur is determined, and printed out. The
+** magic number DAMFAC is used to tell how much faster you can
+** fix things if you are docked.
+*/
+
+dcrept()
+{
+ register int i, f;
+ double x;
+ double m1, m2;
+ register struct event *e;
+
+ /* set up the magic factors to output the time till fixed */
+ if (Ship.cond == DOCKED)
+ {
+ m1 = 1.0 / Param.dockfac;
+ m2 = 1.0;
+ }
+ else
+ {
+ m1 = 1.0;
+ m2 = Param.dockfac;
+ }
+ printf("Damage control report:\n");
+ f = 1;
+
+ /* scan for damages */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV)
+ continue;
+
+ /* output the title first time */
+ if (f)
+ {
+ printf("\t\t\t repair times\n");
+ printf("device\t\t\tin flight docked\n");
+ f = 0;
+ }
+
+ /* compute time till fixed, then adjust by the magic factors */
+ x = e->date - Now.date;
+ printf("%-24s%7.2f %7.2f\n",
+ Device[e->systemname].name, x * m1 + 0.005, x * m2 + 0.005);
+
+ /* do a little consistancy checking */
+ }
+
+ /* if everything was ok, reassure the nervous captain */
+ if (f)
+ printf("All devices functional\n");
+}
diff --git a/trek/destruct.c b/trek/destruct.c
new file mode 100644
index 00000000..906f1400
--- /dev/null
+++ b/trek/destruct.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)destruct.c 5.5 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Self Destruct Sequence
+**
+** The computer starts up the self destruct sequence. Obviously,
+** if the computer is out nothing can happen. You get a countdown
+** and a request for password. This must match the password that
+** you entered at the start of the game.
+**
+** You get to destroy things when you blow up; hence, it is
+** possible to win the game by destructing if you take the last
+** Klingon with you.
+**
+** By the way, the \032 in the message is a ^Z, which is because
+** the terminal in my office is an ADM-3, which uses that char-
+** acter to clear the screen. I also stick in a \014 (form feed)
+** because that clears some other screens.
+**
+** Uses trace flag 41
+*/
+
+destruct()
+{
+ char checkpass[15];
+ register int i, j;
+ double zap;
+
+ if (damaged(COMPUTER))
+ return (out(COMPUTER));
+ printf("\n\07 --- WORKING ---\07\n");
+ sleep(3);
+ /* output the count 10 9 8 7 6 */
+ for (i = 10; i > 5; i--)
+ {
+ for (j = 10; j > i; j--)
+ printf(" ");
+ printf("%d\n", i);
+ sleep(1);
+ }
+ /* check for password on new line only */
+ skiptonl(0);
+ getstrpar("Enter password verification", checkpass, 14, 0);
+ sleep(2);
+ if (!sequal(checkpass, Game.passwd))
+ return (printf("Self destruct sequence aborted\n"));
+ printf("Password verified; self destruct sequence continues:\n");
+ sleep(2);
+ /* output count 5 4 3 2 1 0 */
+ for (i = 5; i >= 0; i--)
+ {
+ sleep(1);
+ for (j = 5; j > i; j--)
+ printf(" ");
+ printf("%d\n", i);
+ }
+ sleep(2);
+ printf("\032\014***** %s destroyed *****\n", Ship.shipname);
+ Game.killed = 1;
+ /* let's see what we can blow up!!!! */
+ zap = 20.0 * Ship.energy;
+ Game.deaths += Ship.crew;
+ for (i = 0; i < Etc.nkling; )
+ {
+ if (Etc.klingon[i].power * Etc.klingon[i].dist <= zap)
+ killk(Etc.klingon[i].x, Etc.klingon[i].y);
+ else
+ i++;
+ }
+ /* if we didn't kill the last Klingon (detected by killk), */
+ /* then we lose.... */
+ lose(L_DSTRCT);
+}
diff --git a/trek/dock.c b/trek/dock.c
new file mode 100644
index 00000000..d83ada39
--- /dev/null
+++ b/trek/dock.c
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dock.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** DOCK TO STARBASE
+**
+** The starship is docked to a starbase. For this to work you
+** must be adjacent to a starbase.
+**
+** You get your supplies replenished and your captives are
+** disembarked. Note that your score is updated now, not when
+** you actually take the captives.
+**
+** Any repairs that need to be done are rescheduled to take
+** place sooner. This provides for the faster repairs when you
+** are docked.
+*/
+
+dock()
+{
+ register int i, j;
+ int ok;
+ register struct event *e;
+
+ if (Ship.cond == DOCKED)
+ return (printf("Chekov: But captain, we are already docked\n"));
+ /* check for ok to dock, i.e., adjacent to a starbase */
+ ok = 0;
+ for (i = Ship.sectx - 1; i <= Ship.sectx + 1 && !ok; i++)
+ {
+ if (i < 0 || i >= NSECTS)
+ continue;
+ for (j = Ship.secty - 1; j <= Ship.secty + 1; j++)
+ {
+ if (j < 0 || j >= NSECTS)
+ continue;
+ if (Sect[i][j] == BASE)
+ {
+ ok++;
+ break;
+ }
+ }
+ }
+ if (!ok)
+ return (printf("Chekov: But captain, we are not adjacent to a starbase.\n"));
+
+ /* restore resources */
+ Ship.energy = Param.energy;
+ Ship.torped = Param.torped;
+ Ship.shield = Param.shield;
+ Ship.crew = Param.crew;
+ Game.captives += Param.brigfree - Ship.brigfree;
+ Ship.brigfree = Param.brigfree;
+
+ /* reset ship's defenses */
+ Ship.shldup = 0;
+ Ship.cloaked = 0;
+ Ship.cond = DOCKED;
+ Ship.reserves = Param.reserves;
+
+ /* recalibrate space inertial navigation system */
+ Ship.sinsbad = 0;
+
+ /* output any saved radio messages */
+ dumpssradio();
+
+ /* reschedule any device repairs */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV)
+ continue;
+ reschedule(e, (e->date - Now.date) * Param.dockfac);
+ }
+ return;
+}
+
+
+/*
+** LEAVE A STARBASE
+**
+** This is the inverse of dock(). The main function it performs
+** is to reschedule any damages so that they will take longer.
+*/
+
+undock()
+{
+ register struct event *e;
+ register int i;
+
+ if (Ship.cond != DOCKED)
+ {
+ printf("Sulu: Pardon me captain, but we are not docked.\n");
+ return;
+ }
+ Ship.cond = GREEN;
+ Move.free = 0;
+
+ /* reschedule device repair times (again) */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV)
+ continue;
+ reschedule(e, (e->date - Now.date) / Param.dockfac);
+ }
+ return;
+}
diff --git a/trek/dumpgame.c b/trek/dumpgame.c
new file mode 100644
index 00000000..51842072
--- /dev/null
+++ b/trek/dumpgame.c
@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dumpgame.c 4.6 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/
+# define VERSION 2
+
+struct dump
+{
+ char *area;
+ int count;
+};
+
+
+struct dump Dump_template[] =
+{
+ (char *)&Ship, sizeof (Ship),
+ (char *)&Now, sizeof (Now),
+ (char *)&Param, sizeof (Param),
+ (char *)&Etc, sizeof (Etc),
+ (char *)&Game, sizeof (Game),
+ (char *)Sect, sizeof (Sect),
+ (char *)Quad, sizeof (Quad),
+ (char *)&Move, sizeof (Move),
+ (char *)Event, sizeof (Event),
+ 0
+};
+
+/*
+** DUMP GAME
+**
+** This routine dumps the game onto the file "trek.dump". The
+** first two bytes of the file are a version number, which
+** reflects whether this image may be used. Obviously, it must
+** change as the size, content, or order of the data structures
+** output change.
+*/
+
+dumpgame()
+{
+ int version;
+ register int fd;
+ register struct dump *d;
+ register int i;
+
+ if ((fd = creat("trek.dump", 0644)) < 0)
+ return (printf("cannot dump\n"));
+ version = VERSION;
+ write(fd, &version, sizeof version);
+
+ /* output the main data areas */
+ for (d = Dump_template; d->area; d++)
+ {
+ write(fd, &d->area, sizeof d->area);
+ i = d->count;
+ write(fd, d->area, i);
+ }
+
+ close(fd);
+}
+
+
+/*
+** RESTORE GAME
+**
+** The game is restored from the file "trek.dump". In order for
+** this to succeed, the file must exist and be readable, must
+** have the correct version number, and must have all the appro-
+** priate data areas.
+**
+** Return value is zero for success, one for failure.
+*/
+
+restartgame()
+{
+ register int fd;
+ int version;
+
+ if ((fd = open("trek.dump", 0)) < 0 ||
+ read(fd, &version, sizeof version) != sizeof version ||
+ version != VERSION ||
+ readdump(fd))
+ {
+ printf("cannot restart\n");
+ close(fd);
+ return (1);
+ }
+
+ close(fd);
+ return (0);
+}
+
+
+/*
+** READ DUMP
+**
+** This is the business end of restartgame(). It reads in the
+** areas.
+**
+** Returns zero for success, one for failure.
+*/
+
+readdump(fd1)
+int fd1;
+{
+ register int fd;
+ register struct dump *d;
+ register int i;
+ int junk;
+
+ fd = fd1;
+
+ for (d = Dump_template; d->area; d++)
+ {
+ if (read(fd, &junk, sizeof junk) != (sizeof junk))
+ return (1);
+ if ((char *)junk != d->area)
+ return (1);
+ i = d->count;
+ if (read(fd, d->area, i) != i)
+ return (1);
+ }
+
+ /* make quite certain we are at EOF */
+ return (read(fd, &junk, 1));
+}
diff --git a/trek/dumpme.c b/trek/dumpme.c
new file mode 100644
index 00000000..ccb9039c
--- /dev/null
+++ b/trek/dumpme.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dumpme.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Dump the starship somewhere in the galaxy
+**
+** Parameter is zero if bounce off of negative energy barrier,
+** one if through a black hole
+**
+** Note that the quadrant is NOT initialized here. This must
+** be done from the calling routine.
+**
+** Repair of devices must be deferred.
+*/
+
+dumpme(flag)
+int flag;
+{
+ register int f;
+ double x;
+ register struct event *e;
+ register int i;
+
+ f = flag;
+ Ship.quadx = ranf(NQUADS);
+ Ship.quady = ranf(NQUADS);
+ Ship.sectx = ranf(NSECTS);
+ Ship.secty = ranf(NSECTS);
+ x += 1.5 * franf();
+ Move.time += x;
+ if (f)
+ {
+ printf("%s falls into a black hole.\n", Ship.shipname);
+ }
+ else
+ {
+ printf("Computer applies full reverse power to avoid hitting the\n");
+ printf(" negative energy barrier. A space warp was entered.\n");
+ }
+ /* bump repair dates forward */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode != E_FIXDV)
+ continue;
+ reschedule(e, (e->date - Now.date) + x);
+ }
+ events(1);
+ printf("You are now in quadrant %d,%d. It is stardate %.2f\n",
+ Ship.quadx, Ship.quady, Now.date);
+ Move.time = 0;
+}
diff --git a/trek/dumpssradio.c b/trek/dumpssradio.c
new file mode 100644
index 00000000..038dfd7f
--- /dev/null
+++ b/trek/dumpssradio.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)dumpssradio.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/**
+ ** output hidden distress calls
+ **/
+
+dumpssradio()
+{
+ register struct event *e;
+ register int j;
+ register int chkrest;
+
+ chkrest = 0;
+ for (j = 0; j < MAXEVENTS; j++)
+ {
+ e = &Event[j];
+ /* if it is not hidden, then just ignore it */
+ if ((e->evcode & E_HIDDEN) == 0)
+ continue;
+ if (e->evcode & E_GHOST)
+ {
+ unschedule(e);
+ printf("Starsystem %s in quadrant %d,%d is no longer distressed\n",
+ systemname(e), e->x, e->y);
+ continue;
+ }
+
+ switch (e->evcode)
+ {
+
+ case E_KDESB:
+ printf("Starbase in quadrant %d,%d is under attack\n",
+ e->x, e->y);
+ chkrest++;
+ break;
+
+ case E_ENSLV:
+ case E_REPRO:
+ printf("Starsystem %s in quadrant %d,%d is distressed\n",
+ systemname(e), e->x, e->y);
+ chkrest++;
+ break;
+
+ }
+ }
+
+ return (chkrest);
+}
diff --git a/trek/events.c b/trek/events.c
new file mode 100644
index 00000000..4ed6d982
--- /dev/null
+++ b/trek/events.c
@@ -0,0 +1,463 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)events.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** CAUSE TIME TO ELAPSE
+**
+** This routine does a hell of a lot. It elapses time, eats up
+** energy, regenerates energy, processes any events that occur,
+** and so on.
+*/
+
+
+events(warp)
+int warp; /* set if called in a time warp */
+{
+ register int i;
+ int j;
+ struct kling *k;
+ double rtime;
+ double xdate;
+ double idate;
+ struct event *ev, *xsched(), *schedule();
+ int ix, iy;
+ register struct quad *q;
+ register struct event *e;
+ int evnum;
+ int restcancel;
+
+ /* if nothing happened, just allow for any Klingons killed */
+ if (Move.time <= 0.0)
+ {
+ Now.time = Now.resource / Now.klings;
+ return (0);
+ }
+
+ /* indicate that the cloaking device is now working */
+ Ship.cloakgood = 1;
+
+ /* idate is the initial date */
+ idate = Now.date;
+
+ /* schedule attacks if resting too long */
+ if (Move.time > 0.5 && Move.resting)
+ schedule(E_ATTACK, 0.5, 0, 0, 0);
+
+ /* scan the event list */
+ while (1)
+ {
+ restcancel = 0;
+ evnum = -1;
+ /* xdate is the date of the current event */
+ xdate = idate + Move.time;
+
+ /* find the first event that has happened */
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode == 0 || (e->evcode & E_GHOST))
+ continue;
+ if (e->date < xdate)
+ {
+ xdate = e->date;
+ ev = e;
+ evnum = i;
+ }
+ }
+ e = ev;
+
+ /* find the time between events */
+ rtime = xdate - Now.date;
+
+ /* decrement the magic "Federation Resources" pseudo-variable */
+ Now.resource -= Now.klings * rtime;
+ /* and recompute the time left */
+ Now.time = Now.resource / Now.klings;
+
+ /* move us up to the next date */
+ Now.date = xdate;
+
+ /* check for out of time */
+ if (Now.time <= 0.0)
+ lose(L_NOTIME);
+# ifdef xTRACE
+ if (evnum >= 0 && Trace)
+ printf("xdate = %.2f, evcode %d params %d %d %d\n",
+ xdate, e->evcode, e->x, e->y, e->systemname);
+# endif
+
+ /* if evnum < 0, no events occurred */
+ if (evnum < 0)
+ break;
+
+ /* otherwise one did. Find out what it is */
+ switch (e->evcode & E_EVENT)
+ {
+
+ case E_SNOVA: /* supernova */
+ /* cause the supernova to happen */
+ snova(-1);
+ /* and schedule the next one */
+ xresched(e, E_SNOVA, 1);
+ break;
+
+ case E_LRTB: /* long range tractor beam */
+ /* schedule the next one */
+ xresched(e, E_LRTB, Now.klings);
+ /* LRTB cannot occur if we are docked */
+ if (Ship.cond != DOCKED)
+ {
+ /* pick a new quadrant */
+ i = ranf(Now.klings) + 1;
+ for (ix = 0; ix < NQUADS; ix++)
+ {
+ for (iy = 0; iy < NQUADS; iy++)
+ {
+ q = &Quad[ix][iy];
+ if (q->stars >= 0)
+ if ((i -= q->klings) <= 0)
+ break;
+ }
+ if (i <= 0)
+ break;
+ }
+
+ /* test for LRTB to same quadrant */
+ if (Ship.quadx == ix && Ship.quady == iy)
+ break;
+
+ /* nope, dump him in the new quadrant */
+ Ship.quadx = ix;
+ Ship.quady = iy;
+ printf("\n%s caught in long range tractor beam\n", Ship.shipname);
+ printf("*** Pulled to quadrant %d,%d\n", Ship.quadx, Ship.quady);
+ Ship.sectx = ranf(NSECTS);
+ Ship.secty = ranf(NSECTS);
+ initquad(0);
+ /* truncate the move time */
+ Move.time = xdate - idate;
+ }
+ break;
+
+ case E_KATSB: /* Klingon attacks starbase */
+ /* if out of bases, forget it */
+ if (Now.bases <= 0)
+ {
+ unschedule(e);
+ break;
+ }
+
+ /* check for starbase and Klingons in same quadrant */
+ for (i = 0; i < Now.bases; i++)
+ {
+ ix = Now.base[i].x;
+ iy = Now.base[i].y;
+ /* see if a Klingon exists in this quadrant */
+ q = &Quad[ix][iy];
+ if (q->klings <= 0)
+ continue;
+
+ /* see if already distressed */
+ for (j = 0; j < MAXEVENTS; j++)
+ {
+ e = &Event[j];
+ if ((e->evcode & E_EVENT) != E_KDESB)
+ continue;
+ if (e->x == ix && e->y == iy)
+ break;
+ }
+ if (j < MAXEVENTS)
+ continue;
+
+ /* got a potential attack */
+ break;
+ }
+ e = ev;
+ if (i >= Now.bases)
+ {
+ /* not now; wait a while and see if some Klingons move in */
+ reschedule(e, 0.5 + 3.0 * franf());
+ break;
+ }
+ /* schedule a new attack, and a destruction of the base */
+ xresched(e, E_KATSB, 1);
+ e = xsched(E_KDESB, 1, ix, iy, 0);
+
+ /* report it if we can */
+ if (!damaged(SSRADIO))
+ {
+ printf("\nUhura: Captain, we have recieved a distress signal\n");
+ printf(" from the starbase in quadrant %d,%d.\n",
+ ix, iy);
+ restcancel++;
+ }
+ else
+ /* SSRADIO out, make it so we can't see the distress call */
+ /* but it's still there!!! */
+ e->evcode |= E_HIDDEN;
+ break;
+
+ case E_KDESB: /* Klingon destroys starbase */
+ unschedule(e);
+ q = &Quad[e->x][e->y];
+ /* if the base has mysteriously gone away, or if the Klingon
+ got tired and went home, ignore this event */
+ if (q->bases <=0 || q->klings <= 0)
+ break;
+ /* are we in the same quadrant? */
+ if (e->x == Ship.quadx && e->y == Ship.quady)
+ {
+ /* yep, kill one in this quadrant */
+ printf("\nSpock: ");
+ killb(Ship.quadx, Ship.quady);
+ }
+ else
+ /* kill one in some other quadrant */
+ killb(e->x, e->y);
+ break;
+
+ case E_ISSUE: /* issue a distress call */
+ xresched(e, E_ISSUE, 1);
+ /* if we already have too many, throw this one away */
+ if (Ship.distressed >= MAXDISTR)
+ break;
+ /* try a whole bunch of times to find something suitable */
+ for (i = 0; i < 100; i++)
+ {
+ ix = ranf(NQUADS);
+ iy = ranf(NQUADS);
+ q = &Quad[ix][iy];
+ /* need a quadrant which is not the current one,
+ which has some stars which are inhabited and
+ not already under attack, which is not
+ supernova'ed, and which has some Klingons in it */
+ if (!((ix == Ship.quadx && iy == Ship.quady) || q->stars < 0 ||
+ (q->qsystemname & Q_DISTRESSED) ||
+ (q->qsystemname & Q_SYSTEM) == 0 || q->klings <= 0))
+ break;
+ }
+ if (i >= 100)
+ /* can't seem to find one; ignore this call */
+ break;
+
+ /* got one!! Schedule its enslavement */
+ Ship.distressed++;
+ e = xsched(E_ENSLV, 1, ix, iy, q->qsystemname);
+ q->qsystemname = (e - Event) | Q_DISTRESSED;
+
+ /* tell the captain about it if we can */
+ if (!damaged(SSRADIO))
+ {
+ printf("\nUhura: Captain, starsystem %s in quadrant %d,%d is under attack\n",
+ Systemname[e->systemname], ix, iy);
+ restcancel++;
+ }
+ else
+ /* if we can't tell him, make it invisible */
+ e->evcode |= E_HIDDEN;
+ break;
+
+ case E_ENSLV: /* starsystem is enslaved */
+ unschedule(e);
+ /* see if current distress call still active */
+ q = &Quad[e->x][e->y];
+ if (q->klings <= 0)
+ {
+ /* no Klingons, clean up */
+ /* restore the system name */
+ q->qsystemname = e->systemname;
+ break;
+ }
+
+ /* play stork and schedule the first baby */
+ e = schedule(E_REPRO, Param.eventdly[E_REPRO] * franf(), e->x, e->y, e->systemname);
+
+ /* report the disaster if we can */
+ if (!damaged(SSRADIO))
+ {
+ printf("\nUhura: We've lost contact with starsystem %s\n",
+ Systemname[e->systemname]);
+ printf(" in quadrant %d,%d.\n",
+ e->x, e->y);
+ }
+ else
+ e->evcode |= E_HIDDEN;
+ break;
+
+ case E_REPRO: /* Klingon reproduces */
+ /* see if distress call is still active */
+ q = &Quad[e->x][e->y];
+ if (q->klings <= 0)
+ {
+ unschedule(e);
+ q->qsystemname = e->systemname;
+ break;
+ }
+ xresched(e, E_REPRO, 1);
+ /* reproduce one Klingon */
+ ix = e->x;
+ iy = e->y;
+ if (Now.klings == 127)
+ break; /* full right now */
+ if (q->klings >= MAXKLQUAD)
+ {
+ /* this quadrant not ok, pick an adjacent one */
+ for (i = ix - 1; i <= ix + 1; i++)
+ {
+ if (i < 0 || i >= NQUADS)
+ continue;
+ for (j = iy - 1; j <= iy + 1; j++)
+ {
+ if (j < 0 || j >= NQUADS)
+ continue;
+ q = &Quad[i][j];
+ /* check for this quad ok (not full & no snova) */
+ if (q->klings >= MAXKLQUAD || q->stars < 0)
+ continue;
+ break;
+ }
+ if (j <= iy + 1)
+ break;
+ }
+ if (j > iy + 1)
+ /* cannot create another yet */
+ break;
+ ix = i;
+ iy = j;
+ }
+ /* deliver the child */
+ q->klings++;
+ Now.klings++;
+ if (ix == Ship.quadx && iy == Ship.quady)
+ {
+ /* we must position Klingon */
+ sector(&ix, &iy);
+ Sect[ix][iy] = KLINGON;
+ k = &Etc.klingon[Etc.nkling++];
+ k->x = ix;
+ k->y = iy;
+ k->power = Param.klingpwr;
+ k->srndreq = 0;
+ compkldist(Etc.klingon[0].dist == Etc.klingon[0].avgdist ? 0 : 1);
+ }
+
+ /* recompute time left */
+ Now.time = Now.resource / Now.klings;
+ break;
+
+ case E_SNAP: /* take a snapshot of the galaxy */
+ xresched(e, E_SNAP, 1);
+ i = (int) Etc.snapshot;
+ i = bmove(Quad, i, sizeof (Quad));
+ i = bmove(Event, i, sizeof (Event));
+ i = bmove(&Now, i, sizeof (Now));
+ Game.snap = 1;
+ break;
+
+ case E_ATTACK: /* Klingons attack during rest period */
+ if (!Move.resting)
+ {
+ unschedule(e);
+ break;
+ }
+ attack(1);
+ reschedule(e, 0.5);
+ break;
+
+ case E_FIXDV:
+ i = e->systemname;
+ unschedule(e);
+
+ /* de-damage the device */
+ printf("%s reports repair work on the %s finished.\n",
+ Device[i].person, Device[i].name);
+
+ /* handle special processing upon fix */
+ switch (i)
+ {
+
+ case LIFESUP:
+ Ship.reserves = Param.reserves;
+ break;
+
+ case SINS:
+ if (Ship.cond == DOCKED)
+ break;
+ printf("Spock has tried to recalibrate your Space Internal Navigation System,\n");
+ printf(" but he has no standard base to calibrate to. Suggest you get\n");
+ printf(" to a starbase immediately so that you can properly recalibrate.\n");
+ Ship.sinsbad = 1;
+ break;
+
+ case SSRADIO:
+ restcancel = dumpssradio();
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (restcancel && Move.resting && getynpar("Spock: Shall we cancel our rest period"))
+ Move.time = xdate - idate;
+
+ }
+
+ /* unschedule an attack during a rest period */
+ if (e = Now.eventptr[E_ATTACK])
+ unschedule(e);
+
+ if (!warp)
+ {
+ /* eat up energy if cloaked */
+ if (Ship.cloaked)
+ Ship.energy -= Param.cloakenergy * Move.time;
+
+ /* regenerate resources */
+ rtime = 1.0 - exp(-Param.regenfac * Move.time);
+ Ship.shield += (Param.shield - Ship.shield) * rtime;
+ Ship.energy += (Param.energy - Ship.energy) * rtime;
+
+ /* decrement life support reserves */
+ if (damaged(LIFESUP) && Ship.cond != DOCKED)
+ Ship.reserves -= Move.time;
+ }
+ return (0);
+}
diff --git a/trek/externs.c b/trek/externs.c
new file mode 100644
index 00000000..5df1d264
--- /dev/null
+++ b/trek/externs.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)externs.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** global variable definitions
+*/
+
+struct device Device[NDEV] =
+{
+ "warp drive", "Scotty",
+ "S.R. scanners", "Scotty",
+ "L.R. scanners", "Scotty",
+ "phasers", "Sulu",
+ "photon tubes", "Sulu",
+ "impulse engines", "Scotty",
+ "shield control", "Sulu",
+ "computer", "Spock",
+ "subspace radio", "Uhura",
+ "life support", "Scotty",
+ "navigation system", "Chekov",
+ "cloaking device", "Scotty",
+ "transporter", "Scotty",
+ "shuttlecraft", "Scotty",
+ "*ERR 14*", "Nobody",
+ "*ERR 15*", "Nobody"
+};
+
+char *Systemname[NINHAB] =
+{
+ "ERROR",
+ "Talos IV",
+ "Rigel III",
+ "Deneb VII",
+ "Canopus V",
+ "Icarus I",
+ "Prometheus II",
+ "Omega VII",
+ "Elysium I",
+ "Scalos IV",
+ "Procyon IV",
+ "Arachnid I",
+ "Argo VIII",
+ "Triad III",
+ "Echo IV",
+ "Nimrod III",
+ "Nemisis IV",
+ "Centarurus I",
+ "Kronos III",
+ "Spectros V",
+ "Beta III",
+ "Gamma Tranguli VI",
+ "Pyris III",
+ "Triachus",
+ "Marcus XII",
+ "Kaland",
+ "Ardana",
+ "Stratos",
+ "Eden",
+ "Arrikis",
+ "Epsilon Eridani IV",
+ "Exo III"
+};
diff --git a/trek/getcodi.c b/trek/getcodi.c
new file mode 100644
index 00000000..c10031c3
--- /dev/null
+++ b/trek/getcodi.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)getcodi.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "getpar.h"
+
+/*
+** get course and distance
+**
+** The user is asked for a course and distance. This is used by
+** move, impulse, and some of the computer functions.
+**
+** The return value is zero for success, one for an invalid input
+** (meaning to drop the request).
+*/
+
+getcodi(co, di)
+int *co;
+double *di;
+{
+
+ *co = getintpar("Course");
+
+ /* course must be in the interval [0, 360] */
+ if (*co < 0 || *co > 360)
+ return (1);
+ *di = getfltpar("Distance");
+
+ /* distance must be in the interval [0, 15] */
+ if (*di <= 0.0 || *di > 15.0)
+ return (1);
+
+ /* good return */
+ return (0);
+}
diff --git a/trek/getpar.c b/trek/getpar.c
new file mode 100644
index 00000000..70142013
--- /dev/null
+++ b/trek/getpar.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)getpar.c 4.8 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include <stdio.h>
+# include "getpar.h"
+
+/**
+ ** get integer parameter
+ **/
+
+getintpar(s)
+char *s;
+{
+ register int i;
+ int n;
+
+ while (1)
+ {
+ if (testnl() && s)
+ printf("%s: ", s);
+ i = scanf("%d", &n);
+ if (i < 0)
+ exit(1);
+ if (i > 0 && testterm())
+ return (n);
+ printf("invalid input; please enter an integer\n");
+ skiptonl(0);
+ }
+}
+
+/**
+ ** get floating parameter
+ **/
+
+double getfltpar(s)
+char *s;
+{
+ register int i;
+ double d;
+
+ while (1)
+ {
+ if (testnl() && s)
+ printf("%s: ", s);
+ i = scanf("%lf", &d);
+ if (i < 0)
+ exit(1);
+ if (i > 0 && testterm())
+ return (d);
+ printf("invalid input; please enter a double\n");
+ skiptonl(0);
+ }
+}
+
+/**
+ ** get yes/no parameter
+ **/
+
+struct cvntab Yntab[] =
+{
+ "y", "es", (int (*)())1, 0,
+ "n", "o", (int (*)())0, 0,
+ 0
+};
+
+getynpar(s)
+char *s;
+{
+ struct cvntab *r;
+
+ r = getcodpar(s, Yntab);
+ return ((int) r->value);
+}
+
+
+/**
+ ** get coded parameter
+ **/
+
+struct cvntab *getcodpar(s, tab)
+char *s;
+struct cvntab tab[];
+{
+ char input[100];
+ register struct cvntab *r;
+ int flag;
+ register char *p, *q;
+ int c;
+ int f;
+
+ flag = 0;
+ while (1)
+ {
+ flag |= (f = testnl());
+ if (flag)
+ printf("%s: ", s);
+ if (f)
+ cgetc(0); /* throw out the newline */
+ scanf("%*[ \t;]");
+ if ((c = scanf("%[^ \t;\n]", input)) < 0)
+ exit(1);
+ if (c == 0)
+ continue;
+ flag = 1;
+
+ /* if command list, print four per line */
+ if (input[0] == '?' && input[1] == 0)
+ {
+ c = 4;
+ for (r = tab; r->abrev; r++)
+ {
+ concat(r->abrev, r->full, input);
+ printf("%14.14s", input);
+ if (--c > 0)
+ continue;
+ c = 4;
+ printf("\n");
+ }
+ if (c != 4)
+ printf("\n");
+ continue;
+ }
+
+ /* search for in table */
+ for (r = tab; r->abrev; r++)
+ {
+ p = input;
+ for (q = r->abrev; *q; q++)
+ if (*p++ != *q)
+ break;
+ if (!*q)
+ {
+ for (q = r->full; *p && *q; q++, p++)
+ if (*p != *q)
+ break;
+ if (!*p || !*q)
+ break;
+ }
+ }
+
+ /* check for not found */
+ if (!r->abrev)
+ {
+ printf("invalid input; ? for valid inputs\n");
+ skiptonl(0);
+ }
+ else
+ return (r);
+ }
+}
+
+
+/**
+ ** get string parameter
+ **/
+
+getstrpar(s, r, l, t)
+char *s;
+char *r;
+int l;
+char *t;
+{
+ register int i;
+ char format[20];
+ register int f;
+
+ if (t == 0)
+ t = " \t\n;";
+ (void)sprintf(format, "%%%d[^%s]", l, t);
+ while (1)
+ {
+ if ((f = testnl()) && s)
+ printf("%s: ", s);
+ if (f)
+ cgetc(0);
+ scanf("%*[\t ;]");
+ i = scanf(format, r);
+ if (i < 0)
+ exit(1);
+ if (i != 0)
+ return;
+ }
+}
+
+
+/**
+ ** test if newline is next valid character
+ **/
+
+testnl()
+{
+ register char c;
+
+ while ((c = cgetc(0)) != '\n')
+ if ((c >= '0' && c <= '9') || c == '.' || c == '!' ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= 'a' && c <= 'z') || c == '-')
+ {
+ ungetc(c, stdin);
+ return(0);
+ }
+ ungetc(c, stdin);
+ return (1);
+}
+
+
+/**
+ ** scan for newline
+ **/
+
+skiptonl(c)
+char c;
+{
+ while (c != '\n')
+ if (!(c = cgetc(0)))
+ return;
+ ungetc('\n', stdin);
+ return;
+}
+
+
+/**
+ ** test for valid terminator
+ **/
+
+testterm()
+{
+ register char c;
+
+ if (!(c = cgetc(0)))
+ return (1);
+ if (c == '.')
+ return (0);
+ if (c == '\n' || c == ';')
+ ungetc(c, stdin);
+ return (1);
+}
+
+
+/*
+** TEST FOR SPECIFIED DELIMETER
+**
+** The standard input is scanned for the parameter. If found,
+** it is thrown away and non-zero is returned. If not found,
+** zero is returned.
+*/
+
+readdelim(d)
+char d;
+{
+ register char c;
+
+ while (c = cgetc(0))
+ {
+ if (c == d)
+ return (1);
+ if (c == ' ')
+ continue;
+ ungetc(c, stdin);
+ break;
+ }
+ return (0);
+}
diff --git a/trek/getpar.h b/trek/getpar.h
new file mode 100644
index 00000000..4da3b071
--- /dev/null
+++ b/trek/getpar.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)getpar.h 5.4 (Berkeley) 6/1/90
+ */
+
+struct cvntab /* used for getcodpar() paramater list */
+{
+ char *abrev;
+ char *full;
+ int (*value)();
+ int value2;
+};
+
+extern double getfltpar();
+extern struct cvntab *getcodpar();
diff --git a/trek/help.c b/trek/help.c
new file mode 100644
index 00000000..091210b0
--- /dev/null
+++ b/trek/help.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)help.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** call starbase for help
+**
+** First, the closest starbase is selected. If there is a
+** a starbase in your own quadrant, you are in good shape.
+** This distance takes quadrant distances into account only.
+**
+** A magic number is computed based on the distance which acts
+** as the probability that you will be rematerialized. You
+** get three tries.
+**
+** When it is determined that you should be able to be remater-
+** ialized (i.e., when the probability thing mentioned above
+** comes up positive), you are put into that quadrant (anywhere).
+** Then, we try to see if there is a spot adjacent to the star-
+** base. If not, you can't be rematerialized!!! Otherwise,
+** it drops you there. It only tries five times to find a spot
+** to drop you. After that, it's your problem.
+*/
+
+char *Cntvect[3] =
+{"first", "second", "third"};
+
+help()
+{
+ register int i;
+ double dist, x;
+ register int dx, dy;
+ int j, l;
+
+ /* check to see if calling for help is reasonable ... */
+ if (Ship.cond == DOCKED)
+ return (printf("Uhura: But Captain, we're already docked\n"));
+
+ /* or possible */
+ if (damaged(SSRADIO))
+ return (out(SSRADIO));
+ if (Now.bases <= 0)
+ return (printf("Uhura: I'm not getting any response from starbase\n"));
+
+ /* tut tut, there goes the score */
+ Game.helps += 1;
+
+ /* find the closest base */
+ dist = 1e50;
+ if (Quad[Ship.quadx][Ship.quady].bases <= 0)
+ {
+ /* there isn't one in this quadrant */
+ for (i = 0; i < Now.bases; i++)
+ {
+ /* compute distance */
+ dx = Now.base[i].x - Ship.quadx;
+ dy = Now.base[i].y - Ship.quady;
+ x = dx * dx + dy * dy;
+ x = sqrt(x);
+
+ /* see if better than what we already have */
+ if (x < dist)
+ {
+ dist = x;
+ l = i;
+ }
+ }
+
+ /* go to that quadrant */
+ Ship.quadx = Now.base[l].x;
+ Ship.quady = Now.base[l].y;
+ initquad(1);
+ }
+ else
+ {
+ dist = 0.0;
+ }
+
+ /* dematerialize the Enterprise */
+ Sect[Ship.sectx][Ship.secty] = EMPTY;
+ printf("Starbase in %d,%d responds\n", Ship.quadx, Ship.quady);
+
+ /* this next thing acts as a probability that it will work */
+ x = pow(1.0 - pow(0.94, dist), 0.3333333);
+
+ /* attempt to rematerialize */
+ for (i = 0; i < 3; i++)
+ {
+ sleep(2);
+ printf("%s attempt to rematerialize ", Cntvect[i]);
+ if (franf() > x)
+ {
+ /* ok, that's good. let's see if we can set her down */
+ for (j = 0; j < 5; j++)
+ {
+ dx = Etc.starbase.x + ranf(3) - 1;
+ if (dx < 0 || dx >= NSECTS)
+ continue;
+ dy = Etc.starbase.y + ranf(3) - 1;
+ if (dy < 0 || dy >= NSECTS || Sect[dx][dy] != EMPTY)
+ continue;
+ break;
+ }
+ if (j < 5)
+ {
+ /* found an empty spot */
+ printf("succeeds\n");
+ Ship.sectx = dx;
+ Ship.secty = dy;
+ Sect[dx][dy] = Ship.ship;
+ dock();
+ compkldist(0);
+ return;
+ }
+ /* the starbase must have been surrounded */
+ }
+ printf("fails\n");
+ }
+
+ /* one, two, three strikes, you're out */
+ lose(L_NOHELP);
+}
diff --git a/trek/impulse.c b/trek/impulse.c
new file mode 100644
index 00000000..9905b338
--- /dev/null
+++ b/trek/impulse.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)impulse.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/**
+ ** move under impulse power
+ **/
+
+impulse()
+{
+ int course;
+ register int power;
+ double dist, time;
+ register int percent;
+ extern double move();
+
+ if (Ship.cond == DOCKED)
+ return (printf("Scotty: Sorry captain, but we are still docked.\n"));
+ if (damaged(IMPULSE))
+ return (out(IMPULSE));
+ if (getcodi(&course, &dist))
+ return;
+ power = 20 + 100 * dist;
+ percent = 100 * power / Ship.energy + 0.5;
+ if (percent >= 85)
+ {
+ printf("Scotty: That would consume %d%% of our remaining energy.\n",
+ percent);
+ if (!getynpar("Are you sure that is wise"))
+ return;
+ printf("Aye aye, sir\n");
+ }
+ time = dist / 0.095;
+ percent = 100 * time / Now.time + 0.5;
+ if (percent >= 85)
+ {
+ printf("Spock: That would take %d%% of our remaining time.\n",
+ percent);
+ if (!getynpar("Are you sure that is wise"))
+ return;
+ printf("(He's finally gone mad)\n");
+ }
+ Move.time = move(0, course, time, 0.095);
+ Ship.energy -= 20 + 100 * Move.time * 0.095;
+}
diff --git a/trek/initquad.c b/trek/initquad.c
new file mode 100644
index 00000000..b644a7f5
--- /dev/null
+++ b/trek/initquad.c
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)initquad.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Paramize Quadrant Upon Entering
+**
+** A quadrant is initialized from the information held in the
+** Quad matrix. Basically, everything is just initialized
+** randomly, except for the starship, which goes into a fixed
+** sector.
+**
+** If there are Klingons in the quadrant, the captain is informed
+** that the condition is RED, and he is given a chance to put
+** his shields up if the computer is working.
+**
+** The flag `f' is set to disable the check for condition red.
+** This mode is used in situations where you know you are going
+** to be docked, i.e., abandon() and help().
+*/
+
+initquad(f)
+int f;
+{
+ register int i, j;
+ int rx, ry;
+ int nbases, nstars;
+ register struct quad *q;
+ int nholes;
+
+ q = &Quad[Ship.quadx][Ship.quady];
+
+ /* ignored supernova'ed quadrants (this is checked again later anyway */
+ if (q->stars < 0)
+ return;
+ Etc.nkling = q->klings;
+ nbases = q->bases;
+ nstars = q->stars;
+ nholes = q->holes;
+
+ /* have we blundered into a battle zone w/ shields down? */
+ if (Etc.nkling > 0 && !f)
+ {
+ printf("Condition RED\n");
+ Ship.cond = RED;
+ if (!damaged(COMPUTER))
+ shield(1);
+ }
+
+ /* clear out the quadrant */
+ for (i = 0; i < NSECTS; i++)
+ for (j = 0; j < NSECTS; j++)
+ Sect[i][j] = EMPTY;
+
+ /* initialize Enterprise */
+ Sect[Ship.sectx][Ship.secty] = Ship.ship;
+
+ /* initialize Klingons */
+ for (i = 0; i < Etc.nkling; i++)
+ {
+ sector(&rx, &ry);
+ Sect[rx][ry] = KLINGON;
+ Etc.klingon[i].x = rx;
+ Etc.klingon[i].y = ry;
+ Etc.klingon[i].power = Param.klingpwr;
+ Etc.klingon[i].srndreq = 0;
+ }
+ compkldist(1);
+
+ /* initialize star base */
+ if (nbases > 0)
+ {
+ sector(&rx, &ry);
+ Sect[rx][ry] = BASE;
+ Etc.starbase.x = rx;
+ Etc.starbase.y = ry;
+ }
+
+ /* initialize inhabited starsystem */
+ if (q->qsystemname != 0)
+ {
+ sector(&rx, &ry);
+ Sect[rx][ry] = INHABIT;
+ nstars -= 1;
+ }
+
+ /* initialize black holes */
+ for (i = 0; i < nholes; i++)
+ {
+ sector(&rx, &ry);
+ Sect[rx][ry] = HOLE;
+ }
+
+ /* initialize stars */
+ for (i = 0; i < nstars; i++)
+ {
+ sector(&rx, &ry);
+ Sect[rx][ry] = STAR;
+ }
+ Move.newquad = 1;
+}
+
+
+sector(x, y)
+int *x, *y;
+{
+ register int i, j;
+
+ do
+ {
+ i = ranf(NSECTS);
+ j = ranf(NSECTS);
+ } while (Sect[i][j] != EMPTY);
+ *x = i;
+ *y = j;
+ return;
+}
diff --git a/trek/kill.c b/trek/kill.c
new file mode 100644
index 00000000..51a5ca6b
--- /dev/null
+++ b/trek/kill.c
@@ -0,0 +1,227 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)kill.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** KILL KILL KILL !!!
+**
+** This file handles the killing off of almost anything.
+*/
+
+/*
+** Handle a Klingon's death
+**
+** The Klingon at the sector given by the parameters is killed
+** and removed from the Klingon list. Notice that it is not
+** removed from the event list; this is done later, when the
+** the event is to be caught. Also, the time left is recomputed,
+** and the game is won if that was the last klingon.
+*/
+
+killk(ix, iy)
+int ix, iy;
+{
+ register int i, j;
+
+ printf(" *** Klingon at %d,%d destroyed ***\n", ix, iy);
+
+ /* remove the scoundrel */
+ Now.klings -= 1;
+ Sect[ix][iy] = EMPTY;
+ Quad[Ship.quadx][Ship.quady].klings -= 1;
+ /* %%% IS THIS SAFE???? %%% */
+ Quad[Ship.quadx][Ship.quady].scanned -= 100;
+ Game.killk += 1;
+
+ /* find the Klingon in the Klingon list */
+ for (i = 0; i < Etc.nkling; i++)
+ if (ix == Etc.klingon[i].x && iy == Etc.klingon[i].y)
+ {
+ /* purge him from the list */
+ Etc.nkling -= 1;
+ for (; i < Etc.nkling; i++)
+ bmove(&Etc.klingon[i+1], &Etc.klingon[i], sizeof Etc.klingon[i]);
+ break;
+ }
+
+ /* find out if that was the last one */
+ if (Now.klings <= 0)
+ win();
+
+ /* recompute time left */
+ Now.time = Now.resource / Now.klings;
+ return;
+}
+
+
+/*
+** handle a starbase's death
+*/
+
+killb(qx, qy)
+int qx, qy;
+{
+ register struct quad *q;
+ register struct xy *b;
+
+ q = &Quad[qx][qy];
+
+ if (q->bases <= 0)
+ return;
+ if (!damaged(SSRADIO))
+ /* then update starchart */
+ if (q->scanned < 1000)
+ q->scanned -= 10;
+ else
+ if (q->scanned > 1000)
+ q->scanned = -1;
+ q->bases = 0;
+ Now.bases -= 1;
+ for (b = Now.base; ; b++)
+ if (qx == b->x && qy == b->y)
+ break;
+ bmove(&Now.base[Now.bases], b, sizeof *b);
+ if (qx == Ship.quadx && qy == Ship.quady)
+ {
+ Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
+ if (Ship.cond == DOCKED)
+ undock();
+ printf("Starbase at %d,%d destroyed\n", Etc.starbase.x, Etc.starbase.y);
+ }
+ else
+ {
+ if (!damaged(SSRADIO))
+ {
+ printf("Uhura: Starfleet command reports that the starbase in\n");
+ printf(" quadrant %d,%d has been destroyed\n", qx, qy);
+ }
+ else
+ schedule(E_KATSB | E_GHOST, 1e50, qx, qy, 0);
+ }
+}
+
+
+/**
+ ** kill an inhabited starsystem
+ **/
+
+kills(x, y, f)
+int x, y; /* quad coords if f == 0, else sector coords */
+int f; /* f != 0 -- this quad; f < 0 -- Enterprise's fault */
+{
+ register struct quad *q;
+ register struct event *e;
+ register char *name;
+ char *systemname();
+
+ if (f)
+ {
+ /* current quadrant */
+ q = &Quad[Ship.quadx][Ship.quady];
+ Sect[x][y] = EMPTY;
+ name = systemname(q);
+ if (name == 0)
+ return;
+ printf("Inhabited starsystem %s at %d,%d destroyed\n",
+ name, x, y);
+ if (f < 0)
+ Game.killinhab += 1;
+ }
+ else
+ {
+ /* different quadrant */
+ q = &Quad[x][y];
+ }
+ if (q->qsystemname & Q_DISTRESSED)
+ {
+ /* distressed starsystem */
+ e = &Event[q->qsystemname & Q_SYSTEM];
+ printf("Distress call for %s invalidated\n",
+ Systemname[e->systemname]);
+ unschedule(e);
+ }
+ q->qsystemname = 0;
+ q->stars -= 1;
+}
+
+
+/**
+ ** "kill" a distress call
+ **/
+
+killd(x, y, f)
+int x, y; /* quadrant coordinates */
+int f; /* set if user is to be informed */
+{
+ register struct event *e;
+ register int i;
+ register struct quad *q;
+
+ q = &Quad[x][y];
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->x != x || e->y != y)
+ continue;
+ switch (e->evcode)
+ {
+ case E_KDESB:
+ if (f)
+ {
+ printf("Distress call for starbase in %d,%d nullified\n",
+ x, y);
+ unschedule(e);
+ }
+ break;
+
+ case E_ENSLV:
+ case E_REPRO:
+ if (f)
+ {
+ printf("Distress call for %s in quadrant %d,%d nullified\n",
+ Systemname[e->systemname], x, y);
+ q->qsystemname = e->systemname;
+ unschedule(e);
+ }
+ else
+ {
+ e->evcode |= E_GHOST;
+ }
+ }
+ }
+}
diff --git a/trek/klmove.c b/trek/klmove.c
new file mode 100644
index 00000000..ca9ba1ce
--- /dev/null
+++ b/trek/klmove.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)klmove.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Move Klingons Around
+**
+** This is a largely incomprehensible block of code that moves
+** Klingons around in a quadrant. It was written in a very
+** "program as you go" fashion, and is a prime candidate for
+** rewriting.
+**
+** The flag `fl' is zero before an attack, one after an attack,
+** and two if you are leaving a quadrant. This serves to
+** change the probability and distance that it moves.
+**
+** Basically, what it will try to do is to move a certain number
+** of steps either toward you or away from you. It will avoid
+** stars whenever possible. Nextx and nexty are the next
+** sector to move to on a per-Klingon basis; they are roughly
+** equivalent to Ship.sectx and Ship.secty for the starship. Lookx and
+** looky are the sector that you are going to look at to see
+** if you can move their. Dx and dy are the increment. Fudgex
+** and fudgey are the things you change around to change your
+** course around stars.
+*/
+
+klmove(fl)
+int fl;
+{
+ int n;
+ register struct kling *k;
+ double dx, dy;
+ int nextx, nexty;
+ register int lookx, looky;
+ int motion;
+ int fudgex, fudgey;
+ int qx, qy;
+ double bigger;
+ int i;
+
+# ifdef xTRACE
+ if (Trace)
+ printf("klmove: fl = %d, Etc.nkling = %d\n", fl, Etc.nkling);
+# endif
+ for (n = 0; n < Etc.nkling; k && n++)
+ {
+ k = &Etc.klingon[n];
+ i = 100;
+ if (fl)
+ i = 100.0 * k->power / Param.klingpwr;
+ if (ranf(i) >= Param.moveprob[2 * Move.newquad + fl])
+ continue;
+ /* compute distance to move */
+ motion = ranf(75) - 25;
+ motion *= k->avgdist * Param.movefac[2 * Move.newquad + fl];
+ /* compute direction */
+ dx = Ship.sectx - k->x + ranf(3) - 1;
+ dy = Ship.secty - k->y + ranf(3) - 1;
+ bigger = dx;
+ if (dy > bigger)
+ bigger = dy;
+ if (bigger == 0.0)
+ bigger = 1.0;
+ dx = dx / bigger + 0.5;
+ dy = dy / bigger + 0.5;
+ if (motion < 0)
+ {
+ motion = -motion;
+ dx = -dx;
+ dy = -dy;
+ }
+ fudgex = fudgey = 1;
+ /* try to move the klingon */
+ nextx = k->x;
+ nexty = k->y;
+ for (; motion > 0; motion--)
+ {
+ lookx = nextx + dx;
+ looky = nexty + dy;
+ if (lookx < 0 || lookx >= NSECTS || looky < 0 || looky >= NSECTS)
+ {
+ /* new quadrant */
+ qx = Ship.quadx;
+ qy = Ship.quady;
+ if (lookx < 0)
+ qx -= 1;
+ else
+ if (lookx >= NSECTS)
+ qx += 1;
+ if (looky < 0)
+ qy -= 1;
+ else
+ if (looky >= NSECTS)
+ qy += 1;
+ if (qx < 0 || qx >= NQUADS || qy < 0 || qy >= NQUADS ||
+ Quad[qx][qy].stars < 0 || Quad[qx][qy].klings > MAXKLQUAD - 1)
+ break;
+ if (!damaged(SRSCAN))
+ {
+ printf("Klingon at %d,%d escapes to quadrant %d,%d\n",
+ k->x, k->y, qx, qy);
+ motion = Quad[qx][qy].scanned;
+ if (motion >= 0 && motion < 1000)
+ Quad[qx][qy].scanned += 100;
+ motion = Quad[Ship.quadx][Ship.quady].scanned;
+ if (motion >= 0 && motion < 1000)
+ Quad[Ship.quadx][Ship.quady].scanned -= 100;
+ }
+ Sect[k->x][k->y] = EMPTY;
+ Quad[qx][qy].klings += 1;
+ Etc.nkling -= 1;
+ bmove(&Etc.klingon[Etc.nkling], k, sizeof *k);
+ Quad[Ship.quadx][Ship.quady].klings -= 1;
+ k = 0;
+ break;
+ }
+ if (Sect[lookx][looky] != EMPTY)
+ {
+ lookx = nextx + fudgex;
+ if (lookx < 0 || lookx >= NSECTS)
+ lookx = nextx + dx;
+ if (Sect[lookx][looky] != EMPTY)
+ {
+ fudgex = -fudgex;
+ looky = nexty + fudgey;
+ if (looky < 0 || looky >= NSECTS || Sect[lookx][looky] != EMPTY)
+ {
+ fudgey = -fudgey;
+ break;
+ }
+ }
+ }
+ nextx = lookx;
+ nexty = looky;
+ }
+ if (k && (k->x != nextx || k->y != nexty))
+ {
+ if (!damaged(SRSCAN))
+ printf("Klingon at %d,%d moves to %d,%d\n",
+ k->x, k->y, nextx, nexty);
+ Sect[k->x][k->y] = EMPTY;
+ Sect[k->x = nextx][k->y = nexty] = KLINGON;
+ }
+ }
+ compkldist(0);
+}
diff --git a/trek/lose.c b/trek/lose.c
new file mode 100644
index 00000000..27fa0c75
--- /dev/null
+++ b/trek/lose.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)lose.c 5.6 (Berkeley) 6/26/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include <setjmp.h>
+
+/*
+** PRINT OUT LOSER MESSAGES
+**
+** The messages are printed out, the score is computed and
+** printed, and the game is restarted. Oh yeh, any special
+** actions which need be taken are taken.
+*/
+
+char *Losemsg[] =
+{
+ "You ran out of time",
+ "You ran out of energy",
+ "You have been destroyed",
+ "You ran into the negative energy barrier",
+ "You destroyed yourself by nova'ing that star",
+ "You have been caught in a supernova",
+ "You just suffocated in outer space",
+ "You could not be rematerialized",
+ "\n\032\014 ***\07 Ship's hull has imploded\07 ***",
+ "You have burned up in a star",
+ "Well, you destroyed yourself, but it didn't do any good",
+ "You have been captured by Klingons and mercilessly tortured",
+ "Your last crew member died",
+};
+
+lose(why)
+int why;
+{
+ extern jmp_buf env;
+
+ Game.killed = 1;
+ sleep(1);
+ printf("\n%s\n", Losemsg[why - 1]);
+ switch (why)
+ {
+
+ case L_NOTIME:
+ Game.killed = 0;
+ break;
+ }
+ Move.endgame = -1;
+ score();
+ skiptonl(0);
+ longjmp(env, 1);
+}
diff --git a/trek/lrscan.c b/trek/lrscan.c
new file mode 100644
index 00000000..ff603868
--- /dev/null
+++ b/trek/lrscan.c
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)lrscan.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** LONG RANGE OF SCANNERS
+**
+** A summary of the quadrants that surround you is printed. The
+** hundreds digit is the number of Klingons in the quadrant,
+** the tens digit is the number of starbases, and the units digit
+** is the number of stars. If the printout is "///" it means
+** that that quadrant is rendered uninhabitable by a supernova.
+** It also updates the "scanned" field of the quadrants it scans,
+** for future use by the "chart" option of the computer.
+*/
+
+lrscan()
+{
+ register int i, j;
+ register struct quad *q;
+
+ if (check_out(LRSCAN))
+ {
+ return;
+ }
+ printf("Long range scan for quadrant %d,%d\n\n", Ship.quadx, Ship.quady);
+
+ /* print the header on top */
+ for (j = Ship.quady - 1; j <= Ship.quady + 1; j++)
+ {
+ if (j < 0 || j >= NQUADS)
+ printf(" ");
+ else
+ printf(" %1d", j);
+ }
+
+ /* scan the quadrants */
+ for (i = Ship.quadx - 1; i <= Ship.quadx + 1; i++)
+ {
+ printf("\n -------------------\n");
+ if (i < 0 || i >= NQUADS)
+ {
+ /* negative energy barrier */
+ printf(" ! * ! * ! * !");
+ continue;
+ }
+
+ /* print the left hand margin */
+ printf("%1d !", i);
+ for (j = Ship.quady - 1; j <= Ship.quady + 1; j++)
+ {
+ if (j < 0 || j >= NQUADS)
+ {
+ /* negative energy barrier again */
+ printf(" * !");
+ continue;
+ }
+ q = &Quad[i][j];
+ if (q->stars < 0)
+ {
+ /* supernova */
+ printf(" /// !");
+ q->scanned = 1000;
+ continue;
+ }
+ q->scanned = q->klings * 100 + q->bases * 10 + q->stars;
+ printf(" %3d !", q->scanned);
+ }
+ }
+ printf("\n -------------------\n");
+ return;
+}
diff --git a/trek/main.c b/trek/main.c
new file mode 100644
index 00000000..3cad83c2
--- /dev/null
+++ b/trek/main.c
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)main.c 5.7 (Berkeley) 2/28/91";
+#endif /* not lint */
+
+# include "trek.h"
+# include <stdio.h>
+# include <sgtty.h>
+# include <setjmp.h>
+
+# define PRIO 00 /* default priority */
+
+int Mother = 51 + (51 << 8);
+
+/*
+** #### ##### # #### ##### #### ##### # #
+** # # # # # # # # # # # #
+** ### # ##### #### # #### ### ###
+** # # # # # # # # # # # #
+** #### # # # # # # # # ##### # #
+**
+** C version by Eric P. Allman 5/76 (U.C. Berkeley) with help
+** from Jeff Poskanzer and Pete Rubinstein.
+**
+** I also want to thank everyone here at Berkeley who
+** where crazy enough to play the undebugged game. I want to
+** particularly thank Nick Whyte, who made considerable
+** suggestions regarding the content of the game. Why, I'll
+** never forget the time he suggested the name for the
+** "capture" command.
+**
+** Please send comments, questions, and suggestions about this
+** game to:
+** Eric P. Allman
+** Project INGRES
+** Electronics Research Laboratory
+** Cory Hall
+** University of California
+** Berkeley, California 94720
+**
+** If you make ANY changes in the game, I sure would like to
+** know about them. It is sort of an ongoing project for me,
+** and I very much want to put in any bug fixes and improvements
+** that you might come up with.
+**
+** FORTRASH version by Kay R. Fisher (DEC) "and countless others".
+** That was adapted from the "original BASIC program" (ha!) by
+** Mike Mayfield (Centerline Engineering).
+**
+** Additional inspiration taken from FORTRAN version by
+** David Matuszek and Paul Reynolds which runs on the CDC
+** 7600 at Lawrence Berkeley Lab, maintained there by
+** Andy Davidson. This version is also available at LLL
+** and at LMSC. In all fairness, this version was the
+** major inspiration for this version of the game (trans-
+** lation: I ripped off a whole lot of code).
+**
+** Minor other input from the "Battelle Version 7A" by Joe Miller
+** (Graphics Systems Group, Battelle-Columbus Labs) and
+** Ross Pavlac (Systems Programmer, Battelle Memorial
+** Institute). That version was written in December '74
+** and extensively modified June '75. It was adapted
+** from the FTN version by Ron Williams of CDC Sunnyvale,
+** which was adapted from the Basic version distributed
+** by DEC. It also had "neat stuff swiped" from T. T.
+** Terry and Jim Korp (University of Texas), Hicks (Penn
+** U.), and Rick Maus (Georgia Tech). Unfortunately, it
+** was not as readable as it could have been and so the
+** translation effort was severely hampered. None the
+** less, I got the idea of inhabited starsystems from this
+** version.
+**
+** Permission is given for use, copying, and modification of
+** all or part of this program and related documentation,
+** provided that all reference to the authors are maintained.
+**
+**
+**********************************************************************
+**
+** NOTES TO THE MAINTAINER:
+**
+** There is a compilation option xTRACE which must be set for any
+** trace information to be generated. It is probably defined in
+** the version that you get. It can be removed, however, if you
+** have trouble finding room in core.
+**
+** Many things in trek are not as clear as they might be, but are
+** done to reduce space. I compile with the -f and -O flags. I
+** am constrained to running with non-seperated I/D space, since
+** we don't have doubleing point hardware here; even if we did, I
+** would like trek to be available to the large number of people
+** who either have an 11/40 or do not have FP hardware. I also
+** found it desirable to make the code run reentrant, so this
+** added even more space constraints.
+**
+** I use the portable C library to do my I/O. This is done be-
+** cause I wanted the game easily transportable to other C
+** implementations, and because I was too lazy to do the doubleing
+** point input myself. Little did I know. The portable C library
+** released by Bell Labs has more bugs than you would believe, so
+** I ended up rewriting the whole blessed thing. Trek excercises
+** many of the bugs in it, as well as bugs in some of the section
+** III UNIX routines. We have fixed them here. One main problem
+** was a bug in alloc() that caused it to always ask for a large
+** hunk of memory, which worked fine unless you were almost out,
+** which I inevitably was. If you want the code for all of this
+** stuff, it is also available through me.
+**
+***********************************************************************
+*/
+
+jmp_buf env;
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+ long vect;
+ /* extern FILE *f_log; */
+ register char opencode;
+ int prio;
+ register int ac;
+ register char **av;
+ struct sgttyb argp;
+
+ av = argv;
+ ac = argc;
+ av++;
+ time(&vect);
+ srand(vect);
+ opencode = 'w';
+ prio = PRIO;
+ if (gtty(1, &argp) == 0)
+ {
+ if ((argp.sg_ispeed ) < B1200)
+ Etc.fast++;
+ }
+ while (ac > 1 && av[0][0] == '-')
+ {
+ switch (av[0][1])
+ {
+ case 'a': /* append to log file */
+ opencode = 'a';
+ break;
+
+ case 'f': /* set fast mode */
+ Etc.fast++;
+ break;
+
+ case 's': /* set slow mode */
+ Etc.fast = 0;
+ break;
+
+# ifdef xTRACE
+ case 't': /* trace */
+ if (getuid() != Mother)
+ goto badflag;
+ Trace++;
+ break;
+# endif
+
+ case 'p': /* set priority */
+ if (getuid() != Mother)
+ goto badflag;
+ prio = atoi(av[0] + 2);
+ break;
+
+ default:
+ badflag:
+ printf("Invalid option: %s\n", av[0]);
+
+ }
+ ac--;
+ av++;
+ }
+ if (ac > 2)
+ syserr(0, "arg count");
+ /*
+ if (ac > 1)
+ f_log = fopen(av[0], opencode);
+ */
+
+ printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
+
+ if (setjmp(env))
+ {
+ if ( !getynpar("Another game") )
+ exit(0);
+ }
+ do
+ {
+ setup();
+ play();
+ } while (getynpar("Another game"));
+
+ fflush(stdout);
+}
diff --git a/trek/move.c b/trek/move.c
new file mode 100644
index 00000000..68bc9dc8
--- /dev/null
+++ b/trek/move.c
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)move.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Move Under Warp or Impulse Power
+**
+** `Ramflag' is set if we are to be allowed to ram stars,
+** Klingons, etc. This is passed from warp(), which gets it from
+** either play() or ram(). Course is the course (0 -> 360) at
+** which we want to move. `Speed' is the speed we
+** want to go, and `time' is the expected time. It
+** can get cut short if a long range tractor beam is to occur. We
+** cut short the move so that the user doesn't get docked time and
+** energy for distance which he didn't travel.
+**
+** We check the course through the current quadrant to see that he
+** doesn't run into anything. After that, though, space sort of
+** bends around him. Note that this puts us in the awkward posi-
+** tion of being able to be dropped into a sector which is com-
+** pletely surrounded by stars. Oh Well.
+**
+** If the SINS (Space Inertial Navigation System) is out, we ran-
+** domize the course accordingly before ever starting to move.
+** We will still move in a straight line.
+**
+** Note that if your computer is out, you ram things anyway. In
+** other words, if your computer and sins are both out, you're in
+** potentially very bad shape.
+**
+** Klingons get a chance to zap you as you leave the quadrant.
+** By the way, they also try to follow you (heh heh).
+**
+** Return value is the actual amount of time used.
+**
+**
+** Uses trace flag 4.
+*/
+
+double move(ramflag, course, time, speed)
+int ramflag;
+int course;
+double time;
+double speed;
+{
+ double angle;
+ double x, y, dx, dy;
+ register int ix, iy;
+ double bigger;
+ int n;
+ register int i;
+ double dist;
+ double sectsize;
+ double xn;
+ double evtime;
+
+# ifdef xTRACE
+ if (Trace)
+ printf("move: ramflag %d course %d time %.2f speed %.2f\n",
+ ramflag, course, time, speed);
+# endif
+ sectsize = NSECTS;
+ /* initialize delta factors for move */
+ angle = course * 0.0174532925;
+ if (damaged(SINS))
+ angle += Param.navigcrud[1] * (franf() - 0.5);
+ else
+ if (Ship.sinsbad)
+ angle += Param.navigcrud[0] * (franf() - 0.5);
+ dx = -cos(angle);
+ dy = sin(angle);
+ bigger = fabs(dx);
+ dist = fabs(dy);
+ if (dist > bigger)
+ bigger = dist;
+ dx /= bigger;
+ dy /= bigger;
+
+ /* check for long range tractor beams */
+ /**** TEMPORARY CODE == DEBUGGING ****/
+ evtime = Now.eventptr[E_LRTB]->date - Now.date;
+# ifdef xTRACE
+ if (Trace)
+ printf("E.ep = %u, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
+ Now.eventptr[E_LRTB], Now.eventptr[E_LRTB]->evcode,
+ Now.eventptr[E_LRTB]->date, evtime);
+# endif
+ if (time > evtime && Etc.nkling < 3)
+ {
+ /* then we got a LRTB */
+ evtime += 0.005;
+ time = evtime;
+ }
+ else
+ evtime = -1.0e50;
+ dist = time * speed;
+
+ /* move within quadrant */
+ Sect[Ship.sectx][Ship.secty] = EMPTY;
+ x = Ship.sectx + 0.5;
+ y = Ship.secty + 0.5;
+ xn = NSECTS * dist * bigger;
+ n = xn + 0.5;
+# ifdef xTRACE
+ if (Trace)
+ printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
+# endif
+ Move.free = 0;
+
+ for (i = 0; i < n; i++)
+ {
+ ix = (x += dx);
+ iy = (y += dy);
+# ifdef xTRACE
+ if (Trace)
+ printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
+# endif
+ if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize)
+ {
+ /* enter new quadrant */
+ dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
+ dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
+ if (dx < 0.0)
+ ix = -1;
+ else
+ ix = dx + 0.5;
+ if (dy < 0.0)
+ iy = -1;
+ else
+ iy = dy + 0.5;
+# ifdef xTRACE
+ if (Trace)
+ printf("New quad: ix = %d, iy = %d\n", ix, iy);
+# endif
+ Ship.sectx = x;
+ Ship.secty = y;
+ compkldist(0);
+ Move.newquad = 2;
+ attack(0);
+ checkcond();
+ Ship.quadx = ix / NSECTS;
+ Ship.quady = iy / NSECTS;
+ Ship.sectx = ix % NSECTS;
+ Ship.secty = iy % NSECTS;
+ if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 || Ship.quady >= NQUADS)
+ if (!damaged(COMPUTER))
+ {
+ dumpme(0);
+ }
+ else
+ lose(L_NEGENB);
+ initquad(0);
+ n = 0;
+ break;
+ }
+ if (Sect[ix][iy] != EMPTY)
+ {
+ /* we just hit something */
+ if (!damaged(COMPUTER) && ramflag <= 0)
+ {
+ ix = x - dx;
+ iy = y - dy;
+ printf("Computer reports navigation error; %s stopped at %d,%d\n",
+ Ship.shipname, ix, iy);
+ Ship.energy -= Param.stopengy * speed;
+ break;
+ }
+ /* test for a black hole */
+ if (Sect[ix][iy] == HOLE)
+ {
+ /* get dumped elsewhere in the galaxy */
+ dumpme(1);
+ initquad(0);
+ n = 0;
+ break;
+ }
+ ram(ix, iy);
+ break;
+ }
+ }
+ if (n > 0)
+ {
+ dx = Ship.sectx - ix;
+ dy = Ship.secty - iy;
+ dist = sqrt(dx * dx + dy * dy) / NSECTS;
+ time = dist / speed;
+ if (evtime > time)
+ time = evtime; /* spring the LRTB trap */
+ Ship.sectx = ix;
+ Ship.secty = iy;
+ }
+ Sect[Ship.sectx][Ship.secty] = Ship.ship;
+ compkldist(0);
+ return (time);
+}
diff --git a/trek/nova.c b/trek/nova.c
new file mode 100644
index 00000000..fc5f584e
--- /dev/null
+++ b/trek/nova.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)nova.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** CAUSE A NOVA TO OCCUR
+**
+** A nova occurs. It is the result of having a star hit with
+** a photon torpedo. There are several things which may happen.
+** The star may not be affected. It may go nova. It may turn
+** into a black hole. Any (yummy) it may go supernova.
+**
+** Stars that go nova cause stars which surround them to undergo
+** the same probabilistic process. Klingons next to them are
+** destroyed. And if the starship is next to it, it gets zapped.
+** If the zap is too much, it gets destroyed.
+*/
+
+nova(x, y)
+int x, y;
+{
+ register int i, j;
+ register int se;
+
+ if (Sect[x][y] != STAR || Quad[Ship.quadx][Ship.quady].stars < 0)
+ return;
+ if (ranf(100) < 15)
+ {
+ printf("Spock: Star at %d,%d failed to nova.\n", x, y);
+ return;
+ }
+ if (ranf(100) < 5)
+ return (snova(x, y));
+ printf("Spock: Star at %d,%d gone nova\n", x, y);
+
+ if (ranf(4) != 0)
+ Sect[x][y] = EMPTY;
+ else
+ {
+ Sect[x][y] = HOLE;
+ Quad[Ship.quadx][Ship.quady].holes += 1;
+ }
+ Quad[Ship.quadx][Ship.quady].stars -= 1;
+ Game.kills += 1;
+ for (i = x - 1; i <= x + 1; i++)
+ {
+ if (i < 0 || i >= NSECTS)
+ continue;
+ for (j = y - 1; j <= y + 1; j++)
+ {
+ if (j < 0 || j >= NSECTS)
+ continue;
+ se = Sect[i][j];
+ switch (se)
+ {
+
+ case EMPTY:
+ case HOLE:
+ break;
+
+ case KLINGON:
+ killk(i, j);
+ break;
+
+ case STAR:
+ nova(i, j);
+ break;
+
+ case INHABIT:
+ kills(i, j, -1);
+ break;
+
+ case BASE:
+ killb(i, j);
+ Game.killb += 1;
+ break;
+
+ case ENTERPRISE:
+ case QUEENE:
+ se = 2000;
+ if (Ship.shldup)
+ if (Ship.shield >= se)
+ {
+ Ship.shield -= se;
+ se = 0;
+ }
+ else
+ {
+ se -= Ship.shield;
+ Ship.shield = 0;
+ }
+ Ship.energy -= se;
+ if (Ship.energy <= 0)
+ lose(L_SUICID);
+ break;
+
+ default:
+ printf("Unknown object %c at %d,%d destroyed\n",
+ se, i, j);
+ Sect[i][j] = EMPTY;
+ break;
+ }
+ }
+ }
+ return;
+}
diff --git a/trek/out.c b/trek/out.c
new file mode 100644
index 00000000..627dc670
--- /dev/null
+++ b/trek/out.c
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)out.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** Announce Device Out
+*/
+
+out(dev)
+int dev;
+{
+ register struct device *d;
+
+ d = &Device[dev];
+ printf("%s reports %s ", d->person, d->name);
+ if (d->name[length(d->name) - 1] == 's')
+ printf("are");
+ else
+ printf("is");
+ printf(" damaged\n");
+}
diff --git a/trek/phaser.c b/trek/phaser.c
new file mode 100644
index 00000000..62b47fbc
--- /dev/null
+++ b/trek/phaser.c
@@ -0,0 +1,369 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)phaser.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/* factors for phaser hits; see description below */
+
+# define ALPHA 3.0 /* spread */
+# define BETA 3.0 /* franf() */
+# define GAMMA 0.30 /* cos(angle) */
+# define EPSILON 150.0 /* dist ** 2 */
+# define OMEGA 10.596 /* overall scaling factor */
+
+/* OMEGA ~= 100 * (ALPHA + 1) * (BETA + 1) / (EPSILON + 1) */
+
+/*
+** Phaser Control
+**
+** There are up to NBANKS phaser banks which may be fired
+** simultaneously. There are two modes, "manual" and
+** "automatic". In manual mode, you specify exactly which
+** direction you want each bank to be aimed, the number
+** of units to fire, and the spread angle. In automatic
+** mode, you give only the total number of units to fire.
+**
+** The spread is specified as a number between zero and
+** one, with zero being minimum spread and one being maximum
+** spread. You will normally want zero spread, unless your
+** short range scanners are out, in which case you probably
+** don't know exactly where the Klingons are. In that case,
+** you really don't have any choice except to specify a
+** fairly large spread.
+**
+** Phasers spread slightly, even if you specify zero spread.
+**
+** Uses trace flag 30
+*/
+
+struct cvntab Matab[] =
+{
+ "m", "anual", (int (*)())1, 0,
+ "a", "utomatic", 0, 0,
+ 0
+};
+
+struct banks
+{
+ int units;
+ double angle;
+ double spread;
+};
+
+
+
+phaser()
+{
+ register int i;
+ int j;
+ register struct kling *k;
+ double dx, dy;
+ double anglefactor, distfactor;
+ register struct banks *b;
+ int manual, flag, extra;
+ int hit;
+ double tot;
+ int n;
+ int hitreqd[NBANKS];
+ struct banks bank[NBANKS];
+ struct cvntab *ptr;
+
+ if (Ship.cond == DOCKED)
+ return(printf("Phasers cannot fire through starbase shields\n"));
+ if (damaged(PHASER))
+ return (out(PHASER));
+ if (Ship.shldup)
+ return (printf("Sulu: Captain, we cannot fire through shields.\n"));
+ if (Ship.cloaked)
+ {
+ printf("Sulu: Captain, surely you must realize that we cannot fire\n");
+ printf(" phasers with the cloaking device up.\n");
+ return;
+ }
+
+ /* decide if we want manual or automatic mode */
+ manual = 0;
+ if (testnl())
+ {
+ if (damaged(COMPUTER))
+ {
+ printf(Device[COMPUTER].name);
+ manual++;
+ }
+ else
+ if (damaged(SRSCAN))
+ {
+ printf(Device[SRSCAN].name);
+ manual++;
+ }
+ if (manual)
+ printf(" damaged, manual mode selected\n");
+ }
+
+ if (!manual)
+ {
+ ptr = getcodpar("Manual or automatic", Matab);
+ manual = (int) ptr->value;
+ }
+ if (!manual && damaged(COMPUTER))
+ {
+ printf("Computer damaged, manual selected\n");
+ skiptonl(0);
+ manual++;
+ }
+
+ /* initialize the bank[] array */
+ flag = 1;
+ for (i = 0; i < NBANKS; i++)
+ bank[i].units = 0;
+ if (manual)
+ {
+ /* collect manual mode statistics */
+ while (flag)
+ {
+ printf("%d units available\n", Ship.energy);
+ extra = 0;
+ flag = 0;
+ for (i = 0; i < NBANKS; i++)
+ {
+ b = &bank[i];
+ printf("\nBank %d:\n", i);
+ hit = getintpar("units");
+ if (hit < 0)
+ return;
+ if (hit == 0)
+ break;
+ extra += hit;
+ if (extra > Ship.energy)
+ {
+ printf("available energy exceeded. ");
+ skiptonl(0);
+ flag++;
+ break;
+ }
+ b->units = hit;
+ hit = getintpar("course");
+ if (hit < 0 || hit > 360)
+ return;
+ b->angle = hit * 0.0174532925;
+ b->spread = getfltpar("spread");
+ if (b->spread < 0 || b->spread > 1)
+ return;
+ }
+ Ship.energy -= extra;
+ }
+ extra = 0;
+ }
+ else
+ {
+ /* automatic distribution of power */
+ if (Etc.nkling <= 0)
+ return (printf("Sulu: But there are no Klingons in this quadrant\n"));
+ printf("Phasers locked on target. ");
+ while (flag)
+ {
+ printf("%d units available\n", Ship.energy);
+ hit = getintpar("Units to fire");
+ if (hit <= 0)
+ return;
+ if (hit > Ship.energy)
+ {
+ printf("available energy exceeded. ");
+ skiptonl(0);
+ continue;
+ }
+ flag = 0;
+ Ship.energy -= hit;
+ extra = hit;
+ n = Etc.nkling;
+ if (n > NBANKS)
+ n = NBANKS;
+ tot = n * (n + 1) / 2;
+ for (i = 0; i < n; i++)
+ {
+ k = &Etc.klingon[i];
+ b = &bank[i];
+ distfactor = k->dist;
+ anglefactor = ALPHA * BETA * OMEGA / (distfactor * distfactor + EPSILON);
+ anglefactor *= GAMMA;
+ distfactor = k->power;
+ distfactor /= anglefactor;
+ hitreqd[i] = distfactor + 0.5;
+ dx = Ship.sectx - k->x;
+ dy = k->y - Ship.secty;
+ b->angle = atan2(dy, dx);
+ b->spread = 0.0;
+ b->units = ((n - i) / tot) * extra;
+# ifdef xTRACE
+ if (Trace)
+ {
+ printf("b%d hr%d u%d df%.2f af%.2f\n",
+ i, hitreqd[i], b->units,
+ distfactor, anglefactor);
+ }
+# endif
+ extra -= b->units;
+ hit = b->units - hitreqd[i];
+ if (hit > 0)
+ {
+ extra += hit;
+ b->units -= hit;
+ }
+ }
+
+ /* give out any extra energy we might have around */
+ if (extra > 0)
+ {
+ for (i = 0; i < n; i++)
+ {
+ b = &bank[i];
+ hit = hitreqd[i] - b->units;
+ if (hit <= 0)
+ continue;
+ if (hit >= extra)
+ {
+ b->units += extra;
+ extra = 0;
+ break;
+ }
+ b->units = hitreqd[i];
+ extra -= hit;
+ }
+ if (extra > 0)
+ printf("%d units overkill\n", extra);
+ }
+ }
+ }
+
+# ifdef xTRACE
+ if (Trace)
+ {
+ for (i = 0; i < NBANKS; i++)
+ {
+ b = &bank[i];
+ printf("b%d u%d", i, b->units);
+ if (b->units > 0)
+ printf(" a%.2f s%.2f\n", b->angle, b->spread);
+ else
+ printf("\n");
+ }
+ }
+# endif
+
+ /* actually fire the shots */
+ Move.free = 0;
+ for (i = 0; i < NBANKS; i++)
+ {
+ b = &bank[i];
+ if (b->units <= 0)
+ {
+ continue;
+ }
+ printf("\nPhaser bank %d fires:\n", i);
+ n = Etc.nkling;
+ k = Etc.klingon;
+ for (j = 0; j < n; j++)
+ {
+ if (b->units <= 0)
+ break;
+ /*
+ ** The formula for hit is as follows:
+ **
+ ** zap = OMEGA * [(sigma + ALPHA) * (rho + BETA)]
+ ** / (dist ** 2 + EPSILON)]
+ ** * [cos(delta * sigma) + GAMMA]
+ ** * hit
+ **
+ ** where sigma is the spread factor,
+ ** rho is a random number (0 -> 1),
+ ** GAMMA is a crud factor for angle (essentially
+ ** cruds up the spread factor),
+ ** delta is the difference in radians between the
+ ** angle you are shooting at and the actual
+ ** angle of the klingon,
+ ** ALPHA scales down the significance of sigma,
+ ** BETA scales down the significance of rho,
+ ** OMEGA is the magic number which makes everything
+ ** up to "* hit" between zero and one,
+ ** dist is the distance to the klingon
+ ** hit is the number of units in the bank, and
+ ** zap is the amount of the actual hit.
+ **
+ ** Everything up through dist squared should maximize
+ ** at 1.0, so that the distance factor is never
+ ** greater than one. Conveniently, cos() is
+ ** never greater than one, but the same restric-
+ ** tion applies.
+ */
+ distfactor = BETA + franf();
+ distfactor *= ALPHA + b->spread;
+ distfactor *= OMEGA;
+ anglefactor = k->dist;
+ distfactor /= anglefactor * anglefactor + EPSILON;
+ distfactor *= b->units;
+ dx = Ship.sectx - k->x;
+ dy = k->y - Ship.secty;
+ anglefactor = atan2(dy, dx) - b->angle;
+ anglefactor = cos((anglefactor * b->spread) + GAMMA);
+ if (anglefactor < 0.0)
+ {
+ k++;
+ continue;
+ }
+ hit = anglefactor * distfactor + 0.5;
+ k->power -= hit;
+ printf("%d unit hit on Klingon", hit);
+ if (!damaged(SRSCAN))
+ printf(" at %d,%d", k->x, k->y);
+ printf("\n");
+ b->units -= hit;
+ if (k->power <= 0)
+ {
+ killk(k->x, k->y);
+ continue;
+ }
+ k++;
+ }
+ }
+
+ /* compute overkill */
+ for (i = 0; i < NBANKS; i++)
+ extra += bank[i].units;
+ if (extra > 0)
+ printf("\n%d units expended on empty space\n", extra);
+}
diff --git a/trek/play.c b/trek/play.c
new file mode 100644
index 00000000..729a2047
--- /dev/null
+++ b/trek/play.c
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)play.c 5.6 (Berkeley) 6/26/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+# include <setjmp.h>
+
+/*
+** INSTRUCTION READ AND MAIN PLAY LOOP
+**
+** Well folks, this is it. Here we have the guts of the game.
+** This routine executes moves. It sets up per-move variables,
+** gets the command, and executes the command. After the command,
+** it calls events() to use up time, attack() to have Klingons
+** attack if the move was not free, and checkcond() to check up
+** on how we are doing after the move.
+*/
+extern int abandon(), capture(), shield(), computer(), dcrept(),
+ destruct(), dock(), help(), impulse(), lrscan(),
+ warp(), dumpgame(), rest(), srscan(),
+ myreset(), torped(), visual(), setwarp(), undock(), phaser();
+
+struct cvntab Comtab[] =
+{
+ "abandon", "", abandon, 0,
+ "ca", "pture", capture, 0,
+ "cl", "oak", shield, -1,
+ "c", "omputer", computer, 0,
+ "da", "mages", dcrept, 0,
+ "destruct", "", destruct, 0,
+ "do", "ck", dock, 0,
+ "help", "", help, 0,
+ "i", "mpulse", impulse, 0,
+ "l", "rscan", lrscan, 0,
+ "m", "ove", warp, 0,
+ "p", "hasers", phaser, 0,
+ "ram", "", warp, 1,
+ "dump", "", dumpgame, 0,
+ "r", "est", rest, 0,
+ "sh", "ield", shield, 0,
+ "s", "rscan", srscan, 0,
+ "st", "atus", srscan, -1,
+ "terminate", "", myreset, 0,
+ "t", "orpedo", torped, 0,
+ "u", "ndock", undock, 0,
+ "v", "isual", visual, 0,
+ "w", "arp", setwarp, 0,
+ 0
+};
+
+myreset()
+{
+ extern jmp_buf env;
+
+ longjmp(env, 1);
+}
+
+play()
+{
+ struct cvntab *r;
+
+ while (1)
+ {
+ Move.free = 1;
+ Move.time = 0.0;
+ Move.shldchg = 0;
+ Move.newquad = 0;
+ Move.resting = 0;
+ skiptonl(0);
+ r = getcodpar("\nCommand", Comtab);
+ (*r->value)(r->value2);
+ events(0);
+ attack(0);
+ checkcond();
+ }
+}
diff --git a/trek/ram.c b/trek/ram.c
new file mode 100644
index 00000000..c3d65621
--- /dev/null
+++ b/trek/ram.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)ram.c 5.5 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** RAM SOME OBJECT
+**
+** You have run into some sort of object. It may be a Klingon,
+** a star, or a starbase. If you run into a star, you are really
+** stupid, because there is no hope for you.
+**
+** If you run into something else, you destroy that object. You
+** also rack up incredible damages.
+*/
+
+ram(ix, iy)
+int ix, iy;
+{
+ register int i;
+ register char c;
+
+ printf("\07RED ALERT\07: collision imminent\n");
+ c = Sect[ix][iy];
+ switch (c)
+ {
+
+ case KLINGON:
+ printf("%s rams Klingon at %d,%d\n", Ship.shipname, ix, iy);
+ killk(ix, iy);
+ break;
+
+ case STAR:
+ case INHABIT:
+ printf("Yeoman Rand: Captain, isn't it getting hot in here?\n");
+ sleep(2);
+ printf("Spock: Hull temperature approaching 550 Degrees Kelvin.\n");
+ lose(L_STAR);
+
+ case BASE:
+ printf("You ran into the starbase at %d,%d\n", ix, iy);
+ killb(Ship.quadx, Ship.quady);
+ /* don't penalize the captain if it wasn't his fault */
+ if (!damaged(SINS))
+ Game.killb += 1;
+ break;
+ }
+ sleep(2);
+ printf("%s heavily damaged\n", Ship.shipname);
+
+ /* select the number of deaths to occur */
+ i = 10 + ranf(20 * Game.skill);
+ Game.deaths += i;
+ Ship.crew -= i;
+ printf("McCoy: Take it easy Jim; we had %d casualties.\n", i);
+
+ /* damage devices with an 80% probability */
+ for (i = 0; i < NDEV; i++)
+ {
+ if (ranf(100) < 20)
+ continue;
+ damage(i, (2.5 * (franf() + franf()) + 1.0) * Param.damfac[i]);
+ }
+
+ /* no chance that your shields remained up in all that */
+ Ship.shldup = 0;
+}
diff --git a/trek/ranf.c b/trek/ranf.c
new file mode 100644
index 00000000..21ad9a33
--- /dev/null
+++ b/trek/ranf.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)ranf.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include <stdio.h>
+
+ranf(max)
+int max;
+{
+ register int t;
+
+ if (max <= 0)
+ return (0);
+ t = rand() >> 5;
+ return (t % max);
+}
+
+
+double franf()
+{
+ double t;
+ t = rand() & 077777;
+ return (t / 32767.0);
+}
diff --git a/trek/rest.c b/trek/rest.c
new file mode 100644
index 00000000..e5bf6a62
--- /dev/null
+++ b/trek/rest.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)rest.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/*
+** REST FOR REPAIRS
+**
+** You sit around and wait for repairs to happen. Actually, you
+** sit around and wait for anything to happen. I do want to point
+** out however, that Klingons are not as patient as you are, and
+** they tend to attack you while you are resting.
+**
+** You can never rest through a long range tractor beam.
+**
+** In events() you will be given an opportunity to cancel the
+** rest period if anything momentous happens.
+*/
+
+rest()
+{
+ double t;
+ register int percent;
+
+ /* get the time to rest */
+ t = getfltpar("How long");
+ if (t <= 0.0)
+ return;
+ percent = 100 * t / Now.time + 0.5;
+ if (percent >= 70)
+ {
+ printf("Spock: That would take %d%% of our remaining time.\n",
+ percent);
+ if (!getynpar("Are you really certain that is wise"))
+ return;
+ }
+ Move.time = t;
+
+ /* boundary condition is the LRTB */
+ t = Now.eventptr[E_LRTB]->date - Now.date;
+ if (Ship.cond != DOCKED && Move.time > t)
+ Move.time = t + 0.0001;
+ Move.free = 0;
+ Move.resting = 1;
+}
diff --git a/trek/schedule.c b/trek/schedule.c
new file mode 100644
index 00000000..fa7bced0
--- /dev/null
+++ b/trek/schedule.c
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)schedule.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** SCHEDULE AN EVENT
+**
+** An event of type 'type' is scheduled for time NOW + 'offset'
+** into the first available slot. 'x', 'y', and 'z' are
+** considered the attributes for this event.
+**
+** The address of the slot is returned.
+*/
+
+struct event *schedule(type, offset, x, y, z)
+int type;
+double offset;
+char x, y;
+char z;
+{
+ register struct event *e;
+ register int i;
+ double date;
+
+ date = Now.date + offset;
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ if (e->evcode)
+ continue;
+ /* got a slot */
+# ifdef xTRACE
+ if (Trace)
+ printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n",
+ type, date, i, x, y, z);
+# endif
+ e->evcode = type;
+ e->date = date;
+ e->x = x;
+ e->y = y;
+ e->systemname = z;
+ Now.eventptr[type] = e;
+ return (e);
+ }
+ syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z);
+}
+
+
+/*
+** RESCHEDULE AN EVENT
+**
+** The event pointed to by 'e' is rescheduled to the current
+** time plus 'offset'.
+*/
+
+reschedule(e1, offset)
+struct event *e1;
+double offset;
+{
+ double date;
+ register struct event *e;
+
+ e = e1;
+
+ date = Now.date + offset;
+ e->date = date;
+# ifdef xTRACE
+ if (Trace)
+ printf("reschedule: type %d parm %d %d %d @ %.2f\n",
+ e->evcode, e->x, e->y, e->systemname, date);
+# endif
+ return;
+}
+
+
+/*
+** UNSCHEDULE AN EVENT
+**
+** The event at slot 'e' is deleted.
+*/
+
+unschedule(e1)
+struct event *e1;
+{
+ register struct event *e;
+
+ e = e1;
+
+# ifdef xTRACE
+ if (Trace)
+ printf("unschedule: type %d @ %.2f parm %d %d %d\n",
+ e->evcode, e->date, e->x, e->y, e->systemname);
+# endif
+ Now.eventptr[e->evcode & E_EVENT] = 0;
+ e->date = 1e50;
+ e->evcode = 0;
+ return;
+}
+
+
+/*
+** Abreviated schedule routine
+**
+** Parameters are the event index and a factor for the time
+** figure.
+*/
+
+struct event *xsched(ev1, factor, x, y, z)
+int ev1;
+int factor;
+int x, y, z;
+{
+ register int ev;
+
+ ev = ev1;
+ return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z));
+}
+
+
+/*
+** Simplified reschedule routine
+**
+** Parameters are the event index, the initial date, and the
+** division factor. Look at the code to see what really happens.
+*/
+
+xresched(e1, ev1, factor)
+struct event *e1;
+int ev1;
+int factor;
+{
+ register int ev;
+ register struct event *e;
+
+ ev = ev1;
+ e = e1;
+ reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
+}
diff --git a/trek/score.c b/trek/score.c
new file mode 100644
index 00000000..e0e3be86
--- /dev/null
+++ b/trek/score.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)score.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/*
+** PRINT OUT THE CURRENT SCORE
+*/
+
+long score()
+{
+ register int u;
+ register int t;
+ long s;
+ double r;
+ extern struct cvntab Skitab[];
+
+ printf("\n*** Your score:\n");
+ s = t = Param.klingpwr / 4 * (u = Game.killk);
+ if (t != 0)
+ printf("%d Klingons killed\t\t\t%6d\n", u, t);
+ r = Now.date - Param.date;
+ if (r < 1.0)
+ r = 1.0;
+ r = Game.killk / r;
+ s += (t = 400 * r);
+ if (t != 0)
+ printf("Kill rate %.2f Klingons/stardate \t%6d\n", r, t);
+ r = Now.klings;
+ r /= Game.killk + 1;
+ s += (t = -400 * r);
+ if (t != 0)
+ printf("Penalty for %d klingons remaining\t%6d\n", Now.klings, t);
+ if (Move.endgame > 0)
+ {
+ s += (t = 100 * (u = Game.skill));
+ printf("Bonus for winning a %s%s game\t\t%6d\n", Skitab[u - 1].abrev, Skitab[u - 1].full, t);
+ }
+ if (Game.killed)
+ {
+ s -= 500;
+ printf("Penalty for getting killed\t\t -500\n");
+ }
+ s += (t = -100 * (u = Game.killb));
+ if (t != 0)
+ printf("%d starbases killed\t\t\t%6d\n", u, t);
+ s += (t = -100 * (u = Game.helps));
+ if (t != 0)
+ printf("%d calls for help\t\t\t%6d\n", u, t);
+ s += (t = -5 * (u = Game.kills));
+ if (t != 0)
+ printf("%d stars destroyed\t\t\t%6d\n", u, t);
+ s += (t = -150 * (u = Game.killinhab));
+ if (t != 0)
+ printf("%d inhabited starsystems destroyed\t%6d\n", u, t);
+ if (Ship.ship != ENTERPRISE)
+ {
+ s -= 200;
+ printf("penalty for abandoning ship\t\t -200\n");
+ }
+ s += (t = 3 * (u = Game.captives));
+ if (t != 0)
+ printf("%d Klingons captured\t\t\t%6d\n", u, t);
+ s += (t = -(u = Game.deaths));
+ if (t != 0)
+ printf("%d casualties\t\t\t\t%6d\n", u, t);
+ printf("\n*** TOTAL\t\t\t%14ld\n", s);
+ return (s);
+}
diff --git a/trek/setup.c b/trek/setup.c
new file mode 100644
index 00000000..7f35a259
--- /dev/null
+++ b/trek/setup.c
@@ -0,0 +1,303 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)setup.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/*
+** INITIALIZE THE GAME
+**
+** The length, skill, and password are read, and the game
+** is initialized. It is far too difficult to describe all
+** that goes on in here, but it is all straight-line code;
+** give it a look.
+**
+** Game restart and tournament games are handled here.
+*/
+
+struct cvntab Lentab[] =
+{
+ "s", "hort", (int (*)())1, 0,
+ "m", "edium", (int (*)())2, 0,
+ "l", "ong", (int (*)())4, 0,
+ "restart", "", 0, 0,
+ 0
+};
+
+struct cvntab Skitab[] =
+{
+ "n", "ovice", (int (*)())1, 0,
+ "f", "air", (int (*)())2, 0,
+ "g", "ood", (int (*)())3, 0,
+ "e", "xpert", (int (*)())4, 0,
+ "c", "ommodore", (int (*)())5, 0,
+ "i", "mpossible", (int (*)())6, 0,
+ 0
+};
+
+setup()
+{
+ struct cvntab *r;
+ register int i, j;
+ double f;
+ int d;
+ int fd;
+ int klump;
+ int ix, iy;
+ register struct quad *q;
+ struct event *e;
+
+ while (1)
+ {
+ r = getcodpar("What length game", Lentab);
+ Game.length = (int) r->value;
+ if (Game.length == 0)
+ {
+ if (restartgame())
+ continue;
+ return;
+ }
+ break;
+ }
+ r = getcodpar("What skill game", Skitab);
+ Game.skill = (int) r->value;
+ Game.tourn = 0;
+ getstrpar("Enter a password", Game.passwd, 14, 0);
+ if (sequal(Game.passwd, "tournament"))
+ {
+ getstrpar("Enter tournament code", Game.passwd, 14, 0);
+ Game.tourn = 1;
+ d = 0;
+ for (i = 0; Game.passwd[i]; i++)
+ d += Game.passwd[i] << i;
+ srand(d);
+ }
+ Param.bases = Now.bases = ranf(6 - Game.skill) + 2;
+ if (Game.skill == 6)
+ Param.bases = Now.bases = 1;
+ Param.time = Now.time = 6.0 * Game.length + 2.0;
+ i = Game.skill;
+ j = Game.length;
+ Param.klings = Now.klings = i * j * 3.5 * (franf() + 0.75);
+ if (Param.klings < i * j * 5)
+ Param.klings = Now.klings = i * j * 5;
+ if (Param.klings <= i) /* numerical overflow problems */
+ Param.klings = Now.klings = 127;
+ Param.energy = Ship.energy = 5000;
+ Param.torped = Ship.torped = 10;
+ Ship.ship = ENTERPRISE;
+ Ship.shipname = "Enterprise";
+ Param.shield = Ship.shield = 1500;
+ Param.resource = Now.resource = Param.klings * Param.time;
+ Param.reserves = Ship.reserves = (6 - Game.skill) * 2.0;
+ Param.crew = Ship.crew = 387;
+ Param.brigfree = Ship.brigfree = 400;
+ Ship.shldup = 1;
+ Ship.cond = GREEN;
+ Ship.warp = 5.0;
+ Ship.warp2 = 25.0;
+ Ship.warp3 = 125.0;
+ Ship.sinsbad = 0;
+ Ship.cloaked = 0;
+ Param.date = Now.date = (ranf(20) + 20) * 100;
+ f = Game.skill;
+ f = log(f + 0.5);
+ for (i = 0; i < NDEV; i++)
+ if (Device[i].name[0] == '*')
+ Param.damfac[i] = 0;
+ else
+ Param.damfac[i] = f;
+ /* these probabilities must sum to 1000 */
+ Param.damprob[WARP] = 70; /* warp drive 7.0% */
+ Param.damprob[SRSCAN] = 110; /* short range scanners 11.0% */
+ Param.damprob[LRSCAN] = 110; /* long range scanners 11.0% */
+ Param.damprob[PHASER] = 125; /* phasers 12.5% */
+ Param.damprob[TORPED] = 125; /* photon torpedoes 12.5% */
+ Param.damprob[IMPULSE] = 75; /* impulse engines 7.5% */
+ Param.damprob[SHIELD] = 150; /* shield control 15.0% */
+ Param.damprob[COMPUTER] = 20; /* computer 2.0% */
+ Param.damprob[SSRADIO] = 35; /* subspace radio 3.5% */
+ Param.damprob[LIFESUP] = 30; /* life support 3.0% */
+ Param.damprob[SINS] = 20; /* navigation system 2.0% */
+ Param.damprob[CLOAK] = 50; /* cloaking device 5.0% */
+ Param.damprob[XPORTER] = 80; /* transporter 8.0% */
+ /* check to see that I didn't blow it */
+ for (i = j = 0; i < NDEV; i++)
+ j += Param.damprob[i];
+ if (j != 1000)
+ syserr("Device probabilities sum to %d", j);
+ Param.dockfac = 0.5;
+ Param.regenfac = (5 - Game.skill) * 0.05;
+ if (Param.regenfac < 0.0)
+ Param.regenfac = 0.0;
+ Param.warptime = 10;
+ Param.stopengy = 50;
+ Param.shupengy = 40;
+ i = Game.skill;
+ Param.klingpwr = 100 + 150 * i;
+ if (i >= 6)
+ Param.klingpwr += 150;
+ Param.phasfac = 0.8;
+ Param.hitfac = 0.5;
+ Param.klingcrew = 200;
+ Param.srndrprob = 0.0035;
+ Param.moveprob[KM_OB] = 45;
+ Param.movefac[KM_OB] = .09;
+ Param.moveprob[KM_OA] = 40;
+ Param.movefac[KM_OA] = -0.05;
+ Param.moveprob[KM_EB] = 40;
+ Param.movefac[KM_EB] = 0.075;
+ Param.moveprob[KM_EA] = 25 + 5 * Game.skill;
+ Param.movefac[KM_EA] = -0.06 * Game.skill;
+ Param.moveprob[KM_LB] = 0;
+ Param.movefac[KM_LB] = 0.0;
+ Param.moveprob[KM_LA] = 10 + 10 * Game.skill;
+ Param.movefac[KM_LA] = 0.25;
+ Param.eventdly[E_SNOVA] = 0.5;
+ Param.eventdly[E_LRTB] = 25.0;
+ Param.eventdly[E_KATSB] = 1.0;
+ Param.eventdly[E_KDESB] = 3.0;
+ Param.eventdly[E_ISSUE] = 1.0;
+ Param.eventdly[E_SNAP] = 0.5;
+ Param.eventdly[E_ENSLV] = 0.5;
+ Param.eventdly[E_REPRO] = 2.0;
+ Param.navigcrud[0] = 1.50;
+ Param.navigcrud[1] = 0.75;
+ Param.cloakenergy = 1000;
+ Param.energylow = 1000;
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ e = &Event[i];
+ e->date = 1e50;
+ e->evcode = 0;
+ }
+ xsched(E_SNOVA, 1, 0, 0, 0);
+ xsched(E_LRTB, Param.klings, 0, 0, 0);
+ xsched(E_KATSB, 1, 0, 0, 0);
+ xsched(E_ISSUE, 1, 0, 0, 0);
+ xsched(E_SNAP, 1, 0, 0, 0);
+ Ship.sectx = ranf(NSECTS);
+ Ship.secty = ranf(NSECTS);
+ Game.killk = Game.kills = Game.killb = 0;
+ Game.deaths = Game.negenbar = 0;
+ Game.captives = 0;
+ Game.killinhab = 0;
+ Game.helps = 0;
+ Game.killed = 0;
+ Game.snap = 0;
+ Move.endgame = 0;
+
+ /* setup stars */
+ for (i = 0; i < NQUADS; i++)
+ for (j = 0; j < NQUADS; j++)
+ {
+ q = &Quad[i][j];
+ q->klings = q->bases = 0;
+ q->scanned = -1;
+ q->stars = ranf(9) + 1;
+ q->holes = ranf(3) - q->stars / 5;
+ q->qsystemname = 0;
+ }
+
+ /* select inhabited starsystems */
+ for (d = 1; d < NINHAB; d++)
+ {
+ do
+ {
+ i = ranf(NQUADS);
+ j = ranf(NQUADS);
+ q = &Quad[i][j];
+ } while (q->qsystemname);
+ q->qsystemname = d;
+ }
+
+ /* position starbases */
+ for (i = 0; i < Param.bases; i++)
+ {
+ while (1)
+ {
+ ix = ranf(NQUADS);
+ iy = ranf(NQUADS);
+ q = &Quad[ix][iy];
+ if (q->bases > 0)
+ continue;
+ break;
+ }
+ q->bases = 1;
+ Now.base[i].x = ix;
+ Now.base[i].y = iy;
+ q->scanned = 1001;
+ /* start the Enterprise near starbase */
+ if (i == 0)
+ {
+ Ship.quadx = ix;
+ Ship.quady = iy;
+ }
+ }
+
+ /* position klingons */
+ for (i = Param.klings; i > 0; )
+ {
+ klump = ranf(4) + 1;
+ if (klump > i)
+ klump = i;
+ while (1)
+ {
+ ix = ranf(NQUADS);
+ iy = ranf(NQUADS);
+ q = &Quad[ix][iy];
+ if (q->klings + klump > MAXKLQUAD)
+ continue;
+ q->klings += klump;
+ i -= klump;
+ break;
+ }
+ }
+
+ /* initialize this quadrant */
+ printf("%d Klingons\n%d starbase", Param.klings, Param.bases);
+ if (Param.bases > 1)
+ printf("s");
+ printf(" at %d,%d", Now.base[0].x, Now.base[0].y);
+ for (i = 1; i < Param.bases; i++)
+ printf(", %d,%d", Now.base[i].x, Now.base[i].y);
+ printf("\nIt takes %d units to kill a Klingon\n", Param.klingpwr);
+ Move.free = 0;
+ initquad(0);
+ srscan(1);
+ attack(0);
+}
diff --git a/trek/setwarp.c b/trek/setwarp.c
new file mode 100644
index 00000000..8d3d8c89
--- /dev/null
+++ b/trek/setwarp.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)setwarp.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/*
+** SET WARP FACTOR
+**
+** The warp factor is set for future move commands. It is
+** checked for consistancy.
+*/
+
+setwarp()
+{
+ double warpfac;
+
+ warpfac = getfltpar("Warp factor");
+ if (warpfac < 0.0)
+ return;
+ if (warpfac < 1.0)
+ return (printf("Minimum warp speed is 1.0\n"));
+ if (warpfac > 10.0)
+ return (printf("Maximum speed is warp 10.0\n"));
+ if (warpfac > 6.0)
+ printf("Damage to warp engines may occur above warp 6.0\n");
+ Ship.warp = warpfac;
+ Ship.warp2 = Ship.warp * warpfac;
+ Ship.warp3 = Ship.warp2 * warpfac;
+}
diff --git a/trek/shield.c b/trek/shield.c
new file mode 100644
index 00000000..e6fadfea
--- /dev/null
+++ b/trek/shield.c
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)shield.c 5.5 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/*
+** SHIELD AND CLOAKING DEVICE CONTROL
+**
+** 'f' is one for auto shield up (in case of Condition RED),
+** zero for shield control, and negative one for cloaking
+** device control.
+**
+** Called with an 'up' or 'down' on the same line, it puts
+** the shields/cloak into the specified mode. Otherwise it
+** reports to the user the current mode, and asks if she wishes
+** to change.
+**
+** This is not a free move. Hits that occur as a result of
+** this move appear as though the shields are half up/down,
+** so you get partial hits.
+*/
+
+struct cvntab Udtab[] =
+{
+ "u", "p", (int (*)())1, 0,
+ "d", "own", 0, 0,
+ 0
+};
+
+shield(f)
+int f;
+{
+ register int i;
+ char c;
+ struct cvntab *r;
+ char s[100];
+ char *device, *dev2, *dev3;
+ int ind;
+ char *stat;
+
+ if (f > 0 && (Ship.shldup || damaged(SRSCAN)))
+ return;
+ if (f < 0)
+ {
+ /* cloaking device */
+ if (Ship.ship == QUEENE)
+ return (printf("Ye Faire Queene does not have the cloaking device.\n"));
+ device = "Cloaking device";
+ dev2 = "is";
+ ind = CLOAK;
+ dev3 = "it";
+ stat = &Ship.cloaked;
+ }
+ else
+ {
+ /* shields */
+ device = "Shields";
+ dev2 = "are";
+ dev3 = "them";
+ ind = SHIELD;
+ stat = &Ship.shldup;
+ }
+ if (damaged(ind))
+ {
+ if (f <= 0)
+ out(ind);
+ return;
+ }
+ if (Ship.cond == DOCKED)
+ {
+ printf("%s %s down while docked\n", device, dev2);
+ return;
+ }
+ if (f <= 0 && !testnl())
+ {
+ r = getcodpar("Up or down", Udtab);
+ i = (int) r->value;
+ }
+ else
+ {
+ if (*stat)
+ (void)sprintf(s, "%s %s up. Do you want %s down", device, dev2, dev3);
+ else
+ (void)sprintf(s, "%s %s down. Do you want %s up", device, dev2, dev3);
+ if (!getynpar(s))
+ return;
+ i = !*stat;
+ }
+ if (*stat == i)
+ {
+ printf("%s already ", device);
+ if (i)
+ printf("up\n");
+ else
+ printf("down\n");
+ return;
+ }
+ if (i)
+ if (f >= 0)
+ Ship.energy -= Param.shupengy;
+ else
+ Ship.cloakgood = 0;
+ Move.free = 0;
+ if (f >= 0)
+ Move.shldchg = 1;
+ *stat = i;
+ return;
+}
diff --git a/trek/snova.c b/trek/snova.c
new file mode 100644
index 00000000..94426153
--- /dev/null
+++ b/trek/snova.c
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)snova.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** CAUSE SUPERNOVA TO OCCUR
+**
+** A supernova occurs. If 'ix' < 0, a random quadrant is chosen;
+** otherwise, the current quadrant is taken, and (ix, iy) give
+** the sector quadrants of the star which is blowing up.
+**
+** If the supernova turns out to be in the quadrant you are in,
+** you go into "emergency override mode", which tries to get you
+** out of the quadrant as fast as possible. However, if you
+** don't have enough fuel, or if you by chance run into something,
+** or some such thing, you blow up anyway. Oh yeh, if you are
+** within two sectors of the star, there is nothing that can
+** be done for you.
+**
+** When a star has gone supernova, the quadrant becomes uninhab-
+** itable for the rest of eternity, i.e., the game. If you ever
+** try stopping in such a quadrant, you will go into emergency
+** override mode.
+*/
+
+snova(x, y)
+int x, y;
+{
+ int qx, qy;
+ register int ix, iy;
+ int f;
+ int dx, dy;
+ int n;
+ register struct quad *q;
+
+ f = 0;
+ ix = x;
+ if (ix < 0)
+ {
+ /* choose a quadrant */
+ while (1)
+ {
+ qx = ranf(NQUADS);
+ qy = ranf(NQUADS);
+ q = &Quad[qx][qy];
+ if (q->stars > 0)
+ break;
+ }
+ if (Ship.quadx == qx && Ship.quady == qy)
+ {
+ /* select a particular star */
+ n = ranf(q->stars);
+ for (ix = 0; ix < NSECTS; ix++)
+ {
+ for (iy = 0; iy < NSECTS; iy++)
+ if (Sect[ix][iy] == STAR || Sect[ix][iy] == INHABIT)
+ if ((n -= 1) <= 0)
+ break;
+ if (n <= 0)
+ break;
+ }
+ f = 1;
+ }
+ }
+ else
+ {
+ /* current quadrant */
+ iy = y;
+ qx = Ship.quadx;
+ qy = Ship.quady;
+ q = &Quad[qx][qy];
+ f = 1;
+ }
+ if (f)
+ {
+ /* supernova is in same quadrant as Enterprise */
+ printf("\nRED ALERT: supernova occuring at %d,%d\n", ix, iy);
+ dx = ix - Ship.sectx;
+ dy = iy - Ship.secty;
+ if (dx * dx + dy * dy <= 2)
+ {
+ printf("*** Emergency override attem");
+ sleep(1);
+ printf("\n");
+ lose(L_SNOVA);
+ }
+ q->scanned = 1000;
+ }
+ else
+ {
+ if (!damaged(SSRADIO))
+ {
+ q->scanned = 1000;
+ printf("\nUhura: Captain, Starfleet Command reports a supernova\n");
+ printf(" in quadrant %d,%d. Caution is advised\n", qx, qy);
+ }
+ }
+
+ /* clear out the supernova'ed quadrant */
+ dx = q->klings;
+ dy = q->stars;
+ Now.klings -= dx;
+ if (x >= 0)
+ {
+ /* Enterprise caused supernova */
+ Game.kills += dy;
+ if (q->bases)
+ killb(qx, qy, -1);
+ Game.killk += dx;
+ }
+ else
+ if (q->bases)
+ killb(qx, qy, 0);
+ killd(qx, qy, (x >= 0));
+ q->stars = -1;
+ q->klings = 0;
+ if (Now.klings <= 0)
+ {
+ printf("Lucky devil, that supernova destroyed the last klingon\n");
+ win();
+ }
+ return;
+}
diff --git a/trek/srscan.c b/trek/srscan.c
new file mode 100644
index 00000000..46803a27
--- /dev/null
+++ b/trek/srscan.c
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)srscan.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+
+/*
+** SHORT RANGE SENSOR SCAN
+**
+** A short range scan is taken of the current quadrant. If the
+** flag 'f' is one, it is an "auto srscan", which is not done
+** unless in 'fast' mode. It does a status report and a srscan.
+** If 'f' is -1, you get a status report only. If it is zero,
+** you get a srscan and an optional status report. The status
+** report is taken if you enter "srscan yes"; for all srscans
+** thereafter you get a status report with your srscan until
+** you type "srscan no". It defaults to on.
+**
+** The current quadrant is filled in on the computer chart.
+*/
+
+char *Color[4] =
+{
+ "GREEN",
+ "DOCKED",
+ "YELLOW",
+ "RED"
+};
+
+srscan(f)
+int f;
+{
+ register int i, j;
+ register int statinfo;
+ char *s;
+ int percent;
+ struct quad *q;
+ extern struct cvntab Skitab[];
+ extern struct cvntab Lentab[];
+ struct cvntab *p;
+
+ if (f >= 0 && check_out(SRSCAN))
+ {
+ return;
+ }
+ if (f)
+ statinfo = 1;
+ else
+ {
+ if (!testnl())
+ Etc.statreport = getynpar("status report");
+ statinfo = Etc.statreport;
+ }
+ if (f > 0)
+ {
+ Etc.statreport = 1;
+ if (!Etc.fast)
+ return;
+ }
+ if (f >= 0)
+ {
+ printf("\nShort range sensor scan\n");
+ q = &Quad[Ship.quadx][Ship.quady];
+ q->scanned = q->klings * 100 + q->bases * 10 + q->stars;
+ printf(" ");
+ for (i = 0; i < NSECTS; i++)
+ {
+ printf("%d ", i);
+ }
+ printf("\n");
+ }
+
+ for (i = 0; i < NSECTS; i++)
+ {
+ if (f >= 0)
+ {
+ printf("%d ", i);
+ for (j = 0; j < NSECTS; j++)
+ printf("%c ", Sect[i][j]);
+ printf("%d", i);
+ if (statinfo)
+ printf(" ");
+ }
+ if (statinfo)
+ switch (i)
+ {
+ case 0:
+ printf("stardate %.2f", Now.date);
+ break;
+ case 1:
+ printf("condition %s", Color[Ship.cond]);
+ if (Ship.cloaked)
+ printf(", CLOAKED");
+ break;
+ case 2:
+ printf("position %d,%d/%d,%d",Ship.quadx, Ship.quady, Ship.sectx, Ship.secty);
+ break;
+ case 3:
+ printf("warp factor %.1f", Ship.warp);
+ break;
+ case 4:
+ printf("total energy %d", Ship.energy);
+ break;
+ case 5:
+ printf("torpedoes %d", Ship.torped);
+ break;
+ case 6:
+ s = "down";
+ if (Ship.shldup)
+ s = "up";
+ if (damaged(SHIELD))
+ s = "damaged";
+ percent = 100.0 * Ship.shield / Param.shield;
+ printf("shields %s, %d%%", s, percent);
+ break;
+ case 7:
+ printf("Klingons left %d", Now.klings);
+ break;
+ case 8:
+ printf("time left %.2f", Now.time);
+ break;
+ case 9:
+ printf("life support ");
+ if (damaged(LIFESUP))
+ {
+ printf("damaged, reserves = %.2f", Ship.reserves);
+ break;
+ }
+ printf("active");
+ break;
+ }
+ printf("\n");
+ }
+ if (f < 0)
+ {
+ printf("current crew %d\n", Ship.crew);
+ printf("brig space %d\n", Ship.brigfree);
+ printf("Klingon power %d\n", Param.klingpwr);
+ p = &Lentab[Game.length - 1];
+ if (Game.length > 2)
+ p--;
+ printf("Length, Skill %s%s, ", p->abrev, p->full);
+ p = &Skitab[Game.skill - 1];
+ printf("%s%s\n", p->abrev, p->full);
+ return;
+ }
+ printf(" ");
+ for (i = 0; i < NSECTS; i++)
+ printf("%d ", i);
+ printf("\n");
+
+ if (q->qsystemname & Q_DISTRESSED)
+ printf("Distressed ");
+ if (q->qsystemname)
+ printf("Starsystem %s\n", systemname(q));
+}
diff --git a/trek/systemname.c b/trek/systemname.c
new file mode 100644
index 00000000..de16077a
--- /dev/null
+++ b/trek/systemname.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)systemname.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** RETRIEVE THE STARSYSTEM NAME
+**
+** Very straightforward, this routine just gets the starsystem
+** name. It returns zero if none in the specified quadrant
+** (which, by the way, is passed it).
+**
+** This routine knows all about such things as distressed
+** starsystems, etc.
+*/
+
+char *systemname(q1)
+struct quad *q1;
+{
+ register struct quad *q;
+ register int i;
+
+ q = q1;
+
+ i = q->qsystemname;
+ if (i & Q_DISTRESSED)
+ i = Event[i & Q_SYSTEM].systemname;
+
+ i &= Q_SYSTEM;
+ if (i == 0)
+ return (0);
+ return (Systemname[i]);
+}
diff --git a/trek/torped.c b/trek/torped.c
new file mode 100644
index 00000000..5e42d309
--- /dev/null
+++ b/trek/torped.c
@@ -0,0 +1,247 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)torped.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include <stdio.h>
+# include "trek.h"
+
+/*
+** PHOTON TORPEDO CONTROL
+**
+** Either one or three photon torpedoes are fired. If three
+** are fired, it is called a "burst" and you also specify
+** a spread angle.
+**
+** Torpedoes are never 100% accurate. There is always a random
+** cludge factor in their course which is increased if you have
+** your shields up. Hence, you will find that they are more
+** accurate at close range. However, they have the advantage that
+** at long range they don't lose any of their power as phasers
+** do, i.e., a hit is a hit is a hit, by any other name.
+**
+** When the course spreads too much, you get a misfire, and the
+** course is randomized even more. You also have the chance that
+** the misfire damages your torpedo tubes.
+*/
+
+
+torped()
+{
+ register int ix, iy;
+ double x, y, dx, dy;
+ double angle;
+ int course, course2;
+ register int k;
+ double bigger;
+ double sectsize;
+ int burst;
+ int n;
+
+ if (Ship.cloaked)
+ {
+ return (printf("Federation regulations do not permit attack while cloaked.\n"));
+ }
+ if (check_out(TORPED))
+ return;
+ if (Ship.torped <= 0)
+ {
+ return (printf("All photon torpedos expended\n"));
+ }
+
+ /* get the course */
+ course = getintpar("Torpedo course");
+ if (course < 0 || course > 360)
+ return;
+ burst = -1;
+
+ /* need at least three torpedoes for a burst */
+ if (Ship.torped < 3)
+ {
+ printf("No-burst mode selected\n");
+ burst = 0;
+ }
+ else
+ {
+ /* see if the user wants one */
+ if (!testnl())
+ {
+ k = ungetc(cgetc(0), stdin);
+ if (k >= '0' && k <= '9')
+ burst = 1;
+ }
+ }
+ if (burst < 0)
+ {
+ burst = getynpar("Do you want a burst");
+ }
+ if (burst)
+ {
+ burst = getintpar("burst angle");
+ if (burst <= 0)
+ return;
+ if (burst > 15)
+ return (printf("Maximum burst angle is 15 degrees\n"));
+ }
+ sectsize = NSECTS;
+ n = -1;
+ if (burst)
+ {
+ n = 1;
+ course -= burst;
+ }
+ for (; n && n <= 3; n++)
+ {
+ /* select a nice random course */
+ course2 = course + randcourse(n);
+ angle = course2 * 0.0174532925; /* convert to radians */
+ dx = -cos(angle);
+ dy = sin(angle);
+ bigger = fabs(dx);
+ x = fabs(dy);
+ if (x > bigger)
+ bigger = x;
+ dx /= bigger;
+ dy /= bigger;
+ x = Ship.sectx + 0.5;
+ y = Ship.secty + 0.5;
+ if (Ship.cond != DOCKED)
+ Ship.torped -= 1;
+ printf("Torpedo track");
+ if (n > 0)
+ printf(", torpedo number %d", n);
+ printf(":\n%6.1f\t%4.1f\n", x, y);
+ while (1)
+ {
+ ix = x += dx;
+ iy = y += dy;
+ if (x < 0.0 || x >= sectsize || y < 0.0 || y >= sectsize)
+ {
+ printf("Torpedo missed\n");
+ break;
+ }
+ printf("%6.1f\t%4.1f\n", x, y);
+ switch (Sect[ix][iy])
+ {
+ case EMPTY:
+ continue;
+
+ case HOLE:
+ printf("Torpedo disappears into a black hole\n");
+ break;
+
+ case KLINGON:
+ for (k = 0; k < Etc.nkling; k++)
+ {
+ if (Etc.klingon[k].x != ix || Etc.klingon[k].y != iy)
+ continue;
+ Etc.klingon[k].power -= 500 + ranf(501);
+ if (Etc.klingon[k].power > 0)
+ {
+ printf("*** Hit on Klingon at %d,%d: extensive damages\n",
+ ix, iy);
+ break;
+ }
+ killk(ix, iy);
+ break;
+ }
+ break;
+
+ case STAR:
+ nova(ix, iy);
+ break;
+
+ case INHABIT:
+ kills(ix, iy, -1);
+ break;
+
+ case BASE:
+ killb(Ship.quadx, Ship.quady);
+ Game.killb += 1;
+ break;
+ default:
+ printf("Unknown object %c at %d,%d destroyed\n",
+ Sect[ix][iy], ix, iy);
+ Sect[ix][iy] = EMPTY;
+ break;
+ }
+ break;
+ }
+ if (damaged(TORPED) || Quad[Ship.quadx][Ship.quady].stars < 0)
+ break;
+ course += burst;
+ }
+ Move.free = 0;
+}
+
+
+/*
+** RANDOMIZE COURSE
+**
+** This routine randomizes the course for torpedo number 'n'.
+** Other things handled by this routine are misfires, damages
+** to the tubes, etc.
+*/
+
+randcourse(n)
+int n;
+{
+ double r;
+ register int d;
+
+ d = ((franf() + franf()) - 1.0) * 20;
+ if (abs(d) > 12)
+ {
+ printf("Photon tubes misfire");
+ if (n < 0)
+ printf("\n");
+ else
+ printf(" on torpedo %d\n", n);
+ if (ranf(2))
+ {
+ damage(TORPED, 0.2 * abs(d) * (franf() + 1.0));
+ }
+ d *= 1.0 + 2.0 * franf();
+ }
+ if (Ship.shldup || Ship.cond == DOCKED)
+ {
+ r = Ship.shield;
+ r = 1.0 + r / Param.shield;
+ if (Ship.cond == DOCKED)
+ r = 2.0;
+ d *= r;
+ }
+ return (d);
+}
diff --git a/trek/trek.6 b/trek/trek.6
new file mode 100644
index 00000000..07d950bd
--- /dev/null
+++ b/trek/trek.6
@@ -0,0 +1,90 @@
+.\" Copyright (c) 1980 The Regents of the University of California.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by the University of
+.\" California, Berkeley and its contributors.
+.\" 4. Neither the name of the University nor the names of its contributors
+.\" may be used to endorse or promote products derived from this software
+.\" without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" @(#)trek.6 6.3 (Berkeley) 6/23/90
+.\"
+.TH TREK 6 "June 23, 1990"
+.UC 4
+.SH NAME
+trek \- trekkie game
+.SH SYNOPSIS
+.B /usr/games/trek
+[ [
+.B \-a
+] file ]
+.SH DESCRIPTION
+.I Trek
+is a game of space glory and war. Below is a summary of commands.
+For complete documentation, see
+.IR Trek
+by Eric Allman.
+.PP
+If a filename is given, a log of the game is written onto that file.
+If the
+.B \-a
+flag is given before the filename, that file is appended to, not truncated.
+.PP
+The game will ask you what length game you would like.
+Valid responses are \*(lqshort\*(rq, \*(lqmedium\*(rq, and \*(lqlong\*(rq.
+You may also type \*(lqrestart\*(rq, which restarts a previously saved game.
+You will then be prompted for the skill, to which you must respond
+\*(lqnovice\*(rq, \*(lqfair\*(rq, \*(lqgood\*(rq, \*(lqexpert\*(rq,
+\*(lqcommadore\*(rq, or \*(lqimpossible\*(rq.
+You should normally start out with a novice and work up.
+.PP
+In general, throughout the game, if you forget what is appropriate
+the game will tell you what it expects if you just type in a question mark.
+.SH AUTHOR
+Eric Allman
+.SH "SEE ALSO"
+/usr/doc/trek
+.SH "COMMAND SUMMARY"
+.ie t .ds f \fB
+.el .ds f \fI
+.ta 3i
+.nf
+\*fabandon\fR \*fca\fRpture
+\*fcl\fRoak \*fu\fRp/\*fd\fRown
+\*fc\fRomputer request; ... \*fda\fRmages
+\*fdestruct\fR \*fdo\fRck
+\*fhelp\fR \*fi\fRmpulse course distance
+\*fl\fRrscan \*fm\fRove course distance
+\*fp\fRhasers \*fa\fRutomatic amount
+\*fp\fRhasers \*fm\fRanual amt1 course1 spread1 ...
+\*ft\fRorpedo course [\*fy\fRes] angle/\*fn\fRo
+\*fram\fR course distance \*fr\fRest time
+\*fshell\fR \*fsh\fRields \*fu\fRp/\*fd\fRown
+\*fs\fRrscan [\*fy\fRes/\*fn\fRo]
+\*fst\fRatus \*fterminate\fR \*fy\fRes/\*fn\fRo
+\*fu\fRndock \*fv\fRisual course
+\*fw\fRarp warp_factor
+.fi
+.DT
diff --git a/trek/trek.h b/trek/trek.h
new file mode 100644
index 00000000..b798d0a1
--- /dev/null
+++ b/trek/trek.h
@@ -0,0 +1,380 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)trek.h 5.5 (Berkeley) 6/1/90
+ */
+
+/*
+** Global Declarations
+**
+** Virtually all non-local variable declarations are made in this
+** file. Exceptions are those things which are initialized, which
+** are defined in "externs.c", and things which are local to one
+** program file.
+**
+** So far as I know, nothing in here must be preinitialized to
+** zero.
+**
+** You may have problems from the loader if you move this to a
+** different machine. These things actually get allocated in each
+** source file, which UNIX allows; however, you may (on other
+** systems) have to change everything in here to be "extern" and
+** actually allocate stuff in "externs.c"
+*/
+
+/* external function definitions */
+extern double franf(); /* floating random number function */
+extern double sqrt(); /* square root */
+extern double sin(), cos(); /* trig functions */
+extern double atan2(); /* fancy arc tangent function */
+extern double log(); /* log base e */
+extern double pow(); /* power function */
+extern double fabs(); /* absolute value function */
+extern double exp(); /* exponential function */
+
+/********************* GALAXY **************************/
+
+/* galactic parameters */
+# define NSECTS 10 /* dimensions of quadrant in sectors */
+# define NQUADS 8 /* dimension of galazy in quadrants */
+# define NINHAB 32 /* number of quadrants which are inhabited */
+
+struct quad /* definition for each quadrant */
+{
+ char bases; /* number of bases in this quadrant */
+ char klings; /* number of Klingons in this quadrant */
+ char holes; /* number of black holes in this quadrant */
+ int scanned; /* star chart entry (see below) */
+ char stars; /* number of stars in this quadrant */
+ char qsystemname; /* starsystem name (see below) */
+};
+
+# define Q_DISTRESSED 0200
+# define Q_SYSTEM 077
+
+/* systemname conventions:
+ * 1 -> NINHAB index into Systemname table for live system.
+ * + Q_DISTRESSED distressed starsystem -- systemname & Q_SYSTEM
+ * is the index into the Event table which will
+ * have the system name
+ * 0 dead or nonexistent starsystem
+ *
+ * starchart ("scanned") conventions:
+ * 0 -> 999 taken as is
+ * -1 not yet scanned ("...")
+ * 1000 supernova ("///")
+ * 1001 starbase + ??? (".1.")
+*/
+
+/* ascii names of systems */
+extern char *Systemname[NINHAB];
+
+/* quadrant definition */
+struct quad Quad[NQUADS][NQUADS];
+
+/* defines for sector map (below) */
+# define EMPTY '.'
+# define STAR '*'
+# define BASE '#'
+# define ENTERPRISE 'E'
+# define QUEENE 'Q'
+# define KLINGON 'K'
+# define INHABIT '@'
+# define HOLE ' '
+
+/* current sector map */
+char Sect[NSECTS][NSECTS];
+
+
+/************************ DEVICES ******************************/
+
+# define NDEV 16 /* max number of devices */
+
+/* device tokens */
+# define WARP 0 /* warp engines */
+# define SRSCAN 1 /* short range scanners */
+# define LRSCAN 2 /* long range scanners */
+# define PHASER 3 /* phaser control */
+# define TORPED 4 /* photon torpedo control */
+# define IMPULSE 5 /* impulse engines */
+# define SHIELD 6 /* shield control */
+# define COMPUTER 7 /* on board computer */
+# define SSRADIO 8 /* subspace radio */
+# define LIFESUP 9 /* life support systems */
+# define SINS 10 /* Space Inertial Navigation System */
+# define CLOAK 11 /* cloaking device */
+# define XPORTER 12 /* transporter */
+# define SHUTTLE 13 /* shuttlecraft */
+
+/* device names */
+struct device
+{
+ char *name; /* device name */
+ char *person; /* the person who fixes it */
+};
+
+struct device Device[NDEV];
+
+/*************************** EVENTS ****************************/
+
+# define NEVENTS 12 /* number of different event types */
+
+# define E_LRTB 1 /* long range tractor beam */
+# define E_KATSB 2 /* Klingon attacks starbase */
+# define E_KDESB 3 /* Klingon destroys starbase */
+# define E_ISSUE 4 /* distress call is issued */
+# define E_ENSLV 5 /* Klingons enslave a quadrant */
+# define E_REPRO 6 /* a Klingon is reproduced */
+# define E_FIXDV 7 /* fix a device */
+# define E_ATTACK 8 /* Klingon attack during rest period */
+# define E_SNAP 9 /* take a snapshot for time warp */
+# define E_SNOVA 10 /* supernova occurs */
+
+# define E_GHOST 0100 /* ghost of a distress call if ssradio out */
+# define E_HIDDEN 0200 /* event that is unreportable because ssradio out */
+# define E_EVENT 077 /* mask to get event code */
+
+struct event
+{
+ char x, y; /* coordinates */
+ double date; /* trap stardate */
+ char evcode; /* event type */
+ char systemname; /* starsystem name */
+};
+/* systemname conventions:
+ * 1 -> NINHAB index into Systemname table for reported distress calls
+ *
+ * evcode conventions:
+ * 1 -> NEVENTS-1 event type
+ * + E_HIDDEN unreported (SSradio out)
+ * + E_GHOST actually already expired
+ * 0 unallocated
+ */
+
+# define MAXEVENTS 25 /* max number of concurrently pending events */
+
+struct event Event[MAXEVENTS]; /* dynamic event list; one entry per pending event */
+
+/***************************** KLINGONS *******************************/
+
+struct kling
+{
+ char x, y; /* coordinates */
+ int power; /* power left */
+ double dist; /* distance to Enterprise */
+ double avgdist; /* average over this move */
+ char srndreq; /* set if surrender has been requested */
+};
+
+# define MAXKLQUAD 9 /* maximum klingons per quadrant */
+
+/********************** MISCELLANEOUS ***************************/
+
+/* condition codes */
+# define GREEN 0
+# define DOCKED 1
+# define YELLOW 2
+# define RED 3
+
+/* starbase coordinates */
+# define MAXBASES 9 /* maximum number of starbases in galaxy */
+
+/* distress calls */
+# define MAXDISTR 5 /* maximum concurrent distress calls */
+
+/* phaser banks */
+# define NBANKS 6 /* number of phaser banks */
+
+struct xy
+{
+ char x, y; /* coordinates */
+};
+
+
+/*
+ * note that much of the stuff in the following structs CAN NOT
+ * be moved around!!!!
+ */
+
+
+/* information regarding the state of the starship */
+struct
+{
+ double warp; /* warp factor */
+ double warp2; /* warp factor squared */
+ double warp3; /* warp factor cubed */
+ char shldup; /* shield up flag */
+ char cloaked; /* set if cloaking device on */
+ int energy; /* starship's energy */
+ int shield; /* energy in shields */
+ double reserves; /* life support reserves */
+ int crew; /* ship's complement */
+ int brigfree; /* space left in brig */
+ char torped; /* torpedoes */
+ char cloakgood; /* set if we have moved */
+ int quadx; /* quadrant x coord */
+ int quady; /* quadrant y coord */
+ int sectx; /* sector x coord */
+ int secty; /* sector y coord */
+ char cond; /* condition code */
+ char sinsbad; /* Space Inertial Navigation System condition */
+ char *shipname; /* name of current starship */
+ char ship; /* current starship */
+ int distressed; /* number of distress calls */
+} Ship;
+
+/* sinsbad is set if SINS is working but not calibrated */
+
+/* game related information, mostly scoring */
+struct
+{
+ int killk; /* number of klingons killed */
+ int deaths; /* number of deaths onboard Enterprise */
+ char negenbar; /* number of hits on negative energy barrier */
+ char killb; /* number of starbases killed */
+ int kills; /* number of stars killed */
+ char skill; /* skill rating of player */
+ char length; /* length of game */
+ char killed; /* set if you were killed */
+ char killinhab; /* number of inhabited starsystems killed */
+ char tourn; /* set if a tournament game */
+ char passwd[15]; /* game password */
+ char snap; /* set if snapshot taken */
+ char helps; /* number of help calls */
+ int captives; /* total number of captives taken */
+} Game;
+
+/* per move information */
+struct
+{
+ char free; /* set if a move is free */
+ char endgame; /* end of game flag */
+ char shldchg; /* set if shields changed this move */
+ char newquad; /* set if just entered this quadrant */
+ char resting; /* set if this move is a rest */
+ double time; /* time used this move */
+} Move;
+
+/* parametric information */
+struct
+{
+ char bases; /* number of starbases */
+ char klings; /* number of klingons */
+ double date; /* stardate */
+ double time; /* time left */
+ double resource; /* Federation resources */
+ int energy; /* starship's energy */
+ int shield; /* energy in shields */
+ double reserves; /* life support reserves */
+ int crew; /* size of ship's complement */
+ int brigfree; /* max possible number of captives */
+ char torped; /* photon torpedos */
+ double damfac[NDEV]; /* damage factor */
+ double dockfac; /* docked repair time factor */
+ double regenfac; /* regeneration factor */
+ int stopengy; /* energy to do emergency stop */
+ int shupengy; /* energy to put up shields */
+ int klingpwr; /* Klingon initial power */
+ int warptime; /* time chewer multiplier */
+ double phasfac; /* Klingon phaser power eater factor */
+ char moveprob[6]; /* probability that a Klingon moves */
+ double movefac[6]; /* Klingon move distance multiplier */
+ double eventdly[NEVENTS]; /* event time multipliers */
+ double navigcrud[2]; /* navigation crudup factor */
+ int cloakenergy; /* cloaking device energy per stardate */
+ double damprob[NDEV]; /* damage probability */
+ double hitfac; /* Klingon attack factor */
+ int klingcrew; /* number of Klingons in a crew */
+ double srndrprob; /* surrender probability */
+ int energylow; /* low energy mark (cond YELLOW) */
+} Param;
+
+/* Sum of damage probabilities must add to 1000 */
+
+/* other information kept in a snapshot */
+struct
+{
+ char bases; /* number of starbases */
+ char klings; /* number of klingons */
+ double date; /* stardate */
+ double time; /* time left */
+ double resource; /* Federation resources */
+ char distressed; /* number of currently distressed quadrants */
+ struct event *eventptr[NEVENTS]; /* pointer to event structs */
+ struct xy base[MAXBASES]; /* locations of starbases */
+} Now;
+
+/* Other stuff, not dumped in a snapshot */
+struct
+{
+ struct kling klingon[MAXKLQUAD]; /* sorted Klingon list */
+ char nkling; /* number of Klingons in this sector */
+ /* < 0 means automatic override mode */
+ char fast; /* set if speed > 300 baud */
+ struct xy starbase; /* starbase in current quadrant */
+ char snapshot[sizeof Quad + sizeof Event + sizeof Now]; /* snapshot for time warp */
+ char statreport; /* set to get a status report on a srscan */
+} Etc;
+
+/*
+ * eventptr is a pointer to the event[] entry of the last
+ * scheduled event of each type. Zero if no such event scheduled.
+ */
+
+/* Klingon move indicies */
+# define KM_OB 0 /* Old quadrant, Before attack */
+# define KM_OA 1 /* Old quadrant, After attack */
+# define KM_EB 2 /* Enter quadrant, Before attack */
+# define KM_EA 3 /* Enter quadrant, After attack */
+# define KM_LB 4 /* Leave quadrant, Before attack */
+# define KM_LA 5 /* Leave quadrant, After attack */
+
+/* you lose codes */
+# define L_NOTIME 1 /* ran out of time */
+# define L_NOENGY 2 /* ran out of energy */
+# define L_DSTRYD 3 /* destroyed by a Klingon */
+# define L_NEGENB 4 /* ran into the negative energy barrier */
+# define L_SUICID 5 /* destroyed in a nova */
+# define L_SNOVA 6 /* destroyed in a supernova */
+# define L_NOLIFE 7 /* life support died (so did you) */
+# define L_NOHELP 8 /* you could not be rematerialized */
+# define L_TOOFAST 9 /* pretty stupid going at warp 10 */
+# define L_STAR 10 /* ran into a star */
+# define L_DSTRCT 11 /* self destructed */
+# define L_CAPTURED 12 /* captured by Klingons */
+# define L_NOCREW 13 /* you ran out of crew */
+
+/****************** COMPILE OPTIONS ***********************/
+
+/* Trace info */
+# define xTRACE 1
+int Trace;
diff --git a/trek/utility.c b/trek/utility.c
new file mode 100644
index 00000000..b44e8acf
--- /dev/null
+++ b/trek/utility.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)utility.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+/*
+** ASSORTED UTILITY ROUTINES
+*/
+
+/*
+** BLOCK MOVE
+**
+** Moves a block of storage of length `l' bytes from the data
+** area pointed to by `a' to the area pointed to by `b'.
+** Returns the address of the byte following the `b' field.
+** Overflow of `b' is not tested.
+*/
+
+char *bmove(a, b, l)
+char *a, *b;
+int l;
+{
+ register int n;
+ register char *p, *q;
+
+ p = a;
+ q = b;
+ n = l;
+ while (n--)
+ *q++ = *p++;
+ return (q);
+}
+
+
+/*
+** STRING EQUALITY TEST
+** null-terminated strings `a' and `b' are tested for
+** absolute equality.
+** returns one if equal, zero otherwise.
+*/
+
+sequal(a, b)
+char *a, *b;
+{
+ register char *p, *q;
+
+ p = a;
+ q = b;
+ while (*p || *q)
+ if (*p++ != *q++)
+ return(0);
+ return(1);
+}
+
+
+/*
+** STRING CONCATENATE
+**
+** The strings `s1' and `s2' are concatenated and stored into
+** `s3'. It is ok for `s1' to equal `s3', but terrible things
+** will happen if `s2' equals `s3'. The return value is is a
+** pointer to the end of `s3' field.
+*/
+
+char *concat(s1, s2, s3)
+char *s1, *s2, *s3;
+{
+ register char *p;
+ register char *q;
+
+ p = s3;
+ q = s1;
+ while (*q)
+ *p++ = *q++;
+ q = s2;
+ while (*q)
+ *p++ = *q++;
+ *p = 0;
+ return (p);
+}
+
+
+/*
+** FIND STRING LENGTH
+**
+** The length of string `s' (excluding the null byte which
+** terminates the string) is returned.
+*/
+
+length(s)
+char *s;
+{
+ register int l;
+ register char *p;
+
+ l = 0;
+ p = s;
+ while (*p++)
+ l++;
+ return(l);
+}
+
+
+/*
+** SYSTEM ERROR
+*/
+
+syserr(p0, p1, p2, p3, p4, p5)
+{
+ extern int errno;
+
+ printf("\n\07TREK SYSERR: ");
+ printf(p0, p1, p2, p3, p4, p5);
+ printf("\n");
+ if (errno)
+ printf("\tsystem error %d\n", errno);
+ exit(-1);
+}
diff --git a/trek/visual.c b/trek/visual.c
new file mode 100644
index 00000000..a4f06c07
--- /dev/null
+++ b/trek/visual.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)visual.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** VISUAL SCAN
+**
+** A visual scan is made in a particular direction of three sectors
+** in the general direction specified. This takes time, and
+** Klingons can attack you, so it should be done only when sensors
+** are out.
+*/
+
+/* This struct[] has the delta x, delta y for particular directions */
+struct xy Visdelta[11] =
+{
+ -1, -1,
+ -1, 0,
+ -1, 1,
+ 0, 1,
+ 1, 1,
+ 1, 0,
+ 1, -1,
+ 0, -1,
+ -1, -1,
+ -1, 0,
+ -1, 1
+};
+
+visual()
+{
+ register int ix, iy;
+ int co;
+ register struct xy *v;
+
+ co = getintpar("direction");
+ if (co < 0 || co > 360)
+ return;
+ co = (co + 22) / 45;
+ v = &Visdelta[co];
+ ix = Ship.sectx + v->x;
+ iy = Ship.secty + v->y;
+ if (ix < 0 || ix >= NSECTS || iy < 0 || iy >= NSECTS)
+ co = '?';
+ else
+ co = Sect[ix][iy];
+ printf("%d,%d %c ", ix, iy, co);
+ v++;
+ ix = Ship.sectx + v->x;
+ iy = Ship.secty + v->y;
+ if (ix < 0 || ix >= NSECTS || iy < 0 || iy >= NSECTS)
+ co = '?';
+ else
+ co = Sect[ix][iy];
+ printf("%c ", co);
+ v++;
+ ix = Ship.sectx + v->x;
+ iy = Ship.secty + v->y;
+ if (ix < 0 || ix >= NSECTS || iy < 0 || iy >= NSECTS)
+ co = '?';
+ else
+ co = Sect[ix][iy];
+ printf("%c %d,%d\n", co, ix, iy);
+ Move.time = 0.05;
+ Move.free = 0;
+}
diff --git a/trek/warp.c b/trek/warp.c
new file mode 100644
index 00000000..2fc4852a
--- /dev/null
+++ b/trek/warp.c
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)warp.c 5.4 (Berkeley) 6/1/90";
+#endif /* not lint */
+
+# include "trek.h"
+
+/*
+** MOVE UNDER WARP POWER
+**
+** This is both the "move" and the "ram" commands, differing
+** only in the flag 'fl'. It is also used for automatic
+** emergency override mode, when 'fl' is < 0 and 'c' and 'd'
+** are the course and distance to be moved. If 'fl' >= 0,
+** the course and distance are asked of the captain.
+**
+** The guts of this routine are in the routine move(), which
+** is shared with impulse(). Also, the working part of this
+** routine is very small; the rest is to handle the slight chance
+** that you may be moving at some riduculous speed. In that
+** case, there is code to handle time warps, etc.
+*/
+
+warp(fl, c, d)
+int fl, c;
+double d;
+{
+ int course;
+ double power;
+ double dist;
+ double time;
+ double speed;
+ double frac;
+ register int percent;
+ register int i;
+ extern double move();
+
+ if (Ship.cond == DOCKED)
+ return (printf("%s is docked\n", Ship.shipname));
+ if (damaged(WARP))
+ {
+ return (out(WARP));
+ }
+ if (fl < 0)
+ {
+ course = c;
+ dist = d;
+ }
+ else
+ if (getcodi(&course, &dist))
+ return;
+
+ /* check to see that we are not using an absurd amount of power */
+ power = (dist + 0.05) * Ship.warp3;
+ percent = 100 * power / Ship.energy + 0.5;
+ if (percent >= 85)
+ {
+ printf("Scotty: That would consume %d%% of our remaining energy.\n",
+ percent);
+ if (!getynpar("Are you sure that is wise"))
+ return;
+ }
+
+ /* compute the speed we will move at, and the time it will take */
+ speed = Ship.warp2 / Param.warptime;
+ time = dist / speed;
+
+ /* check to see that that value is not ridiculous */
+ percent = 100 * time / Now.time + 0.5;
+ if (percent >= 85)
+ {
+ printf("Spock: That would take %d%% of our remaining time.\n",
+ percent);
+ if (!getynpar("Are you sure that is wise"))
+ return;
+ }
+
+ /* compute how far we will go if we get damages */
+ if (Ship.warp > 6.0 && ranf(100) < 20 + 15 * (Ship.warp - 6.0))
+ {
+ frac = franf();
+ dist *= frac;
+ time *= frac;
+ damage(WARP, (frac + 1.0) * Ship.warp * (franf() + 0.25) * 0.20);
+ }
+
+ /* do the move */
+ Move.time = move(fl, course, time, speed);
+
+ /* see how far we actually went, and decrement energy appropriately */
+ dist = Move.time * speed;
+ Ship.energy -= dist * Ship.warp3 * (Ship.shldup + 1);
+
+ /* test for bizarre events */
+ if (Ship.warp <= 9.0)
+ return;
+ printf("\n\n ___ Speed exceeding warp nine ___\n\n");
+ sleep(2);
+ printf("Ship's safety systems malfunction\n");
+ sleep(2);
+ printf("Crew experiencing extreme sensory distortion\n");
+ sleep(4);
+ if (ranf(100) >= 100 * dist)
+ {
+ return (printf("Equilibrium restored -- all systems normal\n"));
+ }
+
+ /* select a bizzare thing to happen to us */
+ percent = ranf(100);
+ if (percent < 70)
+ {
+ /* time warp */
+ if (percent < 35 || !Game.snap)
+ {
+ /* positive time warp */
+ time = (Ship.warp - 8.0) * dist * (franf() + 1.0);
+ Now.date += time;
+ printf("Positive time portal entered -- it is now Stardate %.2f\n",
+ Now.date);
+ for (i = 0; i < MAXEVENTS; i++)
+ {
+ percent = Event[i].evcode;
+ if (percent == E_FIXDV || percent == E_LRTB)
+ Event[i].date += time;
+ }
+ return;
+ }
+
+ /* s/he got lucky: a negative time portal */
+ time = Now.date;
+ i = (int) Etc.snapshot;
+ bmove(i, Quad, sizeof Quad);
+ bmove(i += sizeof Quad, Event, sizeof Event);
+ bmove(i += sizeof Event, &Now, sizeof Now);
+ printf("Negative time portal entered -- it is now Stardate %.2f\n",
+ Now.date);
+ for (i = 0; i < MAXEVENTS; i++)
+ if (Event[i].evcode == E_FIXDV)
+ reschedule(&Event[i], Event[i].date - time);
+ return;
+ }
+
+ /* test for just a lot of damage */
+ if (percent < 80)
+ lose(L_TOOFAST);
+ printf("Equilibrium restored -- extreme damage occured to ship systems\n");
+ for (i = 0; i < NDEV; i++)
+ damage(i, (3.0 * (franf() + franf()) + 1.0) * Param.damfac[i]);
+ Ship.shldup = 0;
+}
diff --git a/trek/win.c b/trek/win.c
new file mode 100644
index 00000000..dc1f7c64
--- /dev/null
+++ b/trek/win.c
@@ -0,0 +1,89 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)win.c 5.5 (Berkeley) 6/26/90";
+#endif /* not lint */
+
+# include "trek.h"
+# include "getpar.h"
+# include <setjmp.h>
+
+/*
+** Signal game won
+**
+** This routine prints out the win message, arranges to print out
+** your score, tells you if you have a promotion coming to you,
+** cleans up the current input line, and arranges to have you
+** asked whether or not you want another game (via the longjmp()
+** call).
+**
+** Pretty straightforward, although the promotion algorithm is
+** pretty off the wall.
+*/
+
+win()
+{
+ long s;
+ extern jmp_buf env;
+ extern long score();
+ extern struct cvntab Skitab[];
+ register struct cvntab *p;
+
+ sleep(1);
+ printf("\nCongratulations, you have saved the Federation\n");
+ Move.endgame = 1;
+
+ /* print and return the score */
+ s = score();
+
+ /* decide if she gets a promotion */
+ if (Game.helps == 0 && Game.killb == 0 && Game.killinhab == 0 && 5 * Game.kills + Game.deaths < 100 &&
+ s >= 1000 && Ship.ship == ENTERPRISE)
+ {
+ printf("In fact, you are promoted one step in rank,\n");
+ if (Game.skill >= 6)
+ printf("to the exalted rank of Commodore Emeritus\n");
+ else
+ {
+ p = &Skitab[Game.skill - 1];
+ printf("from %s%s ", p->abrev, p->full);
+ p++;
+ printf("to %s%s\n", p->abrev, p->full);
+ }
+ }
+
+ /* clean out input, and request new game */
+ skiptonl(0);
+ longjmp(env, 1);
+}