Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!seismo!rutgers!ames!ucbcad!ucbvax!okamoto
From: okamoto@ucbvax.BERKELEY.EDU (The New Number Who)
Newsgroups: net.sources.games
Subject: Trek73 Part 3 (Part 2 of 2)
Message-ID: <16632@ucbvax.BERKELEY.EDU>
Date: Mon, 15-Dec-86 10:52:36 EST
Article-I.D.: ucbvax.16632
Posted: Mon Dec 15 10:52:36 1986
Date-Received: Tue, 16-Dec-86 21:07:31 EST
Organization: University of California at Berkeley
Lines: 756

#! /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:
#	misc.c
#	mission.c
#	bpv.c
#	shipyard.c
# This archive created: Mon Dec 15 07:44:24 1986
# By:	Jeff Okamoto ()
export PATH; PATH=/bin:$PATH
if test -f 'misc.c'
then
	echo shar: will not over-write existing file "'misc.c'"
else
cat << \SHAR_EOF > 'misc.c'
/*
 * TREK73: misc.c
 *
 * Miscellaneous Routines
 *
 * help, scancmd, new_slot, return_slot, vowelstr,
 * check_p_damage, check_t_damage, check_p_turn, check_t_turn,
 * ship_class
 *
 */

#include "externs.h"

int help(dummy)
struct ship *dummy;
{
	struct cmd	*cpbegin, *cpmiddle;

	puts("\nTrek73 Commands:");
	puts("Code		Command			Code		Command");
	putchar('\n');
	cpbegin = &cmds[0];
	cpmiddle = &cmds[(cmdarraysize + 1) >> 1];
	while (cpmiddle->routine != NULL) {
		printf("%3s:  %c %-31s:%3s:  %c %-31s\n",
		    cpbegin->word1, ((cpbegin->turns) ? ' ' : '*'),
		    cpbegin->word2, cpmiddle->word1,
		    ((cpmiddle->turns) ? ' ' : '*'), cpmiddle->word2);
		cpbegin++;
		cpmiddle++;
	}
	if (cmdarraysize & 1)
		printf("%3s:  %c %-31s", cpbegin->word1,
		    ((cpbegin->turns) ? ' ' : '*'), cpbegin->word2);
	puts("\n\n * does not use a turn");
	dummy = dummy;				/* LINT */
}

struct cmd *scancmd(buf)
char *buf;
{
	static char **argp = NULL;
	struct	cmd *cp;
	int	argnum;
	int	first;

	argnum = parsit(buf, &argp);
	first = strlen(argp[0]);
	if (argnum && first)
		for (cp = &cmds[0]; cp->routine != NULL; cp++)
			if (!strncmp(argp[0], cp->word1, first))
				return (cp);
	return (NULL);
}

/*
 * This routine handles getting unique identifier numbers for
 * all objects.
 */
new_slot()
{
	/*
	 * This is to make it appear that in a 2-ship duel, for
	 * instance, the first object to appear will be numbered
	 * as 3.
	 */
	int i = shipnum + 2;

	while ((slots[i] == 'X') && (i <= HIGHSLOT))
		i++;
	if (i > HIGHSLOT) {
		puts("The game will terminate now due to an inability to handle the number of");
		puts("objects in space (i.e. vessels, torpedoes, probes, etc).  Sorry!");
		exit(-1);
	}
	slots[i] = 'X';
	return i;
}

/* 
 * This routine handles returning identifiers
 */
return_slot(i)
int i;
{
	if (slots[i] != 'X')
		printf("FATAL ERROR - Slot already empty!");
	slots[i] = ' ';
}


char *vowelstr(str)
char *str;
{
	switch(*str) {
		case 'a': case 'A':
		case 'e': case 'E':
		case 'i': case 'I':
		case 'o': case 'O':
		case 'u': case 'U':
			return "n";
		default:
			return "";
	}
}


/*
 * This routine takes an array generated from commands 1, 3, and 5
 * to print out a list of those phasers damaged and unable to
 * either fire, lock, or turn.
 */
