Initial revision

git-svn-id: file:///srv/svn/joey/bsdgames-trunk@5086 a4a2c43b-8ac3-0310-8836-e0e880c912e2
This commit is contained in:
joey
1999-09-08 23:56:51 +00:00
commit 03272d67da
623 changed files with 243457 additions and 0 deletions

252
trek/DOC/read_me.nr Normal file
View File

@@ -0,0 +1,252 @@
.\" $NetBSD: read_me.nr,v 1.2 1995/04/22 10:59:44 cgd Exp $
.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

10
trek/DOC/things Normal file
View File

@@ -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

896
trek/DOC/trekmanual.nr Normal file
View File

@@ -0,0 +1,896 @@
.\" $NetBSD: trekmanual.nr,v 1.2 1995/04/22 10:59:45 cgd Exp $
.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

23
trek/Makefile.bsd Normal file
View File

@@ -0,0 +1,23 @@
# $NetBSD: Makefile,v 1.10 1997/10/12 21:24:24 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
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 \
visual.c warp.c win.c cgetc.c
MAN= trek.6
DPADD= ${LIBM}
LDADD= -lm
HIDEGAME=hidegame
.if make(install)
SUBDIR+=USD.doc
.endif
.include <bsd.prog.mk>
.include <bsd.subdir.mk>

10
trek/Makefrag Normal file
View File

@@ -0,0 +1,10 @@
# Makefrag - makefile fragment for trek
trek_DIRS := $(GAMESDIR) $(MAN6DIR)
trek_all: trek/trek trek/trek.6
trek_install: trek_all
$(INSTALL_BINARY) trek/trek $(INSTALL_PREFIX)$(GAMESDIR)/trek
$(HIDE_GAME) trek
$(INSTALL_MANUAL) trek/trek.6

8
trek/README.linux Normal file
View File

@@ -0,0 +1,8 @@
1997-05-18
The full trek manual is in USD.doc/trek.me; this is not installed by
the Makefile. You may wish to install it somewhere; if you do,
remember to update the reference to /usr/doc/trek in the man page.
Joseph Myers
jsm28@cam.ac.uk

11
trek/USD.doc/Makefile.bsd Normal file
View File

@@ -0,0 +1,11 @@
# $NetBSD: Makefile,v 1.2 1995/04/22 10:59:48 cgd Exp $
# @(#)Makefile 8.1 (Berkeley) 6/8/93
DIR= usd/31.trek
SRCS= trek.me
MACROS= -me
paper.ps: ${SRCS}
${TBL} ${SRCS} | ${ROFF} > ${.TARGET}
.include <bsd.doc.mk>

72
trek/USD.doc/spell.ok Normal file
View File

@@ -0,0 +1,72 @@
Allman
Faire
Klingon
Klingons
L.R
Onboard
Queene
S.R
Spock
Starbase
Starbases
Stardate
Starsystem
TO:02:06:12
Torpedoes
Trek''USD:34
U.S.S
USD:34
XII
amt1
anual
arp
atus
ca
ck
cl
course1
da
dist
distresslist
ds
es
est
filename
fo
ft
hasers
ields
impcost
isual
lrscan
mages
mo
mov
mpulse
na
ndock
omputer
onboard
orpedo
ove
partway
pheff
pture
rscan
shuttlecraft
spread1
srscan
st
starbase
starbases
stardate
stardates
starsystem
starsystems
ta
torpedoes
trek.me
utomatic
warpcost
woops
x,y

969
trek/USD.doc/trek.me Normal file
View File

