games-request@tekred.TEK.COM (12/18/87)
Submitted by: Jeff Okamoto <okamoto%hpccc@hplabs.HP.COM>
Comp.sources.games: Volume 3, Issue 23
Archive-name: trek73/Part02
#! /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 2 (of 6)."
# Contents: README2 src/cmds4.c src/enemycom.c src/globals.c
# src/moveships.c src/strat1.c
# Wrapped by billr@tekred on Thu Dec 17 11:43:32 1987
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f README2 -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"README2\"
else
echo shar: Extracting \"README2\" \(319 characters\)
sed "s/^X//" >README2 <<'END_OF_README2'
XThis is the 4.0 version of Trek73, by Jeff Okamoto and Peter Yee.
X
XThe only thing you should need to do is to look through the Makefile
Xin the src subdirectory and follow the instructions.
X
XIf you encounter any problems, please send us mail. Our current
Xmail addresses are:
X
X okamoto%hpccc@hplabs.hp.com yee@ames.arpa
END_OF_README2
if test 319 -ne `wc -c <README2`; then
echo shar: \"README2\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/cmds4.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"src/cmds4.c\"
else
echo shar: Extracting \"src/cmds4.c\" \(9704 characters\)
sed "s/^X//" >src/cmds4.c <<'END_OF_src/cmds4.c'
X#ident "@(#) TREK73 $Header: cmds4.c,v 1.3 87/10/13 16:00:59 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/cmds4.c,v $
X *
X * $Header: cmds4.c,v 1.3 87/10/13 16:00:59 okamoto Exp $
X *
X * $Log: cmds4.c,v $
X * Revision 1.3 87/10/13 16:00:59 16:00:59 okamoto (Jeff Okamoto)
X * Fixed calls to Gets
X *
X * Revision 1.2 87/10/09 14:01:55 14:01:55 okamoto (Jeff Okamoto)
X * Fix bug in self-destruct code.
X *
X * Revision 1.1 87/10/09 11:02:50 11:02:50 okamoto (Jeff Okamoto)
X * Initial revision
X *
X */
X/*
X * TREK73: cmds4.c
X *
X * User Commands
X *
X * alterpntparams, play_dead, corbomite_bluff, surrender_ship,
X * request_surrender, self_destruct, abort_self_destruct
X *
X */
X
X#include "externs.h"
X
X
Xint
Xalterpntparams(sp)
Xstruct ship *sp;
X{
X int temp;
X char buf1[30];
X
X printf("\n%s: Reset tubes, %s?\n",nav,title);
X printf("%s: [yes or no] ",captain);
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL)
X return 0;
X if ((buf1 != NULL) && (buf1[0] != 'n')) {
X printf(" Set launch speed to [0-%d] ", MAX_TUBE_SPEED);
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL)
X return 0;
X if (buf1 != NULL) {
X temp = atoi(buf1);
X if ((temp >= 0) && (temp < MAX_TUBE_SPEED + 1))
X sp->t_lspeed = temp;
X }
X printf(" Set time delay to [0-%d] ", (int) MAX_TUBE_TIME);
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL)
X return 0;
X if (buf1 != NULL) {
X temp = atoi(buf1);
X if ((temp >= 0) && (temp < (int)(MAX_TUBE_TIME + 1)))
X sp->t_delay = temp;
X }
X printf(" Set proximity delay to [0-%d] ", MAX_TUBE_PROX);
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL)
X return 0;
X if (buf1 != NULL) {
X temp = atoi(buf1);
X if ((temp >= 0) && (temp < MAX_TUBE_PROX + 1))
X sp->t_prox = temp;
X }
X }
X printf("%s: Reset phasers, %s?\n",nav ,title);
X printf("%s: [yes or no] ",captain);
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL)
X return 0;
X if (buf1[0] == 'y' || buf1[0] == 'Y') {
X printf(" Reset firing percentage to [0-100] ");
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL)
X return 0;
X temp = atoi(buf1);
X if ((temp >= 0) && (temp <= 100))
X sp->p_percent = temp;
X }
X return 0;
X}
X
Xint
Xplay_dead(sp)
Xstruct ship *sp;
X{
X
X char buf1[30];
X int phaser_charge;
X register int i;
X
X printf("%s: %s, drop shields ...\n", captain, nav);
X if (defenseless) {
X printf("%s: %s, the %ss are not that stupid.\n",
X science, title, foerace);
X return 0;
X }
X printf(" Transfer power to [engines or phasers]: ");
X (void) Gets(buf1, sizeof(buf1));
X if (buf1[0] == NULL) {
X printf("%s: I cannot transfer power there, %s.\n",
X nav, title);
X return 0;
X }
X phaser_charge = -MAX_PHASER_CHARGE;
X if (buf1[0] != 'e' && buf1[0] != 'E') {
X phaser_charge = MAX_PHASER_CHARGE;
X if (buf1[0] != 'p' && buf1[0] != 'P') {
X printf("%s: I cannot transfer power there, %s.\n",
X nav, title);
X return 0;
X }
X } else
X sp->energy = min(sp->energy + phaser_charge, sp->pods);
X for (i=0;i<SHIELDS;i++)
X sp->shields[i].attemp_drain = 0.0;
X for (i=0;i<sp->num_phasers;i++)
X sp->phasers[i].drain = phaser_charge;
X defenseless = 1;
X return 0;
X}
X
Xint
Xcorbomite_bluff(sp)
Xstruct ship *sp;
X{
X
X if (randm(2) == 1) {
X printf("%s: Open a hailing frequency, ship-to-ship.\n",
X captain);
X printf("%s: Hailing frequency open, %s.\n", com, title);
X printf("%s: This is the Captain of the %s. Our respect for\n",
X captain, sp->name);
X puts(" other life forms requires that we give you this warning--");
X puts(" one critical item of information which has never been");
X puts(" incorporated into the memory banks of any Earth ship.");
X puts(" Since the early years of space exploration, Earth vessels");
X puts(" have had incorporated into them a substance know as corbomite.");
X if (!corbomite) {
X puts(" It is a material and a device which prevents attack on");
X puts(" us. If any destructive energy touchs our vessel, a re-");
X puts(" verse reaction of equal strength is created, destroying");
X puts(" the attacker. It may interest you to know that, since");
X puts(" the initial use of corbomite for more than two of our");
X puts(" centuries ago, no attacking vessel has survived the attempt.");
X puts(" Death has little meaning to us. If it has none to you,");
X puts(" then attack us now. We grow annoyed with your foolishness.");
X }
X } else {
X printf("%s: Open a special channel to Starfleet Command.\n",
X captain);
X printf("%s: Aye, %s.\n", com, title);
X printf("%s: Use Code 2.\n", captain);
X printf("%s: but, %s, according to our last Starfleet\n",
X com, title);
X printf(" Bulletin, the %ss have broken code 2.\n", foerace);
X printf("%s: That's an order, Lieutenant. Code 2!\n",
X captain);
X printf("%s: Yes, Captain. Code 2.\n", com);
X printf("%s: Message from %s to Starfleet Command, this sector.\n",
X captain, sp->name);
X printf(" have inadvertantly encroached upon %s neutral zone,\n",
X foerace);
X printf(" surrounded and under heavy %s attack. Escape\n",
X foerace);
X puts(" impossible. Shields failing. Will implement destruct");
X puts(" order using corbomite device recently installed.");
X if (!corbomite) {
X printf(" This will result in the destruction of the %s and\n",
X sp->name);
X puts(" all matter within a 200 megameter diameter and");
X puts(" establish corresponding dead zone, all Federation");
X puts(" vessels will aviod this area for the next four solar");
X printf(" years. Explosion will take place in one minute. %s,\n",
X captain);
X printf(" commanding %s, out.\n",sp->name);
X }
X }
X if (!corbomite) {
X printf(" Mr. %s. Stand by.\n", helmsman);
X printf("%s: Standing by.\n", helmsman);
X corbomite = 1;
X } else {
X printf("\n%s: I don't believe that they will fall for that maneuver\n",
X science);
X printf(" again, %s.\n", title);
X }
X return 0;
X}
X
Xint
Xsurrender_ship(sp)
Xstruct ship *sp;
X{
X printf("%s: %s, open a channel to the %ss.\n", captain, com, foerace);
X printf("%s: Aye, %s.\n", com, title);
X printf("%s: This is Captain %s of the U.S.S. %s. Will\n",
X captain, captain, sp->name);
X puts(" you accept my unconditional surrender?");
X if (global & F_SURRENDER) {
X printf("%s: %s, we have already surrendered.\n",
X science, title);
X return 0;
X }
X if (surrender) {
X printf("%s: The %ss have already refused.\n",science, foerace);
X } else {
X if (foerace == "Romulan") {
X printf("%s: The %ss have not been know to have taken\n",
X science, foerace);
X puts(" prisoners.");
X }
X surrender = 1;
X }
X return 0;
X}
X
Xint
Xrequest_surrender(sp)
Xstruct ship *sp;
X{
X printf("%s: %s, open a hailing frequency to the %ss.\n",
X com, captain,foerace);
X printf("%s: Aye, %s.\n", com, title);
X printf("%s: This is Captain %s of the U. S. S. %s. I give you\n",
X captain, captain, sp->name);
X puts(" one last chance to surrender before we resume our attack.");
X if (global & E_SURRENDER) {
X printf("%s: %s, we are already complying with your previous request!\n",
X foename, captain);
X return 0;
X }
X if (surrenderp) {
X printf("%s: %s, our offer has already been refused.\n",
X science, title);
X } else {
X surrenderp = 1;
X }
X return 0;
X}
X
Xint
Xself_destruct(sp)
Xstruct ship *sp;
X{
X printf("%s: Lieutenant %s, tie in the bridge to the master\n",captain, com);
X printf(" computer.\n");
X if (is_dead(sp, S_COMP)) {
X printf("%s: Our computer is down.\n", science);
X return 0;
X }
X if (!syswork(sp, S_COMP)) {
X printf("%s: That program has been lost. Restoring from backup.",
X science);
X return 0;
X }
X printf("%s: Aye, %s.\n",com, title);
X printf("%s: Computer. Destruct sequence. Are you ready to copy?\n",captain);
X puts("Computer: Working.");
X printf("%s: Computer, this is Captain %s of the U.S.S. %s.\n",
X captain, captain, sp->name);
X puts(" Destruct sequence one, code 1-1A.");
X puts("Computer: Voice and code verified and correct.");
X puts(" Sequence one complete.");
X printf("%s: This is Commander %s, Science Officer. Destruct\n",
X science, science);
X puts(" sequence two, code 1-1A-2B.");
X puts("Computer: Voice and code verified and correct. Sequence");
X puts(" two complete.");
X printf("%s: This is Lieutenant Commander %s, Chief Engineering\n",
X engineer, engineer);
X printf(" Officer of the U. S. S. %s. Destruct sequence\n",sp->name);
X puts(" number three, code 1B-2B-3.");
X puts("Computer: Voice and code verified and correct.");
X puts(" Destruct sequence complete and engaged. Awaiting final");
X puts(" code for twenty second countdown.");
X printf("%s: Computer, this is Captain %s of the U. S. S. %s.\n",
X captain, captain, sp->name);
X puts(" begin countdown, code 0-0-0, destruct 0.");
X sp->delay = 22.;
X return 0;
X}
X
Xint
Xabort_self_destruct(sp)
Xstruct ship *sp;
X{
X printf("%s: Computer, this is Captain %s of the U.S.S. %s.\n",
X captain, captain, sp->name);
X puts(" Code 1-2-3 continuity abort destruct order, repeat:");
X puts(" Code 1-2-3 continuity abort destruct order!");
X if (is_dead(sp, S_COMP)) {
X printf("%s: Our computer is down.\n", science);
X return 0;
X }
X if (!syswork(sp, S_COMP)) {
X printf("%s: Temporary memory loss. Unable to find program.\n",
X science);
X return 0;
X }
X if (sp->delay > 1000.) {
X puts("Computer: Self-destruct sequence has not been");
X puts(" initiated.");
X return 0;
X }
X printf("Computer: Self-destruct order ... ");
X (void) fflush(stdout);
X sleep(4);
X if (sp->delay > 4.) {
X puts("aborted. Destruct order aborted.");
X sp->delay = 10000.;
X return 0;
X } else {
X puts("cannot be aborted.");
X return 0;
X }
X}
END_OF_src/cmds4.c
if test 9704 -ne `wc -c <src/cmds4.c`; then
echo shar: \"src/cmds4.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/enemycom.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"src/enemycom.c\"
else
echo shar: Extracting \"src/enemycom.c\" \(13518 characters\)
sed "s/^X//" >src/enemycom.c <<'END_OF_src/enemycom.c'
X#ident "@(#) TREK73 $Header: enemycom.c,v 1.1 87/10/09 11:05:38 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/enemycom.c,v $
X *
X * $Header: enemycom.c,v 1.1 87/10/09 11:05:38 okamoto Exp $
X *
X * $Log: enemycom.c,v $
X * Revision 1.1 87/10/09 11:05:38 11:05:38 okamoto (Jeff Okamoto)
X * Initial revision
X *
X */
X/*
X * TREK73: enemycom.c
X *
X * Enemy strategy sub-routines
X *
X * e_attack, e_checkarms, e_checkprobe, e_cloak_off, e_cloak_on,
X * e_closetorps, e_destruct, e_evade, e_jettison, e_launchprobe,
X * e_loadtubes, e_lockphasers, e_locktubes, e_phasers, e_pursue,
X * e_runaway, e_torpedo
X *
X */
X
X#include "externs.h"
X
X
X/*
X * This routine turns the ship at speed towards its target
X */
Xint
Xe_attack(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X float speed;
X float tmpf;
X
X tmpf = fabs(fed->warp);
X if (fabs(sp->warp) >= tmpf + 2.0 || (is_dead(sp, S_WARP)))
X return 0;
X if ((speed = tmpf + randm(2) + 2.0) > sp->max_speed)
X speed = sp->max_speed;
X (void) e_pursue(sp, fed, speed);
X if (cansee(sp) && syswork(fed, S_SENSOR))
X printf("%s: %s attacking.\n", helmsman, sp->name);
X return 1;
X}
X
X
X/*
X * Returns the number of currently loaded, undamaged weapons
X */
Xint
Xe_checkarms(sp)
Xstruct ship *sp;
X{
X register int i;
X register int arms;
X
X arms = 0;
X for (i=0; i<sp->num_phasers; i++)
X if (!(sp->phasers[i].status & P_DAMAGED) &&
X (sp->phasers[i].load >= 0))
X arms++;
X for (i=0; i<sp->num_tubes; i++)
X if (!(sp->tubes[i].status & T_DAMAGED) &&
X (sp->tubes[i].load >= 0))
X arms++;
X#ifdef TRACE
X if (trace)
X printf("*** Checkarms: Returning %d\n", arms);
X#endif
X return arms;
X}
X
X
X/*
X * returns 1 if evasive action being taken (to avoid probe)
X */
Xint
Xe_checkprobe(sp)
Xstruct ship *sp;
X{
X register struct list *lp;
X register int range;
X register struct torpedo *tp;
X
X /*
X * If we are cloaked, do not bother with this.
X * Since probes cannot detect us when cloaked.
X */
X if (cantsee(sp))
X return 0;
X for (lp = &head; lp != tail; lp = lp->fwd) {
X if (lp->type != I_PROBE)
X continue;
X tp = lp->data.tp;
X range = rangefind(sp->x, tp->x, sp->y, tp->y);
X#ifdef TRACE
X if (trace)
X printf("*** Checkprobe: Range = %d\n", range);
X#endif
X if (range < 2000) {
X (void) e_evade(sp, tp->x, tp->y, I_PROBE);
X return 1;
X }
X }
X return 0;
X}
X
X
X/*
X * Returns 1 if cloaking device was turned off
X */
Xint
Xe_cloak_off(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X if (sp->cloaking != C_ON)
X return 0;
X sp->cloaking = C_OFF;
X sp->cloak_delay = 4;
X if (syswork(sp, S_SENSOR)) {
X printf("%s: The %s has reappeared on our sensors %d\n",
X science, sp->name, rangefind(sp->x, sp->position.x,
X sp->y, sp->position.y));
X puts(" megameters from its projected position.");
X }
X fed = fed; /* LINT */
X return 1;
X}
X
X
X/*
X * Returns 1 if cloaking device was turned on
X */
Xint
Xe_cloak_on(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X if ((sp->cloak_delay > 0) || (sp->cloaking != C_OFF))
X return 0;
X sp->cloaking = C_ON;
X sp->position.x = sp->x;
X sp->position.y = sp->y;
X sp->position.warp = sp->warp;
X sp->position.course = sp->course;
X if (syswork(fed, S_SENSOR))
X printf("%s: The %s has disappeared from our sensors.\n",
X science, sp->name);
X fed = fed; /* LINT */
X return 1;
X}
X
X
X/*
X * Returns 1 if firing phasers at or evading nearby torpedoes
X */
Xint
Xe_closetorps(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X register struct list *lp;
X register int range;
X register struct torpedo *tp;
X struct torpedo *bad;
X
X /*
X * If we are cloaked, forget about this.
X * Since prox fuses won't affect us under cloak
X */
X if (cantsee(sp))
X return 0;
X bad = NULL;
X for (lp = &head; lp != tail; lp = lp->fwd) {
X if (lp->type != I_TORPEDO)
X continue;
X tp = lp->data.tp;
X if (tp->from != fed)
X continue;
X range = rangefind(sp->x, tp->x, sp->y, tp->y);
X#ifdef TRACE
X if (trace)
X printf("*** Checktorp: Range = %d\n", range);
X#endif
X if (range < 1200) {
X bad = tp;
X /*
X * fire phasers - hope they're pointing in
X * the right direction!
X */
X if (e_phasers(sp, (struct ship *) NULL))
X return 1;
X }
X }
X /*
X * we can't get a phaser shot off.
X * try and evade (although hopeless)
X */
X if (bad != NULL) {
X#ifdef TRACE
X if (trace)
X printf("*** Checktorp: Cannot fire phasers! Evade!\n");
X#endif
X (void) e_evade(sp, tp->x, tp->y, I_TORPEDO);
X return 1;
X }
X return 0;
X}
X
X
X/*
X * goodbye, cruel world (Returns 1 if self-destruct was initiated)
X */
Xint
Xe_destruct(sp, fed)
Xstruct ship *sp, *fed;
X{
X if (sp->delay < 5.0)
X return 0;
X sp->delay = 5.0;
X (void) e_cloak_off(sp, fed);
X sp->cloaking = C_NONE;
X if (syswork(fed, S_SENSOR)) {
X printf("%s: The %s is overloading what remains of it's\n",
X science, sp->name);
X puts(" antimatter pods -- obviously a suicidal gesture.");
X puts(" Estimate detonation in five seconds.");
X }
X return 1;
X}
X
X
X/*
X * Advance to the rear! (Always returns 1)
X */
Xint
Xe_evade(sp, x, y, type)
Xstruct ship *sp;
Xint x;
Xint y;
Xint type; /* Currently unused */
X{
X register float newcourse;
X float bear;
X
X bear = bearing(sp->x, x, sp->y, y);
X if (cansee(sp) && syswork(shiplist[0], S_SENSOR))
X printf("%s taking evasive action!\n", sp->name);
X switch (randm(3)) {
X case 1:
X newcourse = rectify(bear - 90.0);
X break;
X case 2:
X newcourse = rectify(bear + 90.0);
X break;
X case 3:
X newcourse = rectify(bear + 180.0);
X break;
X default:
X printf("error in evade()\n");
X break;
X }
X sp->target = NULL;
X sp->newcourse = newcourse;
X sp->newwarp = 2 + randm((int)(sp->max_speed - 3));
X if (is_dead(sp, S_WARP))
X sp->newwarp = 1.0;
X#ifdef TRACE
X if (trace) {
X printf("*** Evade: Newcourse = %3.0f\n", newcourse);
X printf("*** Evade: Newwarp = %.2f\n", sp->newwarp);
X }
X#endif
X type = type; /* LINT */
X return 1;
X}
X
X
X/*
X * Returns 1 if engineering was jettisoned
X */
Xint
Xe_jettison(sp, fed)
Xstruct ship *sp, *fed;
X{
X register struct list *lp;
X register struct torpedo *tp;
X
X if (is_dead(sp, S_ENG))
X return 0;
X (void) e_cloak_off(sp, fed);
X if (syswork(shiplist[0], S_SENSOR)) {
X printf("%s: Sensors indicate debris being left by\n", science);
X printf(" the %s. Insufficient mass . . .\n", sp->name);
X }
X lp = newitem(I_ENG);
X tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
X if (tp == (struct torpedo *)NULL) {
X fprintf(stderr, "e_jettison: malloc failed\n");
X exit(2);
X }
X tp->id = new_slot();
X /*
X * ship slows to warp 1.0 when jettisonning engineering
X */
X tp->newspeed = 0.0;
X tp->speed = sp->warp;
X tp->target = NULL;
X tp->course = sp->course;
X tp->x = sp->x;
X tp->y = sp->y;
X tp->prox = 0;
X tp->timedelay = 10.;
X tp->fuel = sp->energy;
X tp->type = TP_ENGINEERING;
X sp->energy = sp->pods = 0;
X sp->regen = 0.0;
X tp->from = sp;
X if (sp->newwarp < -1.0)
X sp->newwarp = -0.99;
X if (sp->newwarp > 1.0)
X sp->newwarp = 0.99;
X sp->max_speed = 1.0;
X sp->status[S_ENG] = 100; /* List as destroyed */
X sp->status[S_WARP] = 100;
X sp->cloaking = C_NONE;
X sp->t_blind_left = sp->t_blind_right = sp->p_blind_left =
X sp->p_blind_right = 180;
X return 1;
X}
X
X
X/*
X * Returns 1 if a probe was launched
X */
Xint
Xe_launchprobe(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X register int i;
X register struct list *lp;
X register struct torpedo *tp;
X
X if (!syswork(sp, S_PROBE) || sp->energy <= 10 || cantsee(sp))
X return 0;
X /*
X * fed ship has to be going slow before we'll launch
X * a probe at it.
X */
X if (fabs(fed->warp) > 1.0)
X return 0;
X lp = newitem(I_PROBE);
X tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
X if (tp == (struct torpedo *)NULL) {
X fprintf(stderr, "e_launchprobe: malloc failed\n");
X exit(2);
X }
X tp->from = sp;
X tp->speed = sp->warp;
X tp->newspeed = 3.0;
X tp->target = fed;
X tp->course = bearing(sp->x, fed->x, sp->y, fed->y);
X tp->x = sp->x;
X tp->y = sp->y;
X tp->prox = 200 + randm(200);
X tp->timedelay = 15.;
X tp->id = new_slot();
X if ((i = randm(15) + 10) > sp->energy)
X i = sp->energy;
X tp->fuel = i;
X tp->type = TP_PROBE;
X sp->energy -= i;
X sp->pods -= i;
X printf("%s launching probe #%d\n", sp->name, tp->id);
X return 1;
X}
X
X
X/*
X * Returns the number of tubes that were loaded
X */
Xint
Xe_loadtubes(sp)
Xstruct ship *sp;
X{
X register int i;
X register int j;
X register int loaded;
X register int below;
X
X below = 10;
X loaded = 0;
X for (i=0; i<sp->num_tubes; i++) {
X if (sp->energy <= below)
X break;
X if (sp->tubes[i].status & T_DAMAGED)
X continue;
X j = min(sp->energy, 10 - sp->tubes[i].load);
X if (j == 0)
X continue;
X sp->energy -= j;
X sp->pods -= j;
X sp->tubes[i].load += j;
X loaded++;
X }
X#ifdef TRACE
X if (trace)
X printf("*** Load tubes: Loaded %d tubes\n", loaded);
X#endif
X return loaded;
X}
X
X
X/*
X * Returns the number of phasers that were locked
X */
Xint
Xe_lockphasers(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X register int i;
X register int banks;
X
X banks = 0;
X for (i=0; i<sp->num_phasers; i++) {
X if (sp->phasers[i].status & P_DAMAGED)
X continue;
X if (sp->phasers[i].target != NULL)
X continue;
X sp->phasers[i].target = fed;
X banks++;
X }
X#ifdef TRACE
X if (trace)
X printf("*** Lock phasers: Locked %d phasers\n", banks);
X#endif
X return banks;
X}
X
X
X/*
X * Returns number of tubes locked
X */
Xint
Xe_locktubes(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X register int i;
X register int tubes;
X
X tubes = 0;
X for (i=0; i<sp->num_tubes; i++) {
X if (sp->tubes[i].status & T_DAMAGED)
X continue;
X if (sp->tubes[i].target != NULL)
X continue;
X sp->tubes[i].target = fed;
X tubes++;
X }
X#ifdef TRACE
X if (trace)
X printf("*** Lock tubes: Locked %d tubes\n", tubes);
X#endif
X return tubes;
X}
X
X
X/*
X * returns the number of banks we're going to fire
X * it also sets them up to fire.
X */
Xint
Xe_phasers(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X register int i;
X register int banks;
X register int hit;
X register int howmany;
X float bear;
X
X banks = 0;
X howmany = randm(sp->num_phasers / 2) + sp->num_phasers / 2;
X sp->p_spread = 10 + randm(12);
X for (i=0; i<sp->num_phasers; i++) {
X if ((sp->phasers[i].status & P_DAMAGED) ||
X (sp->phasers[i].load == 0))
X continue;
X if (fed != NULL) {
X if (sp->phasers[i].target == NULL)
X continue;
X bear = bearing(sp->x, fed->x, sp->y, fed->y);
X hit = phaser_hit(sp, fed->x, fed->y, &sp->phasers[i], bear);
X if (hit <= 0)
X continue;
X }
X banks++;
X sp->phasers[i].status |= P_FIRING;
X if (banks >= howmany)
X break;
X }
X return banks;
X}
X
X
X/*
X * This routine will turn the ship, slowing down if necessary to
X * facilitate the turn. (Always returns 1)
X */
Xint
Xe_pursue(sp, fed, speed)
Xstruct ship *sp;
Xstruct ship *fed;
Xfloat speed;
X{
X float bear;
X float coursediff;
X
X bear = bearing(sp->x, fed->x, sp->y, fed->y);
X /*
X * do a quick turn if our speed is > max_warp - 2 and
X * (thus) we are never going to bear on the fed ship
X * speed = max_warp / 2 is a magic cookie. Feel free to change.
X */
X coursediff = rectify(sp->course - bear);
X if (coursediff > 180.0)
X coursediff -= 360.0;
X if (speed >= sp->max_speed - 2 && fabs(coursediff) > 10)
X speed = (int)(sp->max_speed / 2);
X sp->target = fed;
X sp->newcourse = bear;
X sp->newwarp = speed;
X if (speed > 1 && is_dead(sp, S_WARP))
X sp->newwarp = 0.99;
X#ifdef TRACE
X if (trace) {
X printf("*** Pursue: Newcourse = %.2f\n", sp->newcourse);
X printf("*** Pursue: Newwarp = %.2f\n", sp->newwarp);
X }
X#endif
X return 1;
X}
X
X
X/*
X * This routine has the enemy ship turn its strongest shield towards
X * the enemy and then accelerate to 2/3 maximum speed. (Always
X * returns 1)
X */
Xint
Xe_runaway(sp, fed)
Xstruct ship *sp;
Xstruct ship *fed;
X{
X register double bear;
X register int strong;
X register double strength;
X register double temp;
X register int sign;
X register float course;
X register int i;
X
X bear = bearing(sp->x, fed->x, sp->y, fed->y);
X /*
X * Find the strongest shield
X */
X strong = 0;
X strength = 0.;
X for (i=0; i< SHIELDS; i++) {
X temp = sp->shields[i].eff * sp->shields[i].drain *
X (i == 0 ? SHIELD1 : 1.);
X if (temp > strength) {
X strong = i;
X strength = temp;
X }
X }
X switch (strong) {
X case 0: course = bear;
X sign = -1;
X break;
X case 1: course = rectify(bear - 90);
X sign = 1;
X break;
X case 2: course = rectify(bear + 180);
X sign = 1;
X break;
X case 3: course = rectify(bear + 90);
X sign = 1;
X break;
X }
X sp->target = NULL;
X sp->newcourse = course;
X sp->newwarp = 2 / 3 * sp->max_speed * sign;
X if (sp->newwarp > 1.0 && is_dead(sp, S_WARP))
X sp->newwarp = 0.99;
X if (cansee(sp) && syswork(fed, S_SENSOR))
X printf("%s: The %s is retreating.\n", helmsman, sp->name);
X#ifdef TRACE
X if (trace) {
X printf("*** Runaway: Newcourse = %.2f\n", sp->newcourse);
X printf("*** Runaway: Newwarp = %.2f\n", sp->newwarp);
X }
X#endif
X return 1;
X}
X
X
X/*
X * Returns the number of tubes we're going to fire
X * Also sets them up to fire
X */
Xint
Xe_torpedo(sp)
Xstruct ship *sp;
X{
X register int i;
X register int tubes;
X register int howmany;
X register struct ship *sp1;
X register int range;
X
X /*
X * don't shoot if someone might be in the way
X * (i.e. proximity fuse will go off right as the
X * torps leave the tubes!)
X */
X for (i=1; i <= shipnum; i++) {
X sp1 = shiplist[i];
X /* This must check for dead ships too! */
X if (sp1 == sp)
X continue;
X range = rangefind(sp->x, sp1->x, sp->y, sp1->y);
X if (range <= 400)
X return 0;
X }
X tubes = 0;
X /* This is not and should not be dependent on the
X number of tubes one has */
X howmany = randm(2) + 1;
X for (i=0; i<sp->num_tubes; i++) {
X if ((sp->tubes[i].status & T_DAMAGED)
X || (sp->tubes[i].load == 0))
X continue;
X if (sp->tubes[i].target == NULL)
X continue;
X tubes++;
X sp->tubes[i].status |= T_FIRING;
X if (tubes >= howmany)
X break;
X }
X return tubes;
X}
END_OF_src/enemycom.c
if test 13518 -ne `wc -c <src/enemycom.c`; then
echo shar: \"src/enemycom.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/globals.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"src/globals.c\"
else
echo shar: Extracting \"src/globals.c\" \(10917 characters\)
sed "s/^X//" >src/globals.c <<'END_OF_src/globals.c'
X#ident "@(#) TREK73 $Header: globals.c,v 1.1 87/10/09 11:07:25 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/globals.c,v $
X *
X * $Header: globals.c,v 1.1 87/10/09 11:07:25 okamoto Exp $
X *
X * $Log: globals.c,v $
X * Revision 1.1 87/10/09 11:07:25 11:07:25 okamoto (Jeff Okamoto)
X * Initial revision
X *
X */
X/*
X *
X * TREK73: globals.c
X *
X * Global variable declarations
X *
X */
X
X#include "externs.h"
X
Xextern int fire_phasers(), fire_tubes(), lock_phasers(), lock_tubes(),
X turn_phasers(), turn_tubes(), load_tubes(), phaser_status(),
X tube_status(), launch_probe(), probe_control(), pos_report(),
X pos_display(), pursue(), elude(), helm(), self_scan(), scan(),
X alter_power(), jettison_engineering(), detonate_engineering(),
X alterpntparams(), play_dead(), corbomite_bluff(), surrender_ship(),
X request_surrender(), self_destruct(), abort_self_destruct(),
X save_game(), survivors(), help(), vers();
X
Xextern int standard_strategy();
X
Xchar encstr[] = "\211g\321_-\251b\324\237;\255\263\214g\"\327\224.,\252|9\265=\357+\343;\311]\341`\251\b\231)\266Y\325\251";
X
Xchar version[] = "TREK73 Version 4.0 04/15/87";
X
Xchar *sysname[] = {
X "Computer", /* S_COMP */
X "Sensors", /* S_SENSOR */
X "Probe launcher", /* S_PROBE */
X "Warp Drive", /* S_WARP */
X};
X
Xchar *statmsg[] = { /* When this system is dead */
X "computer inoperable", /* S_COMP */
X "sensors annihilated", /* S_SENSOR */
X "probe launcher shot off", /* S_PROBE */
X "warp drive disabled", /* S_WARP */
X "engineering jettisoned", /* S_ENG */
X} ;
X
Xstruct damage p_damage = {
X 50, 2, 20, 10, 3, /* eff, fuel, regen, crew, weapon */
X 1000, "Computer destroyed.", /* S_COMP */
X 500, "Sensors demolished.", /* S_SENSOR */
X 100, "Probe launcher crushed.", /* S_PROBE */
X 50, "Warp drive destroyed.", /* S_WARP */
X} ;
X
Xstruct damage a_damage = {
X 100, 3, 10, 7, 6, /* eff, fuel, regen, crew, weapon */
X 1500, "Computer banks pierced.", /* S_COMP */
X 750, "Sensors smashed.", /* S_SENSOR */
X 150, "Probe launcher shot off.", /* S_PROBE */
X 75, "Warp drive disabled.", /* S_WARP */
X} ;
X
X
Xchar *feds[] = {
X "Constitution", "Enterprise", "Hornet", "Lexington", "Potempkin",
X "Hood", "Kongo", "Republic", "Yorktown",
X} ;
X
Xstruct race_info aliens[MAXFOERACES] = {
X {
X "Klingon", "Empire", 0, 25, 25, 75, 75, 0,
X { "Annihilation", "Crusher", "Devastator", "Merciless",
X "Nemesis", "Pitiliess", "Ruthless", "Savage", "Vengeance",
X },
X { "C-9 Dreadnought", "D-7 Battle Cruiser",
X "D-6 Light Battlecruiser", "F-5L Destroyer",
X },
X { "Koloth", "Kang", "Kor", "Krulix", "Korax", "Karg",
X "Kron", "Kumerian",
X },
X },
X {
X "Romulan", "Star Empire", 0, 5, 5, 80, 50, 0,
X { "Avenger", "Defiance", "Fearless", "Harrower", "Intrepid",
X "Relentless", "Seeker", "Torch", "Vigilant",
X },
X { "Condor Dreadnought", "Firehawk Heavy Cruiser",
X "Sparrowhawk Light Cruiser", "Skyhawk Destroyer",
X },
X { "Tal", "Tiercellus", "Diana", "Tama", "Subeus", "Turm",
X "Strell", "Scipio",
X },
X },
X {
X "Kzinti", "Hegemony", 0, 50, 50, 50, 50, 0,
X { "Black Hole", "Comet", "Ecliptic", "Galaxy", "Meteor",
X "Nova", "Pulsar", "Quasar", "Satellite",
X },
X { "Space Control Ship", "Strike Cruiser", "Light Cruiser",
X "Destroyer",
X },
X { "Hunter", "\"Cat Who Sleeps With Dogs\"", "Fellus", "Corda",
X "\"Cat Who Fought Fuzzy Bear\"", "", "", "",
X },
X },
X {
X "Gorn", "Confederation", 0, 80, 50, 50, 50, 0,
X { "Chimericon", "Dragonicon", "Ornithocon", "Predatoricon",
X "Reptilicon", "Serpenticon", "Tyranicon", "Vipericon",
X "Wyvericon",
X },
X { "Tyrannosaurus Rex Dreadnought", "Allosaurus Heavy Cruiser",
X "Megalosaurus Light Cruiser", "Carnosaurus Destroyer",
X },
X { "Sslith", "Dardiss", "Ssor", "Sslitz", "S'Arnath",
X "Zor", "", "",
X },
X },
X {
X "Orion", "Pirates", 0, 95, 5, 50, 60, 0,
X { "Deuce Coupe", "Final Jeopardy", "Long John Dilithium",
X "Millennium Pelican", "Omega Race", "Penzance",
X "Road Warrior", "Scarlet Pimpernel", "Thunderduck",
X },
X { "Battle Raider", "Heavy Cruiser", "Raider Cruiser",
X "Light Raider",
X },
X { "Daniel \"Deth\" O'Kay", "Neil Ricca", "Delilah Smith",
X "Hamilcar", "Pharoah", "Felna Greymane", "Hacker",
X "Credenza",
X },
X },
X {
X "Hydran", "Monarchy", 0, 50, 50, 50, 50, 0,
X { "Bravery", "Chivalry", "Devotion", "Fortitude", "Loyalty",
X "Modesty", "Purity", "Resolution", "Tenacity",
X },
X { "Paladin Dreadnought", "Ranger-class Cruiser",
X "Horseman Light Cruiser", "Lancer Destroyer",
X },
X { "Hypantspts", "S'Lenthna", "Hydraxan", "", "", "",
X "", "",
X },
X },
X {
X "Lyran", "Empire", 0, 50, 50, 50, 50, 0,
X { "Bandit", "Claw", "Dangerous", "Fury", "Mysterious",
X "Sleek", "Tiger", "Vicious", "Wildcat",
X },
X { "Lion Dreadnought", "Tiger Cruiser",
X "Panther Light Cruiser", "Leopard Destroyer",
X },
X { "Kleave", "Leyraf", "Kuhla", "Nashar",
X "Prekor", "Ffarric", "Rippke", "Larkahn",
X },
X },
X {
X "Tholian", "Holdfast", 0, 75, 25, 50, 50, 0,
X { "Bismark", "Centaur", "Draddock", "Forbin", "Kreiger",
X "Shlurg", "Trakka", "Varnor", "Warrior",
X },
X { "Tarantula Dreadnought", "Cruiser", "Improved Patrol Cruiser",
X "Patrol Cruiser",
X },
X { "Secthane", "Kotheme", "Sectin", "Brezgonne",
X "Loskene", "", "", "",
X },
X },
X {
X "Monty Python", "Flying Circus", 0, -1, -1, -1, -1, 0,
X { "Blancmange", "Spam", "R.J. Gumby", "Lumberjack",
X "Dennis Moore", "Ministry of Silly Walks", "Argument Clinic",
X "Piranha Brothers", "Upper Class Twit of the Year",
X },
X { "Thingee", "Thingee", "Thingee", "Thingee",
X },
X { "Cleese", "Chapman", "Idle", "Jones", "Gilliam", "Bruce",
X "Throatwobblermangrove", "Arthur \"Two Sheds\" Jackson",
X },
X }
X};
X
X
Xfloat init_p_turn[MAXPHASERS][MAXPHASERS] = {
X { 666.666 },
X { 0.0 },
X { 0.0, 0.0 },
X { 90.0, 0.0, 270.0 },
X { 90.0, 0.0, 0.0, 270.0 },
X { 90.0, 0.0, 0.0, 0.0, 270.0 },
X { 90.0, 90.0, 0.0, 0.0, 270.0, 270.0 },
X { 90.0, 90.0, 0.0, 0.0, 0.0, 270.0, 270.0 },
X { 90.0, 90.0, 0.0, 0.0, 0.0, 0.0, 270.0, 270.0 },
X { 90.0, 90.0, 90.0, 0.0, 0.0, 0.0, 270.0, 270.0, 270.0 },
X { 90.0, 90.0, 90.0, 0.0, 0.0, 0.0, 0.0, 270.0, 270.0, 270.0 },
X};
X
Xfloat init_t_turn[MAXTUBES][MAXTUBES] = {
X { 666.666 },
X { 0.0 },
X { 0.0, 0.0 },
X { 60.0, 0.0, 300.0 },
X { 60.0, 0.0, 0.0, 300.0 },
X { 60.0, 0.0, 0.0, 0.0, 300.0 },
X { 120.0, 60.0, 0.0, 0.0, 300.0, 240.0 },
X { 120.0, 60.0, 0.0, 0.0, 0.0, 300.0, 240.0 },
X { 120.0, 60.0, 60.0, 0.0, 0.0, 300.0, 300.0, 240.0 },
X { 120.0, 60.0, 60.0, 0.0, 0.0, 0.0, 300.0, 300.0, 240.0 },
X { 120.0, 120.0, 60.0, 60.0, 0.0, 0.0, 300.0,300.0, 240.0, 240.0 },
X};
X
X/*
X * for the linked list of items in space
X */
Xstruct list head;
Xstruct list *tail;
X
X/*
X * Global definitions
X */
Xfloat segment = 0.05; /* Segment time */
Xfloat timeperturn = 2.0; /* Seconds per turn */
X
Xstruct ship *shiplist[10]; /* All the ships in the battle */
X
Xchar home[256]; /* Path to user's home directory */
Xchar savefile[256]; /* Path to save file */
Xchar captain[30]; /* captain's name */
Xchar science[30]; /* science officer's name */
Xchar engineer[30]; /* engineer's name */
Xchar com[30]; /* communications officer's name */
Xchar nav[30]; /* navigation officer's name */
Xchar helmsman[30]; /* helmsman's name */
Xchar title[9]; /* captain's title */
Xchar foerace[30]; /* enemy's race */
Xchar foename[30]; /* enemy's captain's name */
Xchar foestype[30]; /* enemy's ship type */
Xchar empire[30]; /* What the enemy's empire is called */
Xchar class[3]; /* Class of own ship */
Xchar foeclass[3]; /* Class of enemy ship(s) */
Xint shipnum; /* number of ships this time out */
Xint enemynum; /* Enemy identifier */
Xint terse = 0; /* print out initial description? */
Xint silly = 0; /* Use the Monty Python's Flying Curcus? */
Xint defenseless = 0; /* defensless ruse status */
Xint corbomite = 0; /* corbomite bluff status */
Xint surrender = 0; /* surrender offered by federation? */
Xint surrenderp = 0; /* Did we request that the enemy surrenders? */
Xint restart = 0; /* Should we restart the game? */
Xchar shutup[HIGHSHUTUP]; /* Turn off messages after first printing */
Xchar slots[HIGHSLOT]; /* Id slots */
Xint global = NORMAL; /* Situation status */
Xchar *options; /* Environment variable */
Xchar sex[20]; /* From environment */
Xchar shipname[30]; /* From environment */
Xchar racename[20]; /* From environment */
Xint reengaged = 0; /* Re-engaging far-off ships? */
Xchar com_delay[6]; /* Number of seconds per real-time turn */
Xint teletype = 0; /* Flag for special teletype options */
Xint time_delay = 30; /* Time to enter command */
Xint trace = TR_OFF; /* Trace flag for debugging and records */
Xchar can_cloak = 0; /* Can enemy ship cloak? */
Xdouble e_bpv; /* BPV of enemy */
X
X#ifdef PARSER
Xchar Input[BUFSIZ]; /* Input from user */
Xchar *Inptr; /* Pointer into Input */
Xchar parsed[BUFSIZ]; /* Returned command from yylex */
X#endif PARSER
X
Xstruct ship_stat us; /* Our ship definition */
Xstruct ship_stat them; /* Their ship definition */
X
Xstruct cmd cmds[] = {
X { fire_phasers, "1", "Fire phasers", TURN },
X { fire_tubes, "2", "Fire photon torpedoes", TURN },
X { lock_phasers, "3", "Lock phasers onto target", TURN },
X { lock_tubes, "4", "Lock tubes onto target", TURN },
X { turn_phasers, "5", "Manually rotate phasers", TURN },
X { turn_tubes, "6", "Manually rotate tubes", TURN },
X { phaser_status, "7", "Phaser status", FREE },
X { tube_status, "8", "Tube status", FREE },
X { load_tubes, "9", "Load/unload torpedo tubes", TURN },
X { launch_probe, "10", "Launch antimatter probe", TURN },
X { probe_control, "11", "Probe control", TURN },
X { pos_report, "12", "Position report", FREE },
X { pos_display, "13", "Position display", FREE },
X { pursue, "14", "Pursue an enemy vessel", TURN },
X { elude, "15", "Elude an enemy vessel", TURN },
X { helm, "16", "Change course and speed", TURN },
X { self_scan, "17", "Damage report", FREE },
X { scan, "18", "Scan enemy", TURN },
X { alter_power, "19", "Alter power distribution", TURN },
X { jettison_engineering, "20", "Jettison engineering", TURN },
X { detonate_engineering, "21", "Detonate engineering", TURN },
X { alterpntparams, "22", "Alter firing parameters", TURN},
X { play_dead, "23", "Attempt defenseless ruse", TURN },
X { corbomite_bluff, "24", "Attempt corbomite bluff(s)", TURN },
X { surrender_ship, "25", "Surrender", TURN },
X { request_surrender, "26", "Ask enemy to surrender", TURN },
X { self_destruct, "27", "Initiate self-destruct", TURN },
X { abort_self_destruct, "28", "Abort self-destruct", TURN },
X { survivors, "29", "Survivors report", FREE },
X { vers, "30", "Print version number", FREE },
X { save_game, "31", "Saves game", FREE },
X { help, "32", "Reprints above list", FREE },
X { NULL, NULL, NULL, TURN },
X} ;
X
Xint high_command = 32; /* Highest command in table */
X
X /* used to print cmd list */
Xint cmdarraysize = sizeof(cmds) / sizeof (struct cmd) -1;
X
X/* Strategy table */
Xint (*strategies[])() = {
X standard_strategy,
X};
END_OF_src/globals.c
if test 10917 -ne `wc -c <src/globals.c`; then
echo shar: \"src/globals.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/moveships.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"src/moveships.c\"
else
echo shar: Extracting \"src/moveships.c\" \(11725 characters\)
sed "s/^X//" >src/moveships.c <<'END_OF_src/moveships.c'
X#ident "@(#) TREK73 $Header: moveships.c,v 1.2 87/10/09 14:02:09 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/moveships.c,v $
X *
X * $Header: moveships.c,v 1.2 87/10/09 14:02:09 okamoto Exp $
X *
X * $Log: moveships.c,v $
X * Revision 1.2 87/10/09 14:02:09 14:02:09 okamoto (Jeff Okamoto)
X * Fix bug in self-destruct code.
X *
X * Revision 1.1 87/10/09 11:09:00 11:09:00 okamoto (Jeff Okamoto)
X * Initial revision
X *
X */
X/*
X * TREK73: moveships.c
X *
X * Actual command execution
X *
X * move_ships, check_targets, misc_timers, disposition
X *
X */
X
X#include "externs.h"
X
X
Xmove_ships()
X{
X register int i;
X register float j;
X register float k;
X register struct list *lp;
X register struct ship *sp;
X register float fuel_use;
X struct torpedo *tp;
X struct ship *fed;
X struct list *lp1;
X struct ship *sp1;
X float iterations;
X float tmpf;
X float energy;
X float course, newcourse;
X float warp, newwarp;
X int x, y;
X struct ship *target;
X double d0;
X float Mpersegment;
X double floor(), fabs();
X
X /*
X * The value 100 is the number of Megameters per second
X * per warp-factor
X */
X Mpersegment = segment * 100.0;
X iterations = (int)floor(timeperturn/segment + 0.5); /* What a crock! */
X for (i=0; i<=shipnum; i++)
X distribute(shiplist[i]);
X fed = shiplist[0];
X for (i=0; i<iterations; i++) {
X for (lp = &head; lp != NULL; lp = lp->fwd) {
X if (lp == tail)
X break;
X if (lp->type == I_UNDEFINED)
X continue;
X sp = NULL;
X tp = NULL;
X if (lp->type == I_SHIP)
X sp = lp->data.sp;
X else
X tp = lp->data.tp;
X if (sp && is_dead(sp, S_DEAD))
X continue;
X if ((sp) && (i % sp->p_firing_delay == 0))
X (void) phaser_firing(sp);
X if ((sp) && (i % sp->t_firing_delay == 0))
X (void) torpedo_firing(sp);
X /*
X * time fuses
X */
X if (tp) {
X tp->timedelay -= segment;
X if (tp->timedelay <= 0.) {
X torp_detonate(tp, lp);
X continue;
X }
X } else {
X sp->delay -= segment;
X if (sp->delay < segment / 2) {
X ship_detonate(sp, lp);
X continue;
X }
X }
X /*
X * proximity fuse
X */
X if (tp && tp->prox != 0) {
X for (lp1 = &head; lp1 != tail; lp1 = lp1->fwd) {
X if (lp1->type == I_SHIP) {
X sp1 = lp1->data.sp;
X if (sp1 == tp->from)
X continue;
X if (cantsee(sp1))
X continue;
X j = rangefind(tp->x, sp1->x,
X tp->y, sp1->y);
X } else if (lp1->type == I_ENG) {
X sp1 = lp1->data.sp;
X if (sp1 == tp->from)
X continue;
X if (cantsee(sp1))
X continue;
X j = rangefind(tp->x, sp1->x,
X tp->y, sp1->y);
X } else
X continue;
X if (j >= tp->prox)
X continue;
X torp_detonate(tp, lp);
X break;
X }
X if (lp1 != tail)
X continue;
X }
X /*
X * movement simulation
X */
X if (sp && is_dead(sp, S_DEAD))
X continue;
X if (sp) {
X x = sp->x;
X y = sp->y;
X warp = sp->warp;
X if (fabs(sp->newwarp) > sp->max_speed)
X sp->newwarp = (sp->newwarp > 0)
X ? sp->max_speed : -sp->max_speed;
X newwarp = sp->newwarp;
X course = sp->course;
X newcourse = sp->newcourse;
X target = sp->target;
X energy = sp->energy;
X /*
X * fuel consumption
X */
X if (fabs(warp) > 1.0)
X fuel_use = (fabs(warp) * sp->eff * segment);
X else
X fuel_use = 0.;
X#ifdef TRACE
X /*
X if (trace)
X printf("*** Fuel use = %.2f, energy = %.2f\n",
X fuel_use, energy);
X */
X#endif
X if (fuel_use > energy) {
X if (!shutup[BURNOUT + sp->id] &&
X !(is_dead(sp, S_WARP)) && cansee(sp)) {
X printf("%s's warp drive burning out.\n",
X sp->name);
X shutup[BURNOUT + sp->id]++;
X }
X newwarp = (warp < 0.0) ? -0.99 : 0.99;
X energy = 0;
X } else
X energy -= fuel_use;
X } else {
X x = tp->x;
X y = tp->y;
X warp = tp->speed;
X newwarp = tp->newspeed;
X course = tp->course;
X newcourse = course;
X target = tp->target;
X }
X /*
X * destroyed warp drive
X */
X if (sp && (is_dead(sp, S_WARP)))
X if (fabs(warp) > 1.0)
X newwarp = (warp < 0.0) ? -0.99 : 0.99;
X /*
X * automatic pilot
X */
X if (target != NULL)
X if (sp && (is_dead(target, S_DEAD))) {
X if ((sp == fed) && !shutup[DISENGAGE]
X && !is_dead(sp, S_DEAD)) {
X printf("%s's autopilot disengaging.\n",
X sp->name);
X shutup[DISENGAGE]++;
X }
X newcourse = course;
X target = NULL;
X sp->relbear = 0.0;
X } else {
X if (cantsee(target))
X j =bearing(x,target->position.x,
X y, target->position.y);
X else
X j = bearing(x, target->x, y, target->y);
X if (sp)
X j = rectify(j - sp->relbear);
X newcourse = j;
X }
X /*
X * turn rate (known to be a ship)
X */
X if (tp)
X course = newcourse;
X if (sp && course != newcourse) {
X j = rectify(newcourse - course);
X if (j > 180)
X j -= 360;
X /*
X * maximum degrees turned in one turn
X */
X k = ((sp->max_speed + 2.0 - warp)
X * sp->deg_turn * segment);
X /* If you have no warp drive, you're less
X * maneuverable
X */
X if (is_dead(sp, S_WARP))
X k /= 2;
X k = course + (j < 0.0 ? -1.0 : 1.0) *
X min(fabs(j), k);
X course = rectify(k);
X }
X /*
X * acceleration
X */
X tmpf = newwarp - warp;
X d0 = fabs(tmpf);
X warp += ((tmpf < 0.0) ? -1 : 1) * sqrt(d0) * segment;
X d0 = toradians(course);
X x += (int) (warp * cos(d0) * Mpersegment);
X y += (int) (warp * sin(d0) * Mpersegment);
X /*
X * projected position (cloaked)
X */
X if (sp && cantsee(sp)) {
X d0 = toradians(sp->position.course);
X sp->position.x += (sp->position.warp * cos(d0)
X * segment);
X sp->position.y += (sp->position.warp * sin(d0)
X * segment);
X }
X /*
X * reset all the vars
X */
X if (sp) {
X sp->x = x;
X sp->y = y;
X sp->warp = warp;
X sp->newwarp = newwarp;
X /* XXXXX should these be rectified? */
X sp->course = rectify(course);
X sp->newcourse = rectify(newcourse);
X sp->energy = energy;
X sp->target = target;
X } else {
X tp->x = x;
X tp->y = y;
X tp->speed = warp;
X tp->course = rectify(course);
X tp->target = target;
X }
X }
X }
X}
X
X
Xcheck_targets()
X{
X register int i;
X register int j;
X struct ship *sp;
X struct ship *fed;
X struct ship *target;
X
X fed = shiplist[0];
X for (i=0; i <= shipnum; i++) { /* Check targets */
X sp = shiplist[i];
X if (is_dead(sp, S_DEAD))
X continue;
X target = sp->target;
X if (target && is_dead(target, S_DEAD)) {
X if ((sp == fed) && !shutup[DISENGAGE]) {
X puts(" helm lock disengaging");
X shutup[DISENGAGE]++;
X }
X sp->target = NULL;
X sp->relbear = 0.0;
X }
X for (j=0; j<sp->num_phasers; j++) {
X target = sp->phasers[j].target;
X if (target && is_dead(target, S_DEAD)) {
X if ((sp == fed) && (!shutup[PHASERS+j])
X && !(is_dead(sp, S_DEAD))) {
X printf(" phaser %d disengaging\n",j+1);
X shutup[PHASERS+j]++;
X }
X sp->phasers[j].target = NULL;
X } else if (target)
X sp->phasers[j].bearing = rectify(bearing(sp->x,
X (cantsee(target)) ? target->position.x
X : target->x, sp->y,
X (cantsee(target)) ? target->position.y
X : target->y) - sp->course);
X }
X for (j=0; j<sp->num_tubes; j++) {
X target = sp->tubes[j].target;
X if (target && is_dead(target, S_DEAD)) {
X if ((sp == fed) && (!shutup[TUBES+j])
X && !(is_dead(sp, S_DEAD))) {
X printf(" tube %d disengaging\n", j+1);
X shutup[TUBES+j]++;
X }
X sp->tubes[j].target = NULL;
X } else if (target)
X sp->tubes[j].bearing = rectify(bearing(sp->x,
X (cantsee(target)) ? target->position.x
X : target->x, sp->y,
X (cantsee(target)) ? target->position.y
X : target->y) - sp->course);
X }
X }
X if (sp->cloak_delay > 0)
X sp->cloak_delay--;
X}
X
Xmisc_timers()
X{
X struct ship *fed;
X
X /*
X * self-destruct warning
X */
X fed = shiplist[0];
X if ((fed->delay < 1000.) && (fed->delay > segment / 2)) {
X if (is_dead(fed, S_COMP)) {
X printf("%s: Self-destruct has been aborted due to computer damage\n",
X science);
X fed->delay = 10000.;
X } else
X printf("Computer: %5.2f seconds to self destruct.\n",
X fed->delay);
X }
X
X fed->probe_status = PR_NORMAL;
X
X /*
X * Ruses, bluffs, surrenders
X */
X if (defenseless)
X defenseless++;
X if (corbomite)
X corbomite++;
X if (surrender)
X surrender++;
X if (surrenderp)
X surrenderp++;
X}
X
Xdisposition()
X{
X struct ship *sp;
X struct ship *fed;
X struct ship *ep;
X int kills;
X int others;
X int fedstatus;
X register int i;
X register int j;
X register int k;
X
X /*
X * Federation dispostion
X */
X fed = shiplist[0];
X sp = fed;
X kills = others = fedstatus = 0;
X if (sp->complement <= 0 && !is_dead(sp, S_DEAD)) {
X sp->status[S_DEAD] = 100;
X sp->newwarp = 0.0;
X sp->newcourse = sp->course;
X sp->target = NULL;
X sp->relbear = 0.0;
X for (i = 0; i < sp->num_phasers; i++) {
X sp->phasers[i].target = NULL;
X sp->phasers[i].drain = MIN_PHASER_DRAIN;
X sp->phasers[i].status &= ~P_FIRING;
X }
X for (i = 0; i < sp->num_tubes; i++) {
X sp->tubes[i].target = NULL;
X sp->tubes[i].status &= ~T_FIRING;
X }
X for (i = 0; i < SHIELDS; i++)
X sp->shields[i].attemp_drain = 0.0;
X sp->regen = 0.0;
X sp->cloaking = C_NONE;
X }
X if (is_dead(sp, S_DEAD))
X fedstatus = 1;
X else {
X for (i=0; i<sp->num_phasers; i++)
X if (!(sp->phasers[i].status & P_DAMAGED))
X break;
X if (i == sp->num_phasers) {
X for (i=0; i<sp->num_tubes; i++)
X if (!(sp->tubes[i].status & T_DAMAGED))
X break;
X if (i == sp->num_tubes)
X fedstatus = 1;
X }
X }
X /*
X * enemy disposition
X */
X for (k=1; k <= shipnum; k++) {
X ep = shiplist[k];
X if (ep->complement <= 0 && !is_dead(ep, S_DEAD)) {
X ep->status[S_DEAD] = 100;
X ep->newwarp = 0.0;
X ep->newcourse = ep->course;
X ep->target = NULL;
X ep->relbear = 0.0;
X for (i = 0; i < ep->num_phasers; i++) {
X ep->phasers[i].target = NULL;
X ep->phasers[i].drain = MIN_PHASER_DRAIN;
X ep->phasers[i].status &= ~P_FIRING;
X }
X for (i = 0; i < ep->num_tubes; i++) {
X ep->tubes[i].target = NULL;
X ep->tubes[i].status &= ~T_FIRING;
X }
X for (i = 0; i < SHIELDS; i++)
X ep->shields[i].attemp_drain = 0.0;
X ep->regen = 0.0;
X ep->cloaking = C_NONE;
X }
X if (is_dead(ep, S_DEAD)) {
X kills++;
X continue;
X }
X if (fedstatus)
X continue;
X j = rangefind(sp->x, ep->x, sp->y, ep->y);
X if ((j>3500 && is_dead(ep, S_WARP)) ||
X (j>4500 && ep->delay<10.)) {
X others++;
X continue;
X }
X /* Check if we are within range to turn off the flag */
X if ((j <= 3500) && (reengaged))
X reengaged = 0;
X if (ep->energy > 10)
X continue;
X for (i=0; i<ep->num_phasers; i++)
X if (!(ep->phasers[i].status & P_DAMAGED))
X break;
X if (i != ep->num_phasers)
X continue;
X for (i=0; i<ep->num_tubes; i++)
X if (!(ep->tubes[i].status & T_DAMAGED))
X break;
X if (i != ep->num_tubes)
X continue;
X kills++;
X }
X if (!fedstatus && (global & E_SURRENDER)) /* enemy surrender */
X if (leftovers())
X (void) warn(FIN_E_SURRENDER);
X else
X (void) final(FIN_E_SURRENDER);
X if ((is_dead(fed, S_SURRENDER)) && (kills + others < shipnum))
X if (leftovers()) /* federation surrender */
X (void) warn(FIN_F_SURRENDER);
X else
X (void) final(FIN_F_SURRENDER);
X if (!fedstatus && (kills + others) < shipnum) /* play continues */
X return 0;
X if (fedstatus && kills < shipnum) /* Fed. defeated */
X if (leftovers())
X (void) warn(FIN_F_LOSE);
X else
X (void) final(FIN_F_LOSE);
X if (!fedstatus && kills == shipnum) /* Fed. victory */
X if (leftovers())
X (void) warn(FIN_E_LOSE);
X else
X (void) final(FIN_E_LOSE);
X if (!fedstatus && (kills + others) == shipnum) /* outmaneuvered */
X if (leftovers())
X (void) warn(FIN_TACTICAL);
X else
X (void) final(FIN_TACTICAL);
X if (fedstatus && kills == shipnum)
X (void) final(FIN_COMPLETE); /* both sides dead */
X return 0;
X}
END_OF_src/moveships.c
if test 11725 -ne `wc -c <src/moveships.c`; then
echo shar: \"src/moveships.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f src/strat1.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"src/strat1.c\"
else
echo shar: Extracting \"src/strat1.c\" \(4166 characters\)
sed "s/^X//" >src/strat1.c <<'END_OF_src/strat1.c'
X#ident "@(#) TREK73 $Header: strat1.c,v 1.2 87/11/23 09:19:23 okamoto Exp $"
X/*
X * $Source: /ccc/okamoto/src/trek/src/RCS/strat1.c,v $
X *
X * $Header: strat1.c,v 1.2 87/11/23 09:19:23 okamoto Exp $
X *
X * $Log: strat1.c,v $
X * Revision 1.2 87/11/23 09:19:23 09:19:23 okamoto (Jeff Okamoto)
X * Fixed bug in behaviour after you successfully corbomite bluff.
X *
X * Revision 1.1 87/10/09 11:12:21 11:12:21 okamoto (Jeff Okamoto)
X * Initial revision
X *
X */
X/*
X * TREK73: strat1.c
X *
X * Standard Enemy Strategy
X *
X * standard_strategy
X *
X */
X
X#include "externs.h"
X
X
Xstandard_strategy(sp)
Xstruct ship *sp;
X{
X register struct ship *fed;
X float bear;
X int range;
X float tmpf;
X
X fed = shiplist[0];
X if (is_dead(sp, S_DEAD))
X return;
X range = rangefind(sp->x, fed->x, sp->y, fed->y);
X bear = bearing(sp->x, fed->x, sp->y, fed->y);
X bear = rectify(bear - sp->course);
X /*
X * Handle special requests
X */
X special(sp, range, fed);
X /*
X * Now check for surrendering flags
X */
X if ((global & F_SURRENDER) || (global & E_SURRENDER))
X return;
X
X /*
X * Always turn on cloaking device if we have it and if we
X * can afford it
X */
X if ((sp->cloaking == C_OFF) && (sp->energy >= 20)
X && e_cloak_on(sp, fed))
X return;
X
X /*
X * Check for hostile antimatter devices
X */
X if ((sp->cloaking == C_OFF) && e_closetorps(sp, fed))
X return;
X if ((sp->cloaking == C_OFF) && e_checkprobe(sp))
X return;
X
X /*
X * If cloaking is on, and we're running low on energy,
X * drop the cloak
X */
X /* XXXX May want to change number */
X if ((sp->cloaking == C_ON) && (sp->energy < 30)
X && e_cloak_off(sp, fed))
X return;
X
X /*
X * Short range?
X */
X if (range < 1050) {
X if (e_checkarms(sp) < randm((int)(sp->num_phasers+
X sp->num_tubes)/3)) {
X if (!e_cloak_on(sp, fed))
X (void) e_runaway(sp, fed);
X return;
X }
X if (e_lockphasers(sp, fed))
X return;
X if (e_phasers(sp, fed))
X return;
X if ((betw(bear, 90.0, 270.0)) &&
X !betw(corbomite, 1, 6)) {
X (void) e_pursue(sp, fed, 1.0);
X return;
X }
X if (e_launchprobe(sp, fed))
X return;
X if (sp->pods< 20 && sp->regen < 4.0 && e_destruct(sp, fed))
X return;
X /*
X * set course?
X */
X tmpf = fabs(fed->warp);
X if (((sp->target != fed || fabs(sp->warp) + tmpf > 2.0))
X && (!betw(corbomite, 1, 6))) {
X (void) e_pursue(sp, fed, tmpf);
X return;
X }
X if (e_cloak_on(sp, fed))
X return;
X }
X if (range < 3800) {
X /*
X * Either medium range, or we can't figure out what
X * to do at short range
X */
X if (e_locktubes(sp, fed))
X return;
X if (sp->energy > 30 && sp->pods > 40 && e_loadtubes(sp))
X return;
X if (e_torpedo(sp))
X return;
X /*
X * should we run away; can we?
X */
X if (e_checkarms(sp) < randm((int)(sp->num_phasers+
X sp->num_tubes)/3)) {
X if (!e_cloak_on(sp, fed))
X (void) e_runaway(sp, fed);
X return;
X }
X /*
X * Pursued from behind, low power: jettison engineering!
X */
X if (betw(bear, 90.0, 270.0) && sp->energy < 10
X && sp->regen < 4.0 && e_jettison(sp, fed))
X return;
X /*
X * put in other junk later
X */
X if (e_cloak_on(sp, fed))
X return;
X }
X /*
X * Either distant range, or we can't figure out
X * what to do at medium range
X */
X /* Warp drive dead and Federation destructing, run away! */
X if (fed->delay < 15. && (is_dead(sp, S_WARP))) {
X (void) e_runaway(sp, fed);
X return;
X }
X /*
X * enemy in our blind area? make a quick turn.
X */
X /* XXXX Should we check for blind spots?
X * or should we check for forward/aft
X */
X if ((betw(bear, sp->t_blind_left, sp->t_blind_right))
X && (!betw(corbomite, 1, 6))) {
X (void) e_pursue(sp, fed, 1.0);
X return;
X }
X if (e_locktubes(sp, fed))
X return;
X if (e_lockphasers(sp, fed))
X return;
X /*
X * attack?
X */
X /*
X tmpf = fabs(fed->warp);
X if (((sp->target != fed || sp->warp + tmpf > 2.0)) &&
X (!betw(corbomite, 1, 6))) {
X (void) e_pursue(sp, fed, (int)tmpf + 2.0 + randm(2));
X return;
X }
X */
X if (e_attack(sp, fed))
X return;
X if (sp->energy > 30 && sp->pods > 40 && e_loadtubes(sp))
X return;
X if (e_cloak_on(sp, fed))
X return;
X /*
X * gee, there's nothing that we want to do!
X */
X if (cansee(sp))
X printf("%s: We're being scanned by the %s\n",
X science, sp->name);
X}
END_OF_src/strat1.c
if test 4166 -ne `wc -c <src/strat1.c`; then
echo shar: \"src/strat1.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 2 \(of 6\).
cp /dev/null ark2isdone
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