check_p_damage(array, sp, string)
int array[];
struct ship *sp;
char *string;
{
	int i, j;

	j = 0;
	for (i=0; inum_phasers; i++) {
		if (array[i] && (sp->phasers[i].status & P_DAMAGED)) {
			if (!j)
				printf("Computer: Phaser(s) %d", i+1);
			else
				printf(", %d", i+1);
			j++;
		}
	}
	if (j > 1)
		printf(" are damaged and unable to %s.\n", string);
	else if (j == 1)
		printf(" is damaged and unable to %s.\n", string);
}

/*
 * This routine takes an array generated from commands 2, 4, and 6
 * to print out a list of those tubes damaged and unable to either
 * fire, lock, or turn.
 */
check_t_damage(array, sp, string)
int array[];
struct ship *sp;
char *string;
{
	int i, j;

	j = 0;
	for (i=0; inum_tubes; i++) {
		if (array[i] && (sp->tubes[i].status & P_DAMAGED)) {
			if (!j)
				printf("Computer: Tube(s) %d", i+1);
			else
				printf(", %d", i+1);
			j++;
		}
	}
	if (j > 1)
		printf(" are damaged and unable to %s.\n", string);
	else if (j == 1)
		printf(" is damaged and unable to %s.\n", string);
}

/*
 * This routine checks to see if a phaser is pointing into our
 * blind side
 */
check_p_turn(array, sp, flag)
int array[];
struct ship *sp;
int flag;			/* If 1, came from fire_phasers */
{
	register int i;
	register int j;
	register float k;
	register float bear;
	struct ship *target;

	j = 0;
	for (i=0; inum_phasers; i++) {
		if (!array[i])
			continue;
		if (flag && !(sp->phasers[i].status & P_FIRING))
			continue;
		target = sp->phasers[i].target;
		/*
		 * This hack is here since when the phaser is locked,
		 * the bearing points at the target, whereas when
		 * not locked, the bearing is relative to the ship.
		 */
		if (target == NULL) {
			bear = sp->phasers[i].bearing + sp->course;
			k = sp->phasers[i].bearing;
		} else {
			bear = bearing(sp->x, target->x, sp->y, target->y);
			k = bear - sp->course;
		}
		k = rectify(k);

		if (betw(k, sp->p_blind_left, sp->p_blind_right)
		    && !(is_dead(sp, S_ENG))) {
			if (!j)
				printf("Computer: Phaser(s) %d", i + 1);
			else
				printf(", %d", i + 1);
			j++;
		}
	}
	if (j > 1)
		printf(" are pointing into our blind side.\n");
	else if (j == 1)
		printf(" is pointing into our blind side.\n");
}

/*
 * This routine checks to see if a tube is turned into
 * our blind side.
 */
check_t_turn(array, sp, flag)
int array[];
struct ship *sp;
int flag;			/* If 1, came from fire_tubes */
{
	register int i;
	register int j;
	register float k;
	register float bear;
	struct ship *target;

	j = 0;
	for (i=0; inum_tubes; i++) {
		if (!array[i])
			continue;
		if (flag && !(sp->tubes[i].status & T_FIRING))
			continue;
		target = sp->tubes[i].target;
		/*
		 * This hack is here since when the tube is locked,
		 * the bearing points at the target, whereas when
		 * not locked, the bearing is relative to the ship.
		 */
		if (target == NULL) {
			bear = sp->tubes[i].bearing + sp->course;
			k = sp->tubes[i].bearing;
		} else {
			bear = bearing(sp->x, target->x, sp->y, target->y);
			k = bear - sp->course;
		}
		k = rectify(k);
		if (betw(k, sp->t_blind_left, sp->t_blind_right) && !(is_dead(sp, S_ENG))) {
			if (!j)
				printf("Computer: Tubes(s) %d", i + 1);
			else
				printf(", %d", i + 1);
			j++;
		}
	}
	if (j > 1)
		printf(" are pointing into our blind side.\n");
	else if (j == 1)
		printf(" is pointing into our blind side.\n");
}

struct ship_stat *ship_class(s)
char *s;
{
	int i;

	for (i = 0; i< MAXSHIPCLASS; i++)
		if (!strcmp(stats[i].abbr, s)) {
			return(&stats[i]);
		}
	return(NULL);
}
SHAR_EOF
chmod +x 'misc.c'
fi # end of overwriting check
if test -f 'mission.c'
then
	echo shar: will not over-write existing file "'mission.c'"