@@ -0,0 +1,969 @@
.\" $NetBSD: trek.me,v 1.2 1995/04/22 10:59:49 cgd Exp $
.\"
.\" Copyright (c) 1980, 1993
.\" 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.me 8.1 (Berkeley) 6/8/93
.\"
.if n .na
.de pp
. sp 2
. ti +5
..
.ie t .ds f \fB
.el .ds f \fI
.de he
' sp
' tl 'Star Trek''USD:31-%'
'sp 3
..
.oh 'Star Trek''USD:31-%'
.eh 'USD:31-%''Star Trek'
\" .wh 0 he
.de fo
' bp
..
.wh -3 fo
.sp 16
.ce 1000
.ie n \{\
. tr |
|****||||*****||||||*||||||****|
*||||||||||*|||||||*|*|||||*|||*
|***|||||||*||||||*****||||****|
||||*||||||*||||||*|||*||||*||*|
****|||||||*||||||*|||*||||*|||*
.sp 2
*****||||****|||||*****||||*|||*
||*||||||*|||*||||*||||||||*||*|
||*||||||****|||||***||||||***||
||*||||||*||*|||||*||||||||*||*|
||*||||||*|||*||||*****||||*|||*
.sp 2
. tr ||
by
.\}
.el \{\
. ps 24
. vs 28p
. ft B
STAR
TREK
. ps
. vs
. ft
. ft I
by
.f ft
.\}
Eric Allman
University of California
Berkeley
.ce 0
\".bp
.ce
\*fINTRODUCTION\fR
.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 ninety 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
\*fSTARTING UP THE GAME\fR
.pp
To request the game, issue the command
.sp
.ti +15
.ft B
/usr/games/trek
.ft
.sp
from the shell.
If a filename is supplied,
a log of the game is written onto that file.
(Otherwise, no
file is written.)
If the
``\fB\-a\fP'' flag is stated before the filename,
the log of the game is appended to the file.
.pp
The game will ask you what length game
you would like.
Valid responses are "short", "medium", and "long".
You may also type "restart",
which restarts a previously saved game.
Ideally,
the length of the game does not affect the difficulty,
but currently the shorter games tend to be harder than the longer ones.
.pp
You will then be prompted for the skill,
to which you must respond
"novice", "fair", "good", "expert",
"commodore", 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.
\".bp
.ce
\*fISSUING COMMANDS\fR
.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
.sp
.ie t \fB\\$1\fR
.el \{\
. ne 3
. nr l \\w'\\$1' -\\w'*'
. ds x ****
. **
\\*x
. br
* \\$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
\*fTHE COMMANDS\fR
.bl "Short Range Scan"
Mnemonic: srscan
Shortest Abbreviation: 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
.in +4
Short range sensor scan
.TS
le1 ce1 ce1 ce1 ce1 ce1 ce1 ce1 ce1 ce1 ce1 le3 l1 l.
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
.TE
Distressed Starsystem Marcus XII
.sp
.in +8
.ti -8
The cast of characters is as follows:
.nf
.ta \w'E 'u
E the hero
K the villain
# the starbase
* stars
@ inhabited starsystem
\&. empty space
a black hole
.in -12
.fi
.ev
.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
.ev 1
.in +12
Long range scan for quadrant 0,3
.sp
.ie t \{\
.TS
l1 c1 ce1 c1 ce1 c1 ce1 c0
l1 l s s s s s s s0
l1 c1 ce1 c1 ce1 c1 ce1 c0
l1 l s s s s s s s0.
2 3 4
_
! * ! * ! * !
_
.T&
l1 c1 re1 c1 re1 c1 re1 c0
l1 l s s s s s s s0
l1 c1 re1 c1 re1 c1 re1 c0
l1 l s s s s s s s0.
0 ! 108 ! 6 ! 19 !
_
1 ! 9 ! /// ! 8 !
_
.TE
.\}
.el \{\
.nf
2 3 4
-------------------
! * ! * ! * !
-------------------
0 ! 108 ! 6 ! 19 !
-------------------
1 ! 9 ! /// ! 8 !
-------------------
.fi
.\}
.ev
.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"
Mnemonic: 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 wherever
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 separating 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 receive 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 exit the shell
you will return to the game.
\".bp
.ce
\*fSCORING\fR
.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 1
\*fCOMMAND SUMMARY\fP
.TS
l l l.
Command Requires Consumes
\*fabandon\fR shuttlecraft, -
transporter
\*fca\fRpture subspace radio time
\*fcl\fRoak \*fu\fRp/\*fd\fRown cloaking device energy
\*fc\fRomputer request; ... computer -
\*fda\fRmages - -
\*fdestruct\fR computer -
\*fdo\fRck - -
\*fhelp\fR subspace radio -
\*fi\fRmpulse course distance impulse engines, time, energy
computer, SINS
\*fl\fRrscan L.R. sensors -
\*fm\fRove course distance warp engines, time, energy
computer, SINS
\*fp\fRhasers \*fa\fRutomatic amount phasers, computer energy \*fp\fRhasers \*fm\fRanual
\ \ amt1 course1 spread1 ... phasers energy
\*ft\fRorpedo course [\*fy\fRes] angle/\*fn\fRo torpedo tubes torpedoes
\*fram\fR course distance warp engines, time, energy
computer, SINS
\*fr\fRest time - time
\*fshell\fR - -
\*fsh\fRields \*fu\fRp/\*fd\fRown shields energy
\*fs\fRrscan [\*fy\fRes/\*fn\fRo] S.R. sensors -
\*fst\fRatus - -
\*fterminate\fR \*fy\fRes/\*fn\fRo - -
\*fu\fRndock - -
\*fv\fRisual course - time
\*fw\fRarp warp_factor - -
.TE

172
trek/abandon.c Normal file
View File

@@ -0,0 +1,172 @@
/* $NetBSD: abandon.c,v 1.4 1997/10/12 21:24:25 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)abandon.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: abandon.c,v 1.4 1997/10/12 21:24:25 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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
*/
/*ARGSUSED*/
void
abandon(v)
int v __attribute__((unused));
{
struct quad *q;
int i;
int j;
struct event *e;
if (Ship.ship == QUEENE) {
printf("You may not abandon ye Faire Queene\n");
return;
}
if (Ship.cond != DOCKED)
{
if (damaged(SHUTTLE)) {
out(SHUTTLE);
return;
}
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(0);
compkldist(0);
return;
}
}
}
}

198
trek/attack.c Normal file
View File

@@ -0,0 +1,198 @@
/* $NetBSD: attack.c,v 1.4 1997/10/12 21:24:26 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)attack.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: attack.c,v 1.4 1997/10/12 21:24:26 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#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.
*/
void
attack(resting)
int resting; /* set if attack while resting */
{
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;
}

86
trek/autover.c Normal file
View File

