Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!watmath!clyde!cbatt!ucbvax!okamoto
From: okamoto@ucbvax.UUCP
Newsgroups: net.sources.games
Subject: Trek73 (Part 2 of 6)
Message-ID: <16575@ucbvax.BERKELEY.EDU>
Date: Wed, 10-Dec-86 12:29:03 EST
Article-I.D.: ucbvax.16575
Posted: Wed Dec 10 12:29:03 1986
Date-Received: Sun, 14-Dec-86 03:26:28 EST
Organization: University of California at Berkeley
Lines: 1852

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	cmds3.c
#	cmds4.c
#	damage.c
#	dist.c
#	endgame.c
#	enemycom.c
# This archive created: Wed Dec 10 09:01:12 1986
# By:	Jeff Okamoto ()
export PATH; PATH=/bin:$PATH
if test -f 'cmds3.c'
then
	echo shar: will not over-write existing file "'cmds3.c'"
else
cat << \SHAR_EOF > 'cmds3.c'
/*
 * TREK73: cmds3.c
 *
 * User Commands
 *
 * jettison_engineering, detonate_engineering, phaser_status, tube_status,
 * survivors, alter_power
 *
 * (do_jettison)
 *
 */

#include "externs.h"
#include 


jettison_engineering(sp)
struct ship *sp;
{

	printf("   Mr. %s, jettison our engineering section!\n", engineer);
	if (is_dead(sp, S_ENG)) {
		printf("%s:  But Captain, it's already jettisonned.\n", engineer);
		return 0;
	}
	do_jettison(sp);
	printf("%s:  Aye, %s.  Jettisoning engineering.\n", 
	    engineer, title);
	return 1;
}

do_jettison(sp)
struct ship *sp;
{
	register struct list *lp;
	register struct torpedo *tp;

	lp = newitem(I_ENG);
	tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
	if (tp == (struct torpedo *)NULL) {
		fprintf(stderr, "do_jettison: malloc failed\n");
		exit(2);
	}
	tp->target = NULL;
	tp->speed = sp->warp;
	tp->newspeed = 0.0;
	tp->x = sp->x;
	tp->y = sp->y;
	tp->course = sp->course;
	/* This is correct */
	tp->fuel = sp->energy;
	tp->timedelay = 10.;
	tp->prox = 0;
	tp->from = sp;
	tp->id = new_slot();
	tp->type = TP_ENGINEERING;
	sp->energy = sp->pods = 0.;
	sp->newwarp = (sp->warp < 0.0) ? -0.99 : 0.99;
	sp->regen = 0.0;
	sp->status[S_ENG] = 100;	/* Set these as destroyed */
	sp->status[S_WARP] = 100;
	sp->max_speed = 1.0;
	sp->cloaking = C_NONE;
	sp->t_blind_left = sp->t_blind_right =
	    sp->p_blind_left = sp->p_blind_right = 180;
}

detonate_engineering(sp)
struct ship *sp;
{
	register struct list *lp;
	register struct torpedo *tp;
	register int found;
	char buf[10];

	found = 0;
	printf("   Mr. %s, detonate engineering!\n", engineer);
	if (!is_dead(sp, S_ENG)) {
		printf("%s: But %s, it's still attached.\n",engineer,title);
		printf("   Detonate anyway? ");
		printf("%s:  [yes or no] ", captain);
		(void) Gets(buf, sizeof(buf));
		if ((buf[0] == NULL)
		    || ((buf[0] != 'y') && (buf[0] != 'Y')))
			return 0;
		else 
			do_jettison(sp);
	}
	for (lp = &head; lp != tail; lp = lp->fwd) {
		if (lp->type != I_ENG)
			continue;
		tp = lp->data.tp;
		if (tp->from != sp)
			continue;
		found++;
		tp->timedelay = 0.;
		break;
	}
	if (found)
		printf("%s:  Aye, %s.\n",engineer, title);
	else
		printf("%s:  Ours has already detonated.\n", engineer);
	return 1;
}


phaser_status(sp)
struct ship *sp;
{
	register int i;

	puts("Phasers\n");
	printf("Control: ");
	for (i=0; inum_phasers; i++) {
		if (sp->phasers[i].status & P_DAMAGED)
			printf("\tdamaged");
		else if (sp->phasers[i].target == NULL)
			printf("\tmanual");
		else
			printf("\t%.7s", sp->phasers[i].target->name);
	}
	printf("\n Turned: ");
	for (i=0; inum_phasers; i++)
		if (sp->phasers[i].status & P_DAMAGED)
			putchar('\t');
		else if (sp->phasers[i].target == NULL)
			printf("\t%3.0f", sp->phasers[i].bearing);
		else
			printf("\tLOCKED");
	printf("\n  Level: ");
	for (i=0; inum_phasers; i++) {
		if (sp->phasers[i].status & P_DAMAGED)
			putchar('\t');
		else
			printf("\t%d", sp->phasers[i].load);
	}
	printf("\n  Drain: ");
	for (i=0; inum_phasers; i++) {
		if (sp->phasers[i].status & P_DAMAGED)
			putchar('\t');
		else
			printf("\t%d", sp->phasers[i].drain);
	}
	printf("\n\nFiring percentage: %d\n",sp->p_percent);
	printf("\nFiring angles: ");
	if (is_dead(sp, S_ENG)) {
		printf("unrestricted.\n");
	} else {
		printf("0 - %d and %d - 360.\n",
		    sp->p_blind_left, sp->p_blind_right);
	}
	return 1;
}

tube_status(sp)
struct ship *sp;
{
	register int i;

	puts("Torpedos\n");
	printf("Control: ");
	for (i=0; inum_tubes; i++) {
		if (sp->tubes[i].status & T_DAMAGED)
			printf("\tdamaged");
		else if (sp->tubes[i].target == NULL)
			printf("\tmanual");
		else
			printf("\t%.7s", sp->tubes[i].target->name);
	}
	printf("\n Turned: ");
	for (i=0; inum_tubes; i++)
		if (sp->tubes[i].status & T_DAMAGED)
			putchar('\t');
		else if (sp->tubes[i].target == NULL)
			printf("\t%.0f", sp->tubes[i].bearing);
		else
			printf("\tLOCKED");
	printf("\n  Level: ");
	for (i=0; inum_tubes; i++) {
		if (sp->tubes[i].status & T_DAMAGED)
			putchar('\t');
		else
			printf("\t%d", sp->tubes[i].load);
	}
	printf("\n\nLaunch speed: %d\n", sp->t_lspeed);
	printf("  Time delay: %d\n", sp->t_delay);
	printf("  Prox delay: %d\n", sp->t_prox);
	printf("\nFiring angles: ");
	if (is_dead(sp, S_ENG)) {
		printf("unrestricted.\n");
	} else {
		printf("0 - %d and %d - 360.\n",sp->t_blind_left, sp->t_blind_right);
	}
	return 1;
}