else
cat << \SHAR_EOF > 'mission.c'
/*
 * TREK73: mission.c
 *
 * Mission Assignment Routines
 *
 * mission, alert, missionlog
 */

#ifdef BSD
#include 
#endif
#ifdef SYSV
#include 
#endif

#include "externs.h"


mission()
{
	int onef;
	char temp[3];

	if (terse)
		return;
	onef = (shipnum == 1);
	puts("\n\n\nSpace, the final frontier.");
	printf("These are the voyages of the starship %s.\n", shiplist[0]->name);
	puts("Its five year mission: to explore strange new worlds,");
	puts("to seek out new life and new civilizations,");
	puts("to boldly go where no man has gone before!");
	puts("\n                    S T A R    T R E K\n");
	missionlog();
	if (onef)
		strcpy(temp, "a");
	else
		sprintf(temp,"%d", shipnum);
	printf("%s:  %s, I'm picking up %s vessel%s on an interception\n",
	    helmsman, title, temp, plural(shipnum));
	printf("   course with the %s.\n", shiplist[0]->name);
	printf("%s:  Sensors identify %s as ", science, onef ? "it" : "them");
	if (onef)
		printf("a%s ", vowelstr(foerace));
	printf("%s %s%s,\n", foerace, foestype, plural(shipnum));
	printf("   probably under the command of Captain %s.\n", foename);
	printf("%s:  Sound general quarters, Lieutenant!\n", captain);
	printf("%s:  Aye, %s!\n", com,  title);
}

alert()
{
	register int i;

	printf("Computer: The %ss are attacking the %s with the ",
	    foerace, shiplist[0]->name);
	if (shipnum == 1) {
		printf("%s", shiplist[1]->name);
	} else {
		for (i = 1; i <= shipnum; i++) {
			if (i == shipnum)
				printf("and the ");
			printf("%s", shiplist[i]->name);
			if (i == shipnum)
				continue;
			printf(", ");
			if (i == 1 || i == 6)
				printf("\n   ");
		}
	}
	printf(".\n");
}

missionlog()
{
	static char *missiontab[] = {

	/* "The Trouble with Tribbles" */
	"   We are acting in response to a Priority 1 distress call from",
	"space station K7.",

	/* "The Gamesters of Triskelion" */
	"   We are orbiting Gamma 2 to make a routine check of automatic",
	"communications and astrogation stations.",

	/* "Metamorphosis" */
	"   We are on course for Epsilon Canares 3 to treat Commissioner",
	"Headford for Sukaro's disease.",

	/* "Journey to Babel" */
	"   We have been assigned to transport ambassadors to a diplomatic",
	"conference on the planet code named Babel.",

	/* ?? */
	"   Our mission is to investigate a find of tritanium on Beta 7.",
	0,

	/* "Shore Leave" */
	"   We are orbiting Rigel 4 for therapeutic shore leave.",
	0,

	/* "A Piece of the Action" */
	"   We are orbiting Sigma Iota 2 to study the effects of",
	"contamination upon a developing culture.",

	/* "The Immunity Syndrome" */
	"   We have altered course for a resue mission on the Gamma 7A",
	"system.",

	/* "Amok Time" */
	"   We are presently on course for Altair 6 to attend inauguration",
	"cermonies on the planet.",

	/* "Who Mourns for Adonis?" */
	"   We are on a cartographic mission to Pollux 9.",
	0,

	/* "The Changeling" */
	"   We are headed for Malurian in response to a distress call",
	"from that system.",

	/* "Mirror, Mirror" */
	"   We are to negotiate a treaty to mine dilithium crystals from",
	"the Halkans.",

	/* "The Apple" */
	"   We are to investigate strange sensor readings reported by a",
	"scoutship investigating Gamma Triangula 6.",

	/* "The Doomsday Machine" */
	"   We are headed for planets L370 and L374 to investigate the",
	"disappearance of the starship Constellation in that vincinity.",

	/* "The Ultimate Computer" */
	"   We are ordered, with a skeleton crew, to proceed to Space",
	"Station K2 to test Dr. Richard Daystrom's computer M5.",

	/* "Bread and Circuses" */
	"   We have encountered debris from the SS Beagle and are",
	"proceeding to investigate.",

	/* "Patterns of Force" */
	"   We are on course for Ekos to locate John Gill.",
	0,

	/* "The Paradise Syndrome" */
	"   We are to divert an asteroid from destroying an inhabited",
	"planet.",

	/* "And The Children Shall Lead" */
	"   We are responding to a distresss call form the scientific",
	"expedition on Triacus.",

	/* "Is There in Truth No Beauty?" */
	"   We have been assigned to transport the Medusan Ambassador to",
	"to his home planet.",

	/* "Star Trek II -- The Wrath of Khan" */
	"   We are within the Neutral Zone on a mission to rescue the",
	"Kobayashi Maru.",

	};
	long t1;
	struct tm *localtime(), *date;

	t1 = time(0);
	date = localtime(&t1);
	printf("%s:  Captain's log, stardate %02d%02d.%02d\n",
	    captain, date->tm_year, date->tm_mon+1, date->tm_mday);
	t1 = (randm(sizeof missiontab / sizeof (char *)) - 1) & ~01;
	puts(missiontab[t1]);
	if (missiontab[++t1])
		printf("   %s\n", missiontab[t1]);
}
SHAR_EOF
chmod +x 'mission.c'
fi # end of overwriting check
if test -f 'bpv.c'
then
	echo shar: will not over-write existing file "'bpv.c'"