@@ -0,0 +1,86 @@
/* $NetBSD: autover.c,v 1.4 1997/10/12 21:24:27 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)autover.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: autover.c,v 1.4 1997/10/12 21:24:27 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
void
autover()
{
double dist;
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);
}

140
trek/capture.c Normal file
View File

@@ -0,0 +1,140 @@
/* $NetBSD: capture.c,v 1.4 1997/10/12 21:24:29 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)capture.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: capture.c,v 1.4 1997/10/12 21:24:29 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
/*ARGSUSED*/
void
capture(v)
int v __attribute__((unused));
{
int i;
struct kling *k;
double x;
/* check for not cloaked */
if (Ship.cloaked)
{
printf("Ship-ship communications out when cloaked\n");
return;
}
if (damaged(SSRADIO)) {
out(SSRADIO);
return;
}
/* 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()
{
int i;
if (Etc.nkling < 2)
i = 0;
else
i = ranf(Etc.nkling);
return (&Etc.klingon[i]);
}

52
trek/cgetc.c Normal file
View File

@@ -0,0 +1,52 @@
/* $NetBSD: cgetc.c,v 1.4 1997/10/12 21:24:30 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cgetc.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: cgetc.c,v 1.4 1997/10/12 21:24:30 christos Exp $");
#endif
#endif /* not lint */
# include <stdio.h>
# include "trek.h"
char cgetc(i)
int i __attribute__((unused));
{
return ( getchar() );
}

79
trek/check_out.c Normal file
View File

@@ -0,0 +1,79 @@
/* $NetBSD: check_out.c,v 1.4 1997/10/12 21:24:31 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)check_out.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: check_out.c,v 1.4 1997/10/12 21:24:31 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
int
check_out(device)
int device;
{
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);
}

110
trek/checkcond.c Normal file
View File

@@ -0,0 +1,110 @@
/* $NetBSD: checkcond.c,v 1.4 1997/10/12 21:24:32 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)checkcond.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: checkcond.c,v 1.4 1997/10/12 21:24:32 christos Exp $");
#endif
#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.
*/
void
checkcond()
{
/* 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;
}

124
trek/compkl.c Normal file
View File

@@ -0,0 +1,124 @@
/* $NetBSD: compkl.c,v 1.4 1997/10/12 21:24:33 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)compkl.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: compkl.c,v 1.4 1997/10/12 21:24:33 christos Exp $");
#endif
#endif /* not lint */
#include <math.h>
#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.
*/
static void sortkl __P((void));
void
compkldist(f)
int f; /* set if new quadrant */
{
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
*/
static void
sortkl()
{
struct kling t;
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)
{
t = Etc.klingon[i];
Etc.klingon[i] = Etc.klingon[i+1];
Etc.klingon[i+1] = t;
f = 1;
}
}
}

358
trek/computer.c Normal file
View File

@@ -0,0 +1,358 @@
/* $NetBSD: computer.c,v 1.5 1997/10/12 21:24:34 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)computer.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: computer.c,v 1.5 1997/10/12 21:24:34 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#include "trek.h"
#include "getpar.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", (cmdfun)1, 0 },
{ "t", "rajectory", (cmdfun)2, 0 },
{ "c", "ourse", (cmdfun)3, 0 },
{ "m", "ove", (cmdfun)3, 1 },
{ "s", "core", (cmdfun)4, 0 },
{ "p", "heff", (cmdfun)5, 0 },
{ "w", "arpcost", (cmdfun)6, 0 },
{ "i", "mpcost", (cmdfun)7, 0 },
{ "d", "istresslist", (cmdfun)8, 0 },
{ NULL, NULL, NULL, 0 }
};
static int kalc __P((int, int, int, int, double *));
static void prkalc __P((int, double));
/*ARGSUSED*/
void
computer(v)
int v __attribute__((unused));
{
int ix, iy;
int i, j;
int tqx, tqy;
struct cvntab *r;
int cost;
int course;
double dist, time;
double warpfact;
struct quad *q;
struct event *e;
if (check_out(COMPUTER))
return;
while (1)
{
r = getcodpar("\nRequest", Cputab);
switch ((long)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.
*/
static int
kalc(tqx, tqy, tsx, tsy, dist)
int tqx;
int tqy;
int tsx;
int tsy;
double *dist;
{
double dx, dy;
double quadsize;
double angle;
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);
}
static void
prkalc(course, dist)
int course;
double dist;
{
printf(": course %d dist %.3f\n", course, dist);
}

101
trek/damage.c Normal file
View File

@@ -0,0 +1,101 @@
/* $NetBSD: damage.c,v 1.4 1997/10/12 21:24:36 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)damage.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: damage.c,v 1.4 1997/10/12 21:24:36 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <err.h>
#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.
*/
void
damage(dev1, dam)
int dev1; /* device index */
double dam; /* time to repair */
{
int i;
struct event *e;
int f;
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;
}
errx(1, "Cannot find old damages %d\n", dev);
}

75
trek/damaged.c Normal file
View File

@@ -0,0 +1,75 @@
/* $NetBSD: damaged.c,v 1.4 1997/10/12 21:24:37 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)damaged.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: damaged.c,v 1.4 1997/10/12 21:24:37 christos Exp $");
#endif
#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.
*/
int
damaged(dev)
int dev;
{
int d;
struct event *e;
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);
}

110
trek/dcrept.c Normal file
View File

@@ -0,0 +1,110 @@
/* $NetBSD: dcrept.c,v 1.4 1997/10/12 21:24:38 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dcrept.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dcrept.c,v 1.4 1997/10/12 21:24:38 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
/*ARGSUSED*/
void
dcrept(v)
int v __attribute__((unused));
{
int i, f;
double x;
double m1, m2;
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");
}

127
trek/destruct.c Normal file
View File

@@ -0,0 +1,127 @@
/* $NetBSD: destruct.c,v 1.4 1997/10/12 21:24:40 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)destruct.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: destruct.c,v 1.4 1997/10/12 21:24:40 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <unistd.h>
#include "trek.h"
#include "getpar.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
*/
/*ARGSUSED*/
void
destruct(v)
int v __attribute__((unused));
{
char checkpass[15];
int i, j;
double zap;
if (damaged(COMPUTER)) {
out(COMPUTER);
return;
}
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 (strcmp(checkpass, Game.passwd) != 0) {
printf("Self destruct sequence aborted\n");
return;
}
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);
}

162
trek/dock.c Normal file
View File