survivors(sp)
struct ship *sp;
{
	struct ship *ep;
	register int i;

	printf("\nSurvivors reported:\n");
	for (i=0; i<=shipnum; i++) {
		ep = shiplist[i];
		if (sp->complement < 0)
			printf("   %s -- destructed", sp->name);
		else if (cantsee(ep))
			printf("   %s -- ???\n", ep->name);
		else
			printf("   %s -- %d\n", ep->name, ep->complement);
	}
	sp = sp;		/* LINT */
}

alter_power()
{
	register int i;
	float j;
	char buf1[20];

	printf("\n%s:  Regeneration rate is %5.2f.\n",engineer, shiplist[0]->regen);
	for (i=0; i 1.0))
				goto badparam;
			for (; ishields[i].attemp_drain =j;
			break;
		} else if ((j < 0.0) || (j > 1.0))
			goto badparam;
		else
			shiplist[0]->shields[i].attemp_drain = j;
	}				
	printf("\n");
	for (i=0; inum_phasers; i++) {
		printf("%s:  Phaser %d drain is [%.0f to %.0f] ",
		    captain, i + 1, MIN_PHASER_DRAIN, MAX_PHASER_DRAIN);
		(void) Gets(buf1, sizeof(buf1));
		j = (float) atof(buf1);
		if (buf1[strlen(buf1) - 1] == '*') {
			if ((j < MIN_PHASER_DRAIN)
			    || (j > MAX_PHASER_DRAIN))
				goto badparam;
			for (; inum_phasers; i++)
				shiplist[0]->phasers[i].drain = (int) j;
			break;
		} else if ((j < MIN_PHASER_DRAIN) 
		    || (j > MAX_PHASER_DRAIN))
			goto badparam;
		else
			shiplist[0]->phasers[i].drain = (int) j;
	}
	return 1;
badparam:
	printf("%s:  Bad parameters, %s.\n", engineer, title);
	return 0;
}
SHAR_EOF
chmod +x 'cmds3.c'
fi # end of overwriting check
if test -f 'cmds4.c'
then
	echo shar: will not over-write existing file "'cmds4.c'"
else
cat << \SHAR_EOF > 'cmds4.c'
/*
 * TREK73: cmds4.c
 *
 * User Commands
 *
 * alterpntparams, play_dead, corbomite_bluff, surrender_ship,
 * request_surrender, self_destruct, abort_self_destruct
 *
 */

#include "externs.h"


alterpntparams(sp)
struct ship *sp;
{
	int temp;
	char buf1[30];

	printf("\n%s:  Reset tubes, %s?\n",nav,title);
	printf("%s:  [yes or no] ",captain);
	(void) Gets(buf1, sizeof(buf1));
	if (buf1[0] == NULL)
		return 0;
	if ((buf1 != NULL) && (buf1[0] != 'n')) {
		printf("   Set launch speed to [0-%d] ", MAX_TUBE_SPEED);
		(void) Gets(buf1, sizeof(buf1));
		if (buf1[0] == NULL)
			return 0;
		if (buf1 != NULL) {
			temp = atoi(buf1);
			if ((temp > -1) && (temp < MAX_TUBE_SPEED + 1))
				sp->t_lspeed = temp;
		}
		printf("   Set time delay to [0-%d] ", (int) MAX_TUBE_TIME);
		(void) Gets(buf1, sizeof(buf1));
		if (buf1[0] == NULL)
			return 0;
		if (buf1 != NULL) {
			temp = atoi(buf1);
			if ((temp > -1) && (temp < (int)(MAX_TUBE_TIME + 1)))
				sp->t_delay = temp;
		}
		printf("   Set proximity delay to [0-%d] ", MAX_TUBE_PROX);
		(void) Gets(buf1, sizeof(buf1));
		if (buf1[0] == NULL)
			return 0;
		if (buf1 != NULL) {
			temp = atoi(buf1);
			if ((temp > -1) && (temp < MAX_TUBE_PROX + 1))
				sp->t_prox = temp;
		}
	}
	printf("%s:  Reset phasers, %s?\n",nav ,title);
	printf("%s:  [yes or no] ",captain);
	(void) Gets(buf1, sizeof(buf1));
	if (buf1[0] == NULL)
		return 0;
	if ((buf1 != NULL) && (buf1[0] != 'n')) {
		printf("   Reset firing percentage to [0-100] ");
		if (Gets(buf1, sizeof(buf1)) == NULL)
			return 0;
		if (buf1 != NULL) {
			temp = atoi(buf1);
			if ((temp > -1) && (temp < 101))
				sp->p_percent = temp;
		}
	}
	return 0;
}

play_dead(sp)
struct ship *sp;
{
	
	char buf1[30];
	int  phaser_charge;
	register int i;

	printf("%s:   %s, drop shields ...\n", captain, nav);
	if (defenseless) {
		printf("%s:   %s, the %ss are not that stupid.\n",
		    science, title, foerace);
		return 0;
	}
	printf("   Transfer power to [engines or phasers]: ");
	(void) Gets(buf1, sizeof(buf1));
	if (buf1[0] == NULL) {
		printf("%s:   I cannot transfer power there, %s.\n",
		    nav, title);
		return 0;
	}
	phaser_charge = -MAX_PHASER_CHARGE;
	if (buf1[0] != 'e' && buf1[0] != 'E') {
		phaser_charge = MAX_PHASER_CHARGE;
		if (buf1[0] != 'p' && buf1[0] != 'P') {
			printf("%s:   I cannot transfer power there, %s.\n",
			    nav, title);
			return 0;
		}
	}
	for (i=0;ishields[i].attemp_drain = 0.0;
	for (i=0;inum_phasers;i++)
		sp->phasers[i].drain = phaser_charge;
	defenseless = 1;
	return 0;
}

corbomite_bluff(sp)
struct ship *sp;
{
	