else
cat << \SHAR_EOF > 'bpv.c'
/*
 * TREK73: bpv.c
 *
 * Calculate Basic Point Values for all ships.
 *
 */

#include 
#include "externs.h"

main()
{
	double crew, pods, regen, num_weapons, phaser, torp;
	double bpv;
	double atof();
	int i;
	char buf[20];

	printf("Regeneration multiplier :");
	gets(buf);
	regen = atof(buf);
	printf("Pods divisor            :");
	gets(buf);
	pods = atof(buf);
	printf("Phaser multiplier       :");
	gets(buf);
	phaser = atof(buf);
	printf("Torpedo multiplier      :");
	gets(buf);
	torp = atof(buf);
	printf("Weapons multiplier      :");
	gets(buf);
	num_weapons = atof(buf);
	printf("Crew divisor            :");
	gets(buf);
	crew = atof(buf);

	for(i=0; i 'shipyard.c'
/*
 * TREK73: shipyard.c
 *
 * Design your own ship
 *
 */

#include 
#include 
#include 
#include "externs.h"

char buf[20];
char class[3];
char cloak;
double bpv;
struct {
	char description[30];
	char race[30];
	char empire[30];
} stuff;

struct ship_stat design;

main()
{
	double regen, efficiency, atof(), floor(), round();
	int crew, phasers, torps, pods, max_speed, turn, p_div, t_div;
	int done, atoi();

	printf("Class identifier           :");
	gets(class);
	class[2] = '\0';
	printf("Class description          :");
	gets(stuff.description);
	stuff.description[29] = '\0';
	printf("Race name                  :");
	gets(stuff.race);
	stuff.race[29] = '\0';
	printf("Empire name                :");
	gets(stuff.empire);
	stuff.empire[29] = '\0';
	done = 0;
	while (!done) {
		printf("Regeneration               :");
		gets(buf);
		regen = atof(buf);
		if (regen >= 0)
			done = 1;
		else
			printf(">>> Be reasonable.\n");
	}
	done = 0;
	while (!done) {
		printf("Pods                       :");
		gets(buf);
		pods = atof(buf);
		if (pods >= 0)
			done = 1;
		else
			printf(">>> Be reasonable.\n");
	}
	done = 0;
	while (!done) {
		printf("Number of phasers          :");
		gets(buf);
		phasers = atoi(buf);
		if ((phasers >= 0) && (phasers < MAXWEAPONS))
			done = 1;
		else
			if (phasers < 0)
				printf(">>> Be reasonable.\n");
			else
				printf(">>> Can't have more than %d.\n",
				    MAXWEAPONS-1);
	}
	done = 0;
	while (!done) {
		printf("Number of tubes            :");
		gets(buf);
		torps = atoi(buf);
		if ((torps >= 0) && (torps < MAXWEAPONS))
			done = 1;
		else
			if (torps < 0)
				printf(">>> Be reasonable.\n");
			else
				printf(">>> Can't have more than %d.\n",
				    MAXWEAPONS-1);
	}
	done = 0;
	while (!done) {
		printf("Shield divisor for phasers :");
		gets(buf);
		p_div = atof(buf);
		if (p_div > 0)
			done = 1;
		else
			printf(">>> Be reasonable.\n");
	}
	done = 0;
	while (!done) {
		printf("Shield divisor for torps   :");
		gets(buf);
		t_div = atof(buf);
		if (t_div > 0)
			done = 1;
		else
			printf(">>> Be reasonable.\n");
	}
	done = 0;
	while (!done) {
		printf("Crew                       :");
		gets(buf);
		crew = atoi(buf);
		if (crew > 0)
			done = 1;
		else
			printf(">>> Be reasonable.\n");
	}
	printf("Can the ship cloak         ?");
	gets(buf);
	if (buf != NULL && (buf[0] == 'y' || buf[0] == 'Y'))
		cloak = 1;
	else
		cloak = 0;

	bpv = 0.;
	bpv += regen * 12;
	bpv += pods / 2;
	bpv += p_div * 30;
	bpv += t_div * 40;
	bpv += (phasers + torps) * 10;
	bpv += crew / 15;
	printf("%s: BPV = %.2f\n", class, bpv);

	efficiency = round(4 * (0.0034 * bpv - 0.78)) / 4;
	if (efficiency < 0.25)
		efficiency = 0.25;
	turn = 10 - floor(bpv / 100);
	if (turn < 1)
		turn = 1;
	max_speed = (int) round(-0.004 * bpv + 11);
	if (max_speed < 1)
		max_speed = 1;

	printf("Efficiency = %.2f\n", efficiency);
	printf("Turn = %d\n", turn);
	printf("Max speed = %d\n", max_speed);

	strcpy(design.abbr, class);
	design.num_phaser = phasers;
	design.num_torp = torps;
	design.o_warpmax = max_speed;
	design.e_warpmax = max_speed + 2;
	design.o_eff = efficiency;
	design.e_eff = efficiency;
	design.regen = regen;
	/* XXXX */
	design.energy = pods * 3 / 4;
	design.pods = pods;
	design.o_crew = crew;
	design.e_crew = crew * 5 / 4;
	design.ph_shield = p_div;
	design.tp_shield = t_div;
	design.turn_rate = turn;
	design.cloaking_energy = 4;
	/* XXXX */
	design.t_blind_left = 135;
	design.t_blind_right = 225;
	design.p_blind_left = 125;
	design.p_blind_right = 235;
	design.p_firing_delay = 4;
	design.t_firing_delay = 4;

	save_design();
}

double round(x)
double x;
{
	return( floor(x + 0.5));
}

save_design()
{
	int fd, bytes;
	char path[BUFSIZ];
	char *home, *getenv();

	if ((home = getenv("HOME")) != NULL)
		strcpy(path, home);
	else
		strcpy(path, ".");
	
	strcat(path, "/.trek");
	strcat(path, design.abbr);
	printf("Saving to file %s\n", path);
	
	if ((fd = open(path, O_WRONLY|O_CREAT, 0644)) < 0) {
		perror("open");
		exit(1);
	}
	bytes = write(fd, (char *)&design, sizeof(struct ship_stat));
	if (bytes != sizeof(struct ship_stat)) {
		fprintf(stderr, "Wrote only %d, not %d bytes\n", bytes,
		    sizeof(struct ship_stat));
		unlink(path);
		exit(1);
	}
	bytes = write(fd, &stuff, sizeof(stuff));
	bytes = write(fd, &cloak, 1);
	bytes = write(fd, (char *)&bpv, sizeof(int));
	close(fd);
}
SHAR_EOF
chmod +x 'shipyard.c'
fi # end of overwriting check
#	End of shell archive
exit 0