@@ -0,0 +1,162 @@
/* $NetBSD: dock.c,v 1.4 1997/10/12 21:24:41 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dock.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dock.c,v 1.4 1997/10/12 21:24:41 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
/*ARGSUSED*/
void
dock(v)
int v __attribute__((unused));
{
int i, j;
int ok;
struct event *e;
if (Ship.cond == DOCKED) {
printf("Chekov: But captain, we are already docked\n");
return;
}
/* 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) {
printf("Chekov: But captain, we are not adjacent to a starbase.\n");
return;
}
/* 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.
*/
/*ARGSUSED*/
void
undock(v)
int v __attribute__((unused));
{
struct event *e;
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;
}

181
trek/dumpgame.c Normal file
View File

@@ -0,0 +1,181 @@
/* $NetBSD: dumpgame.c,v 1.6 1998/09/11 14:26:19 hubertf Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dumpgame.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dumpgame.c,v 1.6 1998/09/11 14:26:19 hubertf Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <err.h>
#include <unistd.h>
#include <fcntl.h>
#include "trek.h"
/*** THIS CONSTANT MUST CHANGE AS THE DATA SPACES CHANGE ***/
# define VERSION 2
struct dump
{
char *area;
int count;
};
static int readdump __P((int));
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) },
{ NULL, 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.
*/
/*ARGSUSED*/
void
dumpgame(v)
int v __attribute__((unused));
{
int version;
int fd;
struct dump *d;
int i;
if ((fd = creat("trek.dump", 0644)) < 0) {
warn("cannot open `trek.dump'");
return;
}
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.
*/
int
restartgame()
{
int fd;
int version;
if ((fd = open("trek.dump", O_RDONLY)) < 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.
*/
static int
readdump(fd1)
int fd1;
{
int fd;
struct dump *d;
int i;
long 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));
}

97
trek/dumpme.c Normal file
View File

@@ -0,0 +1,97 @@
/* $NetBSD: dumpme.c,v 1.4 1997/10/12 21:24:43 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dumpme.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dumpme.c,v 1.4 1997/10/12 21:24:43 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
void
dumpme(flag)
int flag;
{
int f;
double x;
struct event *e;
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;
}

94
trek/dumpssradio.c Normal file
View File

@@ -0,0 +1,94 @@
/* $NetBSD: dumpssradio.c,v 1.4 1997/10/12 21:24:45 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)dumpssradio.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: dumpssradio.c,v 1.4 1997/10/12 21:24:45 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include "trek.h"
/**
** output hidden distress calls
**/
int
dumpssradio()
{
struct event *e;
int j;
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(&Quad[e->x][e->y]), 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(&Quad[e->x][e->y]), e->x, e->y);
chkrest++;
break;
}
}
return (chkrest);
}

478
trek/events.c Normal file
View File

@@ -0,0 +1,478 @@
/* $NetBSD: events.c,v 1.5 1997/10/13 22:05:26 cjs Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)events.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: events.c,v 1.5 1997/10/13 22:05:26 cjs Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "getpar.h"
#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.
*/
int
events(warp)
int warp; /* set if called in a time warp */
{
int i;
char *p;
int j = 0;
struct kling *k;
double rtime;
double xdate;
double idate;
struct event *ev = NULL;
int ix, iy;
struct quad *q;
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, 0);
/* 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);
p = (char *) Etc.snapshot;
memcpy(p, Quad, sizeof (Quad));
p += sizeof(Quad);
memcpy(p, Event, sizeof (Event));
p += sizeof(Event);
memcpy(p, &Now, 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]) != NULL)
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);
}

105
trek/externs.c Normal file
View File

@@ -0,0 +1,105 @@
/* $NetBSD: externs.c,v 1.4 1997/10/12 21:24:48 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)externs.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: externs.c,v 1.4 1997/10/12 21:24:48 christos Exp $");
#endif
#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"
};

77
trek/getcodi.c Normal file
View File

@@ -0,0 +1,77 @@
/* $NetBSD: getcodi.c,v 1.4 1997/10/12 21:24:49 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)getcodi.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: getcodi.c,v 1.4 1997/10/12 21:24:49 christos Exp $");
#endif
#endif /* not lint */
#include "getpar.h"
#include "trek.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).
*/
int
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);
}

316
trek/getpar.c Normal file
View File

