home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume3 / trek73 / part04 < prev    next >
Internet Message Format  |  1987-12-17  |  57KB

  1. Path: uunet!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v03i025:  trek73 - computer simulated Star Trek battles, Part04/06
  5. Message-ID: <1949@tekred.TEK.COM>
  6. Date: 17 Dec 87 19:54:39 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 2175
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: Jeff Okamoto <okamoto%hpccc@hplabs.HP.COM>
  12. Comp.sources.games: Volume 3, Issue 25
  13. Archive-name: trek73/Part04
  14.  
  15.  
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 4 (of 6)."
  24. # Contents:  man/01.t man/04.t src/cmds3.c src/firing.c src/main.c
  25. #   src/misc.c src/parseopts.c src/ships.c src/shipyard.c
  26. # Wrapped by billr@tekred on Thu Dec 17 11:43:36 1987
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f man/01.t -a "${1}" != "-c" ; then 
  29.   echo shar: Will not over-write existing file \"man/01.t\"
  30. else
  31. echo shar: Extracting \"man/01.t\" \(6955 characters\)
  32. sed "s/^X//" >man/01.t <<'END_OF_man/01.t'
  33. X.ce
  34. XDetailed Descriptions of Each Command
  35. X.sp
  36. X.PP
  37. XWhat follows is a detailed description of each command.
  38. XEach command is referred to by a number from 1 to 31.
  39. XAfter the name of the command is given, a synopsis of the
  40. Xarguments the command requires is given, if any.
  41. XThese arguments can be entered on the command line, separated
  42. Xby whitespace, if you wish.
  43. XFor instance, to fire phasers 1 through 4 with a spread of 15,
  44. Xyou could type '1 1234 15' on the command line.
  45. X.PP
  46. XIt should be noted that all numbers refer to parameters for
  47. Xthe Heavy Cruiser Class ship, and that other ships have
  48. Xslightly different characteristics.
  49. X.sp
  50. X.LP
  51. X1.  Fire Phasers.
  52. X.PP
  53. X[Phasers | all] [Spread]
  54. X.PP
  55. XPhasers are pure energy units which emit
  56. Xa beam similar to lasers, but of a pulsating nature which
  57. Xcan be `phased' to interfere with the wave pattern of any
  58. Xmolecular form.
  59. XPhasers get their power from phaser banks, which in turn,
  60. Xderive their power from the ship's engines.
  61. XEach phaser bank is capable of holding a charge of 10 units.
  62. XWhen firing, these banks discharge, similar to batteries, to
  63. Xspread their destructive power through space.
  64. XAfter discharging, these banks are then recharged by the
  65. Xengines.
  66. XEach phaser can be set to automatically track a target or
  67. Xcan be manually rotated.
  68. XUnless engineering is jettisoned (code 21), phasers only
  69. Xfire from 0-125 and 235-360 degrees, relative to the ship's
  70. Xcourse.
  71. XIn other words, each vessel has a 110 degree blind side in
  72. Xback of it in which phasers cannot fire.
  73. XIf phasers fired into this blind side, they would destroy
  74. Xthe ship's engineering section.
  75. X.sp
  76. X.PP
  77. XThe Captain also designates a wide or narrow phaser beam: a
  78. Xwide beam to disrupt many targets; a narrow beam to inflict
  79. Xmaximum damage on a single target.
  80. XThe maximum spread of phasers is 45 degrees, the minimum is
  81. X10 degrees.
  82. XThe total beam width is twice the designated spread.
  83. X.sp
  84. X.PP
  85. XThe firing percentage of each bank is preset to 100.
  86. XIn other words, the bank fully discharges when firing.
  87. XThis can be changed, however, using code 22.
  88. X.sp
  89. X.PP
  90. XThe maximum range of phasers is 1000M; the maximum hit
  91. Xfactor is 45 with a ten degree spread, 10 with a forty-five
  92. Xdegree spread.
  93. XPhaser hit factors are calculated by the following formula:
  94. X.sp
  95. X.ce
  96. Xhit = (bankunits)(firing%)sqrt(1-range/1000)(45/spread)
  97. X.sp
  98. X.PP
  99. XPhasers fire in .2-second intervals starting with bank one.
  100. XPhasers inflict heavy damage and casualties, but do not
  101. Xdestroy shields as much as antimatter explosions do.
  102. X.sp
  103. X.PP
  104. XA phaser is unable to fire if damaged, if firing into your
  105. Xblind side, or if completely discharged.
  106. X.sp
  107. X.LP
  108. X2.  Fire Photon Torpedos.
  109. X.PP
  110. X[Tubes | all]
  111. X.PP
  112. XThe Enterprise is equipped with six torpedo tubes, which, as
  113. Xphasers, can be set to automatically track a target or be
  114. Xmanually rotated.
  115. XUnless engineering is jettisoned, tubes only fire from
  116. X0-135 and 225-360 degrees.
  117. XEach tube fires all its antimatter pods, which are
  118. Xheld suspended in a magnetic force field.
  119. XPhoton torpedos can be fired directly at an enemy, laid out
  120. Xas a mine field, or scattered in an attacker's path as
  121. Xdepth charges.
  122. X.sp
  123. X.PP
  124. XTubes must be loaded (code 9) prior to firing.
  125. XNormally, torpedos are launched at warp 12 in .2-second
  126. Xintervals, beginning with tube one.
  127. XPhoton torpedos have a proximity fuse of 200M.
  128. XAll of these values can be changed by using code 22.
  129. X.sp
  130. X.PP
  131. XTorpedos must be launched with care since the antimatter
  132. Xpods which are fired can never be recovered.
  133. XIt is suggested that you not fire more than four torpedos at
  134. Xany one time, since a certain number of them do miss, or are
  135. Xdestroyed by the enemy firing phasers at them.
  136. XIt is also suggested that you fire them at distant targets,
  137. Xbeyond 1100M, to avoid the explosion radius of your own
  138. Xweapons.
  139. XHit factors resulting from antimatter explosions are
  140. Xcalculated as follows:
  141. X.sp
  142. X.ce
  143. Xhit = 5(#podscontained)sqrt(1-range/(50(#podscontained)))
  144. X.sp
  145. X.PP
  146. XThe maximum hit factor of an antimatter device is five times
  147. Xthe number of pods contained (in the case of torpedos, 50);
  148. Xits explosion radius is 50 time the number of pods
  149. Xcontained (in the case of torpedos, 500).
  150. XAntimatter explosions heavily weaken shields but do not
  151. Xdamage equipment as much as phasers do.
  152. XThis formula also applies to vessels, engineering sections,
  153. Xand antimatter probe explosions.
  154. X.sp
  155. X.PP
  156. XA photon torpedo's proximity fuse will not be activated by a
  157. Xcloaked ship.
  158. X.sp
  159. X.PP
  160. XTubes are unable to fire if damaged, if firing into your
  161. Xblind side, or if unloaded.
  162. X.sp
  163. X.LP
  164. X3.  Lock Phasers.
  165. X.PP
  166. X[Phasers | all] [Target Name]
  167. X.PP
  168. XPhasers locked on an enemy vessel will automatically aim
  169. Xtowards it.
  170. XAlthough phasers may track a vessel which is in the firing
  171. Xblind side, they will not fire unless engineering is
  172. Xjettisoned.
  173. XTo fire at vessels in the blind spot, simply change course
  174. Xat least 55 degrees.
  175. XOnce a phaser is locked, it is not disengaged until the
  176. Xtarget is destroyed (in which case it is then rotated to
  177. Xzero degrees relative), relocked, manually overridden, or
  178. Xdamaged.
  179. X.sp
  180. X.PP
  181. XPhasers can not be locked onto cloaked enemy ships.
  182. XPhasers that were previously locked onto a non-cloaked ship
  183. Xwill track the enemy's last known course and speed when
  184. Xthat ship cloaks.
  185. X.sp
  186. X.LP
  187. X4.  Lock Tubes.
  188. X.PP
  189. X[Tubes | all] [Target Name]
  190. X.PP
  191. XTubes lock and unlock in the same manner that phasers do.
  192. X.sp
  193. X.LP
  194. X5.  Manually Rotate Phasers.
  195. X.PP
  196. X[Phasers | all] [Bearing]
  197. X.PP
  198. XManually rotating phasers disengages any previous locks and
  199. Xpositions them as directed, relative to your course.
  200. XFor example, if your course is 30, and phasers are rotated
  201. X45 degrees, they will hit a target bearing 75 degrees.
  202. XRotating phasers into you blind side is permissible,
  203. Xhowever, they will not fire.
  204. X.sp
  205. X.LP
  206. X6.  Manually Rotate Tubes.
  207. X.PP
  208. X[Tubes | all] [Bearing]
  209. X.PP
  210. XManually rotating tubes is similar to rotating phasers.
  211. X.sp
  212. X.LP
  213. X7.  Phaser Status.
  214. X.PP
  215. XPhaser status reports the control (locks and damages),
  216. Xdeployment, levels, firing percentages (normally 100),
  217. Xand charge/discharge rates (normally +10) of all phasers.
  218. XThis command does not use a turn.
  219. XCf. Command 22.
  220. X.sp
  221. X.LP
  222. X8.  Tube Status.
  223. X.PP
  224. XTube status reports the control, deployment, tube levels,
  225. Xlaunch speeds (normally 12), proximity delays (normally
  226. X200), and time delays (normally 10) of all tubes.
  227. XThis command does not use a turn.
  228. XCf. Command 22.
  229. X.sp
  230. X.LP
  231. X9.  Load/Unload Tubes.
  232. X.PP
  233. X[l | u] [Tubes | all]
  234. X.PP
  235. XEach specified tube will be automatically loaded with 10 units or
  236. Xwhatever remains in the engines, whichever is less.
  237. XTubes can also be unloaded if the need arises.
  238. X.sp
  239. X.LP
  240. X10.  Launch Antimatter Probe.
  241. X.PP
  242. X[Pods] [Time] [Proximity] [Target | [<CR> Course]]
  243. X.PP
  244. XProbes are slow-moving devices equipped with internal
  245. Xguidance systems which allow them to chase an enemy vessel.
  246. XProbes consist of at least ten antimatter pods which are
  247. Xlaunched from an undamaged probe launcher at warp three.
  248. XAs with torpedos, probes are set with time and proximity
  249. Xfuses, and use the same hit factor formula as do torpedos.
  250. END_OF_man/01.t
  251. if test 6955 -ne `wc -c <man/01.t`; then
  252.     echo shar: \"man/01.t\" unpacked with wrong size!
  253. fi
  254. # end of overwriting check
  255. fi
  256. if test -f man/04.t -a "${1}" != "-c" ; then 
  257.   echo shar: Will not over-write existing file \"man/04.t\"
  258. else
  259. echo shar: Extracting \"man/04.t\" \(6881 characters\)
  260. sed "s/^X//" >man/04.t <<'END_OF_man/04.t'
  261. X.ce
  262. XOptions
  263. X.sp
  264. X.PP
  265. XIn TREK73, all the names of crewmembers are taken from the
  266. XStar Trek series.
  267. XThrough the use of options, the names, as well as other
  268. Xaspects of the game, can be changed to whatever you want.
  269. X.sp
  270. X.PP
  271. XTo use the options, you must add the variable TREK73OPTS to
  272. Xyour environment.
  273. XA sample would be (using the C-shell):
  274. X.br
  275. X.sp
  276. Xsetenv TREK73OPTS 'name=Jerk, ship=Boobyprize, terse'
  277. X.sp
  278. X.PP
  279. XThe option string is a list of comma-separated options.
  280. XOptions are designated as either boolean or string options.
  281. XBoolean options are turned on by typing their name and turned
  282. Xoff by prepending 'no' to them.
  283. XString options are set equal to the string which follows the "=".
  284. X.sp
  285. X.PP
  286. XThere follows a list of all the options, what type it is,
  287. Xand an explanation of what they mean.
  288. XThe default for the option is in square brackets following
  289. Xthe option.
  290. X.sp
  291. X.LP
  292. Xterse BOOLEAN [noterse]
  293. X.XP
  294. XThis option, when set, turns off the information regarding the
  295. Xship's purpose in the area.
  296. XIt thus reduces the amount of drek on the screen.
  297. XIf you are on a slow terminal, this is a nice option to have set.
  298. X.sp
  299. X.LP
  300. Xshipname STRING [Enterprise]
  301. X.XP
  302. XThis option names your ship.
  303. X.sp
  304. X.LP
  305. Xname STRING
  306. X.XP
  307. XThis option names the captain of the ship.
  308. XIf this option is not set, then the program will ask for a name.
  309. XThe captain is the one who must make all the decisions of strategy
  310. Xand tactics for the ship.
  311. X.sp
  312. X.LP
  313. Xsex STRING
  314. X.XP
  315. XThis option gives the captain a gender.
  316. XIf this option is not set, the program will ask for it's value.
  317. XIf you respond with something that starts with other than "m" or "f",
  318. Xbeware!
  319. X.sp
  320. X.LP
  321. Xscience STRING [Spock]
  322. X.XP
  323. XThis option names the science officer, who is responsible
  324. Xfor checking the parameters of the captain's commands.
  325. XIt is also this officer's duty to report damage to the ship
  326. Xas well as scan for enemy damage.
  327. X.sp
  328. X.LP
  329. Xengineer STRING [Scott]
  330. X.XP
  331. XThis option names the chief engineer of the ship.
  332. XIt is this officer's duty to report on the status of the ship,
  333. Xespecially its energy supply and distribution of the same.
  334. XThe officer also controls the launching of anti-matter probes.
  335. X.sp
  336. X.LP
  337. Xhelmsman STRING [Sulu]
  338. X.XP
  339. XThis option names the ship's helmsman.
  340. XThis officer's duty is to control the speed of the ship
  341. Xand also controls the firing of the ship's weapons.
  342. X.sp
  343. X.LP
  344. Xnav STRING [Chekov]
  345. X.XP
  346. XThis option names the ship's navigator, who is responsible
  347. Xfor the navigation of the ship.
  348. XThis officer makes changes to the ship's course as directed
  349. Xby the captain.
  350. XThis officer also controls any anti-matter probes after they
  351. Xhave been launched.
  352. X.sp
  353. X.LP
  354. Xcom STRING [Uhura]
  355. X.XP
  356. XThis option names the ship's communications officer.
  357. XIt is the duty of this officer to handle all communications between
  358. Xthe ship and the rest of the universe.
  359. X.sp
  360. X.LP
  361. Xenemy STRING [random]
  362. X.XP
  363. XIf this option is set, it tells the program which race you wish
  364. Xto fight.
  365. XThe available races are:
  366. XKlingon, Romulan, Kzinti, Gorn, Orion, Hydran, Lyran, or Tholian.
  367. XIf the option is not set, the race you will fight is chosen at random.
  368. X.sp
  369. X.LP
  370. Xfoename STRING [random]
  371. X.XP
  372. XIf this option is set, it specifies the name of the commander
  373. Xof the enemy ship(s).
  374. XIf this option is not specified, the name is chosen at random.
  375. X.sp
  376. X.LP
  377. Xclass STRING [CA]
  378. X.XP
  379. XThis option specifies the kind of ship you are commanding.
  380. XAllowable classes are: DN, CA, CL, and DD, standing for
  381. Xdreadnought, heavy cruiser, light cruiser, and destroyer.
  382. XIn general, the larger the ship, the more weapons and stronger
  383. Xshields you have, at the cost of less speed and maneuverability.
  384. X.sp
  385. X.LP
  386. Xfoeclass STRING [CA]
  387. X.XP
  388. XThis option specifies the kind of ship that you are fighting.
  389. XThe different classes are explained above.
  390. X.sp
  391. X.LP
  392. Xsilly BOOLEAN [nosilly]
  393. X.XP
  394. XIf this option is set, an additional race is added to the list of
  395. Xpossible races to fight.
  396. XThis race is the Monty Pythons.
  397. XNote that if you wish to always fight the Monty Python's, you merely
  398. Xhave to set the enemy option above.
  399. X.sp
  400. X.LP
  401. Xtime STRING [30]
  402. X.XP
  403. XTime is used to specify the time between commands.
  404. XThe longer this value, the more time may be used in issuing a command.
  405. X.sp
  406. X.LP
  407. Xteletype BOOLEAN [noteletype]
  408. X.XP
  409. XThe teletype option causes some of the output to come out as it did
  410. Xin the original teletype version.
  411. X.sp
  412. X.LP
  413. Xsavefile STRING [$HOME/trek73.save]
  414. X.XP
  415. XThe savefile option specifies where the data image is to be stored
  416. Xif the game is saved during play.
  417. X``~'' is not expanded, so the path should be
  418. Xexplicit and fully expanded.
  419. X.sp 3
  420. X.ce
  421. XCommand Line Options
  422. X.sp
  423. X.PP
  424. XIn all cases, the arguments you place on the command line will supersede
  425. Xoptions in the environment.
  426. X.sp
  427. X.PP
  428. XThe following is a description of the command line options:
  429. X.sp
  430. X.IP \-t
  431. XTurns on terse mode.
  432. XNo initial scenario description is given.
  433. XThis is useful for terminals running at low baud rates.
  434. XThis option is normally off.
  435. X.sp
  436. X.IP \-c
  437. XAllows the specification of the Federation captain's name.
  438. X.sp
  439. X.IP \-s
  440. XSpecify the sex of the captain of the Federation vessel.
  441. X.sp
  442. X.IP \-S
  443. XSpecify the name of the Science Officer of the Federation vessel.
  444. X.sp
  445. X.IP \-E
  446. XSpecify the name of the Chief Engineer of the Federation vessel.
  447. X.sp
  448. X.IP \-C
  449. XSpecify the name of the Communications Officer of the Federation vessel.
  450. X.sp
  451. X.IP \-N
  452. XSpecify the name of the Navigator of the Federation vessel.
  453. X.sp
  454. X.IP \-H
  455. XSpecify the name of the Helmsman of the Federation vessel.
  456. X.sp
  457. X.IP \-f
  458. XSpecify the name of the enemy commanding officer.
  459. X.sp
  460. X.IP \-r
  461. XSpecify the race of the enemy.
  462. XThe race should be one of the following:
  463. XKlingon, Romulan, Kzinti, Gorn, Hydran, Lyran, Tholian, Orion,
  464. Xor Monty Python.
  465. X.sp
  466. X.IP \-d
  467. XSet the delay time for command entry.
  468. XHigher times can be useful for novices or for playing on very slow
  469. Xterminals.
  470. X.sp
  471. X.IP \-y
  472. XSilly option.
  473. XAdds the Monty Pythons as a possible enemy race.
  474. XThis option is normally off.
  475. X.sp
  476. X.IP \-T
  477. XTeletype option.
  478. XCauses certain parts of the output to come out as they did on the
  479. Xoriginal teletype implementation.
  480. XDoesn't do much for the game on crts.
  481. XThis option is normally off.
  482. X.sp
  483. X.IP \-n
  484. XSpecify the name of the Federation vessel.
  485. XThe default name for the Federation vessel is randomly chosen from a
  486. Xset of names.
  487. X.sp
  488. X.IP \-F
  489. XSpecify the class of the enemy vessel(s).
  490. XAllowable classes are Destroyer (DD), Light Cruiser (CL),
  491. XHeavy Cruiser (CA), and Dreadnought (DN).
  492. XIf the argument is none of the above, the program assumes that this is
  493. Xthe name of a file where a player-designed ship is stored.
  494. X.sp
  495. X.IP \-l
  496. XSpecify the class of the Federation vessel.
  497. XAvailable classes are the same as the enemy's.
  498. X.sp
  499. X.IP \-R
  500. XRestore the game from the savefile.  It is assumed that the TREK73OPTS
  501. Xcontains the name of the savefile, otherwise it is not possible to restart
  502. Xthe game with the -R option.  In case the savefile name is not in TREK73OPTS,
  503. Xthe game may be restored by issuing the command with the path to the savefile
  504. Xas the first argument.
  505. X.bp
  506. END_OF_man/04.t
  507. if test 6881 -ne `wc -c <man/04.t`; then
  508.     echo shar: \"man/04.t\" unpacked with wrong size!
  509. fi
  510. # end of overwriting check
  511. fi
  512. if test -f src/cmds3.c -a "${1}" != "-c" ; then 
  513.   echo shar: Will not over-write existing file \"src/cmds3.c\"
  514. else
  515. echo shar: Extracting \"src/cmds3.c\" \(6408 characters\)
  516. sed "s/^X//" >src/cmds3.c <<'END_OF_src/cmds3.c'
  517. X#ident "@(#) TREK73 $Header: cmds3.c,v 1.1 87/10/09 11:02:23 okamoto Exp $"
  518. X/*
  519. X * $Source: /ccc/okamoto/src/trek/src/RCS/cmds3.c,v $
  520. X *
  521. X * $Header: cmds3.c,v 1.1 87/10/09 11:02:23 okamoto Exp $
  522. X *
  523. X * $Log:    cmds3.c,v $
  524. X * Revision 1.1  87/10/09  11:02:23  11:02:23  okamoto (Jeff Okamoto)
  525. X * Initial revision
  526. X * 
  527. X */
  528. X/*
  529. X * TREK73: cmds3.c
  530. X *
  531. X * User Commands
  532. X *
  533. X * jettison_engineering, detonate_engineering, phaser_status, tube_status,
  534. X * survivors, alter_power
  535. X *
  536. X * (do_jettison)
  537. X *
  538. X */
  539. X
  540. X#include "externs.h"
  541. X#include <ctype.h>
  542. X
  543. X
  544. Xint
  545. Xjettison_engineering(sp)
  546. Xstruct ship *sp;
  547. X{
  548. X
  549. X    printf("   Mr. %s, jettison our engineering section!\n", engineer);
  550. X    if (is_dead(sp, S_ENG)) {
  551. X        printf("%s:  But Captain, it's already jettisonned.\n", engineer);
  552. X        return 0;
  553. X    }
  554. X    do_jettison(sp);
  555. X    printf("%s:  Aye, %s.  Jettisoning engineering.\n", 
  556. X        engineer, title);
  557. X    return 1;
  558. X}
  559. X
  560. Xint
  561. Xdo_jettison(sp)
  562. Xstruct ship *sp;
  563. X{
  564. X    register struct list *lp;
  565. X    register struct torpedo *tp;
  566. X
  567. X    lp = newitem(I_ENG);
  568. X    tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
  569. X    if (tp == (struct torpedo *)NULL) {
  570. X        fprintf(stderr, "do_jettison: malloc failed\n");
  571. X        exit(2);
  572. X    }
  573. X    tp->target = NULL;
  574. X    tp->speed = sp->warp;
  575. X    tp->newspeed = 0.0;
  576. X    tp->x = sp->x;
  577. X    tp->y = sp->y;
  578. X    tp->course = sp->course;
  579. X    /* This is correct */
  580. X    tp->fuel = sp->energy;
  581. X    tp->timedelay = 10.;
  582. X    tp->prox = 0;
  583. X    tp->from = sp;
  584. X    tp->id = new_slot();
  585. X    tp->type = TP_ENGINEERING;
  586. X    sp->energy = sp->pods = 0.;
  587. X    sp->newwarp = (sp->warp < 0.0) ? -0.99 : 0.99;
  588. X    sp->regen = 0.0;
  589. X    sp->status[S_ENG] = 100;    /* Set these as destroyed */
  590. X    sp->status[S_WARP] = 100;
  591. X    sp->max_speed = 1.0;
  592. X    sp->cloaking = C_NONE;
  593. X    sp->t_blind_left = sp->t_blind_right =
  594. X        sp->p_blind_left = sp->p_blind_right = 180;
  595. X}
  596. X
  597. Xint
  598. Xdetonate_engineering(sp)
  599. Xstruct ship *sp;
  600. X{
  601. X    register struct list *lp;
  602. X    register struct torpedo *tp;
  603. X    register int found;
  604. X    char buf[10];
  605. X
  606. X    found = 0;
  607. X    printf("   Mr. %s, detonate engineering!\n", engineer);
  608. X    if (!is_dead(sp, S_ENG)) {
  609. X        printf("%s: But %s, it's still attached.\n",engineer,title);
  610. X        printf("   Detonate anyway? ");
  611. X        printf("%s:  [yes or no] ", captain);
  612. X        (void) Gets(buf, sizeof(buf));
  613. X        if ((buf[0] == NULL)
  614. X            || ((buf[0] != 'y') && (buf[0] != 'Y')))
  615. X            return 0;
  616. X        else 
  617. X            do_jettison(sp);
  618. X    }
  619. X    for (lp = &head; lp != tail; lp = lp->fwd) {
  620. X        if (lp->type != I_ENG)
  621. X            continue;
  622. X        tp = lp->data.tp;
  623. X        if (tp->from != sp)
  624. X            continue;
  625. X        found++;
  626. X        tp->timedelay = 0.;
  627. X        break;
  628. X    }
  629. X    if (found)
  630. X        printf("%s:  Aye, %s.\n",engineer, title);
  631. X    else
  632. X        printf("%s:  Ours has already detonated.\n", engineer);
  633. X    return 1;
  634. X}
  635. X
  636. X
  637. Xint
  638. Xphaser_status(sp)
  639. Xstruct ship *sp;
  640. X{
  641. X    register int i;
  642. X
  643. X    puts("Phasers\n");
  644. X    printf("Control: ");
  645. X    for (i=0; i<sp->num_phasers; i++) {
  646. X        if (sp->phasers[i].status & P_DAMAGED)
  647. X            printf("\tdamaged");
  648. X        else if (sp->phasers[i].target == NULL)
  649. X            printf("\tmanual");
  650. X        else
  651. X            printf("\t%.7s", sp->phasers[i].target->name);
  652. X    }
  653. X    printf("\n Turned: ");
  654. X    for (i=0; i<sp->num_phasers; i++)
  655. X        if (sp->phasers[i].status & P_DAMAGED)
  656. X            putchar('\t');
  657. X        else if (sp->phasers[i].target == NULL)
  658. X            printf("\t%3.0f", sp->phasers[i].bearing);
  659. X        else
  660. X            printf("\tLOCKED");
  661. X    printf("\n  Level: ");
  662. X    for (i=0; i<sp->num_phasers; i++) {
  663. X        if (sp->phasers[i].status & P_DAMAGED)
  664. X            putchar('\t');
  665. X        else
  666. X            printf("\t%d", sp->phasers[i].load);
  667. X    }
  668. X    printf("\n  Drain: ");
  669. X    for (i=0; i<sp->num_phasers; i++) {
  670. X        if (sp->phasers[i].status & P_DAMAGED)
  671. X            putchar('\t');
  672. X        else
  673. X            printf("\t%d", sp->phasers[i].drain);
  674. X    }
  675. X    printf("\n\nFiring percentage: %d\n",sp->p_percent);
  676. X    printf("\nFiring angles: ");
  677. X    if (is_dead(sp, S_ENG)) {
  678. X        printf("unrestricted.\n");
  679. X    } else {
  680. X        printf("0 - %d and %d - 360.\n",
  681. X            sp->p_blind_left, sp->p_blind_right);
  682. X    }
  683. X    return 1;
  684. X}
  685. X
  686. Xint
  687. Xtube_status(sp)
  688. Xstruct ship *sp;
  689. X{
  690. X    register int i;
  691. X
  692. X    puts("Torpedos\n");
  693. X    printf("Control: ");
  694. X    for (i=0; i<sp->num_tubes; i++) {
  695. X        if (sp->tubes[i].status & T_DAMAGED)
  696. X            printf("\tdamaged");
  697. X        else if (sp->tubes[i].target == NULL)
  698. X            printf("\tmanual");
  699. X        else
  700. X            printf("\t%.7s", sp->tubes[i].target->name);
  701. X    }
  702. X    printf("\n Turned: ");
  703. X    for (i=0; i<sp->num_tubes; i++)
  704. X        if (sp->tubes[i].status & T_DAMAGED)
  705. X            putchar('\t');
  706. X        else if (sp->tubes[i].target == NULL)
  707. X            printf("\t%.0f", sp->tubes[i].bearing);
  708. X        else
  709. X            printf("\tLOCKED");
  710. X    printf("\n  Level: ");
  711. X    for (i=0; i<sp->num_tubes; i++) {
  712. X        if (sp->tubes[i].status & T_DAMAGED)
  713. X            putchar('\t');
  714. X        else
  715. X            printf("\t%d", sp->tubes[i].load);
  716. X    }
  717. X    printf("\n\nLaunch speed: %d\n", sp->t_lspeed);
  718. X    printf("  Time delay: %d\n", sp->t_delay);
  719. X    printf("  Prox delay: %d\n", sp->t_prox);
  720. X    printf("\nFiring angles: ");
  721. X    if (is_dead(sp, S_ENG)) {
  722. X        printf("unrestricted.\n");
  723. X    } else {
  724. X        printf("0 - %d and %d - 360.\n",sp->t_blind_left, sp->t_blind_right);
  725. X    }
  726. X    return 1;
  727. X}
  728. X
  729. Xint
  730. Xsurvivors(sp)
  731. Xstruct ship *sp;
  732. X{
  733. X    struct ship *ep;
  734. X    register int i;
  735. X
  736. X    printf("\nSurvivors reported:\n");
  737. X    for (i=0; i<=shipnum; i++) {
  738. X        ep = shiplist[i];
  739. X        if (sp->complement < 0)
  740. X            printf("   %s -- destructed", sp->name);
  741. X        else if (cantsee(ep))
  742. X            printf("   %s -- ???\n", ep->name);
  743. X        else
  744. X            printf("   %s -- %d\n", ep->name, ep->complement);
  745. X    }
  746. X    sp = sp;        /* LINT */
  747. X}
  748. X
  749. Xint
  750. Xalter_power()
  751. X{
  752. X    register int i;
  753. X    float j;
  754. X    char buf1[20];
  755. X
  756. X    printf("\n%s:  Regeneration rate is %5.2f.\n",engineer, shiplist[0]->regen);
  757. X    for (i=0; i<SHIELDS; i++) {
  758. X        printf("%s:  Shield %d drain is [0.0 to 1.0] ",
  759. X            captain, i + 1);
  760. X        (void) Gets(buf1, sizeof(buf1));
  761. X        j = (float) atof(buf1);
  762. X        if (buf1[strlen(buf1) - 1] == '*') {
  763. X            if ((j < 0.0) || (j > 1.0))
  764. X                goto badparam;
  765. X            for (; i<SHIELDS; i++)
  766. X                shiplist[0]->shields[i].attemp_drain =j;
  767. X            break;
  768. X        } else if ((j < 0.0) || (j > 1.0))
  769. X            goto badparam;
  770. X        else
  771. X            shiplist[0]->shields[i].attemp_drain = j;
  772. X    }                
  773. X    printf("\n");
  774. X    for (i=0; i<shiplist[0]->num_phasers; i++) {
  775. X        printf("%s:  Phaser %d drain is [%.0f to %.0f] ",
  776. X            captain, i + 1, MIN_PHASER_DRAIN, MAX_PHASER_DRAIN);
  777. X        (void) Gets(buf1, sizeof(buf1));
  778. X        j = (float) atof(buf1);
  779. X        if (buf1[strlen(buf1) - 1] == '*') {
  780. X            if ((j < MIN_PHASER_DRAIN)
  781. X                || (j > MAX_PHASER_DRAIN))
  782. X                goto badparam;
  783. X            for (; i<shiplist[0]->num_phasers; i++)
  784. X                shiplist[0]->phasers[i].drain = (int) j;
  785. X            break;
  786. X        } else if ((j < MIN_PHASER_DRAIN) 
  787. X            || (j > MAX_PHASER_DRAIN))
  788. X            goto badparam;
  789. X        else
  790. X            shiplist[0]->phasers[i].drain = (int) j;
  791. X    }
  792. X    return 1;
  793. Xbadparam:
  794. X    printf("%s:  Bad parameters, %s.\n", engineer, title);
  795. X    return 0;
  796. X}
  797. END_OF_src/cmds3.c
  798. if test 6408 -ne `wc -c <src/cmds3.c`; then
  799.     echo shar: \"src/cmds3.c\" unpacked with wrong size!
  800. fi
  801. # end of overwriting check
  802. fi
  803. if test -f src/firing.c -a "${1}" != "-c" ; then 
  804.   echo shar: Will not over-write existing file \"src/firing.c\"
  805. else
  806. echo shar: Extracting \"src/firing.c\" \(5713 characters\)
  807. sed "s/^X//" >src/firing.c <<'END_OF_src/firing.c'
  808. X#ident "@(#) TREK73 $Header: firing.c,v 1.1 87/10/09 11:06:25 okamoto Exp $"
  809. X/*
  810. X * $Source: /ccc/okamoto/src/trek/src/RCS/firing.c,v $
  811. X *
  812. X * $Header: firing.c,v 1.1 87/10/09 11:06:25 okamoto Exp $
  813. X *
  814. X * $Log:    firing.c,v $
  815. X * Revision 1.1  87/10/09  11:06:25  11:06:25  okamoto (Jeff Okamoto)
  816. X * Initial revision
  817. X * 
  818. X */
  819. X/*
  820. X * TREK73: firing.c
  821. X *
  822. X * Take care of firing phasers and torpedos for both enemy
  823. X * and fed ships.
  824. X *
  825. X * phaser_firing, torpedo_firing, ship_detonate, torp_detonate
  826. X *
  827. X */
  828. X
  829. X#include "externs.h"
  830. X
  831. X
  832. Xphaser_firing(sp)
  833. Xstruct ship *sp;
  834. X{
  835. X    register int i;
  836. X    register float j;
  837. X    int    hit;
  838. X    struct    ship *ep;
  839. X    struct    torpedo *tp;
  840. X    int    s;
  841. X    int    x, y;
  842. X    struct    ship *target;
  843. X    struct    list *lp;
  844. X    float    bear;
  845. X    struct     ship *fed;
  846. X
  847. X
  848. X    fed = shiplist[0];
  849. X    for (i=0; i<sp->num_phasers; i++) {
  850. X        if (sp->phasers[i].status & P_FIRING)
  851. X            break;
  852. X    }
  853. X    if (i == sp->num_phasers)
  854. X        return 0;
  855. X    sp->phasers[i].status &= ~P_FIRING;
  856. X    target = sp->phasers[i].target;
  857. X    /*
  858. X     * Put in j the relative bearing of the phasers relative to the ship
  859. X     * Put in bear the absolute direction the phasers are pointing
  860. X     */
  861. X    bear = sp->phasers[i].bearing + sp->course;
  862. X    j = rectify(sp->phasers[i].bearing);
  863. X    if (betw(j, sp->p_blind_left, sp->p_blind_right)
  864. X        && !is_dead(sp, S_ENG))
  865. X        return 0;
  866. X    if (target != NULL && is_dead(target, S_DEAD)) {
  867. X        if ((sp = fed) && (!shutup[PHASERS+i])
  868. X            && !(is_dead(sp, S_DEAD))) {
  869. X            printf("%s phaser %d unlocking\n",
  870. X                sp->name, i+1);
  871. X            shutup[PHASERS+i]++;
  872. X        }
  873. X        sp->phasers[i].target = NULL;
  874. X        return 0;
  875. X    }
  876. X    if (cantsee(sp))
  877. X        (void) e_cloak_off(sp, fed);
  878. X    printf(" <%s frng phasers>\n", sp->name);
  879. X    for (lp = &head; lp != tail; lp = lp->fwd) {
  880. X        if (lp->type == 0)
  881. X            continue;
  882. X        ep = NULL;
  883. X        tp = NULL;
  884. X        if (lp->type == I_SHIP) {
  885. X            ep = lp->data.sp;
  886. X            if (ep == sp)
  887. X                continue;
  888. X            x = ep->x;
  889. X            y = ep->y;
  890. X        } else {
  891. X            tp = lp->data.tp;
  892. X            x = tp->x;
  893. X            y = tp->y;
  894. X        }
  895. X        hit = phaser_hit(sp, x, y, &sp->phasers[i], bear);
  896. X        if (hit <= 0)
  897. X            continue;
  898. X        if (tp) {
  899. X            if (tp->timedelay > segment) {
  900. X                switch (lp->type) {
  901. X                case I_TORPEDO:
  902. X                    printf("hit on torpedo %d\n",
  903. X                        tp->id);
  904. X                    break;
  905. X                case I_ENG:
  906. X                    printf("hit on %s's engineering\n",
  907. X                        tp->from->name);
  908. X                    break;
  909. X                case I_PROBE:
  910. X                    printf("hit on probe %d\n", 
  911. X                        tp->id);
  912. X                    break;
  913. X                default:
  914. X                    fprintf(stderr, "hit on lp->type\n",
  915. X                        lp->type);
  916. X                    break;
  917. X                }
  918. X                tp->timedelay = 0.;
  919. X            }
  920. X            tp->fuel -= hit/2;
  921. X            if (tp->fuel < 0)
  922. X                tp->fuel = 0;
  923. X            continue;
  924. X        }
  925. X        /*
  926. X         * Determine which shield was hit
  927. X         */
  928. X        j = rectify(bearing(x, sp->x, y, sp->y) - ep->course);
  929. X        if (j > 315.0 || j < 45.0)
  930. X            s = 1;
  931. X        else if (j < 135.0)
  932. X            s = 2;
  933. X        else if (j < 225.0)
  934. X            s = 3;
  935. X        else
  936. X            s = 4;
  937. X        (void) damage(hit, ep, s, &p_damage, D_PHASER);
  938. X    }
  939. X    /*
  940. X     * Reduce the load by the firing percentage
  941. X     */
  942. X    sp->phasers[i].load *= 1.0 - (float) sp->p_percent / 100;
  943. X    return 0;
  944. X}
  945. X
  946. Xtorpedo_firing(sp)
  947. Xstruct ship *sp;
  948. X{
  949. X    register int i;
  950. X    register float j;
  951. X    register int th;
  952. X    struct    torpedo *tp;
  953. X    struct    ship *target;
  954. X    struct    list *lp;
  955. X    float    bear;
  956. X    struct    ship *fed;
  957. X
  958. X    fed = shiplist[0];
  959. X    for (i=0; i<sp->num_tubes; i++) {
  960. X        if (sp->tubes[i].status & T_FIRING)
  961. X            break;
  962. X    }
  963. X    if (i == sp->num_tubes)
  964. X        return 0;
  965. X    sp->tubes[i].status &= ~T_FIRING;
  966. X    th = sp->tubes[i].load;
  967. X    if (th == 0)
  968. X        return 0;
  969. X    target = sp->tubes[i].target;
  970. X    /*
  971. X     * Put in j the relative bearing of the tubes to the ship
  972. X     * Put in bear the absolute direction the tubes are pointing
  973. X     */
  974. X    bear = sp->tubes[i].bearing + sp->course;
  975. X    j = rectify(sp->tubes[i].bearing);
  976. X    if (betw(j, sp->t_blind_left, sp->t_blind_right) && !is_dead(sp, S_ENG))
  977. X        return 0;
  978. X    if (target != NULL && (is_dead(target, S_DEAD))) {
  979. X        if ((sp == fed) && !shutup[TUBES+i] && !is_dead(sp, S_DEAD)) {
  980. X            printf("   tube %d disengaging\n", i+1);
  981. X            shutup[TUBES+i]++;
  982. X        }
  983. X        sp->tubes[i].target = NULL;
  984. X        return 0;
  985. X    }
  986. X    sp->tubes[i].load = 0;
  987. X    lp = newitem(I_TORPEDO);
  988. X    lp->type = I_TORPEDO;
  989. X    lp->data.tp = MKNODE(struct torpedo, *, 1);
  990. X    if (lp->data.tp == (struct torpedo *)NULL) {
  991. X        fprintf(stderr, "torpedo_firing: malloc failed\n");
  992. X        exit(2);
  993. X    }
  994. X    tp = lp->data.tp;
  995. X    tp->from = sp;
  996. X    tp->x = sp->x;
  997. X    tp->y = sp->y;
  998. X    tp->target = NULL;
  999. X    tp->course = rectify(bear);
  1000. X    tp->fuel = th;
  1001. X    tp->speed = sp->t_lspeed + sp->warp;
  1002. X    tp->newspeed = tp->speed;
  1003. X    tp->timedelay = (float)sp->t_delay;
  1004. X    tp->prox = sp->t_prox;
  1005. X    tp->id = new_slot();
  1006. X    tp->type = TP_TORPEDO;
  1007. X    if (teletype)
  1008. X        printf("\007");
  1009. X    if (cantsee(sp))
  1010. X        (void) e_cloak_off(sp, fed);
  1011. X    printf(" <<%s frng torpedo %d>>", sp->name, tp->id);
  1012. X    if (teletype)
  1013. X        printf("\007");
  1014. X    printf("\n");
  1015. X    return 1;
  1016. X}
  1017. X
  1018. Xint
  1019. Xship_detonate(sp, lp)
  1020. Xstruct ship *sp;
  1021. Xstruct list *lp;
  1022. X{
  1023. X    register int fuel;
  1024. X    register int i;
  1025. X
  1026. X    fuel = 0;
  1027. X    printf("++%s++ destruct.\n", sp->name);
  1028. X    for (i=0; i<sp->num_phasers; i++)
  1029. X        if (!(sp->phasers[i].status & P_DAMAGED))
  1030. X            fuel += min(sp->phasers[i].load, MAX_PHASER_CHARGE);
  1031. X    for (i=0; i<sp->num_tubes; i++)
  1032. X        if (!(sp->tubes[i].status & T_DAMAGED))
  1033. X            fuel += min(sp->tubes[i].load, MAX_TUBE_CHARGE);
  1034. X    fuel += sp->pods;
  1035. X    antimatter_hit((char *) sp, sp->x, sp->y, fuel);
  1036. X    lp->type = 0;
  1037. X    for (i=0; i< S_NUMSYSTEMS; i++)
  1038. X        sp->status[i] = 100;    /* He's dead, Jim */
  1039. X    sp->cloaking = C_NONE;
  1040. X    sp->complement = -1;
  1041. X}
  1042. X
  1043. X
  1044. Xint
  1045. Xtorp_detonate(tp, lp)
  1046. Xstruct torpedo *tp;
  1047. Xstruct list *lp;
  1048. X{
  1049. X
  1050. X    switch (lp->type) {
  1051. X        case I_TORPEDO:
  1052. X            printf(":: torp %d ::\n", tp->id);
  1053. X            break;
  1054. X        case I_PROBE:
  1055. X            printf("** probe %d **\n", tp->id);
  1056. X            break;
  1057. X        case I_ENG:
  1058. X            printf("## %s engineering ##\n", tp->from->name);
  1059. X            break;
  1060. X        default:
  1061. X            fprintf(stderr, "torp_detonate lp->type %d\n",lp->type);
  1062. X            break;
  1063. X    }
  1064. X    antimatter_hit((char *) tp, tp->x, tp->y, tp->fuel);
  1065. X    return_slot(tp->id);
  1066. X    delitem(lp);
  1067. X}
  1068. END_OF_src/firing.c
  1069. if test 5713 -ne `wc -c <src/firing.c`; then
  1070.     echo shar: \"src/firing.c\" unpacked with wrong size!
  1071. fi
  1072. # end of overwriting check
  1073. fi
  1074. if test -f src/main.c -a "${1}" != "-c" ; then 
  1075.   echo shar: Will not over-write existing file \"src/main.c\"
  1076. else
  1077. echo shar: Extracting \"src/main.c\" \(5656 characters\)
  1078. sed "s/^X//" >src/main.c <<'END_OF_src/main.c'
  1079. X#ident "@(#) TREK73 $Header: main.c,v 1.1 87/10/09 11:08:01 okamoto Exp $"
  1080. X/*
  1081. X * $Source: /ccc/okamoto/src/trek/src/RCS/main.c,v $
  1082. X *
  1083. X * $Header: main.c,v 1.1 87/10/09 11:08:01 okamoto Exp $
  1084. X *
  1085. X * $Log:    main.c,v $
  1086. X * Revision 1.1  87/10/09  11:08:01  11:08:01  okamoto (Jeff Okamoto)
  1087. X * Initial revision
  1088. X * 
  1089. X */
  1090. X/*
  1091. X * TREK73: main.c
  1092. X *
  1093. X * Originally written (in HP-2000 BASIC) by
  1094. X *    William K. Char, Perry Lee, and Dan Gee
  1095. X *
  1096. X * Rewritten in C by
  1097. X *    Dave Pare (sdcsvax!sdamos!mr-frog)
  1098. X *           (mr-frog@amos.ling.ucsd.edu)
  1099. X *        and
  1100. X *    Christopher Williams (ucbvax!ucbmerlin!williams)
  1101. X *                 (williams@merlin.berkeley.edu)
  1102. X *
  1103. X * Corrected, Completed, and Enhanced by
  1104. X *    Jeff Okamoto    (hpccc!okamoto)
  1105. X *            (hpccc!okamoto@hplabs.hp.com)
  1106. X *    Peter Yee    (ucbvax!yee)
  1107. X *            (yee@ucbarpa.berkeley.edu)
  1108. X *    Matt Dillon    (ucbvax!dillon)
  1109. X *            (dillon@ucbvax.berkeley.edu)
  1110. X *    Dave Sharnoff    (ucbvax!ucbcory!muir)
  1111. X *            (muir@cogsci.berkeley.edu)
  1112. X *    Joel Duisman
  1113. X *        and
  1114. X *    Roger J. Noe    (uniq!rjnoe)
  1115. X *            (ihnp4!uniq!rjnoe@berkeley.edu)
  1116. X *
  1117. X * Main Loop
  1118. X *
  1119. X * main, alarmtrap, quitgame, buffering
  1120. X *
  1121. X */
  1122. X
  1123. X#include "externs.h"
  1124. X#include <signal.h>
  1125. X#include <setjmp.h>
  1126. X#include <ctype.h>
  1127. X
  1128. Xstatic jmp_buf    jumpbuf;
  1129. X
  1130. X
  1131. Xmain(argc, argv, envp)
  1132. Xint argc;
  1133. Xchar *argv[];
  1134. Xchar *envp[];
  1135. X{
  1136. X    int            alarmtrap();
  1137. X    int            quitgame();
  1138. X
  1139. X    if (buffering(stdout) < 0)
  1140. X        perror("cannot fstat stdout");
  1141. X    (void) signal(SIGALRM, alarmtrap);
  1142. X    (void) signal(SIGINT, quitgame);
  1143. X    srandom(time(0));
  1144. X    time_delay = DEFAULT_TIME;
  1145. X    set_save();
  1146. X    options = getenv("TREK73OPTS");
  1147. X    if (options != NULL)
  1148. X        parse_opts(options);
  1149. X    get_comlineopts(argc, argv);
  1150. X    if (restart && savefile[0] != '\0') {
  1151. X        restore(savefile, envp);    /* Will not return */
  1152. X        exit(1);
  1153. X    }
  1154. X    name_crew();
  1155. X    init_ships();
  1156. X    (void) mission();
  1157. X    (void) alert();
  1158. X    playit();
  1159. X    /*NOTREACHED*/
  1160. X}
  1161. X
  1162. X/*
  1163. X * Main loop
  1164. X */
  1165. Xplayit()
  1166. X{
  1167. X    struct cmd        *scancmd();
  1168. X    int            alarmtrap();
  1169. X    int            quitgame();
  1170. X    register struct ship    *sp;
  1171. X#ifndef PARSER
  1172. X    char            buf1[30];
  1173. X#endif PARSER
  1174. X    struct cmd        *cp;
  1175. X    int            loop;
  1176. X    char            *ch;
  1177. X
  1178. X    (void) setjmp(jumpbuf);
  1179. X    sp = shiplist[0];
  1180. X    if (!(is_dead(sp, S_DEAD))) {
  1181. Xnext:
  1182. X        for (loop = 0; loop < HIGHSHUTUP; loop++)
  1183. X            shutup[loop] = 0;
  1184. X        fflush(stdin);
  1185. X        printf("\n%s: Code [1-%d] ", captain, high_command);
  1186. X        fflush(stdout);
  1187. X        (void) alarm((unsigned) time_delay);
  1188. X#ifdef PARSER
  1189. X        (void) Gets(Input, sizeof(Input));
  1190. X        if (Input[0] != NULL) {
  1191. X#else
  1192. X        (void) Gets(buf1, sizeof(buf1));
  1193. X        if (buf1[0] != NULL) {
  1194. X#endif PARSER
  1195. X            (void) alarm(0);
  1196. X#ifdef PARSER
  1197. X            Inptr = Input;
  1198. X            parsed[0] = '\0';
  1199. X            ch = Inptr;
  1200. X            while (isspace(*ch))
  1201. X                ch++;
  1202. X            if (isalpha(*ch))
  1203. X                yyparse();
  1204. X            else
  1205. X                strcpy(parsed, Input);
  1206. X#endif PARSER
  1207. X#ifdef PARSER
  1208. X            cp = scancmd(parsed);
  1209. X#else
  1210. X            cp = scancmd(buf1);
  1211. X#endif PARSER
  1212. X            if (cp != NULL) {
  1213. X                (*cp->routine)(sp);
  1214. X                if (cp->turns == FREE)
  1215. X                    goto next;
  1216. X            } else
  1217. X                printf("\n%s: %s, I am unable to interpret your last utterance.\n", science, title);
  1218. X        } else
  1219. X            (void) alarm(0);
  1220. X    }
  1221. X    ch = ch;        /* LINT */
  1222. X    alarmtrap(0);
  1223. X    /* This point is never reached since alarmtrap() always concludes
  1224. X       with a longjmp() back to the setjmp() above the next: label */
  1225. X    /*NOTREACHED*/
  1226. X}
  1227. X
  1228. Xalarmtrap(sig)
  1229. Xint sig;
  1230. X{
  1231. X    register int i;
  1232. X
  1233. X    if (sig) {
  1234. X        puts("\n** TIME **");
  1235. X        (void) signal(sig, alarmtrap);
  1236. X        stdin->_cnt = 0;
  1237. X    }
  1238. X    for (i = 1; i <= shipnum; i++)
  1239. X        shiplist[i]->strategy(shiplist[i]);
  1240. X    if (!(is_dead(shiplist[0], S_DEAD)))
  1241. X        printf("\n");
  1242. X    (void) move_ships();
  1243. X    (void) check_targets();
  1244. X    (void) misc_timers();
  1245. X    (void) disposition();
  1246. X    longjmp(jumpbuf, 1);
  1247. X}
  1248. X
  1249. X
  1250. Xquitgame()
  1251. X{
  1252. X    char answer[20];
  1253. X    unsigned timeleft;
  1254. X
  1255. X    timeleft = alarm(0);
  1256. X    (void) signal(SIGINT, SIG_IGN);
  1257. X    puts("\n\nDo you really wish to stop now?  Answer yes or no:");
  1258. X    (void) Gets(answer, sizeof(answer));
  1259. X    if(answer[0] == NULL || answer[0] == 'y' || answer[0] == 'Y')
  1260. X        exit(0);
  1261. X    (void) signal(SIGINT, quitgame);
  1262. X    if(timeleft)
  1263. X        (void) alarm((unsigned)timeleft);
  1264. X    return;
  1265. X}
  1266. X
  1267. X
  1268. X/* buffering: Determine whether or not stream is to be buffered.  If
  1269. X   it's a character-special device, any buffering in effect will remain.
  1270. X   If it's not a character-special device, then stream will be
  1271. X   unbuffered.  There are many ways to decide what to do here.  One
  1272. X   would have been to make it unbuffered if and only if
  1273. X   !isatty(fileno(stream)).  This is usually implemented as a single
  1274. X   ioctl() system call which returns true if the ioctl() succeeds, false
  1275. X   if it fails.  But there are ways it could fail and still be a tty.
  1276. X   Then there's also examination of stream->_flag.  UNIX is supposed to
  1277. X   make any stream attached to a terminal line-buffered and all others
  1278. X   fully buffered by default.  But sometimes even when isatty()
  1279. X   succeeds, stream->_flag indicates _IOFBF, not _IOLBF.  And even if it
  1280. X   is determined that the stream should be line buffered, setvbuf(3S)
  1281. X   doesn't work right (in UNIX 5.2) to make it _IOLBF.  So about the
  1282. X   only choice is to do a straightforward fstat() and ascertain
  1283. X   definitely to what the stream is attached.  Then go with old reliable
  1284. X   setbuf(stream, NULL) to make it _IONBF.  The whole reason this is
  1285. X   being done is because the user may be using a pipefitting program to
  1286. X   collect a "transcript" of a session (e.g. tee(1)), or redirecting to
  1287. X   a regular file and then keeping a tail(1) going forever to actually
  1288. X   play the game.  This assures that the output will keep pace with the
  1289. X   execution with no sacrifice in efficiency for normal execution. [RJN]
  1290. X*/
  1291. X
  1292. X#include <sys/types.h>
  1293. X#include <sys/stat.h>
  1294. X
  1295. Xint
  1296. Xbuffering(stream)
  1297. XFILE    *stream;
  1298. X{
  1299. X    struct stat    st;
  1300. X    if (fstat(fileno(stream), &st) < 0)
  1301. X        return -1;
  1302. X    if ((st.st_mode & S_IFMT) != S_IFCHR)
  1303. X        setbuf(stream, NULL);
  1304. X    return 0;
  1305. X}
  1306. END_OF_src/main.c
  1307. if test 5656 -ne `wc -c <src/main.c`; then
  1308.     echo shar: \"src/main.c\" unpacked with wrong size!
  1309. fi
  1310. # end of overwriting check
  1311. fi
  1312. if test -f src/misc.c -a "${1}" != "-c" ; then 
  1313.   echo shar: Will not over-write existing file \"src/misc.c\"
  1314. else
  1315. echo shar: Extracting \"src/misc.c\" \(6183 characters\)
  1316. sed "s/^X//" >src/misc.c <<'END_OF_src/misc.c'
  1317. X#ident "@(#) TREK73 $Header: misc.c,v 1.1 87/10/09 11:08:09 okamoto Exp $"
  1318. X/*
  1319. X * $Source: /ccc/okamoto/src/trek/src/RCS/misc.c,v $
  1320. X *
  1321. X * $Header: misc.c,v 1.1 87/10/09 11:08:09 okamoto Exp $
  1322. X *
  1323. X * $Log:    misc.c,v $
  1324. X * Revision 1.1  87/10/09  11:08:09  11:08:09  okamoto (Jeff Okamoto)
  1325. X * Initial revision
  1326. X * 
  1327. X */
  1328. X/*
  1329. X * TREK73: misc.c
  1330. X *
  1331. X * Miscellaneous Routines
  1332. X *
  1333. X * help, scancmd, new_slot, return_slot, vowelstr,
  1334. X * check_p_damage, check_t_damage, check_p_turn, check_t_turn,
  1335. X * ship_class
  1336. X *
  1337. X */
  1338. X
  1339. X#include "externs.h"
  1340. X
  1341. Xint
  1342. Xhelp(dummy)
  1343. Xstruct ship *dummy;
  1344. X{
  1345. X    struct cmd    *cpbegin, *cpmiddle;
  1346. X
  1347. X    puts("\nTrek73 Commands:");
  1348. X    puts(
  1349. X"Code        Command            Code        Command");
  1350. X    putchar('\n');
  1351. X    cpbegin = &cmds[0];
  1352. X    cpmiddle = &cmds[(cmdarraysize + 1) >> 1];
  1353. X    while (cpmiddle->routine != NULL) {
  1354. X        printf("%3s:  %c %-31s:%3s:  %c %-31s\n",
  1355. X            cpbegin->code_num, ((cpbegin->turns) ? ' ' : '*'),
  1356. X            cpbegin->explanation, cpmiddle->code_num,
  1357. X            ((cpmiddle->turns) ? ' ' : '*'),
  1358. X            cpmiddle->explanation);
  1359. X        cpbegin++;
  1360. X        cpmiddle++;
  1361. X    }
  1362. X    if (cmdarraysize & 1)
  1363. X        printf("%3s:  %c %-31s", cpbegin->code_num,
  1364. X            ((cpbegin->turns) ? ' ' : '*'),
  1365. X            cpbegin->explanation);
  1366. X    puts("\n\n * does not use a turn");
  1367. X    dummy = dummy;                /* LINT */
  1368. X}
  1369. X
  1370. Xstruct cmd *
  1371. Xscancmd(buf)
  1372. Xchar *buf;
  1373. X{
  1374. X    static char **argp = NULL;
  1375. X    struct    cmd *cp;
  1376. X    int    argnum;
  1377. X    int    first;
  1378. X
  1379. X    argnum = parsit(buf, &argp);
  1380. X    first = strlen(argp[0]);
  1381. X    if (argnum && first)
  1382. X        for (cp = &cmds[0]; cp->routine != NULL; cp++)
  1383. X            if (!strncmp(argp[0], cp->code_num, first))
  1384. X                return (cp);
  1385. X    return (NULL);
  1386. X}
  1387. X
  1388. X/*
  1389. X * This routine handles getting unique identifier numbers for
  1390. X * all objects.
  1391. X */
  1392. Xint
  1393. Xnew_slot()
  1394. X{
  1395. X    /*
  1396. X     * This is to make it appear that in a 2-ship duel, for
  1397. X     * instance, the first object to appear will be numbered
  1398. X     * as 3.
  1399. X     */
  1400. X    int i = shipnum + 2;
  1401. X
  1402. X    while ((slots[i] == 'X') && (i <= HIGHSLOT))
  1403. X        i++;
  1404. X    if (i > HIGHSLOT) {
  1405. X        puts("The game will terminate now due to an inability to handle the number of");
  1406. X        puts("objects in space (i.e. vessels, torpedoes, probes, etc).  Sorry!");
  1407. X        exit(-1);
  1408. X    }
  1409. X    slots[i] = 'X';
  1410. X    return i;
  1411. X}
  1412. X
  1413. X/* 
  1414. X * This routine handles returning identifiers
  1415. X */
  1416. Xint
  1417. Xreturn_slot(i)
  1418. Xint i;
  1419. X{
  1420. X    if (slots[i] != 'X')
  1421. X        printf("FATAL ERROR - Slot already empty!");
  1422. X    slots[i] = ' ';
  1423. X}
  1424. X
  1425. X
  1426. Xchar *
  1427. Xvowelstr(str)
  1428. Xchar *str;
  1429. X{
  1430. X    switch(*str) {
  1431. X        case 'a': case 'A':
  1432. X        case 'e': case 'E':
  1433. X        case 'i': case 'I':
  1434. X        case 'o': case 'O':
  1435. X        case 'u': case 'U':
  1436. X            return "n";
  1437. X        default:
  1438. X            return "";
  1439. X    }
  1440. X}
  1441. X
  1442. X
  1443. X/*
  1444. X * This routine takes an array generated from commands 1, 3, and 5
  1445. X * to print out a list of those phasers damaged and unable to
  1446. X * either fire, lock, or turn.
  1447. X */
  1448. Xint
  1449. Xcheck_p_damage(array, sp, string)
  1450. Xint array[];
  1451. Xstruct ship *sp;
  1452. Xchar *string;
  1453. X{
  1454. X    int i, j;
  1455. X
  1456. X    j = 0;
  1457. X    for (i=0; i<sp->num_phasers; i++) {
  1458. X        if (array[i] && (sp->phasers[i].status & P_DAMAGED)) {
  1459. X            if (!j)
  1460. X                printf("Computer: Phaser(s) %d", i+1);
  1461. X            else
  1462. X                printf(", %d", i+1);
  1463. X            j++;
  1464. X        }
  1465. X    }
  1466. X    if (j > 1)
  1467. X        printf(" are damaged and unable to %s.\n", string);
  1468. X    else if (j == 1)
  1469. X        printf(" is damaged and unable to %s.\n", string);
  1470. X}
  1471. X
  1472. X/*
  1473. X * This routine takes an array generated from commands 2, 4, and 6
  1474. X * to print out a list of those tubes damaged and unable to either
  1475. X * fire, lock, or turn.
  1476. X */
  1477. Xint
  1478. Xcheck_t_damage(array, sp, string)
  1479. Xint array[];
  1480. Xstruct ship *sp;
  1481. Xchar *string;
  1482. X{
  1483. X    int i, j;
  1484. X
  1485. X    j = 0;
  1486. X    for (i=0; i<sp->num_tubes; i++) {
  1487. X        if (array[i] && (sp->tubes[i].status & P_DAMAGED)) {
  1488. X            if (!j)
  1489. X                printf("Computer: Tube(s) %d", i+1);
  1490. X            else
  1491. X                printf(", %d", i+1);
  1492. X            j++;
  1493. X        }
  1494. X    }
  1495. X    if (j > 1)
  1496. X        printf(" are damaged and unable to %s.\n", string);
  1497. X    else if (j == 1)
  1498. X        printf(" is damaged and unable to %s.\n", string);
  1499. X}
  1500. X
  1501. X/*
  1502. X * This routine checks to see if a phaser is pointing into our
  1503. X * blind side
  1504. X */
  1505. Xint
  1506. Xcheck_p_turn(array, sp, flag)
  1507. Xint array[];
  1508. Xstruct ship *sp;
  1509. Xint flag;            /* If 1, came from fire_phasers */
  1510. X{
  1511. X    register int i;
  1512. X    register int j;
  1513. X    register float k;
  1514. X    register float bear;
  1515. X    struct ship *target;
  1516. X
  1517. X    j = 0;
  1518. X    for (i=0; i<sp->num_phasers; i++) {
  1519. X        if (!array[i])
  1520. X            continue;
  1521. X        if (flag && !(sp->phasers[i].status & P_FIRING))
  1522. X            continue;
  1523. X        target = sp->phasers[i].target;
  1524. X        /*
  1525. X         * This hack is here since when the phaser is locked,
  1526. X         * the bearing points at the target, whereas when
  1527. X         * not locked, the bearing is relative to the ship.
  1528. X         */
  1529. X        if (target == NULL) {
  1530. X            bear = sp->phasers[i].bearing + sp->course;
  1531. X            k = sp->phasers[i].bearing;
  1532. X        } else {
  1533. X            bear = bearing(sp->x, target->x, sp->y, target->y);
  1534. X            k = bear - sp->course;
  1535. X        }
  1536. X        k = rectify(k);
  1537. X
  1538. X        if (betw(k, sp->p_blind_left, sp->p_blind_right)
  1539. X            && !(is_dead(sp, S_ENG))) {
  1540. X            if (!j)
  1541. X                printf("Computer: Phaser(s) %d", i + 1);
  1542. X            else
  1543. X                printf(", %d", i + 1);
  1544. X            j++;
  1545. X        }
  1546. X    }
  1547. X    if (j > 1)
  1548. X        printf(" are pointing into our blind side.\n");
  1549. X    else if (j == 1)
  1550. X        printf(" is pointing into our blind side.\n");
  1551. X}
  1552. X
  1553. X/*
  1554. X * This routine checks to see if a tube is turned into
  1555. X * our blind side.
  1556. X */
  1557. Xint
  1558. Xcheck_t_turn(array, sp, flag)
  1559. Xint array[];
  1560. Xstruct ship *sp;
  1561. Xint flag;            /* If 1, came from fire_tubes */
  1562. X{
  1563. X    register int i;
  1564. X    register int j;
  1565. X    register float k;
  1566. X    register float bear;
  1567. X    struct ship *target;
  1568. X
  1569. X    j = 0;
  1570. X    for (i=0; i<sp->num_tubes; i++) {
  1571. X        if (!array[i])
  1572. X            continue;
  1573. X        if (flag && !(sp->tubes[i].status & T_FIRING))
  1574. X            continue;
  1575. X        target = sp->tubes[i].target;
  1576. X        /*
  1577. X         * This hack is here since when the tube is locked,
  1578. X         * the bearing points at the target, whereas when
  1579. X         * not locked, the bearing is relative to the ship.
  1580. X         */
  1581. X        if (target == NULL) {
  1582. X            bear = sp->tubes[i].bearing + sp->course;
  1583. X            k = sp->tubes[i].bearing;
  1584. X        } else {
  1585. X            bear = bearing(sp->x, target->x, sp->y, target->y);
  1586. X            k = bear - sp->course;
  1587. X        }
  1588. X        k = rectify(k);
  1589. X        if (betw(k, sp->t_blind_left, sp->t_blind_right) && !(is_dead(sp, S_ENG))) {
  1590. X            if (!j)
  1591. X                printf("Computer: Tubes(s) %d", i + 1);
  1592. X            else
  1593. X                printf(", %d", i + 1);
  1594. X            j++;
  1595. X        }
  1596. X    }
  1597. X    if (j > 1)
  1598. X        printf(" are pointing into our blind side.\n");
  1599. X    else if (j == 1)
  1600. X        printf(" is pointing into our blind side.\n");
  1601. X}
  1602. X
  1603. Xstruct ship_stat *
  1604. Xship_class(s)
  1605. Xchar *s;
  1606. X{
  1607. X    int i;
  1608. X
  1609. X    for (i = 0; i< MAXSHIPCLASS; i++)
  1610. X        if (!strcmp(stats[i].abbr, s)) {
  1611. X            return(&stats[i]);
  1612. X        }
  1613. X    return(NULL);
  1614. X}
  1615. END_OF_src/misc.c
  1616. if test 6183 -ne `wc -c <src/misc.c`; then
  1617.     echo shar: \"src/misc.c\" unpacked with wrong size!
  1618. fi
  1619. # end of overwriting check
  1620. fi
  1621. if test -f src/parseopts.c -a "${1}" != "-c" ; then 
  1622.   echo shar: Will not over-write existing file \"src/parseopts.c\"
  1623. else
  1624. echo shar: Extracting \"src/parseopts.c\" \(5823 characters\)
  1625. sed "s/^X//" >src/parseopts.c <<'END_OF_src/parseopts.c'
  1626. X#ident "@(#) TREK73 $Header: parseopts.c,v 1.2 87/11/23 09:19:40 okamoto Exp $"
  1627. X/*
  1628. X * $Source: /ccc/okamoto/src/trek/src/RCS/parseopts.c,v $
  1629. X *
  1630. X * $Header: parseopts.c,v 1.2 87/11/23 09:19:40 okamoto Exp $
  1631. X *
  1632. X * $Log:    parseopts.c,v $
  1633. X * Revision 1.2  87/11/23  09:19:40  09:19:40  okamoto (Jeff Okamoto)
  1634. X * Removed include to options.h since they are now in defines.h.
  1635. X * 
  1636. X * Revision 1.1  87/10/09  11:09:49  11:09:49  okamoto (Jeff Okamoto)
  1637. X * Initial revision
  1638. X * 
  1639. X */
  1640. X/*
  1641. X * TREK73: parseopts.c
  1642. X *
  1643. X * Parse the environment variable TREK73OPTS and command line options
  1644. X *
  1645. X * parse_opts, get_comlineopts
  1646. X */
  1647. X
  1648. X#include <ctype.h>
  1649. X#include <stdio.h>
  1650. X#include "externs.h"
  1651. X
  1652. X#define    EQSTR(a, b, c)    (strncmp(a, b, c) == 0)
  1653. X
  1654. X#define    NUM_OPTS    (sizeof optlist / sizeof (OPTION))
  1655. X
  1656. X/*
  1657. X * description of an option and what to do with it
  1658. X */
  1659. Xstruct optstruct {
  1660. X    char    *o_name;    /* option name */
  1661. X    int        *o_opt;        /* pointer to thing to set */
  1662. X    int        o_type;        /* Boolean or string */
  1663. X};
  1664. X
  1665. Xtypedef struct optstruct    OPTION;
  1666. X
  1667. X
  1668. XOPTION    optlist[] = {
  1669. X    {"terse",     (int *)&terse, BOOLEAN},
  1670. X    {"name", (int *)captain, STRING},
  1671. X    {"sex", (int *)sex, STRING},
  1672. X    {"science", (int *)science, STRING},
  1673. X    {"engineer", (int *)engineer, STRING},
  1674. X    {"com", (int *)com, STRING},
  1675. X    {"nav", (int *)nav, STRING},
  1676. X    {"helmsman", (int *)helmsman, STRING},
  1677. X    {"shipname", (int *)shipname, STRING},
  1678. X    {"enemy", (int *)racename, STRING},
  1679. X    {"foename", (int *)foename, STRING},
  1680. X    {"silly", (int *)&silly, BOOLEAN},
  1681. X    {"class", (int *)class, STRING},
  1682. X    {"foeclass", (int *)foeclass, STRING},
  1683. X    {"time", (int *)com_delay, STRING},
  1684. X    {"teletype", (int *)&teletype, BOOLEAN},
  1685. X    {"trace", (int *)&trace, BOOLEAN},
  1686. X    {"savefile", (int *)savefile, STRING}
  1687. X};
  1688. X
  1689. X/*
  1690. X * parse_opts:
  1691. X *    Parse options from string, usually taken from the environment.
  1692. X *    The string is a series of comma separated values, with booleans
  1693. X *    being stated as "name" (true) or "noname" (false), and strings
  1694. X *    being "name=....", with the string being defined up to a comma
  1695. X *    or the end of the entire option string.
  1696. X */
  1697. Xparse_opts(str)
  1698. Xregister char *str;
  1699. X{
  1700. X    register char *sp;
  1701. X    register OPTION *op;
  1702. X    register int len;
  1703. X
  1704. X    while (*str)
  1705. X    {
  1706. X    /*
  1707. X     * Get option name
  1708. X     */
  1709. X    for (sp = str; isascii(*sp) && isalpha(*sp); sp++)
  1710. X        continue;
  1711. X    len = sp - str;
  1712. X    /*
  1713. X     * Look it up and deal with it
  1714. X     */
  1715. X    for (op = optlist; op < &optlist[NUM_OPTS]; op++)
  1716. X        if (EQSTR(str, op->o_name, len))
  1717. X        {
  1718. X        if (op->o_type == BOOLEAN)    /* if option is a boolean */
  1719. X            *op->o_opt = 1;
  1720. X        else                /* string option */
  1721. X        {
  1722. X            register char *start;
  1723. X            /*
  1724. X             * Skip to start of string value
  1725. X             */
  1726. X            for (str = sp + 1; *str == '='; str++)
  1727. X            continue;
  1728. X            start = (char *) op->o_opt;
  1729. X            /*
  1730. X             * Skip to end of string value
  1731. X             */
  1732. X            for (sp = str + 1; *sp && *sp != ','; sp++)
  1733. X            continue;
  1734. X            strucpy(start, str, sp - str);
  1735. X        }
  1736. X        break;
  1737. X        }
  1738. X        /*
  1739. X         * check for "noname" for booleans
  1740. X         */
  1741. X        else if (op->o_type == BOOLEAN
  1742. X          && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2))
  1743. X        {
  1744. X        *op->o_opt = 0;
  1745. X        break;
  1746. X        }
  1747. X
  1748. X    /*
  1749. X     * skip to start of next option name
  1750. X     */
  1751. X    while (*sp && !(isascii(*sp) && isalpha(*sp)))
  1752. X        sp++;
  1753. X    str = sp;
  1754. X    }
  1755. X}
  1756. X
  1757. X/*
  1758. X * strucpy:
  1759. X *    Copy string using unctrl for things
  1760. X */
  1761. Xstrucpy(s1, s2, len)
  1762. Xregister char *s1, *s2;
  1763. Xregister int len;
  1764. X{
  1765. X    if (len > 100)
  1766. X    len = 100;
  1767. X    while (len--)
  1768. X    {
  1769. X    if (isascii(*s2) && isprint(*s2))
  1770. X        *s1++ = *s2;
  1771. X    s2++;
  1772. X    }
  1773. X    *s1 = '\0';
  1774. X}
  1775. X
  1776. Xget_comlineopts(argc, argv)
  1777. Xint argc;
  1778. Xchar *argv[];
  1779. X{
  1780. X    int c;
  1781. X    char *opts = "Rtc:s:S:E:C:N:H:f:r:d:yTn:F:l:v";
  1782. X    int errflg = 0;
  1783. X
  1784. X    while ((c = getopt(argc, argv, opts)) != EOF) {
  1785. X        switch(c) {
  1786. X        case 'R':
  1787. X            restart = 1;
  1788. X            break;
  1789. X        case 't':
  1790. X            terse = 1;
  1791. X            break;
  1792. X        case 'c':
  1793. X            (void) strncpy(captain, optarg, sizeof captain);
  1794. X            captain[sizeof captain - 1] = '\0';
  1795. X            break;
  1796. X        case 's':
  1797. X            (void) strncpy(sex, optarg, sizeof sex);
  1798. X            sex[sizeof sex - 1] = '\0';
  1799. X            break;
  1800. X        case 'S':
  1801. X            (void) strncpy(science, optarg, sizeof science);
  1802. X            science[sizeof science - 1] = '\0';
  1803. X            break;
  1804. X        case 'E':
  1805. X            (void) strncpy(engineer, optarg, sizeof engineer);
  1806. X            engineer[sizeof engineer - 1] = '\0';
  1807. X            break;
  1808. X        case 'C':
  1809. X            (void) strncpy(com, optarg, sizeof com);
  1810. X            com[sizeof com - 1] = '\0';
  1811. X            break;
  1812. X        case 'N':
  1813. X            (void) strncpy(nav, optarg, sizeof nav);
  1814. X            nav[sizeof nav - 1] = '\0';
  1815. X            break;
  1816. X        case 'H':
  1817. X            (void) strncpy(helmsman, optarg, sizeof helmsman);
  1818. X            helmsman[sizeof helmsman - 1] = '\0';
  1819. X            break;
  1820. X        case 'f':
  1821. X            (void) strncpy(foename, optarg, sizeof foename);
  1822. X            foename[sizeof foename - 1] = '\0';
  1823. X            break;
  1824. X        case 'r':
  1825. X            (void) strncpy(racename, optarg, sizeof racename);
  1826. X            racename[sizeof racename - 1] = '\0';
  1827. X            break;
  1828. X        case 'd':
  1829. X            (void) strncpy(com_delay, optarg, sizeof com_delay);
  1830. X            com_delay[sizeof com_delay - 1] = '\0';
  1831. X            break;
  1832. X        case 'y':
  1833. X            silly = 1;
  1834. X            break;
  1835. X        case 'T':
  1836. X            teletype = 1;
  1837. X            break;
  1838. X        case 'n':
  1839. X            (void) strncpy(shipname, optarg, sizeof shipname);
  1840. X            shipname[sizeof shipname - 1] = '\0';
  1841. X            break;
  1842. X        case 'F':
  1843. X            (void) strncpy(foeclass, optarg, sizeof foeclass);
  1844. X            foeclass[sizeof foeclass - 1] = '\0';
  1845. X            break;
  1846. X        case 'l':
  1847. X            (void) strncpy(class, optarg, sizeof class);
  1848. X            class[sizeof class - 1] = '\0';
  1849. X            break;
  1850. X        case 'v':
  1851. X            trace = TR_ON;
  1852. X            break;
  1853. X        case '?':
  1854. X        default:
  1855. X            errflg++;
  1856. X            break;
  1857. X        }
  1858. X    }
  1859. X    if (errflg) {
  1860. X        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");
  1861. X        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");
  1862. X        fprintf(stderr, "       or trek73 -R");
  1863. X        exit(1);
  1864. X    }
  1865. X}
  1866. END_OF_src/parseopts.c
  1867. if test 5823 -ne `wc -c <src/parseopts.c`; then
  1868.     echo shar: \"src/parseopts.c\" unpacked with wrong size!
  1869. fi
  1870. # end of overwriting check
  1871. fi
  1872. if test -f src/ships.c -a "${1}" != "-c" ; then 
  1873.   echo shar: Will not over-write existing file \"src/ships.c\"
  1874. else
  1875. echo shar: Extracting \"src/ships.c\" \(923 characters\)
  1876. sed "s/^X//" >src/ships.c <<'END_OF_src/ships.c'
  1877. X#ident "@(#) TREK73 $Header: ships.c,v 1.1 87/10/09 15:55:36 okamoto Exp $"
  1878. X/*
  1879. X * $Source: /ccc/okamoto/src/trek/src/RCS/ships.c,v $
  1880. X *
  1881. X * $Header: ships.c,v 1.1 87/10/09 15:55:36 okamoto Exp $
  1882. X *
  1883. X * $Log:    ships.c,v $
  1884. X * Revision 1.1  87/10/09  15:55:36  15:55:36  okamoto (Jeff Okamoto)
  1885. X * Initial revision
  1886. X * 
  1887. X */
  1888. X/*
  1889. X * TREK73: ships.c
  1890. X *
  1891. X * Global Ship Defs for TREK73
  1892. X *
  1893. X */
  1894. X
  1895. X#include "externs.h"
  1896. X
  1897. X/*
  1898. X * starting stats for the ships depending on the type
  1899. X */
  1900. X
  1901. Xstruct ship_stat stats[] = {
  1902. X{ "DN", 0, 6, 8, 8,  10, 2.,   1.5,  15., 200, 300, 600, 450, 5., 4.,  2, 4,
  1903. X   135, 225, 125, 235, 4, 4},
  1904. X{ "CA", 1, 4, 6, 9,  11, 1.,   0.75, 10., 150, 200, 450, 350, 3., 2.,  5, 2,
  1905. X   135, 225, 125, 235, 4, 4},
  1906. X{ "CL", 2, 4, 4, 9,  11, 0.75, 0.5,  10., 125, 175, 350, 250, 3., 2.,  6, 2,
  1907. X   150, 210, 140, 220, 4, 4},
  1908. X{ "DD", 3, 2, 4, 10, 12, 0.5,  0.5,  8.,  100, 150, 200, 150, 2., 1.5, 7, 1,
  1909. X   160, 200, 150, 210, 4, 4}
  1910. X};
  1911. END_OF_src/ships.c
  1912. if test 923 -ne `wc -c <src/ships.c`; then
  1913.     echo shar: \"src/ships.c\" unpacked with wrong size!
  1914. fi
  1915. # end of overwriting check
  1916. fi
  1917. if test -f src/shipyard.c -a "${1}" != "-c" ; then 
  1918.   echo shar: Will not over-write existing file \"src/shipyard.c\"
  1919. else
  1920. echo shar: Extracting \"src/shipyard.c\" \(5516 characters\)
  1921. sed "s/^X//" >src/shipyard.c <<'END_OF_src/shipyard.c'
  1922. X#ident "@(#) TREK73 $Header: shipyard.c,v 1.2 87/11/30 09:36:35 okamoto Exp $"
  1923. X/*
  1924. X * $Source: /ccc/okamoto/src/trek/src/RCS/shipyard.c,v $
  1925. X *
  1926. X * $Header: shipyard.c,v 1.2 87/11/30 09:36:35 okamoto Exp $
  1927. X *
  1928. X * $Log:    shipyard.c,v $
  1929. X * Revision 1.2  87/11/30  09:36:35  09:36:35  okamoto (Jeff Okamoto)
  1930. X * Fixed some warnings from cc on advice of Bill Randle.
  1931. X * 
  1932. X * Revision 1.1  87/10/09  11:11:13  11:11:13  okamoto (Jeff Okamoto)
  1933. X * Initial revision
  1934. X * 
  1935. X */
  1936. X/*
  1937. X * TREK73: shipyard.c
  1938. X *
  1939. X * Design your own ship
  1940. X *
  1941. X */
  1942. X
  1943. X#include <stdio.h>
  1944. X#include <fcntl.h>
  1945. X#include "externs.h"
  1946. X
  1947. Xchar buf[20];
  1948. Xchar class[3];
  1949. Xchar cloak;
  1950. Xdouble bpv;
  1951. X
  1952. Xstruct {
  1953. X    char description[30];
  1954. X    char race[30];
  1955. X    char empire[30];
  1956. X} stuff;
  1957. X
  1958. Xstruct ship_stat design;
  1959. X
  1960. Xmain()
  1961. X{
  1962. X    double regen, efficiency, atof();
  1963. X    int crew, phasers, torps, pods, max_speed, turn, p_div, t_div;
  1964. X    int done, atoi();
  1965. X    void calculate();
  1966. X
  1967. Xtryagain:
  1968. X    done = 0;
  1969. X    while (!done) {
  1970. X        printf("Regeneration               :");
  1971. X        (void) gets(buf);
  1972. X        regen = atof(buf);
  1973. X        if (regen >= 0)
  1974. X            done = 1;
  1975. X        else
  1976. X            printf(">>> Be reasonable.\n");
  1977. X    }
  1978. X    done = 0;
  1979. X    while (!done) {
  1980. X        printf("Pods                       :");
  1981. X        (void) gets(buf);
  1982. X        pods = atof(buf);
  1983. X        if (pods >= 0)
  1984. X            done = 1;
  1985. X        else
  1986. X            printf(">>> Be reasonable.\n");
  1987. X    }
  1988. X    done = 0;
  1989. X    while (!done) {
  1990. X        printf("Number of phasers          :");
  1991. X        (void) gets(buf);
  1992. X        phasers = atoi(buf);
  1993. X        if ((phasers >= 0) && (phasers < MAXWEAPONS))
  1994. X            done = 1;
  1995. X        else
  1996. X            if (phasers < 0)
  1997. X                printf(">>> Be reasonable.\n");
  1998. X            else
  1999. X                printf(">>> Can't have more than %d.\n",
  2000. X                    MAXWEAPONS-1);
  2001. X    }
  2002. X    done = 0;
  2003. X    while (!done) {
  2004. X        printf("Number of tubes            :");
  2005. X        (void) gets(buf);
  2006. X        torps = atoi(buf);
  2007. X        if ((torps >= 0) && (torps < MAXWEAPONS))
  2008. X            done = 1;
  2009. X        else
  2010. X            if (torps < 0)
  2011. X                printf(">>> Be reasonable.\n");
  2012. X            else
  2013. X                printf(">>> Can't have more than %d.\n",
  2014. X                    MAXWEAPONS-1);
  2015. X    }
  2016. X    done = 0;
  2017. X    while (!done) {
  2018. X        printf("Shield divisor for phasers :");
  2019. X        (void) gets(buf);
  2020. X        p_div = atof(buf);
  2021. X        if (p_div > 0)
  2022. X            done = 1;
  2023. X        else
  2024. X            printf(">>> Be reasonable.\n");
  2025. X    }
  2026. X    done = 0;
  2027. X    while (!done) {
  2028. X        printf("Shield divisor for torps   :");
  2029. X        (void) gets(buf);
  2030. X        t_div = atof(buf);
  2031. X        if (t_div > 0)
  2032. X            done = 1;
  2033. X        else
  2034. X            printf(">>> Be reasonable.\n");
  2035. X    }
  2036. X    done = 0;
  2037. X    while (!done) {
  2038. X        printf("Crew                       :");
  2039. X        (void) gets(buf);
  2040. X        crew = atoi(buf);
  2041. X        if (crew > 0)
  2042. X            done = 1;
  2043. X        else
  2044. X            printf(">>> Be reasonable.\n");
  2045. X    }
  2046. X    printf("Can the ship cloak         ?");
  2047. X    (void) gets(buf);
  2048. X    if (buf != NULL && (buf[0] == 'y' || buf[0] == 'Y'))
  2049. X        cloak = 1;
  2050. X    else
  2051. X        cloak = 0;
  2052. X
  2053. X    calculate(regen, (float)pods, (float)p_div, (float)t_div,
  2054. X        phasers + torps, crew,
  2055. X        &bpv, &efficiency, &turn, &max_speed);
  2056. X
  2057. X    printf("BPV = %.2f\n", bpv);
  2058. X    printf("Efficiency = %.2f\n", efficiency);
  2059. X    printf("Turn = %d\n", turn);
  2060. X    printf("Max speed = %d\n", max_speed);
  2061. X
  2062. X    printf("\nKeep this ship? ");
  2063. X    (void) gets(buf);
  2064. X    if (buf != NULL && (buf[0] == 'n' || buf[0] == 'N'))
  2065. X        goto tryagain;
  2066. X
  2067. X    printf("Class identifier           :");
  2068. X    (void) gets(class);
  2069. X    class[2] = '\0';
  2070. X    printf("Class description          :");
  2071. X    (void) gets(stuff.description);
  2072. X    stuff.description[29] = '\0';
  2073. X    printf("Race name                  :");
  2074. X    (void) gets(stuff.race);
  2075. X    stuff.race[29] = '\0';
  2076. X    printf("Empire name                :");
  2077. X    (void) gets(stuff.empire);
  2078. X    stuff.empire[29] = '\0';
  2079. X
  2080. X    strcpy(design.abbr, class);
  2081. X    design.num_phaser = phasers;
  2082. X    design.num_torp = torps;
  2083. X    /*
  2084. X     * The maximum warp speed for an "enemy" version of this class
  2085. X     * is 2 greater than the "good-guys" version, just as the
  2086. X     * standard class ships are
  2087. X     */
  2088. X    design.o_warpmax = max_speed;
  2089. X    design.e_warpmax = max_speed + 2;
  2090. X    /*
  2091. X     * "Enemy" efficiency is harder to gauge.  It should never
  2092. X     * be less than zero, but should be less than the player's
  2093. X     * version, otherwise the player could run away forever.
  2094. X     * Until a good method is devised, we'll just leave it equal
  2095. X     * to the player's own
  2096. X     */
  2097. X    design.o_eff = efficiency;
  2098. X    design.e_eff = efficiency;
  2099. X    design.regen = regen;
  2100. X    /*
  2101. X     * The starting energy is arbitrarily put at 75% of maximum
  2102. X     */
  2103. X    design.energy = pods * 3 / 4;
  2104. X    design.pods = pods;
  2105. X    /*
  2106. X     * The enemy crew is numbered at 25% greater than your own
  2107. X     */
  2108. X    design.o_crew = crew;
  2109. X    design.e_crew = crew * 5 / 4;
  2110. X    design.ph_shield = p_div;
  2111. X    design.tp_shield = t_div;
  2112. X    design.turn_rate = turn;
  2113. X    /*
  2114. X     * The cloaking energy is arbitrary
  2115. X     */
  2116. X    design.cloaking_energy = 4;
  2117. X    /*
  2118. X     * The blind arcs and firing delays after voiding a cloak
  2119. X     * are arbitrarily set as equal to those of the heavy cruiser.
  2120. X     * A better algorithm should be devised.
  2121. X     */
  2122. X    design.t_blind_left = 135;
  2123. X    design.t_blind_right = 225;
  2124. X    design.p_blind_left = 125;
  2125. X    design.p_blind_right = 235;
  2126. X    design.p_firing_delay = CLOAK_DELAY;
  2127. X    design.t_firing_delay = CLOAK_DELAY;
  2128. X
  2129. X    save_design();
  2130. X}
  2131. X
  2132. Xsave_design()
  2133. X{
  2134. X    int fd, bytes;
  2135. X    char path[BUFSIZ];
  2136. X    char *home, *getenv();
  2137. X
  2138. X    if ((home = getenv("HOME")) != NULL)
  2139. X        strcpy(path, home);
  2140. X    else
  2141. X        strcpy(path, ".");
  2142. X    
  2143. X    strcat(path, "/.trek");
  2144. X    strcat(path, design.abbr);
  2145. X    printf("Saving to file %s\n", path);
  2146. X    
  2147. X    if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
  2148. X        perror("open");
  2149. X        exit(1);
  2150. X    }
  2151. X    bytes = write(fd, (char *)&design, sizeof(struct ship_stat));
  2152. X    if (bytes != sizeof(struct ship_stat)) {
  2153. X        fprintf(stderr, "Wrote only %d, not %d bytes\n", bytes,
  2154. X            sizeof(struct ship_stat));
  2155. X        unlink(path);
  2156. X        exit(1);
  2157. X    }
  2158. X    bytes = write(fd, &stuff, sizeof(stuff));
  2159. X    bytes = write(fd, &cloak, 1);
  2160. X    bytes = write(fd, (char *)&bpv, sizeof(int));
  2161. X    close(fd);
  2162. X}
  2163. END_OF_src/shipyard.c
  2164. if test 5516 -ne `wc -c <src/shipyard.c`; then
  2165.     echo shar: \"src/shipyard.c\" unpacked with wrong size!
  2166. fi
  2167. # end of overwriting check
  2168. fi
  2169. echo shar: End of archive 4 \(of 6\).
  2170. cp /dev/null ark4isdone
  2171. MISSING=""
  2172. for I in 1 2 3 4 5 6 ; do
  2173.     if test ! -f ark${I}isdone ; then
  2174.     MISSING="${MISSING} ${I}"
  2175.     fi
  2176. done
  2177. if test "${MISSING}" = "" ; then
  2178.     echo You have unpacked all 6 archives.
  2179.     rm -f ark[1-9]isdone
  2180. else
  2181.     echo You still need to unpack the following archives:
  2182.     echo "        " ${MISSING}
  2183. fi
  2184. ##  End of shell archive.
  2185. exit 0
  2186.