okamoto@ucbvax.ARPA (Doctor Who) (09/16/85)
# This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. -----cut here-----cut here-----cut here-----cut here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # =doc # This archive created: Mon Sep 16 08:05:29 1985 echo shar: creating directory =doc mkdir =doc chdir =doc echo shar: extracting 0.t '(3308 characters)' sed 's/^XX//' << \SHAR_EOF > 0.t XX.ND XX.ds CF - % - XX.ds LH STAR XX.ds CH XX.ds RH TREK XX.nr PO 0.5i XX.nr LL 6.5i XX.nr PD 0 XX.na XX.LP XX.ce XXT R E K 7 3 XX.ce XXA Star Trek(R) Battle Simulation XX.FS (R) XXStar Trek is a registered trademark of Paramount Pictures. XX.FE XX.sp XX.PP XXTrek73 is a computer-simulated battle based on the famous XXStar Trek television series and XXthe game Star Fleet Battles. XXVia computer terminal, you can clash with enemy XXbattle cruisers, such as Klingon D-7's and Romulan Sparrowhawks, XXand use the same strategies XXthat Captain Kirk has used. XXLike Kirk, you control a Federation vessel similar to the XXEnterprise; a computer program directs the enemy. XXVictory can fall into several categories: XX.sp XX.PP XXDecisive Victory -- You completely destroy or cripple the XXattacking force. XX.sp XX.PP XXTactical Victory -- You out-maneuver the enemy using XXhigh-speed escapes, corbomite bluffs, `play dead' tactics; XXor the enemy surrenders. XX.sp XX.PP XXMoral Victory -- You surrender or self-destruct and destroy XXeach other. XX.sp XX.PP XXAll distances are measured in megameters, one million meters XX(abbreviated `M'). XXSpeed is expressed in `warp factors'. XXEach warp factor equals 100M per second.\** XX.FS XXAlthough technically incorrect, it does save the player from XXhaving to compute cube roots. XX.FE XXAll angles are expressed in common degrees from zero to XX360, measured counter-clockwise from the x-axis, similar to XXreading a protractor. XXOnly two dimensions are used.\** XX.FS XXThis saves the player from having to work out problems in XXspherical geometry. XX.FE XX.sp XX.PP XXPlay is as follows: XX.sp XX.PP XX1. You issue one of a number of commands (fire phasers, change XXcourse, launch antimatter pods, surrender, etc.) by typing XXthe appropriate code number into the keyboard; XX.sp XX.PP XX2. The enemy, under programmed instructions, issues a XXsimilar command; XX.sp XX.PP XX3. Both your commands are executed (phasers are fired, XXprobes are launched, damages are assessed, courses changed, XXetc.) while the vessels move through space; XX.sp XX.PP XX4. Unless certain end-game conditions are met (you destroy XXthe enemy, the enemy destroys you, your out-maneuver the XXenemy, you both destroy each other, or one party surrenders) XXthe above steps are repeated. XX.sp XX.PP XXAppendix 1 displays certain weapon and shield angles. XX.sp XX.PP XXAppendix 2 depicts the Enterprise's power circuits. XX.sp XX.PP XXAppendix 3 lists certain weapon and vessel specifications. XX.sp XX.PP XXAppendix 4 lists initial deployment of resources. XX.sp 2 XX.LP XX.in 1i XX.ta .5i XX.nf XXCODE COMMAND XX==== ======= XX.sp XX1 Fire Phasers XX2 Fire Photon Torpedos XX3 Lock Phasers Onto Target XX4 Lock Tubes Onto Target XX5 Manually Rotate Phasers XX6 Manually Rotate Tubes XX7 *Phaser Status XX8 *Tube Status XX9 Load/Unload Torpedo Tubes XX10 Launch Antimatter Probe XX.sp XX11 Probe Control (Detonate, Direct, Lock) XX12 *Position Report XX13 *Position Display XX14 Pursue An Enemy Vessel XX15 Run From An Enemy Vessel XX16 Manually Change Course And Speed XX17 *Damage Report XX18 Scan Enemy (Damage Report Of Enemy) XX19 Alter Power Distribution XX20 Alter Torpedo And Phaser Firing Parameters XX.sp XX21 Jettison Engineering XX22 Detonate Engineering XX23 Attempt Defenseless Ruse XX24 Attempt Corbomite Bluff(s) XX25 Surrender XX26 Ask Enemy to Surrender XX27 Initiate Self-Destruct Sequence XX28 Abort Self-Destruct XX29 Survivors Report XX30 *Reprints Above List XX.sp XX*Does Not Use A Turn XX.in 0 XX.fi XX.bp SHAR_EOF if test 3308 -ne "`wc -c 0.t`" then echo shar: error transmitting 0.t '(should have been 3308 characters)' fi echo shar: extracting 1.t '(6438 characters)' sed 's/^XX//' << \SHAR_EOF > 1.t XX.ce XXDetailed Descriptions of Each Command XX.sp XX.PP XXWhat follows is a detailed description of each command. XXEach command is referred to by a number from 1 to 30. XXAfter the name of the command is given, a synopsis of the XXarguments the command requires is given, if any. XXThese arguments can be entered on the command line, separated XXby a space, if you wish. XXFor instance, to fire phasers 1 through 4 with a spread of 15, XXyou could type '1 1234 15' on the command line. XX.sp XX.LP XX1. Fire Phasers. XX.PP XX[Phasers] [Spread] XX.PP XXPhasers are pure energy units which emit XXa beam similar to lasers, but of a pulsating nature which XXcan be `phased' to interfere with the wave pattern of any XXmolecular form. XXPhasers get their power from phaser banks, which in turn, XXderive their power from the ship's engines. XXEach phaser bank is capable of holding a charge of 10 units. XXWhen firing, these banks discharge, similar to batteries, to XXspread their destructive power through space. XXAfter discharging, these banks are then recharged by the XXengines. XXEach phaser can be set to automatically track a target or XXcan be manually rotated. XXUnless engineering is jettisoned (code 21), phasers only XXfire from 0-125 and 235-360 degrees, relative to the ship's XXcourse. XXIn other words, each vessel has a 110 degree blind side in XXback of it in which phasers cannot fire. XXIf phasers fired into this blind side, they would destroy XXthe ship's engineering section. XX.sp XX.PP XXThe Captain also designates a wide or narrow phaser beam: a XXwide beam to disrupt many targets; a narrow beam to inflict XXmaximum damage on a single target. XXThe maximum spread of phasers is 45 degrees, the minimum is XX10 degrees. XXThe total beam width is twice the designated spread. XX.sp XX.PP XXThe firing percentage of each bank is preset to 100. XXIn other words, the bank fully discharges when firing. XXThis can be changed, however, using code 22. XX.sp XX.PP XXThe maximum range of phasers is 1000M; the maximum hit XXfactor is 45 with a ten degree spread, 10 with a forty-five XXdegree spread. XXPhaser hit factors are calculated by the following formula: XX.sp XX.ce XXhit = (bankunits)(firing%)sqrt(1-range/1000)(45/spread) XX.sp XX.PP XXPhasers fire in .2-second intervals starting with bank one. XXPhasers inflict heavy damage and casualties, but do not XXdestroy shields as much as antimatter explosions do. XX.sp XX.PP XXA phaser is unable to fire if damaged, if firing into your XXblind side, or if completely discharged. XX.sp XX.LP XX2. Fire Photon Torpedos. XX.PP XX[Tubes] XX.PP XXThe Enterprise is equipped with six torpedo tubes, which, as XXphasers, can be set to automatically track a target or be XXmanually rotated. XXUnless engineering is jettisoned, tubes only fire from XX0-135 and 225-360 degrees. XXEach tube fires all its antimatter pods, which are XXtemporarily held suspended in a magno-photon force field. XXPhoton torpedos can be fired directly at an enemy, laid out XXas a mine field, or scattered in an attacker's path as XXdepth charges. XX.sp XX.PP XXTubes must be loaded (code 9) prior to firing. XXEach tube will be automatically loaded with 10 units or XXwhatever remains in the engines, whichever is less. XXNormally, torpedos are launched at warp 12 in .2-second XXintervals, beginning with tube one. XXPhoton torpedos have a proximity fuse of 200M. XXAll of these values can be changed by using code 22. XX.sp XX.PP XXTorpedos must be launched with care since the antimatter XXpods which are fired can never be recovered. XXIt is suggested that you not fire more than four torpedos at XXany one time, since a certain number of them do miss, or are XXdestroyed by the enemy firing phasers at them. XXIt is also suggested that you fire them at distant targets, XXbeyond 1100M, to avoid the explosion radii of your own XXweapons. XXHit factors resulting from antimatter explosions are XXcalculated as follows: XX.sp XX.ce XXhit = 5(#podscontained)sqrt(1-range/(55(#podscontained))) XX.sp XX.PP XXThe maximum hit factor of an antimatter device is five times XXthe number of pods contained (in the case of torpedos, 50); XXits explosion radius is 50 time the number of pods XXcontained (in the case of torpedos, 500). XXAntimatter explosions heavily weaken shields but do not XXdamage equipment as much as phasers do. XXThis formula also applies to vessels, engineering sections, XXand antimatter probe explosions. XX.sp XX.PP XXTubes are unable to fire if damaged, if firing into your XXblind side, or if unloaded. XX.sp XX.LP XX3. Lock Phasers. XX.PP XX[Phasers] [Target Name] XX.PP XXPhasers locked on an enemy vessel will automatically aim XXtowards it. XXAlthough phasers may track a vessel which is in the firing XXblind side, they will not fire unless engineering is XXjettisoned. XXTo fire at vessels behind, simply change course at least 50 XXdegrees. XXOnce a phaser is locked, it is not disengaged until the XXtarget is destroyed (in which case it is then rotated to XXzero degrees relative), relocked, manually over-ridden, or XXdamaged. XX.sp XX.LP XX4. Lock Tubes. XX.PP XX[Tubes] [Target Name] XX.PP XXTubes lock and unlock in the same manner that phasers do. XX.sp XX.LP XX5. Manually Rotate Phasers. XX.PP XX[Phasers] [Bearing] XX.PP XXManually rotating phasers disengages any previous locks and XXpositions them as directed, relative to your course. XXFor example, if your course is 30, and phasers are rotated XX45 degrees, they will hit a target bearing 75 degrees. XXRotating phasers into you blind side is permissible, XXhowever, they will not fire. XX.sp XX.LP XX6. Manually Rotate Tubes. XX.PP XX[Tubes] [Bearing] XX.PP XXManually rotating tubes is similar to rotating phasers. XX.sp XX.LP XX7. Phaser Status. XX.PP XXPhaser status reports the control (locks and damages), XXdeployment, levels, firing percentages (normally 100), XXand charge/discharge rates (normally +10) of all phasers. XX.sp XX.LP XX8. Tube Status. XX.PP XXTube status reports the control, deployment, tube levels, XXlaunch speeds (normally 12), proximity delays (normally XX200), and the time delays (normally 10). XX.sp XX.LP XX9. Load/Unload Tubes. XX.PP XX[l | u] [Tubes] XX.PP XXTubes are loaded with 10 charged antimatter pods until your XXfuel runs out. XXTubes can also be unloaded if the need arises. XX.sp XX.LP XX10. Launch Antimatter Probe. XX.PP XX[Pods] [Time] [Proximity] [Target | [<CR> Course]] XX.PP XXProbes are slow-moving devices equipped with internal XXguidance systems which allow them to chase an enemy vessel. XXProbes consist of at least ten antimatter pods which are XXlaunched from an undamaged probe launcher at warp three. XXAs with torpedos, probes are set with time and proximity XXfuses, and use the same hit factor formula as do torpedos. SHAR_EOF if test 6438 -ne "`wc -c 1.t`" then echo shar: error transmitting 1.t '(should have been 6438 characters)' fi echo shar: extracting 2.t '(6676 characters)' sed 's/^XX//' << \SHAR_EOF > 2.t XX.sp XX.LP XX11. Probe Control. XX.PP XX[y | [n [Probe] [y | [n [Target | [<CR> Course]]]]]] XX.PP XXProbe control allows you to detonate or redirect probes XXwhich may have missed. XX.sp XX.LP XX12. Position Report. XX.PP XXPosition reports are vital since valuable information on XXcourses, bearings and ranges are given to aid the formation XXof good strategy. XXThis order does not use a turn. XX.sp XX.LP XX13. Position Display. XX.PP XX[Radius of scan] XX.PP XXPosition displays, similar to radar scans, show objects XXwhich surround your vessel. XXThe Enterprise is indicated by a `+', jettisoned engineering XXsections by a `#', probes by a `*', torpedos by a `:', and XXenemy vessels by the first letter of their names. XX.sp XX.LP XX14. Pursue An Enemy Vessel. XX.PP XX[Target Name] [Warp Factor] XX.PP XXThis order instructs the ship's navigation to face an enemy XXvessel whenever possible. XX.sp XX.LP XX15. Run From An Enemy Vessel. XX.PP XX[Target Name] [Warp Factor] XX.PP XXThis order, just the opposite of order #14, instructs the XXnavigation to keep the stern of the Enterprise towards an XXenemy vessel whenever possible. XX.sp XX.LP XX16. Manually Change Course and Speed. XX.PP XX[Course] [Warp Factor] XX.PP XXThis order instructs navigation to maintain a fixed course XXand speed. XXThe following information applies to the above three orders: XX.sp XX.PP XXYour maximum rotation rate when turning is: XX.ce XXdegrees per sec = 5 * (12 - desired warp) XX.sp XX.PP XXAccordingly, you can turn 55 degrees at warp one, 50 at XXwarp two, ..., up to 15 degrees at warp nine. XXIn other words, the faster your speed, the less XXmaneuverable you are. XXYou are also less maneuverable if you lose your warp drive. XXYour maximum speed is warp nine, the enemy's is warp eleven. XX.sp XX.LP XX17. Damage Report. XX.PP XXThis report informs you of certain equipment status. XXA malfunctioning computer (very rare) make orders 3 (lock XXphasers), 4 (lock torpedos), 14 (pursue), 15 (run), 27 XX(initiate self-destruct), and 28 (abort self-destruct) XXimpossible to execute. XXYou will be required to manually rotate phasers and XXtorpedos, and manually change course and speed. XXDamaged sensors (rare) makes orders 13 (position report) and XX18 (scan) impossible. XXA damaged probe launcher (sometimes) prevents you from XXlaunching probes. XXA disabled warp drive (common) slows your speed and XXmaneuverability. XXSee order #20 about jettisoned engineering section. XXWhen your crew of 450 dies, your vessel is as good as dead. XXThere are 350 men aboard each enemy vessel. XX.sp XX.PP XXShield percentage is calculated by its energy drain times XXits operating efficiency. XXEfficiency starts at 100 and declines with each hit. XXNo damages of any kind are incurred when a shield absorbs XXits first hit, no matter how great the hit. XXShield one is 1.5 times as strong as the other three shields. XX.sp XX.PP XX`Efficiency' indicates the number of energy units being XXburned per warp-second. XXThis number is initially one (.75 for enemy) and increases XXper hit. XX.sp XX.PP XX`Regeneration' indicates the number of energy units being XXgained per second. XXInitially set at 10, this number decreases per hit. XX.sp XX.PP XX`Fuel capacity' indicates the number of matter-antimatter XXpods a vessel has aboard. XXThis number rapidly decreases with each torpedo or probe XXfired. XX.sp XX.PP XX`Fuel' indicates the number of matter-antimatter pods which XXare filled with energy. XXThis number rapidly decreases when maintaining high warp XXspeeds or firing phasers. XX.sp XX.LP XX18. Scan Enemy (Damage Report of Enemy). XX.PP XX[Ship Name] XX.PP XXAn enemy damage report is essentially the same as the XXEnterprise's. XX.sp XX.LP XX19. Alter Power Distribution. XX.PP XX[Shld 1 drain [* | ... Sh 4]] [Phsr 1 drain [* | ... Ph 4]] XX.PP XXThe synopsis of this command can be confusing. XXThe first set of numbers gives the drains for each shield. XXAll four shield drains can be specified, but XXif a star is used immediately after a shield drain XX(eg, 19 0.5 1*), XXthen the remaining shields will all be given a drain equal to the XXnumber preceding the '*'. XX(Thus, in the above example, shield 1's drain is 0.5, whereas XXshields 2, 3, and 4 have a drain of 1). XXThe same applies to the phaser drains. XX.sp XX.PP XXThe power circuits of all vessels are illustrated in XXappendix 2. XXDilithium crystals produce energy much like generators. XXThis power is then used to maintain warp speeds, recharge XXantimatter pods in the engine reserve, recharge phaser XXbanks, or maintain shield power. XXYour initial regeneration is ten, however, shields normally XXdrain four units and engines burn one unit per each XXwarp-second. XX.sp XX.PP XXShields can be thought of as electro-magnets. XXThe more energy put into them, the stringer their force field XXbecomes. XXTherefore, a shield's overall percentage is calculated by XXthe following formula: XX.sp XX.ce XXshield percentage = (energy in)(effective %) XX.sp XX.PP XXNotice that dropping power to a shield has the same effect XXas having it hit. XXNotice also that if your regeneration drops below four, XXyou may have to discharge your phaser banks to maintain full XXshield power. XX.sp XX.PP XXPhaser banks, similar to batteries, not only discharge (when XXfiring), but also recharge. XXInitially, they are set to recharge fully in one second XX(+10) so that you can continually use them. XXHowever, they can discharge fully (-10) in one second to XXprovide extra power to shields, warp engines, or engine XXreserve. XX.sp XX.PP XXUnder most conditions, you need not concern yourself with XXpower distribution unless some special need arises. XXDistribution, for the most part, is automatic. XXRegeneration is calculated first; that power is placed in XXreserve, along with any discharged phaser units. XXShield drain is calculated next, then phaser and engine XXdrains. XX.sp XX.PP XXBe concerned with wasting power by indiscriminately firing XXphasers and torpedos, maintaining speeds over warp three, or XXdumping scores of units onto antimatter probes. XXHuge power losses cannot be made up in battle. XX.sp XX.LP XX20. Jettison Engineering. XX.PP XXAlthough this order was never executed in the television XXseries, it is quite possible, according to its producer. XXJettisoning engineering has serious consequences, but it may XXbe your only course of action. XX.sp XX.PP XXOne would jettison engineering if being pursed by vessels, XXprobes or torpedos, or as a suicidal gesture. XX.sp XX.PP XXThe following things happen when engineering is jettisoned: XXA: You lose all your fuel and reserve capacity; B: you lose XXyour regeneration; C: you lose your warp drive; D: your lose XXyour probe launcher; E: you lose your shields until you XXdesignate phasers to discharge; F: the engineering section XXitself decelerates to a stop; G: a ten second time delay on XXit is set; H: hopefully, when it does explode, you are far XXfrom its effects; I: your phasers and torpedos are now free XXto fire in any direction. SHAR_EOF if test 6676 -ne "`wc -c 2.t`" then echo shar: error transmitting 2.t '(should have been 6676 characters)' fi echo shar: extracting 3.t '(2958 characters)' sed 's/^XX//' << \SHAR_EOF > 3.t XX.sp XX.LP XX21. Detonate Engineering. XX.PP XX[nothing | [y | n]] XX.PP XXThis order, issued after the previous one, manually detonates XXyour engineering section. XXIt may also be issued without the previous order, in XXwhich case you will be asked to confirm your (crazy) order. XX.sp XX.LP XX22. Alter Torpedo And Phaser Firing Parameters. XX.PP XX[[y [Launch Speed] [Time Delay] [Proximity Fuse]] | n] XX[[y [Firing Percentage]] | n] XX.PP XXThis option allows you to change the launch speeds, time and XXproximity delays of all torpedos. XXAt the beginning of play, torpedos are launched at warp XXtwelve, have ten second time fuses, and 200M proximity XXfuses. XXAny vessel or engineering section which comes within the XXproximity range will cause the torpedo to explode. XX.sp XX.PP XXPhaser firing percentages can also be altered. XXA phaser bank need not fire its full charge. XX.sp XX.LP XX23. Defenseless Ruse. XX.PP XX[e | p] XX.PP XXAnother name for this tactic is `playing dead'. XXWhen issued, your shields are dropped to zero, and power is XXdiverted to your engines or phaser banks. XXHopefully, the enemy will believe you dead and come too XXclose or break off their attack. XXYou should then be able to fire or run in the opposite XXdirection. XX.sp XX.LP XX24. Attempt Corbomite Bluff(s). XXThere were two corbomite bluffs in the television series; XXone was against a midget operating a huge space vessel the XXother was against Romulan attackers. XXBoth have been incorporated into this game. XXWhichever bluff issued is selected randomly. XX.sp XX.LP XX25. Surrender, If Possible. XX.PP XXThis order sends a message to the enemy, saying that you XXwish to surrender. XXThe enemy will then decide whether or not take you alive. XXYou will have difficulty surrendering to Romulans, who have XXnever accepted one. XX.sp XX.LP XX26. Ask Enemy To Surrender. XX.PP XXThis order ends a message to the enemy demanding that they XXsurrender. XXPlease bear in mind that Romulans are the most suicidal. XX.sp XX.LP XX27. Initiate Self-Destruct. XX.PP XXThis order activates a twenty-second self-destruct sequence. XXBecause final destruct does not occur until ten turns after XXinitialization, it is best to start it early, if at all. XXWhen you do explode, you hope that you explosive force will XXalso destroy your attackers. XX.sp XX.LP XX28. Abort Self-Destruct. XX.PP XXThis order, issued after the previous one, halts the XXdestruct sequence. XXSelf-destruct cannot be aborted withing five seconds to XXdetonation. XX.sp XX.LP XX29. Survivors Report XX.PP XXThis order prints out the number of survivors on board all the ships. XXThis order does not use a turn. XX.sp XX.LP XX30. Reprint Above List. XX.PP XXThis option, which does not use a turn, lists code numbers XXand associated descriptions of each. XX.sp XX.LP XX31 And Up. XX.PP XXFuture options, currently being designed in Trek74, will XXinclude Dr. Daystrom's paranoid, M5 multi-tronics computer XXwhich will take over while you relax; or battle someone else XXwho is on another terminal; or battle in teams; or have a XXfree-for-all against nine other starships. XX.sp XX.bp SHAR_EOF if test 2958 -ne "`wc -c 3.t`" then echo shar: error transmitting 3.t '(should have been 2958 characters)' fi echo shar: extracting 4.t '(3550 characters)' sed 's/^XX//' << \SHAR_EOF > 4.t XX.ce XXOptions XX.sp XX.PP XXIn TREK73, all the names are taken from the series Star Trek. XXThrough the use of options, the names can be changed to whatever XXyou want. XX.sp XX.PP XXTo use the options, you must add the variable TREK73OPTS to XXyour environment. XXA sample would be (using the C-shell): XX.br XX.sp XXsetenv TREK73OPTS 'name=Jerk, ship=Boobyprize, terse' XX.sp XX.PP XXThe option string is a list of comma-separated options. XXOptions are designated as either boolean or string options. XXBoolean options are turned on by typing their name and turned XXoff by prepending 'no' to them. XXString options are set equal to the string which follows the "=". XX.sp XX.PP XXThere follows a list of all the options, what type it is, XXand an explanation of what they mean. XXThe default for the option is in square brackets following XXthe option. XX.sp XX.IP "terse BOOLEAN [noterse]" XXThis option, when set, turns off the information regarding the XXship's purpose in the area. XXIt thus reduces the amount of drek on the screen. XXIf you are on a slow terminal, this is a nice option to have set. XX.sp XX.IP "shipname STRING [Enterprise]" XXThis option names your ship. XX.sp XX.IP "name STRING" XXThis option names the captain of the ship. XXIf this option is not set, then the program will ask for a name. XXThe captain is the one who must make all the decisions of strategy XXand tactics for the ship. XX.sp XX.IP "sex STRING" XXThis option gives the captain a gender. XXIf this option is not set, the program will ask for it's value. XXIf you respond with something that starts with other than "m" or "f", XXbeware! XX.sp XX.IP "science STRING [Spock]" XXThis option names the science officer, who is responsible XXfor checking the parameters of the captain's commands. XXIt is also this officer's duty to report damage to the ship XXas well as scan for enemy damage. XX.sp XX.IP "engineer STRING [Scott]" XXThis option names the chief engineer of the ship. XXIt is this officer's duty to report on the status of the ship, XXespecially its energy supply and distribution of the same. XXThe officer also controls the launching of anti-matter probes. XX.sp XX.IP "helmsman STRING [Sulu]" XXThis option names the ship's helmsman. XXThis officer's duty is to control the speed of the ship XXand also controls the firing of the ship's weapons. XX.sp XX.IP "nav STRING [Chekov]" XXThis option names the ship's navigator, who is responsible XXfor the navigation of the ship. XXThis officer makes changes to the ship's course as directed XXby the captain. XXThis officer also controls any anti-matter probes after they XXhave been launched. XX.sp XX.IP "com STRING [Uhura]" XXThis option names the ship's communications officer. XXIt is the duty of this officer to handle all communications between XXthe ship and the rest of the universe. XX.sp XX.IP "ships STRING" XXThis option, if set, tells the program how many ships you wish to fight. XXIf it is not set, then the program will ask. XX.sp XX.IP "enemy STRING [random]" XXIf this option is set, it tells the program which race you wish XXto fight. XXThe available races are: XXKlingon, Romulan, Kzinti, Gorn, Orion, Hydran, Lyran, or Tholian. XXIf the option is not set, the race you will fight is chosen at random. XX.sp XX.IP "foename STRING [random]" XXIf this option is set, it specifies the name of the commander XXof the enemy ship(s). XXIf this option is not specified, the name is chosen at random. XX.sp XX.IP "silly BOOLEAN [nosilly]" XXIf this option is set, an additional race is added to the list of XXpossible races to fight. XXThis race is the Monty Pythons. XXNote that if you wish to always fight the Monty Python's, you merely XXhave to set the enemy option above. XX.bp SHAR_EOF if test 3550 -ne "`wc -c 4.t`" then echo shar: error transmitting 4.t '(should have been 3550 characters)' fi echo shar: extracting 5.t '(1840 characters)' sed 's/^XX//' << \SHAR_EOF > 5.t XX.ce XXSimple Strategy XX.sp XX.PP XXIf you are a beginner, a simple strategy to follow is A: XXfight only one attacker; B: pursue him (code 14) at warp XXfactor one; C: lock on all phasers (code 3); D: continuously XXtake position reports (code 12) and watch his range; E: XXwhen he gets within 1000M, fire all phasers (code 1) and XXkeep on firing when he is in range; F: When the enemy is out XXof range, take damage reports and scans of the enemy (codes XX17 and 18). XX.sp XX.PP XXAfter a few trial games using the above strategy, you will XXwant to become as efficient as the enemy at firing photon XXtorpedos. XXFinally, when you master launching antimatter probes, you XXcan designate more that one attacker. XX.sp 3 XX.ce XXTrek73's History XX.sp XX.PP XXTrek73 was programmed on a Hewlett-Packard 2000C system by XXWilliam K. Char, Perry Lee, and Dan Gee. XXIn January, 1973, Mr. Char started with a few ideas and five XXmonths later, in May, introduced $SPACE, his first version. XX.sp XX.PP XXSpace had only 14 commands and comprised one 10K program. XXResponse was so great that new ideas flooded in and in June, XXwork on Trek73 was begun. XXOver 70 recordings of past shows were reviewed to XXreconstruct dialogue and vessels. XXOn October 8, 1973, Trek73 was introduced. XX.sp XX.PP XXIn 1984, Dave Pare at Univeristy of California at San Diego and Chris Williams XXat the University of California at Berkeley independently translated XXthe BASIC code into C to run under BSD UNIX.\** XX.FS XXUNIX is a registered trademark of Bell Laboratories. XX.FE XX.sp XX.PP XXIn April 1985, Jeff Okamoto and Peter Yee, both XXat the University of California at Berkeley combined the two XXversions into one, fixing bugs and adding new commands. XXThe user-settable options were also added. XX.sp XX.PP XXIdeas and bug reports should be sent to: XX.br XXARPA: okamoto@BERKELEY and yee@BERKELEY XX.br XXUUCP: ..!ucbvax!okamoto and ..!ucbvax!yee XX.bp SHAR_EOF if test 1840 -ne "`wc -c 5.t`" then echo shar: error transmitting 5.t '(should have been 1840 characters)' fi echo shar: extracting 6.t '(1785 characters)' sed 's/^XX//' << \SHAR_EOF > 6.t XX.ce XXAPPENDIX 1 XX.nf XX.sp 4 XX Secondary Hull Primary Hull XX (engineering) XX ------- XX:-----------------------------------------\\ | .5 | . . . . XX:: N C C - 1 7 0 1 |} |0 / 1|---< . . . . . XX::________________________________________/ | | . . . . XX warp engines ^ | .5 | . . . . XX +++ |0 / 1|---< . . . . . XX ===== | fuel | | . . . . XX |+| + OOOOO reserve | .5 | . . . . XX |+| ---------> +++ ---> OOOOO --- +++ ---> |0 / 1|---< . . . . . XX ------- + ***** | | . . . . XX | | ***** shield | .5 | . . . . XX ------- | \\ control |0 / 1|---< . . . . . XXdilithium * \\ ------- . . . . XXcrystal *** +++ shields XXgenerator * \\phaser control XX | -------- : : : XX | |-10/10|-OOOO>. . : : : | : : XX <***: <[=====| <---+ |-10/10|-**OO>. . : : : : XX probe launcher | |-10/10|-****> XX V |-10/10|-****> XX =*******= -------- phaser banks XX photon =*****=== XX torpedo =**====== XX tubes =======****** XX ========= ******* XX ========= ******** XX+ Energy unit XXO Matter-anti-matter pod XX* Filled matter-anti-matter pod XX---+++---> Energy transfer XX---***---> Pod transfer XX.fi XX.bp SHAR_EOF if test 1785 -ne "`wc -c 6.t`" then echo shar: error transmitting 6.t '(should have been 1785 characters)' fi echo shar: extracting 7.t '(1287 characters)' sed 's/^XX//' << \SHAR_EOF > 7.t XX.ce XXAPPENDIX 2 XX.nf XX.sp 7 XX Shield 2 XX | XX 135 90 XX \\\\,,,,,,,,''-``,,,,,,,, XX ,,''\\ .Phaser.Firing An``,, 45 XX ,' \\ \\125 gles`,/ XX ,' \\. . Torpedo. . `, XX :------------------------\\ \\135_-----_ Fir . , XX :________________________/ _- 1 -_ ing . ` XX | || / 0 \\ Angles . | XX Shield | ,_^^_____/| _ 7 | . . | Shield XX -180| [ { (o) 1 } . . |0- XX 3 | `-vv-----\\| - C | . . | 1 XX | || \\ C / . . | XX :-----------------------\\ -_ N _- . . , XX :_______________________/ -_____- . . ' XX `, /225. . . . . . . ,' XX `, / . ,' \\ XX ``,/ /235. . . . . . . . ,,'' 315 XX /`````````,,_,,'''''''' XX 225 270 XX | XX Shield 4 XX.fi XX.bp SHAR_EOF if test 1287 -ne "`wc -c 7.t`" then echo shar: error transmitting 7.t '(should have been 1287 characters)' fi echo shar: extracting 8.t '(1309 characters)' sed 's/^XX//' << \SHAR_EOF > 8.t XX.ce XXAPPENDIX 3 XX.ce XXWeapon And Vessel Specifications XX.ce XXEnemy exceptions are enclosed within [brackets] XX.sp XX.DS XX.ta 2.8iR 3.3i XX.ce XXPhasers XX Number of banks 4 XX Max range 1000 megameters XX Max spread 90 degrees (45+45) XX Min spread 20 degrees (10+10) XX Max hit with 45 degree spread 10 XX Max hit with 10 degree spread 45 XX Loss of shield 1 per hit hit/4.5 XX Loss of shields 2-3-4 per hit hit/3 XX Firing angles with engineering 0-125, 235-360 degrees XX Max charge per bank 10 units XX Min charge or discharge time 1 sec XX.sp XX.ce XXTubes XX Number of tubes 6 XX Max range 12,000 megameters XX max launch speed warp 12 XX Max time delay 10 seconds XX Max proximity delay 500M XX Max explosion radius 500M XX Max number of pods launched 10 XX Max hit factor 50 XX Loss of shield 1 per hit hit/3 XX Loss of shields 2-3-4 per hit hit/2 XX Firing angles with engineering 0-135, 225-360 degrees XX.sp XX.ce XXProbes XX Number of probe launchers 1 XX Max range 3000M XX Max launch speed 2 XX Max time delay 15 sec XX Max proximity delay any XX Max explosion radius 50 times number of pods XX Max pods launched fuel available XX Max hit factor 10 times number of pods XX Loss of shields per hit same as torpedos XX Firing angles with engineering all XX.sp XX.ce XXVessels XX Max turning rate 50 degrees XX Max speed warp 99 [11] XX Min units burned per warp-second 1 [.75] XX Crew 450 d[350] XX.DE SHAR_EOF if test 1309 -ne "`wc -c 8.t`" then echo shar: error transmitting 8.t '(should have been 1309 characters)' fi echo shar: extracting header '(58 characters)' sed 's/^XX//' << \SHAR_EOF > header XX.ND XX.ds CF - % - XX.ds CH XX.nr PO 0.5i XX.nr LL 6.5i XX.nr PD 0 SHAR_EOF if test 58 -ne "`wc -c header`" then echo shar: error transmitting header '(should have been 58 characters)' fi echo shar: extracting 9.t '(590 characters)' sed 's/^XX//' << \SHAR_EOF > 9.t XX.ce XXAPPENDIX 4 XX.sp 2 XX.ce XXInitial Settings XX.sp 2 XX.ce XXEnemy exceptions are enclosed within [brackets] XX.sp XX.DS XX.ta 2.8iR 3.3i XX Crew 450 [350] XX Speed 1000 megameters XX Course 0 [0-360] degrees XX Engine Efficiency 1 [.75] XX Fuel Level 150 XX Fuel Capacity 200 XX Regeneration Rate per Second 10 XX Helm Lock None [Federation Vessel] XX Phaser Deployment 90, 0, 0, 270 XX Phaser Bank Levels 4 x 10 units XX Phaser Charge/Discharge Rates 4 x 10 units XX Shield Drain 4 x 1 units XX Shield Percentage 4 x 100 XX Torpedo Deployment 120, 60, 0, 0, 300, 240 XX Tube Levels 6 x Zero XX Total Charged Pods Available 190 XX.sp XX.DE SHAR_EOF if test 590 -ne "`wc -c 9.t`" then echo shar: error transmitting 9.t '(should have been 590 characters)' fi echo shar: extracting Makefile '(235 characters)' sed 's/^XX//' << \SHAR_EOF > Makefile XX# Makefile for Trek73.doc XX XXTEXT = header 0.t 1.t 2.t 3.t 4.t 5.t 6.t 7.t 8.t 9.t XXPAGE = trek73.6 XX XXDOC = trek73.doc XXMAN = trek73.man XX XXall: ${DOC} ${MAN} XX XX${DOC}: ${TEXT} XX nroff -ms ${TEXT} > $@ XX XX${MAN}: ${PAGE} XX nroff -man ${PAGE} > $@ SHAR_EOF if test 235 -ne "`wc -c Makefile`" then echo shar: error transmitting Makefile '(should have been 235 characters)' fi echo shar: extracting trek73.6 '(1127 characters)' sed 's/^XX//' << \SHAR_EOF > trek73.6 XX.TH TREK73 6 "18 Jun 1985" XX.UC 4 XX.SH NAME XXtrek73 - A Star Trek simulation XX.SH SYNOPSIS XXtrek73 XX.SH DESCRIPTION XX.PP XX.I Trek73 XXis one of many Star Trek simulations now available. XXIn its time, it was considered one of the best. XX.PP XXThe player takes on the role of a starship commander XXwho is involved in a battle against enemy alien ships. XX.PP XXAt your control are the ships' massive warp engines, XXits main weapons, the phaser banks and photon torpedos, XXand its defensive set of shields. XXUsing these and your own ingenuity, you must form and XXimplement a strategy that will lead you to victory. XX.PP XXAlso at your disposal are such tactics as the defenseless ruse, XXand the corbomite bluff. XX.PP XXFor more information, see the document XX.I "The Star Trek Battle Manual". XX.SH AUTHORS XXWilliam K. Char, Perry Lee, and Dan Gee XXwrote the initial TREK73 in BASIC. XXDave Pare and Chris Williams translated the BASIC into C. XXJeff Okamoto, Peter Yee, and others corrected and enhanced the code. XX.SH SEE ALSO XXJeff Okamoto, XX.I "The Star Trek Battle Manual" XX.SH BUGS XXHopefully none. XXBug reports should be sent to: ..!ucbvax!okamoto and ..!ucbvax!yee. SHAR_EOF if test 1127 -ne "`wc -c trek73.6`" then echo shar: error transmitting trek73.6 '(should have been 1127 characters)' fi echo shar: done with directory =doc chdir .. # End of shell archive exit 0
okamoto@ucbvax.ARPA (Doctor Who) (09/16/85)
# This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. -----cut here-----cut here-----cut here-----cut here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # cmds1.c # cmds2.c # cmds3.c # cmds4.c # defines.h # dist.c # This archive created: Mon Sep 9 12:06:17 1985 echo shar: extracting cmds1.c '(9815 characters)' sed 's/^XX//' << \SHAR_EOF > cmds1.c XX/* XX * TREK73: cmds1.c XX * XX * User Commands XX * XX * fire_phasers, fire_tubes, lock_phasers, lock_tubes XX * turn_phasers, turn_tubes, load_tubes, launch_probe, XX * probe_control XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX XXextern char title[]; XXextern char science[]; XXextern char engineer[]; XXextern char nav[]; XXextern char helmsman[]; XX XXfire_phasers(sp) XXstruct ship *sp; XX{ XX char buf1[20]; XX char buf2[20]; XX char c; XX int typed[4]; XX register int i; XX register int k; XX XX for (i=0; i<4; i++) XX typed[i] = 0; XX printf(" fire phasers [1-4] "); XX if (Gets(buf1) == NULL) XX return 0; XX printf(" spread [10-45] "); XX if (Gets(buf2) == NULL) XX return 0; XX i = atoi(buf2); XX if (i < 10 || i > 45) XX return 0; XX sp->p_spread = i; XX for (i=0; c = buf1[i]; i++) { XX k = c - '1'; XX if (k < 0 || k > 3) XX continue; XX typed[k]++; XX if ((sp->phasers[k].status & P_DAMAGED) || XX (sp->phasers[k].status) & P_FIRING) XX continue; XX sp->phasers[k].status |= P_FIRING; XX } XX check_p_damage(typed, sp, "fire"); /* Type out if damaged */ XX check_p_turn(typed, sp, 1); XX return 1; XX} XX XX XXfire_tubes(sp) XXstruct ship *sp; XX{ XX char buf1[20]; XX char c; XX int typed[6]; XX register int i; XX register int j; XX register int k; XX XX for (i=0; i<6; i++) XX typed[i] = 0; XX printf(" fire tubes [1-6] "); XX if (Gets(buf1) == NULL) XX return 0; XX j = strlen(buf1); XX for (i=0; c = buf1[i]; i++) { XX k = c - '1'; XX if (k < 0 || k > 5) XX continue; XX typed[k]++; XX if ((sp->tubes[k].status & T_DAMAGED) || XX (sp->tubes[k].status & T_FIRING)) XX continue; XX sp->tubes[k].status |= T_FIRING; XX } XX check_t_damage(typed, sp, "fire"); /* Type if damaged */ XX check_t_turn(typed, sp, 1); XX j = 0; XX for (i=0; i<6; i++) { XX if ((typed[i] == 0) || (!(sp->tubes[i].status & T_FIRING))) XX continue; XX if (sp->tubes[i].load == 0) { XX if (!j) XX printf("Computer: Tube(s) %d", i + 1); XX else XX printf(", %d", i + 1); XX j++; XX } XX } XX if (j) XX printf(" have no charge in them.\n"); XX return 0; XX} XX XX XXlock_phasers(sp) XXstruct ship *sp; XX{ XX extern struct ship *ship_name(); XX char buf1[20]; XX char buf2[20]; XX int typed[4]; XX char c; XX struct ship *ep; XX register int i; XX register int k; XX XX for (i=0; i<4; i++) XX typed[i] = 0; XX if (sp->status & S_COMP) { XX printf("%s: Impossible %s, our computer is dead.\n", science, title); XX return 0; XX } XX printf(" lock phasers [1-4] "); XX if (Gets(buf1) == NULL) XX return 0; XX printf(" onto whom "); XX if (Gets(buf2) == NULL) XX return 0; XX ep = ship_name(buf2,ENEMYONLY); XX if (ep == NULL) XX return 0; XX for (i=0; c = buf1[i]; i++) { XX k = c - '1'; XX if (k < 0 || k > 3) XX continue; XX typed[k]++; XX if (sp->phasers[k].status & P_DAMAGED) XX continue; XX sp->phasers[k].target = ep; XX } XX check_p_damage(typed, sp, "lock"); XX check_p_turn(typed, sp, 0); XX return 1; XX} XX XX XXlock_tubes(sp) XXstruct ship *sp; XX{ XX extern struct ship *ship_name(); XX char buf1[20]; XX char buf2[20]; XX int typed[6]; XX char c; XX struct ship *ep; XX register int i; XX register int k; XX XX for (i=0; i<6; i++) XX typed[i] = 0; XX if (sp->status & S_COMP) { XX printf("%s: Impossible %s, our computer is dead.\n", science, title); XX return 0; XX } XX printf(" lock tubes [1-6] "); XX if (Gets(buf1) == NULL) XX return 0; XX printf(" onto whom "); XX if (Gets(buf2) == NULL) XX return 0; XX ep = ship_name(buf2,ENEMYONLY); XX if (ep == NULL) XX return 0; XX for (i=0; c = buf1[i]; i++) { XX k = c - '1'; XX if (k < 0 || k > 5) XX continue; XX typed[k]++; XX if (sp->tubes[k].status & T_DAMAGED) XX continue; XX sp->tubes[k].target = ep; XX } XX check_t_damage(typed, sp, "lock"); XX check_t_turn(typed, sp, 0); XX return 1; XX} XX XX XXturn_phasers(sp) XXstruct ship *sp; XX{ XX char buf1[20]; XX char buf2[20]; XX char c; XX int typed[4]; XX register int i; XX register int j; XX register int k; XX XX for (i=0; i<4; i++) XX typed[i] = 0; XX printf(" turn phasers [1-4] "); XX if (Gets(buf1) == NULL) XX return 0; XX printf(" to [0-360] "); XX if (Gets(buf2) == NULL) XX return 0; XX j = atoi(buf2); XX if (j < 0 || j > 360) XX return 0; XX for (i=0; c = buf1[i]; i++) { XX k = c - '1'; XX if (k < 0 || k > 3) XX continue; XX typed[k]++; XX if (sp->phasers[k].status & P_DAMAGED) XX continue; XX sp->phasers[k].target = NULL; XX sp->phasers[k].bearing = j; XX } XX check_p_damage(typed, sp, "turn"); XX check_p_turn(typed, sp, 0); XX return 1; XX} XX XX XXturn_tubes(sp) XXstruct ship *sp; XX{ XX char buf1[20]; XX char buf2[20]; XX char c; XX int typed[6]; XX register int i; XX register int j; XX register int k; XX XX for (i=0; i<6; i++) XX typed[i] = 0; XX printf(" turn tubes [1-6] "); XX if (Gets(buf1) == NULL) XX return 0; XX printf(" to [0-360] "); XX if (Gets(buf2) == NULL) XX return 0; XX j = atoi(buf2); XX if (j < 0 || j > 360) XX return 0; XX for (i=0; c = buf1[i]; i++) { XX k = c - '1'; XX if (k < 0 || k > 5) XX continue; XX typed[k]++; XX if (sp->tubes[k].status & T_DAMAGED) XX continue; XX sp->tubes[k].target = NULL; XX sp->tubes[k].bearing = j; XX } XX check_t_damage(typed, sp, "turn"); XX check_t_turn(typed, sp, 0); XX return 1; XX} XX XX XXload_tubes(sp) XXstruct ship *sp; XX{ XX char buf1[20]; XX char buf2[20]; XX char c; XX int load; XX struct tube *tp; XX register int i; XX register int j; XX register int k; XX XX load = 0; XX printf(" [load or unload] "); XX if (Gets(buf1) == NULL) XX return 0; XX if (*buf1 == 'l' || *buf1 == 'L') XX load++; XX else if (*buf1 != 'u' && *buf1 != 'U') XX return 0; XX printf(" tubes [1-6] "); XX if (Gets(buf2) == NULL) XX return 0; XX for (i=0; c = buf2[i]; i++) { XX if (sp->energy <= 0) XX break; XX k = c - '1'; XX if (k < 0 || k > 5) XX continue; XX tp = &sp->tubes[k]; XX if (tp->status & T_DAMAGED) XX continue; XX if (load) { XX j = min(sp->energy, 10-tp->load); XX if (j == 0) XX continue; XX sp->energy -= j; XX sp->pods -= j; XX tp->load += j; XX } else { XX j = tp->load; XX if (j == 0) XX continue; XX sp->energy += j; XX sp->pods += j; XX tp->load = 0; XX } XX } XX printf("%s: tubes now ", engineer); XX for (i=0; i<6; i++) { XX if (sp->tubes[i].status & T_DAMAGED) XX printf(" -- "); XX else XX printf(" %-2d ", sp->tubes[i].load); XX } XX printf(" pods at %d\n", sp->pods); XX return 1; XX} XX XX XXlaunch_probe(sp) XXstruct ship *sp; XX{ XX extern char captain[]; XX extern struct list *newitem(); XX char buf1[20]; XX int pods, delay, prox, course; XX struct ship *target; XX struct list *lp; XX struct torpedo *pp; XX XX pods = delay = prox = course = 0; XX target = NULL; XX if (sp->status & S_PROBE) { XX printf("%s: probe launcher destroyed!\n", engineer); XX return 0; XX } XX if (sp->energy < 10) { XX printf("%s: we've not enough power, Captain.\n", engineer); XX return 0; XX } XX printf("%s: %d pods available.\n", engineer, sp->energy); XX printf("%s: number to launch [10+] is ", captain); XX if (Gets(buf1) == NULL) XX return 0; XX pods = atoi(buf1); XX if (pods < 10 || pods > sp->energy) XX return 0; XX printf(" set time delay to [0-15] "); XX if (Gets(buf1) == NULL) XX return 0; XX delay = atoi(buf1); XX if (delay < 0 || delay > 15) XX return 0; XX printf(" set proximity delay to [50+] "); XX if (Gets(buf1) == NULL) XX return 0; XX prox = atoi(buf1); XX if (prox < 50) XX return 0; XX printf(" launch towards [whom, if anyone] "); XX Gets(buf1); XX /* XX * This must be fixed in the near future... XX */ XX if (*buf1) { XX target = ship_name(buf1,ENEMYONLY); XX if (target == NULL) XX return 0; XX } else { XX printf(" course [0-360] "); XX if (gets(buf1) == NULL) XX return 0; XX course = atoi(buf1); XX if (course < 0 || course > 360) XX return 0; XX target = NULL; XX } XX /* XX * add a new item to the list of items in space XX */ XX lp = newitem(I_PROBE); XX lp->data.tp = MKNODE(struct torpedo, *, 1); XX pp = lp->data.tp; XX pp->from = sp; XX pp->fuel = pods; XX pp->timedelay = delay * 10; XX pp->speed = sp->warp; XX pp->newspeed = 2.0; XX pp->prox = prox; XX pp->target = target; XX pp->course = course; XX pp->x = sp->x; XX pp->y = sp->y; XX pp->id = new_slot(); XX /* XX * subtract the pods used XX */ XX sp->pods -= pods; XX sp->energy -= pods; XX printf("%s: probe %d away\n",engineer, pp->id); XX return 1; XX} XX XX XXprobe_control(sp) XXstruct ship *sp; XX{ XX extern int rangefind(); XX extern int bearing(); XX extern struct list head; XX extern struct list *tail; XX register struct list *lp; XX register int i; XX register int j; XX register struct torpedo *pp; XX struct torpedo *probes[10]; XX int probenum; XX struct ship *ep; XX int pnum; XX int bear; XX int range; XX char buf1[20]; XX char *bp; XX XX pnum = 0; XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type != I_PROBE) XX continue; XX pp = lp->data.tp; XX if (pp->from != sp) XX continue; XX if (!pnum) XX printf("\nprobe bearng range course time prox units target\n"); XX probes[pnum] = pp; XX pnum++; XX range = rangefind(sp->x, pp->x, sp->y, pp->y); XX bear = bearing(sp->x, pp->x, sp->y, pp->y); XX if (pp->target == NULL) XX bp = "NONE"; XX else XX bp = pp->target->name; XX printf(" %2d %3d %5d %3d %2d %5d %3d %s\n", XX pp->id, bear, range, pp->course, pp->timedelay, XX pp->prox, pp->fuel, bp); XX } XX if (!pnum) { XX printf("%s: what probes?\n", nav); XX return 0; XX } XX printf("%s: detonate all probes?\n", nav); XX printf("%s: [yes or no] ", captain); XX if (Gets(buf1) != NULL && (*buf1 == 'Y' || *buf1 == 'y')) { XX printf("%s: aye, %s\n",nav, title); XX for (i=0; i<pnum; i++) XX probes[i]->timedelay = 0; XX return 1; XX } XX printf(" control probe [#] "); XX if (Gets(buf1) == NULL) XX return 0; XX probenum = atoi(buf1); XX for (i=0; i<pnum; i++) XX if (probes[i]->id == probenum) XX break; XX if (i == pnum) XX return 0; XX probenum = i; XX printf("%s: detonate it?\n", nav); XX printf("%s: [yes or no] ", captain); XX if (Gets(buf1) != NULL && (*buf1 == 'y' || *buf1 == 'Y')) { XX probes[probenum]->timedelay = 0; XX return 0; XX } XX printf(" lock it onto [whom] "); XX if (Gets(buf1) != NULL && *buf1 != NULL) { XX ep = ship_name(buf1,ENEMYONLY); XX if (ep != NULL) { XX probes[probenum]->target = ep; XX printf("%s: locking.\n", nav); XX return 1; XX } XX } XX printf(" set it to course [0-360] "); XX if (Gets(buf1) == NULL || *buf1 == NULL) XX return 0; XX j = atoi(buf1); XX if (j < 0 || j > 360) XX return 0; XX probes[probenum]->course = j; XX probes[probenum]->target = NULL; XX printf("%s: setting in new course.\n", nav); XX return 1; XX} SHAR_EOF if test 9815 -ne "`wc -c cmds1.c`" then echo shar: error transmitting cmds1.c '(should have been 9815 characters)' fi echo shar: extracting cmds2.c '(9808 characters)' sed 's/^XX//' << \SHAR_EOF > cmds2.c XX/* XX * TREK73: cmds2.c XX * XX * User Commands XX * XX * pos_report, pos_display, pursue, helm, self_scan, scan XX * XX * (print_damages) XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <stdio.h> XX#include <strings.h> XX XXextern char title[]; XXextern char science[]; XXextern char engineer[]; XXextern char helmsman[]; XXextern char nav[]; XX XX XXpos_report(sp) XXstruct ship *sp; XX{ XX extern int rangefind(); XX extern int bearing(); XX extern struct ship *shiplist[]; XX extern struct list head, *tail; XX struct ship *sp1; XX struct torpedo *tp; XX struct list *lp; XX int x, y; XX int range; XX int bear; XX float speed; XX int course; XX int maxlen = 0; XX char whitespace[5], who[80]; XX XX /* XX * Go through tht list of objects and find out the longest XX * name of any of them. This is to insure that no matter XX * what the names of the ship, the position report will XX * come out formatted. XX */ XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type == 0) XX continue; XX if (lp->type == I_SHIP) { XX sp1 = lp->data.sp; XX strcpy(who, sp1->name); XX maxlen = max(maxlen, strlen(who)); XX } else { XX tp = lp->data.tp; XX strcpy(who, tp->from->name); XX switch (lp->type) { XX case I_SHIP: XX case I_TORPEDO: XX continue; XX case I_PROBE: XX maxlen = max(maxlen, strlen(who) + 9); XX case I_ENG: XX maxlen = max(maxlen, strlen(who) + 12); XX break; XX default: XX break; XX } XX } XX } XX /* XX * Construct a string %ns where n is the length of the XX * longest name. XX */ XX sprintf(whitespace, "%%%ds", maxlen); XX /* XX * And print out the position report XX */ XX printf(whitespace, " "); XX printf(" warp course bearing range\n"); XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type == 0) XX continue; XX sp1 = NULL; XX tp = NULL; XX if (lp->type == I_SHIP) { XX sp1 = lp->data.sp; XX if (sp1->status & S_DEAD) XX continue; XX x = sp1->x; XX y = sp1->y; XX speed = sp1->warp; XX course = sp1->course; XX strcpy(who, sp1->name); XX } else { XX tp = lp->data.tp; XX if (lp->type == I_TORPEDO) XX continue; XX x = tp->x; XX y = tp->y; XX speed = tp->speed; XX course = tp->course; XX strcpy(who, tp->from->name); XX switch(lp->type) { XX case I_PROBE: XX sprintf(who, "%s probe %d", who, tp->id); XX break; XX case I_ENG: XX strcat(who, " engineering"); XX break; XX default: XX break; XX } XX } XX bear = bearing(sp->x, x, sp->y, y); XX range = rangefind(sp->x, x, sp->y, y); XX printf(whitespace, who); XX printf(" %4.1f %3d ", speed, course); XX if ((sp1 != NULL) && (sp1 == shiplist[0])) { XX if (shiplist[0]->target != NULL) XX if (shiplist[0]->eluding) XX printf("eluding %s\n", shiplist[0]->target->name); XX else XX printf("pursuing %s\n", shiplist[0]->target->name); XX else XX printf(" \n"); XX } else XX printf("%3d %5d\n", bear, range); XX } XX} XX XX XXpos_display(sp) XXstruct ship *sp; XX{ XX extern struct list head, *tail; XX register int i; XX register int j; XX int range; XX char buf1[20]; XX int x, y; XX float xf, yf; XX int h, v; XX struct list *lp; XX struct ship *sp1; XX struct torpedo *tp; XX char map[13][23]; XX char c; XX XX if (sp->status & S_SENSOR) { XX printf("%s: sensors are damaged.\n", science); XX return 0; XX } XX printf(" display to [100+] "); XX if (Gets(buf1) == NULL) XX return 0; XX range = atoi(buf1); XX if (range < 100 || range > 10000) XX return 0; XX /* XX * Compensation for aspect ratio of the output device XX */ XX x = range/10; XX y = range/6; XX for (i=0; i<13; i++) { XX if (i == 0 || i == 12) XX strcpy(map[i], "---------------------"); XX else XX strcpy(map[i], " "); XX } XX map[6][10] = '+'; XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->data.sp == sp) XX continue; XX if (lp->type == I_SHIP) { XX sp1 = lp->data.sp; XX xf = sp1->x - sp->x; XX yf = sp1->y - sp->y; XX } else { XX tp = lp->data.tp; XX xf = tp->x - sp->x; XX yf = tp->y - sp->y; XX } XX v = yf/y + 6.5; XX h = xf/x + 10.5; XX if (v < 0 || v > 12) XX continue; XX if (h < 0 || h > 20) XX continue; XX switch (lp->type) { XX case I_SHIP: XX c = lp->data.sp->name[0]; XX break; XX case I_TORPEDO: XX c = ':'; XX break; XX case I_ENG: XX c = '#'; XX break; XX case I_PROBE: XX c = '*'; XX break; XX default: XX c = '?'; XX break; XX } XX map[12 - v][h] = c; XX } XX for (i=0; i<13; i++) { XX for (j=0; j<21; j++) XX if (map[i][j] != ' ') XX break; XX if (j != 21) XX printf("%s", map[i]); XX printf("\n"); XX } XX return 0; XX} XX XX XXpursue(sp) XXstruct ship *sp; XX{ XX extern struct ship *ship_name(); XX extern double atof(); XX register int i; XX char buf1[20]; XX struct ship *ep; XX float warp; XX XX if (sp->status & S_COMP) { XX printf("%s: Impossible, %s, our computer is dead\n",science ,title); XX return 0; XX } XX printf(" Mr. %s, pursue [who] ", nav); XX if (Gets(buf1) == NULL) XX return 0; XX ep = ship_name(buf1,ENEMYONLY); XX if (ep == NULL) XX return 0; XX printf(" Mr. %s, warp factor [-9 to 9] ", helmsman); XX if (Gets(buf1) == NULL) XX return 0; XX warp = (float) atof(buf1); XX if (warp > 9.0 || warp < -9.0) { XX printf("%s: %s, the engines canna go that fast!\n",engineer, title); XX return 0; XX } XX if ((warp > 1.0 || warp < -1.0) && (sp->status & S_WARP)) { XX printf("%s: Warp drive is dead, Captain.\n", science); XX warp = warp < 0.0 ? -1.0 : 1.0; XX } XX sp->newwarp = warp; XX sp->target = ep; XX /* Set eluding flag to 0, which means pursue */ XX sp->eluding = 0; XX i = bearing(sp->x, ep->x, sp->y, ep->y); XX printf("%s: Aye, %s, coming to course %d.\n", nav, title, i); XX sp->newcourse = i; XX return 1; XX} XX XX XXelude(sp) XXstruct ship *sp; XX{ XX extern struct ship *ship_name(); XX extern double atof(); XX register int i; XX char buf1[20]; XX struct ship *ep; XX float warp; XX XX if (sp->status & S_COMP) { XX printf("%s: impossible, %s, our computer is dead\n",science, title); XX return 0; XX } XX printf(" Mr. %s, elude [who] ", nav); XX if ((Gets(buf1) == NULL) || (buf1 == NULL)) XX return 0; XX ep = ship_name(buf1,ENEMYONLY); XX if (ep == NULL) XX return 0; XX printf(" Mr. %s, warp factor [-9 to 9] ", helmsman); XX if (Gets(buf1) == NULL) XX return 0; XX warp = (float) atof(buf1); XX if (warp > 9.0 || warp < -9.0) { XX printf("%s: %s, the engines canna go that fast!\n",engineer, title); XX return 0; XX } XX if ((warp > 1.0 || warp < -1.0) && (sp->status & S_WARP)) { XX printf("%s: Warp drive is dead, Captain.\n", science); XX warp = warp < 0.0 ? -1.0 : 1.0; XX } XX sp->newwarp = warp; XX sp->target = ep; XX /* Set eluding flag to 1, which means elude */ XX sp->eluding = 1; XX i = bearing(sp->x, ep->x, sp->y, ep->y); XX i = rectify(i + 180); XX printf("%s: Aye, %s, coming to course %d.\n", nav, title, i); XX sp->newcourse = i; XX return 1; XX} XX XXhelm(sp) XXstruct ship *sp; XX{ XX extern double atof(); XX char buf1[20]; XX register int course; XX float warp; XX XX printf(" Mr. %s, come to course [0-359] ", nav); XX if (Gets(buf1) == NULL) XX return 0; XX course = atoi(buf1); XX if (course < 0 || course > 360) XX return 0; XX printf(" Mr. %s, warp factor [-9 to 9] ", helmsman); XX if (Gets(buf1) == NULL) XX return 0; XX warp = (float) atof(buf1); XX if (warp > 9.0 || warp < -9.0) { XX printf("%s: %s, the engines canna go that fast!\n",engineer, title); XX return 0; XX } XX if ((warp > 1.0 || warp < -1.0) && (sp->status & S_WARP)) { XX printf("%s: Warp drive is dead, Captain.\n", science); XX warp = warp < 0.0 ? -1.0 : 1.0; XX } XX sp->newwarp = warp; XX sp->newcourse = course; XX sp->target = NULL; XX sp->eluding = 0; XX printf("%s: aye, %s.\n", nav, title); XX return 1; XX} XX XXself_scan(sp) XXstruct ship *sp; XX{ XX struct ship *ep; XX extern struct ship *shiplist[]; XX XX ep = shiplist[0]; /* Scanning ourself */ XX print_damage(ep); XX sp = sp; /* LINT */ XX return 1; XX} XX XXscan(sp) XXstruct ship *sp; XX{ XX struct ship *ep; XX char buf1[20]; XX XX printf(" %s, scan [who] ", science); XX if (Gets(buf1) == NULL) XX return 0; XX ep = ship_name(buf1,ENEMYONLY); XX if (ep == NULL) XX return 0; XX if (sp != ep && (sp->status & S_SENSOR)) { XX printf ("%s: The sensors are damaged, Captain.\n", science); XX return 0; XX } XX if (sp == ep) { XX printf ("%s: Captain, don't you mean 'Damage Report'?\n", science); XX return 0; XX } XX print_damage(ep); XX return 1; XX} XX XXprint_damage(ep) XXstruct ship *ep; XX{ XX extern char *statmsg[]; XX register int i; XX register int j; XX register float k; XX XX printf("\n\nDamages to the %s\n", ep->name); XX for (i=0; i<5; i++) { XX if (ep->status & 1<<i) XX printf("%s.\n", statmsg[i]); XX } XX printf("survivors: %d\n", ep->crew); XX printf("\nPhasers Control"); XX for (i=0; i<4; i++) { XX if (ep->phasers[i].status & P_DAMAGED) XX printf("\tdamaged"); XX else if (ep->phasers[i].target == NULL) XX printf("\tmanual"); XX else XX printf("\t%.7s", ep->phasers[i].target->name); XX } XX printf("\n\t turned"); XX for (i=0; i<4; i++) XX if (ep->phasers[i].status & P_DAMAGED) XX printf("\t"); XX else if (ep->phasers[i].target == NULL) XX printf("\t%d", ep->phasers[i].bearing); XX else XX printf("\tLOCKED"); XX printf("\n\t level"); XX for (i=0; i<4; i++) XX if (ep->phasers[i].status & P_DAMAGED) XX printf("\t"); XX else XX printf("\t%-2d", ep->phasers[i].load); XX printf("\n"); XX printf("\nTubes\tcontrol"); XX for (i=0; i<6; i++) { XX if (ep->tubes[i].status & T_DAMAGED) XX printf("\tdamaged"); XX else if (ep->tubes[i].target == NULL) XX printf("\tmanual"); XX else XX printf("\t%.7s", ep->tubes[i].target->name); XX } XX printf("\n\t turned"); XX for (i=0; i<6; i++) XX if (ep->tubes[i].status & T_DAMAGED) XX printf("\t"); XX else if (ep->tubes[i].target == NULL) XX printf("\t%d", ep->tubes[i].bearing); XX else XX printf("\tLOCKED"); XX printf("\n\t level"); XX for (i=0; i<6; i++) XX if (ep->tubes[i].status & T_DAMAGED) XX printf("\t"); XX else XX printf("\t%-2d", ep->tubes[i].load); XX printf("\n"); XX printf("\nShields\t levels"); XX for (i=0; i<4; i++) { XX j = 100 * ep->shields[i].eff * ep->shields[i].drain; XX printf("\t%-2d", j); XX } XX printf("\n\t drains"); XX for (i=0; i<4; i++) { XX k = ep->shields[i].attemp_drain; XX printf("\t%-4.2f", k); XX } XX printf("\n\nefficiency: %3.1f\t\tfuel remaining: %d\n", XX ep->eff, ep->energy); XX printf("regeneration: %4.1f\tfuel capacity: %d\n", XX ep->regen, ep->pods); XX return 1; XX} SHAR_EOF if test 9808 -ne "`wc -c cmds2.c`" then echo shar: error transmitting cmds2.c '(should have been 9808 characters)' fi echo shar: extracting cmds3.c '(5051 characters)' sed 's/^XX//' << \SHAR_EOF > cmds3.c XX/* XX * TREK73: cmds3.c XX * XX * User Commands XX * XX * jettison_engineering, detonate_engineering, phaser_status, tube_status, XX * survivors, alter_power XX * XX * (do_jettison) XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <ctype.h> XX#include <stdio.h> XX XXextern char title[]; XXextern char engineer[]; XX XXjettison_engineering(sp) XXstruct ship *sp; XX{ XX XX printf(" Mr. %s, jettison our engineering section!\n", engineer); XX if (sp->status & S_ENG) { XX printf("%s: But Captain, it's already jettisonned.\n", engineer); XX return 0; XX } XX do_jettison(sp); XX printf("%s: Jettisoning engineering.\n", engineer); XX return 1; XX} XX XXdo_jettison(sp) XXstruct ship *sp; XX{ XX extern struct list *newitem(); XX register struct list *lp; XX register struct torpedo *tp; XX XX lp = newitem(I_ENG); XX tp = lp->data.tp = MKNODE(struct torpedo, *, 1); XX tp->target = NULL; XX tp->speed = sp->warp; XX tp->newspeed = 0.0; XX tp->x = sp->x; XX tp->y = sp->y; XX tp->course = sp->course; XX tp->fuel = sp->pods; XX tp->timedelay = 10 * 10; XX tp->prox = 0; XX tp->from = sp; XX tp->id = new_slot(); XX sp->energy = sp->pods = 0; XX sp->newwarp = .99 * (sp->warp < 0.0 ? -1.0 : 1.0); XX sp->regen = 0.0; XX sp->status |= S_ENG; XX sp->status |= S_WARP; XX} XX XXdetonate_engineering(sp) XXstruct ship *sp; XX{ XX extern struct list head; XX extern struct list *tail; XX register struct list *lp; XX register struct torpedo *tp; XX register int found; XX char buf[10]; XX XX found = 0; XX printf(" %s, detonate engineering!\n", engineer); XX if (!(sp->status & S_ENG)) { XX printf("%s: But %s, it's still attached.\n",engineer,title); XX printf(" Detonate anyway? "); XX if ((Gets(buf) == NULL) || (buf == NULL)) XX return 0; XX if (buf[0] != 'y') XX return 0; XX else XX do_jettison(sp); XX } XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type != I_ENG) XX continue; XX tp = lp->data.tp; XX if (tp->from != sp) XX continue; XX found++; XX tp->timedelay = 1; XX break; XX } XX if (found) XX printf("%s: Aye, %s.\n",engineer, title); XX else XX printf("%s: Ours has already detonated.\n", engineer); XX return 1; XX} XX XX XXphaser_status(sp) XXstruct ship *sp; XX{ XX register int i; XX XX printf("Phasers\n\n"); XX printf("Control: "); XX for (i=0; i<4; i++) { XX if (sp->phasers[i].status & P_DAMAGED) XX printf("\tdamaged"); XX else if (sp->phasers[i].target == NULL) XX printf("\tmanual"); XX else XX printf("\t%.7s", sp->phasers[i].target->name); XX } XX printf("\n Turned: "); XX for (i=0; i<4; i++) XX if (sp->phasers[i].status & P_DAMAGED) XX printf("\t"); XX else if (sp->phasers[i].target == NULL) XX printf("\t%d", sp->phasers[i].bearing); XX else XX printf("\tLOCKED"); XX printf("\n Level: "); XX for (i=0; i<4; i++) { XX if (sp->phasers[i].status & P_DAMAGED) XX printf("\t"); XX else XX printf("\t%d", sp->phasers[i].load); XX } XX printf("\n Drain: "); XX for (i=0; i<4; i++) { XX if (sp->phasers[i].status & P_DAMAGED) XX printf("\t"); XX else XX printf("\t%d", sp->phasers[i].drain); XX } XX printf("\n\nFiring percentage: %d\n",sp->p_percent); XX return 1; XX} XX XXtube_status(sp) XXstruct ship *sp; XX{ XX register int i; XX XX printf("Torpedos\n\n"); XX printf("Control: "); XX for (i=0; i<6; i++) { XX if (sp->tubes[i].status & T_DAMAGED) XX printf("\tdamaged"); XX else if (sp->tubes[i].target == NULL) XX printf("\tmanual"); XX else XX printf("\t%.7s", sp->tubes[i].target->name); XX } XX printf("\n Turned: "); XX for (i=0; i<6; i++) XX if (sp->tubes[i].status & T_DAMAGED) XX printf("\t"); XX else if (sp->tubes[i].target == NULL) XX printf("\t%d", sp->tubes[i].bearing); XX else XX printf("\tLOCKED"); XX printf("\n Level: "); XX for (i=0; i<6; i++) { XX if (sp->tubes[i].status & T_DAMAGED) XX printf("\t"); XX else XX printf("\t%d", sp->tubes[i].load); XX } XX printf("\n\nLaunch speed: %d\n", sp->t_lspeed); XX printf(" time delay: %d\n", sp->t_delay); XX printf(" prox delay: %d\n", sp->t_prox); XX return 1; XX} XX XXsurvivors(sp) XXstruct ship *sp; XX{ XX extern struct ship *shiplist[]; XX extern int shipnum; XX struct ship *ep; XX register int i; XX XX printf("\nSurvivors reported:\n"); XX for (i=0; i<=shipnum; i++) { XX ep = shiplist[i]; XX printf(" %s -- %d\n", ep->name, ep->crew); XX } XX sp = sp; /* LINT */ XX} XX XXalter_power() XX{ XX extern char **argp; XX extern struct ship *shiplist[]; XX extern char captain[]; XX extern double atof(); XX register int i; XX float j; XX char buf1[20]; XX XX printf("\n%s: Regeneration rate is %5.2f.\n",engineer, shiplist[0]->regen); XX for (i=0; i<4; i++) { XX printf("%s: Shield %d drain is ", captain, i + 1); XX Gets(buf1); XX j = (float) atof(buf1); XX if (buf1[strlen(buf1) - 1] == '*') { XX for (; i<4; i++) XX shiplist[0]->shields[i].attemp_drain =j; XX break; XX } else if ((j < 0.0) || (j > 1.0)) XX goto badparam; XX else XX shiplist[0]->shields[i].attemp_drain = j; XX } XX printf("\n"); XX for (i=0; i<4; i++) { XX printf("%s: Phaser %d drain is ", captain, i + 1); XX Gets(buf1); XX j = (float) atof(buf1); XX if (buf1[strlen(buf1) - 1] == '*') { XX for (; i<4; i++) XX shiplist[0]->phasers[i].drain = (int) j; XX break; XX } else if ((j < -10.0) || (j > 10.0)) XX goto badparam; XX else XX shiplist[0]->phasers[i].drain = (int) j; XX } XX return 1; XXbadparam: XX printf("%s: Bad parameters, %s.\n", engineer, title); XX return 0; XX} SHAR_EOF if test 5051 -ne "`wc -c cmds3.c`" then echo shar: error transmitting cmds3.c '(should have been 5051 characters)' fi echo shar: extracting cmds4.c '(8534 characters)' sed 's/^XX//' << \SHAR_EOF > cmds4.c XX/* XX * TREK73: cmds4.c XX * XX * User Commands XX * XX * alterpntparams, play_dead, corbomite_bluff, surrender_ship, XX * request_surrender, self_destruct, abort_self_destruct XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <stdio.h> XX XXextern int defenseless; XXextern char captain[]; XXextern char title[]; XXextern char science[]; XXextern char com[]; XXextern char nav[]; XXextern char helmsman[]; XXextern char engineer[]; XXextern char foerace[]; XXextern int corbomite; XXextern int surrender; XXextern int surrenderp; XX XXalterpntparams(sp) XXstruct ship *sp; XX{ XX int temp; XX char buf1[30]; XX XX printf("\n%s: Reset tubes, %s?\n",nav,title); XX printf("%s: [yes or no] ",captain); XX if (Gets(buf1) == NULL) XX return 0; XX if ((buf1 != NULL) && (buf1[0] != 'n')) { XX printf(" Set launch speed to [0-12] "); XX if (Gets(buf1) == NULL) XX return 0; XX if (buf1 != NULL) { XX temp = atoi(buf1); XX if ((temp > -1) && (temp < 13)) XX sp->t_lspeed = temp; XX } XX printf(" ...time delay to [0-10] "); XX if (Gets(buf1) == NULL) XX return 0; XX if (buf1 != NULL) { XX temp = atoi(buf1); XX if ((temp > -1) && (temp < 11)) XX sp->t_delay = temp; XX } XX printf(" ...proximity delay to [0-500] "); XX if (Gets(buf1) == NULL) XX return 0; XX if (buf1 != NULL) { XX temp = atoi(buf1); XX if ((temp > -1) && (temp < 501)) XX sp->t_prox = temp; XX } XX } XX printf("%s: Reset phasers, %s?\n",nav ,title); XX printf("%s: [yes or no] ",captain); XX if (Gets(buf1) == NULL) XX return 0; XX if ((buf1 != NULL) && (buf1[0] != 'n')) { XX printf(" Reset firing percentage to [0-100] "); XX if (Gets(buf1) == NULL) XX return 0; XX if (buf1 != NULL) { XX temp = atoi(buf1); XX if ((temp > -1) && (temp < 101)) XX sp->p_percent = temp; XX } XX } XX return 0; XX} XX XXplay_dead(sp) XXstruct ship *sp; XX{ XX XX char buf1[30]; XX int phaser_charge; XX register int i; XX XX printf("%s: Weapons officer, drop shields ...\n",captain); XX if (defenseless) { XX printf("%s: %s, the %ss are not that stupid.",science, title,foerace); XX return 0; XX } XX printf(" Transfer power to [engines or phasers]: "); XX if (Gets(buf1) == NULL || *buf1 == NULL) { XX printf("%s: What?\n", nav); XX return 0; XX } XX phaser_charge = -10.; XX if (buf1[0] != 'e') { XX phaser_charge = 10.; XX if (buf1[0] != 'p') { XX printf("%s: What?\n", nav); XX return 0; XX } XX } XX for (i=0;i<4;i++) XX sp->shields[i].attemp_drain = 0.; XX for (i=0;i<4;i++) XX sp->phasers[i].drain = phaser_charge; XX defenseless = 1; XX return 0; XX} XX XXcorbomite_bluff(sp) XXstruct ship *sp; XX{ XX XX if (randm(2) == 1) { XX printf("%s: Open a hailing frequency, ship-to-ship.\n",captain); XX printf("%s: Hailing frequency open, %s.\n", com, title); XX printf("%s: This is the Captain of the %s. Our respect for\n",captain, sp->name); XX printf(" other life forms requires that we give you this warning--\n"); XX printf(" one critical item of information which has never been\n"); XX printf(" incorporated into the memory banks of any Earth ship.\n"); XX printf(" Since the early years of space exploration, Earth vessels\n"); XX printf(" have had incorporated into them a substance know as corbomite.\n"); XX if (!corbomite) { XX printf(" It is a material and a device which prevents attack on\n"); XX printf(" us. If any destructive energy touchs our vessel, a re-\n"); XX printf(" verse reaction of equal strength is created, destroying\n"); XX printf(" the attacker. It may interest you to know that, since\n"); XX printf(" the initial use of corbomite for more than two of our\n"); XX printf(" centuries ago, no attacking vessel has survived the attempt.\n"); XX printf(" Death has little meaning to us. If it has none to you,\n"); XX printf(" then attack us now. We grow annoyed with your foolishness.\n"); XX } XX } else { XX printf("%s: Open a special channel to Starfleet Command.\n",captain); XX printf("%s: Aye, %s.\n",com, title); XX printf("%s: Use Code 2.\n",captain); XX printf("%s: but, Captain, according to our last Starfleet\n", com); XX printf(" Bulletin, the %ss have broken code 2.\n",foerace); XX printf("%s: That's an order, Lieutenant. Code 2!\n",captain); XX printf("%s: Yes, Captain. Code 2.\n", com); XX printf("%s: Message from %s to Starfleet Command, this sector.\n",captain,sp->name); XX printf(" have inadvertantly encroached upon %s neutral zone,\n",foerace); XX printf(" surrounded and under heavy %s attack. Escape\n",foerace); XX printf(" impossible. Shields failing. Will implement destruct\n"); XX printf(" order using corbomite device recently installed.\n"); XX if (!corbomite) { XX printf(" This will result in the destruction of the %s and\n",sp->name); XX printf(" all matter within a 200 megameter diameter and\n"); XX printf(" establish corresponding dead zone, all federation\n"); XX printf(" vessels will aviod this area for the next four solar\n"); XX printf(" years. Explosion will take place in one minute. %s,\n",captain); XX printf(" commanding %s, out.\n",sp->name); XX } XX } XX if (!corbomite) { XX printf(" Mr. %s. Stand by.\n", helmsman); XX printf("%s: Standing by.\n", helmsman); XX corbomite = 1; XX } else { XX printf("\n%s: I don't believe that they will fall for tha maneuver\n", science); XX printf(" again, %s.\n",title); XX } XX return 0; XX} XX XXsurrender_ship(sp) XXstruct ship *sp; XX{ XX printf("%s: Lieutenant, open a channel to the %ss.\n", captain, foerace); XX printf("%s: Aye, %s.\n", com, title); XX printf("%s: This is Captain %s of the U. S. S. %s. Will\n",captain,captain,sp->name); XX printf(" you accept my unconditional surrender?\n"); XX if (surrender) { XX printf("%s: The %ss have already refused.\n",science, foerace); XX } else { XX if (foerace == "Romulan") { XX printf("%s: The %ss have not been know to have taken\n",science, foerace); XX printf(" prisoners.\n"); XX } XX surrender = 1; XX } XX return 0; XX} XX XXrequest_surrender(sp) XXstruct ship *sp; XX{ XX printf("%s: Lieutenant, open a hailing frequency to the %ss.\n",captain,foerace); XX printf("%s: Aye, %s.\n", com, title); XX printf("%s: This is Captain %s of the U. S. S. %s. I give you\n",captain, captain, sp->name); XX printf(" one last chance to surrender before we resume our attack.\n"); XX if (surrenderp) { XX printf("%s: %s, our offer has already been refused.\n",science, title); XX } else { XX surrenderp = 1; XX } XX return 0; XX} XX XXself_destruct(sp) XXstruct ship *sp; XX{ XX printf("%s: Lieutenant %s, tie in the bridge to the master\n",captain, com); XX printf(" computer.\n"); XX if (sp->status & S_COMP) { XX printf("%s: Our computer is down.\n", science); XX return 0; XX } XX printf("%s: Aye, %s.\n",com, title); XX printf("%s: Computer. Destruct sequence. Are you ready to copy?\n",captain); XX printf("Computer: Working.\n"); XX printf("%s: Computer, this is Captain %s of the U. S. S. %s.\n",captain,captain,sp->name); XX printf(" destruct sequence one, code 1-1a.\n"); XX printf("Computer: Voice and code verified and correct.\n"); XX printf(" Sequence one complete.\n"); XX printf("%s: This is Commander %s, Science Officer. Destruct\n", science, science); XX printf(" sequence two, code 1-1a-2b.\n"); XX printf("Computer: Voice and code verified and correct. Sequence\n"); XX printf(" two complete.\n"); XX printf("%s: This is Lieutenant Commander %s, Chief Engineering\n", engineer, engineer); XX printf(" Officer of the U. S. S. %s. Destruct sequence\n",sp->name); XX printf(" number three, code 1-b2-b3.\n"); XX printf("Computer: Voice and code verified and correct.\n"); XX printf(" Destruct sequence complete and engaged. Awaiting final\n"); XX printf(" code for twenty second countdown.\n"); XX printf("%s: Computer, this is Captain %s of the U. S. S. %s.\n",captain, captain, sp->name); XX printf(" begin countdown, code 0-0-0, destruct 0.\n"); XX printf("Computer: 20 seconds to self-detruct.\n"); XX sp->delay = 9 * 20; XXreturn 0; XX} XX XXabort_self_destruct(sp) XXstruct ship *sp; XX{ XX printf("%s: Computer, this is Captain %s of the U. S. S. %s.\n",captain,captain,sp->name); XX printf(" Code 1-2-3 continuity abort destruct order, repeat:\n"); XX printf(" Code 1-2-3 continuity abort destruct order!\n"); XX if (sp->status & S_COMP) { XX printf("%s: Our computer is down.\n", science); XX return 0; XX } XX if (sp->delay > 1000) { XX printf("Computer: Self-destruct sequence has not been\n"); XX printf(" initiated.\n"); XX return 0; XX } XX printf("Computer: Self-destruct order ..."); XX fflush(stdout); XX sleep(4); XX if (sp->delay > 4 * 9) { XX printf("aborted. Destruct order aborted.\n"); XX sp->delay = 10000; XX return 0; XX } else { XX printf("\n%s: Too late, captain ...\n", science); XX return 0; XX } XX} SHAR_EOF if test 8534 -ne "`wc -c cmds4.c`" then echo shar: error transmitting cmds4.c '(should have been 8534 characters)' fi echo shar: extracting defines.h '(1508 characters)' sed 's/^XX//' << \SHAR_EOF > defines.h XX/* XX * TREK73: defines.h XX * XX * Defines for TREK73 XX * XX */ XX XX/* Globals externals */ XXextern char *malloc(), *strcpy(), *gets(); XXextern long random(); XX XX#define toradians(x) ((float)(x)*.0174533) XX#define todegrees(x) ((float)(x)*57.2958) XX#define randm(x) (((int)random() % (x)) + 1) XX XX#define min(x, y) ((x) < (y) ? (x) : (y)) XX#define max(x, y) ((x) > (y) ? (x) : (y)) XX XX#ifndef NULL XX#define NULL 0 XX#endif XX XX/* XX * for the item linked list XX */ XX#define I_UNDEFINED 0 XX#define I_SHIP 1 XX#define I_TORPEDO 2 XX#define I_PROBE 3 XX#define I_ENG 4 XX XX/* XX * for the ship status word XX */ XX#define S_NORMAL 000 XX#define S_COMP 001 XX#define S_SENSOR 002 XX#define S_PROBE 004 XX#define S_WARP 010 XX#define S_ENG 020 XX#define S_DEAD 040 XX#define S_SURRENDER 0100 XX XX/* XX * for the status message turn off array XX */ XX#define DISENGAGE 1 XX#define SHIELDSF 2 XX#define PHASERS 3 XX#define TUBES 7 XX#define SURRENDER 13 XX#define SURRENDERP 14 XX#define PLAYDEAD 15 XX#define CORBOMITE 16 XX#define BURNOUT 17 XX#define HIGHSHUTUP 27 XX XX/* XX * Defines for the play status word XX */ XX#define NORMAL 000 XX#define F_SURRENDER 001 XX#define E_SURRENDER 002 XX XX/* XX * Phaser statuses XX */ XX#define P_NORMAL 000 XX#define P_DAMAGED 001 XX#define P_FIRING 002 XX XX/* XX * Tube statuses XX */ XX#define T_NORMAL 000 XX#define T_DAMAGED 001 XX#define T_FIRING 002 XX XX/* XX * Ship search routine directives XX */ XX#define ALL 0 XX#define ENEMYONLY 1 XX XX#define MKNODE(cast, star, number) (cast star)malloc(sizeof(cast) * number) XX XX#define MAXBADS 9 XX#define MAXFEDS 9 XX#define MAXENCOMM 9 XX#define MAXFOERACES 9 SHAR_EOF if test 1508 -ne "`wc -c defines.h`" then echo shar: error transmitting defines.h '(should have been 1508 characters)' fi echo shar: extracting dist.c '(2568 characters)' sed 's/^XX//' << \SHAR_EOF > dist.c XX/* XX * TREK73: dist.c XX * XX * Power distribution routines XX * XX * distribute XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <math.h> XX XXextern char engineer[]; XX XXdistribute(sp) XXstruct ship *sp; XX{ XX extern char title[]; XX register int i; XX register int fuel; XX register int load; XX register int effload; XX register int drain; XX float shield; XX extern char shutup[]; XX extern struct ship *shiplist[]; XX XX fuel = sp->energy + (int)(sp->regen * 2); XX /* XX * Calculate negative phaser drains XX */ XX for (i=0; i<4; i++) { XX load = sp->phasers[i].load; XX drain = sp->phasers[i].drain; XX if ((sp->phasers[i].status & P_DAMAGED) || (drain >= 0) XX || (sp->phasers[i].load <= 0)) XX continue; XX /* XX * Drain the lesser of either the current load if the XX * load is less than the drain, or the drain value XX */ XX if (drain < 0) { XX effload = max(load + drain, 0); XX fuel += load - effload; XX sp->phasers[i].load = effload; XX } XX } XX /* XX * Calculate shield drains XX */ XX shield = 0.0; XX for (i=0; i<4; i++) XX shield += sp->shields[i].attemp_drain; XX drain = ceil((double) shield); XX /* XX * If all attempted drains are zero, or we have no XX * fuel, our shields are down! XX */ XX if (((shield == 0) || (fuel == 0)) && !shutup[SHIELDSF] && sp == shiplist[0]) { XX printf("%s: %s, our shields are down!\n",engineer, title); XX shutup[SHIELDSF]++; XX } XX /* XX * If there's not enough fuel to sustain the drains, then XX * ration it out in proportion to the attempted drains and XX * say that shields are fluctuating. XX */ XX if (drain <= fuel) { XX fuel -= drain; XX for (i=0; i<4; i++) XX sp->shields[i].drain = sp->shields[i].attemp_drain; XX } else { XX if (!shutup[SHIELDSF] && sp == shiplist[0]) { XX printf("%s: %s, our shields are fluctuating!\n", engineer, title); XX shutup[SHIELDSF]++; XX } XX for (i=0; i<4; i++) XX if (!sp->shields[i].attemp_drain) XX sp->shields[i].drain = sp->shields[i].attemp_drain * (float) fuel / drain; XX else XX sp->shields[i].drain = 0; XX fuel = 0; XX } XX /* XX * Calculate positive phaser drains XX */ XX for (i=0; i<4 && fuel > 0; i++) { XX if (fuel <=0) XX break; XX load = sp->phasers[i].load; XX drain = sp->phasers[i].drain; XX if ((sp->phasers[i].status & P_DAMAGED) || load >= 10 || drain <= 0) XX continue; XX /* XX * Load phasers either enough to top them off, or XX * the full drain XX */ XX if (drain > 0) { XX effload = min(10, load + min(drain, fuel)); XX fuel -= effload - load; XX sp->phasers[i].load = effload; XX } XX } XX /* XX * Now balance the level of energy with the numer of pods XX */ XX if (fuel > sp->pods) XX sp->energy = sp->pods; XX else XX sp->energy = fuel; XX} SHAR_EOF if test 2568 -ne "`wc -c dist.c`" then echo shar: error transmitting dist.c '(should have been 2568 characters)' fi # End of shell archive exit 0
okamoto@ucbvax.ARPA (Doctor Who) (09/16/85)
# This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. -----cut here-----cut here-----cut here-----cut here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # endgame.c # enemycom.c # firing.c # globals.c # This archive created: Mon Sep 9 12:06:55 1985 echo shar: extracting endgame.c '(4612 characters)' sed 's/^XX//' << \SHAR_EOF > endgame.c XX/* XX * TREK73: endgame.c XX * XX * prints end-of-game messages and warnings XX * XX * leftovers, final, warn XX * XX */ XX XX#include <sys/file.h> XX#include "defines.h" XX#include "structs.h" XX XXextern char captain[]; XXextern char title[]; XXextern char science[]; XXextern char com[]; XXextern char helmsman[]; XXextern char foerace[]; XXextern char foename[]; XXextern char foestype[]; XXextern char empire[]; XXextern int reengaged; XX XXleftovers() XX{ XX extern struct list head; XX extern struct list *tail; XX register struct list *lp; XX XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type == 0) XX continue; XX if (lp->type != I_SHIP) XX return 1; XX } XX return 0; XX} XX XX XXfinal(mesg) XXint mesg; XX{ XX extern struct ship *shiplist[]; XX extern int shipnum; XX register int i; XX register int j; XX struct ship *sp; XX struct ship *ep; XX char buf[80]; XX extern char *plural(); XX XX XX sp = shiplist[0]; XX /* If we're getting that message again, ignore it. */ XX if ((mesg == 2) && (reengaged)) XX return; XX switch (mesg) { XX case 0: XX starfleet(); XX printf("We have recieved confirmation that the USS %s,\n", XX sp->name); XX printf(" captained by %s, was destroyed by %s%s\n",captain, shipnum==1 ?"a ":"", foerace); XX printf(" %s%s. May future Federation officers\n", foestype, plural(shipnum)); XX printf(" perform better in their duties.\n\n"); XX break; XX case 1: XX starfleet(); XX printf("We commend Captain %s and his crew on their\n",captain); XX printf(" fine performance against the %ss. May he\n",foerace); XX printf(" be an inspiration to future starship captains.\n"); XX break; XX case 2: XX /* XX * Give him a chance to re-engage if he wants to. If he does, XX * he has to get within a range of 3500 before he can again XX * try to dis-engage XX */ XX if (!reengaged) { XX printf("%s: %s, we are in a position to either disengage from the\n", science, title); XX printf(" %ss, or re-engage them in combat.\n", foerace); XX printf(" Do you wish to re-engage?\n"); XX printf("%s: [y or n] ", captain); XX gets(buf); XX if ((*buf == NULL) || (*buf == 'y') || (*buf == 'Y')) { XX reengaged = 1; XX return; XX } XX } XX starfleet(); XX printf("Captain %s of the starship %s has\n",captain,sp->name); XX printf(" out-maneuvered %s aggressors. We commend\n",foerace); XX printf(" his tactical ability.\n"); XX break; XX case 3: XX starfleet(); XX printf("Captain %s of the starship %s has\n",captain,sp->name); XX printf(" surrendered his vessel to the %ss. May\n",foerace); XX printf(" Captain Donsell be remembered.\n"); XX break; XX case 4: XX starfleet(); XX printf("We have recieved word from the %s that the\n",sp->name); XX printf(" %ss have surrendered.\n",foerace); XX break; XX case 5: XX starfleet(); XX printf("One of our vessels has encountered the wreckage of\n"); XX printf(" the %s and %d other %s vessel%s.\n", sp->name, XX shipnum, foerace, plural(shipnum)); XX break; XX default: XX printf("how did we get here?\n"); XX break; XX } XX printf("\n\n"); XX j = 0; XX for (i=0; i<=shipnum; i++) { XX ep = shiplist[i]; XX if (ep->status & S_DEAD) XX continue; XX if (!j) XX printf("Survivors Reported:\n"); XX j++; XX } XX if (j) { XX for (i=0; i<=shipnum; i++) { XX ep = shiplist[i]; XX if ((ep->status & S_DEAD) || (ep->crew == 0)){ XX printf(" %s -- destroyed.\n",ep->name); XX } XX else XX printf(" %s -- %d\n", ep->name, ep->crew); XX } XX } else XX printf("*** No survivors reported ***\n"); XX exit (1); XX} XX XX XX XXwarn(mesg) XXint mesg; XX{ XX extern struct ship *shiplist[]; XX static int beenhere[5] = {0, 0, 0, 0, 0}; XX struct ship *sp; XX XX if ((reengaged) && (mesg == 2)) { XX return 0; XX } XX if (beenhere[mesg]) XX return 0; XX sp = shiplist[0]; XX switch (mesg) { XX case 0: XX printf("Message to the Federation: This is Commander\n"); XX printf(" %s of the %s %s. We have defeated\n", foename, foerace, empire); XX printf(" the %s and are departing the quadrant.\n", sp->name); XX break; XX case 1: XX printf("%s: All %s vessels have been either\n", science, foerace); XX printf(" destroyed or crippled. We still, however, have\n"); XX printf(" antimatter devices to avoid.\n"); XX break; XX case 2: XX printf("%s: The %ss are falling behind and seem to\n", helmsman, foerace); XX printf(" be breaking off their attack.\n"); XX break; XX case 3: XX printf("%s: I'm informing Starfleet Command of our \n", com); XX printf(" disposition.\n"); XX break; XX case 4: XX printf("%s: Although the %ss have surrendered,\n",science, foerace); XX printf(" there are still antimatter devices floating\n"); XX printf(" around us.\n"); XX break; XX default: XX printf("how did we get here?\n"); XX break; XX } XX beenhere[mesg]++; XX return 0; XX} XX XXstarfleet() XX{ XX printf("\n\nStarfleet Command: \n"); XX sleep(3); XX printf("\n"); XX} SHAR_EOF if test 4612 -ne "`wc -c endgame.c`" then echo shar: error transmitting endgame.c '(should have been 4612 characters)' fi echo shar: extracting enemycom.c '(8299 characters)' sed 's/^XX//' << \SHAR_EOF > enemycom.c XX/* XX * TREK73: enemycom.c XX * XX * Enemy strategy sub-routines XX * XX * e_phasers, e_lockphasers, e_locktubes, e_checkprobe, e_evade, XX * e_pursue, e_launchprobe, e_destruct, e_torpedo, e_jettison, XX * e_checkarms, e_runaway, e_attack, e_loadtubes, e_closetorp XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX XXextern float fabs(); XXextern char science[]; XXextern char helmsman[]; XX XX/* XX * returns the number of banks we're going to fire XX * it also sets them up. XX */ XXint e_phasers(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX register int i; XX register int banks; XX register int hit; XX register int howmany; XX int bear; XX XX banks = 0; XX howmany = randm(2) + 2; XX sp->p_spread = 10 + randm(12); XX for (i=0; i<4; i++) { XX if (sp->phasers[i].status & P_DAMAGED) XX continue; XX if (fed != NULL) { XX if (sp->phasers[i].target == NULL) XX continue; XX bear = bearing(sp->x, fed->x, sp->y, fed->y); XX hit = phaser_hit(sp, fed->x, fed->y, &sp->phasers[i], bear); XX if (hit <= 0) XX continue; XX } XX banks++; XX sp->phasers[i].status |= P_FIRING; XX if (banks > howmany) XX break; XX } XX return banks; XX} XX XX/* XX * returns positive if we had to lock phasers XX */ XXint e_lockphasers(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX register int i; XX register int banks; XX XX banks = 0; XX for (i=0; i<4; i++) { XX if (sp->phasers[i].status & P_DAMAGED) XX continue; XX if (sp->phasers[i].target != NULL) XX continue; XX sp->phasers[i].target = fed; XX banks++; XX } XX return banks; XX} XX XX/* XX * returns positive if we had to lock tubes XX */ XXint e_locktubes(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX register int i; XX register int tubes; XX XX tubes = 0; XX for (i=0; i<4; i++) { XX if (sp->tubes[i].status & T_DAMAGED) XX continue; XX if (sp->tubes[i].target != NULL) XX continue; XX sp->tubes[i].target = fed; XX tubes++; XX } XX return tubes; XX} XX XX/* XX * returns 1 if evasive action being taken (to avoid probe) XX */ XXe_checkprobe(sp) XXstruct ship *sp; XX{ XX extern struct list head; XX extern struct list *tail; XX register struct list *lp; XX register int range; XX register struct torpedo *tp; XX XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type != I_PROBE) XX continue; XX tp = lp->data.tp; XX range = rangefind(sp->x, tp->x, sp->y, tp->y); XX if (range < 1000) { XX e_evade(sp, tp->x, tp->y, I_PROBE); XX return 1; XX } XX } XX return 0; XX} XX XX XX/* XX * advance to the rear! XX */ XXe_evade(sp, x, y, type) XXstruct ship *sp; XXint x; XXint y; XXint type; /* Currently unused */ XX{ XX register int i; XX register int newcourse; XX int bear; XX XX bear = bearing(sp->x, x, sp->y, y); XX printf("%s taking evasive action!\n", sp->name); XX i = randm(3); XX switch (i) { XX case 1: XX newcourse = rectify(bear - 90); XX break; XX case 2: XX newcourse = rectify(bear + 90); XX break; XX case 3: XX newcourse = rectify(bear + 180); XX break; XX default: XX printf("error in evade()\n"); XX break; XX } XX sp->target = NULL; XX sp->newcourse = newcourse; XX sp->newwarp = 2 + randm(8); XX if (sp->status & S_WARP) XX sp->newwarp = 1.0; XX type = type; /* LINT */ XX return 1; XX} XX XX XXe_pursue(sp, fed, speed) XXstruct ship *sp; XXstruct ship *fed; XXint speed; XX{ XX int bear; XX int coursediff; XX XX bear = bearing(sp->x, fed->x, sp->y, fed->y); XX /* XX * do a quick turn if our speed is > warp 10 and XX * (thus) we are never going to bear on the fed ship XX * speed = 7 is a magic cookie. feel free to change. XX */ XX coursediff = abs(sp->course - bear); XX if (speed >= 9 && coursediff > 10) XX speed = 5; XX sp->target = fed; XX sp->newcourse = bear; XX sp->newwarp = speed; XX if (speed > 1 && (sp->status & S_WARP)) XX sp->newwarp = 0.99; XX return 1; XX} XX XX XXint e_launchprobe(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX extern struct list *newitem(); XX register int i; XX register struct list *lp; XX register struct torpedo *tp; XX XX if ((sp->status & S_PROBE) || sp->energy <= 10) XX return 0; XX /* XX * fed ship has to be going slow before we'll launch XX * a probe at it. XX */ XX if (fabs(fed->warp) > 1.0) XX return 0; XX lp = newitem(I_PROBE); XX tp = lp->data.tp = MKNODE(struct torpedo, *, 1); XX printf("%s launching probe\n", sp->name); XX tp->speed = sp->warp; XX tp->newspeed = 3.0; XX tp->target = fed; XX tp->course = bearing(sp->x, fed->x, sp->y, fed->y); XX tp->x = sp->x; XX tp->y = sp->y; XX tp->prox = 200 + randm(200); XX tp->timedelay = 15 * 10; XX i = min(randm(15) + 10, sp->energy); XX tp->fuel = i; XX sp->energy -= i; XX sp->pods -= i; XX return 1; XX} XX XX XX/* XX * goodbye, cruel world XX */ XXint e_destruct(sp) XXstruct ship *sp; XX{ XX if (sp->delay < 5 * 9) XX return 0; XX sp->delay = 5 * 9; XX printf("%s: The %s is overloading what remains of it's\n",science, sp->name); XX printf(" antimatter pods -- obviously a suicidal gesture.\n"); XX printf(" Detonation in five seconds\n"); XX return 1; XX} XX XX XXint e_torpedo(sp) XXstruct ship *sp; XX{ XX extern struct ship *shiplist[]; XX extern int shipnum; XX register int i; XX register int tubes; XX register int howmany; XX register struct ship *sp1; XX register int range; XX XX /* XX * don't shoot if someone might be in the way XX * (i.e. proximity fuse will go off right as the XX * torps leave the tubes!) XX */ XX for (i=1; i <= shipnum; i++) { XX sp1 = shiplist[i]; XX if ((sp1->status & S_DEAD) || sp1 == sp) XX continue; XX range = rangefind(sp->x, sp1->x, sp->y, sp1->y); XX if (range <= 400) XX return 0; XX } XX tubes = 0; XX howmany = randm(2) + 1; XX for (i=0; i<4; i++) { XX if ((sp->tubes[i].status & T_DAMAGED) XX || (sp->tubes[i].load == 0)) XX continue; XX if (sp->tubes[i].target == NULL) XX continue; XX tubes++; XX sp->tubes[i].status |= T_FIRING; XX if (tubes > howmany) XX break; XX } XX return tubes; XX} XX XX XXint e_jettison(sp) XXstruct ship *sp; XX{ XX extern struct list *newitem(); XX register struct list *lp; XX register struct torpedo *tp; XX XX if (sp->status & S_ENG) XX return 0; XX if (!(shiplist[0]->status & S_SENSOR)) { XX printf("%s: Sensors indicate debris being left by\n", science); XX printf(" the %s. Insufficient mass?\n", sp->name); XX } XX lp = newitem(I_ENG); XX tp = lp->data.tp = MKNODE(struct torpedo, *, 1); XX tp->id = new_slot(); XX /* XX * ship slows to warp 1.0 when jettisonning engineering XX */ XX tp->newspeed = 0.0; XX tp->speed = sp->warp; XX tp->target = NULL; XX tp->course = sp->course; XX tp->x = sp->x; XX tp->y = sp->y; XX tp->prox = 0; XX tp->timedelay = 15 * 9; XX tp->fuel = sp->pods; XX sp->energy = sp->pods = 0; XX sp->regen = 0.0; XX tp->from = sp; XX if (sp->newwarp < -1.0) XX sp->newwarp = -0.99; XX if (sp->newwarp > 1.0) XX sp->newwarp = 0.99; XX sp->status |= S_ENG; XX sp->status |= S_WARP; XX return 1; XX} XX XXint e_checkarms(sp) XXstruct ship *sp; XX{ XX register int i; XX register int arms; XX XX arms = 0; XX for (i=0; i<4; i++) XX if (sp->phasers[i].load >= 0) XX arms++; XX for (i=0; i<6; i++) XX if (sp->tubes[i].load >= 0) XX arms++; XX return arms; XX} XX XXint e_runaway(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX register int speed; XX XX speed = randm(4) + 2; XX speed = -speed; XX e_pursue(sp, fed, speed); XX printf("%s: The %s is retreating.\n", helmsman, sp->name); XX return 1; XX} XX XXint e_attack(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX int speed; XX float tmpf; XX XX tmpf = fabs(fed->warp); XX if (sp->warp >= tmpf + 2.0 || (sp->status & S_WARP)) XX return 0; XX speed = min(11, tmpf + randm(2) + 2.0); XX e_pursue(sp, fed, speed); XX printf("%s: %s attacking.\n", helmsman, sp->name); XX return 1; XX} XX XXint e_loadtubes(sp) XXstruct ship *sp; XX{ XX register int i; XX register int j; XX register int loaded; XX register int below; XX XX below = 10; XX loaded = 0; XX for (i=0; i<6; i++) { XX if (sp->energy <= below) XX break; XX if (sp->tubes[i].status & T_DAMAGED) XX continue; XX j = min(sp->energy, 10-sp->tubes[i].load); XX if (j == 0) XX continue; XX sp->energy -= j; XX sp->pods -= j; XX sp->tubes[i].load += j; XX loaded++; XX } XX return loaded; XX} XX XXe_closetorps(sp, fed) XXstruct ship *sp; XXstruct ship *fed; XX{ XX extern struct list head; XX extern struct list *tail; XX register struct list *lp; XX register int range; XX register struct torpedo *tp; XX struct torpedo *bad; XX XX bad = NULL; XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type != I_TORPEDO) XX continue; XX tp = lp->data.tp; XX if (tp->from != fed) XX continue; XX range = rangefind(sp->x, tp->x, sp->y, tp->y); XX if (range < 1200) { XX bad = tp; XX /* XX * fire phasers - hope they're pointing in XX * the right direction! XX */ XX if (e_phasers(sp, (struct ship *) NULL)) XX return 1; XX return 1; XX } XX } XX /* XX * we can't get a phaser shot off. XX * try and evade (although hopeless) XX */ XX if (bad != NULL) { XX e_evade(sp, tp->x, tp->y, I_TORPEDO); XX return 1; XX } XX return 0; XX} SHAR_EOF if test 8299 -ne "`wc -c enemycom.c`" then echo shar: error transmitting enemycom.c '(should have been 8299 characters)' fi echo shar: extracting firing.c '(5253 characters)' sed 's/^XX//' << \SHAR_EOF > firing.c XX/* XX * TREK73: firing.c XX * XX * Take care of firing phasers and torpedos for both enemy XX * and fed ships. XX * XX * phaser_firing, torpedo_firing, ship_detonate, torp_detonate XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX XXextern struct ship *shiplist[]; XXextern char shutup[]; XX XXphaser_firing(sp) XXstruct ship *sp; XX{ XX extern struct list head; XX extern struct list *tail; XX extern struct damage p_damage; XX register int i; XX register int j; XX int hit; XX struct ship *ep; XX struct torpedo *tp; XX int s; XX int x, y; XX struct ship *target; XX struct list *lp; XX int bear; XX struct ship *fed; XX XX XX fed = shiplist[0]; XX for (i=0; i<4; i++) { XX if (sp->phasers[i].status & P_FIRING) XX break; XX } XX if (i == 4) XX return 0; XX sp->phasers[i].status &= ~P_FIRING; XX target = sp->phasers[i].target; XX /* XX * Put in j the exact bearing of the phasers relative to XX * the ship XX */ XX if (target == NULL) { XX bear = sp->phasers[i].bearing + sp->course; XX j = sp->phasers[i].bearing; XX } else { XX bear = bearing(sp->x, target->x, sp->y, target->y); XX j = bear - sp->course; XX } XX j = rectify(j); XX if (j > 125 && j < 235 && !(sp->status & S_ENG)) XX return 0; XX if (target != NULL && (target->status & S_DEAD)) { XX if ((sp = fed) && (!shutup[PHASERS+j])&& !(sp->status & S_DEAD)) XX printf("%s phaser %d disengaging\n", sp->name, i+1); XX sp->phasers[i].target = NULL; XX shutup[PHASERS+j]++; XX return 0; XX } XX if (target != NULL) XX sp->phasers[i].bearing = j; XX printf(" <%s frng phasers>\n", sp->name); XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type == 0) XX continue; XX ep = NULL; XX tp = NULL; XX if (lp->type == I_SHIP) { XX ep = lp->data.sp; XX if (ep == sp) XX continue; XX x = ep->x; XX y = ep->y; XX } else { XX tp = lp->data.tp; XX x = tp->x; XX y = tp->y; XX } XX hit = phaser_hit(sp, x, y, &sp->phasers[i], bear); XX if (hit == 0) XX continue; XX if (tp) { XX if (tp->timedelay > 2) { XX switch (lp->type) { XX default: XX case I_SHIP: XX printf("oops...\n"); XX break; XX case I_TORPEDO: XX printf("hit on torpedo %d\n", XX tp->id); XX break; XX case I_ENG: XX printf("%s's engineering hit.\n", XX tp->from->name); XX break; XX case I_PROBE: XX printf("hit on probe %d\n", XX tp->id); XX break; XX } XX tp->timedelay = 2; XX } XX tp->fuel -= hit/2; XX if (tp->fuel < 0) XX tp->fuel = 0; XX continue; XX } XX /* XX * Determine which shield was hit XX */ XX j = rectify(bearing(x, sp->x, y, sp->y) - ep->course); XX if (j > 315 || j < 45) XX s = 1; XX else if (j < 135) XX s = 2; XX else if (j < 225) XX s = 3; XX else XX s = 4; XX damage(hit, ep, s, &p_damage); XX } XX /* XX * Reduce the load by the firing percentage XX */ XX sp->phasers[i].load = sp->phasers[i].load XX - sp->phasers[i].load * sp->p_percent / 100; XX return 0; XX} XX XXtorpedo_firing(sp) XXstruct ship *sp; XX{ XX extern struct damage a_damage; XX extern struct list *newitem(); XX register int i; XX register int j; XX register int th; XX struct torpedo *tp; XX struct ship *target; XX struct list *lp; XX int bear; XX struct ship *fed; XX XX XX fed = shiplist[0]; XX for (i=0; i<6; i++) { XX if (sp->tubes[i].status & T_FIRING) XX break; XX } XX if (i == 6) XX return 0; XX sp->tubes[i].status &= ~T_FIRING; XX th = sp->tubes[i].load; XX if (th == 0) XX return 0; XX target = sp->tubes[i].target; XX /* XX * Put in j the relative bearing of the tube XX */ XX if (target == NULL) { XX bear = sp->tubes[i].bearing + sp->course; XX j = sp->tubes[i].bearing; XX } else { XX bear = bearing(sp->x, target->x, sp->y, target->y); XX j = bear - sp->course; XX } XX j = rectify(j); XX if (j > 125 && j < 235 && !(sp->status & S_ENG)) XX return 0; XX if (target != NULL && (target->status & S_DEAD)) { XX if ((sp = fed) && (!shutup[TUBES+j])&&!(sp->status & S_DEAD)) XX printf(" tube %d disengaging\n", i+1); XX sp->tubes[i].target = NULL; XX shutup[TUBES+j]++; XX return 0; XX } XX if (target != NULL) XX sp->tubes[i].bearing = j; XX sp->tubes[i].load = 0; XX lp = newitem(I_TORPEDO); XX lp->type = I_TORPEDO; XX lp->data.tp = MKNODE(struct torpedo, *, 1); XX tp = lp->data.tp; XX tp->from = sp; XX tp->x = sp->x; XX tp->y = sp->y; XX tp->target = NULL; XX tp->course = rectify(bear); XX tp->fuel = th; XX tp->speed = sp->t_lspeed + sp->warp; XX tp->newspeed = tp->speed; XX tp->timedelay = sp->t_delay * 10; XX tp->prox = sp->t_prox; XX tp->id = new_slot(); XX printf(" <<%s frng torpedo %d>>\n", sp->name, tp->id); XX return 1; XX} XX XXint ship_detonate(sp, lp) XXstruct ship *sp; XXstruct list *lp; XX{ XX register int fuel; XX register int i; XX XX fuel = 0; XX printf("++%s++ destruct.\n", sp->name); XX for (i=0; i<4; i++) XX if (sp->phasers[i].status & ~P_DAMAGED) XX fuel += min(sp->phasers[i].load, 10); XX for (i=0; i<6; i++) XX if (sp->tubes[i].status & ~T_DAMAGED) XX fuel += min(sp->tubes[i].load, 10); XX fuel += sp->pods; XX antimatter_hit((char *) sp, sp->x, sp->y, fuel); XX lp->type = 0; XX sp->status |= S_DEAD; XX} XX XX XXint torp_detonate(tp, lp) XXstruct torpedo *tp; XXstruct list *lp; XX{ XX XX switch (lp->type) { XX case I_SHIP: XX printf("we aren't supposed to be here \n"); XX break; XX case I_TORPEDO: XX printf(":: torp %d ::\n", tp->id); XX break; XX case I_PROBE: XX printf("** probe %d **\n", tp->id); XX break; XX case I_ENG: XX printf("## %s engineering ##\n", tp->from->name); XX break; XX default: XX printf("what the heck is this\n"); XX break; XX } XX antimatter_hit((char *) tp, tp->x, tp->y, tp->fuel); XX return_slot(tp->id); XX delitem(lp); XX} SHAR_EOF if test 5253 -ne "`wc -c firing.c`" then echo shar: error transmitting firing.c '(should have been 5253 characters)' fi echo shar: extracting globals.c '(6478 characters)' sed 's/^XX//' << \SHAR_EOF > globals.c XX/* XX * XX * TREK73: globals.c XX * XX * Global variable declarations XX * XX */ XX#include "defines.h" XX#include "structs.h" XX XXextern int fire_phasers(), fire_tubes(), lock_phasers(), lock_tubes(), XX turn_phasers(), turn_tubes(), load_tubes(), phaser_status(), XX tube_status(), launch_probe(), probe_control(), pos_report(), XX pos_display(), pursue(), elude(), helm(), self_scan(), scan(), XX alter_power(), jettison_engineering(), detonate_engineering(), XX alterpntparams(), play_dead(), corbomite_bluff(), surrender_ship(), XX request_surrender(), self_destruct(), abort_self_destruct(), XX survivors(), help(); XX XXextern int XX standard_strategy(); XX XX XXchar *statmsg[] = { XX "computer inoperable", XX "sensors annihilated", XX "probe launcher shot off", XX "warp drive disabled", XX "engineering jettisoned", XX} ; XX XXstruct damage p_damage = { XX 50, 2, 20, 3, 10, 3, XX 1000, "Computer destroyed.", XX 500, "Sensors demolished.", XX 100, "Probe launcher crushed.", XX 50, "Warp drive destroyed.", XX} ; XX XXstruct damage a_damage = { XX 100, 3, 10, 2, 7, 6, XX 1500, "Computer banks pierced.", XX 750, "Sensors smashed.", XX 150, "Probe launcher shot off.", XX 75, "Warp drive disabled.", XX} ; XX XX XXchar *baddies[MAXFOERACES][MAXBADS] = { XX /* Klingons*/ XX "Annihilation", "Crusher", "Devastator", "Merciless", "Nemesis", XX "Pitiliess", "Ruthless", "Savage", "Vengeance", XX /* Romulan */ XX "Avenger", "Defiance", "Fearless", "Harrower", "Intrepid", XX "Relentless", "Seeker", "Torch", "Vigilant", XX /* Kzinti */ XX "Black Hole", "Comet", "Ecliptic", "Galaxy", "Meteor", XX "Nova", "Pulsar", "Quasar", "Satellite", XX /* Gorn */ XX "Chimericon", "Dragonicon", "Ornithocon", "Predatoricon", "Reptilicon", XX "Serpenticon", "Tyranicon", "Vipericon", "Wyvericon", XX /* Orion */ XX "Arrogant", "Boisterous", "Daring", "Flamboyant", "Heavensent", XX "Jolly Tar", "Magnificent", "Resplendent", "Stupendous", XX /* Hydran */ XX "Baron", "Chancellor", "Dictator", "Emperor", "Lord", XX "Monarch", "President", "Shogun", "Viscount", XX /* Lyran */ XX "Bandit", "Claw", "Dangerous", "Fury", "Mysterious", XX "Sleek", "Tiger", "Vicious", "Wildcat", XX /* Tholian */ XX "Bismark", "Centaur", "Draddock", "Forbin", "Kreiger", XX "Shlurg", "Trakka", "Varnor", "Warrior", XX /* Monty Python */ XX "Blancmange", "Spam", "R.J. Gumby", "Lumberjack", "Dennis Moore", XX "Ministry of Silly Walks", "Argument Clinic", "Piranha Brothers", XX "Upper Class Twit of the Year", XX} ; XX XXchar *feds[] = { XX "Constitution", "Enterprise", "Hornet", "Lexington", "Potempkin", XX "Hood", "Kongo", "Republic", "Yorktown", XX} ; XX XXchar *foeraces[] = { XX "Klingon", "Romulan", "Kzinti", "Gorn", "Orion", "Hydran", XX "Lyran", "Tholian", "Monty Python", XX} ; XX XXchar *foeempire[] = { XX "Empire", "Star Empire", "Hegemony", "Confederation", "Pirates", XX "Monarchy", "Something", "Holdfast", "Flying Circus", XX}; XX XXchar *foeshiptype[] = { XX "D-7 Battle Cruiser", "Sparrowhawk", "Strike Cruiser", XX "Heavy Cruiser", "Raider Cruiser", "Ranger-class Cruiser", XX "Tiger-class Cruiser", "Patrol Cruiser", "Thingee", XX}; XX XXchar *foecaps[] = { XX "Bolak", "Kang", "Koloth", "Kor", "Korax", "Krulix", "Quarlo", XX "Tal", "Troblak" XX}; XX XXint init_p_turn[] = { XX -90, 0, 0, 90 XX}; XX XXint init_t_turn[] = { XX -120, -60, 0, 0, 60, 120 XX}; XX XX/* XX * for the linked list of items in space XX */ XXstruct list head; XXstruct list *tail; XX XX/* XX * Global definitions XX */ XXfloat segment = 0.2; /* Segment time */ XXfloat timeperturn = 2.0; /* Seconds per turn */ XX XXstruct ship *shiplist[10]; /* All the ships in the battle */ XX XXchar captain[30]; /* captain's name */ XXchar science[30]; /* science officer's name */ XXchar engineer[30]; /* engineer's name */ XXchar com[30]; /* communications officer's name */ XXchar nav[30]; /* navigation officer's name */ XXchar helmsman[30]; /* helmsman's name */ XXchar title[9]; /* captain's title */ XXchar foerace[11]; /* enemy's race */ XXchar foename[9]; /* enemy's captain's name */ XXchar foestype[30]; /* enemy's ship type */ XXchar empire[30]; /* What the enemy's empire is called */ XXint shipnum; /* number of ships this time out */ XXint terse = 0; /* print out initial description? */ XXint silly = 0; /* Use the Monty Python's Flying Curcus? */ XXint defenseless = 0; /* defensless ruse status */ XXint corbomite = 0; /* corbomite bluff status */ XXint surrender = 0; /* surrender offered by federation? */ XXint surrenderp = 0; /* Did we request that the enemy surrenders? */ XXchar shutup[HIGHSHUTUP]; /* Turn off messages after first printing */ XXchar slots[300]; /* Id slots */ XXint global = NORMAL; /* Situation status */ XXchar **argp = NULL; /* Argument list for parsit() routine */ XXchar options[100]; /* Environment variable */ XXchar sex[20]; /* From environment */ XXchar shipbuf[10]; /* From environment */ XXchar shipname[20]; /* From environment */ XXchar racename[20]; /* From environment */ XXint reengaged = 0; /* Re-engaging far-off ships? */ XX XXstruct cmd cmds[] = { XX { fire_phasers, "1", "Fire phasers", 1 }, XX { fire_tubes, "2", "Fire photon torpedoes", 1 }, XX { lock_phasers, "3", "Lock phasers onto target", 1 }, XX { lock_tubes, "4", "Lock tubes onto target", 1 }, XX { turn_phasers, "5", "Manually rotate phasers", 1 }, XX { turn_tubes, "6", "Manually rotate tubes", 1 }, XX { phaser_status, "7", "Phaser status", 1 }, XX { tube_status, "8", "Tube status", 1 }, XX { load_tubes, "9", "Load/unload torpedo tubes", 1 }, XX { launch_probe, "10", "Launch antimatter probe", 1 }, XX { probe_control, "11", "Probe control", 1 }, XX { pos_report, "12", "Position report", 0 }, XX { pos_display, "13", "Position display", 0 }, XX { pursue, "14", "Pursue an enemy vessel", 1 }, XX { elude, "15", "Elude an enemy vessel", 1 }, XX { helm, "16", "Manually change course and speed", 1 }, XX { self_scan, "17", "Damage report", 1 }, XX { scan, "18", "Scan enemy (enemy Damage report)", 1 }, XX { alter_power, "19", "Alter power distribution", 1 }, XX { jettison_engineering, "20", "Jettison engineering", 1 }, XX { detonate_engineering, "21", "Detonate engineering", 1 }, XX { alterpntparams, "22", "Alter firing parameters", 1}, XX { play_dead, "23", "Attempt defenseless ruse", 1 }, XX { corbomite_bluff, "24", "Attempt corbomite bluff(s)", 1 }, XX { surrender_ship, "25", "Surrender", 1 }, XX { request_surrender, "26", "Ask enemy to surrender", 1 }, XX { self_destruct, "27", "Initiate self-destruct sequence", 1 }, XX { abort_self_destruct, "28", "Abort self-destruct", 1 }, XX { survivors, "29", "Survivors report", 0 }, XX { help, "30", "Reprints above list", 0 }, XX { NULL, NULL, NULL, 1 }, XX} ; XX XX/* Strategy table */ XXint (*strategies[])() = { XX standard_strategy XX}; SHAR_EOF if test 6478 -ne "`wc -c globals.c`" then echo shar: error transmitting globals.c '(should have been 6478 characters)' fi # End of shell archive exit 0
okamoto@ucbvax.ARPA (Doctor Who) (09/16/85)
# This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. -----cut here-----cut here-----cut here-----cut here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # main.c # misc.c # mission.c # moveships.c # options.h # parseopts.c # parsit.c # strat1.c # structs.h # This archive created: Mon Sep 9 12:07:23 1985 echo shar: extracting main.c '(7038 characters)' sed 's/^XX//' << \SHAR_EOF > main.c XX/* XX * TREK73: main.c XX * XX * Originally written (in HP-2000 BASIC) by XX * William K. Char, Perry Lee, and Dan Gee XX * XX * Rewritten in C by XX * Dave Pare (sdcsvax!sdamos!mr-frog) XX * and XX * Christopher Williams (ucbvax!ucbmerlin!williams) XX * XX * Corrected, Completed, and Enhanced by XX * Jeff Okamoto (ucbvax!okamoto) XX * Peter Yee (ucbvax!yee) XX * Matt Dillon (ucbvax!dillon) XX * Dave Sharnoff (ucbvax!ucbcory!muir) XX * and XX * Joel Duisman (ucbvax!duisman) XX * XX * Main Loop XX * XX * main, alarmtrap XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <math.h> XX#include <signal.h> XX#include <setjmp.h> XX#include <stdio.h> XX XXint timeout; XXjmp_buf jumpbuf; XXextern char shutup[]; XX XX XXmain() XX{ XX extern char **environ; XX extern struct list *newitem(); XX extern char captain[]; XX extern char title[]; XX extern char foename[]; XX extern char *foeraces[]; XX extern char *foecaps[]; XX extern char *foeshiptype[]; XX extern char foerace[]; XX extern char foestype[]; XX extern int terse; XX extern int silly; XX extern char *feds[]; XX extern char *baddies[MAXFOERACES][MAXBADS]; XX extern struct cmd cmds[]; XX extern struct ship *shiplist[]; XX extern int shipnum; XX extern char shipname[]; XX extern char slots[]; XX struct cmd *scancmd(); XX int alarmtrap(); XX register int i; XX register int j; XX register struct ship *sp; XX register struct list *lp; XX char buf1[30]; XX struct cmd *cp; XX int range; XX float bearing; XX int loop; XX int len; XX int enemynum; XX extern char slots[]; XX char *tmp; XX int swap1; XX int swap2; XX int offset; XX extern int (*strategies[])(); XX extern char *options; XX extern char *getenv(); XX extern char sex[]; XX extern char shipbuf[]; XX extern char science[]; XX extern char engineer[]; XX extern char com[]; XX extern char nav[]; XX extern char helmsman[]; XX extern char racename[]; XX extern int init_p_turn[]; XX extern int init_t_turn[]; XX extern char *foeempire[]; XX extern char empire[]; XX XX signal(SIGALRM, alarmtrap); XX signal(SIGINT, SIG_IGN); XX srandom(time(0)); XX options = getenv("TREK73OPTS"); XX if (options != NULL) { XX parse_opts(options); XX } XX if (strlen(science) == 0) XX strcpy(science, "Spock"); XX if (strlen(engineer) == 0) XX strcpy(engineer, "Scott"); XX if (strlen(com) == 0) XX strcpy(com, "Uhura"); XX if (strlen(nav) == 0) XX strcpy(nav, "Chekov"); XX if (strlen(helmsman) == 0) XX strcpy(helmsman, "Sulu"); XX if (strlen(captain) == 0) { XX printf("\n\nCaptain: my last name is "); XX if (gets(buf1) == NULL || *buf1 == NULL) XX exit(1); XX strcpy (captain, buf1); XX } XX if (*captain == '*') { XX terse = 1; XX len = strlen(captain) + 1; XX for (loop = 1; loop < len; loop++) XX captain[loop-1] = captain[loop]; XX } XX if (strlen(sex) != 0) XX strcpy(buf1,sex); XX else { XX printf("%s: My sex is: ",captain); XX if (gets(buf1) == NULL || *buf1 == NULL) XX exit(1); XX } XX if ((*buf1 <= 'z') && (*buf1 >= 'a')) XX *buf1 = *buf1 - 'a' + 'A'; XX switch(*buf1) { XX case 'M': XX strcpy(title, "Sir"); XX break; XX case 'F': XX strcpy(title, "Ma'am"); XX break; XX default : XX switch (random() % 6) { XX case 0: XX strcpy(title, "Fag"); XX break; XX case 1: XX strcpy(title, "Fairy"); XX break; XX case 2: XX strcpy(title, "Fruit"); XX break; XX case 3: XX strcpy(title, "Weirdo"); XX break; XX case 4: XX strcpy(title, "Gumby"); XX break; XX case 5: XX strcpy(title, "Freak"); XX break; XX } XX } XX if (strlen(shipbuf) != 0) { XX strcpy(buf1,shipbuf); XX } else { XX getships: XX printf(" I'm expecting [1-9] enemy vessels "); XX if (gets(buf1) == NULL || *buf1 == NULL) XX exit(1); XX } XX i = atoi(buf1); XX if (i < 1 || i > 9) { XX printf("%s: %s, Starfleet Command reports that it can only\n", com, title); XX printf(" be from 1 to 9. Try again.\n"); XX printf("%s: Correct, Lieutenant -- just testing your attention..\n", captain); XX goto getships; XX } XX shipnum = i; XX for (loop = 0; loop < shipnum; loop++); XX slots[loop] = 'X'; XX if (strlen(racename) == 0) { XX if (silly == 0) XX offset = 1; XX else XX offset = 0; XX enemynum = randm(MAXFOERACES - offset) - 1; XX } else { XX for (loop=0; loop<MAXFOERACES; loop++) XX if (strncmp(racename, foeraces[loop], strlen(racename)) == 0) { XX enemynum = loop; XX break; XX } XX if (loop == MAXFOERACES) { XX printf("Cannot find race %s.\n", racename); XX enemynum = randm(MAXFOERACES) - 1; XX } XX } XX strcpy(foerace, foeraces[enemynum]); XX strcpy(foestype, foeshiptype[enemynum]); XX strcpy(empire, foeempire[enemynum]); XX if (strlen(foename) == 0) XX strcpy(foename, foecaps[randm(MAXENCOMM) - 1]); XX /* XX * Randomize the enemy ships XX */ XX for (loop = 0; loop < 20; loop++) { XX swap1 = randm(MAXBADS) - 1; XX swap2 = randm(MAXBADS) - 1; XX tmp = baddies[enemynum][swap1]; XX baddies[enemynum][swap1] = baddies[enemynum][swap2]; XX baddies[enemynum][swap2] = tmp; XX } XX /* XX * everybody is centered on the federation ship XX * (for now, anyways) XX */ XX for (i=0; i<=shipnum; i++) { XX lp = newitem(I_SHIP); XX lp->data.sp = MKNODE(struct ship, *, 1); XX sp = shiplist[i] = lp->data.sp; XX if (i) XX strcpy(sp->name, baddies[enemynum][i-1]); XX sp->warp = sp->newwarp = 1.0; XX sp->course = sp->newcourse = randm(360); XX sp->eff = .75; XX sp->regen = 10.0; XX sp->energy = 150; XX sp->pods = 200; XX sp->id = i; XX for (j=0; j<4; j++) { XX sp->phasers[j].target = NULL; XX sp->phasers[j].bearing = init_p_turn[j]; XX sp->phasers[j].load = 10; XX sp->phasers[j].drain = 10; XX sp->phasers[j].status = P_NORMAL; XX } XX for (j=0; j<4; j++) { XX sp->shields[j].eff = 1.0; XX sp->shields[j].drain = 0.0; XX sp->shields[j].attemp_drain = 1.0; XX } XX sp->p_spread = 10; XX for (j=0; j<6; j++) { XX sp->tubes[j].target = NULL; XX sp->tubes[j].bearing = init_t_turn[j]; XX sp->tubes[j].load = 0; XX sp->tubes[j].status = T_NORMAL; XX } XX sp->t_lspeed = 12; XX sp->t_prox = 200; XX sp->t_delay = 10; XX sp->p_percent = 100; XX sp->status = S_NORMAL; /* all is well */ XX sp->target = NULL; XX sp->eluding = 0; XX sp->delay = 10000; XX range = 4100 + randm(300) - i * 200; XX bearing = toradians(randm(360)); XX sp->x = range * cos(bearing); XX sp->y = range * sin(bearing); XX sp->crew = 350; XX sp->strategy = strategies[0]; XX } XX /* XX * federation exceptions XX */ XX sp = shiplist[0]; XX sp->course = sp->newcourse = 0; XX sp->eff = 1.0; XX sp->x = sp->y = 0; XX sp->crew = 450; XX if (strlen(shipname) == 0) { XX i = randm(MAXFEDS) - 1; XX strcpy(sp->name, feds[i]); XX } else { XX strcpy(sp->name, shipname); XX } XX for(loop=shipnum+1; loop<300; loop++) XX slots[loop] = ' '; XX mission(); XX warning(); XX setjmp(jumpbuf); XX timeout = 0; XX signal(SIGALRM, alarmtrap); XX alarm(0); XX for (;;) { XX sp = shiplist[0]; XX if (!(sp->status & S_DEAD)) { XX alarm(20); XX for (loop = 0; loop < HIGHSHUTUP; loop++) XX shutup[loop] = 0; XX printf("\n%s: Code [1-30] ", captain); XX if (gets(buf1) != NULL) { XX cp = scancmd(buf1); XX if (cp != NULL) { XX (*cp->routine)(sp); XX if (!cp->turns) XX continue; XX } else XX printf("\n%s: What??\n", science); XX } XX } XX alarm(0); XX alarmtrap(0); XX } XX} XX XXalarmtrap(sig) XXint sig; XX{ XX extern int timeout; XX extern jmp_buf jumpbuf; XX XX if (sig) { XX printf("\n** TIME **\n"); XX stdin->_cnt = 0; XX } XX if (!(shiplist[0]->status & S_DEAD)) XX printf("\n"); XX shiplist[1]->strategy(); XX move_ships(); XX if (sig) { XX timeout = 1; XX longjmp(jumpbuf, 1); XX } XX} SHAR_EOF if test 7038 -ne "`wc -c main.c`" then echo shar: error transmitting main.c '(should have been 7038 characters)' fi echo shar: extracting misc.c '(5106 characters)' sed 's/^XX//' << \SHAR_EOF > misc.c XX/* XX * TREK73: misc.c XX * XX * Miscellaneous Routines XX * XX * help, scancmd, new_slot, return_slot, betw, vowelstr, plural, XX * check_p_damage, check_t_damage, check_p_turn, check_t_turn XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <stdio.h> XX XXint help(dummy) XXstruct ship *dummy; XX{ XX extern struct cmd cmds[]; XX struct cmd *cp; XX int column = 0; XX XX printf("\nTrek84 Commands: \n"); XX printf("Code Command\n\n"); XX for (cp = &cmds[0]; cp->routine != NULL; cp++) { XX printf("%3s: ", cp->word1); XX if (cp->turns == 0) XX printf (" *"); XX else XX printf (" "); XX printf(" %-31s", cp->word2); XX if (column++ & 1) XX puts(""); XX } XX printf("\n\n\n * does not use a turn\n"); XX dummy = dummy; /* LINT */ XX} XX XXstruct cmd *scancmd(buf) XXchar *buf; XX{ XX extern struct cmd cmds[]; XX struct cmd *cp; XX extern char **argp; XX int argnum; XX int first; XX XX argnum = parsit(buf, &argp); XX first = strlen(argp[0]); XX if (argnum && first) { XX for (cp = &cmds[0]; cp->routine != NULL; cp++) { XX if (strncmp(argp[0], cp->word1, first) == 0) XX return (cp); XX } XX } XX return (NULL); XX} XX XX/* XX * This routine handles getting unique identifier numbers for XX * all objects. XX */ XXnew_slot() XX{ XX extern char slots[]; XX extern int shipnum; XX /* XX * This is to make it appear that in a 2-ship duel, for XX * instance, the first object to appear will be numbered XX * as 3. XX */ XX int i = shipnum + 2; XX XX while (slots[i] == 'X') XX i++; XX slots[i] = 'X'; XX return i; XX} XX XX/* XX * This routine handles returning identifiers XX */ XXreturn_slot(i) XXint i; XX{ XX extern char slots[]; XX XX if (slots[i] != 'X') XX printf("FATAL ERROR - Slot already empty!"); XX slots[i] = ' '; XX} XX XXbetw(i, j, k) XXint i, j, k; XX{ XX if ((i > j) && (i < k)) XX return(1); XX else XX return(0); XX} XX XXchar *vowelstr(str) XXchar *str; XX{ XX switch(*str) { XX case 'a': case 'A': XX case 'e': case 'E': XX case 'i': case 'I': XX case 'o': case 'O': XX case 'u': case 'U': XX return "n"; XX default: XX return ""; XX } XX} XX XXchar *plural(i) XXint i; XX{ XX if (i != 1) XX return("s"); XX else XX return(""); XX} XX XX/* XX * This routine takes an array generated from commands 1, 3, and 5 XX * to print out a list of those phasers damaged and unable to XX * either fire, lock, or turn. XX */ XXcheck_p_damage(array, sp, string) XXint array[]; XXstruct ship *sp; XXchar *string; XX{ XX int i, j = 0; XX XX for (i=0; i<4; i++) { XX if ((array[i] != 0) && (sp->phasers[i].status & P_DAMAGED)) { XX if (!j) XX printf("Computer: Phaser(s) %d", i+1); XX else XX printf(", %d", i+1); XX j++; XX } XX } XX if (j) XX printf(" damaged and unable to %s.\n", string); XX} XX XX/* XX * This routine takes an array generated from commands 2, 4, and 6 XX * to print out a list of those tubes damaged and unable to either XX * fire, lock, or turn. XX */ XXcheck_t_damage(array, sp, string) XXint array[]; XXstruct ship *sp; XXchar *string; XX{ XX int i, j = 0; XX XX for (i=0; i<6; i++) { XX if ((array[i] != 0) && (sp->tubes[i].status & P_DAMAGED)) { XX if (!j) XX printf("Computer: Tube(s) %d", i+1); XX else XX printf(", %d", i+1); XX j++; XX } XX } XX if (j) XX printf(" damaged and unable to %s.\n", string); XX} XX XX/* XX * This routine checks to see if a phaser is pointing into our XX * blind side XX */ XXcheck_p_turn(array, sp, flag) XXint array[]; XXstruct ship *sp; XXint flag; /* If 1, came from fire_phasers */ XX{ XX register int i; XX register int j = 0; XX register int k; XX register int bear; XX struct ship *target; XX XX for (i=0; i<4; i++) { XX if (array[i] == 0) XX continue; XX if ((flag) && (!(sp->phasers[i].status & P_FIRING))) XX continue; XX target = sp->phasers[i].target; XX /* XX * This hack is here since when the phaser is locked, XX * the bearing points at the target, whereas when XX * not locked, the bearing is relative to the ship. XX */ XX if (target == NULL) { XX bear = sp->phasers[i].bearing + sp->course; XX k = sp->phasers[i].bearing; XX } else { XX bear = bearing(sp->x, target->x, sp->y, target->y); XX k = bear - sp->course; XX } XX k = rectify(k); XX if ((k > 125) && (k < 235) && (!(sp->status & S_ENG))) { XX if (!j) XX printf("Computer: Phaser(s) %d", i + 1); XX else XX printf(", %d", i + 1); XX j++; XX } XX } XX if (j) XX printf(" are pointing into our blind side.\n"); XX} XX XX/* XX * This routine checks to see if a tube is turned into XX * our blind side. XX */ XXcheck_t_turn(array, sp, flag) XXint array[]; XXstruct ship *sp; XXint flag; /* If 1, came from fire_tubes */ XX{ XX register int i; XX register int j = 0; XX register int k; XX register int bear; XX struct ship *target; XX XX for (i=0; i<6; i++) { XX if (array[i] == 0) XX continue; XX if (flag && (!(sp->tubes[i].status & T_FIRING))) XX continue; XX target = sp->tubes[i].target; XX /* XX * This hack is here since when the tube is locked, XX * the bearing points at the target, whereas when XX * not locked, the bearing is relative to the ship. XX */ XX if (target == NULL) { XX bear = sp->tubes[i].bearing + sp->course; XX k = sp->tubes[i].bearing; XX } else { XX bear = bearing(sp->x, target->x, sp->y, target->y); XX k = bear - sp->course; XX } XX k = rectify(k); XX if ((k > 135) && (k < 225) && (!(sp->status & S_ENG))) { XX if (!j) XX printf("Computer: Tubes(s) %d", i + 1); XX else XX printf(", %d", i + 1); XX j++; XX } XX } XX if (j) XX printf(" are pointing into our blind side.\n"); XX} SHAR_EOF if test 5106 -ne "`wc -c misc.c`" then echo shar: error transmitting misc.c '(should have been 5106 characters)' fi echo shar: extracting mission.c '(4017 characters)' sed 's/^XX//' << \SHAR_EOF > mission.c XX/* XX * TREK73: mission.c XX * XX * Mission Assignment XX * XX */ XX XX#include "structs.h" XX#include "defines.h" XX XXextern int terse; XXextern char title[]; XXextern char foerace[]; XXextern char foename[]; XXextern char foestype[]; XXextern char captain[]; XXextern char science[]; XXextern char com[]; XXextern char helmsman[]; XXextern struct ship *shiplist[]; XXextern int shipnum; XX XXmission() XX{ XX int onef; XX extern char *plural(), *vowelstr(); XX XX if (terse) XX return; XX onef = (shipnum == 1); XX printf("\n\n\nSpace, the final frontier.\n"); XX printf("These are the voyages of the starship %s.\n", shiplist[0]->name); XX printf("Its five year mission: to explore strange new worlds,\n"); XX printf("to seek our new life and new civilizations,\n"); XX printf("to boldly go where no man has gone before!\n"); XX printf("\n"); XX printf(" S T A R T R E K\n"); XX printf("\n"); XX missionlog(); XX printf("%s: %s, I'm picking up %d vessel%s on interception\n", helmsman, title, shipnum, plural(shipnum)); XX printf(" course with the %s.\n", shiplist[0]->name); XX printf("%s: Sensors identify %s as ", science, onef ? "it" : "them"); XX if (onef) XX printf("a%s ", vowelstr(foerace)); XX printf("%s %s%s,\n", foerace, foestype, plural); XX printf(" probably under the command of Captain %s.\n", foename); XX printf("%s: Sound general quarters, Lieutenant!\n", captain); XX printf("%s: Aye, %s!\n", com, title); XX} XX XXwarning() XX{ XX register int i; XX XX printf("Computer: The %ss are attacking the %s with the ", foerace, shiplist[0]->name); XX if (shipnum == 1) { XX printf("%s", shiplist[1]->name); XX } else { XX for (i = 1; i <= shipnum; i++) { XX if (i == shipnum) XX printf("and the "); XX printf("%s", shiplist[i]->name); XX if (i == shipnum) XX break; XX printf(", "); XX /* XX if ((shipnum == 2 && i == 1) || i == 2 || i == 7) XX */ XX if (i == 1 || i == 7) XX printf("\n "); XX } XX } XX printf(".\n"); XX} XX XXmissionlog() XX{ XX static char *missiontab[] = { XX " We are acting in response to a Priority 1 distress call from", XX "space station K7.", XX " We are orbiting Gamma 2 to make a routine check of automatic", XX "communications and astrogation stations.", XX " We are on course for Epsilon Canares 3 to treat Commissioner", XX "Headford for Sukaro's disease.", XX " We have been assigned to transport ambassadors to a diplomatic", XX "conference on the planet code named Babel.", XX " Our mission is to investigate a find of tritanium on Beta 7.", XX 0, XX " We are orbiting Rigel 4 for therapeutic shore leave.", XX 0, XX " We are orbiting Sigma Iota 2 to study the effects of", XX "contamination upon a devoloping culture.", XX " We have altered course for a resue mission on the Gamma 7A", XX "system.", XX " We are presently on course for Altair 6 to attend inauguration", XX "cermonies on the planet.", XX " We are on a cartographic mission to Polex 9.", XX 0, XX " We are headed for Malurian in response to a distress call", XX "from that system.", XX " We are to negotiate a treaty to mine dilithium crystals from", XX "the Halkans.", XX " We are to investigate strange sensor readings reported by a", XX "scoutship investigating Gamma Triangula 6.", XX " We are headed for planets L370 and L374 to investigate the", XX "disappearance of the starship Constellation in that vincinity.", XX " We are ordered, with a skeleton crew, to proceed to Space", XX "Station K2 to test Dr. Richard Daystrom's computer M5.", XX " We have encountered debris from the SS Beagle and are", XX "proceeding to investigate.", XX " We are on course for Ekos to locate John Gill.", XX 0, XX " We are to divert an asteroid from destroying an inhabited", XX "planet.", XX " We are responding to a distresss call form the scientific", XX "expedition on Triacus.", XX " We have been assigned to transport the Medusan Ambassador to", XX "to his home planet." XX }; XX int t1, t2; XX XX t2 = randm(100) - 1; XX t1 = randm(100) - 1; XX printf("%s: Captain's log, stardate %d.%d.\n", captain, t1, t2); XX t1 = (randm(20) - 1) * 2; XX printf("%s\n", missiontab[t1]); XX t1++; XX if (!missiontab[t1]) XX return; XX printf(" %s\n", missiontab[t1]); XX} SHAR_EOF if test 4017 -ne "`wc -c mission.c`" then echo shar: error transmitting mission.c '(should have been 4017 characters)' fi echo shar: extracting moveships.c '(7887 characters)' sed 's/^XX//' << \SHAR_EOF > moveships.c XX/* XX * TREK73: moveships.c XX * XX * Actual command execution XX * XX * move_ships XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX XXextern int defenseless; XXextern int corbomite; XXextern int surrender; XXextern int surrenderp; XXextern char shutup[]; XXextern int global; XXextern int reengaged; XX XX XXmove_ships() { XX extern double sin(); XX extern double cos(); XX extern double sqrt(); XX extern float fabs(); XX extern struct list head; XX extern struct list *tail; XX extern int shipnum; XX extern struct ship *shiplist[]; XX register int i; XX register int j; XX register int k; XX register struct list *lp; XX register struct ship *sp; XX struct torpedo *tp; XX struct ship *fed; XX struct list *lp1; XX struct ship *sp1; XX int iterations; XX float tmpf; XX int course, newcourse, energy; XX float warp, newwarp; XX int x, y; XX struct ship *target; XX int kills, others, fedstatus; XX struct ship *ep; XX double d0; XX extern float segment; XX extern float timeperturn; XX float Mpersegment; XX XX /* XX * The value 100 is the number of Megameters per second XX * per warp-factor XX */ XX Mpersegment = segment * 100.0; XX iterations = timeperturn/segment; XX for (i=0; i<=shipnum; i++) XX distribute(shiplist[i]); XX fed = shiplist[0]; XX for (i=0; i<iterations; i++) { XX for (lp = &head; lp != NULL; lp = lp->fwd) { XX if (lp == tail) XX break; XX if (lp->type == 0) XX continue; XX sp = NULL; XX tp = NULL; XX if (lp->type == I_SHIP) XX sp = lp->data.sp; XX else XX tp = lp->data.tp; XX if (sp && sp->status & S_DEAD) XX continue; XX if (sp) { XX phaser_firing(sp); XX torpedo_firing(sp); XX } XX /* XX * time fuses XX */ XX if (tp) { XX tp->timedelay--; XX if (tp->timedelay <= 0) { XX torp_detonate(tp, lp); XX continue; XX } XX } else { XX sp->delay--; XX if (sp->delay <= 0) { XX ship_detonate(sp, lp); XX continue; XX } XX } XX /* XX * proximity fuse XX */ XX if (tp && tp->prox != 0) { XX for (lp1 = &head; lp1 != tail; lp1 = lp1->fwd) { XX if (lp1->type != I_SHIP) XX continue; XX sp1 = lp1->data.sp; XX if (sp1 == tp->from) XX continue; XX j=rangefind(tp->x,sp1->x,tp->y,sp1->y); XX if (j > tp->prox) XX continue; XX torp_detonate(tp, lp); XX tp = 0; XX break; XX } XX if (!tp) XX continue; XX } XX /* XX * movement simulation XX */ XX if (sp && sp->status & S_DEAD) XX continue; XX if (sp) { XX x = sp->x; XX y = sp->y; XX warp = sp->warp; XX newwarp = sp->newwarp; XX course = sp->course; XX newcourse = sp->newcourse; XX target = sp->target; XX energy = sp->energy; XX /* XX * fuel consumption XX */ XX if (fabs((double) warp) >= 1) XX j = (int) (warp * sp->eff * segment); XX else XX j = 0; XX if (j < 0) XX j *= -1; XX if (j > energy) { XX if (!shutup[BURNOUT + sp->id] && !(sp->status & S_WARP)) { XX printf("%s's warp drive burning out.\n", XX sp->name); XX shutup[BURNOUT + sp->id]++; XX } XX newwarp = warp < 0 ? -.99 : .99; XX energy = 0; XX } else XX energy -= j; XX } else { XX x = tp->x; XX y = tp->y; XX warp = tp->speed; XX newwarp = tp->newspeed; XX course = tp->course; XX newcourse = course; XX target = tp->target; XX } XX /* XX * destroyed warp drive XX */ XX if (sp && (sp->status & S_WARP)) XX if (fabs((double)warp) > 1.0) XX newwarp = warp < 0.0 ? -.99 : .99; XX /* XX * automatic pilot XX */ XX if (target != NULL) { XX if (sp && (target->status & S_DEAD)) { XX if ((sp == fed) && (!shutup[DISENGAGE]) && !(sp->status & S_DEAD)) XX printf("%s's autopilot disengaging.\n", XX sp->name); XX newcourse = course; XX shutup[DISENGAGE]++; XX target = NULL; XX sp->eluding = 0; XX } else { XX j = bearing(x, target->x, y, target->y); XX if (sp && sp->eluding) XX j = rectify(j + 180); XX newcourse = (float) j; XX /*if ((sp) && (sp != fed)) { XX sp->newwarp = 1.0; XX newwarp = 1.0; XX }*/ XX if (tp) XX course = newcourse; XX } XX } XX /* XX * turn rate XX */ XX if (course != newcourse) { XX j = rectify(newcourse - course); XX if (j > 180) XX j -= 360; XX /* XX * maximum degrees turned in one turn XX */ XX k = (int) ((12.0 - warp) * 4.0 * segment); XX if (sp->status & S_WARP) XX k /= 2; XX k = (int) course + (j < 0 ? -1 : 1) * XX min(abs(j), k); XX course = (float) rectify(k); XX } XX /* XX * acceleration XX */ XX tmpf = newwarp - warp; XX if (tmpf < 0.0) XX d0 = (double) (tmpf * -1.0); XX else XX d0 = (double) tmpf; XX if (tmpf != 0.0) XX warp += (tmpf < 0 ? -1 : 1) * sqrt(d0) XX * segment; XX d0 = (double) toradians(course); XX x += (int) (warp * cos(d0) * Mpersegment); XX y += (int) (warp * sin(d0) * Mpersegment); XX if ((warp > -0.1) && (warp < 0.1)){ XX warp = 0.0; XX } XX /* XX * reset all the vars XX */ XX if (sp) { XX sp->x = x; XX sp->y = y; XX sp->warp = warp; XX sp->newwarp = newwarp; XX sp->course = course % 360; XX sp->newcourse = newcourse % 360; XX sp->energy = energy; XX sp->target = target; XX } else { XX tp->x = x; XX tp->y = y; XX tp->speed = warp; XX tp->course = course % 360; XX tp->target = target; XX } XX } XX } XX for (i=0; i <= shipnum; i++) { /* Check targets */ XX sp = shiplist[i]; XX if (sp->status & S_DEAD) XX continue; XX for (j=0; j<4; j++) { XX target = sp->phasers[j].target; XX if (target && (target->status & S_DEAD)) { XX if ((sp == fed) && (!shutup[PHASERS+j])&& !(sp->status & S_DEAD)) XX printf(" phaser %d disengaging\n",j+1); XX sp->phasers[j].target = NULL; XX shutup[PHASERS+j]++; XX } XX } XX for (j=0; j<6; j++) { XX target = sp->tubes[j].target; XX if (target && (target->status & S_DEAD)) { XX if ((sp == fed) && (!shutup[TUBES+j]) && !(sp->status & S_DEAD)) XX printf(" tube %d disengaging\n", j+1); XX sp->tubes[j].target = NULL; XX shutup[TUBES+j]++; XX } XX } XX } XX /* XX * self-destruct warning XX */ XX if ((fed->delay < 1000) && (fed->delay > 8)) { XX printf("Computer: %d seconds to self destruct.\n",fed->delay/9); XX } XX /* XX * Ruses, bluffs, surrenders XX */ XX if (defenseless) XX defenseless++; XX if (corbomite) XX corbomite++; XX if (surrender) XX surrender++; XX if (surrenderp) XX surrenderp++; XX /* XX * Federation dispostion XX */ XX sp = fed; XX kills = others = fedstatus = 0; XX if ((sp->crew <= 0) || (sp->status & S_DEAD)) { XX fedstatus = 1; XX sp->status |= S_DEAD; XX } else XX for (j=0; j<1; j++) { XX for (i=0; i<4; i++) XX if (~sp->phasers[i].status | ~P_DAMAGED) XX break; XX if (i != 4) XX continue; XX for (i=0; i<6; i++) XX if (~sp->tubes[i].status | ~T_DAMAGED) XX break; XX if (i != 6) XX continue; XX fedstatus = 1; XX } XX /* XX * enemy disposition XX */ XX for (k=1; k <= shipnum; k++) { XX ep = shiplist[k]; XX if (ep->status & S_DEAD) { XX kills++; XX continue; XX } XX if (ep->crew <= 0) { XX ep->status |= S_DEAD; XX kills++; XX continue; XX } XX if (fedstatus) XX continue; XX j = rangefind(sp->x, ep->x, sp->y, ep->y); XX if ((j>3500 && (ep->status & S_WARP)) || XX (j>4500 && ep->delay<100)) { XX others++; XX continue; XX } XX /* Check if we are within range to turn off the flag */ XX if ((j <= 3500) && (reengaged)) XX reengaged = 0; XX if (ep->energy > 10) XX continue; XX for (i=0; i<4; i++) XX if (~ep->phasers[i].status | ~P_DAMAGED) XX break; XX if (i != 4) XX continue; XX for (i=0; i<6; i++) XX if (~ep->tubes[i].status | ~T_DAMAGED) XX break; XX if (i != 6) XX continue; XX kills++; XX } XX if (fedstatus == 0 && (global & E_SURRENDER)) { XX if (leftovers()) XX warn(4); XX else { XX final(4); XX } XX } XX if ((fed->status & S_SURRENDER) && (kills + others < shipnum)) { XX if (leftovers()) XX warn(3); XX else { XX final(3); XX } XX } XX if (fedstatus == 0 && kills+others < shipnum) XX return 0; XX if (fedstatus == 1 && kills+others < shipnum) { XX if (leftovers()) XX warn(0); XX else XX final(0); XX } XX if (fedstatus == 0 && kills == shipnum) { XX if (leftovers()) XX warn(1); XX else XX final(1); XX } XX if (fedstatus == 0 && kills+others == shipnum) { XX if (leftovers()) XX warn(2); XX else XX final(2); XX } XX if (fedstatus == 1 && kills == shipnum) { XX final(5); XX } XX return 0; XX} SHAR_EOF if test 7887 -ne "`wc -c moveships.c`" then echo shar: error transmitting moveships.c '(should have been 7887 characters)' fi echo shar: extracting options.h '(92 characters)' sed 's/^XX//' << \SHAR_EOF > options.h XX/* XX * TREK73: options.h XX * XX * Parse_opts defines XX * XX */ XX XX#define BOOLEAN 0 XX#define STRING 1 SHAR_EOF if test 92 -ne "`wc -c options.h`" then echo shar: error transmitting options.h '(should have been 92 characters)' fi echo shar: extracting parseopts.c '(3053 characters)' sed 's/^XX//' << \SHAR_EOF > parseopts.c XX/* XX * TREK73: parse_opt.c XX * XX * Parse the environment variable TREK73OPTS XX * XX * parse_opts XX */ XX XX#include <ctype.h> XX#include "structs.h" XX#include "options.h" XX XX#define EQSTR(a, b, c) (strncmp(a, b, c) == 0) XX XX#define NUM_OPTS (sizeof optlist / sizeof (OPTION)) XX XX/* XX * description of an option and what to do with it XX */ XXstruct optstruct { XX char *o_name; /* option name */ XX int *o_opt; /* pointer to thing to set */ XX int o_type /* Boolean or string */ XX}; XX XXtypedef struct optstruct OPTION; XX XXextern int terse; XXextern char captain[]; XXextern char sex[]; XXextern char shipbuf[]; XXextern char science[]; XXextern char engineer[]; XXextern char com[]; XXextern char nav[]; XXextern char helmsman[]; XXextern char shipname[]; XXextern char foename[]; XXextern char racename[]; XXextern int silly; XX XX XXOPTION optlist[] = { XX {"terse", (int *)&terse, BOOLEAN}, XX {"name", (int *)captain, STRING}, XX {"sex", (int *)sex, STRING}, XX {"ships", (int *)shipbuf, STRING}, XX {"science", (int *)science, STRING}, XX {"engineer", (int *)engineer, STRING}, XX {"com", (int *)com, STRING}, XX {"nav", (int *)nav, STRING}, XX {"helmsman", (int *)helmsman, STRING}, XX {"shipname", (int *)shipname, STRING}, XX {"enemy", (int *)racename, STRING}, XX {"foename", (int *)foename, STRING}, XX {"silly", (int *)&silly, BOOLEAN}, XX}; XX XX/* XX * parse_opts: XX * Parse options from string, usually taken from the environment. XX * The string is a series of comma seperated values, with booleans XX * being stated as "name" (true) or "noname" (false), and strings XX * being "name=....", with the string being defined up to a comma XX * or the end of the entire option string. XX */ XXparse_opts(str) XXregister char *str; XX{ XX register char *sp; XX register OPTION *op; XX register int len; XX XX while (*str) XX { XX /* XX * Get option name XX */ XX for (sp = str; isalpha(*sp); sp++) XX continue; XX len = sp - str; XX /* XX * Look it up and deal with it XX */ XX for (op = optlist; op < &optlist[NUM_OPTS]; op++) XX if (EQSTR(str, op->o_name, len)) XX { XX if (op->o_type == BOOLEAN) /* if option is a boolean */ XX *op->o_opt = 1; XX else /* string option */ XX { XX register char *start; XX /* XX * Skip to start of string value XX */ XX for (str = sp + 1; *str == '='; str++) XX continue; XX start = (char *) op->o_opt; XX /* XX * Skip to end of string value XX */ XX for (sp = str + 1; *sp && *sp != ','; sp++) XX continue; XX strucpy(start, str, sp - str); XX } XX break; XX } XX /* XX * check for "noname" for booleans XX */ XX else if (op->o_type == BOOLEAN XX && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) XX { XX *op->o_opt = 0; XX break; XX } XX XX /* XX * skip to start of next option name XX */ XX while (*sp && !isalpha(*sp)) XX sp++; XX str = sp; XX } XX} XX XX/* XX * strucpy: XX * Copy string using unctrl for things XX */ XXstrucpy(s1, s2, len) XXregister char *s1, *s2; XXregister int len; XX{ XX if (len > 100) XX len = 100; XX while (len--) XX { XX if (isprint(*s2) || *s2 == ' ') XX *s1++ = *s2; XX s2++; XX } XX *s1 = '\0'; XX} XX SHAR_EOF if test 3053 -ne "`wc -c parseopts.c`" then echo shar: error transmitting parseopts.c '(should have been 3053 characters)' fi echo shar: extracting parsit.c '(2631 characters)' sed 's/^XX//' << \SHAR_EOF > parsit.c XX/* XX * TREK73: parsit.c XX * XX * Parse and get input XX * XX * Gets, parsit (courtesy, P. Lapsley) XX * XX */ XX#include <stdio.h> XXstatic int gindex; XXstatic char **argv; XXchar * XXGets(buf) XXchar *buf; XX{ XX extern char *gets(); XX XX if (argv[gindex] == NULL) XX return (gets (buf)); XX ++gindex; XX if (argv[gindex] == NULL) XX return (gets (buf)); XX strcpy (buf, argv[gindex]); XX puts (buf); XX return (buf); XX} XX XX/* XX** parsit.c 23 September 1984 P. Lapsley (phil@Berkeley.ARPA) XX** XX** Parse a string of words separated by spaces into an XX** array of pointers to characters, just like good ol' argv[] XX** and argc. XX** XX** Usage: XX** XX** char line[132]; XX** char **argv; XX** int argc; XX** XX** argv = (char **) NULL; XX** argc = parsit(line, &argv); XX** XX** returns the number of words parsed in argc. argv[argc] will XX** be (char *) NULL to indicate end of list, if you're not XX** happy with just knowing how many words you have. XX** XX** Note that setting argv = (char **) NULL is only done the first XX** time the routine is called with a new "argv" -- it tells XX** parsit that "argv" is a new array, and parsit shouldn't free XX** up the elements (as it would do if it were an old array). XX*/ XX XX XXparsit(line, array) XXchar *line; XXchar ***array; XX{ XX char *malloc(); XX char word[132]; XX char *linecp; XX int i, j, num_words; XX XX gindex = 0; XX argv = *array; XX if (argv != (char **) NULL) { /* Check to see if we should */ XX i = 0; /* free up the old array */ XX do { XX free(argv[i]); /* If so, free each member */ XX } while (argv[i++] != (char *) NULL); XX free(argv); /* and then free the ptr itself */ XX } XX XX linecp = line; XX num_words = 0; XX while (1) { /* count words in input */ XX for (; *linecp == ' ' || *linecp == '\t'; ++linecp) XX ; XX if (*linecp == '\0') XX break; XX XX for (; *linecp != ' ' && *linecp != '\t' && *linecp != '\0'; ++linecp) XX ; XX ++num_words; XX if (*linecp == '\0') XX break; XX } XX XX /* Then malloc enough for that many words plus 1 (for null) */ XX XX if ((argv = (char **) malloc((num_words + 1) * sizeof(char *))) == XX (char **) NULL) { XX fprintf(stderr, "parsit: malloc out of space!\n"); XX return(0); XX } XX XX j = i = 0; XX while (1) { /* Now build the list of words */ XX for (; *line == ' ' || *line == '\t'; ++line) XX ; XX if (*line == '\0') XX break; XX XX i = 0; XX for (; *line != ' ' && *line != '\t' && *line != '\0'; ++line) XX word[i++] = *line; XX word[i] = '\0'; XX argv[j] = malloc(strlen(word) + 1); XX if (argv[j] == (char *) NULL) { XX fprintf(stderr, "parsit: malloc out of space!\n"); XX return(0); XX } XX XX strcpy(argv[j], word); XX ++j; XX if (*line == '\0') XX break; XX } XX argv[j] = (char *) NULL; /* remember null at end of list */ XX *array = argv; XX return(j); XX} XX XX SHAR_EOF if test 2631 -ne "`wc -c parsit.c`" then echo shar: error transmitting parsit.c '(should have been 2631 characters)' fi echo shar: extracting strat1.c '(8821 characters)' sed 's/^XX//' << \SHAR_EOF > strat1.c XX/* XX * TREK73: strat1.c XX * XX * Standard Enemy Strategy XX * XX * standard_strategy XX * XX */ XX XX#include "defines.h" XX#include "structs.h" XX XX XXstandard_strategy() XX{ XX extern float fabs(); XX extern struct ship *shiplist[]; XX extern int shipnum; XX extern int defenseless; XX extern int corbomite; XX extern int surrender; XX extern int surrenderp; XX extern char captain[]; XX extern char science[]; XX extern char nav[]; XX extern char com[]; XX extern char helmsman[]; XX extern char title[]; XX extern char foename[]; XX extern char foerace[]; XX extern int global; XX extern char empire[]; XX int i; XX register struct ship *sp; XX register struct ship *fed; XX int bear; XX int range; XX float tmpf; XX int loop, loop2; XX int probability; XX XX fed = shiplist[0]; XX for (i=1; i <= shipnum; i++) { XX sp = shiplist[i]; XX if (sp->status & S_DEAD) XX continue; XX range = rangefind(sp->x, fed->x, sp->y, fed->y); XX bear = bearing(sp->x, fed->x, sp->y, fed->y); XX bear = rectify(sp->course - bear); XX /* XX * Take care of special commands like defenseless ruses, XX * corbomite bluffs, surrenders (both sides) XX */ XX /* XX * Play dead effects XX */ XX switch (defenseless) { XX case 1: { XX if (randm(10) > 2) { XX defenseless = 2; XX dstrat: XX if (randm(2) == 1) { XX sp->target = NULL; XX sp->newwarp = 0.0; XX } else { XX sp->newwarp = 1.0; XX } XX printf("%s: The %s is ",helmsman, sp->name); XX if (sp->target != NULL) { XX printf("cautiously advancing.\n"); XX } else { XX printf("turning away.\n"); XX } XX astrat: XX if ((fabs(sp->target->warp) > 1.0) XX || (range < 200)) { XX defenseless = 6; XX } else { XX for (loop = 0; loop < 4; loop++) { XX if (sp->target->shields[loop].drain) { XX defenseless = 6; XX } XX } XX } XX } else { XX printf("%s: No apparent change in the enemy's actions.\n", helmsman); XX defenseless = 6; XX } XX } XX break; XX case 2: goto dstrat; XX case 4: goto astrat; XX case 5: goto astrat; XX } XX /* XX * Corbomite bluff effects. XX */ XX switch (corbomite) { XX case 1: { XX probability = 30; XX if (!strcmp(foerace, "Romulan")) { XX probability = 50; XX } XX if (randm(100) < probability) { XX printf("%s: %ss giving ground, Captain. Obviously, they\n", science, foerace); XX printf(" tapped in as you expected them to.\n"); XX printf("%s: A logical assumption, Mr. %s. Are they still\n", captain, science); XX printf(" retreating?\n"); XX printf("%s: Yes, %s\n",science, title); XX printf("%s: Good. All hands, stand by.\n",captain); XX corbomite = 2; XX cstrat: XX sp->target = NULL; XX sp->newwarp = 3.0 + randm(7); XX } else { XX printf("%s: Message coming in from the %ss.\n",com, foerace); XX printf("%s: Put it on audio.\n",captain); XX if (randm(2) == 1) { XX printf ("%s: Ha, ha, ha, %s. You lose.\n", foename, captain); XX } else { XX printf("%s: I fell for that the last time we met, idiot!\n", foename); XX } XX corbomite = 6; XX } XX } XX break; XX case 2: goto cstrat; XX case 3: if (fabs(sp->target->warp) > 2.0) { XX corbomite = 6; XX } XX break; XX case 4: if (fabs(sp->target->warp) > 2.0) { XX corbomite = 6; XX } XX break; XX case 5: if (fabs(sp->target->warp) > 2.0) { XX corbomite = 6; XX } XX break; XX } XX /* XX * Will the enemy accept your surrender? XX */ XX XX if (surrender) XX switch (surrender) { XX case 1: { XX probability=49; XX if (!strcmp(foerace, "Romulan")) { XX probability = 4; XX printf("%s: The %ss do not take prisoners.\n", nav, foerace); XX } XX if (randm(100) < probability) { XX if (randm(2) == 1) { XX printf("%s: Prepare to die, Chicken %s!\n", foename, captain); XX } else { XX printf("%s: No reply from the %ss.\n",com, foerace); XX } XX surrender = 6; XX } else { XX printf("%s: Message coming in from the %s.\n", com, sp->name); XX printf("%s: On behalf of the %s %s, I accept your surrender.\n", foename, foerace, empire); XX printf(" You have five seconds to drop your shields, cut\n"); XX printf(" warp, and prepare to be boarded.\n"); XX surrender = 2; XX global |= F_SURRENDER; XX sstrat: XX sp->target = fed; XX sp->newwarp = 2.0; XX } XX break; XX } XX case 2: XX case 3: { XX warn(3); XX goto sstrat; XX } XX case 4: XX case 5: { XX for (loop = 0; loop < 4; loop++) { XX if (sp->target->shields[loop].attemp_drain) XX goto breakout; XX } XX if (range <= 1400) XX sp->newwarp = 1.0; XX if ((range > 1000) || (fabs(sp->target->warp) > 1.0)) { XX if (surrender == 5) { XX printf("%s: Captain %s, you have not fulfilled our terms.\n", foename, captain); XX printf(" We are resuming our attack.\n"); XX } XX goto breakout; XX } else { XX fed->status |= S_SURRENDER; XX final(3); XX } XX } XX default: global &= ~F_SURRENDER; XX break; XX breakout: XX break; XX } XX /* XX * Enemy surrenders? XX */ XX switch (surrenderp) { XX case 1: XX for (loop = 1; loop < shipnum; loop++) XX if (!(sp->status & S_ENG) && (sp->crew > 100)) { XX printf("%s: You must be joking, Captain %s. Why don't you\n", foename, captain); XX printf(" surrender?\n"); XX surrenderp = 6; XX break; XX } XX if (loop = shipnum) { XX probability = 49; XX if (!strcmp (foerace, "Romulan")) XX probability = 4; XX if (randm(100) < probability) { XX printf("%s: As much as I hate to, Captain %s, we will surrender.\n", foename, captain); XX printf(" We are dropping shields. You may board us.\n"); XX surrenderp = 2; XX dropshields: XX for (loop = 0; loop < 3; loop++) XX sp->shields[0].drain = 0; XX sp->newwarp = 0.0; XX for (loop = 1; loop < shipnum; loop++) XX shiplist[loop]->status |= S_SURRENDER; XX global |= E_SURRENDER; XX } else { XX printf("%s: You must be joking, Captain %s. Why don't you\n", foename, captain); XX printf(" surrender?\n"); XX surrenderp = 6; XX } XX } XX break; XX case 2: XX case 3: XX warn(4); XX goto dropshields; XX } XX /* XX * Unsportsmanlike firing XX */ XX if (betw(defenseless, 0, 6) || betw(corbomite, 0, 6) XX || betw(surrender, 0, 6) || betw(surrenderp, 0, 6)) { XX for (loop = 0; loop < 4; loop++) XX if (fed->phasers[i].status & P_FIRING) XX break; XX for (loop2 = 0; loop2 < 6; loop2++) XX if (fed->tubes[i].status & T_FIRING) XX break; XX /* Has he fired? */ XX if ((loop != 4) || (loop2 != 6)) { XX /* Yes, be angry and disbelieve everything from now on */ XX printf("%s: How dare you fire on us! We are\n", foename); XX printf(" resuming our attack!\n"); XX global = NORMAL; XX if (betw(defenseless,0,6)) XX defenseless = 6; XX if (betw(corbomite,0,6)) XX corbomite = 6; XX if (betw(surrender,0,6)) XX surrender = 6; XX if (betw(surrenderp,0,6)) XX surrenderp = 6; XX for (loop = 0; loop < shipnum; loop++) XX shiplist[loop]->status &= ~S_SURRENDER; XX } XX } XX if ((global & F_SURRENDER) || (global & E_SURRENDER)) XX continue; XX /* XX * short range? XX * 1). fire phasers XX * 2). lock phasers XX * 3). evade probes XX * 4). enemy to the rear - turn around XX * 5). launch a probe? XX * 6). self destruct? XX * 7). set course. XX */ XX if (range < 1050) { XX if (e_closetorps(sp, fed)) XX continue; XX if (e_lockphasers(sp, fed)) XX continue; XX if (e_phasers(sp, fed)) XX continue; XX if (e_checkprobe(sp)) XX continue; XX if (bear > 90 && bear < 270) { XX e_pursue(sp, fed, 1); XX continue; XX } XX if (bear > 90 && bear < 270 && e_launchprobe(sp, fed)) XX continue; XX if (sp->pods<20 && sp->regen < 4.0 && e_destruct(sp)) XX continue; XX /* XX * set course? XX */ XX tmpf = fabs(fed->warp); XX if (sp->target != fed || sp->warp + tmpf > 2.0) { XX e_pursue(sp, fed, (int)tmpf); XX continue; XX } XX } XX if (range < 3800) { XX /* XX * either medium range, or we can't figure out what XX * to do at short range XX */ XX if (e_torpedo(sp)) XX continue; XX if (e_locktubes(sp, fed)) XX continue; XX /* XX * should we run away; can we? XX */ XX if (e_checkarms(sp) < randm(3)) { XX e_runaway(sp, fed); XX continue; XX } XX /* XX * pursued from behind, low power: jettison engineering! XX */ XX if (sp->energy<10 && sp->regen < 4.0 && e_jettison(sp)) XX continue; XX /* XX * put in other junk later XX */ XX } XX /* XX * either distant range, or we can't figure out XX * what to do at medium range XX */ XX if (fed->delay < 15*10 && (sp->status & S_WARP)) { XX e_runaway(sp, fed); XX continue; XX } XX /* XX * enemy behind us? make a quick turn. XX */ XX if (bear > 135 && bear < 225) { XX e_pursue(sp, fed, 1); XX continue; XX } XX /* XX * attack? XX */ XX if (sp->pods > 40 && e_attack(sp, fed)) XX continue; XX if (sp->energy > 30 && sp->pods > 40) XX if (e_loadtubes(sp)) XX continue; XX if (e_locktubes(sp, fed)) XX continue; XX if (e_lockphasers(sp, fed)) XX continue; XX /* XX * gee, there's nothing that we want to do! XX */ XX printf("%s: We're being scanned by the %s\n", science, sp->name); XX } XX} SHAR_EOF if test 8821 -ne "`wc -c strat1.c`" then echo shar: error transmitting strat1.c '(should have been 8821 characters)' fi echo shar: extracting structs.h '(2965 characters)' sed 's/^XX//' << \SHAR_EOF > structs.h XX/* XX * TREK73: structs.h XX * XX * Struct Defs for TREK73 XX * XX */ XX XX XXstruct phaser { XX struct ship *target; /* who we're aimed at */ XX int bearing; /* direction aimed (if no target) */ XX char load; /* energy in phasers */ XX char status; /* Damaged, etc. */ XX int drain; /* Drain from engines (to if negative) */ XX} ; XX XXstruct tube { XX struct ship *target; /* who we're aimed at */ XX int bearing; /* direction aimed (if no target) */ XX char load; /* energy in tubes */ XX char status; /* Damaged, etc */ XX} ; XX XXstruct shield { XX float eff; /* efficiency from 0-1 */ XX float drain; /* Actual drain from engines */ XX float attemp_drain; /* Attempted drain from engines */ XX} ; XX XXstruct ship { XX char name[30]; /* name of ship */ XX char nat; /* nationality */ XX int x, y; /* location */ XX float warp; /* warp speed */ XX float newwarp; /* for speed changes */ XX int course; /* 0-360 */ XX int newcourse; /* for course changes */ XX struct ship *target; /* who we're pursuing */ XX int eluding; /* Flag for eluding */ XX struct phaser phasers[4]; /* phaser banks */ XX int p_spread; /* phaser spread */ XX int p_percent; /* phaser firing percentage */ XX struct tube tubes[6]; /* torpedo tubes */ XX int t_prox; /* proximity delay */ XX int t_delay; /* time delay */ XX int t_lspeed; /* launch speed */ XX struct shield shields[4]; /* shields */ XX float eff; /* efficiency */ XX float regen; /* regeneration (energy per turn) */ XX int energy; /* amount of effective energy */ XX int pods; /* max energy level */ XX int crew; /* crew left alive */ XX int status; /* computer, probe l, warp, sensors, eng */ XX int delay; /* how long 'till we blow up? */ XX int id; /* Unique identifier */ XX int (*strategy)(); /* Which strategy to use */ XX} ; XX XX/* XX * note that probes act like torpedos XX * but have targets; torps only have XX * courses XX */ XXstruct torpedo { XX struct ship *from; /* pointer to ship they're from */ XX int x, y; /* coords of object */ XX int course; /* where it's going */ XX float speed; /* how fast we're moving */ XX float newspeed; /* what our target speed is */ XX struct ship *target; /* who we're aimed at */ XX int fuel; /* how many antimatter pods it has */ XX int timedelay; /* time clicks left before detonation */ XX int prox; /* proximity fuse */ XX int id; /* Unique identifier */ XX} ; XX XX/* XX * the list of what's in space -- depending on the type, we use XX * differing parts of the union (data) structure. it's a linked XX * list of all the stuff in space. XX */ XXstruct list { XX int type; XX struct list *back, *fwd; XX union { XX struct torpedo *tp; XX struct ship *sp; XX } data; XX} ; XX XXstruct cmd { XX int (*routine)(); XX char *word1; XX char *word2; XX int turns; XX} ; XX XX/* XX * for the phaser and anti-matter damage lists XX */ XX XXstruct dam { XX int roll; XX char *mesg; XX}; XX XXstruct damage { XX float eff; XX float fuel; XX float regen; XX float shield; XX float crew; XX float weapon; XX struct dam stats[4]; XX}; XX XXstruct score { XX int score; XX int ships; XX char captain[30]; XX char username[10]; XX}; XX XXstruct rates { XX char *rate; XX int points; XX}; SHAR_EOF if test 2965 -ne "`wc -c structs.h`" then echo shar: error transmitting structs.h '(should have been 2965 characters)' fi # End of shell archive exit 0
okamoto@ucbvax.ARPA (Doctor Who) (09/17/85)
Here is the Makefile for trek73 and the missing file. Sorry for any problems. Jeff Okamoto # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. -----cut here-----cut here-----cut here-----cut here----- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # Makefile # subs.c # This archive created: Tue Sep 17 07:39:18 1985 echo shar: extracting Makefile '(709 characters)' sed 's/^XX//' << \SHAR_EOF > Makefile XX# XX# makefile for trek73 XX# XX XXCFLAGS=-O XXOBJECTS= cmds1.o cmds2.o cmds3.o cmds4.o dist.o endgame.o enemycom.o\ XX firing.o globals.o main.o misc.o mission.o moveships.o\ XX parseopts.o strat1.o subs.o XXCFILES= cmds1.c cmds2.c cmds3.c cmds4.c dist.c endgame.c enemycom.c\ XX firing.c globals.c main.c misc.c mission.c moveships.c\ XX parseopts.c strat1.c subs.c XXHEADS= structs.h defines.h XXLIBS= -lm XX XXall: trek73 XX XXtrek73: ${OBJECTS} parsit.o XX cc ${CFLAGS} ${OBJECTS} parsit.o ${LIBS} XX install a.out trek73 XX XX${OBJECTS}: ${HEADS} XX XXparsit.o: parsit.c XX cc -O -c parsit.c XX XXtags: ${CFILES} XX ctags ${CFILES} ${HEADS} XX XXlint: XX lint -za ${CFILES} > lint.out XX XXclean: XX rm -f ${OBJECTS} parsit.o trek73 make.out errs core lint.out a.out SHAR_EOF if test 709 -ne "`wc -c Makefile`" then echo shar: error transmitting Makefile '(should have been 709 characters)' fi echo shar: extracting subs.c '(7513 characters)' sed 's/^XX//' << \SHAR_EOF > subs.c XX/* XX * TREK73: subs.c XX * XX * Miscellaneous Subroutines XX * XX * ship_name, newitem, delitem, rangefind, bearing, phaser_hit, XX * torpedo_hit, damage, antimatter_hit, recitfy XX */ XX XX#include "defines.h" XX#include "structs.h" XX#include <math.h> XX#include <ctype.h> XX XXextern struct ship *shiplist[]; XXextern char science[]; XX XXstruct ship *ship_name(name, start) XXchar *name; XXint start; XX{ XX extern int shipnum; XX register int i; XX register int j; XX register int len; XX XX if (islower(*name)) { XX *name = toupper(*name); XX } XX j = shipnum; XX len = strlen(name); XX for (i=start; i<=j; i++) { XX if (shiplist[i]->name[0] == NULL) XX continue; XX if (strncmp(name, shiplist[i]->name, len) == 0) XX return shiplist[i]; XX } XX printf("%s: I am unable to find the %s\n", science, name); XX return NULL; XX} XX XX XXstruct list *newitem(item) XXint item; XX{ XX extern struct list head; XX extern struct list *tail; XX register struct list *new; XX register struct list *newtail; XX XX /* XX * if there's no "tail" node, make one (only happens at init) XX */ XX if (tail == NULL) { XX new = MKNODE(struct list, *, 1); XX new->back = &head; XX new->fwd = NULL; XX new->data.tp = NULL; XX head.fwd = new; XX tail = new; XX } XX new = tail; XX /* XX * now make the new tail node XX */ XX newtail = MKNODE(struct list, *, 1); XX newtail->back = new; XX newtail->fwd = NULL; XX newtail->data.tp = NULL; XX newtail->type = 0; XX tail = newtail; XX /* XX * link the old tail node to the new one XX */ XX new->type = item; XX new->fwd = newtail; XX return new; XX} XX XX XXint delitem(item) XXstruct list *item; XX{ XX extern struct list *tail; XX extern struct list head; XX register struct list *bp; XX register struct list *fp; XX XX bp = item->back; XX fp = item->fwd; XX if (item->data.tp != NULL) XX free((char *) item->data.tp); XX /* XX * re-arrange pointers on both the next and the previous XX * nodes; if no forward pointer, we were the tail so make XX * the bp the new tail node. XX */ XX if (fp != NULL) { XX bp->fwd = fp; XX fp->back = bp; XX } else { XX tail = bp; XX bp->fwd = NULL; XX } XX free((char *) item); XX} XX XXint rangefind(x1, x2, y1, y2) XXint x1; XXint x2; XXint y1; XXint y2; XX{ XX extern double sqrt(); XX extern double atan(); XX register int i; XX register int x, y; XX double d1, d2; XX XX x = x2 - x1; XX y = y2 - y1; XX /* XX * Both x and y must be cast as double else overflow XX * may occur. XX */ XX d1 = (double) x * (double) x + (double) y * (double) y; XX d2 = sqrt(d1); XX i = d2; XX return i; XX} XX XX/* XX * This routine finds the bearing of (x2,y2) from (x1,y1) XX */ XXint bearing(x1, x2, y1, y2) XXint x1; XXint x2; XXint y1; XXint y2; XX{ XX extern double atan(); XX float x; XX float y; XX register int bear; XX double d1; XX double d2; XX XX x = x2 - x1; XX y = y2 - y1; XX if (x == 0.0) XX bear = 90; XX else { XX d1 = y/x; XX d2 = atan(d1) * 57.2958; XX bear = d2; XX } XX if (x < 0.0 || y < 0.0) { XX bear += 180; XX if (x >= 0.0) XX bear += 180; XX } XX return bear; XX} XX XXint phaser_hit(sp, x, y, bank, true_bear) XXstruct ship *sp; XXint x; XXint y; XXstruct phaser *bank; XXint true_bear; XX{ XX extern double sqrt(); XX register int hit; XX int i; XX int spread; XX int bear; XX double d1; XX double d2; XX XX hit = 0; XX i = rangefind(sp->x, x, sp->y, y); XX if (i < 1000) { XX bear = bearing(sp->x, x, sp->y, y); XX spread = rectify(true_bear - bear); XX /* XX * Check if a target is within the phaser spread XX */ XX if (spread > sp->p_spread && 360-spread > sp->p_spread) XX return 0; XX d1 = 1.0 - (float)i/1000.0; XX d2 = (float)bank->load * sqrt(d1) * sp->p_percent / 100; XX d2 = (float)bank->load * d2 * 45.0/(float)sp->p_spread * sp->p_percent / 100; XX hit = d2/10.0; XX } XX return hit; XX} XX XXint torpedo_hit(fuel, x, y, tx, ty) XXint fuel; XXint x; XXint y; XXint tx; XXint ty; XX{ XX extern double sqrt(); XX register int hit; XX int i; XX double d1; XX double d2; XX float f1; XX float f2; XX XX hit = 0; XX i = rangefind(x, tx, y, ty); XX f1 = fuel * 5.0; XX f2 = f1 * 10.0; XX if (i < f2) { XX d1 = 1.0 - (float)i/f2; XX d2 = (float)f1 * sqrt(d1); XX hit = d2; XX } XX return hit; XX} XX XX XXdamage(hit, ep, s, dam) XXint hit; XXstruct ship *ep; XXint s; XXstruct damage *dam; XX{ XX register int i; XX register int j; XX register int k; XX float f1; XX float f2; XX struct ship *fed; XX XX fed = shiplist[0]; XX printf("hit %d on %s's shield %d\n", hit, ep->name, s); XX s--; XX /* XX * Note that if the shield is at 100% efficiency, no XX * damage at all will be taken XX */ XX f1 = hit * (1.0 - ep->shields[s].eff * ep->shields[s].drain); XX if (f1 < 0) XX return 0; XX ep->eff += f1/dam->eff; XX ep->pods -= f1/dam->fuel; XX ep->energy -= f1/dam->fuel; XX ep->regen -= f1/dam->regen; XX if (ep->regen < 0.0) XX ep->regen = 0.0; XX if (ep->pods < 0.0) XX ep->pods = 0.0; XX if (ep->energy < 0.0) XX ep->energy = 0.0; XX if (ep->pods < ep->energy) XX ep->energy = ep->pods; XX f2 = dam->shield * 100; XX if (s == 0) XX f2 *= 1.5; XX ep->shields[s].eff -= max(hit/f2, 0); XX if (ep->shields[s].eff < 0.0) XX ep->shields[s].eff = 0.0; XX j = f1 * dam->crew; XX if (j > 0) XX ep->crew -= max(randm(j), 0); XX if (ep->crew < 0) XX ep->crew = 0; XX j = f1/dam->weapon; XX for(i=0; i<j; i++) { XX k = randm(10); XX if (k <= 4) { XX k--; XX if (ep->phasers[k].status & P_DAMAGED) XX continue; XX ep->phasers[k].status |= P_DAMAGED; XX /* XX * Reroute the energy XX * back to the engines XX */ XX ep->energy = min(ep->pods, ep->energy XX + ep->phasers[k].load); XX ep->phasers[k].load = 0; XX ep->phasers[k].drain = 0; XX k++; XX if (ep == fed) XX printf(" phaser %d damaged.\n", k); XX } else { XX k -= 5; XX if (ep->tubes[k].status & T_DAMAGED) XX continue; XX /* XX * If tubes are damaged, reroute the pods XX * back to the engines XX */ XX ep->pods += ep->tubes[k].load; XX ep->energy += ep->tubes[k].load; XX ep->tubes[k].load = 0; XX ep->tubes[k].status |= T_DAMAGED; XX k++; XX if (ep == fed) XX printf(" tube %d damaged\n", k); XX } XX } XX for (i=0; i<4; i++) { XX if (ep->status & 1<<i) XX continue; XX if (randm(dam->stats[i].roll) < f1) { XX ep->status |= 1<<i; XX if (ep == fed) XX printf(" %s\n", dam->stats[i].mesg); XX } XX } XX#ifdef HISTORICAL XX /* XX * Historically, if more than 43 points of damage were done XX * to the ship, it would destroy itself. This led to much XX * abuse of probes and thus has been enclosed inside of XX * an #ifdef XX */ XX if (f1 > 43) XX ep->delay = 1; XX#endif XX return 0; XX} XX XX XXantimatter_hit(ptr, x, y, fuel) XXchar *ptr; XXint x; XXint y; XXint fuel; XX{ XX extern struct list head; XX extern struct list *tail; XX extern struct damage a_damage; XX register struct list *lp; XX register int hit; XX int tarx, tary; XX int s; XX int bear; XX struct torpedo *tp; XX struct ship *sp; XX XX for (lp = &head; lp != tail; lp = lp->fwd) { XX if (lp->type == 0) XX continue; XX sp = NULL; XX tp = NULL; XX if (lp->type == I_SHIP) { XX sp = lp->data.sp; XX tarx = sp->x; XX tary = sp->y; XX } else { XX tp = lp->data.tp; XX tarx = tp->x; XX tary = tp->y; XX } XX if (sp == (struct ship *) ptr || tp == (struct torpedo *) ptr) XX continue; XX hit = torpedo_hit(fuel, x, y, tarx, tary); XX if (hit <= 0) XX continue; XX if (sp) { XX /* XX * Determine which shield is hit XX */ XX bear = rectify(bearing(tarx, x, tary, y) - sp->course); XX if (bear < 45 || bear > 315) XX s = 1; XX else if (bear < 135) XX s = 2; XX else if (bear < 225) XX s = 3; XX else XX s = 4; XX damage(hit, sp, s, &a_damage); XX } else { XX if (tp->timedelay <= 2) XX continue; XX tp->timedelay = 2; XX switch (lp->type) { XX case I_TORPEDO: XX printf("hit on torpedo %d\n", XX tp->id); XX break; XX case I_PROBE: XX printf("hit on probe %d\n", XX tp->id); XX break; XX case I_ENG: XX printf("hit on %s engineering\n", XX tp->from->name); XX break; XX } XX } XX } XX} XX XXint rectify(x) XXint x; XX{ XX register int ret; XX XX ret = x; XX if (ret < 0) XX ret += 360; XX else if (ret > 360) XX ret -= 360; XX return ret; XX} SHAR_EOF if test 7513 -ne "`wc -c subs.c`" then echo shar: error transmitting subs.c '(should have been 7513 characters)' fi # End of shell archive exit 0
rcook@uiucuxc.Uiuc.ARPA (09/19/85)
Can you post a makefile for this. Rob Cook UUCP: {ihnp4,pur-ee}!uiucdcs!uiucuxc!rcook 'Life is just a cocktail party on the street' -Mick Jagger-
robert@smcvax.UUCP (09/21/85)
Trek73 looks like an interesting game. Sure would be easier to compile it if a makefile had been included in the distribution. (there is one for the documentation, however) Robert {infoswx, ctvax}!smcvax!robert
okamoto@ucbvax.UUCP (12/10/86)
Enclosed is the latest version of Trek73. The newest feature is that of "designer ships", ie, the designing of other ships besides the four default designes (DN, CA, CL, DD). It has been playtested, but I am sure that there are still a lot of bugs in it. Please send all bug reports to: okamoto@ucbvax.berkeley.edu or ..!ucbvax!okamoto Enjoy! The New Number Who, Jeff Okamoto
okamoto@ucbvax.UUCP (12/10/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # Makefile # defines.h # externs.h # options.h # structs.h # cmds1.c # cmds2.c # This archive created: Wed Dec 10 09:01:05 1986 # By: Jeff Okamoto () export PATH; PATH=/bin:$PATH if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else cat << \SHAR_EOF > 'Makefile' # # Makefile for TREK73 # # # Select which operating system you are using. # Acceptable flags are BSD and SYSV. # OS = BSD # # Select whether you wish to use symbolic debugger or not. # NOTE: UNIX System V Release 2.0 cannot do profiling on programs # compiled with -g. Also, sdb will not be very useful if the # symbols are stripped from the load module. (See STRIP) #SDB = -g SDB = # # Select whether code optimization is to be done. OPT = -O #OPT = # # Select whether profiling is to be done. # NOTE: In System V Relase 2.0, this is incompatible with # both SDB and STRIP. # PROF = -p PROF = # # Select whether or not the load module is to be stripped. # This is incompatible with both SDB and PROF. # Note: In BSD Unix, this option should always be blank # STRIP = -s STRIP = # # Select whether or not tracing mode is to be turned on. # This is useful when testing new strategies. TRACE = -DTRACE DEFINES = -D${OS} CFLAGS = ${DEFINES} ${SDB} ${OPT} ${PROF} ${STRIP} T73OBJECTS = cmds1.o cmds2.o cmds3.o cmds4.o damage.o dist.o endgame.o\ enemycom.o firing.o globals.o init.o main.o misc.o mission.o\ moveships.o parseopts.o save.o ships.o special.o strat1.o\ subs.o vers.o T73CFILES = cmds1.c cmds2.c cmds3.c cmds4.c damage.c dist.c endgame.c\ enemycom.c firing.c globals.c init.c main.c misc.c mission.c\ moveships.c parseopts.c save.c ships.c special.c strat1.c\ subs.c vers.c BPVOBJECTS = bpv.o ships.o BPVFILES = bpv.c ships.c DYOOBJECTS = shipyard.o DYOFILES = shipyard.c HEADS= structs.h defines.h externs.h RDIST = ${T73CFILES} ${BPVFILES} ${DYOFILES} ${HEADS} LIBS= -lm FLUFF = parsit.o make.out errs core lint.errs a.out tags\ shar.1 shar.2 shar.3 shar.4 BINS = trek73 bpv shipyard all: trek73 bpv shipyard trek73: ${T73OBJECTS} parsit.o cc ${CFLAGS} ${T73OBJECTS} parsit.o ${LIBS} install a.out trek73 bpv: ${BPVOBJECTS} cc ${CFLAGS} ${BPVOBJECTS} install a.out bpv shipyard: ${DYOOBJECTS} cc ${CFLAGS} ${DYOOBJECTS} -lm install a.out shipyard ${T73OBJECTS}: ${HEADS} ${BPVOBJECTS}: ${HEADS} ${DYOOBJECTS}: ${HEADS} parsit.o: parsit.c cc -O -c parsit.c tags: ${T73CFILES} ctags ${T73CFILES} ${HEADS} count: wc ${T73CFILES} ${HEADS} lint: lint -abchx ${DEFINES} ${T73CFILES} > lint.errs clean: rm -f ${BINS} ${T73OBJECTS} ${DYOOBJECTS} ${BPVOBJECTS} ${FLUFF} shar: shar.1 shar.2 shar.3 shar.4 shar.1: Makefile defines.h externs.h options.h structs.h cmds1.c cmds2.c shar Makefile defines.h externs.h options.h structs.h cmds1.c cmds2.c >$@ shar.2: cmds3.c cmds4.c damage.c dist.c endgame.c enemycom.c shar cmds3.c cmds4.c damage.c dist.c endgame.c enemycom.c >$@ shar.3: firing.c globals.c init.c main.c misc.c mission.c bpv.c shipyard.c shar firing.c globals.c init.c main.c misc.c mission.c bpv.c shipyard.c >$@ shar.4: moveships.c parseopts.c parsit.c save.c ships.c special.c strat1.c subs.c vers.c shar moveships.c parseopts.c parsit.c save.c ships.c special.c strat1.c subs.c vers.c >$@ SHAR_EOF chmod +x 'Makefile' fi # end of overwriting check if test -f 'defines.h' then echo shar: will not over-write existing file "'defines.h'" else cat << \SHAR_EOF > 'defines.h' /* * TREK73: defines.h * * Defines for TREK73 * */ /* Globals externals */ extern char *strcpy(), *gets(); extern char *Gets(); extern float rectify(), bearing(); #ifdef BSD extern long random(); #endif #ifdef SYSV #define random() ((long)(rand())) #define srandom(seed) (srand((unsigned)(seed))) #endif #define is_dead(sp, sys) ((sp)->status[sys] == 100) #define randm(x) ((int)random() % (x) + 1) #define syswork(sp, sys) (randm(100) > (sp)->status[sys]) #define toradians(x) ((double)(x)*.0174533) #define todegrees(x) ((double)(x)*57.2958) #define betw(i, j, k) (((j) < (i)) && ((i) < (k))) #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) #define cansee(x) ((x)->cloaking != C_ON) #define cantsee(x) ((x)->cloaking == C_ON) #define plural(n) (((n) > 1) ? "s" : "") #ifndef NULL #define NULL 0 #endif /* * for the item linked list */ #define I_UNDEFINED 0 #define I_SHIP 1 #define I_TORPEDO 2 #define I_PROBE 3 #define I_ENG 4 /* * for the ship status word */ #define S_COMP 0 #define S_SENSOR 1 #define S_PROBE 2 #define S_WARP 3 #define S_ENG 4 #define S_DEAD 5 #define S_SURRENDER 6 /* The following define must also be in structs.h */ #define S_NUMSYSTEMS 4 /* Number of systems with damage descriptions */ #define MAXSYSTEMS 7 /* * for the status message turn off array (shutup[]) */ #define DISENGAGE 1 /* Autopilot disengaging */ #define SHIELDSF 2 /* Shields fluctuating */ #define PHASERS 3 /* Phasers disengaging */ #define TUBES (PHASERS + MAXPHASERS) /* Tubes disengaging */ #define SURRENDER (TUBES + MAXTUBES) /* Flag for enemy surrender */ #define SURRENDERP 20 /* Flag for our surrender */ #define PLAYDEAD 21 /* Flag for playing dead */ #define CORBOMITE 22 /* Flag for corbomite bluff */ #define BURNOUT 23 /* Flag for warp burnout */ #define HIGHSHUTUP (BURNOUT + 10) /* Burnout + 10 */ /* * Multiplier for shield 1 */ #define SHIELD1 1.5 /* * Defines for the play status word */ #define NORMAL 000 #define F_SURRENDER 001 #define E_SURRENDER 002 /* * Phaser statuses */ #define P_NORMAL 000 #define P_DAMAGED 001 #define P_FIRING 002 /* * Tube statuses */ #define T_NORMAL 000 #define T_DAMAGED 001 #define T_FIRING 002 /* * Probe launcher status */ #define PR_NORMAL 000 #define PR_LAUNCHING 001 #define PR_DETONATE 002 #define PR_LOCK 004 /* * Cloaking device status / capability */ #define C_NONE 000 #define C_OFF 001 #define C_ON 002 #define CLOAK_DELAY 2 /* * Number of turns after cloak is * dropped before it can be reactivated */ /* * For the damage routine */ #define D_PHASER 0 #define D_ANTIMATTER 1 /* * Some necessary constants */ #define HIT_PER_POD 5 #define PROX_PER_POD 50 /* * A handy little routine */ #define MKNODE(cast, star, number) (cast star)malloc(sizeof(cast) * number) /* * Definitions for the bad guys */ #define MAXESHIPS 9 #define MAXFEDS 9 #define MAXECAPS 8 #define MAXFOERACES 9 /* * For the different ship classes */ #define MAXSHIPCLASS 4 #define MAXPHASERS 11 #define MAXTUBES 11 /* * Turn costs (either takes a turn or is a free command) */ #define TURN 1 #define FREE 0 /* * Type of torpedo object (can be probe, torpedo, or engineering) */ #define TP_TORPEDO 0 #define TP_PROBE 1 #define TP_ENGINEERING 2 /* * Defines for the end of game calls to warn and final */ #define FIN_F_LOSE 0 #define FIN_E_LOSE 1 #define FIN_TACTICAL 2 #define FIN_F_SURRENDER 3 #define FIN_E_SURRENDER 4 #define FIN_COMPLETE 5 #define QUIT 6 /* * Number of items we allow in space. */ #define HIGHSLOT 300 /* * Trace flags */ #define TR_OFF 0 #define TR_ON 1 /* * Some hard constants */ #define MIN_PHASER_SPREAD 10 #define MAX_PHASER_SPREAD 45 #define MAX_PHASER_RANGE 1000 #define MAX_PHASER_CHARGE 10. #define MIN_PHASER_DRAIN -MAX_PHASER_CHARGE #define MAX_PHASER_DRAIN MAX_PHASER_CHARGE #define MAX_TUBE_CHARGE 10 #define MAX_TUBE_PROX 500 /* 50 times the number of pods */ #define MAX_TUBE_SPEED 12 #define MAX_TUBE_TIME 10. #define MAX_PROBE_DELAY 15 #define MIN_PROBE_CHARGE 10 #define MIN_PROBE_PROX 50 #define MIN_SENSOR_RANGE 100 #define MAX_SENSOR_RANGE 50000 #define INIT_P_SPREAD MIN_PHASER_SPREAD #define INIT_P_LOAD MAX_PHASER_CHARGE #define INIT_P_DRAIN MAX_PHASER_DRAIN #define INIT_P_PERCENT 100 #define INIT_T_LOAD 0 #define INIT_T_PROX 200 #define INIT_T_TIME MAX_TUBE_TIME #define INIT_T_SPEED MAX_TUBE_SPEED SHAR_EOF chmod +x 'defines.h' fi # end of overwriting check if test -f 'externs.h' then echo shar: will not over-write existing file "'externs.h'" else cat << \SHAR_EOF > 'externs.h' /* * TREK73: externs.h * * External declarations for TREK73 * */ /* UNIX include files needed for most (if not all) of the C files */ #include <stdio.h> #ifdef SYSV #include <string.h> #endif SYSV #ifdef BSD #include <strings.h> #endif BSD #include <math.h> /* UNIX extern declarations of functions used which do not return int plus any extern variable declarations */ extern char *getenv(), *malloc(); extern long time(); extern unsigned sleep(), alarm(); extern void exit(), free(), perror(); #ifdef SYSV extern void srand(); #endif SYSV extern char *optarg; /* * Now continue with declarations specific to TREK73 */ #include "structs.h" extern char *Gets(), *vowelstr(); extern char *sysname[S_NUMSYSTEMS]; extern char *statmsg[S_NUMSYSTEMS + 1]; extern char *feds[]; extern char *options; extern float init_p_turn[MAXPHASERS][MAXPHASERS]; extern float init_t_turn[MAXTUBES][MAXTUBES]; extern float segment, timeperturn; extern float rectify(), bearing(); extern char home[256]; extern char savefile[256]; extern char captain[30]; extern char class[3]; extern char com[30]; extern char com_delay[6]; extern char empire[30]; extern char engineer[30]; extern char foeclass[3]; extern char foename[30]; extern char foerace[30]; extern char foestype[30]; extern char helmsman[30]; extern char nav[30]; extern char racename[20]; extern char savefile[256]; extern char science[30]; extern char sex[20]; extern char shipname[30]; extern char shutup[HIGHSHUTUP]; extern char slots[HIGHSLOT]; extern char title[9]; extern int cmdarraysize; extern int corbomite; extern int defenseless; extern int enemynum; extern int global; extern int high_command; extern int reengaged; extern int restart; extern int shipnum; extern int silly; extern int surrender; extern int surrenderp; extern int teletype; extern int terse; extern int time_delay; extern int trace; extern char can_cloak; extern double o_bpv; extern double e_bpv; extern struct ship_stat us; extern struct ship_stat them; extern int (*strategies[])(); extern int rangefind(); extern struct cmd *scancmd(), cmds[]; extern struct race_info aliens[MAXFOERACES]; extern struct damage p_damage, a_damage; extern struct list *newitem(), head, *tail; extern struct ship *shiplist[10], *ship_name(); extern struct ship_stat stats[]; SHAR_EOF chmod +x 'externs.h' fi # end of overwriting check if test -f 'options.h' then echo shar: will not over-write existing file "'options.h'" else cat << \SHAR_EOF > 'options.h' /* * TREK73: options.h * * Parse_opts defines * */ #define BOOLEAN 0 #define STRING 1 SHAR_EOF chmod +x 'options.h' fi # end of overwriting check if test -f 'structs.h' then echo shar: will not over-write existing file "'structs.h'" else cat << \SHAR_EOF > 'structs.h' /* * TREK73: structs.h * * Struct Defs for TREK73 * */ #include "defines.h" struct phaser { struct ship *target; /* who we're aimed at */ float bearing; /* direction aimed (if no target) */ int drain; /* Drain from engines (to if negative) */ short load; /* energy in phasers */ char status; /* Damaged, etc. */ } ; struct tube { struct ship *target; /* who we're aimed at */ float bearing; /* direction aimed (if no target) */ int load; /* energy in tubes */ char status; /* Damaged, etc */ } ; struct shield { float eff; /* efficiency from 0-1 */ float drain; /* Actual drain from engines */ float attemp_drain; /* Attempted drain from engines */ } ; #define MAXWEAPONS 11 #define SHIELDS 4 struct ship { char name[30]; /* name of ship */ char class[3]; /* Type of ship */ int x, y; /* location */ float warp; /* warp speed */ float newwarp; /* for speed changes */ float course; /* 0-360 */ float newcourse; /* for course changes */ struct ship *target; /* who we're pursuing */ float relbear; /* Relative bearing to keep */ struct phaser phasers[MAXWEAPONS]; /* phaser banks */ int p_spread; /* phaser spread */ int p_percent; /* phaser firing percentage */ int p_blind_left; /* phaser blind area, left side angle */ int p_blind_right; /* phaser blind area, right side angle */ struct tube tubes[MAXWEAPONS]; /* torpedo tubes */ int t_prox; /* proximity delay */ int t_delay; /* time delay to detonation */ int t_lspeed; /* launch speed */ int t_blind_left; /* tube blind area, left side angle */ int t_blind_right; /* tube blind area, right side angle */ struct shield shields[SHIELDS]; /* shields */ int probe_status; /* Probe launcher status */ float eff; /* efficiency */ float regen; /* regeneration (energy per turn) */ float energy; /* amount of effective energy */ float pods; /* max energy level */ int complement; /* crew left alive */ int status[MAXSYSTEMS]; /* Holds damage percentage of these systems */ float delay; /* how long 'till we blow up? */ int id; /* Unique identifier */ int num_phasers; /* Number of phasers */ int num_tubes; /* Number of tubes */ float orig_max; /* Maximum original warp */ float max_speed; /* Maximum warp */ float deg_turn; /* Degrees per warp turn */ float ph_damage; /* Damage divisor from phasers */ float tu_damage; /* Damage divisor from tubes */ int cloaking; /* Cloaking device status */ int cloak_energy; /* Energy needed to run cloak per segment */ int cloak_delay; /* Time until a cloak may be restarted */ int (*strategy)(); /* Which strategy to use */ struct pos { /* Last known position (before a cloak) */ int x,y; /* Coordinates */ float warp; /* Warp speed */ int range; /* Distance to ship */ float bearing; /* Bearing */ float course; /* Course */ } position ; int p_firing_delay; /* Delay in segments for firing phasers */ int t_firing_delay; /* Delay in segments for firing torpedoes */ } ; /* * note that probes act like torpedos * but have targets; torps only have * courses */ struct torpedo { struct ship *from; /* pointer to ship they're from */ int x, y; /* coords of object */ float course; /* where it's going */ float speed; /* how fast we're moving */ float newspeed; /* what our target speed is */ struct ship *target; /* who we're aimed at */ int fuel; /* how many antimatter pods it has */ float timedelay; /* seconds until detonation */ int prox; /* proximity fuse */ int id; /* Unique identifier */ int type; /* torpedo, probe, or engineering */ } ; /* * the list of what's in space -- depending on the type, we use * differing parts of the union (data) structure. it's a linked * list of all the stuff in space. */ struct list { int type; struct list *back, *fwd; union { struct torpedo *tp; struct ship *sp; } data; } ; struct cmd { int (*routine)(); char *word1; char *word2; int turns; } ; /* * for the phaser and anti-matter damage lists */ struct dam { int roll; char *mesg; }; struct damage { float eff; float fuel; float regen; float crew; float weapon; struct dam stats[S_NUMSYSTEMS]; }; struct score { int score; int ships; char captain[30]; char username[10]; }; struct rates { char *rate; int points; }; struct ship_stat { char abbr[4]; /* Abbreviation */ int class_num; /* Index into array */ int num_phaser; /* Number of phasers */ int num_torp; /* Number of tubes */ int o_warpmax; /* Own max speed */ int e_warpmax; /* Enemy max speed */ float o_eff; /* Own efficiency */ float e_eff; /* Enemy efficiency */ float regen; /* Regeneration */ float energy; /* Starting fuel */ float pods; /* Max pods */ int o_crew; /* Own crew */ int e_crew; /* Enemy crew */ float ph_shield; /* Divisor for phaser damage */ float tp_shield; /* Divisor for torp damage */ int turn_rate; /* Degrees per warp-second */ int cloaking_energy; /* Energy to run cloaking device */ int t_blind_left; /* Start of tube blind area left */ int t_blind_right; /* Start of tube blind area right */ int p_blind_left; /* Start of phaser blind area left */ int p_blind_right; /* Start of phaser blind area right */ /* Must change to absolute time */ int p_firing_delay; /* Delay in segments for firing phasers */ int t_firing_delay; /* Delay in segments for firing torpedoes */ }; struct race_info { char race_name[30]; /* Name of the race */ char empire_name[30]; /* What they call themselves */ int id; /* Identifier number */ int surrender; /* Chance they will accept a surrender */ int surrenderp; /* Chance they will surrender to you */ int corbomite; /* Chance they fall for a corbomite bluff */ int defenseless; /* Chance they fall for a defenseless ruse */ int attitude; /* Attitude factor for strategies */ char *ship_names[MAXESHIPS]; /* Ship names */ char *ship_types[MAXSHIPCLASS]; /* Ship types */ char *captains[MAXECAPS]; /* Some exemplary captains */ /* * For the strategic game that is to come. -Deep Thought */ int relation; /* Diplomatic relation with other races */ }; struct planet { char name[30]; /* Planetary name */ int id; /* Unique identifier number */ int x; /* Location in the X plane */ int y; /* Location in the Y plane */ int radius; /* Planetary radius */ int mass; /* Planetary mass */ int race; /* Owner's race */ /* * planetary weaponry goes here */ }; SHAR_EOF chmod +x 'structs.h' fi # end of overwriting check if test -f 'cmds1.c' then echo shar: will not over-write existing file "'cmds1.c'" else cat << \SHAR_EOF > 'cmds1.c' /* * TREK73: cmds1.c * * User Commands * * fire_phasers, fire_tubes, lock_phasers, lock_tubes, * turn_phasers, turn_tubes, load_tubes, launch_probe, * probe_control * */ #include "externs.h" fire_phasers(sp) struct ship *sp; { char buf1[20]; char buf2[20]; char c; int typed[MAXPHASERS]; register int i; register int k; for (i=0; i<MAXPHASERS; i++) typed[i] = 0; printf(" fire phasers [1-%d] ", sp->num_phasers); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) { printf("%s: Belay that order!\n", captain); return 0; } printf(" spread [10-45] "); (void) Gets(buf2, sizeof(buf2)); if (buf2[0] == NULL) { printf("%s: Belay that order!\n", captain); return 0; } i = atoi(buf2); if (i < 10 || i > 45) return 0; sp->p_spread = i; if (strcmp(buf1, "all") && strcmp(buf1, "ALL")) for (i=0; c = buf1[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_phasers - 1) continue; typed[k]++; if (sp->phasers[k].status & (P_DAMAGED | P_FIRING)) continue; sp->phasers[k].status |= P_FIRING; } else for (i=0; i<sp->num_phasers; i++) { typed[i]++; if (sp->phasers[i].status & (P_DAMAGED | P_FIRING)) continue; sp->phasers[i].status |= P_FIRING; } check_p_damage(typed, sp, "fire"); /* Type out if damaged */ check_p_turn(typed, sp, 1); return 1; } fire_tubes(sp) struct ship *sp; { char buf1[20]; char c; int typed[MAXTUBES]; register int i; register int j; register int k; for (i=0; i<MAXTUBES; i++) typed[i] = 0; printf(" fire tubes [1-%d] ", sp->num_tubes); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) { printf("%s: Belay that order!\n", captain); return 0; } if (strcmp(buf1, "all") && strcmp(buf1, "ALL")) for (i=0; c = buf1[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_tubes - 1) continue; typed[k]++; if (sp->tubes[k].status & (T_DAMAGED | T_FIRING)) continue; sp->tubes[k].status |= T_FIRING; } else for (i=0; i<sp->num_tubes; i++) { typed[i]++; if (sp->tubes[i].status & (T_DAMAGED | T_FIRING)) continue; sp->tubes[i].status |= T_FIRING; } check_t_damage(typed, sp, "fire"); /* Type if damaged */ check_t_turn(typed, sp, 1); j = 0; for (i=0; i < sp->num_tubes; i++) { if ((typed[i] == 0) || (!(sp->tubes[i].status & T_FIRING))) continue; if (sp->tubes[i].load == 0) { if (!j) printf("Computer: Tube(s) %d", i + 1); else printf(", %d", i + 1); j++; } } if (j > 1) puts(" are not loaded."); else if (j == 1) puts(" is not loaded."); return 0; } lock_phasers(sp) struct ship *sp; { char buf1[20]; char buf2[20]; int typed[MAXPHASERS]; char c; struct ship *ep; register int i; register int k; for (i=0; i<MAXPHASERS; i++) typed[i] = 0; if (is_dead(sp, S_COMP)) { printf("%s: Impossible %s, our computer is dead.\n", science, title); return 0; } if (!syswork(sp, S_COMP)) { printf("%s: Our computer is temporarily buggy", science); return 0; } printf(" lock phasers [1-%d] ", sp->num_phasers); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; printf(" onto [whom] "); (void) Gets(buf2, sizeof(buf2)); if (buf2[0] == NULL) return 0; ep = ship_name(buf2); if (ep == NULL) return 0; if (cantsee(ep)) { printf("%s: %s, unable to lock phasers onto %s.\n", nav, title, ep->name); return 0; } if (strcmp(buf1, "all") && strcmp(buf1, "ALL")) for (i=0; c = buf1[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_phasers - 1) continue; typed[k]++; if (sp->phasers[k].status & P_DAMAGED) continue; sp->phasers[k].target = ep; } else for (i=0; i<sp->num_phasers; i++) { typed[i]++; if (sp->phasers[i].status & P_DAMAGED) continue; sp->phasers[i].target = ep; } check_p_damage(typed, sp, "lock"); check_p_turn(typed, sp, 0); return 1; } lock_tubes(sp) struct ship *sp; { char buf1[20]; char buf2[20]; int typed[MAXTUBES]; char c; struct ship *ep; register int i; register int k; for (i=0; i<sp->num_tubes; i++) typed[i] = 0; if (is_dead(sp, S_COMP)) { printf("%s: Impossible %s, our computer is dead.\n", science, title); return 0; } if (!syswork(sp, S_COMP)) { printf("%s: Our computer is temporarily buggy", science); return 0; } printf(" lock tubes [1-%d] ", sp->num_tubes); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; printf(" onto whom "); (void) Gets(buf2, sizeof(buf2)); if (buf2[0] == NULL) return 0; ep = ship_name(buf2); if (ep == NULL) return 0; if (cantsee(ep)) { printf ("%s: %s, unable to lock tubes onto %s.", nav, title, ep->name); return 0; } if (strcmp(buf1, "all") && strcmp(buf1, "ALL")) for (i=0; c = buf1[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_tubes - 1) continue; typed[k]++; if (sp->tubes[k].status & T_DAMAGED) continue; sp->tubes[k].target = ep; } else for (i=0; i<sp->num_tubes; i++) { typed[i]++; if (sp->tubes[i].status & T_DAMAGED) continue; sp->tubes[i].target = ep; } check_t_damage(typed, sp, "lock"); check_t_turn(typed, sp, 0); return 1; } turn_phasers(sp) struct ship *sp; { char buf1[20]; char buf2[20]; char c; int typed[MAXPHASERS]; register int i; register float j; register int k; for (i=0; i<MAXPHASERS; i++) typed[i] = 0; printf(" turn phasers [1-%d] ", sp->num_phasers); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; printf(" to [0-360] "); (void) Gets(buf2, sizeof(buf2)); if (buf2[0] == NULL) return 0; j = atof(buf2); if (j < 0.0 || j > 360.0) return 0; if (strcmp(buf1, "all") && strcmp(buf1, "ALL")) for (i=0; c = buf1[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_phasers - 1) continue; typed[k]++; if (sp->phasers[k].status & P_DAMAGED) continue; sp->phasers[k].target = NULL; sp->phasers[k].bearing = j; } else for (i=0; i<sp->num_phasers; i++) { typed[i]++; if (sp->phasers[i].status & P_DAMAGED) continue; sp->phasers[i].target = NULL; sp->phasers[i].bearing = j; } check_p_damage(typed, sp, "turn"); check_p_turn(typed, sp, 0); return 1; } turn_tubes(sp) struct ship *sp; { char buf1[20]; char buf2[20]; char c; int typed[MAXTUBES]; register int i; register float j; register int k; for (i=0; i<MAXTUBES; i++) typed[i] = 0; printf(" turn tubes [1-%d] ", sp->num_tubes); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; printf(" to [0-360] "); (void) Gets(buf2, sizeof(buf2)); if (buf2[0] == NULL) return 0; j = atof(buf2); if (j < 0.0 || j > 360.0) return 0; if (strcmp(buf1, "all") && strcmp(buf1, "ALL")) for (i=0; c = buf1[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_tubes - 1) continue; typed[k]++; if (sp->tubes[k].status & T_DAMAGED) continue; sp->tubes[k].target = NULL; sp->tubes[k].bearing = j; } else for (i=0; i<sp->num_tubes; i++) { typed[i]++; if (sp->tubes[i].status & T_DAMAGED) continue; sp->tubes[i].target = NULL; sp->tubes[i].bearing = j; } check_t_damage(typed, sp, "turn"); check_t_turn(typed, sp, 0); return 1; } load_tubes(sp) struct ship *sp; { char buf1[20]; char buf2[20]; char c; int load; struct tube *tp; int typed[MAXTUBES]; register int i; register float j; register int k; for (i=0; i<MAXTUBES; i++) typed[i] = 0; load = 0; printf(" [load or unload] "); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if (*buf1 == 'l' || *buf1 == 'L') load++; else if (*buf1 != 'u' && *buf1 != 'U') return 0; printf(" tubes [1-%d] ", sp->num_tubes); (void) Gets(buf2, sizeof(buf2)); if (buf2[0] == NULL) return 0; if (strcmp(buf2, "all") && strcmp(buf2, "ALL")) for (i=0; c = buf2[i]; i++) { k = c - '1'; if (k < 0 || k > sp->num_tubes - 1) continue; typed[k]++; } else for (i=0; i<sp->num_tubes; i++) typed[i]++; for (i = 0; i < sp->num_tubes; i++) { tp = &sp->tubes[i]; if (!typed[i] || tp->status & T_DAMAGED) continue; if (load) { j = min(sp->energy, MAX_TUBE_CHARGE - tp->load); if (j <= 0) continue; sp->energy -= j; sp->pods -= j; tp->load += j; } else { j = tp->load; if (j <= 0) continue; sp->energy += j; sp->pods += j; tp->load = 0; } } printf("%s: Tubes now ", engineer); for (i=0; i<sp->num_tubes; i++) { if (sp->tubes[i].status & T_DAMAGED) printf(" -- "); else printf(" %-2d ", sp->tubes[i].load); } printf(" energy at %d/%d\n", (int)sp->energy, (int)sp->pods); return 1; } launch_probe(sp) struct ship *sp; { char buf1[20]; int pods, delay, prox; float course; struct ship *target; struct list *lp; struct torpedo *pp; pods = delay = prox = 0; course = 0.0; target = NULL; if (is_dead(sp, S_PROBE)) { printf("%s: Probe launcher destroyed!\n", engineer); return 0; } if (!syswork(sp, S_PROBE)) { printf("%s: Probe launcher temporarily disabled, %s\n", engineer, title); return 0; } if (sp->energy < MIN_PROBE_CHARGE) { printf("%s: We've not enough power, Captain.\n", engineer); return 0; } printf("%s: %d pods available.\n", engineer, (int)sp->energy); printf("%s: Number to launch [%d+] is ", captain, MIN_PROBE_CHARGE); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) goto bad_param; pods = atoi(buf1); if (pods < MIN_PROBE_CHARGE || pods > sp->energy) goto bad_param; printf(" set time delay to [0-%d] ", MAX_PROBE_DELAY); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) goto bad_param; delay = atoi(buf1); if (delay < 0 || delay > MAX_PROBE_DELAY) goto bad_param; printf(" set proximity delay to [%d+] ", MIN_PROBE_PROX); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) goto bad_param; prox = atoi(buf1); if (prox < MIN_PROBE_PROX) goto bad_param; printf(" launch towards [whom, if anyone] "); Gets(buf1, sizeof(buf1)); if (*buf1) { target = ship_name(buf1); if (target == NULL) goto bad_param; if (cantsee(target) || !syswork(sp, S_SENSOR)) { printf("%s: %s, unable to lock probe onto the %s.\n", helmsman, title, target->name); return 0; } } else { printf(" course [0-360] "); if (gets(buf1) == NULL) goto bad_param; course = atof(buf1); if (course < 0.0 || course > 360.0) goto bad_param; target = NULL; } /* * add a new item to the list of items in space */ lp = newitem(I_PROBE); lp->data.tp = MKNODE(struct torpedo, *, 1); pp = lp->data.tp; if (pp == (struct torpedo *)NULL) { fprintf(stderr, "launch_probe: malloc failed\n"); exit(2); } pp->from = sp; pp->fuel = pods; pp->timedelay = delay; pp->speed = sp->warp; pp->newspeed = 3.0; pp->prox = prox; pp->target = target; pp->course = course; pp->x = sp->x; pp->y = sp->y; pp->id = new_slot(); pp->type = TP_PROBE; /* * subtract the pods used */ sp->pods -= pods; sp->energy -= pods; sp->probe_status = PR_LAUNCHING; printf("%s: Probe %d away\n",engineer, pp->id); return 1; bad_param: printf("%s: Bad parameters, %s.\n", science, title); return 0; } probe_control(sp) struct ship *sp; { register struct list *lp; register int i; register float j; register struct torpedo *pp; struct torpedo *probes[20]; int probenum; struct ship *ep; int pnum; float bear; int range; char buf1[20]; char *bp; pnum = 0; for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type != I_PROBE) continue; pp = lp->data.tp; if (pp->from != sp) continue; if (!pnum) printf("\nprobe bearng range course time prox units target\n"); if (pnum >= sizeof probes / sizeof probes[0]) { printf("\n%s: There are other probes out but\n", nav); puts(" these are all we can control at one time."); } probes[pnum] = pp; pnum++; range = rangefind(sp->x, pp->x, sp->y, pp->y); bear = bearing(sp->x, pp->x, sp->y, pp->y); if (pp->target == NULL) bp = "NONE"; else bp = pp->target->name; printf(" %2d %4.1f %5d %4.0f %4.1f %5d %3d %s\n", pp->id, bear, range, pp->course, pp->timedelay, pp->prox, pp->fuel, bp); } if (!pnum) { printf("%s: What probes?\n", nav); return 0; } printf("%s: Detonate all probes?\n", nav); printf("%s: [yes or no] ", captain); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] != NULL && (*buf1 == 'Y' || *buf1 == 'y')) { printf("%s: Aye, %s\n", nav, title); for (i=0; i<pnum; i++) probes[i]->timedelay = 0.0; sp->probe_status = PR_DETONATE; return 1; } printf(" control probe [#] "); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; probenum = atoi(buf1); for (i=0; i<pnum; i++) if (probes[i]->id == probenum) break; if (i == pnum) return 0; probenum = i; printf("%s: Detonate it?\n", nav); printf("%s: [yes or no] ", captain); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] != NULL && (*buf1 == 'y' || *buf1 == 'Y')) { probes[probenum]->timedelay = 0.; sp->probe_status = PR_DETONATE; return 1; } printf(" lock it onto [whom, if anyone] "); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] != NULL) { ep = ship_name(buf1); if (ep != NULL) { sp->probe_status = PR_LOCK; if (cansee(ep) && syswork(sp, S_SENSOR)) { probes[probenum]->target = ep; printf("%s: locking.\n", nav); return 1; } else { printf("%s: %s, unable to lock probe on the %s.\n", helmsman, title, ep->name); return 0; } } } printf(" set it to course [0-360] "); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; sp->probe_status = PR_LOCK; j = atof(buf1); if (j < 0.0 || j > 360.0) return 0; probes[probenum]->course = j; probes[probenum]->target = NULL; printf("%s: setting in new course.\n", nav); return 1; } SHAR_EOF chmod +x 'cmds1.c' fi # end of overwriting check if test -f 'cmds2.c' then echo shar: will not over-write existing file "'cmds2.c'" else cat << \SHAR_EOF > 'cmds2.c' /* * TREK73: cmds2.c * * User Commands * * pos_report, pos_display, pursue, elude, helm, self_scan, scan * * (print_damages) * */ #include "externs.h" #include <ctype.h> pos_report(sp) struct ship *sp; { struct ship *sp1; struct torpedo *tp; struct list *lp; int x, y; int range; float bear; float speed; float course; float relbear; float revrelbear; int maxlen = 0; int incltorp = 0; char whitespace[5], who[80]; #ifdef SHOWTORP char buf[20]; #endif #ifdef SHOWTORP printf("%s: Include torpedoes?\n", science); printf("%s: [yes or no] ", captain); if (Gets(buf, sizeof buf) != NULL && (buf[0] == 'y' || buf[0] == 'Y')) incltorp = 1; #endif /* * Go through the list of objects and find out the longest * name of any of them. This is to insure that no matter * what the names of the ship, the position report will * come out formatted. */ for (lp = &head; lp != tail; lp = lp->fwd) switch(lp->type) { case I_SHIP: sp1 = lp->data.sp; maxlen = max(maxlen, strlen(sp1->name)); break; #ifdef SHOWTORP case I_TORPEDO: if (!incltorp) break; tp = lp->data.tp; maxlen = max(maxlen, strlen(tp->from->name) + 8); break; #endif case I_PROBE: tp = lp->data.tp; maxlen = max(maxlen, strlen(tp->from->name) + 9); break; case I_ENG: tp = lp->data.tp; maxlen = max(maxlen, strlen(tp->from->name) + 12); break; } maxlen += 2; /* For "cloaked" column */ /* * Construct a string %ns where n is the length of the * longest name. */ (void) sprintf(whitespace, "%%%ds", maxlen); /* * And print out the position report */ printf(whitespace, " "); puts(" abs rel rev rel"); printf(whitespace, " "); puts(" class warp course bearing range bearing bearing"); for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type == 0) continue; sp1 = NULL; tp = NULL; if (lp->type == I_SHIP) { sp1 = lp->data.sp; if (is_dead(sp1, S_DEAD)) continue; if (cansee(sp1)) { x = sp1->x; y = sp1->y; speed = sp1->warp; course = sp1->course; /* Reset what we know about his position */ sp1->position.x = sp1->x; sp1->position.y = sp1->y; sp1->position.warp = sp1->warp; sp1->position.course = sp1->course; sp1->position.bearing = bearing(sp->x, sp1->x, sp->y, sp1->y); sp1->position.range = rangefind(sp->x, sp1->x, sp->y, sp1->y); (void) sprintf(who, "%.*s ", sizeof who - 3, sp1->name); } else { x = sp1->position.x; y = sp1->position.y; speed = sp1->position.warp; course = sp1->position.course; (void) sprintf(who, "%.*s *", sizeof who - 3, sp1->name); } } else { tp = lp->data.tp; if (lp->type == I_TORPEDO && !incltorp) continue; x = tp->x; y = tp->y; speed = tp->speed; course = tp->course; switch(lp->type) { #ifdef SHOWTORP case I_TORPEDO: (void) sprintf(who,"%.*s torp %d ", sizeof who - 11, tp->from->name, tp->id); break; #endif case I_PROBE: (void) sprintf(who, "%.*s probe %d ", sizeof who - 12, tp->from->name, tp->id); break; case I_ENG: (void) sprintf(who,"%.*s engineering ", sizeof who - 15, tp->from->name); break; default: (void) sprintf(who, "lp->type = %d ", lp->type); break; } } printf(whitespace, who); if (sp1) printf("%5s", sp1->class); else printf(" "); printf("%6.1f %3.0f ", speed, course); if (sp1 == sp) { if (sp->target != NULL) printf("helm locked on %s", sp->target->name); putchar('\n'); } else { bear = bearing(sp->x, x, sp->y, y); range = rangefind(sp->x, x, sp->y, y); relbear = rectify(round(bear - sp->course)); revrelbear = rectify(round(bear + 180.0 - course)); printf(" %3.0f %5d %3.0f %3.0f\n", bear, range, relbear, revrelbear); } } return 0; } pos_display(sp) struct ship *sp; { register int i; register int j; int range; char buf1[20]; int x, y; float xf, yf; int h, v; int hpitch = 10; int vpitch = 6; char map[13][23]; /* [2*MAXvpitch + 1][2*MAXhpitch + 1] */ struct list *lp; struct ship *sp1; struct torpedo *tp; char c; if (is_dead(sp, S_SENSOR)) { printf("%s: Sensors are damaged.\n", science); return 0; } if (!syswork(sp, S_SENSOR)) { printf("%s: Sensors are temporarily inoperative.\n", science); return 0; } printf(" display to [%d-%d] ", MIN_SENSOR_RANGE, MAX_SENSOR_RANGE); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; range = atoi(buf1); if (range < MIN_SENSOR_RANGE || range > MAX_SENSOR_RANGE) return 0; /* * Compensation for aspect ratio of the output device */ x = range/hpitch; y = range/vpitch; for (i=0; i<=2*vpitch; i++) { if (i == 0 || i == 2*vpitch) for(j=0; j<=2*hpitch; j++) map[i][j] = '-'; else for(j=0; j<=2*hpitch; j++) map[i][j] = ' '; } map[vpitch][hpitch] = '+'; for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->data.sp == sp) continue; if (lp->type == I_SHIP) { sp1 = lp->data.sp; if (cansee(sp1)) { /* Update the position */ sp1->position.x = sp1->x; sp1->position.y = sp1->y; sp1->position.warp = sp1->warp; sp1->position.course = sp1->course; sp1->position.bearing = bearing(sp->x, x, sp->y, y); sp1->position.range = rangefind(sp->x, x, sp->y, y); xf = sp1->x - sp->x; yf = sp1->y - sp->y; } else { xf = sp1->position.x - sp->x; yf = sp1->position.y - sp->y; } } else { tp = lp->data.tp; xf = tp->x - sp->x; yf = tp->y - sp->y; } v = yf/y + vpitch + 0.5; h = xf/x + hpitch + 0.5; if (v < 0 || v > 2*vpitch) continue; if (h < 0 || h > 2*hpitch) continue; switch (lp->type) { case I_SHIP: c = lp->data.sp->name[0]; if (cantsee(lp->data.sp)) c = tolower(c); break; case I_TORPEDO: c = ':'; break; case I_ENG: c = '#'; break; case I_PROBE: c = '*'; break; default: c = '?'; break; } map[2*vpitch - v][h] = c; } for (i=0; i<=2*vpitch; i++) { for (j=0; j<=2*hpitch; j++) if (map[i][j] != ' ') break; if (j <= 2*hpitch) printf("%.*s", 2*hpitch + 1, map[i]); putchar('\n'); } return 0; } pursue(sp) struct ship *sp; { register float i; char buf1[20]; struct ship *ep; float warp; if (is_dead(sp, S_COMP)) { printf("%s: Impossible, %s, our computer is dead\n",science ,title); return 0; } if (!syswork(sp, S_COMP)) { printf("%s: Main computer down, %s. Rebooting.\n", science, title); return 0; } printf(" Mr. %s, pursue [who] ", nav); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; ep = ship_name(buf1); if (ep == NULL) return 0; if (cantsee(ep)) { printf("%s: %s, unable to acquire helm lock.\n", nav, title); return 0; } printf(" Mr. %s, warp factor [-%.2f to %.2f] ", helmsman, sp->max_speed, sp->max_speed); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; warp = atof(buf1); if (fabs(warp) > 1.0 && is_dead(sp, S_WARP)) { printf("%s: Warp drive is dead, Captain.\n", science); warp = (warp < 0.0) ? -1.0 : 1.0; } if (fabs(warp) > sp->max_speed) { printf("%s: %s, the engines canna go that fast!\n",engineer, title); warp = (warp < 0.0) ? -sp->max_speed : sp->max_speed; } sp->newwarp = warp; sp->target = ep; sp->relbear = 0.0; i = bearing(sp->x, ep->x, sp->y, ep->y); printf("%s: Aye, %s, coming to course %3.0f.\n", nav, title, i); sp->newcourse = i; return 1; } elude(sp) struct ship *sp; { register float i; char buf1[20]; struct ship *ep; float warp; if (is_dead(sp, S_COMP)) { printf("%s: Impossible, %s, our computer is dead\n", science, title); return 0; } if (!syswork(sp, S_COMP)) { printf("%s: Main computer down, %s. Rebooting.\n", science, title); return 0; } printf(" Mr. %s, elude [who] ", nav); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; ep = ship_name(buf1); if (ep == NULL) return 0; if (cantsee(ep)) { printf("%s: %s, unable to acquire helm lock.\n", nav, title); return 0; } printf(" Mr. %s, warp factor [-%.2f to %.2f] ", helmsman, sp->max_speed, sp->max_speed); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; warp = (float) atof(buf1); if (fabs(warp) > 1.0 && is_dead(sp, S_WARP)) { printf("%s: Warp drive is dead, Captain.\n", science); warp = (warp < 0.0) ? -1.0 : 1.0; } if (fabs(warp) > sp->max_speed) { printf("%s: %s, the engines canna go that fast!\n",engineer, title); warp = (warp < 0.0) ? -sp->max_speed : sp->max_speed; } sp->newwarp = warp; sp->target = ep; sp->relbear = 180.0; i = bearing(sp->x, ep->x, sp->y, ep->y); i = rectify(i + 180.0); printf("%s: Aye, %s, coming to course %3.0f.\n", nav, title, i); sp->newcourse = i; return 1; } helm(sp) struct ship *sp; { char buf1[20]; register float course; float warp; printf(" Mr. %s, come to course [0-359] ", nav); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; course = atof(buf1); if (course < 0.0 || course >= 360.0) return 0; printf(" Mr. %s, warp factor [-%.2f to %.2f] ", helmsman, sp->max_speed, sp->max_speed); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; warp = (float) atof(buf1); if (fabs(warp) > 1.0 && is_dead(sp, S_WARP)) { printf("%s: Warp drive is dead, Captain.\n", science); warp = (warp < 0.0) ? -1.0 : 1.0; } if (fabs(warp) > sp->max_speed) { printf("%s: %s, the engines canna go that fast!\n",engineer, title); warp = (warp < 0.0) ? -sp->max_speed : sp->max_speed; } sp->newwarp = warp; sp->newcourse = course; sp->target = NULL; sp->relbear = 0.0; printf("%s: Aye, %s.\n", nav, title); printf("%s: Aye, %s.\n", helmsman, title); return 1; } self_scan(sp) struct ship *sp; { (void) print_damage(sp); return 1; } scan(sp) struct ship *sp; { struct ship *ep = NULL; struct torpedo *tp = NULL; struct list *lp; int item = I_UNDEFINED; int probe_num; char buf1[20]; printf(" %s, scan [who] ", science); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if (buf1[0] == '#') { strcpy(buf1,buf1+1); if (strlen(buf1) == 0) { printf("%s: %s, scan whose engineering?\n", science, title); return 0; } ep = ship_name(buf1); if (ep == NULL) { printf("%s: %s, no such ship as the %s.\n", science, title, buf1); return 0; } for (lp = &head; lp != NULL; lp = lp->fwd) { if (lp == tail) break; if (lp->type == I_UNDEFINED) continue; if (lp->type == I_ENG && lp->data.tp->from == ep) { tp = lp->data.tp; break; } } if (tp == NULL) { printf("%s: %s, the %s has not jettisoned it's engineering.\n", science, title, ep->name); return 0; } item = I_ENG; } else if ((probe_num = atoi(buf1)) > 0) { for (lp = &head; lp != NULL; lp = lp->fwd) { if (lp == tail) break; if (lp->type != I_PROBE) continue; if (lp->data.tp->id == probe_num) { tp = lp->data.tp; break; } } if (tp == NULL) { printf("%s: %s, there is no probe %d", science, title, probe_num); return 0; } item = I_PROBE; } else { ep = ship_name(buf1); if (ep == NULL) { printf("%s: %s, no such ship as the %s.\n", science, title, buf1); return 0; } item = I_SHIP; if (cantsee(ep)) { printf("%s: %s, I am unable to scan the %s.\n", science, title, ep->name); return 0; } } if ((sp != ep) && (is_dead(sp, S_SENSOR))) { printf ("%s: The sensors are damaged, Captain.\n", science); return 0; } if ((sp != ep) && (!syswork(sp, S_SENSOR))) { printf("%s: %s, sensors are temporarily out.\n", science, title); return 0; } if ((sp == ep) && (item == I_SHIP)) { printf ("%s: Captain, don't you mean 'Damage Report'?\n", science); return 0; } if (item == I_SHIP) (void) print_damage(ep); else (void) scan_torpedo(tp); return 1; } print_damage(ep) struct ship *ep; { register int i; register int j; register float k; printf("\n\nDamages to the %s\n", ep->name); for (i=0; i<S_NUMSYSTEMS + 1; i++) { if (is_dead(ep, i)) printf("%s.\n", statmsg[i]); else if (ep->status[i] && i < S_NUMSYSTEMS) printf("%s damaged %d%%\n", sysname[i], ep->status[i]); } printf("Survivors: %d\n", ep->complement); printf("Helm lock: "); if (ep->target == NULL) printf("none.\n"); else printf("%s\n",ep->target); printf("\nPhasers Control"); for (i=0; i<ep->num_phasers; i++) { if (ep->phasers[i].status & P_DAMAGED) printf("\tdamaged"); else if (ep->phasers[i].target == NULL) printf("\tmanual"); else printf("\t%.7s", ep->phasers[i].target->name); } printf("\n\t turned"); for (i=0; i<ep->num_phasers; i++) if (ep->phasers[i].status & P_DAMAGED) printf("\t"); else if (ep->phasers[i].target == NULL) printf("\t%.0f", ep->phasers[i].bearing); else printf("\tLOCKED"); printf("\n\t level"); for (i=0; i<ep->num_phasers; i++) if (ep->phasers[i].status & P_DAMAGED) printf("\t"); else printf("\t%-2d", ep->phasers[i].load); printf("\n"); printf("\nTubes\tcontrol"); for (i=0; i<ep->num_tubes; i++) { if (ep->tubes[i].status & T_DAMAGED) printf("\tdamaged"); else if (ep->tubes[i].target == NULL) printf("\tmanual"); else printf("\t%.7s", ep->tubes[i].target->name); } printf("\n\t turned"); for (i=0; i<ep->num_tubes; i++) if (ep->tubes[i].status & T_DAMAGED) printf("\t"); else if (ep->tubes[i].target == NULL) printf("\t%.0f", ep->tubes[i].bearing); else printf("\tLOCKED"); printf("\n\t level"); for (i=0; i<ep->num_tubes; i++) if (ep->tubes[i].status & T_DAMAGED) printf("\t"); else printf("\t%-2d", ep->tubes[i].load); printf("\n"); printf("\nShields\t levels"); for (i=0; i<SHIELDS; i++) { j = 100 * ep->shields[i].eff * ep->shields[i].drain; printf("\t%-2d", j); } printf("\n\t drains"); for (i=0; i<SHIELDS; i++) { k = ep->shields[i].attemp_drain; printf("\t%-4.2f", k); } printf("\n\nEfficiency: %4.1f\tFuel remaining: %d\n", ep->eff, (int)ep->energy); printf("Regeneration: %4.1f\tFuel capacity: %d\n", ep->regen, (int)ep->pods); return 1; } scan_torpedo(pp) struct torpedo *pp; { char kind[20]; char tgt[20]; printf("\nobject id time prox units target\n"); if (pp->type == TP_PROBE) strcpy(kind, "probe"); else strcpy(kind, "engng"); if (pp->target == NULL) strcpy(tgt, "NONE"); else strcpy(tgt, pp->target->name); printf("%-7s%2d %2.1f %4d %3d %s\n", kind, pp->id, pp->timedelay, pp->prox, pp->fuel, tgt); return 1; } SHAR_EOF chmod +x 'cmds2.c' fi # end of overwriting check # End of shell archive exit 0
okamoto@ucbvax.UUCP (12/10/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # cmds3.c # cmds4.c # damage.c # dist.c # endgame.c # enemycom.c # This archive created: Wed Dec 10 09:01:12 1986 # By: Jeff Okamoto () export PATH; PATH=/bin:$PATH if test -f 'cmds3.c' then echo shar: will not over-write existing file "'cmds3.c'" else cat << \SHAR_EOF > 'cmds3.c' /* * TREK73: cmds3.c * * User Commands * * jettison_engineering, detonate_engineering, phaser_status, tube_status, * survivors, alter_power * * (do_jettison) * */ #include "externs.h" #include <ctype.h> jettison_engineering(sp) struct ship *sp; { printf(" Mr. %s, jettison our engineering section!\n", engineer); if (is_dead(sp, S_ENG)) { printf("%s: But Captain, it's already jettisonned.\n", engineer); return 0; } do_jettison(sp); printf("%s: Aye, %s. Jettisoning engineering.\n", engineer, title); return 1; } do_jettison(sp) struct ship *sp; { register struct list *lp; register struct torpedo *tp; lp = newitem(I_ENG); tp = lp->data.tp = MKNODE(struct torpedo, *, 1); if (tp == (struct torpedo *)NULL) { fprintf(stderr, "do_jettison: malloc failed\n"); exit(2); } tp->target = NULL; tp->speed = sp->warp; tp->newspeed = 0.0; tp->x = sp->x; tp->y = sp->y; tp->course = sp->course; /* This is correct */ tp->fuel = sp->energy; tp->timedelay = 10.; tp->prox = 0; tp->from = sp; tp->id = new_slot(); tp->type = TP_ENGINEERING; sp->energy = sp->pods = 0.; sp->newwarp = (sp->warp < 0.0) ? -0.99 : 0.99; sp->regen = 0.0; sp->status[S_ENG] = 100; /* Set these as destroyed */ sp->status[S_WARP] = 100; sp->max_speed = 1.0; sp->cloaking = C_NONE; sp->t_blind_left = sp->t_blind_right = sp->p_blind_left = sp->p_blind_right = 180; } detonate_engineering(sp) struct ship *sp; { register struct list *lp; register struct torpedo *tp; register int found; char buf[10]; found = 0; printf(" Mr. %s, detonate engineering!\n", engineer); if (!is_dead(sp, S_ENG)) { printf("%s: But %s, it's still attached.\n",engineer,title); printf(" Detonate anyway? "); printf("%s: [yes or no] ", captain); (void) Gets(buf, sizeof(buf)); if ((buf[0] == NULL) || ((buf[0] != 'y') && (buf[0] != 'Y'))) return 0; else do_jettison(sp); } for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type != I_ENG) continue; tp = lp->data.tp; if (tp->from != sp) continue; found++; tp->timedelay = 0.; break; } if (found) printf("%s: Aye, %s.\n",engineer, title); else printf("%s: Ours has already detonated.\n", engineer); return 1; } phaser_status(sp) struct ship *sp; { register int i; puts("Phasers\n"); printf("Control: "); for (i=0; i<sp->num_phasers; i++) { if (sp->phasers[i].status & P_DAMAGED) printf("\tdamaged"); else if (sp->phasers[i].target == NULL) printf("\tmanual"); else printf("\t%.7s", sp->phasers[i].target->name); } printf("\n Turned: "); for (i=0; i<sp->num_phasers; i++) if (sp->phasers[i].status & P_DAMAGED) putchar('\t'); else if (sp->phasers[i].target == NULL) printf("\t%3.0f", sp->phasers[i].bearing); else printf("\tLOCKED"); printf("\n Level: "); for (i=0; i<sp->num_phasers; i++) { if (sp->phasers[i].status & P_DAMAGED) putchar('\t'); else printf("\t%d", sp->phasers[i].load); } printf("\n Drain: "); for (i=0; i<sp->num_phasers; i++) { if (sp->phasers[i].status & P_DAMAGED) putchar('\t'); else printf("\t%d", sp->phasers[i].drain); } printf("\n\nFiring percentage: %d\n",sp->p_percent); printf("\nFiring angles: "); if (is_dead(sp, S_ENG)) { printf("unrestricted.\n"); } else { printf("0 - %d and %d - 360.\n", sp->p_blind_left, sp->p_blind_right); } return 1; } tube_status(sp) struct ship *sp; { register int i; puts("Torpedos\n"); printf("Control: "); for (i=0; i<sp->num_tubes; i++) { if (sp->tubes[i].status & T_DAMAGED) printf("\tdamaged"); else if (sp->tubes[i].target == NULL) printf("\tmanual"); else printf("\t%.7s", sp->tubes[i].target->name); } printf("\n Turned: "); for (i=0; i<sp->num_tubes; i++) if (sp->tubes[i].status & T_DAMAGED) putchar('\t'); else if (sp->tubes[i].target == NULL) printf("\t%.0f", sp->tubes[i].bearing); else printf("\tLOCKED"); printf("\n Level: "); for (i=0; i<sp->num_tubes; i++) { if (sp->tubes[i].status & T_DAMAGED) putchar('\t'); else printf("\t%d", sp->tubes[i].load); } printf("\n\nLaunch speed: %d\n", sp->t_lspeed); printf(" Time delay: %d\n", sp->t_delay); printf(" Prox delay: %d\n", sp->t_prox); printf("\nFiring angles: "); if (is_dead(sp, S_ENG)) { printf("unrestricted.\n"); } else { printf("0 - %d and %d - 360.\n",sp->t_blind_left, sp->t_blind_right); } return 1; } survivors(sp) struct ship *sp; { struct ship *ep; register int i; printf("\nSurvivors reported:\n"); for (i=0; i<=shipnum; i++) { ep = shiplist[i]; if (sp->complement < 0) printf(" %s -- destructed", sp->name); else if (cantsee(ep)) printf(" %s -- ???\n", ep->name); else printf(" %s -- %d\n", ep->name, ep->complement); } sp = sp; /* LINT */ } alter_power() { register int i; float j; char buf1[20]; printf("\n%s: Regeneration rate is %5.2f.\n",engineer, shiplist[0]->regen); for (i=0; i<SHIELDS; i++) { printf("%s: Shield %d drain is [0.0 to 1.0] ", captain, i + 1); (void) Gets(buf1, sizeof(buf1)); j = (float) atof(buf1); if (buf1[strlen(buf1) - 1] == '*') { if ((j < 0.0) || (j > 1.0)) goto badparam; for (; i<SHIELDS; i++) shiplist[0]->shields[i].attemp_drain =j; break; } else if ((j < 0.0) || (j > 1.0)) goto badparam; else shiplist[0]->shields[i].attemp_drain = j; } printf("\n"); for (i=0; i<shiplist[0]->num_phasers; i++) { printf("%s: Phaser %d drain is [%.0f to %.0f] ", captain, i + 1, MIN_PHASER_DRAIN, MAX_PHASER_DRAIN); (void) Gets(buf1, sizeof(buf1)); j = (float) atof(buf1); if (buf1[strlen(buf1) - 1] == '*') { if ((j < MIN_PHASER_DRAIN) || (j > MAX_PHASER_DRAIN)) goto badparam; for (; i<shiplist[0]->num_phasers; i++) shiplist[0]->phasers[i].drain = (int) j; break; } else if ((j < MIN_PHASER_DRAIN) || (j > MAX_PHASER_DRAIN)) goto badparam; else shiplist[0]->phasers[i].drain = (int) j; } return 1; badparam: printf("%s: Bad parameters, %s.\n", engineer, title); return 0; } SHAR_EOF chmod +x 'cmds3.c' fi # end of overwriting check if test -f 'cmds4.c' then echo shar: will not over-write existing file "'cmds4.c'" else cat << \SHAR_EOF > 'cmds4.c' /* * TREK73: cmds4.c * * User Commands * * alterpntparams, play_dead, corbomite_bluff, surrender_ship, * request_surrender, self_destruct, abort_self_destruct * */ #include "externs.h" alterpntparams(sp) struct ship *sp; { int temp; char buf1[30]; printf("\n%s: Reset tubes, %s?\n",nav,title); printf("%s: [yes or no] ",captain); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if ((buf1 != NULL) && (buf1[0] != 'n')) { printf(" Set launch speed to [0-%d] ", MAX_TUBE_SPEED); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if (buf1 != NULL) { temp = atoi(buf1); if ((temp > -1) && (temp < MAX_TUBE_SPEED + 1)) sp->t_lspeed = temp; } printf(" Set time delay to [0-%d] ", (int) MAX_TUBE_TIME); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if (buf1 != NULL) { temp = atoi(buf1); if ((temp > -1) && (temp < (int)(MAX_TUBE_TIME + 1))) sp->t_delay = temp; } printf(" Set proximity delay to [0-%d] ", MAX_TUBE_PROX); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if (buf1 != NULL) { temp = atoi(buf1); if ((temp > -1) && (temp < MAX_TUBE_PROX + 1)) sp->t_prox = temp; } } printf("%s: Reset phasers, %s?\n",nav ,title); printf("%s: [yes or no] ",captain); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) return 0; if ((buf1 != NULL) && (buf1[0] != 'n')) { printf(" Reset firing percentage to [0-100] "); if (Gets(buf1, sizeof(buf1)) == NULL) return 0; if (buf1 != NULL) { temp = atoi(buf1); if ((temp > -1) && (temp < 101)) sp->p_percent = temp; } } return 0; } play_dead(sp) struct ship *sp; { char buf1[30]; int phaser_charge; register int i; printf("%s: %s, drop shields ...\n", captain, nav); if (defenseless) { printf("%s: %s, the %ss are not that stupid.\n", science, title, foerace); return 0; } printf(" Transfer power to [engines or phasers]: "); (void) Gets(buf1, sizeof(buf1)); if (buf1[0] == NULL) { printf("%s: I cannot transfer power there, %s.\n", nav, title); return 0; } phaser_charge = -MAX_PHASER_CHARGE; if (buf1[0] != 'e' && buf1[0] != 'E') { phaser_charge = MAX_PHASER_CHARGE; if (buf1[0] != 'p' && buf1[0] != 'P') { printf("%s: I cannot transfer power there, %s.\n", nav, title); return 0; } } for (i=0;i<SHIELDS;i++) sp->shields[i].attemp_drain = 0.0; for (i=0;i<sp->num_phasers;i++) sp->phasers[i].drain = phaser_charge; defenseless = 1; return 0; } corbomite_bluff(sp) struct ship *sp; { if (randm(2) == 1) { printf("%s: Open a hailing frequency, ship-to-ship.\n", captain); printf("%s: Hailing frequency open, %s.\n", com, title); printf("%s: This is the Captain of the %s. Our respect for\n", captain, sp->name); puts(" other life forms requires that we give you this warning--"); puts(" one critical item of information which has never been"); puts(" incorporated into the memory banks of any Earth ship."); puts(" Since the early years of space exploration, Earth vessels"); puts(" have had incorporated into them a substance know as corbomite."); if (!corbomite) { puts(" It is a material and a device which prevents attack on"); puts(" us. If any destructive energy touchs our vessel, a re-"); puts(" verse reaction of equal strength is created, destroying"); puts(" the attacker. It may interest you to know that, since"); puts(" the initial use of corbomite for more than two of our"); puts(" centuries ago, no attacking vessel has survived the attempt."); puts(" Death has little meaning to us. If it has none to you,"); puts(" then attack us now. We grow annoyed with your foolishness."); } } else { printf("%s: Open a special channel to Starfleet Command.\n", captain); printf("%s: Aye, %s.\n", com, title); printf("%s: Use Code 2.\n", captain); printf("%s: but, %s, according to our last Starfleet\n", com, title); printf(" Bulletin, the %ss have broken code 2.\n", foerace); printf("%s: That's an order, Lieutenant. Code 2!\n", captain); printf("%s: Yes, Captain. Code 2.\n", com); printf("%s: Message from %s to Starfleet Command, this sector.\n", captain, sp->name); printf(" have inadvertantly encroached upon %s neutral zone,\n", foerace); printf(" surrounded and under heavy %s attack. Escape\n", foerace); puts(" impossible. Shields failing. Will implement destruct"); puts(" order using corbomite device recently installed."); if (!corbomite) { printf(" This will result in the destruction of the %s and\n", sp->name); puts(" all matter within a 200 megameter diameter and"); puts(" establish corresponding dead zone, all Federation"); puts(" vessels will aviod this area for the next four solar"); printf(" years. Explosion will take place in one minute. %s,\n", captain); printf(" commanding %s, out.\n",sp->name); } } if (!corbomite) { printf(" Mr. %s. Stand by.\n", helmsman); printf("%s: Standing by.\n", helmsman); corbomite = 1; } else { printf("\n%s: I don't believe that they will fall for that maneuver\n", science); printf(" again, %s.\n", title); } return 0; } surrender_ship(sp) struct ship *sp; { printf("%s: %s, open a channel to the %ss.\n", captain, com, foerace); printf("%s: Aye, %s.\n", com, title); printf("%s: This is Captain %s of the U.S.S. %s. Will\n", captain, captain, sp->name); puts(" you accept my unconditional surrender?"); if (global & F_SURRENDER) { printf("%s: %s, we have already surrendered.\n", science, title); return 0; } if (surrender) { printf("%s: The %ss have already refused.\n",science, foerace); } else { if (foerace == "Romulan") { printf("%s: The %ss have not been know to have taken\n", science, foerace); puts(" prisoners."); } surrender = 1; } return 0; } request_surrender(sp) struct ship *sp; { printf("%s: %s, open a hailing frequency to the %ss.\n", com, captain,foerace); printf("%s: Aye, %s.\n", com, title); printf("%s: This is Captain %s of the U. S. S. %s. I give you\n", captain, captain, sp->name); puts(" one last chance to surrender before we resume our attack."); if (global & E_SURRENDER) { printf("%s: %s, we are already complying with your previous request!\n", foename, captain); return 0; } if (surrenderp) { printf("%s: %s, our offer has already been refused.\n", science, title); } else { surrenderp = 1; } return 0; } self_destruct(sp) struct ship *sp; { printf("%s: Lieutenant %s, tie in the bridge to the master\n",captain, com); printf(" computer.\n"); if (is_dead(sp, S_COMP)) { printf("%s: Our computer is down.\n", science); return 0; } if (!syswork(sp, S_COMP)) { printf("%s: That program has been lost. Restoring from backup.", science); return 0; } printf("%s: Aye, %s.\n",com, title); printf("%s: Computer. Destruct sequence. Are you ready to copy?\n",captain); puts("Computer: Working."); printf("%s: Computer, this is Captain %s of the U.S.S. %s.\n", captain, captain, sp->name); puts(" Destruct sequence one, code 1-1A."); puts("Computer: Voice and code verified and correct."); puts(" Sequence one complete."); printf("%s: This is Commander %s, Science Officer. Destruct\n", science, science); puts(" sequence two, code 1-1A-2B."); puts("Computer: Voice and code verified and correct. Sequence"); puts(" two complete."); printf("%s: This is Lieutenant Commander %s, Chief Engineering\n", engineer, engineer); printf(" Officer of the U. S. S. %s. Destruct sequence\n",sp->name); puts(" number three, code 1B-2B-3."); puts("Computer: Voice and code verified and correct."); puts(" Destruct sequence complete and engaged. Awaiting final"); puts(" code for twenty second countdown."); printf("%s: Computer, this is Captain %s of the U. S. S. %s.\n", captain, captain, sp->name); puts(" begin countdown, code 0-0-0, destruct 0."); puts("Computer: 20 seconds to self-detruct."); sp->delay = 20.; return 0; } abort_self_destruct(sp) struct ship *sp; { printf("%s: Computer, this is Captain %s of the U.S.S. %s.\n", captain, captain, sp->name); puts(" Code 1-2-3 continuity abort destruct order, repeat:"); puts(" Code 1-2-3 continuity abort destruct order!"); if (is_dead(sp, S_COMP)) { printf("%s: Our computer is down.\n", science); return 0; } if (!syswork(sp, S_COMP)) { printf("%s: Temporary memory loss. Unable to find program.\n", science); return 0; } if (sp->delay > 1000.) { puts("Computer: Self-destruct sequence has not been"); puts(" initiated."); return 0; } printf("Computer: Self-destruct order ... "); (void) fflush(stdout); sleep(4); if (sp->delay > 4.) { puts("aborted. Destruct order aborted."); sp->delay = 10000.; return 0; } else { puts("cannot be aborted."); return 0; } } SHAR_EOF chmod +x 'cmds4.c' fi # end of overwriting check if test -f 'damage.c' then echo shar: will not over-write existing file "'damage.c'" else cat << \SHAR_EOF > 'damage.c' /* * TREK73: damage.c * * Damage routines * * damage, check_locks * */ #include "externs.h" damage(hit, ep, s, dam, flag) int hit; struct ship *ep; int s; struct damage *dam; int flag; { register int i; register int j; register int k; float f1; /* Damage factor except for shields */ float f2; /* Shield damage factor */ int percent; struct ship *fed; fed = shiplist[0]; printf("hit %d on %s's shield %d\n", hit, ep->name, s); s--; /* * Note that if the shield is at 100% efficiency, no * damage at all will be taken (except to the shield itself) */ f1 = hit * (1.0 - ep->shields[s].eff * ep->shields[s].drain); if (f1 < 0) return 0; /* Calculate shield damage */ if (flag == D_ANTIMATTER) f2 = ep->tu_damage * 100; else if (flag == D_PHASER) f2 = ep->ph_damage * 100; if (s == 0) f2 *= SHIELD1; ep->shields[s].eff -= max(hit/f2, 0); if (ep->shields[s].eff < 0.0) ep->shields[s].eff = 0.0; /* Calculate loss of fuel, regeneration, etc. */ ep->eff += f1/dam->eff; ep->pods -= f1/dam->fuel; ep->energy -= f1/dam->fuel; ep->regen -= f1/dam->regen; if (ep->regen < 0.0) ep->regen = 0.0; if (ep->pods < 0.0) ep->pods = 0.0; if (ep->energy < 0.0) ep->energy = 0.0; if (ep->pods < ep->energy) ep->energy = ep->pods; /* Kill some crew */ if (ep->complement > 0) { j = f1 * dam->crew; if (j > 0) ep->complement -= randm(j); if (ep->complement < 0) ep->complement = 0; } /* Damage some weapons */ j = f1/dam->weapon; for(i=0; i<j; i++) { k = randm(ep->num_phasers + ep->num_tubes) - 1; if (k < ep->num_phasers) { if (ep->phasers[k].status & P_DAMAGED) continue; ep->phasers[k].status |= P_DAMAGED; ep->phasers[k].target = NULL; /* * Reroute the energy * back to the engines */ ep->energy = min(ep->pods, ep->energy + ep->phasers[k].load); ep->phasers[k].load = 0; ep->phasers[k].drain = 0; k++; if (ep == fed) printf(" phaser %d damaged\n", k); } else { k -= ep->num_phasers; if (ep->tubes[k].status & T_DAMAGED) continue; /* * If tubes are damaged, reroute the pods * back to the engines */ ep->pods += ep->tubes[k].load; ep->energy += ep->tubes[k].load; ep->tubes[k].load = 0; ep->tubes[k].status |= T_DAMAGED; ep->tubes[k].target = NULL; k++; if (ep == fed) printf(" tube %d damaged\n", k); } } /* Damage the different systems */ for (i=0; i<S_NUMSYSTEMS; i++) { if (is_dead(ep, i)) /* Don't damage a dead system */ continue; percent = 0; if (randm(dam->stats[i].roll) < f1) { /* A better method should be found */ percent = (int) randm((int) f1); /* The expected value for the percent damage to each system is roughly equal to: f1 * f1 / (2 * dam->stats[i].roll) Only these damages are proportional to hit squared. All others are linearly proportional. This includes shield damage, ship's fuel supply, consumption and regeneration rates, casualties, and weapons. (When weapons are damaged, they are 100% damaged - the number of weapons damaged is proportional to hit.) I think the old way decided whether or not to completely damage a system based on the comparison "randm(dam->stats[i].roll) < f1". This is almost like the weapons are still handled. Another possibility is to always damage each system by: 100 * randm((int)f1) / dam->stats[i].roll percent. This adds some randomness and makes the approx. expected value of the damage to each system: 100 * f1 / (2 * dam->stats[i].roll) percent. Perhaps this isn't such a good idea after all; this is 100/f1 times the current expected value, often > 2. And it is actually somewhat less random since each system gets damaged each time. I had thought that the damage should be directly proportional to f1, not to its square. But perhaps it makes sense that a hit twice as big has an expected value of damage four times as big as that from a smaller hit. The actual damage any given time is still proportional to the hit, but the probability that any damage will be done at all is also directly proportional to the hit. This is a pretty good system after all. [RJN] */ ep->status[i] += percent; if (ep->status[i] > 100) ep->status[i] = 100; if (ep == fed) { if (is_dead(ep, i)) printf(" %s\n", dam->stats[i].mesg); else printf(" %s damaged.\n", sysname[i]); } /* Now check for the effects of the damage */ /* Do the effects of a totally destroyed system */ if (is_dead(ep, i)) { switch(i) { case S_SENSOR: case S_PROBE: /* No bookkeeping needed */ break; case S_WARP: /* Reduce max speed */ ep->max_speed = 1.0; break; case S_COMP: check_locks(ep, 100, fed); break; default: printf("How'd we get here?\n"); } } else { /* Now check partially damaged systems */ switch(i) { case S_SENSOR: case S_PROBE: /* No bookkeeping needed */ break; case S_WARP: f2 = percent * ep->orig_max / 100; ep->max_speed -= f2; if (ep->max_speed < 1.0) { ep->max_speed = 1.0; ep->status[S_WARP] = 100; } break; case S_COMP: check_locks(ep, percent, fed); break; default: printf("Oh, oh....\n"); } } } } #ifdef HISTORICAL /* * Historically, if more than 43 points of damage were done * to the ship, it would destroy itself. This led to much * abuse of probes and thus has been enclosed inside of * an #ifdef */ if (f1 > 43) ep->delay = 1.; #endif return 0; } check_locks(ep, percent, fed) struct ship *ep; int percent; struct ship *fed; { register int i, j = 0; for (i=0; i<ep->num_phasers; i++) { if ((ep->phasers[i].target != NULL) && (randm(100) <= percent)) { ep->phasers[i].target = NULL; if (ep != fed) continue; if (!j) printf("Computer: Phaser(s) %d", i+1); else printf(", %d", i+1); j++; } } if (j > 1) puts(" have lost their target locks."); else if (j == 1) puts(" has lost its target lock."); j = 0; for (i=0; i<ep->num_tubes; i++) { if ((ep->tubes[i].target != NULL) && (randm(100) <= percent)) { ep->tubes[i].target = NULL; if (ep != fed) continue; if (!j) printf("Computer: Tube(s) %d", i+1); else printf(", %d", i+1); j++; } } if (j > 1) puts(" have lost their target locks."); else if (j == 1) puts(" has lost its target lock."); if ((ep->target != NULL) && (randm(100) <= percent)) { ep->target = NULL; ep->relbear = 0; if (ep == fed) printf("Computer: %s has lost helm lock\n", shipname); } } SHAR_EOF chmod +x 'damage.c' fi # end of overwriting check if test -f 'dist.c' then echo shar: will not over-write existing file "'dist.c'" else cat << \SHAR_EOF > 'dist.c' /* * TREK73: dist.c * * Power distribution routines * * distribute * */ #include "externs.h" #include <math.h> distribute(sp) struct ship *sp; { register int i; register float fuel; register int load; register int effload; register int drain; register int loop; float shield; struct ship *fed; fed = shiplist[0]; /* * Granularity of 1 second as far as this loop is concerned */ for (loop = 0; loop < (int)timeperturn; loop++) { fuel = sp->energy + sp->regen; /* Slightly unrealistic */ /* * Calculate negative phaser drains */ for (i=0; i<sp->num_phasers; i++) { load = sp->phasers[i].load; drain = sp->phasers[i].drain; if ((sp->phasers[i].status & P_DAMAGED) || (drain >= 0) || (load <= 0)) continue; /* * Drain the lesser of either the current load if the * load is less than the drain, or the drain value */ effload = max(load + drain, 0); fuel += load - effload; sp->phasers[i].load = effload; } /* * Calculate shield drains */ shield = 0.0; for (i=0; i<SHIELDS; i++) shield += sp->shields[i].attemp_drain; drain = ceil((double) shield); /* * If all attempted drains are zero, or we have no * fuel, our shields are down! */ if ((shield * fuel == 0) && !shutup[SHIELDSF] && sp == shiplist[0]) { printf("%s: %s, our shields are down!\n",engineer, title); shutup[SHIELDSF]++; } /* * If there's not enough fuel to sustain the drains, then * ration it out in proportion to the attempted drains and * say that shields are fluctuating. */ if (drain <= fuel) { fuel -= drain; for (i=0; i<SHIELDS; i++) sp->shields[i].drain = sp->shields[i].attemp_drain; } else { if (!shutup[SHIELDSF] && sp == shiplist[0]) { printf("%s: %s, our shields are fluctuating!\n", engineer, title); shutup[SHIELDSF]++; } for (i=0; i<SHIELDS; i++) sp->shields[i].drain = sp->shields[i].attemp_drain * fuel / drain; fuel = 0.; } /* * Calculate cloaking device drains. If there is * in sufficient energy to run the device, then * it is turned off completely */ if (cantsee(sp)) { if (fuel < sp->cloak_energy) { if (sp == shiplist[0]) { sp->cloaking = C_OFF; printf("%s: %s, there's not enough energy to", engineer, title); puts(" keep our cloaking device activated."); } else (void) e_cloak_off(sp, fed); } else fuel -= sp->cloak_energy; } /* * Calculate positive phaser drains */ for (i=0; i<sp->num_phasers && fuel > 0; i++) { if (fuel <=0.) break; load = sp->phasers[i].load; drain = sp->phasers[i].drain; if ((sp->phasers[i].status & P_DAMAGED) || load >= MAX_PHASER_CHARGE || drain <= 0) continue; /* * Load phasers either enough to top them off, or * the full drain */ effload = min(MAX_PHASER_CHARGE, load + min(drain, fuel)); fuel -= effload - load; sp->phasers[i].load = effload; } /* * Now balance the level of energy with the numer of pods */ sp->energy = min(fuel, sp->pods); } } SHAR_EOF chmod +x 'dist.c' fi # end of overwriting check if test -f 'endgame.c' then echo shar: will not over-write existing file "'endgame.c'" else cat << \SHAR_EOF > 'endgame.c' /* * TREK73: endgame.c * * prints end-of-game messages and warnings * * leftovers, final, warn * */ #ifdef BSD #include <sys/file.h> #endif #include "externs.h" leftovers() { register struct list *lp; for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type == 0) continue; if (lp->type != I_SHIP) return 1; } return 0; } final(mesg) int mesg; { register int i; register int j; struct ship *sp; struct ship *ep; char buf[80]; sp = shiplist[0]; /* If we're getting that message again, ignore it. */ if ((mesg == 2) && (reengaged)) return; switch (mesg) { case FIN_F_LOSE: starfleet(); printf("We have recieved confirmation that the U.S.S. %s,\n", sp->name); printf(" captained by %s, was destroyed by %s%s\n", captain, shipnum==1 ?"a ":"", foerace); printf(" %s%s. May future Federation officers\n", foestype, plural(shipnum)); printf(" perform better in their duties.\n\n"); break; case FIN_E_LOSE: starfleet(); printf("We commend Captain %s and the crew of the %s on their\n", captain, shipname); printf(" fine performance against the %ss. They are\n", foerace); puts(" an inspiration to all Starfleet personnel.\n"); break; case FIN_TACTICAL: /* * Give him a chance to re-engage if he wants to. If he does, * he has to get within a range of 3500 before he can again * try to dis-engage */ if (!reengaged) { printf("%s: %s, we are in a position to either disengage from the\n", science, title); printf(" %ss, or re-engage them in combat.\n", foerace); printf(" Do you wish to re-engage?\n"); printf("%s: [y or n] ", captain); gets(buf); if ((*buf == NULL) || (*buf == 'y') || (*buf == 'Y')) { reengaged = 1; return; } } starfleet(); printf("Captain %s of the starship %s has\n",captain,sp->name); printf(" out-maneuvered %s aggressors. We commend\n",foerace); printf(" his tactical ability.\n"); break; case FIN_F_SURRENDER: starfleet(); printf("Captain %s has surrendered the U.S.S. %s \n", captain, sp->name); printf(" to the %ss. May Captain Donsell be remembered.\n", foerace); break; case FIN_E_SURRENDER: starfleet(); printf("We have recieved word from the %s that the\n",sp->name); printf(" %ss have surrendered.\n",foerace); break; case FIN_COMPLETE: starfleet(); puts("One of our scout vessels has encountered the wreckage of"); printf(" the %s and %d other %s vessel%s.\n", sp->name, shipnum, foerace, plural(shipnum)); break; case QUIT: starfleet(); printf("We have received word that Captain %s of the\n", captain); printf(" starship %s has sold out to the %ss.\n",sp->name, foerace); printf(" May he soon be court-martialled.\n"); break; default: printf("How did we get here? final(%d)\n", mesg); break; } puts("\n\n"); j = 0; for (i=0; i<=shipnum; i++) { ep = shiplist[i]; if (is_dead(ep, S_DEAD)) continue; if (!j) puts("Survivors Reported:\n"); j++; } if (j) { for (i=0; i<=shipnum; i++) { ep = shiplist[i]; if ((is_dead(ep, S_DEAD)) || (ep->complement <= 0)) printf(" %s -- destroyed\n", ep->name); else printf(" %s -- %d\n", ep->name, ep->complement); } } else puts("*** No survivors reported ***\n"); exit (1); } warn(mesg) int mesg; { static int beenhere[5] = {0, 0, 0, 0, 0}; struct ship *sp; if ((reengaged) && (mesg == 2)) { return 0; } if (beenhere[mesg]) return 0; sp = shiplist[0]; switch (mesg) { case FIN_F_LOSE: printf("Message to the Federation: This is Commander\n"); printf(" %s of the %s %s. We have defeated\n", foename, foerace, empire); printf(" the %s and are departing the quadrant.\n", sp->name); break; case FIN_E_LOSE: printf("%s: All %s vessels have been either\n", science, foerace); printf(" destroyed or crippled. We still, however, have\n"); printf(" antimatter devices to avoid.\n"); break; case FIN_TACTICAL: printf("%s: The %ss are falling behind and seem to\n", helmsman, foerace); printf(" be breaking off their attack.\n"); break; case FIN_F_SURRENDER: printf("%s: I'm informing Starfleet Command of our \n", com); printf(" disposition.\n"); break; case FIN_E_SURRENDER: printf("%s: Although the %ss have surrendered,\n", science, foerace); printf(" there are still antimatter devices floating\n"); printf(" around us.\n"); break; default: printf("How did we get here? final(%d)\n", mesg); break; } beenhere[mesg]++; return 0; } starfleet() { puts("\n\nStarfleet Command: \n"); (void) sleep(3); putchar('\n'); } SHAR_EOF chmod +x 'endgame.c' fi # end of overwriting check if test -f 'enemycom.c' then echo shar: will not over-write existing file "'enemycom.c'" else cat << \SHAR_EOF > 'enemycom.c' /* * TREK73: enemycom.c * * Enemy strategy sub-routines * * e_attack, e_checkarms, e_checkprobe, e_cloak_off, e_cloak_on, * e_closetorps, e_destruct, e_evade, e_jettison, e_launchprobe, * e_loadtubes, e_lockphasers, e_locktubes, e_phasers, e_pursue, * e_runaway, e_torpedo * */ #include "externs.h" /* * This routine turns the ship at speed towards its target */ int e_attack(sp, fed) struct ship *sp; struct ship *fed; { float speed; float tmpf; tmpf = fabs(fed->warp); if (fabs(sp->warp) >= tmpf + 2.0 || (is_dead(sp, S_WARP))) return 0; if ((speed = tmpf + randm(2) + 2.0) > sp->max_speed) speed = sp->max_speed; (void) e_pursue(sp, fed, speed); if (cansee(sp) && syswork(fed, S_SENSOR)) printf("%s: %s attacking.\n", helmsman, sp->name); return 1; } /* * Returns the number of currently loaded, undamaged weapons */ int e_checkarms(sp) struct ship *sp; { register int i; register int arms; arms = 0; for (i=0; i<sp->num_phasers; i++) if (!(sp->phasers[i].status & P_DAMAGED) && (sp->phasers[i].load >= 0)) arms++; for (i=0; i<sp->num_tubes; i++) if (!(sp->tubes[i].status & T_DAMAGED) && (sp->tubes[i].load >= 0)) arms++; #ifdef TRACE if (trace) printf("*** Checkarms: Returning %d\n", arms); #endif return arms; } /* * returns 1 if evasive action being taken (to avoid probe) */ int e_checkprobe(sp) struct ship *sp; { register struct list *lp; register int range; register struct torpedo *tp; /* * If we are cloaked, do not bother with this. * Since probes cannot detect us when cloaked. */ if (cantsee(sp)) return 0; for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type != I_PROBE) continue; tp = lp->data.tp; range = rangefind(sp->x, tp->x, sp->y, tp->y); #ifdef TRACE if (trace) printf("*** Checkprobe: Range = %d\n", range); #endif if (range < 2000) { (void) e_evade(sp, tp->x, tp->y, I_PROBE); return 1; } } return 0; } /* * Returns 1 if cloaking device was turned off */ int e_cloak_off(sp, fed) struct ship *sp; struct ship *fed; { if (sp->cloaking != C_ON) return 0; sp->cloaking = C_OFF; sp->cloak_delay = 4; if (syswork(sp, S_SENSOR)) { printf("%s: The %s has reappeared on our sensors %d\n", science, sp->name, rangefind(sp->x, sp->position.x, sp->y, sp->position.y)); puts(" megameters from its projected position."); } fed = fed; /* LINT */ return 1; } /* * Returns 1 if cloaking device was turned on */ int e_cloak_on(sp, fed) struct ship *sp; struct ship *fed; { if ((sp->cloak_delay > 0) || (sp->cloaking != C_OFF)) return 0; sp->cloaking = C_ON; sp->position.x = sp->x; sp->position.y = sp->y; sp->position.warp = sp->warp; sp->position.course = sp->course; if (syswork(fed, S_SENSOR)) printf("%s: The %s has disappeared from our sensors.\n", science, sp->name); fed = fed; /* LINT */ return 1; } /* * Returns 1 if firing phasers at or evading nearby torpedoes */ int e_closetorps(sp, fed) struct ship *sp; struct ship *fed; { register struct list *lp; register int range; register struct torpedo *tp; struct torpedo *bad; /* * If we are cloaked, forget about this. * Since prox fuses won't affect us under cloak */ if (cantsee(sp)) return 0; bad = NULL; for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type != I_TORPEDO) continue; tp = lp->data.tp; if (tp->from != fed) continue; range = rangefind(sp->x, tp->x, sp->y, tp->y); #ifdef TRACE if (trace) printf("*** Checktorp: Range = %d\n", range); #endif if (range < 1200) { bad = tp; /* * fire phasers - hope they're pointing in * the right direction! */ if (e_phasers(sp, (struct ship *) NULL)) return 1; } } /* * we can't get a phaser shot off. * try and evade (although hopeless) */ if (bad != NULL) { #ifdef TRACE if (trace) printf("*** Checktorp: Cannot fire phasers! Evade!\n"); #endif (void) e_evade(sp, tp->x, tp->y, I_TORPEDO); return 1; } return 0; } /* * goodbye, cruel world (Returns 1 if self-destruct was initiated) */ int e_destruct(sp, fed) struct ship *sp, *fed; { if (sp->delay < 5.0) return 0; sp->delay = 5.0; (void) e_cloak_off(sp, fed); sp->cloaking = C_NONE; if (syswork(fed, S_SENSOR)) { printf("%s: The %s is overloading what remains of it's\n", science, sp->name); puts(" antimatter pods -- obviously a suicidal gesture."); puts(" Estimate detonation in five seconds."); } return 1; } /* * Advance to the rear! (Always returns 1) */ int e_evade(sp, x, y, type) struct ship *sp; int x; int y; int type; /* Currently unused */ { register float newcourse; float bear; bear = bearing(sp->x, x, sp->y, y); if (cansee(sp) && syswork(shiplist[0], S_SENSOR)) printf("%s taking evasive action!\n", sp->name); switch (randm(3)) { case 1: newcourse = rectify(bear - 90.0); break; case 2: newcourse = rectify(bear + 90.0); break; case 3: newcourse = rectify(bear + 180.0); break; default: printf("error in evade()\n"); break; } sp->target = NULL; sp->newcourse = newcourse; sp->newwarp = 2 + randm((int)(sp->max_speed - 3)); if (is_dead(sp, S_WARP)) sp->newwarp = 1.0; #ifdef TRACE if (trace) { printf("*** Evade: Newcourse = %3.0f\n", newcourse); printf("*** Evade: Newwarp = %.2f\n", sp->newwarp); } #endif type = type; /* LINT */ return 1; } /* * Returns 1 if engineering was jettisoned */ int e_jettison(sp, fed) struct ship *sp, *fed; { register struct list *lp; register struct torpedo *tp; if (is_dead(sp, S_ENG)) return 0; (void) e_cloak_off(sp, fed); if (syswork(shiplist[0], S_SENSOR)) { printf("%s: Sensors indicate debris being left by\n", science); printf(" the %s. Insufficient mass . . .\n", sp->name); } lp = newitem(I_ENG); tp = lp->data.tp = MKNODE(struct torpedo, *, 1); if (tp == (struct torpedo *)NULL) { fprintf(stderr, "e_jettison: malloc failed\n"); exit(2); } tp->id = new_slot(); /* * ship slows to warp 1.0 when jettisonning engineering */ tp->newspeed = 0.0; tp->speed = sp->warp; tp->target = NULL; tp->course = sp->course; tp->x = sp->x; tp->y = sp->y; tp->prox = 0; tp->timedelay = 10.; tp->fuel = sp->energy; tp->type = TP_ENGINEERING; sp->energy = sp->pods = 0; sp->regen = 0.0; tp->from = sp; if (sp->newwarp < -1.0) sp->newwarp = -0.99; if (sp->newwarp > 1.0) sp->newwarp = 0.99; sp->max_speed = 1.0; sp->status[S_ENG] = 100; /* List as destroyed */ sp->status[S_WARP] = 100; sp->cloaking = C_NONE; sp->t_blind_left = sp->t_blind_right = sp->p_blind_left = sp->p_blind_right = 180; return 1; } /* * Returns 1 if a probe was launched */ int e_launchprobe(sp, fed) struct ship *sp; struct ship *fed; { register int i; register struct list *lp; register struct torpedo *tp; if (!syswork(sp, S_PROBE) || sp->energy <= 10 || cantsee(sp)) return 0; /* * fed ship has to be going slow before we'll launch * a probe at it. */ if (fabs(fed->warp) > 1.0) return 0; lp = newitem(I_PROBE); tp = lp->data.tp = MKNODE(struct torpedo, *, 1); if (tp == (struct torpedo *)NULL) { fprintf(stderr, "e_launchprobe: malloc failed\n"); exit(2); } tp->from = sp; tp->speed = sp->warp; tp->newspeed = 3.0; tp->target = fed; tp->course = bearing(sp->x, fed->x, sp->y, fed->y); tp->x = sp->x; tp->y = sp->y; tp->prox = 200 + randm(200); tp->timedelay = 15.; tp->id = new_slot(); if ((i = randm(15) + 10) > sp->energy) i = sp->energy; tp->fuel = i; tp->type = TP_PROBE; sp->energy -= i; sp->pods -= i; printf("%s launching probe #%d\n", sp->name, tp->id); return 1; } /* * Returns the number of tubes that were loaded */ int e_loadtubes(sp) struct ship *sp; { register int i; register int j; register int loaded; register int below; below = 10; loaded = 0; for (i=0; i<sp->num_tubes; i++) { if (sp->energy <= below) break; if (sp->tubes[i].status & T_DAMAGED) continue; j = min(sp->energy, 10 - sp->tubes[i].load); if (j == 0) continue; sp->energy -= j; sp->pods -= j; sp->tubes[i].load += j; loaded++; } #ifdef TRACE if (trace) printf("*** Load tubes: Loaded %d tubes\n", loaded); #endif return loaded; } /* * Returns the number of phasers that were locked */ int e_lockphasers(sp, fed) struct ship *sp; struct ship *fed; { register int i; register int banks; banks = 0; for (i=0; i<sp->num_phasers; i++) { if (sp->phasers[i].status & P_DAMAGED) continue; if (sp->phasers[i].target != NULL) continue; sp->phasers[i].target = fed; banks++; } #ifdef TRACE if (trace) printf("*** Lock phasers: Locked %d phasers\n", banks); #endif return banks; } /* * Returns number of tubes locked */ int e_locktubes(sp, fed) struct ship *sp; struct ship *fed; { register int i; register int tubes; tubes = 0; for (i=0; i<sp->num_tubes; i++) { if (sp->tubes[i].status & T_DAMAGED) continue; if (sp->tubes[i].target != NULL) continue; sp->tubes[i].target = fed; tubes++; } #ifdef TRACE if (trace) printf("*** Lock tubes: Locked %d tubes\n", tubes); #endif return tubes; } /* * returns the number of banks we're going to fire * it also sets them up. */ int e_phasers(sp, fed) struct ship *sp; struct ship *fed; { register int i; register int banks; register int hit; register int howmany; float bear; banks = 0; howmany = randm(sp->num_phasers / 2) + sp->num_phasers / 2; sp->p_spread = 10 + randm(12); for (i=0; i<sp->num_phasers; i++) { if ((sp->phasers[i].status & P_DAMAGED) || (sp->phasers[i].load == 0)) continue; if (fed != NULL) { if (sp->phasers[i].target == NULL) continue; bear = bearing(sp->x, fed->x, sp->y, fed->y); hit = phaser_hit(sp, fed->x, fed->y, &sp->phasers[i], bear); if (hit <= 0) continue; } banks++; sp->phasers[i].status |= P_FIRING; if (banks >= howmany) break; } return banks; } /* * This routine will turn the ship, slowing down if necessary to facilitate * the turn. (Always returns 1) */ int e_pursue(sp, fed, speed) struct ship *sp; struct ship *fed; float speed; { float bear; float coursediff; bear = bearing(sp->x, fed->x, sp->y, fed->y); /* * do a quick turn if our speed is > max_warp - 2 and * (thus) we are never going to bear on the fed ship * speed = max_warp / 2 is a magic cookie. Feel free to change. */ coursediff = rectify(sp->course - bear); if (coursediff > 180.0) coursediff -= 360.0; if (speed >= sp->max_speed - 2 && fabs(coursediff) > 10) speed = (int)(sp->max_speed / 2); sp->target = fed; sp->newcourse = bear; sp->newwarp = speed; if (speed > 1 && is_dead(sp, S_WARP)) sp->newwarp = 0.99; #ifdef TRACE if (trace) { printf("*** Pursue: Newcourse = %.2f\n", sp->newcourse); printf("*** Pursue: Newwarp = %.2f\n", sp->newwarp); } #endif return 1; } /* * This routine has the enemy ship turn its strongest shield towards * the enemy and then accelerate to 2/3 maximum speed. (Always returns 1) */ int e_runaway(sp, fed) struct ship *sp; struct ship *fed; { register double bear; register int strong; register double strength; register double temp; register int sign; register float course; register int i; bear = bearing(sp->x, fed->x, sp->y, fed->y); /* * Find the strongest shield */ strong = 0; strength = 0.; for (i=0; i< SHIELDS; i++) { temp = sp->shields[i].eff * sp->shields[i].drain * (i == 0 ? SHIELD1 : 1.); if (temp > strength) { strong = i; strength = temp; } } switch (strong) { case 0: course = bear; sign = -1; break; case 1: course = rectify(bear - 90); sign = 1; break; case 2: course = rectify(bear + 180); sign = 1; break; case 3: course = rectify(bear + 90); sign = 1; break; } sp->target = NULL; sp->newcourse = course; sp->newwarp = 2 / 3 * sp->max_speed * sign; if (sp->newwarp > 1.0 && is_dead(sp, S_WARP)) sp->newwarp = 0.99; if (cansee(sp) && syswork(fed, S_SENSOR)) printf("%s: The %s is retreating.\n", helmsman, sp->name); #ifdef TRACE if (trace) { printf("*** Runaway: Newcourse = %.2f\n", sp->newcourse); printf("*** Runaway: Newwarp = %.2f\n", sp->newwarp); } #endif return 1; } /* * Returns the number of tubes we're going to fire * Also sets them up to fire */ int e_torpedo(sp) struct ship *sp; { register int i; register int tubes; register int howmany; register struct ship *sp1; register int range; /* * don't shoot if someone might be in the way * (i.e. proximity fuse will go off right as the * torps leave the tubes!) */ for (i=1; i <= shipnum; i++) { sp1 = shiplist[i]; /* This must check for dead ships too! */ if (sp1 == sp) continue; range = rangefind(sp->x, sp1->x, sp->y, sp1->y); if (range <= 400) return 0; } tubes = 0; /* This is not and should not be dependent on the number of tubes one has */ howmany = randm(2) + 1; for (i=0; i<sp->num_tubes; i++) { if ((sp->tubes[i].status & T_DAMAGED) || (sp->tubes[i].load == 0)) continue; if (sp->tubes[i].target == NULL) continue; tubes++; sp->tubes[i].status |= T_FIRING; if (tubes >= howmany) break; } return tubes; } SHAR_EOF chmod +x 'enemycom.c' fi # end of overwriting check # End of shell archive exit 0
okamoto@ucbvax.UUCP (12/10/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # firing.c # globals.c # init.c # main.c # misc.c # mission.c # bpv.c # shipyard.c # This archive created: Wed Dec 10 09:01:21 1986 # By: Jeff Okamoto () export PATH; PATH=/bin:$PATH if test -f 'firing.c' then echo shar: will not over-write existing file "'firing.c'" else cat << \SHAR_EOF > 'firing.c' /* * TREK73: firing.c * * Take care of firing phasers and torpedos for both enemy * and fed ships. * * phaser_firing, torpedo_firing, ship_detonate, torp_detonate * */ #include "externs.h" phaser_firing(sp) struct ship *sp; { register int i; register float j; int hit; struct ship *ep; struct torpedo *tp; int s; int x, y; struct ship *target; struct list *lp; float bear; struct ship *fed; fed = shiplist[0]; for (i=0; i<sp->num_phasers; i++) { if (sp->phasers[i].status & P_FIRING) break; } if (i == sp->num_phasers) return 0; sp->phasers[i].status &= ~P_FIRING; target = sp->phasers[i].target; /* * Put in j the relative bearing of the phasers relative to the ship * Put in bear the absolute direction the phasers are pointing */ bear = sp->phasers[i].bearing + sp->course; j = rectify(sp->phasers[i].bearing); if (betw(j, sp->p_blind_left, sp->p_blind_right) && !is_dead(sp, S_ENG)) return 0; if (target != NULL && is_dead(target, S_DEAD)) { if ((sp = fed) && (!shutup[PHASERS+i]) && !(is_dead(sp, S_DEAD))) { printf("%s phaser %d unlocking\n", sp->name, i+1); shutup[PHASERS+i]++; } sp->phasers[i].target = NULL; return 0; } if (cantsee(sp)) e_cloak_off(sp, fed); printf(" <%s frng phasers>\n", sp->name); for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type == 0) continue; ep = NULL; tp = NULL; if (lp->type == I_SHIP) { ep = lp->data.sp; if (ep == sp) continue; x = ep->x; y = ep->y; } else { tp = lp->data.tp; x = tp->x; y = tp->y; } hit = phaser_hit(sp, x, y, &sp->phasers[i], bear); if (hit <= 0) continue; if (tp) { if (tp->timedelay > segment) { switch (lp->type) { case I_TORPEDO: printf("hit on torpedo %d\n", tp->id); break; case I_ENG: printf("hit on %s's engineering\n", tp->from->name); break; case I_PROBE: printf("hit on probe %d\n", tp->id); break; default: fprintf(stderr, "hit on lp->type\n", lp->type); break; } tp->timedelay = 0.; } tp->fuel -= hit/2; if (tp->fuel < 0) tp->fuel = 0; continue; } /* * Determine which shield was hit */ j = rectify(bearing(x, sp->x, y, sp->y) - ep->course); if (j > 315.0 || j < 45.0) s = 1; else if (j < 135.0) s = 2; else if (j < 225.0) s = 3; else s = 4; (void) damage(hit, ep, s, &p_damage, D_PHASER); } /* * Reduce the load by the firing percentage */ sp->phasers[i].load *= 1.0 - (float) sp->p_percent / 100; return 0; } torpedo_firing(sp) struct ship *sp; { register int i; register float j; register int th; struct torpedo *tp; struct ship *target; struct list *lp; float bear; struct ship *fed; fed = shiplist[0]; for (i=0; i<sp->num_tubes; i++) { if (sp->tubes[i].status & T_FIRING) break; } if (i == sp->num_tubes) return 0; sp->tubes[i].status &= ~T_FIRING; th = sp->tubes[i].load; if (th == 0) return 0; target = sp->tubes[i].target; /* * Put in j the relative bearing of the tubes to the ship * Put in bear the absolute direction the tubes are pointing */ bear = sp->tubes[i].bearing + sp->course; j = rectify(sp->tubes[i].bearing); if (betw(j, sp->t_blind_left, sp->t_blind_right) && !is_dead(sp, S_ENG)) return 0; if (target != NULL && (is_dead(target, S_DEAD))) { if ((sp == fed) && !shutup[TUBES+i] && !is_dead(sp, S_DEAD)) { printf(" tube %d disengaging\n", i+1); shutup[TUBES+i]++; } sp->tubes[i].target = NULL; return 0; } sp->tubes[i].load = 0; lp = newitem(I_TORPEDO); lp->type = I_TORPEDO; lp->data.tp = MKNODE(struct torpedo, *, 1); if (lp->data.tp == (struct torpedo *)NULL) { fprintf(stderr, "torpedo_firing: malloc failed\n"); exit(2); } tp = lp->data.tp; tp->from = sp; tp->x = sp->x; tp->y = sp->y; tp->target = NULL; tp->course = rectify(bear); tp->fuel = th; tp->speed = sp->t_lspeed + sp->warp; tp->newspeed = tp->speed; tp->timedelay = (float)sp->t_delay; tp->prox = sp->t_prox; tp->id = new_slot(); tp->type = TP_TORPEDO; if (teletype) printf("\007"); if (cantsee(sp)) e_cloak_off(sp, fed); printf(" <<%s frng torpedo %d>>", sp->name, tp->id); if (teletype) printf("\007"); printf("\n"); return 1; } int ship_detonate(sp, lp) struct ship *sp; struct list *lp; { register int fuel; register int i; fuel = 0; printf("++%s++ destruct.\n", sp->name); for (i=0; i<sp->num_phasers; i++) if (!(sp->phasers[i].status & P_DAMAGED)) fuel += min(sp->phasers[i].load, MAX_PHASER_CHARGE); for (i=0; i<sp->num_tubes; i++) if (!(sp->tubes[i].status & T_DAMAGED)) fuel += min(sp->tubes[i].load, MAX_TUBE_CHARGE); fuel += sp->pods; antimatter_hit((char *) sp, sp->x, sp->y, fuel); lp->type = 0; for (i=0; i< S_NUMSYSTEMS; i++) sp->status[i] = 100; /* He's dead, Jim */ sp->cloaking = C_NONE; sp->complement = -1; } int torp_detonate(tp, lp) struct torpedo *tp; struct list *lp; { switch (lp->type) { case I_TORPEDO: printf(":: torp %d ::\n", tp->id); break; case I_PROBE: printf("** probe %d **\n", tp->id); break; case I_ENG: printf("## %s engineering ##\n", tp->from->name); break; default: fprintf(stderr, "torp_detonate lp->type %d\n",lp->type); break; } antimatter_hit((char *) tp, tp->x, tp->y, tp->fuel); return_slot(tp->id); delitem(lp); } SHAR_EOF chmod +x 'firing.c' fi # end of overwriting check if test -f 'globals.c' then echo shar: will not over-write existing file "'globals.c'" else cat << \SHAR_EOF > 'globals.c' /* * * TREK73: globals.c * * Global variable declarations * */ #include "externs.h" extern int fire_phasers(), fire_tubes(), lock_phasers(), lock_tubes(), turn_phasers(), turn_tubes(), load_tubes(), phaser_status(), tube_status(), launch_probe(), probe_control(), pos_report(), pos_display(), pursue(), elude(), helm(), self_scan(), scan(), alter_power(), jettison_engineering(), detonate_engineering(), alterpntparams(), play_dead(), corbomite_bluff(), surrender_ship(), request_surrender(), self_destruct(), abort_self_destruct(), save_game(), survivors(), help(), vers(); extern int standard_strategy(); char encstr[] = "\211g\321_-\251b\324\237;\255\263\214g\"\327\224.,\252|9\265=\357+\343;\311]\341`\251\b\231)\266Y\325\251"; char version[] = "TREK73 Version 3.2 08/17/86"; char *sysname[] = { "Computer", /* S_COMP */ "Sensors", /* S_SENSOR */ "Probe launcher", /* S_PROBE */ "Warp Drive", /* S_WARP */ }; char *statmsg[] = { /* When this system is dead */ "computer inoperable", /* S_COMP */ "sensors annihilated", /* S_SENSOR */ "probe launcher shot off", /* S_PROBE */ "warp drive disabled", /* S_WARP */ "engineering jettisoned", /* S_ENG */ } ; struct damage p_damage = { 50, 2, 20, 10, 3, /* eff, fuel, regen, crew, weapon */ 1000, "Computer destroyed.", /* S_COMP */ 500, "Sensors demolished.", /* S_SENSOR */ 100, "Probe launcher crushed.", /* S_PROBE */ 50, "Warp drive destroyed.", /* S_WARP */ } ; struct damage a_damage = { 100, 3, 10, 7, 6, /* eff, fuel, regen, crew, weapon */ 1500, "Computer banks pierced.", /* S_COMP */ 750, "Sensors smashed.", /* S_SENSOR */ 150, "Probe launcher shot off.", /* S_PROBE */ 75, "Warp drive disabled.", /* S_WARP */ } ; char *feds[] = { "Constitution", "Enterprise", "Hornet", "Lexington", "Potempkin", "Hood", "Kongo", "Republic", "Yorktown", } ; struct race_info aliens[MAXFOERACES] = { { "Klingon", "Empire", 0, 25, 25, 75, 75, 0, { "Annihilation", "Crusher", "Devastator", "Merciless", "Nemesis", "Pitiliess", "Ruthless", "Savage", "Vengeance", }, { "C-9 Dreadnought", "D-7 Battle Cruiser", "D-6 Light Battlecruiser", "F-5L Destroyer", }, { "Koloth", "Kang", "Kor", "Krulix", "Korax", "Karg", "Kron", "Kumerian", }, 0, }, { "Romulan", "Star Empire", 0, 5, 5, 80, 50, 0, { "Avenger", "Defiance", "Fearless", "Harrower", "Intrepid", "Relentless", "Seeker", "Torch", "Vigilant", }, { "Condor Dreadnought", "Firehawk Heavy Cruiser", "Sparrowhawk Light Cruiser", "Skyhawk Destroyer", }, { "Tal", "Tiercellus", "Diana", "Tama", "Subeus", "Turm", "Strell", "Scipio", }, 0, }, { "Kzinti", "Hegemony", 0, 50, 50, 50, 50, 0, { "Black Hole", "Comet", "Ecliptic", "Galaxy", "Meteor", "Nova", "Pulsar", "Quasar", "Satellite", }, { "Space Control Ship", "Strike Cruiser", "Light Cruiser", "Destroyer", }, { "Hunter", "\"Cat Who Sleeps With Dogs\"", "Fellus", "Corda", "\"Cat Who Fought Fuzzy Bear\"", "", "", "", }, 0, }, { "Gorn", "Confederation", 0, 80, 50, 50, 50, 0, { "Chimericon", "Dragonicon", "Ornithocon", "Predatoricon", "Reptilicon", "Serpenticon", "Tyranicon", "Vipericon", "Wyvericon", }, { "Tyrannosaurus Rex Dreadnought", "Allosaurus Heavy Cruiser", "Megalosaurus Light Cruiser", "Carnosaurus Destroyer", }, { "Sslith", "Dardiss", "Ssor", "Sslitz", "S'Arnath", "Zor", "", "", }, 0, }, { "Orion", "Pirates", 0, 95, 5, 50, 60, 0, { "Deuce Coupe", "Final Jeopardy", "Long John Dilithium", "Millennium Pelican", "Omega Race", "Penzance", "Road Warrior", "Scarlet Pimpernel", "Thunderduck", }, { "Battle Raider", "Heavy Cruiser", "Raider Cruiser", "Light Raider", }, { "Daniel \"Deth\" O'Kay", "Neil Ricca", "Delilah Smith", "Hamilcar", "Pharoah", "Felna Greymane", "Hacker", "Credenza", }, 0, }, { "Hydran", "Monarchy", 0, 50, 50, 50, 50, 0, { "Bravery", "Chivalry", "Devotion", "Fortitude", "Loyalty", "Modesty", "Purity", "Resolution", "Tenacity", }, { "Paladin Dreadnought", "Ranger-class Cruiser", "Horseman Light Cruiser", "Lancer Destroyer", }, { "Hypantspts", "S'Lenthna", "Hydraxan", "", "", "", "", "", }, 0, }, { "Lyran", "Empire", 0, 50, 50, 50, 50, 0, { "Bandit", "Claw", "Dangerous", "Fury", "Mysterious", "Sleek", "Tiger", "Vicious", "Wildcat", }, { "Lion Dreadnought", "Tiger Cruiser", "Panther Light Cruiser", "Leopard Destroyer", }, { "Kleave", "Leyraf", "Kuhla", "Nashar", "Prekor", "Ffarric", "Rippke", "Larkahn", }, 0, }, { "Tholian", "Holdfast", 0, 75, 25, 50, 50, 0, { "Bismark", "Centaur", "Draddock", "Forbin", "Kreiger", "Shlurg", "Trakka", "Varnor", "Warrior", }, { "Tarantula Dreadnought", "Cruiser", "Improved Patrol Cruiser", "Patrol Cruiser", }, { "Secthane", "Kotheme", "Sectin", "Brezgonne", "", "", "", "", }, 0, }, { "Monty Python", "Flying Circus", 0, -1, -1, -1, -1, 0, { "Blancmange", "Spam", "R.J. Gumby", "Lumberjack", "Dennis Moore", "Ministry of Silly Walks", "Argument Clinic", "Piranha Brothers", "Upper Class Twit of the Year", }, { "Thingee", "Thingee", "Thingee", "Thingee", }, { "Cleese", "Chapman", "Idle", "Jones", "Gilliam", "Bruce", "Throatwobblermangrove", "Arthur \"Two Sheds\" Jackson", }, 0, } }; float init_p_turn[MAXPHASERS][MAXPHASERS] = { { 666.666 }, { 0.0 }, { 0.0, 0.0 }, { 90.0, 0.0, 270.0 }, { 90.0, 0.0, 0.0, 270.0 }, { 90.0, 0.0, 0.0, 0.0, 270.0 }, { 90.0, 90.0, 0.0, 0.0, 270.0, 270.0 }, { 90.0, 90.0, 0.0, 0.0, 0.0, 270.0, 270.0 }, { 90.0, 90.0, 0.0, 0.0, 0.0, 0.0, 270.0, 270.0 }, { 90.0, 90.0, 90.0, 0.0, 0.0, 0.0, 270.0, 270.0, 270.0 }, { 90.0, 90.0, 90.0, 0.0, 0.0, 0.0, 0.0, 270.0, 270.0, 270.0 }, }; float init_t_turn[MAXTUBES][MAXTUBES] = { { 666.666 }, { 0.0 }, { 0.0, 0.0 }, { 60.0, 0.0, 300.0 }, { 60.0, 0.0, 0.0, 300.0 }, { 60.0, 0.0, 0.0, 0.0, 300.0 }, { 120.0, 60.0, 0.0, 0.0, 300.0, 240.0 }, { 120.0, 60.0, 0.0, 0.0, 0.0, 300.0, 240.0 }, { 120.0, 60.0, 60.0, 0.0, 0.0, 300.0, 300.0, 240.0 }, { 120.0, 60.0, 60.0, 0.0, 0.0, 0.0, 300.0, 300.0, 240.0 }, { 120.0, 120.0, 60.0, 60.0, 0.0, 0.0, 300.0,300.0, 240.0, 240.0 }, }; /* * for the linked list of items in space */ struct list head; struct list *tail; /* * Global definitions */ float segment = 0.05; /* Segment time */ float timeperturn = 2.0; /* Seconds per turn */ struct ship *shiplist[10]; /* All the ships in the battle */ char home[256]; /* Path to user's home directory */ char savefile[256]; /* Path to save file */ char captain[30]; /* captain's name */ char science[30]; /* science officer's name */ char engineer[30]; /* engineer's name */ char com[30]; /* communications officer's name */ char nav[30]; /* navigation officer's name */ char helmsman[30]; /* helmsman's name */ char title[9]; /* captain's title */ char foerace[30]; /* enemy's race */ char foename[30]; /* enemy's captain's name */ char foestype[30]; /* enemy's ship type */ char empire[30]; /* What the enemy's empire is called */ char class[3]; /* Class of own ship */ char foeclass[3]; /* Class of enemy ship(s) */ int shipnum; /* number of ships this time out */ int enemynum; /* Enemy identifier */ int terse = 0; /* print out initial description? */ int silly = 0; /* Use the Monty Python's Flying Curcus? */ int defenseless = 0; /* defensless ruse status */ int corbomite = 0; /* corbomite bluff status */ int surrender = 0; /* surrender offered by federation? */ int surrenderp = 0; /* Did we request that the enemy surrenders? */ int restart = 0; /* Should we restart the game? */ char shutup[HIGHSHUTUP]; /* Turn off messages after first printing */ char slots[HIGHSLOT]; /* Id slots */ int global = NORMAL; /* Situation status */ char *options; /* Environment variable */ char sex[20]; /* From environment */ char shipname[30]; /* From environment */ char racename[20]; /* From environment */ int reengaged = 0; /* Re-engaging far-off ships? */ char com_delay[6]; /* Number of seconds per real-time turn */ int teletype = 0; /* Flag for special teletype options */ int time_delay = 30; /* Time to enter command */ int trace = TR_OFF; /* Trace flag for debugging and records */ char can_cloak = 0; /* Can enemy ship cloak? */ double o_bpv; /* BPV of us */ double e_bpv; /* BPV of enemy */ struct ship_stat us; /* Our ship definition */ struct ship_stat them; /* Their ship definition */ struct cmd cmds[] = { { fire_phasers, "1", "Fire phasers", TURN }, { fire_tubes, "2", "Fire photon torpedoes", TURN }, { lock_phasers, "3", "Lock phasers onto target", TURN }, { lock_tubes, "4", "Lock tubes onto target", TURN }, { turn_phasers, "5", "Manually rotate phasers", TURN }, { turn_tubes, "6", "Manually rotate tubes", TURN }, { phaser_status, "7", "Phaser status", FREE }, { tube_status, "8", "Tube status", FREE }, { load_tubes, "9", "Load/unload torpedo tubes", TURN }, { launch_probe, "10", "Launch antimatter probe", TURN }, { probe_control, "11", "Probe control", TURN }, { pos_report, "12", "Position report", FREE }, { pos_display, "13", "Position display", FREE }, { pursue, "14", "Pursue an enemy vessel", TURN }, { elude, "15", "Elude an enemy vessel", TURN }, { helm, "16", "Change course and speed", TURN }, { self_scan, "17", "Damage report", FREE }, { scan, "18", "Scan enemy", TURN }, { alter_power, "19", "Alter power distribution", TURN }, { jettison_engineering, "20", "Jettison engineering", TURN }, { detonate_engineering, "21", "Detonate engineering", TURN }, { alterpntparams, "22", "Alter firing parameters", TURN}, { play_dead, "23", "Attempt defenseless ruse", TURN }, { corbomite_bluff, "24", "Attempt corbomite bluff(s)", TURN }, { surrender_ship, "25", "Surrender", TURN }, { request_surrender, "26", "Ask enemy to surrender", TURN }, { self_destruct, "27", "Initiate self-destruct", TURN }, { abort_self_destruct, "28", "Abort self-destruct", TURN }, { survivors, "29", "Survivors report", FREE }, { vers, "30", "Print version number", FREE }, { save_game, "31", "Saves game", FREE }, { help, "32", "Reprints above list", FREE }, { NULL, NULL, NULL, TURN }, } ; int high_command = 32; /* XXX */ /* used to print cmd list */ int cmdarraysize = sizeof(cmds) / sizeof (struct cmd) -1; /* Strategy table */ int (*strategies[])() = { standard_strategy, }; SHAR_EOF chmod +x 'globals.c' fi # end of overwriting check if test -f 'init.c' then echo shar: will not over-write existing file "'init.c'" else cat << \SHAR_EOF > 'init.c' /* * TREK73: init.c * * Game initialization routines * * name_crew, init_ships * */ #include "externs.h" #include <fcntl.h> name_crew() { char buf1[30]; int loop; int len; if (com_delay[0] != 0) time_delay = atoi(com_delay); if (science[0] == '\0') (void) strcpy(science, "Spock"); if (engineer[0] == '\0') (void) strcpy(engineer, "Scott"); if (com[0] == '\0') (void) strcpy(com, "Uhura"); if (nav[0] == '\0') (void) strcpy(nav, "Chekov"); if (helmsman[0] == '\0') (void) strcpy(helmsman, "Sulu"); if (captain[0] == '\0') { printf("\n\nCaptain: my last name is "); if (gets(buf1) == NULL || *buf1 == '\0') exit(1); (void) strncpy (captain, buf1, sizeof captain); captain[sizeof captain - 1] = '\0'; } if (captain[0] == '*') { terse = 1; len = strlen(captain) + 1; for (loop = 1; loop <= len; loop++) captain[loop-1] = captain[loop]; } if (sex[0] != '\0') { (void) strncpy(buf1, sex, sizeof sex); sex[sizeof sex - 1] = '\0'; } else { printf("%s: My sex is: ",captain); if (gets(buf1) == NULL || *buf1 == '\0') exit(1); } switch(*buf1) { case 'M': case 'm': (void) strcpy(title, "Sir"); break; case 'F': case 'f': (void) strcpy(title, "Ma'am"); break; default : switch ((int)(random() % 6)) { case 0: (void) strcpy(title, "Fag"); break; case 1: (void) strcpy(title, "Fairy"); break; case 2: (void) strcpy(title, "Fruit"); break; case 3: (void) strcpy(title, "Weirdo"); break; case 4: (void) strcpy(title, "Gumby"); break; case 5: (void) strcpy(title, "Freak"); break; } } } init_ships() { struct ship_stat *my_class, *his_class, *ship_class(), *read_class(); int myread, hisread; /* Did we read from file? */ register int i; register int j; register struct ship *sp; register struct list *lp; int range; float bear; char *tmp; int swap1, swap2; int offset; int loop; char buf1[30]; getships: printf(" I'm expecting [1-9] enemy vessels "); if (gets(buf1) == NULL || *buf1 == NULL) { printf("%s: %s, Starfleet Command reports that you have been\n", com, title); puts(" relieved of command for dereliction of duty."); exit(1); } if (buf1[0] != '\0') { i = atoi(buf1); if (i < 1 || i > MAXESHIPS) { printf("%s: %s, Starfleet Command reports that it can only\n", com, title); printf(" be from 1 to 9. Try again.\n"); printf("%s: Correct, Lieutenant -- just testing your attention..\n", captain); goto getships; } shipnum = i; } else shipnum = randm(MAXESHIPS); for (loop = 0; loop < shipnum; loop++); slots[loop] = 'X'; offset = !silly; if (racename[0] == '\0') { enemynum = randm(MAXFOERACES - offset) - 1; } else { for (loop=0; loop<MAXFOERACES; loop++) if (!strncmp(racename, aliens[loop].race_name, strlen(racename))) { enemynum = loop; break; } if (loop == MAXFOERACES) { printf("Cannot find race %s.\n", racename); enemynum = randm(MAXFOERACES - offset) - 1; } } if (class[0] == '\0') (void) strcpy(class, "CA"); if (foeclass[0] == '\0') (void) strcpy(foeclass, "CA"); myread = 0; hisread = 0; if ((my_class = ship_class(class)) == NULL) if ((my_class = read_class(class, 0)) == NULL) my_class = ship_class("CA"); else myread = 1; if ((his_class = ship_class(foeclass)) == NULL) if ((his_class = read_class(foeclass, 1)) == NULL) his_class = ship_class("CA"); else { hisread = 1; enemynum = randm(MAXFOERACES-1); } if (!hisread) { (void) strncpy(foerace, aliens[enemynum].race_name, sizeof foerace); (void) strncpy(foestype, aliens[enemynum].ship_types[his_class->class_num], sizeof foestype); (void) strncpy(empire, aliens[enemynum].empire_name, sizeof empire); } while (foename[0] == '\0') (void) strncpy(foename, aliens[enemynum].captains[randm(MAXECAPS) - 1], sizeof foename); foerace[sizeof foerace - 1] = '\0'; foestype[sizeof foestype - 1] = '\0'; empire[sizeof empire - 1] = '\0'; foename[sizeof foename - 1] = '\0'; /* * Randomize the enemy ships */ for (loop = 0; loop < 20; loop++) { swap1 = randm(MAXESHIPS) - 1; swap2 = randm(MAXESHIPS) - 1; tmp = aliens[enemynum].ship_names[swap1]; aliens[enemynum].ship_names[swap1] = aliens[enemynum].ship_names[swap2]; aliens[enemynum].ship_names[swap2] = tmp; } /* * Everybody is centered on the Federation ship * (for now, anyways) */ for (i=0; i<=shipnum; i++) { lp = newitem(I_SHIP); lp->data.sp = MKNODE(struct ship, *, 1); sp = shiplist[i] = lp->data.sp; if (sp == (struct ship *)NULL) { fprintf(stderr, "init_ships: malloc failed\n"); exit(2); } if (i) (void) strncpy(sp->name, aliens[enemynum].ship_names[i-1], sizeof sp->name); (void) strncpy(sp->class, his_class->abbr, sizeof sp->class); sp->warp = sp->newwarp = 1.0; sp->course = sp->newcourse = (float)randm(360); sp->eff = his_class->e_eff; sp->regen = his_class->regen; sp->energy = his_class->energy; sp->pods = his_class->pods; sp->id = i; sp->p_spread = INIT_P_SPREAD; sp->num_phasers = his_class->num_phaser; sp->num_tubes = his_class->num_torp; sp->max_speed = his_class->e_warpmax; sp->orig_max = his_class->e_warpmax; sp->deg_turn = his_class->turn_rate; sp->ph_damage = his_class->ph_shield; sp->tu_damage = his_class->tp_shield; sp->p_blind_left = his_class->p_blind_left; sp->p_blind_right = his_class->p_blind_right; sp->t_blind_left = his_class->t_blind_left; sp->t_blind_right = his_class->t_blind_right; for (j=0; j<SHIELDS; j++) { sp->shields[j].eff = 1.0; sp->shields[j].drain = 1.0; sp->shields[j].attemp_drain = 1.0; } for (j=0; j<sp->num_phasers; j++) { sp->phasers[j].target = NULL; sp->phasers[j].bearing = init_p_turn[sp->num_phasers][j]; sp->phasers[j].load = INIT_P_LOAD; sp->phasers[j].drain = INIT_P_DRAIN; sp->phasers[j].status = P_NORMAL; } for (j=0; j<sp->num_tubes; j++) { sp->tubes[j].target = NULL; sp->tubes[j].bearing = init_t_turn[sp->num_tubes][j]; sp->tubes[j].load = INIT_T_LOAD; sp->tubes[j].status = T_NORMAL; } sp->t_lspeed = INIT_T_SPEED; sp->t_prox = INIT_T_PROX; sp->t_delay = INIT_T_TIME; sp->p_percent = INIT_P_PERCENT; for (j=0; j<MAXSYSTEMS; j++) /* Everything is OK */ sp->status[j] = 0; sp->target = NULL; sp->relbear = 0.0; sp->delay = 10000.; range = 4100 + randm(300) - i * 200; bear = toradians(randm(360)); sp->x = range * cos(bear); sp->y = range * sin(bear); sp->complement = his_class->e_crew; sp->strategy = strategies[0]; if (!strcmp(foerace, "Romulan") || can_cloak) sp->cloaking = C_OFF; else sp->cloaking = C_NONE; sp->cloak_energy = his_class->cloaking_energy; sp->cloak_delay = CLOAK_DELAY; sp->position.x = 0; sp->position.y = 0; sp->position.warp = 0.0; sp->position.range = 0; sp->position.bearing = 0.0; sp->position.course = 0.0; sp->p_firing_delay = his_class->p_firing_delay; sp->t_firing_delay = his_class->t_firing_delay; } /* * federation exceptions */ sp = shiplist[0]; (void) strcpy(sp->class, my_class->abbr); sp->course = sp->newcourse = 0.0; sp->x = sp->y = 0; sp->eff = my_class->o_eff; sp->regen = my_class->regen; sp->energy = my_class->energy; sp->pods = my_class->pods; sp->complement = my_class->o_crew; sp->num_phasers = my_class->num_phaser; sp->num_tubes = my_class->num_torp; sp->max_speed = my_class->o_warpmax; sp->orig_max = my_class->o_warpmax; sp->deg_turn = my_class->turn_rate; sp->ph_damage = my_class->ph_shield; sp->tu_damage = my_class->tp_shield; sp->cloaking = C_NONE; for (j=0; j<sp->num_phasers; j++) { sp->phasers[j].target = NULL; sp->phasers[j].bearing = init_p_turn[sp->num_phasers][j]; sp->phasers[j].load = INIT_P_LOAD; sp->phasers[j].drain = INIT_P_DRAIN; sp->phasers[j].status = P_NORMAL; } for (j=0; j<sp->num_tubes; j++) { sp->tubes[j].target = NULL; sp->tubes[j].bearing = init_t_turn[sp->num_tubes][j]; sp->tubes[j].load = INIT_T_LOAD; sp->tubes[j].status = T_NORMAL; } sp->p_firing_delay = my_class->p_firing_delay; sp->t_firing_delay = my_class->t_firing_delay; if (strlen(shipname) == 0) { i = randm(MAXFEDS) - 1; (void) strcpy(sp->name, feds[i]); (void) strcpy(shipname, sp->name); } else { (void) strcpy(sp->name, shipname); } for(loop=shipnum + 1; loop < HIGHSLOT; loop++) slots[loop] = ' '; } struct ship_stat *read_class(str, flag) char *str; int flag; { int fd, bytes; char path[BUFSIZ]; sprintf(path, "%s.trek%s", home, str); if ((fd = open(path, O_RDONLY, 0)) < 0) { printf("Could not find file %s\n", path); return(NULL); } switch (flag) { case 0: if ((bytes = read(fd, &us, sizeof(us))) != sizeof(us)) { puts("Bad format in file"); return(NULL); } return(&us); break; case 1: if ((bytes = read(fd, &them, sizeof(them))) != sizeof(them)) { puts("Bad format in file"); return(NULL); } if ((bytes = read(fd, foestype, 30)) < 0) return(NULL); if ((bytes = read(fd, foerace, 30)) < 0) return(NULL); if ((bytes = read(fd, empire, 30)) < 0) return(NULL); if ((bytes = read(fd, &can_cloak, 1)) < 0) return(NULL); if ((bytes = read(fd, &e_bpv, sizeof(int))) < 0) return(NULL); return(&them); break; } } SHAR_EOF chmod +x 'init.c' fi # end of overwriting check if test -f 'main.c' then echo shar: will not over-write existing file "'main.c'" else cat << \SHAR_EOF > 'main.c' /* * TREK73: main.c * * Originally written (in HP-2000 BASIC) by * William K. Char, Perry Lee, and Dan Gee * * Rewritten in C by * Dave Pare (sdcsvax!sdamos!mr-frog) * (mr-frog@amos.ling.ucsd.edu) * and * Christopher Williams (ucbvax!ucbmerlin!williams) * (williams@merlin.berkeley.edu) * * Corrected, Completed, and Enhanced by * Jeff Okamoto (ucbvax!okamoto) * (okamoto@cory.berkeley.edu) * Peter Yee (ucbvax!yee) * (yee@ucbarpa.berkeley.edu) * Matt Dillon (ucbvax!dillon) * (dillon@berkeley.edu) * Dave Sharnoff (ucbvax!ucbcory!muir) * (muir@cogsci.berkeley.edu) * Joel Duisman (ucbvax!duisman) * (duisman@miro.berkeley.edu) * and * Roger J. Noe (riccb!rjnoe) * (ihnp4!riccb!rjnoe@berkeley.edu) * * Main Loop * * main, alarmtrap, quitgame, buffering * */ #include "externs.h" #include <signal.h> #include <setjmp.h> static jmp_buf jumpbuf; main(argc, argv, envp) int argc; char *argv[]; char *envp[]; { register char *env; int alarmtrap(); int quitgame(); if (buffering(stdout) < 0) perror("cannot fstat stdout"); (void) signal(SIGALRM, alarmtrap); (void) signal(SIGINT, quitgame); srandom(time(0)); time_delay = 30; set_save(); if (argc > 1) if (argv[1][0] != '-') { restore(argv[1], envp); /* Will not return */ exit(1); } options = getenv("TREK73OPTS"); if (options != NULL) parse_opts(options); get_comlineopts(argc, argv); if (restart && savefile[0] != '\0') { restore(savefile, envp); /* Will not return */ exit(1); } name_crew(); init_ships(); (void) mission(); (void) alert(); playit(); } /* * Main loop */ playit() { struct cmd *scancmd(); int alarmtrap(); int quitgame(); register struct ship *sp; char buf1[30]; struct cmd *cp; int loop; (void) setjmp(jumpbuf); sp = shiplist[0]; if (!(is_dead(sp, S_DEAD))) { next: for (loop = 0; loop < HIGHSHUTUP; loop++) shutup[loop] = 0; fflush(stdin); printf("\n%s: Code [1-%d] ", captain, high_command); fflush(stdout); (void) alarm((unsigned) time_delay); if (gets(buf1) != NULL) { (void) alarm(0); cp = scancmd(buf1); if (cp != NULL) { (*cp->routine)(sp); if (cp->turns == FREE) goto next; } else printf("\n%s: %s, I am unable to interpret your last utterance.\n", science, title); } else (void) alarm(0); } alarmtrap(0); /* This point is never reached since alarmtrap() always concludes with a longjmp() back to the setjmp() above the next: label */ /*NOTREACHED*/ } alarmtrap(sig) int sig; { register int i; if (sig) { puts("\n** TIME **"); (void) signal(sig, alarmtrap); stdin->_cnt = 0; } for (i = 1; i <= shipnum; i++) shiplist[i]->strategy(shiplist[i]); if (!(is_dead(shiplist[0], S_DEAD))) printf("\n"); (void) move_ships(); (void) check_targets(); (void) misc_timers(); (void) disposition(); longjmp(jumpbuf, 1); } quitgame() { char answer[20]; unsigned timeleft; timeleft = alarm(0); (void) signal(SIGINT, SIG_IGN); puts("\n\nDo you really wish to stop now? Answer yes or no:"); if(gets(answer) == NULL || answer[0] == 'y' || answer[0] == 'Y') exit(0); (void) signal(SIGINT, quitgame); if(timeleft) (void) alarm((unsigned)timeleft); return; } /* buffering: Determine whether or not stream is to be buffered. If it's a character-special device, any buffering in effect will remain. If it's not a character-special device, then stream will be unbuffered. There are many ways to decide what to do here. One would have been to make it unbuffered if and only if !isatty(fileno(stream)). This is usually implemented as a single ioctl() system call which returns true if the ioctl() succeeds, false if it fails. But there are ways it could fail and still be a tty. Then there's also examination of stream->_flag. UNIX is supposed to make any stream attached to a terminal line-buffered and all others fully buf- fered by default. But sometimes even when isatty() succeeds, stream->_flag indicates _IOFBF, not _IOLBF. And even if it is determined that the stream should be line buffered, setvbuf(3S) doesn't work right (in UNIX 5.2) to make it _IOLBF. So about the only choice is to do a straightforward fstat() and ascertain definitely to what the stream is attached. Then go with old reliable setbuf(stream, NULL) to make it _IONBF. The whole reason this is being done is because the user may be using a pipefitting program to collect a "transcript" of a session (e.g. tee(1)), or redirecting to a regular file and then keeping a tail(1) going forever to actually play the game. This assures that the output will keep pace with the execution with no sacrifice in efficiency for normal execution. [RJN] *****/ #include <sys/types.h> #include <sys/stat.h> int buffering(stream) FILE *stream; { struct stat st; if (fstat(fileno(stream), &st) < 0) return -1; if ((st.st_mode & S_IFMT) != S_IFCHR) setbuf(stream, NULL); return 0; } SHAR_EOF chmod +x 'main.c' fi # end of overwriting check if test -f 'misc.c' then echo shar: will not over-write existing file "'misc.c'" else cat << \SHAR_EOF > 'misc.c' /* * TREK73: misc.c * * Miscellaneous Routines * * help, scancmd, new_slot, return_slot, vowelstr, * check_p_damage, check_t_damage, check_p_turn, check_t_turn, * ship_class * */ #include "externs.h" int help(dummy) struct ship *dummy; { struct cmd *cpbegin, *cpmiddle; puts("\nTrek73 Commands:"); puts("Code Command Code Command"); putchar('\n'); cpbegin = &cmds[0]; cpmiddle = &cmds[(cmdarraysize + 1) >> 1]; while (cpmiddle->routine != NULL) { printf("%3s: %c %-31s:%3s: %c %-31s\n", cpbegin->word1, ((cpbegin->turns) ? ' ' : '*'), cpbegin->word2, cpmiddle->word1, ((cpmiddle->turns) ? ' ' : '*'), cpmiddle->word2); cpbegin++; cpmiddle++; } if (cmdarraysize & 1) printf("%3s: %c %-31s", cpbegin->word1, ((cpbegin->turns) ? ' ' : '*'), cpbegin->word2); puts("\n\n * does not use a turn"); dummy = dummy; /* LINT */ } struct cmd *scancmd(buf) char *buf; { static char **argp = NULL; struct cmd *cp; int argnum; int first; argnum = parsit(buf, &argp); first = strlen(argp[0]); if (argnum && first) for (cp = &cmds[0]; cp->routine != NULL; cp++) if (!strncmp(argp[0], cp->word1, first)) return (cp); return (NULL); } /* * This routine handles getting unique identifier numbers for * all objects. */ new_slot() { /* * This is to make it appear that in a 2-ship duel, for * instance, the first object to appear will be numbered * as 3. */ int i = shipnum + 2; while ((slots[i] == 'X') && (i <= HIGHSLOT)) i++; if (i > HIGHSLOT) { puts("The game will terminate now due to an inability to handle the number of"); puts("objects in space (i.e. vessels, torpedoes, probes, etc). Sorry!"); exit(-1); } slots[i] = 'X'; return i; } /* * This routine handles returning identifiers */ return_slot(i) int i; { if (slots[i] != 'X') printf("FATAL ERROR - Slot already empty!"); slots[i] = ' '; } char *vowelstr(str) char *str; { switch(*str) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': return "n"; default: return ""; } } /* * This routine takes an array generated from commands 1, 3, and 5 * to print out a list of those phasers damaged and unable to * either fire, lock, or turn. */ check_p_damage(array, sp, string) int array[]; struct ship *sp; char *string; { int i, j; j = 0; for (i=0; i<sp->num_phasers; i++) { if (array[i] && (sp->phasers[i].status & P_DAMAGED)) { if (!j) printf("Computer: Phaser(s) %d", i+1); else printf(", %d", i+1); j++; } } if (j > 1) printf(" are damaged and unable to %s.\n", string); else if (j == 1) printf(" is damaged and unable to %s.\n", string); } /* * This routine takes an array generated from commands 2, 4, and 6 * to print out a list of those tubes damaged and unable to either * fire, lock, or turn. */ check_t_damage(array, sp, string) int array[]; struct ship *sp; char *string; { int i, j; j = 0; for (i=0; i<sp->num_tubes; i++) { if (array[i] && (sp->tubes[i].status & P_DAMAGED)) { if (!j) printf("Computer: Tube(s) %d", i+1); else printf(", %d", i+1); j++; } } if (j > 1) printf(" are damaged and unable to %s.\n", string); else if (j == 1) printf(" is damaged and unable to %s.\n", string); } /* * This routine checks to see if a phaser is pointing into our * blind side */ check_p_turn(array, sp, flag) int array[]; struct ship *sp; int flag; /* If 1, came from fire_phasers */ { register int i; register int j; register float k; register float bear; struct ship *target; j = 0; for (i=0; i<sp->num_phasers; i++) { if (!array[i]) continue; if (flag && !(sp->phasers[i].status & P_FIRING)) continue; target = sp->phasers[i].target; /* * This hack is here since when the phaser is locked, * the bearing points at the target, whereas when * not locked, the bearing is relative to the ship. */ if (target == NULL) { bear = sp->phasers[i].bearing + sp->course; k = sp->phasers[i].bearing; } else { bear = bearing(sp->x, target->x, sp->y, target->y); k = bear - sp->course; } k = rectify(k); if (betw(k, sp->p_blind_left, sp->p_blind_right) && !(is_dead(sp, S_ENG))) { if (!j) printf("Computer: Phaser(s) %d", i + 1); else printf(", %d", i + 1); j++; } } if (j > 1) printf(" are pointing into our blind side.\n"); else if (j == 1) printf(" is pointing into our blind side.\n"); } /* * This routine checks to see if a tube is turned into * our blind side. */ check_t_turn(array, sp, flag) int array[]; struct ship *sp; int flag; /* If 1, came from fire_tubes */ { register int i; register int j; register float k; register float bear; struct ship *target; j = 0; for (i=0; i<sp->num_tubes; i++) { if (!array[i]) continue; if (flag && !(sp->tubes[i].status & T_FIRING)) continue; target = sp->tubes[i].target; /* * This hack is here since when the tube is locked, * the bearing points at the target, whereas when * not locked, the bearing is relative to the ship. */ if (target == NULL) { bear = sp->tubes[i].bearing + sp->course; k = sp->tubes[i].bearing; } else { bear = bearing(sp->x, target->x, sp->y, target->y); k = bear - sp->course; } k = rectify(k); if (betw(k, sp->t_blind_left, sp->t_blind_right) && !(is_dead(sp, S_ENG))) { if (!j) printf("Computer: Tubes(s) %d", i + 1); else printf(", %d", i + 1); j++; } } if (j > 1) printf(" are pointing into our blind side.\n"); else if (j == 1) printf(" is pointing into our blind side.\n"); } struct ship_stat *ship_class(s) char *s; { int i; for (i = 0; i< MAXSHIPCLASS; i++) if (!strcmp(stats[i].abbr, s)) { return(&stats[i]); } return(NULL); } SHAR_EOF chmod +x 'misc.c' fi # end of overwriting check if test -f 'mission.c' then echo shar: will not over-write existing file "'mission.c'" else cat << \SHAR_EOF > 'mission.c' /* * TREK73: mission.c * * Mission Assignment Routines * * mission, alert, missionlog */ #ifdef BSD #include <sys/time.h> #endif #ifdef SYSV #include <time.h> #endif #include "externs.h" mission() { int onef; char temp[3]; if (terse) return; onef = (shipnum == 1); puts("\n\n\nSpace, the final frontier."); printf("These are the voyages of the starship %s.\n", shiplist[0]->name); puts("Its five year mission: to explore strange new worlds,"); puts("to seek out new life and new civilizations,"); puts("to boldly go where no man has gone before!"); puts("\n S T A R T R E K\n"); missionlog(); if (onef) strcpy(temp, "a"); else sprintf(temp,"%d", shipnum); printf("%s: %s, I'm picking up %s vessel%s on an interception\n", helmsman, title, temp, plural(shipnum)); printf(" course with the %s.\n", shiplist[0]->name); printf("%s: Sensors identify %s as ", science, onef ? "it" : "them"); if (onef) printf("a%s ", vowelstr(foerace)); printf("%s %s%s,\n", foerace, foestype, plural(shipnum)); printf(" probably under the command of Captain %s.\n", foename); printf("%s: Sound general quarters, Lieutenant!\n", captain); printf("%s: Aye, %s!\n", com, title); } alert() { register int i; printf("Computer: The %ss are attacking the %s with the ", foerace, shiplist[0]->name); if (shipnum == 1) { printf("%s", shiplist[1]->name); } else { for (i = 1; i <= shipnum; i++) { if (i == shipnum) printf("and the "); printf("%s", shiplist[i]->name); if (i == shipnum) continue; printf(", "); if (i == 1 || i == 6) printf("\n "); } } printf(".\n"); } missionlog() { static char *missiontab[] = { /* "The Trouble with Tribbles" */ " We are acting in response to a Priority 1 distress call from", "space station K7.", /* "The Gamesters of Triskelion" */ " We are orbiting Gamma 2 to make a routine check of automatic", "communications and astrogation stations.", /* "Metamorphosis" */ " We are on course for Epsilon Canares 3 to treat Commissioner", "Headford for Sukaro's disease.", /* "Journey to Babel" */ " We have been assigned to transport ambassadors to a diplomatic", "conference on the planet code named Babel.", /* ?? */ " Our mission is to investigate a find of tritanium on Beta 7.", 0, /* "Shore Leave" */ " We are orbiting Rigel 4 for therapeutic shore leave.", 0, /* "A Piece of the Action" */ " We are orbiting Sigma Iota 2 to study the effects of", "contamination upon a developing culture.", /* "The Immunity Syndrome" */ " We have altered course for a resue mission on the Gamma 7A", "system.", /* "Amok Time" */ " We are presently on course for Altair 6 to attend inauguration", "cermonies on the planet.", /* "Who Mourns for Adonis?" */ " We are on a cartographic mission to Pollux 9.", 0, /* "The Changeling" */ " We are headed for Malurian in response to a distress call", "from that system.", /* "Mirror, Mirror" */ " We are to negotiate a treaty to mine dilithium crystals from", "the Halkans.", /* "The Apple" */ " We are to investigate strange sensor readings reported by a", "scoutship investigating Gamma Triangula 6.", /* "The Doomsday Machine" */ " We are headed for planets L370 and L374 to investigate the", "disappearance of the starship Constellation in that vincinity.", /* "The Ultimate Computer" */ " We are ordered, with a skeleton crew, to proceed to Space", "Station K2 to test Dr. Richard Daystrom's computer M5.", /* "Bread and Circuses" */ " We have encountered debris from the SS Beagle and are", "proceeding to investigate.", /* "Patterns of Force" */ " We are on course for Ekos to locate John Gill.", 0, /* "The Paradise Syndrome" */ " We are to divert an asteroid from destroying an inhabited", "planet.", /* "And The Children Shall Lead" */ " We are responding to a distresss call form the scientific", "expedition on Triacus.", /* "Is There in Truth No Beauty?" */ " We have been assigned to transport the Medusan Ambassador to", "to his home planet.", /* "Star Trek II -- The Wrath of Khan" */ " We are within the Neutral Zone on a mission to rescue the", "Kobayashi Maru.", }; long t1; struct tm *localtime(), *date; t1 = time(0); date = localtime(&t1); printf("%s: Captain's log, stardate %02d%02d.%02d\n", captain, date->tm_year, date->tm_mon+1, date->tm_mday); t1 = (randm(sizeof missiontab / sizeof (char *)) - 1) & ~01; puts(missiontab[t1]); if (missiontab[++t1]) printf(" %s\n", missiontab[t1]); } SHAR_EOF chmod +x 'mission.c' fi # end of overwriting check if test -f 'bpv.c' then echo shar: will not over-write existing file "'bpv.c'" else cat << \SHAR_EOF > 'bpv.c' /* * TREK73: bpv.c * * Calculate Basic Point Values for all ships. * */ #include <stdio.h> #include "externs.h" main() { double crew, pods, regen, num_weapons, phaser, torp; double bpv; double atof(); int i; char buf[20]; printf("Regeneration multiplier :"); gets(buf); regen = atof(buf); printf("Pods divisor :"); gets(buf); pods = atof(buf); printf("Phaser multiplier :"); gets(buf); phaser = atof(buf); printf("Torpedo multiplier :"); gets(buf); torp = atof(buf); printf("Weapons multiplier :"); gets(buf); num_weapons = atof(buf); printf("Crew divisor :"); gets(buf); crew = atof(buf); for(i=0; i<MAXSHIPCLASS; i++) { bpv = 0.; bpv += stats[i].regen * regen; bpv += stats[i].pods / pods; bpv += stats[i].ph_shield * phaser; bpv += stats[i].tp_shield * torp; bpv += (stats[i].num_phaser + stats[i].num_torp) * num_weapons; bpv += stats[i].o_crew / crew; printf("%s: BPV = %.2f\n", stats[i].abbr, bpv); } } SHAR_EOF chmod +x 'bpv.c' fi # end of overwriting check if test -f 'shipyard.c' then echo shar: will not over-write existing file "'shipyard.c'" else cat << \SHAR_EOF > 'shipyard.c' /* * TREK73: shipyard.c * * Design your own ship * */ #include <stdio.h> #include <strings.h> #include <fcntl.h> #include "externs.h" char buf[20]; char class[3]; char cloak; double bpv; struct { char description[30]; char race[30]; char empire[30]; } stuff; struct ship_stat design; main() { double regen, efficiency, atof(), floor(), round(); int crew, phasers, torps, pods, max_speed, turn, p_div, t_div; int done, atoi(); printf("Class identifier :"); gets(class); class[2] = '\0'; printf("Class description :"); gets(stuff.description); stuff.description[29] = '\0'; printf("Race name :"); gets(stuff.race); stuff.race[29] = '\0'; printf("Empire name :"); gets(stuff.empire); stuff.empire[29] = '\0'; done = 0; while (!done) { printf("Regeneration :"); gets(buf); regen = atof(buf); if (regen >= 0) done = 1; else printf(">>> Be reasonable.\n"); } done = 0; while (!done) { printf("Pods :"); gets(buf); pods = atof(buf); if (pods >= 0) done = 1; else printf(">>> Be reasonable.\n"); } done = 0; while (!done) { printf("Number of phasers :"); gets(buf); phasers = atoi(buf); if ((phasers >= 0) && (phasers < MAXWEAPONS)) done = 1; else if (phasers < 0) printf(">>> Be reasonable.\n"); else printf(">>> Can't have more than %d.\n", MAXWEAPONS-1); } done = 0; while (!done) { printf("Number of tubes :"); gets(buf); torps = atoi(buf); if ((torps >= 0) && (torps < MAXWEAPONS)) done = 1; else if (torps < 0) printf(">>> Be reasonable.\n"); else printf(">>> Can't have more than %d.\n", MAXWEAPONS-1); } done = 0; while (!done) { printf("Shield divisor for phasers :"); gets(buf); p_div = atof(buf); if (p_div > 0) done = 1; else printf(">>> Be reasonable.\n"); } done = 0; while (!done) { printf("Shield divisor for torps :"); gets(buf); t_div = atof(buf); if (t_div > 0) done = 1; else printf(">>> Be reasonable.\n"); } done = 0; while (!done) { printf("Crew :"); gets(buf); crew = atoi(buf); if (crew > 0) done = 1; else printf(">>> Be reasonable.\n"); } printf("Can the ship cloak ?"); gets(buf); if (buf != NULL && (buf[0] == 'y' || buf[0] == 'Y')) cloak = 1; else cloak = 0; bpv = 0.; bpv += regen * 12; bpv += pods / 2; bpv += p_div * 30; bpv += t_div * 40; bpv += (phasers + torps) * 10; bpv += crew / 15; printf("%s: BPV = %.2f\n", class, bpv); efficiency = round(4 * (0.0034 * bpv - 0.78)) / 4; if (efficiency < 0.25) efficiency = 0.25; turn = 10 - floor(bpv / 100); if (turn < 1) turn = 1; max_speed = (int) round(-0.004 * bpv + 11); if (max_speed < 1) max_speed = 1; printf("Efficiency = %.2f\n", efficiency); printf("Turn = %d\n", turn); printf("Max speed = %d\n", max_speed); strcpy(design.abbr, class); design.num_phaser = phasers; design.num_torp = torps; design.o_warpmax = max_speed; design.e_warpmax = max_speed + 2; design.o_eff = efficiency; design.e_eff = efficiency; design.regen = regen; /* XXXX */ design.energy = pods * 3 / 4; design.pods = pods; design.o_crew = crew; design.e_crew = crew * 5 / 4; design.ph_shield = p_div; design.tp_shield = t_div; design.turn_rate = turn; design.cloaking_energy = 4; /* XXXX */ design.t_blind_left = 135; design.t_blind_right = 225; design.p_blind_left = 125; design.p_blind_right = 235; design.p_firing_delay = 4; design.t_firing_delay = 4; save_design(); } double round(x) double x; { return( floor(x + 0.5)); } save_design() { int fd, bytes; char path[BUFSIZ]; char *home, *getenv(); if ((home = getenv("HOME")) != NULL) strcpy(path, home); else strcpy(path, "."); strcat(path, "/.trek"); strcat(path, design.abbr); printf("Saving to file %s\n", path); if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) { perror("open"); exit(1); } bytes = write(fd, (char *)&design, sizeof(struct ship_stat)); if (bytes != sizeof(struct ship_stat)) { fprintf(stderr, "Wrote only %d, not %d bytes\n", bytes, sizeof(struct ship_stat)); unlink(path); exit(1); } bytes = write(fd, &stuff, sizeof(stuff)); bytes = write(fd, &cloak, 1); bytes = write(fd, (char *)&bpv, sizeof(int)); close(fd); } SHAR_EOF chmod +x 'shipyard.c' fi # end of overwriting check # End of shell archive exit 0
okamoto@ucbvax.UUCP (12/10/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # moveships.c # parseopts.c # parsit.c # save.c # ships.c # special.c # strat1.c # subs.c # vers.c # This archive created: Wed Dec 10 09:01:32 1986 # By: Jeff Okamoto () export PATH; PATH=/bin:$PATH if test -f 'moveships.c' then echo shar: will not over-write existing file "'moveships.c'" else cat << \SHAR_EOF > 'moveships.c' /* * TREK73: moveships.c * * Actual command execution * * move_ships, check_targets, misc_timers, disposition * */ #include "externs.h" move_ships() { register int i; register float j; register float k; register struct list *lp; register struct ship *sp; register float fuel_use; struct torpedo *tp; struct ship *fed; struct list *lp1; struct ship *sp1; float iterations; float tmpf; float energy; float course, newcourse; float warp, newwarp; int x, y; struct ship *target; double d0; float Mpersegment; double floor(), fabs(); /* * The value 100 is the number of Megameters per second * per warp-factor */ Mpersegment = segment * 100.0; iterations = (int)floor(timeperturn/segment + 0.5); /* What a crock! */ for (i=0; i<=shipnum; i++) distribute(shiplist[i]); fed = shiplist[0]; for (i=0; i<iterations; i++) { for (lp = &head; lp != NULL; lp = lp->fwd) { if (lp == tail) break; if (lp->type == I_UNDEFINED) continue; sp = NULL; tp = NULL; if (lp->type == I_SHIP) sp = lp->data.sp; else tp = lp->data.tp; if (sp && is_dead(sp, S_DEAD)) continue; if ((sp) && (i % sp->p_firing_delay == 0)) (void) phaser_firing(sp); if ((sp) && (i % sp->t_firing_delay == 0)) (void) torpedo_firing(sp); /* * time fuses */ if (tp) { tp->timedelay -= segment; if (tp->timedelay <= 0.) { torp_detonate(tp, lp); continue; } } else { sp->delay -= segment; if (sp->delay <= 0.) { ship_detonate(sp, lp); continue; } } /* * proximity fuse */ if (tp && tp->prox != 0) { for (lp1 = &head; lp1 != tail; lp1 = lp1->fwd) { if (lp1->type == I_SHIP) { sp1 = lp1->data.sp; if (sp1 == tp->from) continue; if (cantsee(sp1)) continue; j = rangefind(tp->x, sp1->x, tp->y, sp1->y); } else if (lp1->type == I_ENG) { sp1 = lp1->data.sp; if (sp1 == tp->from) continue; if (cantsee(sp1)) continue; j = rangefind(tp->x, sp1->x, tp->y, sp1->y); } else continue; if (j >= tp->prox) continue; torp_detonate(tp, lp); break; } if (lp1 != tail) continue; } /* * movement simulation */ if (sp && is_dead(sp, S_DEAD)) continue; if (sp) { x = sp->x; y = sp->y; warp = sp->warp; if (fabs(sp->newwarp) > sp->max_speed) sp->newwarp = (sp->newwarp > 0) ? sp->max_speed : -sp->max_speed; newwarp = sp->newwarp; course = sp->course; newcourse = sp->newcourse; target = sp->target; energy = sp->energy; /* * fuel consumption */ if (fabs(warp) > 1.0) fuel_use = (fabs(warp) * sp->eff * segment); else fuel_use = 0.; #ifdef TRACE /* if (trace) printf("*** Fuel use = %.2f, energy = %.2f\n", fuel_use, energy); */ #endif if (fuel_use > energy) { if (!shutup[BURNOUT + sp->id] && !(is_dead(sp, S_WARP)) && cansee(sp)) { printf("%s's warp drive burning out.\n", sp->name); shutup[BURNOUT + sp->id]++; } newwarp = (warp < 0.0) ? -0.99 : 0.99; energy = 0; } else energy -= fuel_use; } else { x = tp->x; y = tp->y; warp = tp->speed; newwarp = tp->newspeed; course = tp->course; newcourse = course; target = tp->target; } /* * destroyed warp drive */ if (sp && (is_dead(sp, S_WARP))) if (fabs(warp) > 1.0) newwarp = (warp < 0.0) ? -0.99 : 0.99; /* * automatic pilot */ if (target != NULL) if (sp && (is_dead(target, S_DEAD))) { if ((sp == fed) && !shutup[DISENGAGE] && !is_dead(sp, S_DEAD)) { printf("%s's autopilot disengaging.\n", sp->name); shutup[DISENGAGE]++; } newcourse = course; target = NULL; sp->relbear = 0.0; } else { if (cantsee(target)) j =bearing(x,target->position.x, y, target->position.y); else j = bearing(x, target->x, y, target->y); if (sp) j = rectify(j - sp->relbear); newcourse = j; } /* * turn rate (known to be a ship) */ if (tp) course = newcourse; if (sp && course != newcourse) { j = rectify(newcourse - course); if (j > 180) j -= 360; /* * maximum degrees turned in one turn */ k = ((sp->max_speed + 2.0 - warp) * sp->deg_turn * segment); /* If you have no warp drive, you're less * maneuverable */ if (is_dead(sp, S_WARP)) k /= 2; k = course + (j < 0.0 ? -1.0 : 1.0) * min(fabs(j), k); course = rectify(k); } /* * acceleration */ tmpf = newwarp - warp; d0 = fabs(tmpf); warp += ((tmpf < 0.0) ? -1 : 1) * sqrt(d0) * segment; d0 = toradians(course); x += (int) (warp * cos(d0) * Mpersegment); y += (int) (warp * sin(d0) * Mpersegment); /* * projected position (cloaked) */ if (sp && cantsee(sp)) { d0 = toradians(sp->position.course); sp->position.x += (sp->position.warp * cos(d0) * segment); sp->position.y += (sp->position.warp * sin(d0) * segment); } /* * reset all the vars */ if (sp) { sp->x = x; sp->y = y; sp->warp = warp; sp->newwarp = newwarp; /* XXXXX should these be rectified? */ sp->course = rectify(course); sp->newcourse = rectify(newcourse); sp->energy = energy; sp->target = target; } else { tp->x = x; tp->y = y; tp->speed = warp; tp->course = rectify(course); tp->target = target; } } } } check_targets() { register int i; register int j; struct ship *sp; struct ship *fed; struct ship *target; fed = shiplist[0]; for (i=0; i <= shipnum; i++) { /* Check targets */ sp = shiplist[i]; if (is_dead(sp, S_DEAD)) continue; target = sp->target; if (target && is_dead(target, S_DEAD)) { if ((sp == fed) && !shutup[DISENGAGE]) { puts(" helm lock disengaging"); shutup[DISENGAGE]++; } sp->target = NULL; sp->relbear = 0.0; } for (j=0; j<sp->num_phasers; j++) { target = sp->phasers[j].target; if (target && is_dead(target, S_DEAD)) { if ((sp == fed) && (!shutup[PHASERS+j]) && !(is_dead(sp, S_DEAD))) { printf(" phaser %d disengaging\n",j+1); shutup[PHASERS+j]++; } sp->phasers[j].target = NULL; } else if (target) sp->phasers[j].bearing = rectify(bearing(sp->x, (cantsee(target)) ? target->position.x : target->x, sp->y, (cantsee(target)) ? target->position.y : target->y) - sp->course); } for (j=0; j<sp->num_tubes; j++) { target = sp->tubes[j].target; if (target && is_dead(target, S_DEAD)) { if ((sp == fed) && (!shutup[TUBES+j]) && !(is_dead(sp, S_DEAD))) { printf(" tube %d disengaging\n", j+1); shutup[TUBES+j]++; } sp->tubes[j].target = NULL; } else if (target) sp->tubes[j].bearing = rectify(bearing(sp->x, (cantsee(target)) ? target->position.x : target->x, sp->y, (cantsee(target)) ? target->position.y : target->y) - sp->course); } } if (sp->cloak_delay > 0) sp->cloak_delay--; } misc_timers() { struct ship *fed; /* * self-destruct warning */ fed = shiplist[0]; if ((fed->delay < 1000.) && (fed->delay > 0.)) { if (is_dead(fed, S_COMP)) { printf("%s: Self-destruct has been aborted due to computer damage\n", science); fed->delay = 10000.; } else printf("Computer: %5.2f seconds to self destruct.\n", fed->delay); } fed->probe_status = PR_NORMAL; /* * Ruses, bluffs, surrenders */ if (defenseless) defenseless++; if (corbomite) corbomite++; if (surrender) surrender++; if (surrenderp) surrenderp++; } disposition() { struct ship *sp; struct ship *fed; struct ship *ep; int kills; int others; int fedstatus; register int i; register int j; register int k; /* * Federation dispostion */ fed = shiplist[0]; sp = fed; kills = others = fedstatus = 0; if (sp->complement <= 0 && !is_dead(sp, S_DEAD)) { sp->status[S_DEAD] = 100; sp->newwarp = 0.0; sp->newcourse = sp->course; sp->target = NULL; sp->relbear = 0.0; for (i = 0; i < sp->num_phasers; i++) { sp->phasers[i].target = NULL; sp->phasers[i].drain = MIN_PHASER_DRAIN; sp->phasers[i].status &= ~P_FIRING; } for (i = 0; i < sp->num_tubes; i++) { sp->tubes[i].target = NULL; sp->tubes[i].status &= ~T_FIRING; } for (i = 0; i < SHIELDS; i++) sp->shields[i].attemp_drain = 0.0; sp->regen = 0.0; sp->cloaking = C_NONE; } if (is_dead(sp, S_DEAD)) fedstatus = 1; else { for (i=0; i<sp->num_phasers; i++) if (!(sp->phasers[i].status & P_DAMAGED)) break; if (i == sp->num_phasers) { for (i=0; i<sp->num_tubes; i++) if (!(sp->tubes[i].status & T_DAMAGED)) break; if (i == sp->num_tubes) fedstatus = 1; } } /* * enemy disposition */ for (k=1; k <= shipnum; k++) { ep = shiplist[k]; if (ep->complement <= 0 && !is_dead(ep, S_DEAD)) { ep->status[S_DEAD] = 100; ep->newwarp = 0.0; ep->newcourse = ep->course; ep->target = NULL; ep->relbear = 0.0; for (i = 0; i < ep->num_phasers; i++) { ep->phasers[i].target = NULL; ep->phasers[i].drain = MIN_PHASER_DRAIN; ep->phasers[i].status &= ~P_FIRING; } for (i = 0; i < ep->num_tubes; i++) { ep->tubes[i].target = NULL; ep->tubes[i].status &= ~T_FIRING; } for (i = 0; i < SHIELDS; i++) ep->shields[i].attemp_drain = 0.0; ep->regen = 0.0; ep->cloaking = C_NONE; } if (is_dead(ep, S_DEAD)) { kills++; continue; } if (fedstatus) continue; j = rangefind(sp->x, ep->x, sp->y, ep->y); if ((j>3500 && is_dead(ep, S_WARP)) || (j>4500 && ep->delay<10.)) { others++; continue; } /* Check if we are within range to turn off the flag */ if ((j <= 3500) && (reengaged)) reengaged = 0; if (ep->energy > 10) continue; for (i=0; i<ep->num_phasers; i++) if (!(ep->phasers[i].status & P_DAMAGED)) break; if (i != ep->num_phasers) continue; for (i=0; i<ep->num_tubes; i++) if (!(ep->tubes[i].status & T_DAMAGED)) break; if (i != ep->num_tubes) continue; kills++; } if (!fedstatus && (global & E_SURRENDER)) /* enemy surrender */ if (leftovers()) (void) warn(FIN_E_SURRENDER); else (void) final(FIN_E_SURRENDER); if ((is_dead(fed, S_SURRENDER)) && (kills + others < shipnum)) if (leftovers()) /* federation surrender */ (void) warn(FIN_F_SURRENDER); else (void) final(FIN_F_SURRENDER); if (!fedstatus && (kills + others) < shipnum) /* play continues */ return 0; if (fedstatus && kills < shipnum) /* Fed. defeated */ if (leftovers()) (void) warn(FIN_F_LOSE); else (void) final(FIN_F_LOSE); if (!fedstatus && kills == shipnum) /* Fed. victory */ if (leftovers()) (void) warn(FIN_E_LOSE); else (void) final(FIN_E_LOSE); if (!fedstatus && (kills + others) == shipnum) /* outmaneuvered */ if (leftovers()) (void) warn(FIN_TACTICAL); else (void) final(FIN_TACTICAL); if (fedstatus && kills == shipnum) (void) final(FIN_COMPLETE); /* both sides dead */ return 0; } SHAR_EOF chmod +x 'moveships.c' fi # end of overwriting check if test -f 'parseopts.c' then echo shar: will not over-write existing file "'parseopts.c'" else cat << \SHAR_EOF > 'parseopts.c' /* * TREK73: parseopts.c * * Parse the environment variable TREK73OPTS and command line options * * parse_opts, get_comlineopts */ #include <ctype.h> #include <stdio.h> #include "externs.h" #include "options.h" #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) /* * description of an option and what to do with it */ struct optstruct { char *o_name; /* option name */ int *o_opt; /* pointer to thing to set */ int o_type /* Boolean or string */ }; typedef struct optstruct OPTION; OPTION optlist[] = { {"terse", (int *)&terse, BOOLEAN}, {"name", (int *)captain, STRING}, {"sex", (int *)sex, STRING}, {"science", (int *)science, STRING}, {"engineer", (int *)engineer, STRING}, {"com", (int *)com, STRING}, {"nav", (int *)nav, STRING}, {"helmsman", (int *)helmsman, STRING}, {"shipname", (int *)shipname, STRING}, {"enemy", (int *)racename, STRING}, {"foename", (int *)foename, STRING}, {"silly", (int *)&silly, BOOLEAN}, {"class", (int *)class, STRING}, {"foeclass", (int *)foeclass, STRING}, {"time", (int *)com_delay, STRING}, {"teletype", (int *)&teletype, BOOLEAN}, {"trace", (int *)&trace, BOOLEAN}, {"savefile", (int *)savefile, STRING} }; /* * parse_opts: * Parse options from string, usually taken from the environment. * The string is a series of comma separated values, with booleans * being stated as "name" (true) or "noname" (false), and strings * being "name=....", with the string being defined up to a comma * or the end of the entire option string. */ parse_opts(str) register char *str; { register char *sp; register OPTION *op; register int len; while (*str) { /* * Get option name */ for (sp = str; isascii(*sp) && isalpha(*sp); sp++) continue; len = sp - str; /* * Look it up and deal with it */ for (op = optlist; op < &optlist[NUM_OPTS]; op++) if (EQSTR(str, op->o_name, len)) { if (op->o_type == BOOLEAN) /* if option is a boolean */ *op->o_opt = 1; else /* string option */ { register char *start; /* * Skip to start of string value */ for (str = sp + 1; *str == '='; str++) continue; start = (char *) op->o_opt; /* * Skip to end of string value */ for (sp = str + 1; *sp && *sp != ','; sp++) continue; strucpy(start, str, sp - str); } break; } /* * check for "noname" for booleans */ else if (op->o_type == BOOLEAN && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) { *op->o_opt = 0; break; } /* * skip to start of next option name */ while (*sp && !(isascii(*sp) && isalpha(*sp))) sp++; str = sp; } } /* * strucpy: * Copy string using unctrl for things */ strucpy(s1, s2, len) register char *s1, *s2; register int len; { if (len > 100) len = 100; while (len--) { if (isascii(*s2) && isprint(*s2)) *s1++ = *s2; s2++; } *s1 = '\0'; } get_comlineopts(argc, argv) int argc; char *argv[]; { int c; char *opts = "Rtc:s:S:E:C:N:H:f:r:d:yTn:F:l:v"; int errflg = 0; while ((c = getopt(argc, argv, opts)) != EOF) { switch(c) { case 'R': restart = 1; break; case 't': terse = 1; break; case 'c': (void) strncpy(captain, optarg, sizeof captain); captain[sizeof captain - 1] = '\0'; break; case 's': (void) strncpy(sex, optarg, sizeof sex); sex[sizeof sex - 1] = '\0'; break; case 'S': (void) strncpy(science, optarg, sizeof science); science[sizeof science - 1] = '\0'; break; case 'E': (void) strncpy(engineer, optarg, sizeof engineer); engineer[sizeof engineer - 1] = '\0'; break; case 'C': (void) strncpy(com, optarg, sizeof com); com[sizeof com - 1] = '\0'; break; case 'N': (void) strncpy(nav, optarg, sizeof nav); nav[sizeof nav - 1] = '\0'; break; case 'H': (void) strncpy(helmsman, optarg, sizeof helmsman); helmsman[sizeof helmsman - 1] = '\0'; break; case 'f': (void) strncpy(foename, optarg, sizeof foename); foename[sizeof foename - 1] = '\0'; break; case 'r': (void) strncpy(racename, optarg, sizeof racename); racename[sizeof racename - 1] = '\0'; break; case 'd': (void) strncpy(com_delay, optarg, sizeof com_delay); com_delay[sizeof com_delay - 1] = '\0'; break; case 'y': silly = 1; break; case 'T': teletype = 1; break; case 'n': (void) strncpy(shipname, optarg, sizeof shipname); shipname[sizeof shipname - 1] = '\0'; break; case 'F': (void) strncpy(foeclass, optarg, sizeof foeclass); foeclass[sizeof foeclass - 1] = '\0'; break; case 'l': (void) strncpy(class, optarg, sizeof class); class[sizeof class - 1] = '\0'; break; case 'v': trace = TR_ON; break; case '?': default: errflg++; break; } } if (errflg) { fprintf(stderr, "Usage: trek73 [-t] [-c captain's name] [-s sex] [-S science officer]\n [-E engineer] [-C communications officer] [-N navigator] [-H helmsman]\n"); fprintf(stderr, " [-f enemy captain] [-r enemy race] [-d command delay time] [-y] [-T] \n [-n shipname] [-F enemy ship type] [-l federation ship type] [-v]\n"); fprintf(stderr, " or trek73 -R"); exit(1); } } SHAR_EOF chmod +x 'parseopts.c' fi # end of overwriting check if test -f 'parsit.c' then echo shar: will not over-write existing file "'parsit.c'" else cat << \SHAR_EOF > 'parsit.c' /* * TREK73: parsit.c * * Parse and get input * * Gets, parsit (courtesy, P. Lapsley) * */ #include <stdio.h> extern void free(); extern char *gets(), *malloc(), *strcpy(), *index(); static int gindex; static char **argv; char * Gets(buf, len) char *buf; int len; { register char *tmp; if (argv[gindex] == NULL) { (void) fgets(buf, len, stdin); if (tmp = index(buf, '\n')) *tmp = '\0'; return(buf); } ++gindex; if (argv[gindex] == NULL) { (void) fgets(buf, len, stdin); if (tmp = index(buf, '\n')) *tmp = '\0'; return (buf); } (void) strcpy (buf, argv[gindex]); puts (buf); return (buf); } /* ** parsit.c 23 September 1984 P. Lapsley (phil@Berkeley.ARPA) ** ** Parse a string of words separated by spaces into an ** array of pointers to characters, just like good ol' argv[] ** and argc. ** ** Usage: ** ** char line[132]; ** char **argv; ** int argc; ** ** argv = (char **) NULL; ** argc = parsit(line, &argv); ** ** returns the number of words parsed in argc. argv[argc] will ** be (char *) NULL to indicate end of list, if you're not ** happy with just knowing how many words you have. ** ** Note that setting argv = (char **) NULL is only done the first ** time the routine is called with a new "argv" -- it tells ** parsit that "argv" is a new array, and parsit shouldn't free ** up the elements (as it would do if it were an old array). */ parsit(line, array) char *line; char ***array; { char *malloc(); char word[132]; char *linecp; int i, j, num_words; gindex = 0; argv = *array; if (argv != (char **) NULL) { /* Check to see if we should */ i = 0; /* free up the old array */ do { free(argv[i]); /* If so, free each member */ } while (argv[i++] != (char *) NULL); free((char *)argv); /* and then free the ptr itself */ } linecp = line; num_words = 0; while (1) { /* count words in input */ for (; *linecp == ' ' || *linecp == '\t'; ++linecp) ; if (*linecp == '\0') break; for (; *linecp != ' ' && *linecp != '\t' && *linecp != '\0'; ++linecp) ; ++num_words; if (*linecp == '\0') break; } /* Then malloc enough for that many words plus 1 (for null) */ if ((argv = (char **) malloc((unsigned)((num_words + 1) * sizeof(char *)))) == (char **) NULL) { fprintf(stderr, "parsit: malloc out of space!\n"); return(0); } j = i = 0; while (1) { /* Now build the list of words */ for (; *line == ' ' || *line == '\t'; ++line) ; if (*line == '\0') break; i = 0; for (; *line != ' ' && *line != '\t' && *line != '\0'; ++line) word[i++] = *line; word[i] = '\0'; argv[j] = malloc(strlen(word) + 1); if (argv[j] == (char *) NULL) { fprintf(stderr, "parsit: malloc out of space!\n"); return(0); } (void) strcpy(argv[j], word); ++j; if (*line == '\0') break; } argv[j] = (char *) NULL; /* remember null at end of list */ *array = argv; return(j); } SHAR_EOF chmod +x 'parsit.c' fi # end of overwriting check if test -f 'save.c' then echo shar: will not over-write existing file "'save.c'" else cat << \SHAR_EOF > 'save.c' /* * TREK73: save.c * * save and restore routines * * @(#)save.c 4.15 (Berkeley) 5/10/82 */ #include <stdio.h> #include <pwd.h> #include <sys/types.h> #include <sys/stat.h> #include <signal.h> #include <stdio.h> #define MAXSTR 256 typedef struct stat STAT; extern char *sys_errlist[], version[], encstr[]; extern int errno; char *sbrk(); STAT sbuf; set_save() { register char *env; register struct passwd *pw; char *getpass(); extern char home[]; extern char savefile[]; char *getenv(); if ((env = getenv("HOME")) != NULL) strcpy(home, env); else if ((pw = getpwuid(getuid())) != NULL) strcpy(home, pw->pw_dir); else home[0] = '\0'; strcat(home, "/"); strcpy(savefile, home); strcat(savefile, "trek73.save"); } /* * save_game: * Implement the "save game" command */ save_game() { register FILE *savef; register int c; char buf[MAXSTR]; extern char savefile[]; /* * get file name */ over: if (savefile[0] != '\0') { for (;;) { printf("Save file (%s)? ", savefile); c = getchar(); if (c == 'n' || c == 'N' || c == 'y' || c == 'Y') break; else printf("\nPlease answer Yes or No"); } if (c == 'y' || c == 'Y') { strcpy(buf, savefile); goto gotfile; } } do { stdin->_cnt = 0; printf("File name: "); buf[0] = '\0'; gets(buf); gotfile: /* * test to see if the file exists */ if (stat(buf, &sbuf) >= 0) { for (;;) { stdin->_cnt = 0; printf("\nFile exists. Do you wish to overwrite it?"); if (c == 'y' || c == 'Y') break; else if (c == 'n' || c == 'N') goto over; else printf("\nPlease answer Y or N"); } } strcpy(savefile, buf); if ((savef = fopen(savefile, "w")) == NULL) perror("Trek73: Save problems"); } while (savef == NULL); /* * write out encrpyted file (after a stat) * The fwrite is to force allocation of the buffer before the write */ save_file(savef); exit(0); } /* * save_file: * Write the saved game on the file */ save_file(savef) register FILE *savef; { /* * close any open score file */ fstat(fileno(savef), &sbuf); /* * DO NOT DELETE. This forces stdio to allocate the output buffer * so that malloc doesn't get confused on restart */ fwrite("junk", 1, 5, savef); fseek(savef, 0L, 0); encwrite(version, sbrk(0) - version, savef); fclose(savef); exit(0); } /* * restore: * Restore a saved game from a file with elaborate checks for file * integrity from cheaters */ restore(file, envp) register char *file; char **envp; { register int inf, (*func)(); register char syml; extern char **environ; char buf[MAXSTR]; STAT sbuf2; func = signal(SIGTSTP, SIG_IGN); if ((inf = open(file, 0)) < 0) { perror(file); return 0; } fstat(inf, &sbuf2); syml = symlink(file); if ( unlink(file) < 0) { printf("Cannot unlink file\n"); return 0; } fflush(stdout); encread(buf, (unsigned int) (strlen(version) + 1), inf); if (strcmp(buf, version) != 0) { printf("Sorry, saved game is out of date.\n"); return 0; } fflush(stdout); brk(version + sbuf2.st_size); lseek(inf, 0L, 0); encread(version, (unsigned int) sbuf2.st_size, inf); /* * we do not close the file so that we will have a hold of the * inode for as long as possible */ if (sbuf2.st_ino != sbuf.st_ino || sbuf2.st_dev != sbuf.st_dev) { printf("Sorry, saved game is not in the same file.\n"); return 0; } #ifdef NOTDEF /* * defeat multiple restarting from the same place */ if (sbuf2.st_nlink != 1 || syml) { printf("Cannot restore from a linked file %d %d\n", sbuf2.st_nlink, syml); return 0; } #endif signal(SIGTSTP, SIG_DFL); environ = envp; stdin->_cnt = 0; playit(); /*NOTREACHED*/ } /* * encwrite: * Perform an encrypted write */ encwrite(start, size, outf) register char *start; unsigned int size; register FILE *outf; { register char *ep; ep = encstr; while (size--) { putc(*start++ ^ *ep++, outf); if (*ep == '\0') ep = encstr; } } /* * encread: * Perform an encrypted read */ encread(start, size, inf) register char *start; unsigned int size; register int inf; { register char *ep; register int read_size; if ((read_size = read(inf, start, size)) == -1 || read_size == 0) return read_size; ep = encstr; while (size--) { *start++ ^= *ep++; if (*ep == '\0') ep = encstr; } return read_size; } SHAR_EOF chmod +x 'save.c' fi # end of overwriting check if test -f 'ships.c' then echo shar: will not over-write existing file "'ships.c'" else cat << \SHAR_EOF > 'ships.c' /* * TREK73: ships.c * * Global Ship Defs for TREK73 * */ #include "externs.h" /* * starting stats for the ships depending on the type */ struct ship_stat stats[] = { { "DN", 0, 6, 8, 8, 10, 2., 1.5, 15., 200, 300, 600, 450, 5., 4., 2, 4, 135, 225, 125, 235, 4, 4}, { "CA", 1, 4, 6, 9, 11, 1., 0.75, 10., 150, 200, 450, 350, 3., 2., 5, 2, 135, 225, 125, 235, 4, 4}, { "CL", 2, 4, 4, 9, 11, 0.75, 0.5, 10., 125, 175, 350, 250, 3., 2., 6, 2, 150, 210, 140, 220, 4, 4}, { "DD", 3, 2, 4, 10, 12, 0.5, 0.5, 8., 100, 150, 200, 150, 2., 1.5, 7, 1, 160, 200, 150, 210, 4, 4} }; SHAR_EOF chmod +x 'ships.c' fi # end of overwriting check if test -f 'special.c' then echo shar: will not over-write existing file "'special.c'" else cat << \SHAR_EOF > 'special.c' /* * TREK73: special.c * * special: Take care of special commands like defenseless ruses, * corbomite bluffs, surrenders (both sides) * */ #include "externs.h" special(sp, range, fed) struct ship *sp; int range; struct ship *fed; { int loop, loop2, loop3; /* * Play dead effects */ switch (defenseless) { case 1: /* Monty Pythons? */ if (aliens[enemynum].defenseless == -1) aliens[enemynum].defenseless = randm(100); if (randm(100) > aliens[enemynum].defenseless) { /* Didn't work. Too bad. */ if (cansee(sp)) { printf("%s: No apparent change in the enemy's actions.\n", helmsman); } defenseless = 6; break; } defenseless = 2; case 2: case 3: /* Okay, he's fallen for it. Choose his action */ if (randm(2) == 1) { sp->target = NULL; sp->newwarp = 0.0; } else { sp->newwarp = 1.0; } if (cansee(sp)) { printf("%s: The %s is ", helmsman, sp->name); if (sp->target != NULL) { puts("cautiously advancing."); } else { puts("turning away."); } } case 4: case 5: /* * Now he might get suspicious. If he's moving too * fast or if we're close enough, or if his shields * are up, we'll spot him. */ if ((fabs(sp->target->warp) > 1.0) || (range < 200)) defenseless = 6; else for (loop = 0; loop < SHIELDS; loop++) if (sp->target->shields[loop].drain) defenseless = 6; } /* * Corbomite bluff effects. */ switch (corbomite) { case 1: /* Monty Pythons? */ if (aliens[enemynum].corbomite == -1) aliens[enemynum].corbomite = randm(100); if (randm(100) > aliens[enemynum].corbomite) { /* He didn't fall for it */ printf("%s: Message coming in from the %ss.\n", com, foerace); printf("%s: Put it on audio.\n", captain); if (randm(2) == 1) printf ("%s: Ha, ha, ha, %s. You lose.\n", foename, captain); else printf("%s: I fell for that the last time we met, idiot!\n", foename); corbomite = 6; break; } if (cansee(sp)) { printf("%s: %ss giving ground, Captain. Obviously they\n", science, foerace); puts(" tapped in as you expected them to."); printf("%s: A logical assumption, Mr. %s. Are they still\n", captain, science); puts(" retreating?"); printf("%s: Yes, %s\n", science, title); printf("%s: Good. All hands, stand by.\n", captain); } corbomite = 2; case 2: /* He fell for it, retrograde out of here! */ sp->target = NULL; sp->newwarp = -(3.0 + randm(7)); break; case 3: case 4: case 5: /* Begin to get suspicious */ if (fabs(sp->target->warp) > 2.0) corbomite = 6; break; } /* * Will the enemy accept your surrender? */ switch (surrender) { case 1: /* Monty Python */ if (aliens[enemynum].surrender == -1) aliens[enemynum].surrender = randm(100); /* Just a little reminder */ if (aliens[enemynum].surrender <= 10) printf("%s: The %ss do not take prisoners.\n", nav, foerace); if (randm(100) > aliens[enemynum].surrender) { /* Tough luck */ if (randm(2) == 1) { printf("%s: Message coming in from the %ss.\n", com, foerace); printf("%s: Put it on audio.\n", captain); printf("%s: Prepare to die, Chicken %s!\n", foename, captain); } else printf("%s: No reply from the %ss", com, foerace); surrender = 6; break; } /* He took it! */ printf("%s: Message coming in from the %ss.\n", com, foerace); printf("%s: Put it on audio.\n", captain); printf("%s: On behalf of the %s %s, I accept your surrender.\n", foename, foerace, empire); puts(" You have five seconds to drop your shields, cut"); puts(" warp, and prepare to be boarded."); global |= F_SURRENDER; case 2: case 3: if (surrender == 1) surrender = 2; else (void) warn(FIN_F_SURRENDER); sp->target = fed; sp->newwarp = sp->max_speed; (void) e_cloak_off(sp, fed); break; case 4: case 5: /* Begin checking surrender conditions */ for (loop = 0; loop < SHIELDS; loop++) if (sp->target->shields[loop].drain) break; if (loop < SHIELDS) break; if (range <= 1400) sp->newwarp = 1.0; if ((range <= 1000) && (fabs(sp->target->warp) <= 1.0)) { fed->status[S_SURRENDER] = 100; final(FIN_F_SURRENDER); } if (surrender == 4) break; if (!shutup[SURRENDER]) printf("%s: Captain %s, you have not fulfilled our terms.\n", foename, captain); printf(" We are resuming our attack.\n"); surrender = 6; shutup[SURRENDER]++; default: global &= ~F_SURRENDER; break; } /* * Enemy surrenders? */ switch (surrenderp) { case 1: for (loop = 1; loop <= shipnum; loop++) if (!is_dead(shiplist[loop], S_ENG) && (sp->complement > 100)) { printf("%s: Message coming in from the %ss.\n", com, foerace); printf("%s: Put it on audio.\n", captain); printf("%s: You must be joking, Captain %s.\n", foename, captain); puts(" Why don't you surrender?"); surrenderp = 6; break; } if (loop <= shipnum) break; /* Monty Python */ if (aliens[enemynum].surrenderp == -1) aliens[enemynum].surrenderp = randm(100); if (randm(100) > aliens[enemynum].surrenderp) { printf("%s: I'll never surrender to you, %s\n", foename, captain); surrenderp = 6; break; } printf("%s: As much as I hate to, Captain %s, we will surrender.\n", foename, captain); puts(" We are dropping shields. You may board us."); case 2: case 3: if (surrenderp == 1) surrenderp = 2; else (void) warn(FIN_E_SURRENDER); for (loop = 0; loop < SHIELDS; loop++) sp->shields[loop].attemp_drain = 0.0; sp->newwarp = 0.0; for (loop = 1; loop <= shipnum; loop++) shiplist[loop]->status[S_SURRENDER] = 100; global |= E_SURRENDER; break; } /* * Unsportsmanlike firing */ if (betw(defenseless, 0, 6) || betw(corbomite, 0, 6) || betw(surrender, 0, 6) || betw(surrenderp, 0, 6)) { for (loop = 0; loop < fed->num_phasers; loop++) if (fed->phasers[loop].status & P_FIRING) break; for (loop2 = 0; loop2 < fed->num_tubes; loop2++) if (fed->tubes[loop].status & T_FIRING) break; loop3 = (fed->probe_status != PR_NORMAL); /* Has he fired? */ if ((loop != fed->num_phasers) || (loop2 != fed->num_tubes) || (loop3 == 1)) { /* Yes, be angry and disbelieve everything from now on */ printf("%s: How dare you fire on us! We are resuming our attack!\n", foename); global = NORMAL; if (betw(defenseless,0,6)) defenseless = 6; if (betw(corbomite,0,6)) corbomite = 6; if (betw(surrender,0,6)) surrender = 6; if (betw(surrenderp,0,6)) surrenderp = 6; for (loop = 0; loop <= shipnum; loop++) shiplist[loop]->status[S_SURRENDER] = 0; } } } SHAR_EOF chmod +x 'special.c' fi # end of overwriting check if test -f 'strat1.c' then echo shar: will not over-write existing file "'strat1.c'" else cat << \SHAR_EOF > 'strat1.c' /* * TREK73: strat1.c * * Standard Enemy Strategy * * standard_strategy * */ #include "externs.h" standard_strategy(sp) struct ship *sp; { register struct ship *fed; float bear; int range; float tmpf; fed = shiplist[0]; if (is_dead(sp, S_DEAD)) return; range = rangefind(sp->x, fed->x, sp->y, fed->y); bear = bearing(sp->x, fed->x, sp->y, fed->y); bear = rectify(bear - sp->course); /* * Handle special requests */ special(sp, range, fed); /* * Now check for surrendering flags */ if ((global & F_SURRENDER) || (global & E_SURRENDER)) return; /* * Always turn on cloaking device if we have it and if we * can afford it */ if ((sp->cloaking == C_OFF) && (sp->energy >= 20) && e_cloak_on(sp, fed)) return; /* * Check for hostile antimatter devices */ if ((sp->cloaking == C_OFF) && e_closetorps(sp, fed)) return; if ((sp->cloaking == C_OFF) && e_checkprobe(sp)) return; /* * If cloaking is on, and we're running low on energy, * drop the cloak */ /* XXXX May want to change number */ if ((sp->cloaking == C_ON) && (sp->energy < 30) && e_cloak_off(sp, fed)) return; /* * Short range? */ if (range < 1050) { if (e_checkarms(sp) < randm((int)(sp->num_phasers+ sp->num_tubes)/3)) { if (!e_cloak_on(sp, fed)) (void) e_runaway(sp, fed); return; } if (e_lockphasers(sp, fed)) return; if (e_phasers(sp, fed)) return; if (betw(bear, 90.0, 270.0)) { (void) e_pursue(sp, fed, 1.0); return; } if (e_launchprobe(sp, fed)) return; if (sp->pods< 20 && sp->regen < 4.0 && e_destruct(sp, fed)) return; /* * set course? */ tmpf = fabs(fed->warp); if (sp->target != fed || fabs(sp->warp) + tmpf > 2.0) { (void) e_pursue(sp, fed, tmpf); return; } if (e_cloak_on(sp, fed)) return; } if (range < 3800) { /* * Either medium range, or we can't figure out what * to do at short range */ if (e_locktubes(sp, fed)) return; if (sp->energy > 30 && sp->pods > 40 && e_loadtubes(sp)) return; if (e_torpedo(sp)) return; /* * should we run away; can we? */ if (e_checkarms(sp) < randm((int)(sp->num_phasers+ sp->num_tubes)/3)) { if (!e_cloak_on(sp, fed)) (void) e_runaway(sp, fed); return; } /* * Pursued from behind, low power: jettison engineering! */ if (betw(bear, 90.0, 270.0) && sp->energy < 10 && sp->regen < 4.0 && e_jettison(sp, fed)) return; /* * put in other junk later */ if (e_cloak_on(sp, fed)) return; } /* * Either distant range, or we can't figure out * what to do at medium range */ /* Warp drive dead and Federation destructing, run away! */ if (fed->delay < 15. && (is_dead(sp, S_WARP))) { (void) e_runaway(sp, fed); return; } /* * enemy in our blind area? make a quick turn. */ /* XXXX Should we check for blind spots? * or should we check for forward/aft */ if (betw(bear, sp->t_blind_left, sp->t_blind_right)) { (void) e_pursue(sp, fed, 1.0); return; } if (e_locktubes(sp, fed)) return; if (e_lockphasers(sp, fed)) return; /* * attack? */ /* tmpf = fabs(fed->warp); if (sp->target != fed || sp->warp + tmpf > 2.0) { (void) e_pursue(sp, fed, (int)tmpf + 2.0 + randm(2)); return; } */ if (e_attack(sp, fed)) return; if (sp->energy > 30 && sp->pods > 40 && e_loadtubes(sp)) return; if (e_cloak_on(sp, fed)) return; /* * gee, there's nothing that we want to do! */ if (cansee(sp)) printf("%s: We're being scanned by the %s\n", science, sp->name); } SHAR_EOF chmod +x 'strat1.c' fi # end of overwriting check if test -f 'subs.c' then echo shar: will not over-write existing file "'subs.c'" else cat << \SHAR_EOF > 'subs.c' /* * TREK73: subs.c * * Miscellaneous Subroutines * * ship_name, newitem, delitem, rangefind, bearing, phaser_hit, * torpedo_hit, antimatter_hit, round, rectify */ #include "externs.h" #include <math.h> #include <ctype.h> struct ship *ship_name(name) char *name; { register int i; register int j; register int len; if (isascii(*name) && islower(*name)) *name = toupper(*name); j = shipnum; len = strlen(name); for (i=1; i<=j; i++) { if (shiplist[i]->complement < 0) continue; if (!strncmp(name, shiplist[i]->name, len)) return shiplist[i]; } printf("%s: I am unable to find the %s\n", science, name); return NULL; } struct list *newitem(item) int item; { register struct list *new; register struct list *newtail; /* * if there's no "tail" node, make one (only happens at init) */ if (tail == NULL) { new = MKNODE(struct list, *, 1); if (new == (struct list *)NULL) { fprintf(stderr, "newitem: malloc failed\n"); exit(2); } new->back = &head; new->fwd = NULL; new->data.tp = NULL; head.fwd = new; tail = new; } new = tail; /* * now make the new tail node */ newtail = MKNODE(struct list, *, 1); if (newtail == (struct list *)NULL) { fprintf(stderr, "newitem: malloc failed\n"); exit(2); } newtail->back = new; newtail->fwd = NULL; newtail->data.tp = NULL; newtail->type = 0; tail = newtail; /* * link the old tail node to the new one */ new->type = item; new->fwd = newtail; return new; } int delitem(item) struct list *item; { register struct list *bp; register struct list *fp; bp = item->back; fp = item->fwd; if (item->data.tp != NULL) free((char *) item->data.tp); /* * re-arrange pointers on both the next and the previous * nodes; if no forward pointer, we were the tail so make * the bp the new tail node. */ if (fp != NULL) { bp->fwd = fp; fp->back = bp; } else { tail = bp; bp->fwd = NULL; } free((char *) item); } int rangefind(xfrom, xto, yfrom, yto) int xfrom; int xto; int yfrom; int yto; { register double x, y; x = xto - xfrom; y = yto - yfrom; if (x == 0.0 && y == 0.0) return 0; else return (int) hypot(x, y); } /* * This routine finds the bearing of (xto,yto) from (xfrom,yfrom) */ float bearing(xfrom, xto, yfrom, yto) int xfrom; int xto; int yfrom; int yto; { register double x, y; register float bear; x = xto - xfrom; y = yto - yfrom; if (x == 0.0 && y == 0.0) bear = 0.0; else bear = todegrees(atan2(y, x)); bear = rectify(bear); return bear; } int phaser_hit(sp, x, y, bank, true_bear) struct ship *sp; int x; int y; struct phaser *bank; float true_bear; { register int hit; int i; float spread; float bear; double d1; double d2; hit = 0; i = rangefind(sp->x, x, sp->y, y); if (i < MAX_PHASER_RANGE) { bear = bearing(sp->x, x, sp->y, y); spread = rectify(true_bear - bear); /* * Check if a target is within the phaser spread */ if (betw(spread, sp->p_spread, 360-spread)) return 0; d1 = 1.0 - (float)i/MAX_PHASER_RANGE; d2 = (float)bank->load * sqrt(d1) * sp->p_percent / 100; /* XXXX */ /* * This may have to be changed if phaser spread or maximum * phaser load is changed */ d2 = (float)bank->load * d2 * 45.0/(float)sp->p_spread * sp->p_percent / 100; hit = d2/10.0; } return hit; } int torpedo_hit(fuel, x, y, tx, ty) int fuel; int x; int y; int tx; int ty; { register int hit; int i; double d1; double d2; float f1; float f2; hit = 0; i = rangefind(x, tx, y, ty); f1 = fuel * HIT_PER_POD; f2 = fuel * PROX_PER_POD; if (i < f2) { d1 = 1.0 - (float)i/f2; d2 = (float)f1 * sqrt(d1); hit = d2; } return hit; } antimatter_hit(ptr, x, y, fuel) char *ptr; int x; int y; int fuel; { register struct list *lp; register int hit; int tarx, tary; int s; float bear; struct torpedo *tp; struct ship *sp; for (lp = &head; lp != tail; lp = lp->fwd) { if (lp->type == 0) continue; sp = NULL; tp = NULL; if (lp->type == I_SHIP) { sp = lp->data.sp; tarx = sp->x; tary = sp->y; } else { tp = lp->data.tp; tarx = tp->x; tary = tp->y; } if (sp == (struct ship *) ptr || tp == (struct torpedo *) ptr) continue; hit = torpedo_hit(fuel, x, y, tarx, tary); if (hit <= 0) continue; if (sp) { /* * Determine which shield is hit */ bear = rectify(bearing(tarx, x, tary, y) - sp->course); if (bear <= 45.0 || bear >= 315.0) s = 1; else if (bear <= 135.0) s = 2; else if (bear < 225.0) s = 3; else s = 4; (void) damage(hit, sp, s, &a_damage, D_ANTIMATTER); } else { if (tp->timedelay <= segment) continue; tp->timedelay = segment; switch (lp->type) { case I_TORPEDO: printf("hit on torpedo %d\n", tp->id); break; case I_PROBE: printf("hit on probe %d\n", tp->id); break; case I_ENG: printf("hit on %s engineering\n", tp->from->name); break; default: printf("hit on unknown item %d\n", tp->id); } } } } float round(x) float x; { return(floor(x + 0.5)); } float rectify(x) float x; { while (x < 0.0) { x += 360.0; } while (x >= 360.0){ x -= 360.0; } return x; } SHAR_EOF chmod +x 'subs.c' fi # end of overwriting check if test -f 'vers.c' then echo shar: will not over-write existing file "'vers.c'" else cat << \SHAR_EOF > 'vers.c' /* * TREK73: vers.c * * version */ vers() { extern char version[]; printf("%s\n", version); printf("Jeff Okamoto, Peter Yee, and Roger Noe\n"); return 1; } SHAR_EOF chmod +x 'vers.c' fi # end of overwriting check # End of shell archive exit 0
okamoto@ucbvax.UUCP (12/10/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # header # 00.t # 01.t # 02.t # 03.t # 04.t # 04.5.t # 05.t # 06.t # 07.t # 08dd.t # 08cl.t # This archive created: Wed Dec 10 09:01:52 1986 # By: Jeff Okamoto () export PATH; PATH=/bin:$PATH if test -f 'header' then echo shar: will not over-write existing file "'header'" else cat << \SHAR_EOF > 'header' .ND .ds CF - % - .ds CH .nr PO 0.5i .nr LL 6.5i .nr PD 0 SHAR_EOF chmod +x 'header' fi # end of overwriting check if test -f '00.t' then echo shar: will not over-write existing file "'00.t'" else cat << \SHAR_EOF > '00.t' .ND .ds CF - % - .ds LH STAR .ds CH .ds RH TREK .nr PO 0.5i .nr LL 6.5i .nr PD 0 .na .LP .FS (R) Star Trek is a registered trademark of Paramount Pictures. .FE .FS (TM) Star Fleet Battles is a trademark held jointly by Task Force Games and Amarillo Design Bureau. .FE .ce T R E K 7 3 .ce A Star Trek Battle Simulation .sp .PP Trek73 is a computer-simulated battle based on the famous Star Trek television series and the board game Star Fleet Battles. Via computer terminal, you can clash with enemy battle cruisers, such as Klingon D-7's and Romulan Sparrowhawks, and use the same strategies that Captain Kirk has used. Like Kirk, you control a Federation vessel similar to the Enterprise; a computer program directs the enemy. Victory can fall into several categories: .sp .PP Decisive Victory -- You completely destroy or cripple the attacking force. .sp .PP Tactical Victory -- You out-maneuver the enemy using high-speed escapes, corbomite bluffs, `play dead' tactics; or the enemy surrenders. .sp .PP Moral Victory -- You surrender or self-destruct and destroy each other. .sp .PP All distances are measured in megameters, one million meters (abbreviated `M'). Speed is expressed in `Warp Factors'. Each warp factor equals 100M per second.\** .FS Although technically incorrect, it does save the player from having to compute cube roots. .FE All angles are expressed in common degrees from zero to 360, measured counter-clockwise from the x-axis, similar to reading a protractor. Only two dimensions are used.\** .FS This saves the player from having to work out problems in spherical geometry. .FE .sp .PP Play is as follows: .sp .PP 1. You issue one of a number of commands (fire phasers, change course, launch antimatter pods, surrender, etc.) by typing the appropriate code number into the keyboard; .sp .PP 2. The enemy, under programmed instructions, issues a similar command; .sp .PP 3. Both your commands are executed (phasers are fired, probes are launched, damages are assessed, courses changed, etc.) while the vessels move through space; .sp .PP 4. Unless certain end-game conditions are met (you destroy the enemy, the enemy destroys you, your out-maneuver the enemy, you both destroy each other, or one party surrenders) the above steps are repeated. .sp .PP Appendix 1 depicts the Enterprise's power circuits. .sp .PP Appendix 2 displays certain weapon and shield angles. .sp .PP Appendix 3 lists certain weapon and vessel specifications. .sp .PP Appendix 4 lists initial deployment of resources. .sp .PP Appendix 5 contains the designer's notes. .sp 2 .LP .in 1i .ta .5i .nf CODE COMMAND ==== ======= .sp 1 Fire Phasers 2 Fire Photon Torpedos 3 Lock Phasers Onto Target 4 Lock Tubes Onto Target 5 Manually Rotate Phasers 6 Manually Rotate Tubes 7 *Phaser Status 8 *Tube Status 9 Load/Unload Torpedo Tubes 10 Launch Antimatter Probe .sp 11 Probe Control (Detonate, Redirect, Lock) 12 *Position Report 13 *Position Display 14 Pursue An Enemy Vessel 15 Run From An Enemy Vessel 16 Manually Change Course And Speed 17 *Damage Report 18 Scan Enemy (Damage Report Of Enemy) 19 Alter Power Distribution 20 Jettison Engineering .sp 21 Detonate Engineering 22 Alter Torpedo And Phaser Firing Parameters 23 Attempt Defenseless Ruse 24 Attempt Corbomite Bluff(s) 25 Surrender 26 Ask Enemy to Surrender 27 Initiate Self-Destruct Sequence 28 Abort Self-Destruct 29 *Survivors Report 30 *Print Version Number 31 *Reprints Above List .sp *Does Not Use A Turn .in 0 .fi .bp SHAR_EOF chmod +x '00.t' fi # end of overwriting check if test -f '01.t' then echo shar: will not over-write existing file "'01.t'" else cat << \SHAR_EOF > '01.t' .ce Detailed Descriptions of Each Command .sp .PP What follows is a detailed description of each command. Each command is referred to by a number from 1 to 31. After the name of the command is given, a synopsis of the arguments the command requires is given, if any. These arguments can be entered on the command line, separated by whitespace, if you wish. For instance, to fire phasers 1 through 4 with a spread of 15, you could type '1 1234 15' on the command line. .PP It should be noted that all numbers refer to parameters for the Heavy Cruiser Class ship, and that other ships have slightly different characteristics. .sp .LP 1. Fire Phasers. .PP [Phasers | all] [Spread] .PP Phasers are pure energy units which emit a beam similar to lasers, but of a pulsating nature which can be `phased' to interfere with the wave pattern of any molecular form. Phasers get their power from phaser banks, which in turn, derive their power from the ship's engines. Each phaser bank is capable of holding a charge of 10 units. When firing, these banks discharge, similar to batteries, to spread their destructive power through space. After discharging, these banks are then recharged by the engines. Each phaser can be set to automatically track a target or can be manually rotated. Unless engineering is jettisoned (code 21), phasers only fire from 0-125 and 235-360 degrees, relative to the ship's course. In other words, each vessel has a 110 degree blind side in back of it in which phasers cannot fire. If phasers fired into this blind side, they would destroy the ship's engineering section. .sp .PP The Captain also designates a wide or narrow phaser beam: a wide beam to disrupt many targets; a narrow beam to inflict maximum damage on a single target. The maximum spread of phasers is 45 degrees, the minimum is 10 degrees. The total beam width is twice the designated spread. .sp .PP The firing percentage of each bank is preset to 100. In other words, the bank fully discharges when firing. This can be changed, however, using code 22. .sp .PP The maximum range of phasers is 1000M; the maximum hit factor is 45 with a ten degree spread, 10 with a forty-five degree spread. Phaser hit factors are calculated by the following formula: .sp .ce hit = (bankunits)(firing%)sqrt(1-range/1000)(45/spread) .sp .PP Phasers fire in .2-second intervals starting with bank one. Phasers inflict heavy damage and casualties, but do not destroy shields as much as antimatter explosions do. .sp .PP A phaser is unable to fire if damaged, if firing into your blind side, or if completely discharged. .sp .LP 2. Fire Photon Torpedos. .PP [Tubes | all] .PP The Enterprise is equipped with six torpedo tubes, which, as phasers, can be set to automatically track a target or be manually rotated. Unless engineering is jettisoned, tubes only fire from 0-135 and 225-360 degrees. Each tube fires all its antimatter pods, which are temporarily held suspended in a magno-photon force field. Photon torpedos can be fired directly at an enemy, laid out as a mine field, or scattered in an attacker's path as depth charges. .sp .PP Tubes must be loaded (code 9) prior to firing. Normally, torpedos are launched at warp 12 in .2-second intervals, beginning with tube one. Photon torpedos have a proximity fuse of 200M. All of these values can be changed by using code 22. .sp .PP Torpedos must be launched with care since the antimatter pods which are fired can never be recovered. It is suggested that you not fire more than four torpedos at any one time, since a certain number of them do miss, or are destroyed by the enemy firing phasers at them. It is also suggested that you fire them at distant targets, beyond 1100M, to avoid the explosion radii of your own weapons. Hit factors resulting from antimatter explosions are calculated as follows: .sp .ce hit = 5(#podscontained)sqrt(1-range/(50(#podscontained))) .sp .PP The maximum hit factor of an antimatter device is five times the number of pods contained (in the case of torpedos, 50); its explosion radius is 50 time the number of pods contained (in the case of torpedos, 500). Antimatter explosions heavily weaken shields but do not damage equipment as much as phasers do. This formula also applies to vessels, engineering sections, and antimatter probe explosions. .sp .PP A photon torpedo's proximity fuse will not be activated by a cloaked ship. .sp .PP Tubes are unable to fire if damaged, if firing into your blind side, or if unloaded. .sp .LP 3. Lock Phasers. .PP [Phasers | all] [Target Name] .PP Phasers locked on an enemy vessel will automatically aim towards it. Although phasers may track a vessel which is in the firing blind side, they will not fire unless engineering is jettisoned. To fire at vessels in the blind spot, simply change course at least 55 degrees. Once a phaser is locked, it is not disengaged until the target is destroyed (in which case it is then rotated to zero degrees relative), relocked, manually overridden, or damaged. .sp .PP Phasers can not be locked onto cloaked enemy ships as they can not find the target. Phasers that were previously locked onto a non-cloaked ship will track the enemy's last known course and position when that ship cloaks. .sp .LP 4. Lock Tubes. .PP [Tubes | all] [Target Name] .PP Tubes lock and unlock in the same manner that phasers do. Tubes suffer the same locking limitations that phasers do in reference to cloaked ships. .sp .LP 5. Manually Rotate Phasers. .PP [Phasers | all] [Bearing] .PP Manually rotating phasers disengages any previous locks and positions them as directed, relative to your course. For example, if your course is 30, and phasers are rotated 45 degrees, they will hit a target bearing 75 degrees. Rotating phasers into you blind side is permissible, however, they will not fire. .sp .LP 6. Manually Rotate Tubes. .PP [Tubes | all] [Bearing] .PP Manually rotating tubes is similar to rotating phasers. .sp .LP 7. Phaser Status. .PP Phaser status reports the control (locks and damages), deployment, levels, firing percentages (normally 100), and charge/discharge rates (normally +10) of all phasers. This command does not use a turn. Cf. Command 22. .sp .LP 8. Tube Status. .PP Tube status reports the control, deployment, tube levels, launch speeds (normally 12), proximity delays (normally 200), and time delays (normally 10) of all tubes. This command does not use a turn. Cf. Command 22. .sp .LP 9. Load/Unload Tubes. .PP [l | u] [Tubes | all] .PP Each specified tube will be automatically loaded with 10 units or whatever remains in the engines, whichever is less. Tubes can also be unloaded if the need arises. .sp .LP 10. Launch Antimatter Probe. .PP [Pods] [Time] [Proximity] [Target | [<CR> Course]] .PP Probes are slow-moving devices equipped with internal guidance systems which allow them to chase an enemy vessel. Probes consist of at least ten antimatter pods which are launched from an undamaged probe launcher at warp three. As with torpedos, probes are set with time and proximity fuses, and use the same hit factor formula as do torpedos. SHAR_EOF chmod +x '01.t' fi # end of overwriting check if test -f '02.t' then echo shar: will not over-write existing file "'02.t'" else cat << \SHAR_EOF > '02.t' .sp .LP 11. Probe Control. .PP [y | [n [Probe] [y | [n [Target | [<CR> Course]]]]]] .PP Probe control allows you to detonate or redirect probes which may have missed. .sp .LP 12. Position Report. .PP Position reports are vital since valuable information on courses, bearings and ranges are given to aid the formation of good strategy. .PP Each ship is listed along with its current speed, course, and bearing. Also listed is your relative bearing to that ship. A relative bearing of 0 means you are pointed directly at the ship, whereas a relative bearing of 180 means you are pointed directly away from the ship. Next is the reverse relative bearing, which gives the relative bearing of you with respect to the ship listed. .PP Cloaked ships show up with an asterisk (*) before the name, and the information displayed is the last available information on those ships. If no position report has been performed prior to the enemy ship engages a cloaking device, no information will be available on that ship. This order does not use a turn. .sp .LP 13. Position Display. .PP [Radius of scan] .PP Position displays, similar to radar scans, show objects which surround your vessel. The Enterprise is indicated by a `+', jettisoned engineering sections by a `#', probes by a `*', torpedos by a `:', and enemy vessels by the first letter of their names. Enemy vessels that are cloaked appear as lower case letters and remain in their last noted absolute position. .sp .LP 14. Pursue An Enemy Vessel. .PP [Target Name] [Warp Factor] .PP This order instructs the ship's navigation to face an enemy vessel whenever possible. Obviously it is impossible to pursue a cloaked vessel. .sp .LP 15. Run From An Enemy Vessel. .PP [Target Name] [Warp Factor] .PP This order, just the opposite of order #14, instructs the navigation to keep the stern of the Enterprise towards an enemy vessel whenever possible. Running from a cloaked vessel is not very useful. .sp .LP 16. Manually Change Course and Speed. .PP [Course] [Warp Factor] .PP This order instructs navigation to maintain a fixed course and speed. The following information applies to the above three orders: .sp .PP Your maximum rotation rate when turning is: .ce degrees per sec = 5 * (11 - current warp speed) .sp .PP Accordingly, you can turn 55 degrees at warp one, 50 at warp two, and so on down to 10 degrees at warp nine. In other words, the faster your speed, the less maneuverable you are. You are also less maneuverable if your warp drive is damaged or destroyed. Your maximum speed is warp nine, the enemy's is warp eleven. .sp .LP 17. Damage Report. .PP This report informs you of certain equipment status. A destroyed computer make orders 3 (lock phasers), 4 (lock torpedos), 14 (pursue), 15 (run), 27 (initiate self-destruct), and 28 (abort self-destruct) impossible to execute. You will be required to manually rotate phasers and torpedos, and manually change course and speed. Destroyed sensors makes orders 13 (position display) and 18 (scan) impossible. A destroyed probe launcher prevents you from launching probes. A destroyed warp drive slows your maximum speed to warp 0.99 and severly limits your maneuverability. See order 20 about jettisoned engineering section. When your crew of 450 dies, your vessel is as good as dead. There are 350 men aboard each enemy vessel. .sp .PP All of the above systems can be partially damaged. A damaged warp drive (common) lowers your maximum speed and maneuverability. A damaged probe launcher (sometimes) may refuse to launch. Damaged sensors (rare) may not be able to return position displays or be able to scan an enemy. A damaged computer (very rare) will sometimes refuse to lock onto targets, and in addition, when damaged, may lose some of the locks held by the weapons or by the helm. .sp .PP Shield percentage is calculated by its energy drain times its operating efficiency. Efficiency starts at 100 and declines with each hit. No damages of any kind are incurred when a shield absorbs its first hit, no matter how great the hit. Shield one is 1.5 times as strong as the other three shields. .sp .PP `Efficiency' indicates the number of energy units being burned per warp-second. This number is initially one (.75 for enemy) and increases per hit. .sp .PP `Regeneration' indicates the number of energy units being gained per second. Initially set at 10, this number decreases per hit. .sp .PP `Fuel capacity' indicates the number of matter-antimatter pods a vessel has aboard. This number rapidly decreases with each torpedo or probe fired. .sp .PP `Fuel' indicates the number of matter-antimatter pods which are filled with energy. This number rapidly decreases when maintaining high warp speeds or firing phasers. .sp .LP 18. Scan Enemy (Damage Report of Enemy). .PP [Ship Name | Probe id | #Ship Name] .PP An enemy damage report is essentially the same as the Enterprise's. Sensor reports can not be had for cloaked vessels. .PP By giving the id number of a probe, information about it can be gathered. The same information can be gathered about a ship's (jettisoned) engineering by prepending a '#' before the ship's name. .sp .LP 19. Alter Power Distribution. .PP [Shld 1 drain [* | ... Sh 4]] [Phsr 1 drain [* | ... Ph 4]] .PP The synopsis of this command can be confusing. The first set of numbers gives the drains for each shield. All four shield drains can be specified, but if a star is used immediately after a shield drain (eg, 19 0.5 1*), then the remaining shields will all be given a drain equal to the number preceding the '*'. (Thus, in the above example, shield 1's drain is 0.5, whereas shields 2, 3, and 4 have a drain of 1). The same applies to the phaser drains. .sp .PP The power circuits of all vessels are illustrated in Appendix 2. Dilithium crystals produce energy much like generators. This power is then used to maintain warp speeds, recharge antimatter pods in the engine reserve, recharge phaser banks, or maintain shield power. Your initial regeneration is ten, however, the shields normally drain four units and the engines require one unit per each warp-second. .sp .PP Shields can be thought of as electromagnets. The more energy put into them, the stronger their force field becomes. Therefore, a shield's overall percentage is calculated by the following formula: .sp .ce shield percentage = (energy in)(effective %) .sp .PP Notice that dropping power to a shield has the same effect as having it hit. Notice also that if your regeneration drops below four, you may have to discharge your phaser banks to maintain full shield power. .sp .PP Phaser banks, similar to batteries, not only discharge (when firing), but also recharge. Initially, they are set to recharge fully in one second (+10) so that you can continually use them. However, they can discharge fully (-10) in one second to provide extra power to shields, warp engines, or engine reserve. .sp .PP Under most conditions, you need not concern yourself with power distribution unless some special need arises. Distribution, for the most part, is automatic. Regeneration is calculated first; that power is placed in reserve, along with any discharged phaser units. Shield drain is calculated next, then the cloaking device, then phaser and engine drains. .sp .PP Be concerned with wasting power by indiscriminately firing phasers and torpedos, maintaining speeds over warp three, or dumping scores of units onto antimatter probes. Huge power losses cannot be made up in battle. .sp .LP 20. Jettison Engineering. .PP Although this order was never executed in the television series, it is quite possible according to its producer. Jettisoning engineering has serious consequences, but it may be your only course of action. .sp .PP One would jettison engineering if being pursed by vessels, probes or torpedos, or as a suicidal gesture. .sp .PP The following things happen when engineering is jettisoned: A: You lose all your fuel and reserve capacity; B: you lose your regeneration; C: you lose your warp drive; D: your lose your probe launcher; E: you lose your shields until you designate phasers to discharge; F: the engineering section itself decelerates to a stop; G: a ten second time delay on it is set (hopefully, when it does explode, you are far from its effects); H: you lose your cloaking device; I: your phasers and torpedos are now free to fire in any direction. SHAR_EOF chmod +x '02.t' fi # end of overwriting check if test -f '03.t' then echo shar: will not over-write existing file "'03.t'" else cat << \SHAR_EOF > '03.t' .sp .LP 21. Detonate Engineering. .PP [nothing | [y | n]] .PP This order, issued after the previous one, manually detonates your engineering section. It may also be issued without the previous order, in which case you will be asked to confirm your (crazy) order. .sp .LP 22. Alter Torpedo And Phaser Firing Parameters. .PP [[y [Launch Speed] [Time Delay] [Proximity Fuse]] | n] [[y [Firing Percentage]] | n] .PP This option allows you to change the launch speeds, time and proximity delays of all torpedos. At the beginning of play, torpedos are launched at warp twelve, have ten second time fuses, and 200M proximity fuses. Any vessel or engineering section which comes within the proximity range will cause the torpedo to explode. .sp .PP Phaser firing percentages can also be altered. A phaser bank need not fire its full charge. .sp .LP 23. Defenseless Ruse. .PP [e | p] .PP Another name for this tactic is `playing dead'. When issued, your shields are dropped to zero, and power is diverted to your engines or phaser banks. Hopefully, the enemy will believe you dead and come too close or break off their attack. You should then be able to fire or run in the opposite direction. .sp .LP 24. Attempt Corbomite Bluff(s). .PP There were two corbomite bluffs in the television series; one was against a midget operating a huge space vessel the other was against Romulan attackers. Both have been incorporated into this game. Whichever bluff issued is selected randomly. .sp .LP 25. Surrender, If Possible. .PP This order sends a message to the enemy, saying that you wish to surrender. The enemy will then decide whether or not take you alive. You will have difficulty surrendering to Romulans, who have never accepted one. .sp .LP 26. Ask Enemy To Surrender. .PP This order ends a message to the enemy demanding that they surrender. Please bear in mind that Romulans and Orions are the most suicidal. .sp .LP 27. Initiate Self-Destruct. .PP This order activates a twenty-second self-destruct sequence. Because final destruct does not occur until ten turns after initialization, it is best to start it early, if at all. When you do explode, you hope that you explosive force will also destroy your attackers. .sp .LP 28. Abort Self-Destruct. .PP This order, issued after the previous one, halts the destruct sequence. Self-destruct cannot be aborted withing five seconds to detonation. .sp .LP 29. Survivors Report .PP This order prints out the number of survivors on board all the ships. This order does not use a turn. Cloaked ships are reported as having `???' survivors. .sp .LP 30. Print version number .PP This command, which does not use a turn, prints the current version of TREK73. .sp .LP 31. Save game .PP This command saves the current game into a file. It can be restarted later by using the command line option `-r'. .sp .LP 32. Reprint Above List. .PP This command, which does not use a turn, lists code numbers and associated descriptions of each. .sp .LP 33 And Up. .PP Future options, currently being designed in Trek74, will include Dr. Daystrom's paranoid, M5 multi-tronics computer which will take over while you relax; or battle someone else who is on another terminal; or battle in teams; or have a free-for-all against nine other players. .sp .bp SHAR_EOF chmod +x '03.t' fi # end of overwriting check if test -f '04.t' then echo shar: will not over-write existing file "'04.t'" else cat << \SHAR_EOF > '04.t' .ce Options .sp .PP In TREK73, all the names of crewmembers are taken from the Star Trek series. Through the use of options, the names, as well as other aspects of the game, can be changed to whatever you want. .sp .PP To use the options, you must add the variable TREK73OPTS to your environment. A sample would be (using the C-shell): .br .sp setenv TREK73OPTS 'name=Jerk, ship=Boobyprize, terse' .sp .PP The option string is a list of comma-separated options. Options are designated as either boolean or string options. Boolean options are turned on by typing their name and turned off by prepending 'no' to them. String options are set equal to the string which follows the "=". .sp .PP There follows a list of all the options, what type it is, and an explanation of what they mean. The default for the option is in square brackets following the option. .sp .IP "terse BOOLEAN [noterse]" This option, when set, turns off the information regarding the ship's purpose in the area. It thus reduces the amount of drek on the screen. If you are on a slow terminal, this is a nice option to have set. .sp .IP "shipname STRING [Enterprise]" This option names your ship. .sp .IP "name STRING" This option names the captain of the ship. If this option is not set, then the program will ask for a name. The captain is the one who must make all the decisions of strategy and tactics for the ship. .sp .IP "sex STRING" This option gives the captain a gender. If this option is not set, the program will ask for it's value. If you respond with something that starts with other than "m" or "f", beware! .sp .IP "science STRING [Spock]" This option names the science officer, who is responsible for checking the parameters of the captain's commands. It is also this officer's duty to report damage to the ship as well as scan for enemy damage. .sp .IP "engineer STRING [Scott]" This option names the chief engineer of the ship. It is this officer's duty to report on the status of the ship, especially its energy supply and distribution of the same. The officer also controls the launching of anti-matter probes. .sp .IP "helmsman STRING [Sulu]" This option names the ship's helmsman. This officer's duty is to control the speed of the ship and also controls the firing of the ship's weapons. .sp .IP "nav STRING [Chekov]" This option names the ship's navigator, who is responsible for the navigation of the ship. This officer makes changes to the ship's course as directed by the captain. This officer also controls any anti-matter probes after they have been launched. .sp .IP "com STRING [Uhura]" This option names the ship's communications officer. It is the duty of this officer to handle all communications between the ship and the rest of the universe. .sp .IP "enemy STRING [random]" If this option is set, it tells the program which race you wish to fight. The available races are: Klingon, Romulan, Kzinti, Gorn, Orion, Hydran, Lyran, or Tholian. If the option is not set, the race you will fight is chosen at random. .sp .IP "foename STRING [random]" If this option is set, it specifies the name of the commander of the enemy ship(s). If this option is not specified, the name is chosen at random. .sp .IP "class STRING [CA]" This option specifies the kind of ship you are commanding. Allowable classes are: DN, CA, CL, and DD, standing for dreadnought, heavy cruiser, light cruiser, and destroyer. In general, the larger the ship, the more weapons and stronger shields you have, at the cost of less speed and maneuverability. .sp .IP "foeclass STRING [CA]" This option specifies the kind of ship that you are fighting. The different classes are explained above. .sp .IP "silly BOOLEAN [nosilly]" If this option is set, an additional race is added to the list of possible races to fight. This race is the Monty Pythons. Note that if you wish to always fight the Monty Python's, you merely have to set the enemy option above. .sp .IP "time STRING [30]" Time is used to specify the time between commands. The longer this value, the more time may be used in issuing a command. .sp .IP "teletype BOOLEAN [noteletype]" The teletype option causes some of the output to come out as it did in the original teletype version. .sp .IP "savefile STRING [$HOME/trek73.save]" The savefile option specifies where the data image is to be stored if the game is saved during play. ``~'' is not expanded, so the path should be explicit and fully expanded. .sp 3 .ce Command Line Options .sp .PP In all cases, the arguments you place on the command line will supersede options in the environment. .sp .PP The following is a description of the command line options: .sp .IP \-t Turns on terse mode. No initial scenario description is given. This is useful for terminals running at low baud rates. This option is normally off. .sp .IP \-c Allows the specification of the Federation captain's name. .sp .IP \-s Specify the sex of the captain of the Federation vessel. .sp .IP \-S Specify the name of the Science Officer of the Federation vessel. .sp .IP \-E Specify the name of the Chief Engineer of the Federation vessel. .sp .IP \-C Specify the name of the Communications Officer of the Federation vessel. .sp .IP \-N Specify the name of the Navigator of the Federation vessel. .sp .IP \-H Specify the name of the Helmsman of the Federation vessel. .sp .IP \-f Specify the name of the enemy commanding officer. .sp .IP \-r Specify the race of the enemy. The race should be one of the following: Klingon, Romulan, Kzinti, Gorn, Hydran, Lyran, Tholian, Orion, or Monty Python. .sp .IP \-d Set the delay time for command entry. Higher times can be useful for novices or for playing on very slow terminals. .sp .IP \-y Silly option. Adds the Monty Pythons as a possible enemy race. This option is normally off. .sp .IP \-T Teletype option. Causes certain parts of the output to come out as they did on the original teletype implementation. Doesn't do much for the game on crts. This option is normally off. .sp .IP \-n Specify the name of the Federation vessel. The default name for the Federation vessel is randomly chosen from a set of names. .sp .IP \-F Specify the class of the enemy vessel(s). Allowable classes are Destroyer (DD), Light Cruiser (CL), Heavy Cruiser (CA), and Dreadnought (DN). If the argument is none of the above, the program assumes that this is the name of a file where a player-designed ship is stored. .sp .IP \-l Specify the class of the Federation vessel. Available classes are the same as the enemy's. .sp .IP \-R Restore the game from the savefile. It is assumed that the TREK73OPTS contains the name of the savefile, otherwise it is not possible to restart the game with the -R option. In case the savefile name is not in TREK73OPTS, the game may be restored by issuing the command with the path to the savefile as the first argument. .bp SHAR_EOF chmod +x '04.t' fi # end of overwriting check if test -f '04.5.t' then echo shar: will not over-write existing file "'04.5.t'" else cat << \SHAR_EOF > '04.5.t' .ce Designer Ships .sp .PP A feature of TREK73 allows you to have more than just the standard four ship types. The program .I shipyard (6) allows new ship types to be created. .I Shipyard in conjunction with the -F and/or -l command line option allows battle between, say, the Enterprise and the Death Star. .PP See the manual page for .I shipyard for more information about designer ships. SHAR_EOF fi # end of overwriting check if test -f '05.t' then echo shar: will not over-write existing file "'05.t'" else cat << \SHAR_EOF > '05.t' .ce Simple Strategy .sp .PP If you are a beginner, a simple strategy to follow is A: fight only one attacker; B: pursue him (code 14) at warp factor one; C: lock on all phasers (code 3); D: continuously take position reports (code 12) and watch his range; E: when he gets within 1000M, fire all phasers (code 1) and keep on firing when he is in range; F: When the enemy is out of range, take damage reports and scans of the enemy (codes 17 and 18). .sp .PP After a few trial games using the above strategy, you will want to become as efficient as the enemy at firing photon torpedos. Finally, when you master launching antimatter probes, you can designate more that one attacker. .sp 3 .ce Trek73's History .sp .PP Trek73 was programmed on a Hewlett-Packard 2000C system by William K. Char, Perry Lee, and Dan Gee. In January, 1973, Mr. Char started with a few ideas and five months later, in May, introduced $SPACE, his first version. .sp .PP Space had only 14 commands and comprised one 10K program. Response was so great that new ideas flooded in and in June, work on Trek73 was begun. Over 70 recordings of past shows were reviewed to reconstruct dialogue and vessels. On October 8, 1973, Trek73 was introduced. .sp .PP In 1984, Dave Pare at Univeristy of California at San Diego and Chris Williams at the University of California at Berkeley independently translated the BASIC code into C to run under BSD UNIX.\** .FS UNIX is a registered trademark of Bell Laboratories. .FE .sp .PP In April 1985, Jeff Okamoto and Peter Yee, both at the University of California at Berkeley combined the two versions into one, fixing bugs and adding new commands and concepts. .sp .PP Ideas and bug reports should be sent to: .br ARPA: okamoto@ucbvax.berkeley.edu and yee@ucbvaxberkeley.edu .br UUCP: ..!ucbvax!okamoto and ..!ucbvax!yee .bp SHAR_EOF chmod +x '05.t' fi # end of overwriting check if test -f '06.t' then echo shar: will not over-write existing file "'06.t'" else cat << \SHAR_EOF > '06.t' .ce APPENDIX 1 .nf .sp 4 Secondary Hull Primary Hull (engineering) ------- :-----------------------------------------\\ | .5 | . . . . :: N C C - 1 7 0 1 |} |0 / 1|---< . . . . . ::________________________________________/ | | . . . . warp engines ^ | .5 | . . . . +++ |0 / 1|---< . . . . . ===== | fuel | | . . . . |+| + OOOOO reserve | .5 | . . . . |+| ---------> +++ ---> OOOOO --- +++ ---> |0 / 1|---< . . . . . ------- + ***** | | . . . . | | ***** shield | .5 | . . . . ------- | \\ control |0 / 1|---< . . . . . dilithium * \\ ------- . . . . crystal *** +++ shields generator * \\phaser control | -------- : : : | |-10/10|-OOOO>. . : : : | : : <***: <[=====| <---+ |-10/10|-**OO>. . : : : : probe launcher | |-10/10|-****> V |-10/10|-****> =*******= -------- phaser banks photon =*******= torpedo ===******* tubes =======******* ========= ******* ========= ******* + Energy unit O Matter-anti-matter pod * Filled matter-anti-matter pod ---+++---> Energy transfer ---***---> Pod transfer .fi .bp SHAR_EOF chmod +x '06.t' fi # end of overwriting check if test -f '07.t' then echo shar: will not over-write existing file "'07.t'" else cat << \SHAR_EOF > '07.t' .ce APPENDIX 2 .br .ce Heavy Cruiser .nf .sp 7 Shield 2 | 135 90 \\\\,,,,,,,,''-``,,,,,,,, ,,''\\ .Phaser.Firing An``,, 45 ,' \\ \\125 gles`,/ ,' \\. . Torpedo. . `, :------------------------\\ \\135_-----_ Fir . , :________________________/ _- 1 -_ ing . ` | || / 0 \\ Angles . | Shield | ,_^^_____/| _ 7 | . . | Shield -180| [ { (o) 1 } . . |0- 3 | `-vv-----\\| - C | . . | 1 | || \\ C / . . | :-----------------------\\ -_ N _- . . , :_______________________/ -_____- . . ' `, /225. . . . . . . ,' `, / . ,' \\ ``,/ /235. . . . . . . . ,,'' 315 /`````````,,_,,'''''''' 225 270 | Shield 4 .fi .bp SHAR_EOF chmod +x '07.t' fi # end of overwriting check if test -f '08dd.t' then echo shar: will not over-write existing file "'08dd.t'" else cat << \SHAR_EOF > '08dd.t' .ce APPENDIX 3 .sp 2 .ce Weapon And Vessel Specifications .ce Destroyer Class Vessel .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i .ce Phasers Number of banks 2 Max range 1000 megameters Max spread 90 degrees (45+45) Min spread 20 degrees (10+10) Max hit with 45 degree spread 10 Max hit with 10 degree spread 45 Loss of shield 1 per hit hit/3 Loss of shields 2-3-4 per hit hit/2 Firing angles with engineering 0-150, 210-360 degrees Max charge per bank 10 units Min charge or discharge time 1 sec .sp .ce Tubes Number of tubes 4 Max range 12,000 megameters max launch speed warp 12 Max time delay 10 seconds Max proximity delay 500M Max explosion radius 500M Max number of pods launched 10 Max hit factor 50 Loss of shield 1 per hit hit/2.25 Loss of shields 2-3-4 per hit hit/1.5 Firing angles with engineering 0-160, 200-360 degrees .sp .ce Probes Number of probe launchers 1 Max range 3000M Max launch speed 2 Max time delay 15 sec Max proximity delay any Max explosion radius 50 times number of pods Max pods launched fuel available Max hit factor 10 times number of pods Loss of shields per hit same as torpedos Firing angles with engineering all .sp .ce Vessels Max turning rate 120 degrees Max speed warp 10 [12] Min units burned per warp-second .5 [.5] Crew 200 [150] .DE SHAR_EOF chmod +x '08dd.t' fi # end of overwriting check if test -f '08cl.t' then echo shar: will not over-write existing file "'08cl.t'" else cat << \SHAR_EOF > '08cl.t' .bp .ce Weapon And Vessel Specifications .ce Light Cruiser Class .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i .ce Phasers Number of banks 4 Max range 1000 megameters Max spread 90 degrees (45+45) Min spread 20 degrees (10+10) Max hit with 45 degree spread 10 Max hit with 10 degree spread 45 Loss of shield 1 per hit hit/4.5 Loss of shields 2-3-4 per hit hit/3 Firing angles with engineering 0-140, 220-360 degrees Max charge per bank 10 units Min charge or discharge time 1 sec .sp .ce Tubes Number of tubes 4 Max range 12,000 megameters max launch speed warp 12 Max time delay 10 seconds Max proximity delay 500M Max explosion radius 500M Max number of pods launched 10 Max hit factor 50 Loss of shield 1 per hit hit/3 Loss of shields 2-3-4 per hit hit/2 Firing angles with engineering 0-150, 210-360 degrees .sp .ce Probes Number of probe launchers 1 Max range 3000M Max launch speed 2 Max time delay 15 sec Max proximity delay any Max explosion radius 50 times number of pods Max pods launched fuel available Max hit factor 10 times number of pods Loss of shields per hit same as torpedos Firing angles with engineering all .sp .ce Vessels Max turning rate 77 degrees Max speed warp 9 [11] Min units burned per warp-second .75 [.5] Crew 350 [250] .DE SHAR_EOF chmod +x '08cl.t' fi # end of overwriting check # End of shell archive exit 0
okamoto@ucbvax.UUCP (12/10/86)
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # 08ca.t # 08dn.t # 09dd.t # 09cl.t # 09ca.t # 09dn.t # 10.t # trek73.6 # Makefile # This archive created: Wed Dec 10 09:02:01 1986 # By: Jeff Okamoto () export PATH; PATH=/bin:$PATH if test -f '08ca.t' then echo shar: will not over-write existing file "'08ca.t'" else cat << \SHAR_EOF > '08ca.t' .bp .ce Weapon And Vessel Specifications .ce Heavy Cruiser Class .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i .ce Phasers Number of banks 4 Max range 1000 megameters Max spread 90 degrees (45+45) Min spread 20 degrees (10+10) Max hit with 45 degree spread 10 Max hit with 10 degree spread 45 Loss of shield 1 per hit hit/4.5 Loss of shields 2-3-4 per hit hit/3 Firing angles with engineering 0-125, 235-360 degrees Max charge per bank 10 units Min charge or discharge time 1 sec .sp .ce Tubes Number of tubes 6 Max range 12,000 megameters max launch speed warp 12 Max time delay 10 seconds Max proximity delay 500M Max explosion radius 500M Max number of pods launched 10 Max hit factor 50 Loss of shield 1 per hit hit/3 Loss of shields 2-3-4 per hit hit/2 Firing angles with engineering 0-135, 225-360 degrees .sp .ce Probes Number of probe launchers 1 Max range 3000M Max launch speed 2 Max time delay 15 sec Max proximity delay any Max explosion radius 50 times number of pods Max pods launched fuel available Max hit factor 10 times number of pods Loss of shields per hit same as torpedos Firing angles with engineering all .sp .ce Vessels Max turning rate 55 degrees Max speed warp 9 [11] Min units burned per warp-second 1 [.75] Crew 450 [350] .DE SHAR_EOF chmod +x '08ca.t' fi # end of overwriting check if test -f '08dn.t' then echo shar: will not over-write existing file "'08dn.t'" else cat << \SHAR_EOF > '08dn.t' .bp .ce Weapon And Vessel Specifications .ce Dreadnought Class .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i .ce Phasers Number of banks 6 Max range 1000 megameters Max spread 90 degrees (45+45) Min spread 20 degrees (10+10) Max hit with 45 degree spread 10 Max hit with 10 degree spread 45 Loss of shield 1 per hit hit/7.5 Loss of shields 2-3-4 per hit hit/5 Firing angles with engineering 0-125, 235-360 degrees Max charge per bank 10 units Min charge or discharge time 1 sec .sp .ce Tubes Number of tubes 8 Max range 12,000 megameters max launch speed warp 12 Max time delay 10 seconds Max proximity delay 500M Max explosion radius 500M Max number of pods launched 10 Max hit factor 50 Loss of shield 1 per hit hit/6 Loss of shields 2-3-4 per hit hit/4 Firing angles with engineering 0-135, 225-360 degrees .sp .ce Probes Number of probe launchers 1 Max range 3000M Max launch speed 2 Max time delay 15 sec Max proximity delay any Max explosion radius 50 times number of pods Max pods launched fuel available Max hit factor 10 times number of pods Loss of shields per hit same as torpedos Firing angles with engineering all .sp .ce Vessels Max turning rate 30 degrees Max speed warp 8 [10] Min units burned per warp-second 2 [1.5] Crew 600 [450] .DE SHAR_EOF chmod +x '08dn.t' fi # end of overwriting check if test -f '09dd.t' then echo shar: will not over-write existing file "'09dd.t'" else cat << \SHAR_EOF > '09dd.t' .bp .ce APPENDIX 4 .sp 2 .ce Initial Settings .ce Destroyer class .sp 1 .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i Crew 200 [150] Speed Warp 1 Course 0 [0-360] degrees Engine Efficiency .5 [.5] Fuel Level 100 Fuel Capacity 150 Regeneration Rate per Second 8.0 Helm Lock None [None] Phaser Deployment 0, 0 Phaser Bank Levels 2 x 10 units Phaser Charge/Discharge Rates 2 x 10 units Shield Drain 2 x 1 units Shield Percentage 2 x 100 Torpedo Deployment 60, 0, 0, 300 Tube Levels 4 x Zero Total Charged Pods Available 190 .sp .DE SHAR_EOF chmod +x '09dd.t' fi # end of overwriting check if test -f '09cl.t' then echo shar: will not over-write existing file "'09cl.t'" else cat << \SHAR_EOF > '09cl.t' .ce Initial Settings .ce Light Cruiser Class .sp 1 .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i Crew 350 [250] Speed Warp 1 Course 0 [0-360] degrees Engine Efficiency .75 [.5] Fuel Level 125 Fuel Capacity 175 Regeneration Rate per Second 10 Helm Lock None [None] Phaser Deployment 90, 0, 0, 270 Phaser Bank Levels 4 x 10 units Phaser Charge/Discharge Rates 4 x 10 units Shield Drain 4 x 1 units Shield Percentage 4 x 100 Torpedo Deployment 60, 0, 0, 300 Tube Levels 4 x Zero Total Charged Pods Available 190 .sp .DE SHAR_EOF chmod +x '09cl.t' fi # end of overwriting check if test -f '09ca.t' then echo shar: will not over-write existing file "'09ca.t'" else cat << \SHAR_EOF > '09ca.t' .bp .ce Initial Settings .ce Heavy Cruiser Class .sp 1 .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i Crew 450 [350] Speed Warp 1 Course 0 [0-360] degrees Engine Efficiency 1 [.75] Fuel Level 150 Fuel Capacity 200 Regeneration Rate per Second 10 Helm Lock None [None] Phaser Deployment 90, 0, 0, 270 Phaser Bank Levels 4 x 10 units Phaser Charge/Discharge Rates 4 x 10 units Shield Drain 4 x 1 units Shield Percentage 4 x 100 Torpedo Deployment 120, 60, 0, 0, 300, 240 Tube Levels 6 x Zero Total Charged Pods Available 190 .sp .DE SHAR_EOF chmod +x '09ca.t' fi # end of overwriting check if test -f '09dn.t' then echo shar: will not over-write existing file "'09dn.t'" else cat << \SHAR_EOF > '09dn.t' .ce Initial Settings .ce Dreadnought Class .sp 1 .ce Enemy exceptions are enclosed within [brackets] .sp .DS .ta 2.8iR 3.3i Crew 600 [450] Speed Warp 1 Course 0 [0-360] degrees Engine Efficiency 2 [1.5] Fuel Level 200 Fuel Capacity 200 Regeneration Rate per Second 15 Helm Lock None [None] Phaser Deployment 90, 90, 0, 0, 270, 270 Phaser Bank Levels 6 x 10 units Phaser Charge/Discharge Rates 6 x 10 units Shield Drain 4 x 1 units Shield Percentage 4 x 100 Torpedo Deployment 120, 60, 60, 0, 0, 300, 300, 240 Tube Levels 8 x Zero Total Charged Pods Available 190 .sp .DE SHAR_EOF chmod +x '09dn.t' fi # end of overwriting check if test -f '10.t' then echo shar: will not over-write existing file "'10.t'" else cat << \SHAR_EOF > '10.t' .bp .ce APPENDIX 5 .sp 2 .ce Designer's Notes .sp 2 .PP When I was about 10 or 11, I would go to the Lawrence Hall of Science quite frequently. There, on their time-sharing system, I would sit at a Teletype Model 33 and play trek. .PP Sadly, LHS replaced their system and trek went away. It was my intention that it should not be forgotten. I had had a copy of a slightly different version of trek written in BASIC, but it was sadly unimplementable on my Apple computer. .PP When I learned of an implementation of trek written in C, I jumped at the chance to bring it to the systems here at UC Berkeley. At that time, the game was mostly a direct translation of the original BASIC source. Many of the commands and routines were either missing or faulty. With Peter Yee, we worked together to fix up the program and managed to get it running. .PP Once it was running, the time came for improvements. I admit to pulling many concepts from the game Star Fleet Battles, most notably the different races (Hydrans, Lyrans, etc.) and the ship names. .PP This version of the game represents many hours of thinking and debugging. I hope you enjoy playing it as much as I did coding it. .sp .IP " " 30 -Jeff Okamoto .sp 2 .PP My first experience with TREK73 was also at the Lawrence Hall of Science. I had been taking classes in Time-Sharing Basic and noticed that other people always talked about a game called $TREK that was a real CPU hog and was usually turned off. Naturally I was intrigued. Soon I was paying $2.00 an hour for the chance to play that game. Many long hours and quite a few dollars went into playing $TREK, so it was with a certain sadness that I learned that the DG Ecllipse on which $TREK ran was being phased out. I made several attempts to obtain the source before it went away, but I was unable to get it. .PP Fortunately for me, Dave Pare at UC San Diego was also a fan of the game, and more importantly, he had an outdated copy of the source from an HP 2000. Dave had started to implement the game in C to run under 4.2 BSD UNIX. Expressing my interest to Dave, I was able to get a copy of Dave's code and thus the TREK Project at Berkeley was started. I spent endless hours tweaking with Dave's code, implementing some of the fifteen or so commands that he had not yet translated. .PP At about this time, I learned that Christopher Williams, here at Berkeley, had also tried to implement the game in C. What is more, he had a copy of the source (in BASIC) from Berkeley High School, and had implemented most of the commands. Merging the work that Chris had done into my copy of Dave's work led to a fairly complete version of the game. There still remained a large number of bugs, poor ideas, and outright mistakes in the code, but it ran. .PP Jeff Okamoto, being a fan of the game and a Star Fleet Battles player, was greatly interested in hacking on the game to bring up to par with the version that ran at LHS and to extend it even beyond that. Thus our partnership was formed and the current version of the game represents several hundred hours of our joint work (and play). Also represented are the suggestions, modifications and bug fixes we received from numerous people, including (to name a few) Matt Dillon, David Sharnoff, Joel Duisman, all at Berkeley, and Roger Noe at Rockwell International. .PP It is hoped that this implementation of a classic game will bring joy (and perhaps fond remembrances) to all who play. .sp .IP " " 30 Live Long and Prosper, .br -Peter Yee SHAR_EOF chmod +x '10.t' fi # end of overwriting check if test -f 'trek73.6' then echo shar: will not over-write existing file "'trek73.6'" else cat << \SHAR_EOF > 'trek73.6' .TH TREK73 6 "04 Mar 1986" .UC 4 .SH NAME trek73 - A Star Trek simulation .SH SYNOPSIS trek73 [-tcsSECNHfrdyTnFl] .SH DESCRIPTION .PP .I Trek73 is one of many Star Trek simulations now available. In its time, it was considered one of the best. .PP The player takes on the role of a starship commander who is involved in a battle against enemy alien ships. .PP Your starship can be one of four classes, or it can even be a ship of your own design -- see shipyard(6). .PP At your control are the ships' massive warp engines, its main weapons, the phaser banks and photon torpedos, and its defensive set of shields. Using these and your own ingenuity, you must form and implement a strategy that will lead you to victory. .PP Also at your disposal are such tactics as the defenseless ruse, and the corbomite bluff. .PP Reminiscent of .I ls (1), .I trek73 has a large number of options: .TP .B \-t Turns on terse mode. No initial scenario description is given. This is useful for terminals running at low baud rates. This option is normally off. .TP .B \-c Allows the specification of the Federation captain's name. .TP .B \-s Specify the sex of the captain of the Federation vessel. .TP .B \-S Specify the name of the Science Officer of the Federation vessel. By default the Science Officer is Mr. Spock. .TP .B \-E Specify the name of the Chief Engineer of the Federation vessel. By default the Chief Engineer is Mr. Scott. .TP .B \-C Specify the name of the Communications Officer of the Federation vessel. By default the Communications Officer is Lieutenant Uhura. .TP .B \-N Specify the name of the Navigator of the Federation vessel. By default the Navigator is Ensign Chekov. .TP .B \-H Specify the name of the Helmsman of the Federation vessel. By default the Helmsman is Lieutenant Sulu. .TP .B \-f Specify the name of the enemy commanding officer. .TP .B \-r Specify the race of the enemy. The race should be one of the following: Klingon, Romulan, Kzinti, Gorn, Hydran, Lyran, Tholian, Orion, or Monty Python. .TP .B \-d Set the delay time for command entry. Higher times can be useful for novices or for playing on very slow terminals. .TP .B \-y Silly option. Adds the Monty Pythons as a possible enemy race. This option is normally off. .TP .B \-T Teletype option. Causes certain parts of the output to come out as they did on the original teletype implementation. Doesn't do much for the game on crts. This option is normally off. .TP .B \-n Specify the name of the Federation vessel. The default name for the Federation vessel is randomly chosen from a set of names. .TP .B \-F Specify the class of the enemy vessel(s). Allowable classes are Destroyer (DD), Light Cruiser (CL), Heavy Cruiser (CA), and Dreadnought (DN). If the argument is none of the above, the program assumes that this is the name of a file where a player-designed ship is stored. .TP .B \-l Specify the class of the Federation vessel. Classes available are the same as the enemy's. .SH AUTHORS William K. Char, Perry Lee, and Dan Gee wrote the initial TREK73 in BASIC. Dave Pare and Chris Williams translated the BASIC into C. Jeff Okamoto, Peter Yee, and others corrected and enhanced the code. .SH SEE ALSO Jeff Okamoto, .I "The Star Trek Battle Manual" .SH BUGS Hopefully none. Bug reports should be sent to: ..!ucbvax!okamoto and ..!ucbvax!yee. SHAR_EOF chmod +x 'trek73.6' fi # end of overwriting check if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else cat << \SHAR_EOF > 'Makefile' # Makefile for Trek73.doc TEXT = header 00.t 01.t 02.t 03.t 04.t 04.5.t 05.t 06.t 07.t 08dd.t\ 08cl.t 08ca.t 08dn.t 09dd.t 09cl.t 09ca.t 09dn.t 10.t PAGE = trek73.6 DOC = trek73.doc MAN = trek73.man all: ${DOC} ${MAN} ${DOC}: ${TEXT} nroff -ms ${TEXT} > $@ ${MAN}: ${PAGE} nroff -man ${PAGE} > $@ shar: shar.doc1 shar.doc2 shar.doc1: header 00.t 01.t 02.t 03.t 04.t 04.5.t 05.t 06.t 07.t 08dd.t 08cl.t shar header 00.t 01.t 02.t 03.t 04.t 04.5.t 05.t 06.t 07.t 08dd.t 08cl.t >$@ shar.doc2: 08ca.t 08dn.t 09dd.t 09cl.t 09ca.t 09dn.t 10.t trek73.6 Makefile shar 08ca.t 08dn.t 09dd.t 09cl.t 09ca.t 09dn.t 10.t trek73.6 Makefile >$@ clean: rm -f shar.doc1 shar.doc2 make.out ${DOC} ${MAN} SHAR_EOF chmod +x 'Makefile' fi # end of overwriting check # End of shell archive exit 0