@@ -0,0 +1,316 @@
/* $NetBSD: getpar.c,v 1.6 1997/10/13 22:12:01 cjs Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)getpar.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: getpar.c,v 1.6 1997/10/13 22:12:01 cjs Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <string.h>
#include "getpar.h"
#include "trek.h"
static int testterm __P((void));
/**
** get integer parameter
**/
int
getintpar(s)
char *s;
{
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;
{
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", (cmdfun)1, 1 },
{ "n", "o", (cmdfun)0, 0 },
{ NULL, NULL, NULL, 0 }
};
int
getynpar(s)
char *s;
{
struct cvntab *r;
r = getcodpar(s, Yntab);
return r->value2;
}
/**
** get coded parameter
**/
struct cvntab *getcodpar(s, tab)
char *s;
struct cvntab tab[];
{
char input[100];
struct cvntab *r;
int flag;
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++)
{
strcpy(input, r->abrev);
strcat(input, r->full);
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
**/
void
getstrpar(s, r, l, t)
char *s;
char *r;
int l;
char *t;
{
int i;
char format[20];
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
**/
int
testnl()
{
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
**/
void
skiptonl(c)
int c;
{
while (c != '\n')
if (!(c = cgetc(0)))
return;
ungetc('\n', stdin);
return;
}
/**
** test for valid terminator
**/
static int
testterm()
{
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.
*/
int
readdelim(d)
char d;
{
char c;
while ((c = cgetc(0)) != '\0')
{
if (c == d)
return (1);
if (c == ' ')
continue;
ungetc(c, stdin);
break;
}
return (0);
}

54
trek/getpar.h Normal file
View File

@@ -0,0 +1,54 @@
/* $NetBSD: getpar.h,v 1.4 1997/10/12 21:24:51 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*
* @(#)getpar.h 8.1 (Berkeley) 5/31/93
*/
typedef void (*cmdfun) __P((int));
struct cvntab /* used for getcodpar() paramater list */
{
char *abrev;
char *full;
cmdfun value;
int value2;
};
int getintpar __P((char *));
double getfltpar __P((char *));
int getynpar __P((char *));
struct cvntab *getcodpar __P((char *, struct cvntab[]));
void getstrpar __P((char *, char *, int, char *));
int testnl __P((void));
void skiptonl __P((int));
int readdelim __P((int));

176
trek/help.c Normal file
View File

@@ -0,0 +1,176 @@
/* $NetBSD: help.c,v 1.4 1997/10/12 21:24:53 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)help.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: help.c,v 1.4 1997/10/12 21:24:53 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#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"};
/*ARGSUSED*/
void
help(v)
int v __attribute__((unused));
{
int i;
double dist, x;
int dx = 0, dy = 0;
int j, l = 0;
/* check to see if calling for help is reasonable ... */
if (Ship.cond == DOCKED) {
printf("Uhura: But Captain, we're already docked\n");
return;
}
/* or possible */
if (damaged(SSRADIO)) {
out(SSRADIO);
return;
}
if (Now.bases <= 0) {
printf("Uhura: I'm not getting any response from starbase\n");
return;
}
/* 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(0);
compkldist(0);
return;
}
/* the starbase must have been surrounded */
}
printf("fails\n");
}
/* one, two, three strikes, you're out */
lose(L_NOHELP);
}

95
trek/impulse.c Normal file
View File

@@ -0,0 +1,95 @@
/* $NetBSD: impulse.c,v 1.4 1997/10/12 21:24:54 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)impulse.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: impulse.c,v 1.4 1997/10/12 21:24:54 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include "trek.h"
#include "getpar.h"
/**
** move under impulse power
**/
/*ARGSUSED*/
void
impulse(v)
int v __attribute__((unused));
{
int course;
int power;
double dist, time;
int percent;
if (Ship.cond == DOCKED) {
printf("Scotty: Sorry captain, but we are still docked.\n");
return;
}
if (damaged(IMPULSE)) {
out(IMPULSE);
return;
}
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;
}

162
trek/initquad.c Normal file
View File

@@ -0,0 +1,162 @@
/* $NetBSD: initquad.c,v 1.4 1997/10/12 21:24:55 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)initquad.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: initquad.c,v 1.4 1997/10/12 21:24:55 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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().
*/
void
initquad(f)
int f;
{
int i, j;
int rx, ry;
int nbases, nstars;
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;
}
void
sector(x, y)
int *x, *y;
{
int i, j;
do
{
i = ranf(NSECTS);
j = ranf(NSECTS);
} while (Sect[i][j] != EMPTY);
*x = i;
*y = j;
return;
}

239
trek/kill.c Normal file
View File

@@ -0,0 +1,239 @@
/* $NetBSD: kill.c,v 1.5 1998/08/30 09:19:40 veego Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)kill.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: kill.c,v 1.5 1998/08/30 09:19:40 veego Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
void
killk(ix, iy)
int ix, iy;
{
int i;
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++)
Etc.klingon[i] = Etc.klingon[i+1];
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
*/
void
killb(qx, qy)
int qx, qy;
{
struct quad *q;
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;
*b = Now.base[Now.bases];
if (qx == Ship.quadx && qy == Ship.quady)
{
Sect[Etc.starbase.x][Etc.starbase.y] = EMPTY;
if (Ship.cond == DOCKED)
undock(0);
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
**/
void
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 */
{
struct quad *q;
struct event *e;
char *name;
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
**/
void
killd(x, y, f)
int x, y; /* quadrant coordinates */
int f; /* set if user is to be informed */
{
struct event *e;
int i;
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;
}
}
}
}

191
trek/klmove.c Normal file
View File

@@ -0,0 +1,191 @@
/* $NetBSD: klmove.c,v 1.4 1997/10/12 21:24:57 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)klmove.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: klmove.c,v 1.4 1997/10/12 21:24:57 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
void
klmove(fl)
int fl;
{
int n;
struct kling *k;
double dx, dy;
int nextx, nexty;
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; 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;
*k = Etc.klingon[Etc.nkling];
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);
}

96
trek/lose.c Normal file
View File

@@ -0,0 +1,96 @@
/* $NetBSD: lose.c,v 1.4 1997/10/12 21:24:58 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lose.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: lose.c,v 1.4 1997/10/12 21:24:58 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <setjmp.h>
#include <unistd.h>
#include "trek.h"
#include "getpar.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",
};
void
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);
}

118
trek/lrscan.c Normal file
View File

@@ -0,0 +1,118 @@
/* $NetBSD: lrscan.c,v 1.4 1997/10/12 21:24:59 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)lrscan.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: lrscan.c,v 1.4 1997/10/12 21:24:59 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
/*ARGSUSED*/
void
lrscan(v)
int v __attribute__((unused));
{
int i, j;
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;
}

257
trek/main.c Normal file
View File

@@ -0,0 +1,257 @@
/* $NetBSD: main.c,v 1.6 1997/10/13 22:18:32 cjs Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: main.c,v 1.6 1997/10/13 22:18:32 cjs Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <setjmp.h>
#include <termios.h>
#include <stdlib.h>
#include <unistd.h>
#include <err.h>
#include <time.h>
#include <sys/types.h>
#include "trek.h"
#include "getpar.h"
# define PRIO 00 /* default priority */
uid_t 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;
int main __P((int, char **));
int
main(argc, argv)
int argc;
char **argv;
{
time_t curtime;
long vect;
char opencode;
int prio;
int ac;
char **av;
struct termios argp;
/* Revoke setgid privileges */
setregid(getgid(), getgid());
av = argv;
ac = argc;
av++;
time(&curtime);
vect = (long) curtime;
srand(vect);
opencode = 'w';
prio = PRIO;
if (tcgetattr(1, &argp) == 0)
{
if (cfgetispeed(&argp) < 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)
errx(1, "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);
return 0;
}

239
trek/move.c Normal file
View File

@@ -0,0 +1,239 @@
/* $NetBSD: move.c,v 1.5 1998/08/30 09:19:40 veego Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: move.c,v 1.5 1998/08/30 09:19:40 veego Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#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;
int ix = 0, iy = 0;
double bigger;
int n;
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 = %p, ->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);
}

150
trek/nova.c Normal file
View File

@@ -0,0 +1,150 @@
/* $NetBSD: nova.c,v 1.5 1998/08/30 09:19:40 veego Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)nova.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: nova.c,v 1.5 1998/08/30 09:19:40 veego Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
void
nova(x, y)
int x, y;
{
int i, j;
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) {
snova(x, y);
return;
}
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;
}

66
trek/out.c Normal file
View File

@@ -0,0 +1,66 @@
/* $NetBSD: out.c,v 1.5 1997/10/13 22:20:35 cjs Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)out.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: out.c,v 1.5 1997/10/13 22:20:35 cjs Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <string.h>
#include "trek.h"
/*
** Announce Device Out
*/
void
out(dev)
int dev;
{
struct device *d;
d = &Device[dev];
printf("%s reports %s ", d->person, d->name);
if (d->name[strlen(d->name) - 1] == 's')
printf("are");
else
printf("is");
printf(" damaged\n");
}

389
trek/phaser.c Normal file
View File

@@ -0,0 +1,389 @@
/* $NetBSD: phaser.c,v 1.5 1997/10/12 21:25:06 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)phaser.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: phaser.c,v 1.5 1997/10/12 21:25:06 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#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", (cmdfun) 1, 0 },
{ "a", "utomatic", (cmdfun) 0, 0 },
{ NULL, NULL, NULL, 0 }
};
struct banks
{
int units;
double angle;
double spread;
};
/*ARGSUSED*/
void
phaser(v)
int v __attribute__((unused));
{
int i;
int j;
struct kling *k;
double dx, dy;
double anglefactor, distfactor;
struct banks *b;
int manual, flag, extra = 0;
int hit;
double tot;
int n;
int hitreqd[NBANKS];
struct banks bank[NBANKS];
struct cvntab *ptr;
if (Ship.cond == DOCKED) {
printf("Phasers cannot fire through starbase shields\n");
return;
}
if (damaged(PHASER)) {
out(PHASER);
return;
}
if (Ship.shldup) {
printf("Sulu: Captain, we cannot fire through shields.\n");
return;
}
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 = (long) 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) {
printf("Sulu: But there are no Klingons in this quadrant\n");
return;
}
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);
}

118
trek/play.c Normal file
View File

@@ -0,0 +1,118 @@
/* $NetBSD: play.c,v 1.4 1997/10/12 21:25:07 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)play.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: play.c,v 1.4 1997/10/12 21:25:07 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <setjmp.h>
#include "trek.h"
#include "getpar.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.
*/
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", dowarp, 0 },
{ "p", "hasers", phaser, 0 },
{ "ram", "", dowarp, 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 },
{ NULL, NULL, NULL, 0 }
};
/*ARGSUSED*/
void
myreset(v)
int v __attribute__((unused));
{
extern jmp_buf env;
longjmp(env, 1);
}
void
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();
}
}