	if (randm(2) == 1) {
		printf("%s:   Open a hailing frequency, ship-to-ship.\n",
		    captain);
		printf("%s:  Hailing frequency open, %s.\n", com, title);
		printf("%s:  This is the Captain of the %s.  Our respect for\n",
		    captain, sp->name);
		puts("   other life forms requires that we give you this warning--");
		puts("   one critical item of information which has never been");
		puts("   incorporated into the memory banks of any Earth ship.");
		puts("   Since the early years of space exploration, Earth vessels");
		puts("   have had incorporated into them a substance know as corbomite.");
		if (!corbomite) {
			puts("      It is a material and a device which prevents attack on");
			puts("   us.  If any destructive energy touchs our vessel, a re-");
			puts("   verse reaction of equal strength is created, destroying");
			puts("   the attacker.  It may interest you to know that, since");
			puts("   the initial use of corbomite for more than two of our");
			puts("   centuries ago, no attacking vessel has survived the attempt.");
			puts("   Death has little meaning to us.  If it has none to you,");
			puts("   then attack us now.  We grow annoyed with your foolishness.");
		}
	} else {
		printf("%s:   Open a special channel to Starfleet Command.\n",
		    captain);
		printf("%s:   Aye, %s.\n", com, title);
		printf("%s:   Use Code 2.\n", captain);
		printf("%s:   but, %s, according to our last Starfleet\n",
		    com, title);
		printf("   Bulletin, the %ss have broken code 2.\n", foerace);
		printf("%s:   That's an order, Lieutenant.  Code 2!\n",
		    captain);
		printf("%s:   Yes, Captain.  Code 2.\n", com);
		printf("%s:   Message from %s to Starfleet Command, this sector.\n",
		    captain, sp->name);
		printf("   have inadvertantly encroached upon %s neutral zone,\n",
		    foerace);
		printf("   surrounded and under heavy %s attack.  Escape\n",
		    foerace);
		puts("   impossible.  Shields failing.  Will implement destruct");
		puts("   order using corbomite device recently installed.");
		if (!corbomite) {
			printf("   This will result in the destruction of the %s and\n",
			    sp->name);
			puts("   all matter within a 200 megameter diameter and");
			puts("   establish corresponding dead zone, all Federation");
			puts("   vessels will aviod this area for the next four solar");
			printf("   years.  Explosion will take place in one minute.  %s,\n",
			    captain);
			printf("   commanding %s, out.\n",sp->name);
		}
	}
	if (!corbomite) {
		printf("      Mr. %s.  Stand by.\n", helmsman);
		printf("%s:  Standing by.\n", helmsman);
		corbomite = 1;
	} else {
		printf("\n%s:  I don't believe that they will fall for that maneuver\n",
		    science);
		printf("   again, %s.\n", title);
	}
	return 0;
}

surrender_ship(sp)
struct ship *sp;
{
	printf("%s:   %s, open a channel to the %ss.\n", captain, com, foerace);
	printf("%s:   Aye, %s.\n", com, title);
	printf("%s:   This is Captain %s of the U.S.S. %s.  Will\n",
	    captain, captain, sp->name);
	puts("   you accept my unconditional surrender?");
	if (global & F_SURRENDER) {
		printf("%s:  %s, we have already surrendered.\n",
		    science, title);
		return 0;
	}
	if (surrender) {
		printf("%s:  The %ss have already refused.\n",science, foerace);
	} else {
		if (foerace == "Romulan") {
			printf("%s:  The %ss have not been know to have taken\n",
			    science, foerace);
			puts("   prisoners.");
		}
		surrender = 1;
	}
	return 0;
}

request_surrender(sp)
struct ship *sp;
{
	printf("%s:   %s, open a hailing frequency to the %ss.\n",
	    com, captain,foerace);
	printf("%s:  Aye, %s.\n", com, title);
	printf("%s:  This is Captain %s of the U. S. S. %s.  I give you\n",
	    captain, captain, sp->name);
	puts("   one last chance to surrender before we resume our attack.");
	if (global & E_SURRENDER) {
		printf("%s:  %s, we are already complying with your previous request!\n",
		    foename, captain);
		return 0;
	}
	if (surrenderp) {
		printf("%s:   %s, our offer has already been refused.\n",
		    science, title);
	} else {
		surrenderp = 1;
	}
	return 0;
}

self_destruct(sp)
struct ship *sp;
{
	printf("%s:   Lieutenant %s, tie in the bridge to the master\n",captain, com);
	printf("   computer.\n");
	if (is_dead(sp, S_COMP)) {
		printf("%s:  Our computer is down.\n", science);
		return 0;
	}
	if (!syswork(sp, S_COMP)) {
		printf("%s:  That program has been lost.  Restoring from backup.",
		    science);
		return 0;
	}
	printf("%s:  Aye, %s.\n",com, title);
	printf("%s:  Computer.  Destruct sequence.  Are you ready to copy?\n",captain);
	puts("Computer:  Working.");
	printf("%s:  Computer, this is Captain %s of the U.S.S. %s.\n",
	    captain, captain, sp->name);
	puts("   Destruct sequence one, code 1-1A.");
	puts("Computer:  Voice and code verified and correct.");
	puts("   Sequence one complete.");
	printf("%s:  This is Commander %s, Science Officer.  Destruct\n",
	    science, science);
	puts("   sequence two, code 1-1A-2B.");
	puts("Computer:  Voice and code verified and correct.  Sequence");
	puts("   two complete.");
	printf("%s:  This is Lieutenant Commander %s, Chief Engineering\n",
	    engineer, engineer);
	printf("   Officer of the U. S. S. %s.  Destruct sequence\n",sp->name);
	puts("   number three, code 1B-2B-3.");
	puts("Computer:  Voice and code verified and correct.");
	puts("   Destruct sequence complete and engaged.  Awaiting final");
	puts("   code for twenty second countdown.");
	printf("%s:  Computer, this is Captain %s of the U. S. S. %s.\n",
	    captain, captain, sp->name);
	puts("   begin countdown, code 0-0-0, destruct 0.");
	puts("Computer:  20 seconds to self-detruct.");
	sp->delay = 20.;
	return 0;
}

abort_self_destruct(sp)
struct ship *sp;
{
	printf("%s:   Computer, this is Captain %s of the U.S.S. %s.\n",
	    captain, captain, sp->name);
	puts("   Code 1-2-3 continuity abort destruct order, repeat:");
	puts("   Code 1-2-3 continuity abort destruct order!");
	if (is_dead(sp, S_COMP)) {
		printf("%s:  Our computer is down.\n", science);
		return 0;
	}
	if (!syswork(sp, S_COMP)) {
		printf("%s:  Temporary memory loss.  Unable to find program.\n",
		    science);
		return 0;
	}
	if (sp->delay > 1000.) {
		puts("Computer:  Self-destruct sequence has not been");
		puts("   initiated.");
		return 0;
	}
	printf("Computer:   Self-destruct order ... ");
	(void) fflush(stdout);
	sleep(4);
	if (sp->delay > 4.) {
		puts("aborted.  Destruct order aborted.");
		sp->delay = 10000.;
		return 0;
	} else {
		puts("cannot be aborted.");
		return 0;
	}
}
SHAR_EOF
chmod +x 'cmds4.c'
fi # end of overwriting check
if test -f 'damage.c'
then
	echo shar: will not over-write existing file "'damage.c'"
else
cat << \SHAR_EOF > 'damage.c'
/*
 * TREK73: damage.c
 *
 * Damage routines
 *
 * damage, check_locks
 *
 */

#include "externs.h"


damage(hit, ep, s, dam, flag)
int hit;
struct ship *ep;
int s;
struct damage *dam;
int flag;
{
	register int i;
	register int j;
	register int k;
	float	f1;		/* Damage factor except for shields */
	float	f2;		/* Shield damage factor */
	int percent;
	struct ship *fed;

	fed = shiplist[0];
	printf("hit %d on %s's shield %d\n", hit, ep->name, s);
	s--;
	/*
	 * Note that if the shield is at 100% efficiency, no
	 * damage at all will be taken (except to the shield itself)
	 */
	f1 = hit * (1.0 - ep->shields[s].eff * ep->shields[s].drain);
	if (f1 < 0)
		return 0;
	/* Calculate shield damage */
	if (flag == D_ANTIMATTER)
		f2 = ep->tu_damage * 100;
	else if (flag == D_PHASER)
		f2 = ep->ph_damage * 100;
	if (s == 0)
		f2 *= SHIELD1;
	ep->shields[s].eff -= max(hit/f2, 0);
	if (ep->shields[s].eff < 0.0)
		ep->shields[s].eff = 0.0;
	/* Calculate loss of fuel, regeneration, etc. */
	ep->eff += f1/dam->eff;
	ep->pods -= f1/dam->fuel;
	ep->energy -= f1/dam->fuel;
	ep->regen -= f1/dam->regen;
	if (ep->regen < 0.0)
		ep->regen = 0.0;
	if (ep->pods < 0.0)
		ep->pods = 0.0;
	if (ep->energy < 0.0)
		ep->energy = 0.0;
	if (ep->pods < ep->energy)
		ep->energy = ep->pods;
	/* Kill some crew */
	if (ep->complement > 0) {
		j = f1 * dam->crew;
		if (j > 0)
			ep->complement -= randm(j);
		if (ep->complement < 0)
			ep->complement = 0;
	}
	/* Damage some weapons */
	j = f1/dam->weapon;
	for(i=0; inum_phasers + ep->num_tubes) - 1;
		if (k < ep->num_phasers) {
			if (ep->phasers[k].status & P_DAMAGED)
				continue;
			ep->phasers[k].status |= P_DAMAGED;
			ep->phasers[k].target = NULL;
			/*
			 * Reroute the energy
			 * back to the engines
			 */
			ep->energy = min(ep->pods, ep->energy
			    + ep->phasers[k].load);
			ep->phasers[k].load = 0;
			ep->phasers[k].drain = 0;
			k++;
			if (ep == fed)
				printf("   phaser %d damaged\n", k);
		} else {
			k -= ep->num_phasers;
			if (ep->tubes[k].status & T_DAMAGED)
				continue;
			/*
			 * If tubes are damaged, reroute the pods
			 * back to the engines
			 */
			ep->pods += ep->tubes[k].load;
			ep->energy += ep->tubes[k].load;
			ep->tubes[k].load = 0;
			ep->tubes[k].status |= T_DAMAGED;
			ep->tubes[k].target = NULL;
			k++;
			if (ep == fed)
				printf("   tube %d damaged\n", k);
		}
	}
	/* Damage the different systems */
	for (i=0; istats[i].roll) < f1) {
			/* A better method should be found */
			percent = (int) randm((int) f1);
			/* The expected value for the percent damage
			   to each system is roughly equal to:
			      f1 * f1 / (2 * dam->stats[i].roll)
			   Only these damages are proportional to hit
			   squared.  All others are linearly
			   proportional.  This includes shield damage,
			   ship's fuel supply, consumption and
			   regeneration rates, casualties, and weapons.
			   (When weapons are damaged, they are 100%
			   damaged - the number of weapons damaged is
			   proportional to hit.)
			   I think the old way decided whether or not to
			   completely damage a system based on the
			   comparison "randm(dam->stats[i].roll) < f1".
			   This is almost like the weapons are still
			   handled.  Another possibility is to always
			   damage each system by:
			      100 * randm((int)f1) / dam->stats[i].roll
			   percent.  This adds some randomness and makes
			   the approx. expected value of the damage to
			   each system:
			      100 * f1 / (2 * dam->stats[i].roll)
			   percent.  Perhaps this isn't such a good
			   idea after all; this is 100/f1 times the
			   current expected value, often > 2.  And it is
			   actually somewhat less random since each
			   system gets damaged each time.  I had thought
			   that the damage should be directly
			   proportional to f1, not to its square.
			   But perhaps it makes sense that a hit twice
			   as big has an expected value of damage four
			   times as big as that from a smaller hit.
			   The actual damage any given time is still
			   proportional to the hit, but the probability
			   that any damage will be done at all is also
			   directly proportional to the hit.  This is
			   a pretty good system after all.	[RJN]
			*/
			ep->status[i] += percent;
			if (ep->status[i] > 100)
				ep->status[i] = 100;
			if (ep == fed) {
				if (is_dead(ep, i))
					printf("   %s\n",
				    	    dam->stats[i].mesg);
				else
					printf("   %s damaged.\n",
					    sysname[i]);
			}
			/* Now check for the effects of the damage */
			/* Do the effects of a totally destroyed system */
			if (is_dead(ep, i)) {
				switch(i) {
				case S_SENSOR:
				case S_PROBE:
					/* No bookkeeping needed */
					break;
				case S_WARP:
					/* Reduce max speed */
					ep->max_speed = 1.0;
					break;
				case S_COMP:
					check_locks(ep, 100, fed);
					break;
				default:
					printf("How'd we get here?\n");
				}
			} else {
				/* Now check partially damaged systems */
				switch(i) {
				case S_SENSOR:
				case S_PROBE:
					/* No bookkeeping needed */
					break;
				case S_WARP:
					f2 = percent * ep->orig_max / 100;
					ep->max_speed -= f2;
					if (ep->max_speed < 1.0) {
						ep->max_speed = 1.0;
						ep->status[S_WARP] = 100;
					}
					break;
				case S_COMP:
					check_locks(ep, percent, fed);
					break;
				default:
					printf("Oh, oh....\n");
				}
			}
		}
	}
