Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site ucbvax.ARPA
Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!ucbvax!okamoto
From: okamoto@ucbvax.ARPA (Doctor Who)
Newsgroups: net.sources.games
Subject: Trek73 (part 5 of 4)
Message-ID: <10411@ucbvax.ARPA>
Date: Tue, 17-Sep-85 10:41:47 EDT
Article-I.D.: ucbvax.10411
Posted: Tue Sep 17 10:41:47 1985
Date-Received: Thu, 19-Sep-85 04:30:45 EDT
Organization: University of California at Berkeley
Lines: 478
Here is the Makefile for trek73 and the missing file. Sorry for
any problems.
Jeff Okamoto
# This is a shell archive.
# Remove everything above and including the cut line.
# Then run the rest of the file through sh.
-----cut here-----cut here-----cut here-----cut here-----
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# Makefile
# subs.c
# This archive created: Tue Sep 17 07:39:18 1985
echo shar: extracting Makefile '(709 characters)'
sed 's/^XX//' << \SHAR_EOF > Makefile
XX#
XX# makefile for trek73
XX#
XX
XXCFLAGS=-O
XXOBJECTS= cmds1.o cmds2.o cmds3.o cmds4.o dist.o endgame.o enemycom.o\
XX firing.o globals.o main.o misc.o mission.o moveships.o\
XX parseopts.o strat1.o subs.o
XXCFILES= cmds1.c cmds2.c cmds3.c cmds4.c dist.c endgame.c enemycom.c\
XX firing.c globals.c main.c misc.c mission.c moveships.c\
XX parseopts.c strat1.c subs.c
XXHEADS= structs.h defines.h
XXLIBS= -lm
XX
XXall: trek73
XX
XXtrek73: ${OBJECTS} parsit.o
XX cc ${CFLAGS} ${OBJECTS} parsit.o ${LIBS}
XX install a.out trek73
XX
XX${OBJECTS}: ${HEADS}
XX
XXparsit.o: parsit.c
XX cc -O -c parsit.c
XX
XXtags: ${CFILES}
XX ctags ${CFILES} ${HEADS}
XX
XXlint:
XX lint -za ${CFILES} > lint.out
XX
XXclean:
XX rm -f ${OBJECTS} parsit.o trek73 make.out errs core lint.out a.out
SHAR_EOF
if test 709 -ne "`wc -c Makefile`"
then
echo shar: error transmitting Makefile '(should have been 709 characters)'
fi
echo shar: extracting subs.c '(7513 characters)'
sed 's/^XX//' << \SHAR_EOF > subs.c
XX/*
XX * TREK73: subs.c
XX *
XX * Miscellaneous Subroutines
XX *
XX * ship_name, newitem, delitem, rangefind, bearing, phaser_hit,
XX * torpedo_hit, damage, antimatter_hit, recitfy
XX */
XX
XX#include "defines.h"
XX#include "structs.h"
XX#include
XX#include
XX
XXextern struct ship *shiplist[];
XXextern char science[];
XX
XXstruct ship *ship_name(name, start)
XXchar *name;
XXint start;
XX{
XX extern int shipnum;
XX register int i;
XX register int j;
XX register int len;
XX
XX if (islower(*name)) {
XX *name = toupper(*name);
XX }
XX j = shipnum;
XX len = strlen(name);
XX for (i=start; i<=j; i++) {
XX if (shiplist[i]->name[0] == NULL)
XX continue;
XX if (strncmp(name, shiplist[i]->name, len) == 0)
XX return shiplist[i];
XX }
XX printf("%s: I am unable to find the %s\n", science, name);
XX return NULL;
XX}
XX
XX
XXstruct list *newitem(item)
XXint item;
XX{
XX extern struct list head;
XX extern struct list *tail;
XX register struct list *new;
XX register struct list *newtail;
XX
XX /*
XX * if there's no "tail" node, make one (only happens at init)
XX */
XX if (tail == NULL) {
XX new = MKNODE(struct list, *, 1);
XX new->back = &head;
XX new->fwd = NULL;
XX new->data.tp = NULL;
XX head.fwd = new;
XX tail = new;
XX }
XX new = tail;
XX /*
XX * now make the new tail node
XX */
XX newtail = MKNODE(struct list, *, 1);
XX newtail->back = new;
XX newtail->fwd = NULL;
XX newtail->data.tp = NULL;
XX newtail->type = 0;
XX tail = newtail;
XX /*
XX * link the old tail node to the new one
XX */
XX new->type = item;
XX new->fwd = newtail;
XX return new;
XX}
XX
XX
XXint delitem(item)
XXstruct list *item;
XX{
XX extern struct list *tail;
XX extern struct list head;
XX register struct list *bp;
XX register struct list *fp;
XX
XX bp = item->back;
XX fp = item->fwd;
XX if (item->data.tp != NULL)
XX free((char *) item->data.tp);
XX /*
XX * re-arrange pointers on both the next and the previous
XX * nodes; if no forward pointer, we were the tail so make
XX * the bp the new tail node.
XX */
XX if (fp != NULL) {
XX bp->fwd = fp;
XX fp->back = bp;
XX } else {
XX tail = bp;
XX bp->fwd = NULL;
XX }
XX free((char *) item);
XX}
XX
XXint rangefind(x1, x2, y1, y2)
XXint x1;
XXint x2;
XXint y1;
XXint y2;
XX{
XX extern double sqrt();
XX extern double atan();
XX register int i;
XX register int x, y;
XX double d1, d2;
XX
XX x = x2 - x1;
XX y = y2 - y1;
XX /*
XX * Both x and y must be cast as double else overflow
XX * may occur.
XX */
XX d1 = (double) x * (double) x + (double) y * (double) y;
XX d2 = sqrt(d1);
XX i = d2;
XX return i;
XX}
XX
XX/*
XX * This routine finds the bearing of (x2,y2) from (x1,y1)
XX */
XXint bearing(x1, x2, y1, y2)
XXint x1;
XXint x2;
XXint y1;
XXint y2;
XX{
XX extern double atan();
XX float x;
XX float y;
XX register int bear;
XX double d1;
XX double d2;
XX
XX x = x2 - x1;
XX y = y2 - y1;
XX if (x == 0.0)
XX bear = 90;
XX else {
XX d1 = y/x;
XX d2 = atan(d1) * 57.2958;
XX bear = d2;
XX }
XX if (x < 0.0 || y < 0.0) {
XX bear += 180;
XX if (x >= 0.0)
XX bear += 180;
XX }
XX return bear;
XX}
XX
XXint phaser_hit(sp, x, y, bank, true_bear)
XXstruct ship *sp;
XXint x;
XXint y;
XXstruct phaser *bank;
XXint true_bear;
XX{
XX extern double sqrt();
XX register int hit;
XX int i;
XX int spread;
XX int bear;
XX double d1;
XX double d2;
XX
XX hit = 0;
XX i = rangefind(sp->x, x, sp->y, y);
XX if (i < 1000) {
XX bear = bearing(sp->x, x, sp->y, y);
XX spread = rectify(true_bear - bear);
XX /*
XX * Check if a target is within the phaser spread
XX */
XX if (spread > sp->p_spread && 360-spread > sp->p_spread)
XX return 0;
XX d1 = 1.0 - (float)i/1000.0;
XX d2 = (float)bank->load * sqrt(d1) * sp->p_percent / 100;
XX d2 = (float)bank->load * d2 * 45.0/(float)sp->p_spread * sp->p_percent / 100;
XX hit = d2/10.0;
XX }
XX return hit;
XX}
XX
XXint torpedo_hit(fuel, x, y, tx, ty)
XXint fuel;
XXint x;
XXint y;
XXint tx;
XXint ty;
XX{
XX extern double sqrt();
XX register int hit;
XX int i;
XX double d1;
XX double d2;
XX float f1;
XX float f2;
XX
XX hit = 0;
XX i = rangefind(x, tx, y, ty);
XX f1 = fuel * 5.0;
XX f2 = f1 * 10.0;
XX if (i < f2) {
XX d1 = 1.0 - (float)i/f2;
XX d2 = (float)f1 * sqrt(d1);
XX hit = d2;
XX }
XX return hit;
XX}
XX
XX
XXdamage(hit, ep, s, dam)
XXint hit;
XXstruct ship *ep;
XXint s;
XXstruct damage *dam;
XX{
XX register int i;
XX register int j;
XX register int k;
XX float f1;
XX float f2;
XX struct ship *fed;
XX
XX fed = shiplist[0];
XX printf("hit %d on %s's shield %d\n", hit, ep->name, s);
XX s--;
XX /*
XX * Note that if the shield is at 100% efficiency, no
XX * damage at all will be taken
XX */
XX f1 = hit * (1.0 - ep->shields[s].eff * ep->shields[s].drain);
XX if (f1 < 0)
XX return 0;
XX ep->eff += f1/dam->eff;
XX ep->pods -= f1/dam->fuel;
XX ep->energy -= f1/dam->fuel;
XX ep->regen -= f1/dam->regen;
XX if (ep->regen < 0.0)
XX ep->regen = 0.0;
XX if (ep->pods < 0.0)
XX ep->pods = 0.0;
XX if (ep->energy < 0.0)
XX ep->energy = 0.0;
XX if (ep->pods < ep->energy)
XX ep->energy = ep->pods;
XX f2 = dam->shield * 100;
XX if (s == 0)
XX f2 *= 1.5;
XX ep->shields[s].eff -= max(hit/f2, 0);
XX if (ep->shields[s].eff < 0.0)
XX ep->shields[s].eff = 0.0;
XX j = f1 * dam->crew;
XX if (j > 0)
XX ep->crew -= max(randm(j), 0);
XX if (ep->crew < 0)
XX ep->crew = 0;
XX j = f1/dam->weapon;
XX for(i=0; iphasers[k].status & P_DAMAGED)
XX continue;
XX ep->phasers[k].status |= P_DAMAGED;
XX /*
XX * Reroute the energy
XX * back to the engines
XX */
XX ep->energy = min(ep->pods, ep->energy
XX + ep->phasers[k].load);
XX ep->phasers[k].load = 0;
XX ep->phasers[k].drain = 0;
XX k++;
XX if (ep == fed)
XX printf(" phaser %d damaged.\n", k);
XX } else {
XX k -= 5;
XX if (ep->tubes[k].status & T_DAMAGED)
XX continue;
XX /*
XX * If tubes are damaged, reroute the pods
XX * back to the engines
XX */
XX ep->pods += ep->tubes[k].load;
XX ep->energy += ep->tubes[k].load;
XX ep->tubes[k].load = 0;
XX ep->tubes[k].status |= T_DAMAGED;
XX k++;
XX if (ep == fed)
XX printf(" tube %d damaged\n", k);
XX }
XX }
XX for (i=0; i<4; i++) {
XX if (ep->status & 1<stats[i].roll) < f1) {
XX ep->status |= 1<stats[i].mesg);
XX }
XX }
XX#ifdef HISTORICAL
XX /*
XX * Historically, if more than 43 points of damage were done
XX * to the ship, it would destroy itself. This led to much
XX * abuse of probes and thus has been enclosed inside of
XX * an #ifdef
XX */
XX if (f1 > 43)
XX ep->delay = 1;
XX#endif
XX return 0;
XX}
XX
XX
XXantimatter_hit(ptr, x, y, fuel)
XXchar *ptr;
XXint x;
XXint y;
XXint fuel;
XX{
XX extern struct list head;
XX extern struct list *tail;
XX extern struct damage a_damage;
XX register struct list *lp;
XX register int hit;
XX int tarx, tary;
XX int s;
XX int bear;
XX struct torpedo *tp;
XX struct ship *sp;
XX
XX for (lp = &head; lp != tail; lp = lp->fwd) {
XX if (lp->type == 0)
XX continue;
XX sp = NULL;
XX tp = NULL;
XX if (lp->type == I_SHIP) {
XX sp = lp->data.sp;
XX tarx = sp->x;
XX tary = sp->y;
XX } else {
XX tp = lp->data.tp;
XX tarx = tp->x;
XX tary = tp->y;
XX }
XX if (sp == (struct ship *) ptr || tp == (struct torpedo *) ptr)
XX continue;
XX hit = torpedo_hit(fuel, x, y, tarx, tary);
XX if (hit <= 0)
XX continue;
XX if (sp) {
XX /*
XX * Determine which shield is hit
XX */
XX bear = rectify(bearing(tarx, x, tary, y) - sp->course);
XX if (bear < 45 || bear > 315)
XX s = 1;
XX else if (bear < 135)
XX s = 2;
XX else if (bear < 225)
XX s = 3;
XX else
XX s = 4;
XX damage(hit, sp, s, &a_damage);
XX } else {
XX if (tp->timedelay <= 2)
XX continue;
XX tp->timedelay = 2;
XX switch (lp->type) {
XX case I_TORPEDO:
XX printf("hit on torpedo %d\n",
XX tp->id);
XX break;
XX case I_PROBE:
XX printf("hit on probe %d\n",
XX tp->id);
XX break;
XX case I_ENG:
XX printf("hit on %s engineering\n",
XX tp->from->name);
XX break;
XX }
XX }
XX }
XX}
XX
XXint rectify(x)
XXint x;
XX{
XX register int ret;
XX
XX ret = x;
XX if (ret < 0)
XX ret += 360;
XX else if (ret > 360)
XX ret -= 360;
XX return ret;
XX}
SHAR_EOF
if test 7513 -ne "`wc -c subs.c`"
then
echo shar: error transmitting subs.c '(should have been 7513 characters)'
fi
# End of shell archive
exit 0