111
trek/ram.c Normal file
View File

@@ -0,0 +1,111 @@
/* $NetBSD: ram.c,v 1.4 1997/10/12 21:25:08 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ram.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: ram.c,v 1.4 1997/10/12 21:25:08 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <unistd.h>
#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.
*/
void
ram(ix, iy)
int ix, iy;
{
int i;
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;
}

67
trek/ranf.c Normal file
View File

@@ -0,0 +1,67 @@
/* $NetBSD: ranf.c,v 1.4 1997/10/12 21:25:09 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ranf.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: ranf.c,v 1.4 1997/10/12 21:25:09 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <stdlib.h>
#include "trek.h"
int
ranf(max)
int max;
{
int t;
if (max <= 0)
return (0);
t = rand() >> 5;
return (t % max);
}
double franf()
{
double t;
t = rand() & 077777;
return (t / 32767.0);
}

91
trek/rest.c Normal file
View File

@@ -0,0 +1,91 @@
/* $NetBSD: rest.c,v 1.4 1997/10/12 21:25:10 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)rest.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: rest.c,v 1.4 1997/10/12 21:25:10 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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.
*/
/*ARGSUSED*/
void
rest(v)
int v __attribute__((unused));
{
double t;
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;
}

186
trek/schedule.c Normal file
View File

@@ -0,0 +1,186 @@
/* $NetBSD: schedule.c,v 1.4 1997/10/12 21:25:11 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)schedule.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: schedule.c,v 1.4 1997/10/12 21:25:11 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#include <err.h>
#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;
{
struct event *e;
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);
}
errx(1, "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'.
*/
void
reschedule(e1, offset)
struct event *e1;
double offset;
{
double date;
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.
*/
void
unschedule(e1)
struct event *e1;
{
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;
{
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.
*/
void
xresched(e1, ev1, factor)
struct event *e1;
int ev1;
int factor;
{
int ev;
struct event *e;
ev = ev1;
e = e1;
reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor);
}

111
trek/score.c Normal file
View File

@@ -0,0 +1,111 @@
/* $NetBSD: score.c,v 1.4 1997/10/12 21:25:13 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: score.c,v 1.4 1997/10/12 21:25:13 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include "trek.h"
#include "getpar.h"
/*
** PRINT OUT THE CURRENT SCORE
*/
long score()
{
int u;
int t;
long s;
double r;
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);
}

315
trek/setup.c Normal file
View File

@@ -0,0 +1,315 @@
/* $NetBSD: setup.c,v 1.5 1997/10/12 21:25:15 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: setup.c,v 1.5 1997/10/12 21:25:15 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
#include <err.h>
#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", (cmdfun)1, 0 },
{ "m", "edium", (cmdfun)2, 0 },
{ "l", "ong", (cmdfun)4, 0 },
{ "restart", "", (cmdfun)0, 0 },
{ NULL, NULL, NULL, 0 }
};
struct cvntab Skitab[] =
{
{ "n", "ovice", (cmdfun)1, 0 },
{ "f", "air", (cmdfun)2, 0 },
{ "g", "ood", (cmdfun)3, 0 },
{ "e", "xpert", (cmdfun)4, 0 },
{ "c", "ommodore", (cmdfun)5, 0 },
{ "i", "mpossible", (cmdfun)6, 0 },
{ NULL, NULL, NULL, 0 }
};
void
setup()
{
struct cvntab *r;
int i, j;
double f;
int d;
int klump;
int ix, iy;
struct quad *q;
struct event *e;
while (1)
{
r = getcodpar("What length game", Lentab);
Game.length = (long) r->value;
if (Game.length == 0)
{
if (restartgame())
continue;
return;
}
break;
}
r = getcodpar("What skill game", Skitab);
Game.skill = (long) r->value;
Game.tourn = 0;
getstrpar("Enter a password", Game.passwd, 14, 0);
if (strcmp(Game.passwd, "tournament") == 0)
{
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)
errx(1, "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);
}

79
trek/setwarp.c Normal file
View File

@@ -0,0 +1,79 @@
/* $NetBSD: setwarp.c,v 1.4 1997/10/12 21:25:16 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)setwarp.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: setwarp.c,v 1.4 1997/10/12 21:25:16 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include "trek.h"
#include "getpar.h"
/*
** SET WARP FACTOR
**
** The warp factor is set for future move commands. It is
** checked for consistancy.
*/
/*ARGSUSED*/
void
setwarp(v)
int v __attribute__((unused));
{
double warpfac;
warpfac = getfltpar("Warp factor");
if (warpfac < 0.0)
return;
if (warpfac < 1.0) {
printf("Minimum warp speed is 1.0\n");
return;
}
if (warpfac > 10.0) {
printf("Maximum speed is warp 10.0\n");
return;
}
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;
}

154
trek/shield.c Normal file
View File

@@ -0,0 +1,154 @@
/* $NetBSD: shield.c,v 1.6 1998/08/30 09:19:40 veego Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)shield.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: shield.c,v 1.6 1998/08/30 09:19:40 veego Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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", (cmdfun)1, 0 },
{ "d", "own", (cmdfun)0, 0 },
{ NULL, NULL, NULL, 0 }
};
void
shield(f)
int f;
{
int i;
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) {
printf("Ye Faire Queene does not have the cloaking device.\n");
return;
}
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 = (long) 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;
}

168
trek/snova.c Normal file
View File

@@ -0,0 +1,168 @@
/* $NetBSD: snova.c,v 1.4 1997/10/12 21:25:18 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)snova.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: snova.c,v 1.4 1997/10/12 21:25:18 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <unistd.h>
#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.
*/
void
snova(x, y)
int x, y;
{
int qx, qy;
int ix, iy = 0;
int f;
int dx, dy;
int n;
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);
Game.killk += dx;
}
else
if (q->bases)
killb(qx, qy);
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;
}