#ifdef HISTORICAL
	/*
	 * Historically, if more than 43 points of damage were done
	 * to the ship, it would destroy itself.  This led to much
	 * abuse of probes and thus has been enclosed inside of
	 * an #ifdef
	 */
	if (f1 > 43)
		ep->delay = 1.;
#endif
	return 0;
}

check_locks(ep, percent, fed)
struct ship *ep;
int percent;
struct ship *fed;
{
	register int i, j = 0;

	for (i=0; inum_phasers; i++) {
		if ((ep->phasers[i].target != NULL)
		    && (randm(100) <= percent)) {
			ep->phasers[i].target = NULL;
			if (ep != fed)
				continue;
			if (!j)
				printf("Computer: Phaser(s) %d", i+1);
			else
				printf(", %d", i+1);
			j++;
		}
	}
	if (j > 1)
		puts(" have lost their target locks.");
	else if (j == 1)
		puts(" has lost its target lock.");
	j = 0;
	for (i=0; inum_tubes; i++) {
		if ((ep->tubes[i].target != NULL)
		    && (randm(100) <= percent)) {
			ep->tubes[i].target = NULL;
			if (ep != fed)
				continue;
			if (!j)
				printf("Computer: Tube(s) %d", i+1);
			else
				printf(", %d", i+1);
			j++;
		}
	}
	if (j > 1)
		puts(" have lost their target locks.");
	else if (j == 1)
		puts(" has lost its target lock.");
	if ((ep->target != NULL) && (randm(100) <= percent)) {
		ep->target = NULL;
		ep->relbear = 0;
		if (ep == fed)
			printf("Computer: %s has lost helm lock\n",
			    shipname);
	}
}
SHAR_EOF
chmod +x 'damage.c'
fi # end of overwriting check
if test -f 'dist.c'
then
	echo shar: will not over-write existing file "'dist.c'"
