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

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

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



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 4 (of 6)."
# Contents:  man/01.t man/04.t src/cmds3.c src/firing.c src/main.c
#   src/misc.c src/parseopts.c src/ships.c src/shipyard.c
# Wrapped by billr@tekred on Thu Dec 17 11:43:36 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f man/01.t -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/01.t\"
else
echo shar: Extracting \"man/01.t\" \(6955 characters\)
sed "s/^X//" >man/01.t <<'END_OF_man/01.t'
X.ce
XDetailed Descriptions of Each Command
X.sp
X.PP
XWhat follows is a detailed description of each command.
XEach command is referred to by a number from 1 to 31.
XAfter the name of the command is given, a synopsis of the
Xarguments the command requires is given, if any.
XThese arguments can be entered on the command line, separated
Xby whitespace, if you wish.
XFor instance, to fire phasers 1 through 4 with a spread of 15,
Xyou could type '1 1234 15' on the command line.
X.PP
XIt should be noted that all numbers refer to parameters for
Xthe Heavy Cruiser Class ship, and that other ships have
Xslightly different characteristics.
X.sp
X.LP
X1.  Fire Phasers.
X.PP
X[Phasers | all] [Spread]
X.PP
XPhasers are pure energy units which emit
Xa beam similar to lasers, but of a pulsating nature which
Xcan be `phased' to interfere with the wave pattern of any
Xmolecular form.
XPhasers get their power from phaser banks, which in turn,
Xderive their power from the ship's engines.
XEach phaser bank is capable of holding a charge of 10 units.
XWhen firing, these banks discharge, similar to batteries, to
Xspread their destructive power through space.
XAfter discharging, these banks are then recharged by the
Xengines.
XEach phaser can be set to automatically track a target or
Xcan be manually rotated.
XUnless engineering is jettisoned (code 21), phasers only
Xfire from 0-125 and 235-360 degrees, relative to the ship's
Xcourse.
XIn other words, each vessel has a 110 degree blind side in
Xback of it in which phasers cannot fire.
XIf phasers fired into this blind side, they would destroy
Xthe ship's engineering section.
X.sp
X.PP
XThe Captain also designates a wide or narrow phaser beam: a
Xwide beam to disrupt many targets; a narrow beam to inflict
Xmaximum damage on a single target.
XThe maximum spread of phasers is 45 degrees, the minimum is
X10 degrees.
XThe total beam width is twice the designated spread.
X.sp
X.PP
XThe firing percentage of each bank is preset to 100.
XIn other words, the bank fully discharges when firing.
XThis can be changed, however, using code 22.
X.sp
X.PP
XThe maximum range of phasers is 1000M; the maximum hit
Xfactor is 45 with a ten degree spread, 10 with a forty-five
Xdegree spread.
XPhaser hit factors are calculated by the following formula:
X.sp
X.ce
Xhit = (bankunits)(firing%)sqrt(1-range/1000)(45/spread)
X.sp
X.PP
XPhasers fire in .2-second intervals starting with bank one.
XPhasers inflict heavy damage and casualties, but do not
Xdestroy shields as much as antimatter explosions do.
X.sp
X.PP
XA phaser is unable to fire if damaged, if firing into your
Xblind side, or if completely discharged.
X.sp
X.LP
X2.  Fire Photon Torpedos.
X.PP
X[Tubes | all]
X.PP
XThe Enterprise is equipped with six torpedo tubes, which, as
Xphasers, can be set to automatically track a target or be
Xmanually rotated.
XUnless engineering is jettisoned, tubes only fire from
X0-135 and 225-360 degrees.
XEach tube fires all its antimatter pods, which are
Xheld suspended in a magnetic force field.
XPhoton torpedos can be fired directly at an enemy, laid out
Xas a mine field, or scattered in an attacker's path as
Xdepth charges.
X.sp
X.PP
XTubes must be loaded (code 9) prior to firing.
XNormally, torpedos are launched at warp 12 in .2-second
Xintervals, beginning with tube one.
XPhoton torpedos have a proximity fuse of 200M.
XAll of these values can be changed by using code 22.
X.sp
X.PP
XTorpedos must be launched with care since the antimatter
Xpods which are fired can never be recovered.
XIt is suggested that you not fire more than four torpedos at
Xany one time, since a certain number of them do miss, or are
Xdestroyed by the enemy firing phasers at them.
XIt is also suggested that you fire them at distant targets,
Xbeyond 1100M, to avoid the explosion radius of your own
Xweapons.
XHit factors resulting from antimatter explosions are
Xcalculated as follows:
X.sp
X.ce
Xhit = 5(#podscontained)sqrt(1-range/(50(#podscontained)))
X.sp
X.PP
XThe maximum hit factor of an antimatter device is five times
Xthe number of pods contained (in the case of torpedos, 50);
Xits explosion radius is 50 time the number of pods
Xcontained (in the case of torpedos, 500).
XAntimatter explosions heavily weaken shields but do not
Xdamage equipment as much as phasers do.
XThis formula also applies to vessels, engineering sections,
Xand antimatter probe explosions.
X.sp
X.PP
XA photon torpedo's proximity fuse will not be activated by a
Xcloaked ship.
X.sp
X.PP
XTubes are unable to fire if damaged, if firing into your
Xblind side, or if unloaded.
X.sp
X.LP
X3.  Lock Phasers.
X.PP
X[Phasers | all] [Target Name]
X.PP
XPhasers locked on an enemy vessel will automatically aim
Xtowards it.
XAlthough phasers may track a vessel which is in the firing
Xblind side, they will not fire unless engineering is
Xjettisoned.
XTo fire at vessels in the blind spot, simply change course
Xat least 55 degrees.
XOnce a phaser is locked, it is not disengaged until the
Xtarget is destroyed (in which case it is then rotated to
Xzero degrees relative), relocked, manually overridden, or
Xdamaged.
X.sp
X.PP
XPhasers can not be locked onto cloaked enemy ships.
XPhasers that were previously locked onto a non-cloaked ship
Xwill track the enemy's last known course and speed when
Xthat ship cloaks.
X.sp
X.LP
X4.  Lock Tubes.
X.PP
X[Tubes | all] [Target Name]
X.PP
XTubes lock and unlock in the same manner that phasers do.
X.sp
X.LP
X5.  Manually Rotate Phasers.
X.PP
X[Phasers | all] [Bearing]
X.PP
XManually rotating phasers disengages any previous locks and
Xpositions them as directed, relative to your course.
XFor example, if your course is 30, and phasers are rotated
X45 degrees, they will hit a target bearing 75 degrees.
XRotating phasers into you blind side is permissible,
Xhowever, they will not fire.
X.sp
X.LP
X6.  Manually Rotate Tubes.
X.PP
X[Tubes | all] [Bearing]
X.PP
XManually rotating tubes is similar to rotating phasers.
X.sp
X.LP
X7.  Phaser Status.
X.PP
XPhaser status reports the control (locks and damages),
Xdeployment, levels, firing percentages (normally 100),
Xand charge/discharge rates (normally +10) of all phasers.
XThis command does not use a turn.
XCf. Command 22.
X.sp
X.LP
X8.  Tube Status.
X.PP
XTube status reports the control, deployment, tube levels,
Xlaunch speeds (normally 12), proximity delays (normally
X200), and time delays (normally 10) of all tubes.
XThis command does not use a turn.
XCf. Command 22.
X.sp
X.LP
X9.  Load/Unload Tubes.
X.PP
X[l | u] [Tubes | all]
X.PP
XEach specified tube will be automatically loaded with 10 units or
Xwhatever remains in the engines, whichever is less.
XTubes can also be unloaded if the need arises.
X.sp
X.LP
X10.  Launch Antimatter Probe.
X.PP
X[Pods] [Time] [Proximity] [Target | [<CR> Course]]
X.PP
XProbes are slow-moving devices equipped with internal
Xguidance systems which allow them to chase an enemy vessel.
XProbes consist of at least ten antimatter pods which are
Xlaunched from an undamaged probe launcher at warp three.
XAs with torpedos, probes are set with time and proximity
Xfuses, and use the same hit factor formula as do torpedos.
END_OF_man/01.t
if test 6955 -ne `wc -c <man/01.t`; then
    echo shar: \"man/01.t\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f man/04.t -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"man/04.t\"
else
echo shar: Extracting \"man/04.t\" \(6881 characters\)
sed "s/^X//" >man/04.t <<'END_OF_man/04.t'
X.ce
XOptions
X.sp
X.PP
XIn TREK73, all the names of crewmembers are taken from the
XStar Trek series.
XThrough the use of options, the names, as well as other
Xaspects of the game, can be changed to whatever you want.
X.sp
X.PP
XTo use the options, you must add the variable TREK73OPTS to
Xyour environment.
XA sample would be (using the C-shell):
X.br
X.sp
Xsetenv TREK73OPTS 'name=Jerk, ship=Boobyprize, terse'
X.sp
X.PP
XThe option string is a list of comma-separated options.
XOptions are designated as either boolean or string options.
XBoolean options are turned on by typing their name and turned
Xoff by prepending 'no' to them.
XString options are set equal to the string which follows the "=".
X.sp
X.PP
XThere follows a list of all the options, what type it is,
Xand an explanation of what they mean.
XThe default for the option is in square brackets following
Xthe option.
X.sp
X.LP
Xterse BOOLEAN [noterse]
X.XP
XThis option, when set, turns off the information regarding the
Xship's purpose in the area.
XIt thus reduces the amount of drek on the screen.
XIf you are on a slow terminal, this is a nice option to have set.
X.sp
X.LP
Xshipname STRING [Enterprise]
X.XP
XThis option names your ship.
X.sp
X.LP
Xname STRING
X.XP
XThis option names the captain of the ship.
XIf this option is not set, then the program will ask for a name.
XThe captain is the one who must make all the decisions of strategy
Xand tactics for the ship.
X.sp
X.LP
Xsex STRING
X.XP
XThis option gives the captain a gender.
XIf this option is not set, the program will ask for it's value.
XIf you respond with something that starts with other than "m" or "f",
Xbeware!
X.sp
X.LP
Xscience STRING [Spock]
X.XP
XThis option names the science officer, who is responsible
Xfor checking the parameters of the captain's commands.
XIt is also this officer's duty to report damage to the ship
Xas well as scan for enemy damage.
X.sp
X.LP
Xengineer STRING [Scott]
X.XP
XThis option names the chief engineer of the ship.
XIt is this officer's duty to report on the status of the ship,
Xespecially its energy supply and distribution of the same.
XThe officer also controls the launching of anti-matter probes.
X.sp
X.LP
Xhelmsman STRING [Sulu]
X.XP
XThis option names the ship's helmsman.
XThis officer's duty is to control the speed of the ship
Xand also controls the firing of the ship's weapons.
X.sp
X.LP
Xnav STRING [Chekov]
X.XP
XThis option names the ship's navigator, who is responsible
Xfor the navigation of the ship.
XThis officer makes changes to the ship's course as directed
Xby the captain.
XThis officer also controls any anti-matter probes after they
Xhave been launched.
X.sp
X.LP
Xcom STRING [Uhura]
X.XP
XThis option names the ship's communications officer.
XIt is the duty of this officer to handle all communications between
Xthe ship and the rest of the universe.
X.sp
X.LP
Xenemy STRING [random]
X.XP
XIf this option is set, it tells the program which race you wish
Xto fight.
XThe available races are:
XKlingon, Romulan, Kzinti, Gorn, Orion, Hydran, Lyran, or Tholian.
XIf the option is not set, the race you will fight is chosen at random.
X.sp
X.LP
Xfoename STRING [random]
X.XP
XIf this option is set, it specifies the name of the commander
Xof the enemy ship(s).
XIf this option is not specified, the name is chosen at random.
X.sp
X.LP
Xclass STRING [CA]
X.XP
XThis option specifies the kind of ship you are commanding.
XAllowable classes are: DN, CA, CL, and DD, standing for
Xdreadnought, heavy cruiser, light cruiser, and destroyer.
XIn general, the larger the ship, the more weapons and stronger
Xshields you have, at the cost of less speed and maneuverability.
X.sp
X.LP
Xfoeclass STRING [CA]
X.XP
XThis option specifies the kind of ship that you are fighting.
XThe different classes are explained above.
X.sp
X.LP
Xsilly BOOLEAN [nosilly]
X.XP
XIf this option is set, an additional race is added to the list of
Xpossible races to fight.
XThis race is the Monty Pythons.
XNote that if you wish to always fight the Monty Python's, you merely
Xhave to set the enemy option above.
X.sp
X.LP
Xtime STRING [30]
X.XP
XTime is used to specify the time between commands.
XThe longer this value, the more time may be used in issuing a command.
X.sp
X.LP
Xteletype BOOLEAN [noteletype]
X.XP
XThe teletype option causes some of the output to come out as it did
Xin the original teletype version.
X.sp
X.LP
Xsavefile STRING [$HOME/trek73.save]
X.XP
XThe savefile option specifies where the data image is to be stored
Xif the game is saved during play.
X``~'' is not expanded, so the path should be
Xexplicit and fully expanded.
X.sp 3
X.ce
XCommand Line Options
X.sp
X.PP
XIn all cases, the arguments you place on the command line will supersede
Xoptions in the environment.
X.sp
X.PP
XThe following is a description of the command line options:
X.sp
X.IP \-t
XTurns on terse mode.
XNo initial scenario description is given.
XThis is useful for terminals running at low baud rates.
XThis option is normally off.
X.sp
X.IP \-c
XAllows the specification of the Federation captain's name.
X.sp
X.IP \-s
XSpecify the sex of the captain of the Federation vessel.
X.sp
X.IP \-S
XSpecify the name of the Science Officer of the Federation vessel.
X.sp
X.IP \-E
XSpecify the name of the Chief Engineer of the Federation vessel.
X.sp
X.IP \-C
XSpecify the name of the Communications Officer of the Federation vessel.
X.sp
X.IP \-N
XSpecify the name of the Navigator of the Federation vessel.
X.sp
X.IP \-H
XSpecify the name of the Helmsman of the Federation vessel.
X.sp
X.IP \-f
XSpecify the name of the enemy commanding officer.
X.sp
X.IP \-r
XSpecify the race of the enemy.
XThe race should be one of the following:
XKlingon, Romulan, Kzinti, Gorn, Hydran, Lyran, Tholian, Orion,
Xor Monty Python.
X.sp
X.IP \-d
XSet the delay time for command entry.
XHigher times can be useful for novices or for playing on very slow
Xterminals.
X.sp
X.IP \-y
XSilly option.
XAdds the Monty Pythons as a possible enemy race.
XThis option is normally off.
X.sp
X.IP \-T
XTeletype option.
XCauses certain parts of the output to come out as they did on the
Xoriginal teletype implementation.
XDoesn't do much for the game on crts.
XThis option is normally off.
X.sp
X.IP \-n
XSpecify the name of the Federation vessel.
XThe default name for the Federation vessel is randomly chosen from a
Xset of names.
X.sp
X.IP \-F
XSpecify the class of the enemy vessel(s).
XAllowable classes are Destroyer (DD), Light Cruiser (CL),
XHeavy Cruiser (CA), and Dreadnought (DN).
XIf the argument is none of the above, the program assumes that this is
Xthe name of a file where a player-designed ship is stored.
X.sp
X.IP \-l
XSpecify the class of the Federation vessel.
XAvailable classes are the same as the enemy's.
X.sp
X.IP \-R
XRestore the game from the savefile.  It is assumed that the TREK73OPTS
Xcontains the name of the savefile, otherwise it is not possible to restart
Xthe game with the -R option.  In case the savefile name is not in TREK73OPTS,
Xthe game may be restored by issuing the command with the path to the savefile
Xas the first argument.
X.bp
END_OF_man/04.t
if test 6881 -ne `wc -c <man/04.t`; then
    echo shar: \"man/04.t\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/cmds3.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/cmds3.c\"
else
echo shar: Extracting \"src/cmds3.c\" \(6408 characters\)
sed "s/^X//" >src/cmds3.c <<'END_OF_src/cmds3.c'
X#ident "@(#) TREK73 $Header: cmds3.c,v 1.1 87/10/09 11:02:23 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/cmds3.c,v $
X *
X * $Header: cmds3.c,v 1.1 87/10/09 11:02:23 okamoto Exp $
X *
X * $Log:	cmds3.c,v $
X * Revision 1.1  87/10/09  11:02:23  11:02:23  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: cmds3.c
X *
X * User Commands
X *
X * jettison_engineering, detonate_engineering, phaser_status, tube_status,
X * survivors, alter_power
X *
X * (do_jettison)
X *
X */
X
X#include "externs.h"
X#include <ctype.h>
X
X
Xint
Xjettison_engineering(sp)
Xstruct ship *sp;
X{
X
X	printf("   Mr. %s, jettison our engineering section!\n", engineer);
X	if (is_dead(sp, S_ENG)) {
X		printf("%s:  But Captain, it's already jettisonned.\n", engineer);
X		return 0;
X	}
X	do_jettison(sp);
X	printf("%s:  Aye, %s.  Jettisoning engineering.\n", 
X	    engineer, title);
X	return 1;
X}
X
Xint
Xdo_jettison(sp)
Xstruct ship *sp;
X{
X	register struct list *lp;
X	register struct torpedo *tp;
X
X	lp = newitem(I_ENG);
X	tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
X	if (tp == (struct torpedo *)NULL) {
X		fprintf(stderr, "do_jettison: malloc failed\n");
X		exit(2);
X	}
X	tp->target = NULL;
X	tp->speed = sp->warp;
X	tp->newspeed = 0.0;
X	tp->x = sp->x;
X	tp->y = sp->y;
X	tp->course = sp->course;
X	/* This is correct */
X	tp->fuel = sp->energy;
X	tp->timedelay = 10.;
X	tp->prox = 0;
X	tp->from = sp;
X	tp->id = new_slot();
X	tp->type = TP_ENGINEERING;
X	sp->energy = sp->pods = 0.;
X	sp->newwarp = (sp->warp < 0.0) ? -0.99 : 0.99;
X	sp->regen = 0.0;
X	sp->status[S_ENG] = 100;	/* Set these as destroyed */
X	sp->status[S_WARP] = 100;
X	sp->max_speed = 1.0;
X	sp->cloaking = C_NONE;
X	sp->t_blind_left = sp->t_blind_right =
X	    sp->p_blind_left = sp->p_blind_right = 180;
X}
X
Xint
Xdetonate_engineering(sp)
Xstruct ship *sp;
X{
X	register struct list *lp;
X	register struct torpedo *tp;
X	register int found;
X	char buf[10];
X
X	found = 0;
X	printf("   Mr. %s, detonate engineering!\n", engineer);
X	if (!is_dead(sp, S_ENG)) {
X		printf("%s: But %s, it's still attached.\n",engineer,title);
X		printf("   Detonate anyway? ");
X		printf("%s:  [yes or no] ", captain);
X		(void) Gets(buf, sizeof(buf));
X		if ((buf[0] == NULL)
X		    || ((buf[0] != 'y') && (buf[0] != 'Y')))
X			return 0;
X		else 
X			do_jettison(sp);
X	}
X	for (lp = &head; lp != tail; lp = lp->fwd) {
X		if (lp->type != I_ENG)
X			continue;
X		tp = lp->data.tp;
X		if (tp->from != sp)
X			continue;
X		found++;
X		tp->timedelay = 0.;
X		break;
X	}
X	if (found)
X		printf("%s:  Aye, %s.\n",engineer, title);
X	else
X		printf("%s:  Ours has already detonated.\n", engineer);
X	return 1;
X}
X
X
Xint
Xphaser_status(sp)
Xstruct ship *sp;
X{
X	register int i;
X
X	puts("Phasers\n");
X	printf("Control: ");
X	for (i=0; i<sp->num_phasers; i++) {
X		if (sp->phasers[i].status & P_DAMAGED)
X			printf("\tdamaged");
X		else if (sp->phasers[i].target == NULL)
X			printf("\tmanual");
X		else
X			printf("\t%.7s", sp->phasers[i].target->name);
X	}
X	printf("\n Turned: ");
X	for (i=0; i<sp->num_phasers; i++)
X		if (sp->phasers[i].status & P_DAMAGED)
X			putchar('\t');
X		else if (sp->phasers[i].target == NULL)
X			printf("\t%3.0f", sp->phasers[i].bearing);
X		else
X			printf("\tLOCKED");
X	printf("\n  Level: ");
X	for (i=0; i<sp->num_phasers; i++) {
X		if (sp->phasers[i].status & P_DAMAGED)
X			putchar('\t');
X		else
X			printf("\t%d", sp->phasers[i].load);
X	}
X	printf("\n  Drain: ");
X	for (i=0; i<sp->num_phasers; i++) {
X		if (sp->phasers[i].status & P_DAMAGED)
X			putchar('\t');
X		else
X			printf("\t%d", sp->phasers[i].drain);
X	}
X	printf("\n\nFiring percentage: %d\n",sp->p_percent);
X	printf("\nFiring angles: ");
X	if (is_dead(sp, S_ENG)) {
X		printf("unrestricted.\n");
X	} else {
X		printf("0 - %d and %d - 360.\n",
X		    sp->p_blind_left, sp->p_blind_right);
X	}
X	return 1;
X}
X
Xint
Xtube_status(sp)
Xstruct ship *sp;
X{
X	register int i;
X
X	puts("Torpedos\n");
X	printf("Control: ");
X	for (i=0; i<sp->num_tubes; i++) {
X		if (sp->tubes[i].status & T_DAMAGED)
X			printf("\tdamaged");
X		else if (sp->tubes[i].target == NULL)
X			printf("\tmanual");
X		else
X			printf("\t%.7s", sp->tubes[i].target->name);
X	}
X	printf("\n Turned: ");
X	for (i=0; i<sp->num_tubes; i++)
X		if (sp->tubes[i].status & T_DAMAGED)
X			putchar('\t');
X		else if (sp->tubes[i].target == NULL)
X			printf("\t%.0f", sp->tubes[i].bearing);
X		else
X			printf("\tLOCKED");
X	printf("\n  Level: ");
X	for (i=0; i<sp->num_tubes; i++) {
X		if (sp->tubes[i].status & T_DAMAGED)
X			putchar('\t');
X		else
X			printf("\t%d", sp->tubes[i].load);
X	}
X	printf("\n\nLaunch speed: %d\n", sp->t_lspeed);
X	printf("  Time delay: %d\n", sp->t_delay);
X	printf("  Prox delay: %d\n", sp->t_prox);
X	printf("\nFiring angles: ");
X	if (is_dead(sp, S_ENG)) {
X		printf("unrestricted.\n");
X	} else {
X		printf("0 - %d and %d - 360.\n",sp->t_blind_left, sp->t_blind_right);
X	}
X	return 1;
X}
X
Xint
Xsurvivors(sp)
Xstruct ship *sp;
X{
X	struct ship *ep;
X	register int i;
X
X	printf("\nSurvivors reported:\n");
X	for (i=0; i<=shipnum; i++) {
X		ep = shiplist[i];
X		if (sp->complement < 0)
X			printf("   %s -- destructed", sp->name);
X		else if (cantsee(ep))
X			printf("   %s -- ???\n", ep->name);
X		else
X			printf("   %s -- %d\n", ep->name, ep->complement);
X	}
X	sp = sp;		/* LINT */
X}
X
Xint
Xalter_power()
X{
X	register int i;
X	float j;
X	char buf1[20];
X
X	printf("\n%s:  Regeneration rate is %5.2f.\n",engineer, shiplist[0]->regen);
X	for (i=0; i<SHIELDS; i++) {
X		printf("%s:  Shield %d drain is [0.0 to 1.0] ",
X		    captain, i + 1);
X		(void) Gets(buf1, sizeof(buf1));
X		j = (float) atof(buf1);
X		if (buf1[strlen(buf1) - 1] == '*') {
X			if ((j < 0.0) || (j > 1.0))
X				goto badparam;
X			for (; i<SHIELDS; i++)
X				shiplist[0]->shields[i].attemp_drain =j;
X			break;
X		} else if ((j < 0.0) || (j > 1.0))
X			goto badparam;
X		else
X			shiplist[0]->shields[i].attemp_drain = j;
X	}				
X	printf("\n");
X	for (i=0; i<shiplist[0]->num_phasers; i++) {
X		printf("%s:  Phaser %d drain is [%.0f to %.0f] ",
X		    captain, i + 1, MIN_PHASER_DRAIN, MAX_PHASER_DRAIN);
X		(void) Gets(buf1, sizeof(buf1));
X		j = (float) atof(buf1);
X		if (buf1[strlen(buf1) - 1] == '*') {
X			if ((j < MIN_PHASER_DRAIN)
X			    || (j > MAX_PHASER_DRAIN))
X				goto badparam;
X			for (; i<shiplist[0]->num_phasers; i++)
X				shiplist[0]->phasers[i].drain = (int) j;
X			break;
X		} else if ((j < MIN_PHASER_DRAIN) 
X		    || (j > MAX_PHASER_DRAIN))
X			goto badparam;
X		else
X			shiplist[0]->phasers[i].drain = (int) j;
X	}
X	return 1;
Xbadparam:
X	printf("%s:  Bad parameters, %s.\n", engineer, title);
X	return 0;
X}
END_OF_src/cmds3.c
if test 6408 -ne `wc -c <src/cmds3.c`; then
    echo shar: \"src/cmds3.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/firing.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/firing.c\"
else
echo shar: Extracting \"src/firing.c\" \(5713 characters\)
sed "s/^X//" >src/firing.c <<'END_OF_src/firing.c'
X#ident "@(#) TREK73 $Header: firing.c,v 1.1 87/10/09 11:06:25 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/firing.c,v $
X *
X * $Header: firing.c,v 1.1 87/10/09 11:06:25 okamoto Exp $
X *
X * $Log:	firing.c,v $
X * Revision 1.1  87/10/09  11:06:25  11:06:25  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: firing.c
X *
X * Take care of firing phasers and torpedos for both enemy
X * and fed ships.
X *
X * phaser_firing, torpedo_firing, ship_detonate, torp_detonate
X *
X */
X
X#include "externs.h"
X
X
Xphaser_firing(sp)
Xstruct ship *sp;
X{
X	register int i;
X	register float j;
X	int	hit;
X	struct	ship *ep;
X	struct	torpedo *tp;
X	int	s;
X	int	x, y;
X	struct	ship *target;
X	struct	list *lp;
X	float	bear;
X	struct 	ship *fed;
X
X
X	fed = shiplist[0];
X	for (i=0; i<sp->num_phasers; i++) {
X		if (sp->phasers[i].status & P_FIRING)
X			break;
X	}
X	if (i == sp->num_phasers)
X		return 0;
X	sp->phasers[i].status &= ~P_FIRING;
X	target = sp->phasers[i].target;
X	/*
X	 * Put in j the relative bearing of the phasers relative to the ship
X	 * Put in bear the absolute direction the phasers are pointing
X	 */
X	bear = sp->phasers[i].bearing + sp->course;
X	j = rectify(sp->phasers[i].bearing);
X	if (betw(j, sp->p_blind_left, sp->p_blind_right)
X	    && !is_dead(sp, S_ENG))
X		return 0;
X	if (target != NULL && is_dead(target, S_DEAD)) {
X		if ((sp = fed) && (!shutup[PHASERS+i])
X		    && !(is_dead(sp, S_DEAD))) {
X			printf("%s phaser %d unlocking\n",
X			    sp->name, i+1);
X			shutup[PHASERS+i]++;
X		}
X		sp->phasers[i].target = NULL;
X		return 0;
X	}
X	if (cantsee(sp))
X		(void) e_cloak_off(sp, fed);
X	printf(" <%s frng phasers>\n", sp->name);
X	for (lp = &head; lp != tail; lp = lp->fwd) {
X		if (lp->type == 0)
X			continue;
X		ep = NULL;
X		tp = NULL;
X		if (lp->type == I_SHIP) {
X			ep = lp->data.sp;
X			if (ep == sp)
X				continue;
X			x = ep->x;
X			y = ep->y;
X		} else {
X			tp = lp->data.tp;
X			x = tp->x;
X			y = tp->y;
X		}
X		hit = phaser_hit(sp, x, y, &sp->phasers[i], bear);
X		if (hit <= 0)
X			continue;
X		if (tp) {
X			if (tp->timedelay > segment) {
X				switch (lp->type) {
X				case I_TORPEDO:
X					printf("hit on torpedo %d\n",
X						tp->id);
X					break;
X				case I_ENG:
X					printf("hit on %s's engineering\n",
X						tp->from->name);
X					break;
X				case I_PROBE:
X					printf("hit on probe %d\n", 
X						tp->id);
X					break;
X				default:
X					fprintf(stderr, "hit on lp->type\n",
X						lp->type);
X					break;
X				}
X				tp->timedelay = 0.;
X			}
X			tp->fuel -= hit/2;
X			if (tp->fuel < 0)
X				tp->fuel = 0;
X			continue;
X		}
X		/*
X		 * Determine which shield was hit
X		 */
X		j = rectify(bearing(x, sp->x, y, sp->y) - ep->course);
X		if (j > 315.0 || j < 45.0)
X			s = 1;
X		else if (j < 135.0)
X			s = 2;
X		else if (j < 225.0)
X			s = 3;
X		else
X			s = 4;
X		(void) damage(hit, ep, s, &p_damage, D_PHASER);
X	}
X	/*
X	 * Reduce the load by the firing percentage
X	 */
X	sp->phasers[i].load *= 1.0 - (float) sp->p_percent / 100;
X	return 0;
X}
X
Xtorpedo_firing(sp)
Xstruct ship *sp;
X{
X	register int i;
X	register float j;
X	register int th;
X	struct	torpedo *tp;
X	struct	ship *target;
X	struct	list *lp;
X	float	bear;
X	struct	ship *fed;
X
X	fed = shiplist[0];
X	for (i=0; i<sp->num_tubes; i++) {
X		if (sp->tubes[i].status & T_FIRING)
X			break;
X	}
X	if (i == sp->num_tubes)
X		return 0;
X	sp->tubes[i].status &= ~T_FIRING;
X	th = sp->tubes[i].load;
X	if (th == 0)
X		return 0;
X	target = sp->tubes[i].target;
X	/*
X	 * Put in j the relative bearing of the tubes to the ship
X	 * Put in bear the absolute direction the tubes are pointing
X	 */
X	bear = sp->tubes[i].bearing + sp->course;
X	j = rectify(sp->tubes[i].bearing);
X	if (betw(j, sp->t_blind_left, sp->t_blind_right) && !is_dead(sp, S_ENG))
X		return 0;
X	if (target != NULL && (is_dead(target, S_DEAD))) {
X		if ((sp == fed) && !shutup[TUBES+i] && !is_dead(sp, S_DEAD)) {
X			printf("   tube %d disengaging\n", i+1);
X			shutup[TUBES+i]++;
X		}
X		sp->tubes[i].target = NULL;
X		return 0;
X	}
X	sp->tubes[i].load = 0;
X	lp = newitem(I_TORPEDO);
X	lp->type = I_TORPEDO;
X	lp->data.tp = MKNODE(struct torpedo, *, 1);
X	if (lp->data.tp == (struct torpedo *)NULL) {
X		fprintf(stderr, "torpedo_firing: malloc failed\n");
X		exit(2);
X	}
X	tp = lp->data.tp;
X	tp->from = sp;
X	tp->x = sp->x;
X	tp->y = sp->y;
X	tp->target = NULL;
X	tp->course = rectify(bear);
X	tp->fuel = th;
X	tp->speed = sp->t_lspeed + sp->warp;
X	tp->newspeed = tp->speed;
X	tp->timedelay = (float)sp->t_delay;
X	tp->prox = sp->t_prox;
X	tp->id = new_slot();
X	tp->type = TP_TORPEDO;
X	if (teletype)
X		printf("\007");
X	if (cantsee(sp))
X		(void) e_cloak_off(sp, fed);
X	printf(" <<%s frng torpedo %d>>", sp->name, tp->id);
X	if (teletype)
X		printf("\007");
X	printf("\n");
X	return 1;
X}
X
Xint
Xship_detonate(sp, lp)
Xstruct ship *sp;
Xstruct list *lp;
X{
X	register int fuel;
X	register int i;
X
X	fuel = 0;
X	printf("++%s++ destruct.\n", sp->name);
X	for (i=0; i<sp->num_phasers; i++)
X		if (!(sp->phasers[i].status & P_DAMAGED))
X			fuel += min(sp->phasers[i].load, MAX_PHASER_CHARGE);
X	for (i=0; i<sp->num_tubes; i++)
X		if (!(sp->tubes[i].status & T_DAMAGED))
X			fuel += min(sp->tubes[i].load, MAX_TUBE_CHARGE);
X	fuel += sp->pods;
X	antimatter_hit((char *) sp, sp->x, sp->y, fuel);
X	lp->type = 0;
X	for (i=0; i< S_NUMSYSTEMS; i++)
X		sp->status[i] = 100;	/* He's dead, Jim */
X	sp->cloaking = C_NONE;
X	sp->complement = -1;
X}
X
X
Xint
Xtorp_detonate(tp, lp)
Xstruct torpedo *tp;
Xstruct list *lp;
X{
X
X	switch (lp->type) {
X		case I_TORPEDO:
X			printf(":: torp %d ::\n", tp->id);
X			break;
X		case I_PROBE:
X			printf("** probe %d **\n", tp->id);
X			break;
X		case I_ENG:
X			printf("## %s engineering ##\n", tp->from->name);
X			break;
X		default:
X			fprintf(stderr, "torp_detonate lp->type %d\n",lp->type);
X			break;
X	}
X	antimatter_hit((char *) tp, tp->x, tp->y, tp->fuel);
X	return_slot(tp->id);
X	delitem(lp);
X}
END_OF_src/firing.c
if test 5713 -ne `wc -c <src/firing.c`; then
    echo shar: \"src/firing.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/main.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/main.c\"
else
echo shar: Extracting \"src/main.c\" \(5656 characters\)
sed "s/^X//" >src/main.c <<'END_OF_src/main.c'
X#ident "@(#) TREK73 $Header: main.c,v 1.1 87/10/09 11:08:01 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/main.c,v $
X *
X * $Header: main.c,v 1.1 87/10/09 11:08:01 okamoto Exp $
X *
X * $Log:	main.c,v $
X * Revision 1.1  87/10/09  11:08:01  11:08:01  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: main.c
X *
X * Originally written (in HP-2000 BASIC) by
X *	William K. Char, Perry Lee, and Dan Gee
X *
X * Rewritten in C by
X *	Dave Pare (sdcsvax!sdamos!mr-frog)
X * 		  (mr-frog@amos.ling.ucsd.edu)
X *		and
X *	Christopher Williams (ucbvax!ucbmerlin!williams)
X *			     (williams@merlin.berkeley.edu)
X *
X * Corrected, Completed, and Enhanced by
X *	Jeff Okamoto	(hpccc!okamoto)
X *			(hpccc!okamoto@hplabs.hp.com)
X *	Peter Yee	(ucbvax!yee)
X *			(yee@ucbarpa.berkeley.edu)
X *	Matt Dillon	(ucbvax!dillon)
X *			(dillon@ucbvax.berkeley.edu)
X *	Dave Sharnoff	(ucbvax!ucbcory!muir)
X *			(muir@cogsci.berkeley.edu)
X *	Joel Duisman
X *	    and
X *	Roger J. Noe    (uniq!rjnoe)
X *			(ihnp4!uniq!rjnoe@berkeley.edu)
X *
X * Main Loop
X *
X * main, alarmtrap, quitgame, buffering
X *
X */
X
X#include "externs.h"
X#include <signal.h>
X#include <setjmp.h>
X#include <ctype.h>
X
Xstatic jmp_buf	jumpbuf;
X
X
Xmain(argc, argv, envp)
Xint argc;
Xchar *argv[];
Xchar *envp[];
X{
X	int			alarmtrap();
X	int			quitgame();
X
X	if (buffering(stdout) < 0)
X		perror("cannot fstat stdout");
X	(void) signal(SIGALRM, alarmtrap);
X	(void) signal(SIGINT, quitgame);
X	srandom(time(0));
X	time_delay = DEFAULT_TIME;
X	set_save();
X	options = getenv("TREK73OPTS");
X	if (options != NULL)
X		parse_opts(options);
X	get_comlineopts(argc, argv);
X	if (restart && savefile[0] != '\0') {
X		restore(savefile, envp);	/* Will not return */
X		exit(1);
X	}
X	name_crew();
X	init_ships();
X	(void) mission();
X	(void) alert();
X	playit();
X	/*NOTREACHED*/
X}
X
X/*
X * Main loop
X */
Xplayit()
X{
X	struct cmd		*scancmd();
X	int			alarmtrap();
X	int			quitgame();
X	register struct ship	*sp;
X#ifndef PARSER
X	char			buf1[30];
X#endif PARSER
X	struct cmd		*cp;
X	int			loop;
X	char			*ch;
X
X	(void) setjmp(jumpbuf);
X	sp = shiplist[0];
X	if (!(is_dead(sp, S_DEAD))) {
Xnext:
X		for (loop = 0; loop < HIGHSHUTUP; loop++)
X			shutup[loop] = 0;
X		fflush(stdin);
X		printf("\n%s: Code [1-%d] ", captain, high_command);
X		fflush(stdout);
X		(void) alarm((unsigned) time_delay);
X#ifdef PARSER
X		(void) Gets(Input, sizeof(Input));
X		if (Input[0] != NULL) {
X#else
X		(void) Gets(buf1, sizeof(buf1));
X		if (buf1[0] != NULL) {
X#endif PARSER
X			(void) alarm(0);
X#ifdef PARSER
X			Inptr = Input;
X			parsed[0] = '\0';
X			ch = Inptr;
X			while (isspace(*ch))
X				ch++;
X			if (isalpha(*ch))
X				yyparse();
X			else
X				strcpy(parsed, Input);
X#endif PARSER
X#ifdef PARSER
X			cp = scancmd(parsed);
X#else
X			cp = scancmd(buf1);
X#endif PARSER
X			if (cp != NULL) {
X				(*cp->routine)(sp);
X				if (cp->turns == FREE)
X					goto next;
X			} else
X				printf("\n%s: %s, I am unable to interpret your last utterance.\n", science, title);
X		} else
X			(void) alarm(0);
X	}
X	ch = ch;		/* LINT */
X	alarmtrap(0);
X	/* This point is never reached since alarmtrap() always concludes
X	   with a longjmp() back to the setjmp() above the next: label */
X	/*NOTREACHED*/
X}
X
Xalarmtrap(sig)
Xint sig;
X{
X	register int i;
X
X	if (sig) {
X		puts("\n** TIME **");
X		(void) signal(sig, alarmtrap);
X		stdin->_cnt = 0;
X	}
X	for (i = 1; i <= shipnum; i++)
X		shiplist[i]->strategy(shiplist[i]);
X	if (!(is_dead(shiplist[0], S_DEAD)))
X		printf("\n");
X	(void) move_ships();
X	(void) check_targets();
X	(void) misc_timers();
X	(void) disposition();
X	longjmp(jumpbuf, 1);
X}
X
X
Xquitgame()
X{
X	char answer[20];
X	unsigned timeleft;
X
X	timeleft = alarm(0);
X	(void) signal(SIGINT, SIG_IGN);
X	puts("\n\nDo you really wish to stop now?  Answer yes or no:");
X	(void) Gets(answer, sizeof(answer));
X	if(answer[0] == NULL || answer[0] == 'y' || answer[0] == 'Y')
X		exit(0);
X	(void) signal(SIGINT, quitgame);
X	if(timeleft)
X		(void) alarm((unsigned)timeleft);
X	return;
X}
X
X
X/* buffering: Determine whether or not stream is to be buffered.  If
X   it's a character-special device, any buffering in effect will remain.
X   If it's not a character-special device, then stream will be
X   unbuffered.  There are many ways to decide what to do here.  One
X   would have been to make it unbuffered if and only if
X   !isatty(fileno(stream)).  This is usually implemented as a single
X   ioctl() system call which returns true if the ioctl() succeeds, false
X   if it fails.  But there are ways it could fail and still be a tty.
X   Then there's also examination of stream->_flag.  UNIX is supposed to
X   make any stream attached to a terminal line-buffered and all others
X   fully buffered by default.  But sometimes even when isatty()
X   succeeds, stream->_flag indicates _IOFBF, not _IOLBF.  And even if it
X   is determined that the stream should be line buffered, setvbuf(3S)
X   doesn't work right (in UNIX 5.2) to make it _IOLBF.  So about the
X   only choice is to do a straightforward fstat() and ascertain
X   definitely to what the stream is attached.  Then go with old reliable
X   setbuf(stream, NULL) to make it _IONBF.  The whole reason this is
X   being done is because the user may be using a pipefitting program to
X   collect a "transcript" of a session (e.g. tee(1)), or redirecting to
X   a regular file and then keeping a tail(1) going forever to actually
X   play the game.  This assures that the output will keep pace with the
X   execution with no sacrifice in efficiency for normal execution. [RJN]
X*/
X
X#include <sys/types.h>
X#include <sys/stat.h>
X
Xint
Xbuffering(stream)
XFILE	*stream;
X{
X	struct stat	st;
X	if (fstat(fileno(stream), &st) < 0)
X		return -1;
X	if ((st.st_mode & S_IFMT) != S_IFCHR)
X		setbuf(stream, NULL);
X	return 0;
X}
END_OF_src/main.c
if test 5656 -ne `wc -c <src/main.c`; then
    echo shar: \"src/main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/misc.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/misc.c\"
else
echo shar: Extracting \"src/misc.c\" \(6183 characters\)
sed "s/^X//" >src/misc.c <<'END_OF_src/misc.c'
X#ident "@(#) TREK73 $Header: misc.c,v 1.1 87/10/09 11:08:09 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/misc.c,v $
X *
X * $Header: misc.c,v 1.1 87/10/09 11:08:09 okamoto Exp $
X *
X * $Log:	misc.c,v $
X * Revision 1.1  87/10/09  11:08:09  11:08:09  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: misc.c
X *
X * Miscellaneous Routines
X *
X * help, scancmd, new_slot, return_slot, vowelstr,
X * check_p_damage, check_t_damage, check_p_turn, check_t_turn,
X * ship_class
X *
X */
X
X#include "externs.h"
X
Xint
Xhelp(dummy)
Xstruct ship *dummy;
X{
X	struct cmd	*cpbegin, *cpmiddle;
X
X	puts("\nTrek73 Commands:");
X	puts(
X"Code		Command			Code		Command");
X	putchar('\n');
X	cpbegin = &cmds[0];
X	cpmiddle = &cmds[(cmdarraysize + 1) >> 1];
X	while (cpmiddle->routine != NULL) {
X		printf("%3s:  %c %-31s:%3s:  %c %-31s\n",
X		    cpbegin->code_num, ((cpbegin->turns) ? ' ' : '*'),
X		    cpbegin->explanation, cpmiddle->code_num,
X		    ((cpmiddle->turns) ? ' ' : '*'),
X		    cpmiddle->explanation);
X		cpbegin++;
X		cpmiddle++;
X	}
X	if (cmdarraysize & 1)
X		printf("%3s:  %c %-31s", cpbegin->code_num,
X		    ((cpbegin->turns) ? ' ' : '*'),
X		    cpbegin->explanation);
X	puts("\n\n * does not use a turn");
X	dummy = dummy;				/* LINT */
X}
X
Xstruct cmd *
Xscancmd(buf)
Xchar *buf;
X{
X	static char **argp = NULL;
X	struct	cmd *cp;
X	int	argnum;
X	int	first;
X
X	argnum = parsit(buf, &argp);
X	first = strlen(argp[0]);
X	if (argnum && first)
X		for (cp = &cmds[0]; cp->routine != NULL; cp++)
X			if (!strncmp(argp[0], cp->code_num, first))
X				return (cp);
X	return (NULL);
X}
X
X/*
X * This routine handles getting unique identifier numbers for
X * all objects.
X */
Xint
Xnew_slot()
X{
X	/*
X	 * This is to make it appear that in a 2-ship duel, for
X	 * instance, the first object to appear will be numbered
X	 * as 3.
X	 */
X	int i = shipnum + 2;
X
X	while ((slots[i] == 'X') && (i <= HIGHSLOT))
X		i++;
X	if (i > HIGHSLOT) {
X		puts("The game will terminate now due to an inability to handle the number of");
X		puts("objects in space (i.e. vessels, torpedoes, probes, etc).  Sorry!");
X		exit(-1);
X	}
X	slots[i] = 'X';
X	return i;
X}
X
X/* 
X * This routine handles returning identifiers
X */
Xint
Xreturn_slot(i)
Xint i;
X{
X	if (slots[i] != 'X')
X		printf("FATAL ERROR - Slot already empty!");
X	slots[i] = ' ';
X}
X
X
Xchar *
Xvowelstr(str)
Xchar *str;
X{
X	switch(*str) {
X		case 'a': case 'A':
X		case 'e': case 'E':
X		case 'i': case 'I':
X		case 'o': case 'O':
X		case 'u': case 'U':
X			return "n";
X		default:
X			return "";
X	}
X}
X
X
X/*
X * This routine takes an array generated from commands 1, 3, and 5
X * to print out a list of those phasers damaged and unable to
X * either fire, lock, or turn.
X */
Xint
Xcheck_p_damage(array, sp, string)
Xint array[];
Xstruct ship *sp;
Xchar *string;
X{
X	int i, j;
X
X	j = 0;
X	for (i=0; i<sp->num_phasers; i++) {
X		if (array[i] && (sp->phasers[i].status & P_DAMAGED)) {
X			if (!j)
X				printf("Computer: Phaser(s) %d", i+1);
X			else
X				printf(", %d", i+1);
X			j++;
X		}
X	}
X	if (j > 1)
X		printf(" are damaged and unable to %s.\n", string);
X	else if (j == 1)
X		printf(" is damaged and unable to %s.\n", string);
X}
X
X/*
X * This routine takes an array generated from commands 2, 4, and 6
X * to print out a list of those tubes damaged and unable to either
X * fire, lock, or turn.
X */
Xint
Xcheck_t_damage(array, sp, string)
Xint array[];
Xstruct ship *sp;
Xchar *string;
X{
X	int i, j;
X
X	j = 0;
X	for (i=0; i<sp->num_tubes; i++) {
X		if (array[i] && (sp->tubes[i].status & P_DAMAGED)) {
X			if (!j)
X				printf("Computer: Tube(s) %d", i+1);
X			else
X				printf(", %d", i+1);
X			j++;
X		}
X	}
X	if (j > 1)
X		printf(" are damaged and unable to %s.\n", string);
X	else if (j == 1)
X		printf(" is damaged and unable to %s.\n", string);
X}
X
X/*
X * This routine checks to see if a phaser is pointing into our
X * blind side
X */
Xint
Xcheck_p_turn(array, sp, flag)
Xint array[];
Xstruct ship *sp;
Xint flag;			/* If 1, came from fire_phasers */
X{
X	register int i;
X	register int j;
X	register float k;
X	register float bear;
X	struct ship *target;
X
X	j = 0;
X	for (i=0; i<sp->num_phasers; i++) {
X		if (!array[i])
X			continue;
X		if (flag && !(sp->phasers[i].status & P_FIRING))
X			continue;
X		target = sp->phasers[i].target;
X		/*
X		 * This hack is here since when the phaser is locked,
X		 * the bearing points at the target, whereas when
X		 * not locked, the bearing is relative to the ship.
X		 */
X		if (target == NULL) {
X			bear = sp->phasers[i].bearing + sp->course;
X			k = sp->phasers[i].bearing;
X		} else {
X			bear = bearing(sp->x, target->x, sp->y, target->y);
X			k = bear - sp->course;
X		}
X		k = rectify(k);
X
X		if (betw(k, sp->p_blind_left, sp->p_blind_right)
X		    && !(is_dead(sp, S_ENG))) {
X			if (!j)
X				printf("Computer: Phaser(s) %d", i + 1);
X			else
X				printf(", %d", i + 1);
X			j++;
X		}
X	}
X	if (j > 1)
X		printf(" are pointing into our blind side.\n");
X	else if (j == 1)
X		printf(" is pointing into our blind side.\n");
X}
X
X/*
X * This routine checks to see if a tube is turned into
X * our blind side.
X */
Xint
Xcheck_t_turn(array, sp, flag)
Xint array[];
Xstruct ship *sp;
Xint flag;			/* If 1, came from fire_tubes */
X{
X	register int i;
X	register int j;
X	register float k;
X	register float bear;
X	struct ship *target;
X
X	j = 0;
X	for (i=0; i<sp->num_tubes; i++) {
X		if (!array[i])
X			continue;
X		if (flag && !(sp->tubes[i].status & T_FIRING))
X			continue;
X		target = sp->tubes[i].target;
X		/*
X		 * This hack is here since when the tube is locked,
X		 * the bearing points at the target, whereas when
X		 * not locked, the bearing is relative to the ship.
X		 */
X		if (target == NULL) {
X			bear = sp->tubes[i].bearing + sp->course;
X			k = sp->tubes[i].bearing;
X		} else {
X			bear = bearing(sp->x, target->x, sp->y, target->y);
X			k = bear - sp->course;
X		}
X		k = rectify(k);
X		if (betw(k, sp->t_blind_left, sp->t_blind_right) && !(is_dead(sp, S_ENG))) {
X			if (!j)
X				printf("Computer: Tubes(s) %d", i + 1);
X			else
X				printf(", %d", i + 1);
X			j++;
X		}
X	}
X	if (j > 1)
X		printf(" are pointing into our blind side.\n");
X	else if (j == 1)
X		printf(" is pointing into our blind side.\n");
X}
X
Xstruct ship_stat *
Xship_class(s)
Xchar *s;
X{
X	int i;
X
X	for (i = 0; i< MAXSHIPCLASS; i++)
X		if (!strcmp(stats[i].abbr, s)) {
X			return(&stats[i]);
X		}
X	return(NULL);
X}
END_OF_src/misc.c
if test 6183 -ne `wc -c <src/misc.c`; then
    echo shar: \"src/misc.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/parseopts.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/parseopts.c\"
else
echo shar: Extracting \"src/parseopts.c\" \(5823 characters\)
sed "s/^X//" >src/parseopts.c <<'END_OF_src/parseopts.c'
X#ident "@(#) TREK73 $Header: parseopts.c,v 1.2 87/11/23 09:19:40 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/parseopts.c,v $
X *
X * $Header: parseopts.c,v 1.2 87/11/23 09:19:40 okamoto Exp $
X *
X * $Log:	parseopts.c,v $
X * Revision 1.2  87/11/23  09:19:40  09:19:40  okamoto (Jeff Okamoto)
X * Removed include to options.h since they are now in defines.h.
X * 
X * Revision 1.1  87/10/09  11:09:49  11:09:49  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: parseopts.c
X *
X * Parse the environment variable TREK73OPTS and command line options
X *
X * parse_opts, get_comlineopts
X */
X
X#include <ctype.h>
X#include <stdio.h>
X#include "externs.h"
X
X#define	EQSTR(a, b, c)	(strncmp(a, b, c) == 0)
X
X#define	NUM_OPTS	(sizeof optlist / sizeof (OPTION))
X
X/*
X * description of an option and what to do with it
X */
Xstruct optstruct {
X    char	*o_name;	/* option name */
X    int		*o_opt;		/* pointer to thing to set */
X    int		o_type;		/* Boolean or string */
X};
X
Xtypedef struct optstruct	OPTION;
X
X
XOPTION	optlist[] = {
X    {"terse",	 (int *)&terse, BOOLEAN},
X    {"name", (int *)captain, STRING},
X    {"sex", (int *)sex, STRING},
X    {"science", (int *)science, STRING},
X    {"engineer", (int *)engineer, STRING},
X    {"com", (int *)com, STRING},
X    {"nav", (int *)nav, STRING},
X    {"helmsman", (int *)helmsman, STRING},
X    {"shipname", (int *)shipname, STRING},
X    {"enemy", (int *)racename, STRING},
X    {"foename", (int *)foename, STRING},
X    {"silly", (int *)&silly, BOOLEAN},
X    {"class", (int *)class, STRING},
X    {"foeclass", (int *)foeclass, STRING},
X    {"time", (int *)com_delay, STRING},
X    {"teletype", (int *)&teletype, BOOLEAN},
X    {"trace", (int *)&trace, BOOLEAN},
X    {"savefile", (int *)savefile, STRING}
X};
X
X/*
X * parse_opts:
X *	Parse options from string, usually taken from the environment.
X *	The string is a series of comma separated values, with booleans
X *	being stated as "name" (true) or "noname" (false), and strings
X *	being "name=....", with the string being defined up to a comma
X *	or the end of the entire option string.
X */
Xparse_opts(str)
Xregister char *str;
X{
X    register char *sp;
X    register OPTION *op;
X    register int len;
X
X    while (*str)
X    {
X	/*
X	 * Get option name
X	 */
X	for (sp = str; isascii(*sp) && isalpha(*sp); sp++)
X	    continue;
X	len = sp - str;
X	/*
X	 * Look it up and deal with it
X	 */
X	for (op = optlist; op < &optlist[NUM_OPTS]; op++)
X	    if (EQSTR(str, op->o_name, len))
X	    {
X		if (op->o_type == BOOLEAN)	/* if option is a boolean */
X		    *op->o_opt = 1;
X		else				/* string option */
X		{
X		    register char *start;
X		    /*
X		     * Skip to start of string value
X		     */
X		    for (str = sp + 1; *str == '='; str++)
X			continue;
X		    start = (char *) op->o_opt;
X		    /*
X		     * Skip to end of string value
X		     */
X		    for (sp = str + 1; *sp && *sp != ','; sp++)
X			continue;
X		    strucpy(start, str, sp - str);
X		}
X		break;
X	    }
X	    /*
X	     * check for "noname" for booleans
X	     */
X	    else if (op->o_type == BOOLEAN
X	      && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2))
X	    {
X		*op->o_opt = 0;
X		break;
X	    }
X
X	/*
X	 * skip to start of next option name
X	 */
X	while (*sp && !(isascii(*sp) && isalpha(*sp)))
X	    sp++;
X	str = sp;
X    }
X}
X
X/*
X * strucpy:
X *	Copy string using unctrl for things
X */
Xstrucpy(s1, s2, len)
Xregister char *s1, *s2;
Xregister int len;
X{
X    if (len > 100)
X	len = 100;
X    while (len--)
X    {
X	if (isascii(*s2) && isprint(*s2))
X	    *s1++ = *s2;
X	s2++;
X    }
X    *s1 = '\0';
X}
X
Xget_comlineopts(argc, argv)
Xint argc;
Xchar *argv[];
X{
X	int c;
X	char *opts = "Rtc:s:S:E:C:N:H:f:r:d:yTn:F:l:v";
X	int errflg = 0;
X
X	while ((c = getopt(argc, argv, opts)) != EOF) {
X		switch(c) {
X		case 'R':
X			restart = 1;
X			break;
X		case 't':
X			terse = 1;
X			break;
X		case 'c':
X			(void) strncpy(captain, optarg, sizeof captain);
X			captain[sizeof captain - 1] = '\0';
X			break;
X		case 's':
X			(void) strncpy(sex, optarg, sizeof sex);
X			sex[sizeof sex - 1] = '\0';
X			break;
X		case 'S':
X			(void) strncpy(science, optarg, sizeof science);
X			science[sizeof science - 1] = '\0';
X			break;
X		case 'E':
X			(void) strncpy(engineer, optarg, sizeof engineer);
X			engineer[sizeof engineer - 1] = '\0';
X			break;
X		case 'C':
X			(void) strncpy(com, optarg, sizeof com);
X			com[sizeof com - 1] = '\0';
X			break;
X		case 'N':
X			(void) strncpy(nav, optarg, sizeof nav);
X			nav[sizeof nav - 1] = '\0';
X			break;
X		case 'H':
X			(void) strncpy(helmsman, optarg, sizeof helmsman);
X			helmsman[sizeof helmsman - 1] = '\0';
X			break;
X		case 'f':
X			(void) strncpy(foename, optarg, sizeof foename);
X			foename[sizeof foename - 1] = '\0';
X			break;
X		case 'r':
X			(void) strncpy(racename, optarg, sizeof racename);
X			racename[sizeof racename - 1] = '\0';
X			break;
X		case 'd':
X			(void) strncpy(com_delay, optarg, sizeof com_delay);
X			com_delay[sizeof com_delay - 1] = '\0';
X			break;
X		case 'y':
X			silly = 1;
X			break;
X		case 'T':
X			teletype = 1;
X			break;
X		case 'n':
X			(void) strncpy(shipname, optarg, sizeof shipname);
X			shipname[sizeof shipname - 1] = '\0';
X			break;
X		case 'F':
X			(void) strncpy(foeclass, optarg, sizeof foeclass);
X			foeclass[sizeof foeclass - 1] = '\0';
X			break;
X		case 'l':
X			(void) strncpy(class, optarg, sizeof class);
X			class[sizeof class - 1] = '\0';
X			break;
X		case 'v':
X			trace = TR_ON;
X			break;
X		case '?':
X		default:
X			errflg++;
X			break;
X		}
X	}
X	if (errflg) {
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");
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");
X		fprintf(stderr, "       or trek73 -R");
X		exit(1);
X	}
X}
END_OF_src/parseopts.c
if test 5823 -ne `wc -c <src/parseopts.c`; then
    echo shar: \"src/parseopts.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/ships.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/ships.c\"
else
echo shar: Extracting \"src/ships.c\" \(923 characters\)
sed "s/^X//" >src/ships.c <<'END_OF_src/ships.c'
X#ident "@(#) TREK73 $Header: ships.c,v 1.1 87/10/09 15:55:36 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/ships.c,v $
X *
X * $Header: ships.c,v 1.1 87/10/09 15:55:36 okamoto Exp $
X *
X * $Log:	ships.c,v $
X * Revision 1.1  87/10/09  15:55:36  15:55:36  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: ships.c
X *
X * Global Ship Defs for TREK73
X *
X */
X
X#include "externs.h"
X
X/*
X * starting stats for the ships depending on the type
X */
X
Xstruct ship_stat stats[] = {
X{ "DN", 0, 6, 8, 8,  10, 2.,   1.5,  15., 200, 300, 600, 450, 5., 4.,  2, 4,
X   135, 225, 125, 235, 4, 4},
X{ "CA", 1, 4, 6, 9,  11, 1.,   0.75, 10., 150, 200, 450, 350, 3., 2.,  5, 2,
X   135, 225, 125, 235, 4, 4},
X{ "CL", 2, 4, 4, 9,  11, 0.75, 0.5,  10., 125, 175, 350, 250, 3., 2.,  6, 2,
X   150, 210, 140, 220, 4, 4},
X{ "DD", 3, 2, 4, 10, 12, 0.5,  0.5,  8.,  100, 150, 200, 150, 2., 1.5, 7, 1,
X   160, 200, 150, 210, 4, 4}
X};
END_OF_src/ships.c
if test 923 -ne `wc -c <src/ships.c`; then
    echo shar: \"src/ships.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/shipyard.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"src/shipyard.c\"
else
echo shar: Extracting \"src/shipyard.c\" \(5516 characters\)
sed "s/^X//" >src/shipyard.c <<'END_OF_src/shipyard.c'
X#ident "@(#) TREK73 $Header: shipyard.c,v 1.2 87/11/30 09:36:35 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/shipyard.c,v $
X *
X * $Header: shipyard.c,v 1.2 87/11/30 09:36:35 okamoto Exp $
X *
X * $Log:	shipyard.c,v $
X * Revision 1.2  87/11/30  09:36:35  09:36:35  okamoto (Jeff Okamoto)
X * Fixed some warnings from cc on advice of Bill Randle.
X * 
X * Revision 1.1  87/10/09  11:11:13  11:11:13  okamoto (Jeff Okamoto)
X * Initial revision
X * 
X */
X/*
X * TREK73: shipyard.c
X *
X * Design your own ship
X *
X */
X
X#include <stdio.h>
X#include <fcntl.h>
X#include "externs.h"
X
Xchar buf[20];
Xchar class[3];
Xchar cloak;
Xdouble bpv;
X
Xstruct {
X	char description[30];
X	char race[30];
X	char empire[30];
X} stuff;
X
Xstruct ship_stat design;
X
Xmain()
X{
X	double regen, efficiency, atof();
X	int crew, phasers, torps, pods, max_speed, turn, p_div, t_div;
X	int done, atoi();
X	void calculate();
X
Xtryagain:
X	done = 0;
X	while (!done) {
X		printf("Regeneration               :");
X		(void) gets(buf);
X		regen = atof(buf);
X		if (regen >= 0)
X			done = 1;
X		else
X			printf(">>> Be reasonable.\n");
X	}
X	done = 0;
X	while (!done) {
X		printf("Pods                       :");
X		(void) gets(buf);
X		pods = atof(buf);
X		if (pods >= 0)
X			done = 1;
X		else
X			printf(">>> Be reasonable.\n");
X	}
X	done = 0;
X	while (!done) {
X		printf("Number of phasers          :");
X		(void) gets(buf);
X		phasers = atoi(buf);
X		if ((phasers >= 0) && (phasers < MAXWEAPONS))
X			done = 1;
X		else
X			if (phasers < 0)
X				printf(">>> Be reasonable.\n");
X			else
X				printf(">>> Can't have more than %d.\n",
X				    MAXWEAPONS-1);
X	}
X	done = 0;
X	while (!done) {
X		printf("Number of tubes            :");
X		(void) gets(buf);
X		torps = atoi(buf);
X		if ((torps >= 0) && (torps < MAXWEAPONS))
X			done = 1;
X		else
X			if (torps < 0)
X				printf(">>> Be reasonable.\n");
X			else
X				printf(">>> Can't have more than %d.\n",
X				    MAXWEAPONS-1);
X	}
X	done = 0;
X	while (!done) {
X		printf("Shield divisor for phasers :");
X		(void) gets(buf);
X		p_div = atof(buf);
X		if (p_div > 0)
X			done = 1;
X		else
X			printf(">>> Be reasonable.\n");
X	}
X	done = 0;
X	while (!done) {
X		printf("Shield divisor for torps   :");
X		(void) gets(buf);
X		t_div = atof(buf);
X		if (t_div > 0)
X			done = 1;
X		else
X			printf(">>> Be reasonable.\n");
X	}
X	done = 0;
X	while (!done) {
X		printf("Crew                       :");
X		(void) gets(buf);
X		crew = atoi(buf);
X		if (crew > 0)
X			done = 1;
X		else
X			printf(">>> Be reasonable.\n");
X	}
X	printf("Can the ship cloak         ?");
X	(void) gets(buf);
X	if (buf != NULL && (buf[0] == 'y' || buf[0] == 'Y'))
X		cloak = 1;
X	else
X		cloak = 0;
X
X	calculate(regen, (float)pods, (float)p_div, (float)t_div,
X	    phasers + torps, crew,
X	    &bpv, &efficiency, &turn, &max_speed);
X
X	printf("BPV = %.2f\n", bpv);
X	printf("Efficiency = %.2f\n", efficiency);
X	printf("Turn = %d\n", turn);
X	printf("Max speed = %d\n", max_speed);
X
X	printf("\nKeep this ship? ");
X	(void) gets(buf);
X	if (buf != NULL && (buf[0] == 'n' || buf[0] == 'N'))
X		goto tryagain;
X
X	printf("Class identifier           :");
X	(void) gets(class);
X	class[2] = '\0';
X	printf("Class description          :");
X	(void) gets(stuff.description);
X	stuff.description[29] = '\0';
X	printf("Race name                  :");
X	(void) gets(stuff.race);
X	stuff.race[29] = '\0';
X	printf("Empire name                :");
X	(void) gets(stuff.empire);
X	stuff.empire[29] = '\0';
X
X	strcpy(design.abbr, class);
X	design.num_phaser = phasers;
X	design.num_torp = torps;
X	/*
X	 * The maximum warp speed for an "enemy" version of this class
X	 * is 2 greater than the "good-guys" version, just as the
X	 * standard class ships are
X	 */
X	design.o_warpmax = max_speed;
X	design.e_warpmax = max_speed + 2;
X	/*
X	 * "Enemy" efficiency is harder to gauge.  It should never
X	 * be less than zero, but should be less than the player's
X	 * version, otherwise the player could run away forever.
X	 * Until a good method is devised, we'll just leave it equal
X	 * to the player's own
X	 */
X	design.o_eff = efficiency;
X	design.e_eff = efficiency;
X	design.regen = regen;
X	/*
X	 * The starting energy is arbitrarily put at 75% of maximum
X	 */
X	design.energy = pods * 3 / 4;
X	design.pods = pods;
X	/*
X	 * The enemy crew is numbered at 25% greater than your own
X	 */
X	design.o_crew = crew;
X	design.e_crew = crew * 5 / 4;
X	design.ph_shield = p_div;
X	design.tp_shield = t_div;
X	design.turn_rate = turn;
X	/*
X	 * The cloaking energy is arbitrary
X	 */
X	design.cloaking_energy = 4;
X	/*
X	 * The blind arcs and firing delays after voiding a cloak
X	 * are arbitrarily set as equal to those of the heavy cruiser.
X	 * A better algorithm should be devised.
X	 */
X	design.t_blind_left = 135;
X	design.t_blind_right = 225;
X	design.p_blind_left = 125;
X	design.p_blind_right = 235;
X	design.p_firing_delay = CLOAK_DELAY;
X	design.t_firing_delay = CLOAK_DELAY;
X
X	save_design();
X}
X
Xsave_design()
X{
X	int fd, bytes;
X	char path[BUFSIZ];
X	char *home, *getenv();
X
X	if ((home = getenv("HOME")) != NULL)
X		strcpy(path, home);
X	else
X		strcpy(path, ".");
X	
X	strcat(path, "/.trek");
X	strcat(path, design.abbr);
X	printf("Saving to file %s\n", path);
X	
X	if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
X		perror("open");
X		exit(1);
X	}
X	bytes = write(fd, (char *)&design, sizeof(struct ship_stat));
X	if (bytes != sizeof(struct ship_stat)) {
X		fprintf(stderr, "Wrote only %d, not %d bytes\n", bytes,
X		    sizeof(struct ship_stat));
X		unlink(path);
X		exit(1);
X	}
X	bytes = write(fd, &stuff, sizeof(stuff));
X	bytes = write(fd, &cloak, 1);
X	bytes = write(fd, (char *)&bpv, sizeof(int));
X	close(fd);
X}
END_OF_src/shipyard.c
if test 5516 -ne `wc -c <src/shipyard.c`; then
    echo shar: \"src/shipyard.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 4 \(of 6\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0