197
trek/srscan.c Normal file
View File

@@ -0,0 +1,197 @@
/* $NetBSD: srscan.c,v 1.4 1997/10/12 21:25:19 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)srscan.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: srscan.c,v 1.4 1997/10/12 21:25:19 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#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"
};
void
srscan(f)
int f;
{
int i, j;
int statinfo;
char *s;
int percent;
struct quad *q = NULL;
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));
}

74
trek/systemname.c Normal file
View File

@@ -0,0 +1,74 @@
/* $NetBSD: systemname.c,v 1.4 1997/10/12 21:25:21 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)systemname.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: systemname.c,v 1.4 1997/10/12 21:25:21 christos Exp $");
#endif
#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;
{
struct quad *q;
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]);
}

265
trek/torped.c Normal file
View File

@@ -0,0 +1,265 @@
/* $NetBSD: torped.c,v 1.4 1997/10/12 21:25:22 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)torped.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: torped.c,v 1.4 1997/10/12 21:25:22 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#include "trek.h"
#include "getpar.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.
*/
static int randcourse __P((int));
/*ARGSUSED*/
void
torped(v)
int v __attribute__((unused));
{
int ix, iy;
double x, y, dx, dy;
double angle;
int course, course2;
int k;
double bigger;
double sectsize;
int burst;
int n;
if (Ship.cloaked)
{
printf("Federation regulations do not permit attack while cloaked.\n");
return;
}
if (check_out(TORPED))
return;
if (Ship.torped <= 0)
{
printf("All photon torpedos expended\n");
return;
}
/* 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) {
printf("Maximum burst angle is 15 degrees\n");
return;
}
}
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.
*/
static int
randcourse(n)
int n;
{
double r;
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);
}

142
trek/trek.6.in Normal file
View File

@@ -0,0 +1,142 @@
.\" $NetBSD: trek.6,v 1.4 1995/04/22 10:59:35 cgd Exp $
.\"
.\" Copyright (c) 1980, 1993
.\" 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 8.2 (Berkeley) 12/30/93
.\"
.Dd December 30, 1993
.Dt TREK 6
.Os
.Sh NAME
.Nm trek
.Nd trekkie game
.Sh SYNOPSIS
.Nm @gamesdir@/trek
.Oo
.Op Fl a
.Ar file
.Oc
.Sh DESCRIPTION
.Nm Trek
is a game of space glory and war. Below is a summary of commands.
For complete documentation, see
.Em Trek
by Eric Allman.
.Pp
If a filename is given, a log of the game is written onto that file.
If the
.Fl 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
.Dq short ,
.Dq medium ,
and
.Dq long .
You may also type
.Dq restart ,
which restarts a previously saved game.
You will then be prompted for the skill, to which you must respond
.Dq novice ,
.Dq fair ,
.Dq good ,
.Dq expert ,
.Dq commodore ,
or
.Dq impossible .
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"
.Pa /usr/doc/trek
.Sh COMMAND SUMMARY
.Bl -item -compact
.It
.Ic abandon
.It
.Ic ca Ns pture
.It
.Ic cl Ns oak
.Ic u Ns p/ Ns Ic d Ns own
.It
.Ic c Ns omputer request; ...
.It
.Ic da Ns mages
.It
.Ic destruct
.It
.Ic do Ns ck
.It
.Ic help
.It
.Ic i Ns mpulse course distance
.It
.Ic l Ns rscan
.It
.Ic m Ns ove course distance
.It
.Ic p Ns hasers Ic a Ns utomatic
amount
.It
.Ic p Ns hasers Ic m Ns anual
amt1 course1 spread1 ...
.It
.Ic t Ns orpedo course
.Op Ic y Ns es
.No angle/ Ns Ic n Ns o
.It
.Ic ram No course distance
.It
.Ic r Ns est time
.It
.Ic shell
.It
.Ic sh Ns ields
.Ic u Ns p/ Ns Ic d Ns own
.It
.Ic s Ns rscan
.Op Ic y Ns es/ Ic n Ns o
.It
.Ic st Ns atus
.It
.Ic terminate y Ns es/ Ns Ic n Ns o
.It
.Ic u Ns ndock
.It
.Ic v Ns isual course
.It
.Ic w Ns arp warp_factor
.El