else
cat << \SHAR_EOF > 'dist.c'
/*
 * TREK73: dist.c
 *
 * Power distribution routines
 *
 * distribute
 *
 */

#include "externs.h"
#include 


distribute(sp)
struct ship *sp;
{
	register int i;
	register float fuel;
	register int load;
	register int effload;
	register int drain;
	register int loop;
	float shield;
	struct ship *fed;

	fed = shiplist[0];
	/*
	 * Granularity of 1 second as far as this loop is concerned
	 */
	for (loop = 0; loop < (int)timeperturn; loop++) {

		fuel = sp->energy + sp->regen;	/* Slightly unrealistic */
		/*
		 * Calculate negative phaser drains
		 */
		for (i=0; inum_phasers; i++) {
			load = sp->phasers[i].load;
			drain = sp->phasers[i].drain;
			if ((sp->phasers[i].status & P_DAMAGED)
			    || (drain >= 0) || (load <= 0))
				continue;
			/*
			 * Drain the lesser of either the current load if the
			 * load is less than the drain, or the drain value
			 */
			effload = max(load + drain, 0);
			fuel += load - effload;
			sp->phasers[i].load = effload;
		}
		/*
		 * Calculate shield drains
		 */
		shield = 0.0;
		for (i=0; ishields[i].attemp_drain;
		drain = ceil((double) shield);
		/*
		 * If all attempted drains are zero, or we have no
		 * fuel, our shields are down!
		 */
		if ((shield * fuel == 0) && !shutup[SHIELDSF]
		    && sp == shiplist[0]) {
			printf("%s: %s, our shields are down!\n",engineer, title);
			shutup[SHIELDSF]++;
		}
		/*
		 * If there's not enough fuel to sustain the drains, then
		 * ration it out in proportion to the attempted drains and
		 * say that shields are fluctuating.
		 */
		if (drain <= fuel) {
			fuel -= drain;
			for (i=0; ishields[i].drain = sp->shields[i].attemp_drain;
		} else {
			if (!shutup[SHIELDSF] && sp == shiplist[0]) {
				printf("%s: %s, our shields are fluctuating!\n",
				    engineer, title);
				shutup[SHIELDSF]++;
			}
			for (i=0; ishields[i].drain =
				    sp->shields[i].attemp_drain *
				    fuel / drain;
			fuel = 0.;
		}
		/*
		 * Calculate cloaking device drains.  If there is
		 * in sufficient energy to run the device, then
		 * it is turned off completely
		 */
		if (cantsee(sp)) {
			if (fuel < sp->cloak_energy) {
				if (sp == shiplist[0]) {
					sp->cloaking = C_OFF;
					printf("%s:  %s, there's not enough energy to",
					    engineer, title);
					puts("    keep our cloaking device activated.");
				} else
					(void) e_cloak_off(sp, fed);
			} else
				fuel -= sp->cloak_energy;
		}
		/*
		 * Calculate positive phaser drains
		 */
		for (i=0; inum_phasers && fuel > 0; i++) {
			if (fuel <=0.)
				break;
			load = sp->phasers[i].load;
			drain = sp->phasers[i].drain;
			if ((sp->phasers[i].status & P_DAMAGED)
			    || load >= MAX_PHASER_CHARGE || drain <= 0)
				continue;
			/*
			 * Load phasers either enough to top them off, or
			 * the full drain
			 */
			effload = min(MAX_PHASER_CHARGE,
			    load + min(drain, fuel));
			fuel -= effload - load;
			sp->phasers[i].load = effload;
		}
		/*
		 * Now balance the level of energy with the numer of pods
		 */
		sp->energy = min(fuel, sp->pods);
	}
}
SHAR_EOF
chmod +x 'dist.c'
fi # end of overwriting check
if test -f 'endgame.c'
then
	echo shar: will not over-write existing file "'endgame.c'"
else
cat << \SHAR_EOF > 'endgame.c'
/*
 * TREK73: endgame.c
 *
 * prints end-of-game messages and warnings
 *
 * leftovers, final, warn
 *
 */

#ifdef BSD
#include 
#endif

#include "externs.h"


leftovers()
{
	register struct list *lp;

	for (lp = &head; lp != tail; lp = lp->fwd) {
		if (lp->type == 0)
			continue;
		if (lp->type != I_SHIP)
			return 1;
	}
	return 0;
}


final(mesg)
int mesg;
{
	register int i;
	register int j;
	struct	ship *sp;
	struct	ship *ep;
	char buf[80];


	sp = shiplist[0];
	/* If we're getting that message again, ignore it. */
	if ((mesg == 2) && (reengaged))
		return;
	switch (mesg) {
	case FIN_F_LOSE:
		starfleet();
		printf("We have recieved confirmation that the U.S.S. %s,\n",
			sp->name);
		printf("   captained by %s, was destroyed by %s%s\n",
		    captain, shipnum==1 ?"a ":"", foerace);
		printf("   %s%s.  May future Federation officers\n",
		    foestype, plural(shipnum));
		printf("   perform better in their duties.\n\n");
		break;
	case FIN_E_LOSE:
		starfleet();
		printf("We commend Captain %s and the crew of the %s on their\n",
		    captain, shipname);
		printf("   fine performance against the %ss.  They are\n",
		    foerace);
		puts("   an inspiration to all Starfleet personnel.\n");
		break;
	case FIN_TACTICAL:
		/*
		 * Give him a chance to re-engage if he wants to.  If he does,
		 * he has to get within a range of 3500 before he can again
		 * try to dis-engage
		 */
		if (!reengaged) {
			printf("%s:  %s, we are in a position to either disengage from the\n",
			    science, title);
			printf("   %ss, or re-engage them in combat.\n",
			    foerace);
			printf("   Do you wish to re-engage?\n");
			printf("%s: [y or n] ", captain);
			gets(buf);
			if ((*buf == NULL) || (*buf == 'y') || (*buf == 'Y')) {
				reengaged = 1;
				return;
			}
		}
		starfleet();
		printf("Captain %s of the starship %s has\n",captain,sp->name);
		printf("   out-maneuvered %s aggressors.  We commend\n",foerace);
		printf("   his tactical ability.\n");
		break;
	case FIN_F_SURRENDER:
		starfleet();
		printf("Captain %s has surrendered the U.S.S. %s \n",
		    captain, sp->name);
		printf("   to the %ss.  May Captain Donsell be remembered.\n",
		    foerace);
		break;
	case FIN_E_SURRENDER:
		starfleet();
		printf("We have recieved word from the %s that the\n",sp->name);
		printf("   %ss have surrendered.\n",foerace);
		break;
	case FIN_COMPLETE:
		starfleet();
		puts("One of our scout vessels has encountered the wreckage of");
		printf("   the %s and %d other %s vessel%s.\n", sp->name,
			shipnum, foerace, plural(shipnum));
		break;
	case QUIT:
		starfleet();
		printf("We have received word that Captain %s of the\n",
		    captain);
		printf("  starship %s has sold out to the %ss.\n",sp->name,
		    foerace);
		printf("  May he soon be court-martialled.\n");
		break;
	default:
		printf("How did we get here? final(%d)\n", mesg);
		break;
	}
	puts("\n\n");
	j = 0;
	for (i=0; i<=shipnum; i++) {
		ep = shiplist[i];
		if (is_dead(ep, S_DEAD))
			continue;
		if (!j)
			puts("Survivors Reported:\n");
		j++;
	}
	if (j) {
		for (i=0; i<=shipnum; i++) {
			ep = shiplist[i];
			if ((is_dead(ep, S_DEAD)) || (ep->complement <= 0))
				printf("   %s -- destroyed\n",
				    ep->name);
			else
				printf("   %s -- %d\n",
				    ep->name, ep->complement);
		}
	} else
		puts("*** No survivors reported ***\n");
	exit (1);
}



warn(mesg)
int mesg;
{
	static	int beenhere[5] = {0, 0, 0, 0, 0};
	struct	ship *sp;

	if ((reengaged) && (mesg == 2)) {
		return 0;
	}
	if (beenhere[mesg])
		return 0;
	sp = shiplist[0];
	switch (mesg) {
	case FIN_F_LOSE:
		printf("Message to the Federation:  This is Commander\n");
		printf("   %s of the %s %s.  We have defeated\n",
		    foename, foerace, empire);
		printf("   the %s and are departing the quadrant.\n", sp->name);
		break;
	case FIN_E_LOSE:
		printf("%s: All %s vessels have been either\n",
		    science, foerace);
		printf("   destroyed or crippled.  We still, however, have\n");
		printf("   antimatter devices to avoid.\n");
		break;
	case FIN_TACTICAL:
		printf("%s: The %ss are falling behind and seem to\n",
		    helmsman, foerace);
		printf("   be breaking off their attack.\n");
		break;
	case FIN_F_SURRENDER:
		printf("%s: I'm informing Starfleet Command of our \n", com);
		printf("   disposition.\n");
		break;
	case FIN_E_SURRENDER:
		printf("%s: Although the %ss have surrendered,\n",
		    science, foerace);
		printf("   there are still antimatter devices floating\n");
		printf("   around us.\n");
		break;
	default:
		printf("How did we get here? final(%d)\n", mesg);
		break;
	}
	beenhere[mesg]++;
	return 0;
}

starfleet()
{
	puts("\n\nStarfleet Command: \n");
	(void) sleep(3);
	putchar('\n');
}
SHAR_EOF
chmod +x 'endgame.c'
fi # end of overwriting check
if test -f 'enemycom.c'
then
	echo shar: will not over-write existing file "'enemycom.c'"
else
cat << \SHAR_EOF > 'enemycom.c'
/*
 * TREK73: enemycom.c
 *
 * Enemy strategy sub-routines
 *
 * e_attack, e_checkarms, e_checkprobe, e_cloak_off, e_cloak_on,
 * e_closetorps, e_destruct, e_evade, e_jettison, e_launchprobe,
 * e_loadtubes, e_lockphasers, e_locktubes, e_phasers, e_pursue,
 * e_runaway, e_torpedo
 *
 */

#include "externs.h"


/*
 * This routine turns the ship at speed towards its target
 */
int e_attack(sp, fed)
struct ship *sp;
struct ship *fed;
{
	float	speed;
	float	tmpf;

	tmpf = fabs(fed->warp);
	if (fabs(sp->warp) >= tmpf + 2.0 || (is_dead(sp, S_WARP)))
		return 0;
	if ((speed = tmpf + randm(2) + 2.0) > sp->max_speed)
		speed = sp->max_speed;
	(void) e_pursue(sp, fed, speed);
	if (cansee(sp) && syswork(fed, S_SENSOR))
		printf("%s:  %s attacking.\n", helmsman, sp->name);
	return 1;
}


/*
 * Returns the number of currently loaded, undamaged weapons
 */
int e_checkarms(sp)
struct ship *sp;
{
	register int i;
	register int arms;

	arms = 0;
	for (i=0; inum_phasers; i++)
		if (!(sp->phasers[i].status & P_DAMAGED) &&
		    (sp->phasers[i].load >= 0))
			arms++;
	for (i=0; inum_tubes; i++)
		if (!(sp->tubes[i].status & T_DAMAGED) &&
		    (sp->tubes[i].load >= 0))
			arms++;
#ifdef TRACE
	if (trace)
		printf("*** Checkarms: Returning %d\n", arms);
#endif
	return arms;
}


/*
 * returns 1 if evasive action being taken (to avoid probe)
 */
int e_checkprobe(sp)
struct ship *sp;
{
	register struct list *lp;
	register int range;
	register struct torpedo *tp;

	/*
	 * If we are cloaked, do not bother with this.
	 * Since probes cannot detect us when cloaked.
	 */
	if (cantsee(sp))
		return 0;
	for (lp = &head; lp != tail; lp = lp->fwd) {
		if (lp->type != I_PROBE)
			continue;
		tp = lp->data.tp;
		range = rangefind(sp->x, tp->x, sp->y, tp->y);
#ifdef TRACE
		if (trace)
			printf("*** Checkprobe: Range = %d\n", range);
#endif
		if (range < 2000) {
			(void) e_evade(sp, tp->x, tp->y, I_PROBE);
			return 1;
		}
	}
	return 0;
}


/*
 * Returns 1 if cloaking device was turned off
 */
int e_cloak_off(sp, fed)
struct ship *sp;
struct ship *fed;
{
	if (sp->cloaking != C_ON)
		return 0;
	sp->cloaking = C_OFF;
	sp->cloak_delay = 4;
	if (syswork(sp, S_SENSOR)) {
		printf("%s:  The %s has reappeared on our sensors %d\n",
		    science, sp->name, rangefind(sp->x, sp->position.x,
		    sp->y, sp->position.y));
		puts("   megameters from its projected position.");
	}
	fed = fed;		/* LINT */
	return 1;
}


/*
 * Returns 1 if cloaking device was turned on
 */
int e_cloak_on(sp, fed)
struct ship *sp;
struct ship *fed;
{
	if ((sp->cloak_delay > 0) || (sp->cloaking != C_OFF))
		return 0;
	sp->cloaking = C_ON;
	sp->position.x = sp->x;
	sp->position.y = sp->y;
	sp->position.warp = sp->warp;
	sp->position.course = sp->course;
	if (syswork(fed, S_SENSOR))
		printf("%s:  The %s has disappeared from our sensors.\n",
		    science, sp->name);
	fed = fed;		/* LINT */
	return 1;
}


/*
 * Returns 1 if firing phasers at or evading nearby torpedoes
 */
int e_closetorps(sp, fed)
struct ship *sp;
struct ship *fed;
{
	register struct list *lp;
	register int range;
	register struct torpedo *tp;
	struct	torpedo *bad;

	/*
	 * If we are cloaked, forget about this.
	 * Since prox fuses won't affect us under cloak
	 */
	if (cantsee(sp))
		return 0;
	bad = NULL;
	for (lp = &head; lp != tail; lp = lp->fwd) {
		if (lp->type != I_TORPEDO)
			continue;
		tp = lp->data.tp;
		if (tp->from != fed)
			continue;
		range = rangefind(sp->x, tp->x, sp->y, tp->y);
#ifdef TRACE
		if (trace)
			printf("*** Checktorp: Range = %d\n", range);
#endif
		if (range < 1200) {
			bad = tp;
			/*
			 * fire phasers - hope they're pointing in
			 * the right direction!
			 */
			if (e_phasers(sp, (struct ship *) NULL))
				return 1;
		}
	}
	/*
	 * we can't get a phaser shot off.
	 * try and evade (although hopeless)
	 */
	if (bad != NULL) {
#ifdef TRACE
		if (trace)
			printf("*** Checktorp: Cannot fire phasers!  Evade!\n");
#endif
		(void) e_evade(sp, tp->x, tp->y, I_TORPEDO);
		return 1;
	}
	return 0;
}


/*
 * goodbye, cruel world (Returns 1 if self-destruct was initiated)
 */
int e_destruct(sp, fed)
struct ship *sp, *fed;
{
	if (sp->delay < 5.0)
		return 0;
	sp->delay = 5.0;
	(void) e_cloak_off(sp, fed);
	sp->cloaking = C_NONE;
	if (syswork(fed, S_SENSOR)) {
		printf("%s: The %s is overloading what remains of it's\n",
		    science, sp->name);
		puts("   antimatter pods -- obviously a suicidal gesture.");
		puts("   Estimate detonation in five seconds.");
	}
	return 1;
}


/*
 * Advance to the rear! (Always returns 1)
 */
int e_evade(sp, x, y, type)
struct ship *sp;
int x;
int y;
int type;		/* Currently unused */
{
	register float newcourse;
	float	bear;

	bear = bearing(sp->x, x, sp->y, y);
	if (cansee(sp) && syswork(shiplist[0], S_SENSOR))
		printf("%s taking evasive action!\n", sp->name);
	switch (randm(3)) {
		case 1:
			newcourse = rectify(bear - 90.0);
			break;
		case 2:
			newcourse = rectify(bear + 90.0);
			break;
		case 3:
			newcourse = rectify(bear + 180.0);
			break;
		default:
			printf("error in evade()\n");
			break;
	}
	sp->target = NULL;
	sp->newcourse = newcourse;
	sp->newwarp = 2 + randm((int)(sp->max_speed - 3));
	if (is_dead(sp, S_WARP))
		sp->newwarp = 1.0;
#ifdef TRACE
	if (trace) {
		printf("*** Evade: Newcourse = %3.0f\n", newcourse);
		printf("*** Evade: Newwarp = %.2f\n", sp->newwarp);
	}
#endif
	type = type;	/* LINT */
	return 1;
}


/*
 * Returns 1 if engineering was jettisoned
 */
int e_jettison(sp, fed)
struct ship *sp, *fed;
{
	register struct list *lp;
	register struct torpedo *tp;

	if (is_dead(sp, S_ENG))
		return 0;
	(void) e_cloak_off(sp, fed);
	if (syswork(shiplist[0], S_SENSOR)) {
		printf("%s: Sensors indicate debris being left by\n", science);
		printf("   the %s.  Insufficient mass . . .\n", sp->name);
	}
	lp = newitem(I_ENG);
	tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
	if (tp == (struct torpedo *)NULL) {
		fprintf(stderr, "e_jettison: malloc failed\n");
		exit(2);
	}
	tp->id = new_slot();
	/*
	 * ship slows to warp 1.0 when jettisonning engineering
	 */
	tp->newspeed = 0.0;
	tp->speed = sp->warp;
	tp->target = NULL;
	tp->course = sp->course;
	tp->x = sp->x;
	tp->y = sp->y;
	tp->prox = 0;
	tp->timedelay = 10.;
	tp->fuel = sp->energy;
	tp->type = TP_ENGINEERING;
	sp->energy = sp->pods = 0;
	sp->regen = 0.0;
	tp->from = sp;
	if (sp->newwarp < -1.0)
		sp->newwarp = -0.99;
	if (sp->newwarp > 1.0)
		sp->newwarp = 0.99;
	sp->max_speed = 1.0;
	sp->status[S_ENG] = 100;	/* List as destroyed */
	sp->status[S_WARP] = 100;
	sp->cloaking = C_NONE;
	sp->t_blind_left = sp->t_blind_right = sp->p_blind_left =
	    sp->p_blind_right = 180;
	return 1;
}


/*
 * Returns 1 if a probe was launched
 */
int e_launchprobe(sp, fed)
struct ship *sp;
struct ship *fed;
{
	register int i;
	register struct list *lp;
	register struct torpedo *tp;

	if (!syswork(sp, S_PROBE) || sp->energy <= 10 || cantsee(sp))
		return 0;
	/*
	 * fed ship has to be going slow before we'll launch
	 * a probe at it.
	 */
	if (fabs(fed->warp) > 1.0)
		return 0;
	lp = newitem(I_PROBE);
	tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
	if (tp == (struct torpedo *)NULL) {
		fprintf(stderr, "e_launchprobe: malloc failed\n");
		exit(2);
	}
	tp->from = sp;
	tp->speed = sp->warp;
	tp->newspeed = 3.0;
	tp->target = fed;
	tp->course = bearing(sp->x, fed->x, sp->y, fed->y);
	tp->x = sp->x;
	tp->y = sp->y;
	tp->prox = 200 + randm(200);
	tp->timedelay = 15.;
	tp->id = new_slot();
	if ((i = randm(15) + 10) > sp->energy)
		i = sp->energy;
	tp->fuel = i;
	tp->type = TP_PROBE;
	sp->energy -= i;
	sp->pods -= i;
	printf("%s launching probe #%d\n", sp->name, tp->id);
	return 1;
}


/*
 * Returns the number of tubes that were loaded
 */
int e_loadtubes(sp)
struct ship *sp;
{
	register int i;
	register int j;
	register int loaded;
	register int below;

	below = 10;
	loaded = 0;
	for (i=0; inum_tubes; i++) {
		if (sp->energy <= below)
			break;
		if (sp->tubes[i].status & T_DAMAGED)
			continue;
		j = min(sp->energy, 10 - sp->tubes[i].load);
		if (j == 0)
			continue;
		sp->energy -= j;
		sp->pods -= j;
		sp->tubes[i].load += j;
		loaded++;
	}
#ifdef TRACE
	if (trace)
		printf("*** Load tubes: Loaded %d tubes\n", loaded);
#endif
	return loaded;
}


/*
 * Returns the number of phasers that were locked
 */
int e_lockphasers(sp, fed)
struct ship *sp;
struct ship *fed;
{
	register int i;
	register int banks;

	banks = 0;
	for (i=0; inum_phasers; i++) {
		if (sp->phasers[i].status & P_DAMAGED)
			continue;
		if (sp->phasers[i].target != NULL)
			continue;
		sp->phasers[i].target = fed;
		banks++;
	}
#ifdef TRACE
	if (trace)
		printf("*** Lock phasers: Locked %d phasers\n", banks);
#endif
	return banks;
}


/*
 * Returns number of tubes locked
 */
int e_locktubes(sp, fed)
struct ship *sp;
struct ship *fed;
{
	register int i;
	register int tubes;

	tubes = 0;
	for (i=0; inum_tubes; i++) {
		if (sp->tubes[i].status & T_DAMAGED)
			continue;
		if (sp->tubes[i].target != NULL)
			continue;
		sp->tubes[i].target = fed;
		tubes++;
	}
#ifdef TRACE
	if (trace)
		printf("*** Lock tubes: Locked %d tubes\n", tubes);
#endif
	return tubes;
}


/*
 * returns the number of banks we're going to fire
 * it also sets them up.
 */
int e_phasers(sp, fed)
struct ship *sp;
struct ship *fed;
{
	register int i;
	register int banks;
	register int hit;
	register int howmany;
	float bear;

	banks = 0;
	howmany = randm(sp->num_phasers / 2) + sp->num_phasers / 2;
	sp->p_spread = 10 + randm(12);
	for (i=0; inum_phasers; i++) {
		if ((sp->phasers[i].status & P_DAMAGED) ||
		    (sp->phasers[i].load == 0))
			continue;
		if (fed != NULL) {
			if (sp->phasers[i].target == NULL)
				continue;
			bear = bearing(sp->x, fed->x, sp->y, fed->y);
			hit = phaser_hit(sp, fed->x, fed->y, &sp->phasers[i], bear);
			if (hit <= 0)
				continue;
		}
		banks++;
		sp->phasers[i].status |= P_FIRING;
		if (banks >= howmany)
			break;
	}
	return banks;
}


/*
 * This routine will turn the ship, slowing down if necessary to facilitate
 * the turn.  (Always returns 1)
 */
int e_pursue(sp, fed, speed)
struct ship *sp;
struct ship *fed;
float speed;
{
	float	bear;
	float	coursediff;

	bear = bearing(sp->x, fed->x, sp->y, fed->y);
	/*
	 * do a quick turn if our speed is > max_warp - 2 and
	 * (thus) we are never going to bear on the fed ship
	 * speed = max_warp / 2 is a magic cookie.  Feel free to change.
	 */
	coursediff = rectify(sp->course - bear);
	if (coursediff > 180.0)
		coursediff -= 360.0;
	if (speed >= sp->max_speed - 2 && fabs(coursediff) > 10)
		speed = (int)(sp->max_speed / 2);
	sp->target = fed;
	sp->newcourse = bear;
	sp->newwarp = speed;
	if (speed > 1 && is_dead(sp, S_WARP))
		sp->newwarp = 0.99;
#ifdef TRACE
	if (trace) {
		printf("*** Pursue: Newcourse = %.2f\n", sp->newcourse);
		printf("*** Pursue: Newwarp = %.2f\n", sp->newwarp);
	}
#endif
	return 1;
}


/*
 * This routine has the enemy ship turn its strongest shield towards
 * the enemy and then accelerate to 2/3 maximum speed.  (Always returns 1)
 */
int e_runaway(sp, fed)
struct ship *sp;
struct ship *fed;
{
	register double bear;
	register int strong;
	register double strength;
	register double temp;
	register int sign;
	register float course;
	register int i;

	bear = bearing(sp->x, fed->x, sp->y, fed->y);
	/*
	 * Find the strongest shield
	 */
	strong = 0;
	strength = 0.;
	for (i=0; i< SHIELDS; i++) {
		temp = sp->shields[i].eff * sp->shields[i].drain *
		    (i == 0 ? SHIELD1 : 1.);
		if (temp > strength) {
			strong = i;
			strength = temp;
		}
	}
	switch (strong) {
		case 0:	course = bear;
			sign = -1;
			break;
		case 1:	course = rectify(bear - 90);
			sign = 1;
			break;
		case 2:	course = rectify(bear + 180);
			sign = 1;
			break;
		case 3:	course = rectify(bear + 90);
			sign = 1;
			break;
	}
	sp->target = NULL;
	sp->newcourse = course;
	sp->newwarp = 2 / 3 * sp->max_speed * sign;
	if (sp->newwarp > 1.0 && is_dead(sp, S_WARP))
		sp->newwarp = 0.99;
	if (cansee(sp) && syswork(fed, S_SENSOR))
		printf("%s: The %s is retreating.\n", helmsman, sp->name);
#ifdef TRACE
	if (trace) {
		printf("*** Runaway: Newcourse = %.2f\n", sp->newcourse);
		printf("*** Runaway: Newwarp = %.2f\n", sp->newwarp);
	}
#endif
	return 1;
}


/*
 * Returns the number of tubes we're going to fire
 * Also sets them up to fire
 */
int e_torpedo(sp)
struct ship *sp;
{
	register int i;
	register int tubes;
	register int howmany;
	register struct ship *sp1;
	register int range;

	/*
	 * don't shoot if someone might be in the way
	 * (i.e. proximity fuse will go off right as the
	 * torps leave the tubes!)
	 */
	for (i=1; i <= shipnum; i++) {
		sp1 = shiplist[i];
		/* This must check for dead ships too! */
		if (sp1 == sp)
			continue;
		range = rangefind(sp->x, sp1->x, sp->y, sp1->y);
		if (range <= 400)
			return 0;
	}
	tubes = 0;
	/* This is not and should not be dependent on the
	   number of tubes one has */
	howmany = randm(2) + 1;		
	for (i=0; inum_tubes; i++) {
		if ((sp->tubes[i].status & T_DAMAGED)
		    || (sp->tubes[i].load == 0))
			continue;
		if (sp->tubes[i].target == NULL)
			continue;
		tubes++;
		sp->tubes[i].status |= T_FIRING;
		if (tubes >= howmany)
			break;
	}
	return tubes;
}
SHAR_EOF
chmod +x 'enemycom.c'
fi # end of overwriting check
#	End of shell archive
exit 0