532
trek/trek.h Normal file
View File

@@ -0,0 +1,532 @@
/* $NetBSD: trek.h,v 1.5 1997/10/12 21:25:23 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.h 8.1 (Berkeley) 5/31/93
*/
/*
** 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 */
/********************* 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 */
{
unsigned 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) */
short 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
{
unsigned char x, y; /* coordinates */
double date; /* trap stardate */
char evcode; /* event type */
unsigned 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
{
unsigned 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
{
unsigned char x, y; /* coordinates */
};
extern struct cvntab Skitab[];
extern struct cvntab Lentab[];
/*
* 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 */
unsigned 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
{
unsigned 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
{
unsigned 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 */
short 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;
/* abandon.c */
void abandon __P((int));
/* attack.c */
void attack __P((int));
/* autover.c */
void autover __P((void));
/* capture.c */
void capture __P((int));
struct kling *selectklingon __P((void));
/* cgetc.c */
char cgetc __P((int));
/* check_out.c */
int check_out __P((int));
/* checkcond.c */
void checkcond __P((void));
/* compkl.c */
void compkldist __P((int));
/* computer.c */
void computer __P((int));
/* damage.c */
void damage __P((int, double));
/* damaged.c */
int damaged __P((int));
/* dcrept.c */
void dcrept __P((int));
/* destruct.c */
void destruct __P((int));
/* dock.c */
void dock __P((int));
void undock __P((int));
/* dumpgame.c */
void dumpgame __P((int));
int restartgame __P((void));
/* dumpme.c */
void dumpme __P((int));
/* dumpssradio.c */
int dumpssradio __P((void));
/* events.c */
int events __P((int));
/* externs.c */
/* getcodi.c */
int getcodi __P((int *, double *));
/* help.c */
void help __P((int));
/* impulse.c */
void impulse __P((int));
/* initquad.c */
void initquad __P((int));
void sector __P((int *, int *));
/* kill.c */
void killk __P((int, int ));
void killb __P((int, int ));
void kills __P((int, int , int));
void killd __P((int, int , int));
/* klmove.c */
void klmove __P((int));
/* lose.c */
void lose __P((int));
/* lrscan.c */
void lrscan __P((int));
/* move.c */
double move __P((int, int, double, double));
/* nova.c */
void nova __P((int, int ));
/* out.c */
void out __P((int));
/* phaser.c */
void phaser __P((int));
/* play.c */
void myreset __P((int));
void play __P((void));
/* ram.c */
void ram __P((int, int ));
/* ranf.c */
int ranf __P((int));
double franf __P((void));
/* rest.c */
void rest __P((int));
/* schedule.c */
struct event *schedule __P((int, double, int, int , int));
void reschedule __P((struct event *, double));
void unschedule __P((struct event *));
struct event *xsched __P((int, int, int, int , int ));
void xresched __P((struct event *, int, int));
/* score.c */
long score __P((void));
/* setup.c */
void setup __P((void));
/* setwarp.c */
void setwarp __P((int));
/* shield.c */
void shield __P((int));
/* snova.c */
void snova __P((int, int ));
/* srscan.c */
void srscan __P((int));
/* systemname.c */
char *systemname __P((struct quad *));
/* torped.c */
void torped __P((int));
/* visual.c */
void visual __P((int));
/* warp.c */
void dowarp __P((int));
void warp __P((int, int, double));
/* win.c */
void win __P((void));

113
trek/visual.c Normal file
View File

@@ -0,0 +1,113 @@
/* $NetBSD: visual.c,v 1.4 1997/10/12 21:25:26 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)visual.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: visual.c,v 1.4 1997/10/12 21:25:26 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include "trek.h"
#include "getpar.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 }
};
/*ARGSUSED*/
void
visual(z)
int z __attribute__((unused));
{
int ix, iy;
int co;
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;
}

208
trek/warp.c Normal file
View File

@@ -0,0 +1,208 @@
/* $NetBSD: warp.c,v 1.6 1998/09/11 14:28:28 hubertf Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)warp.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: warp.c,v 1.6 1998/09/11 14:28:28 hubertf Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include "trek.h"
#include "getpar.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.
*/
void
dowarp(fl)
int fl;
{
int c;
double d;
if (getcodi(&c, &d))
return;
warp(fl, c, d);
}
void
warp(fl, c, d)
int fl, c;
double d;
{
char *p;
int course;
double power;
double dist;
double time;
double speed;
double frac;
int percent;
int i;
if (Ship.cond == DOCKED) {
printf("%s is docked\n", Ship.shipname);
return;
}
if (damaged(WARP))
{
out(WARP);
return;
}
course = c;
dist = d;
/* 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)
{
printf("Equilibrium restored -- all systems normal\n");
return;
}
/* 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;
p = (char *) Etc.snapshot;
memcpy(p, Quad, sizeof Quad);
p += sizeof Quad;
memcpy(p, Event, sizeof Event);
p += sizeof Event;
memcpy(p, &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;
}

97
trek/win.c Normal file
View File

@@ -0,0 +1,97 @@
/* $NetBSD: win.c,v 1.4 1997/10/12 21:25:28 christos Exp $ */
/*
* Copyright (c) 1980, 1993
* 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)win.c 8.1 (Berkeley) 5/31/93";
#else
__RCSID("$NetBSD: win.c,v 1.4 1997/10/12 21:25:28 christos Exp $");
#endif
#endif /* not lint */
#include <stdio.h>
#include <unistd.h>
#include <setjmp.h>
#include "trek.h"
#include "getpar.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.
*/
void
win()
{
long s;
struct cvntab *p = NULL;
extern jmp_buf env;
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);
}