wei@princeton.UUCP (P Wei) (11/15/85)
I am posting this file for Robert Viduya at GIT, who could not post it by himself because of some problems at GIT. Now , here it goes... Enjoy!! HP Wei (wei@princeton) >They just turned off net.sources.games at this site and they'll probably >turn it off for all of the Georgia Tech machines in a couple of weeks. >Since I promised a cursified vtrek to be posted to net.sources.games, >could you post this? I got a number of requests for it and you were one >closer. > thanks.. > robert >Robert Viduya >Office of Computing Services >Georgia Institute of Technology >UUCP: {akgua,allegra,amd,hplabs,ihnp4,masscomp,ut-ngp,rlgvax,sb1, .. > uf-cgrl,unmvax,ut-sally}!gatech!{gitpyr,gt-oscar,gt-felix}!robert >BITNET: CC100RV @ GITVM1 --cut here-- #! /bin/sh # Run the following text with /bin/sh to create: # makefile # vtrek.h # main.c # plot.c # sub1.c # sub2.c # termio.c # vtrek.doc if test -f 'makefile' then echo "`basename $0`: can't extract" 'makefile' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_makefile--' > 'makefile' XOBJS=main.o plot.o sub1.o sub2.o termio.o X X# use -f if on a 3b2/300 (no hardware floating point) X# use -DBSD if on a BSD machine X#CFLAGS=-O -f X#CFLAGS=-O -DBSD XCFLAGS=-O X X# use -ltermlib if on a BSD machine X#LIBS=-lm -lcurses -ltermlib XLIBS=-lm -lcurses X Xa.out: $(OBJS) X cc $(CFLAGS) $(OBJS) $(LIBS) X Xinstall: a.out X mv a.out /usr/games/vtrek X cp vtrek.doc /usr/games/lib/vtrek.doc X X.c.o: X cc $(CFLAGS) -c $*.c X X$(OBJS): vtrek.h --End_of_makefile-- if test 429 -ne `wc -c < 'makefile'` then echo "`basename $0`: error in" 'makefile' ": sent 429 chars, received `wc -c < 'makefile'`" 1>&2 fi fi if test -f 'vtrek.h' then echo "`basename $0`: can't extract" 'vtrek.h' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_vtrek.h--' > 'vtrek.h' X/* vtrek.h -- header file for visual star trek */ X X X#include <stdio.h> X#include <math.h> X#include <ctype.h> X#include <curses.h> X X#define VTREKINS "/usr/games/lib/vtrek.doc" /* instructions */ X#define ERROR -1 X#define PI 3.1415926 X#define Toupper(x) (islower(x) ? toupper(x) : x) X#define abs(x) (x < 0 ? -x : x) X X/* used for damaging klingon */ X#define AUTOKILL 9999 X X/* used for fixing/damaging devices */ X#define ABS 0 /* absolute fix */ X#define REL 1 /* relative fix */ X#define RND -1 /* pick a random device */ X X/* status of a ship */ X#define ALIVE 0 /* ship is still here */ X#define DEAD 1 /* ship has been destroyed */ X X/* used for replot calls */ X#define TEXT 1 /* replot text portion */ X#define INFO 2 /* replot information portion */ X#define ELEMENT 4 /* replot individual element */ X#define ALL (TEXT | INFO) /* replot all */ X X/* legal condition values */ X#define GREEN 0 /* everything OK */ X#define YELLOW 1 /* reason to be cautious */ X#define RED 2 /* eminent danger */ X#define DOCKED 3 /* docked at base (no danger) */ X X/* legal quadrant values (used in s.r.s) */ X#define EMPTY 0 /* sector is empty */ X#define KLINGON 1 /* sector contains klingon */ X#define STARBASE 2 /* sector contains star base */ X#define STAR 3 /* sector contains star */ X#define PLAYER 4 /* sector contains player */ X#define TBLAST 5 /* torpedo */ X X/* legal damage control indices */ X#define WARP 0 /* warp drive */ X#define SRS 1 /* short range sensors */ X#define LRS 2 /* long range sensors */ X#define PHASER 3 /* phaser control */ X#define DAMAGE 4 /* damage control */ X#define DEFENSE 5 /* defense control (shields) */ X#define COMPUTER 6 /* computer (galaxy map, calculations) */ X#define TUBES 7 /* torpedo tubes */ X X/* legal status items */ X#define STARDATE 0 X#define CONDITION 1 X#define QUADRANT 2 X#define SECTOR 3 X#define ENERGY 4 X#define TORPS 5 X#define SHIELDS 6 X X/* used for readout calls */ X#define CLEAR 0 /* clear readout */ X#define ADDLINE 1 /* add line to readout */ X X/* sructure used to store quandrant information */ Xtypedef struct { X char nkling; /* number of klingons in quadrant */ X char nbase; /* number of bases in quadrant */ X char nstar; /* number of stars in quadrant */ X char known; /* tells if info is known to player */ X} QUADINFO; X X/* structure used to store klingon information */ Xstruct { X int xs, ys; /* sector coordinates */ X int sh; /* shield level */ X} klingon[3]; X XQUADINFO galaxy[8][8]; /* galaxy */ Xint numbases; /* number of bases in galaxy */ Xint numkling; /* number of klingons in galaxy */ Xint begkling; /* beginning number of klingons */ Xint condition; /* current condition (GREEN,YELLOW,RED,DOCKED) */ Xint xquad, yquad; /* current quadrant */ Xint xsect, ysect; /* current sector */ Xint old_xquad, old_yquad; /* quadrant before last movement */ Xint old_xsect, old_ysect; /* sector before last movement */ Xint energy; /* energy level */ Xint shields; /* shield level */ Xint torps; /* number of torps left */ Xint quadrant[8][8]; /* current quadrant picture (EMPTY,KLINGON,STARBASE,STAR,PLAYER) */ Xextern int rolines; /* number of lines used in current readout */ Xint damage[8]; /* % effectiveness of devices, normal range is 0-100 */ X /* if < 0 then device is damaged beyond use */ Xextern char playership[]; /* image of player's ship for s.r.s */ Xchar captain[11]; /* captain's name */ Xchar shipname[11]; /* ship's name */ Xfloat stardate; /* current star date */ Xfloat lastdate; /* last star date before federation is conquered */ Xfloat begdate; /* beginning star date */ Xint base_xsect, base_ysect; /* starbase sector, if one is present */ Xint numkmove; /* number of klingon moves allowed */ Xint skill; /* skill level */ --End_of_vtrek.h-- if test 3722 -ne `wc -c < 'vtrek.h'` then echo "`basename $0`: error in" 'vtrek.h' ": sent 3722 chars, received `wc -c < 'vtrek.h'`" 1>&2 fi fi if test -f 'main.c' then echo "`basename $0`: can't extract" 'main.c' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_main.c--' > 'main.c' X/* X * main.c X * X * visual star trek X * X * BASIC version written by Tom Goerz and debugged by Dug Patrick X * 22-Dec-79, 13-Nov-80 X * C version written by Dug Patrick X * 05-Aug-84, 11-Mar-85 X * X */ X X#include "vtrek.h" X Xchar playership[] = " ? "; Xint rolines = 0; X Xmain() X{ X int cmd, ch; X char str[44]; X X instructions(); X initvars(); X terminit(); X replot(); X X (void) sprintf(str, "You have %.1f stardates to save the", lastdate - stardate); X readout(ADDLINE, str); X readout(ADDLINE, "Federation from the Klingon invasion."); X X setcondition(); X X while (numkling > 0) { X switch (cmd = getcmd()) { X X case 'H' : /* hyper-space */ X hyperspace(); X break; X X case 'S' : /* short range scan */ X srs(); X break; X X case 'L' : /* long range scan */ X lrs(); X break; X X case 'P' : /* fire phasers */ X phasers(); X break; X X case 'T' : /* fire photon torpedo */ X torpedo(); X break; X X case 'U' : /* change shield level */ X defense(); X break; X X case 'R' : /* replot screen */ X replot(); X continue; X X case 'Q' : /* move using impulse engines */ X case 'W' : X case 'E' : X case 'A' : X case 'D' : X case 'Z' : X case 'X' : X case 'C' : X (void) impulse(cmd); X break; X X case 'K' : /* kill - commit suicide */ X prompt("Quit ? "); X refresh (); X ch = getch(); X if (Toupper(ch) == 'Y') X die(); X break; X X case 'F' : /* fix devices */ X repdevices(); X break; X X case 03 : /* exit without warning */ X case 04 : X die(); X break; X X case '?' : /* help */ X help(); X break; X X default : /* illegal command */ X readout(ADDLINE, "Type '?' for help."); X break; X } X X fixdev(REL, RND, 5); X setcondition(); X klingmove(); X X if ((stardate += 0.1) > lastdate) X timeout(); X plt_stat(ELEMENT, STARDATE); X plt_num(INFO); X X if (energy <= 0 && shields <= 0) X dead(); X } X X win(); X return (0); X} --End_of_main.c-- if test 1905 -ne `wc -c < 'main.c'` then echo "`basename $0`: error in" 'main.c' ": sent 1905 chars, received `wc -c < 'main.c'`" 1>&2 fi fi if test -f 'plot.c' then echo "`basename $0`: can't extract" 'plot.c' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_plot.c--' > 'plot.c' X/* plot.c -- plot routines for visual star trek */ X X#include "vtrek.h" X#ifdef BSD X#include <strings.h> X#else X#include <string.h> X#endif X X/* replot screen */ Xreplot() X{ X clear (); X plt_stat(ALL, 0); X plt_srs(ALL, 0, 0); X plt_dam(ALL, 0); X plt_gal(ALL, 0, 0); X mvaddstr (11, 17, "READOUT"); X mvaddstr (12, 17, "-------"); X plt_num(ALL); X} X X/* plot status (upper left) */ Xplt_stat(op, item) Xint op, item; X{ X static char *text[9] = { X " Status", " ------", "Stardate :", X "Condition :", "Quadrant :", "Sector :", X "Energy :", "Photon torps :", "Shields :" X }; X static char *ctext[4] = { X "Green", "Yellow", "Red", "Docked" X }; X int i, high, low; X X if (op & TEXT) X for (i = 0; i < 9; i++) X mvaddstr (i + 1, 0, text[i]); X X if (op & (INFO | ELEMENT)) { X if (op & INFO) { X low = STARDATE; X high = SHIELDS; X } X else { X low = item; X high = item; X } X X for (i = low; i <= high; i++) { X switch (i) { X case STARDATE : X (void) mvprintw (3, 15, "%-.1f", stardate); X break; X case CONDITION : X (void) mvprintw (4, 15, "%-6s", ctext[condition]); X break; X case QUADRANT : X (void) mvprintw (5, 15, "[%d,%d]", xquad + 1, yquad + 1); X break; X case SECTOR : X (void) mvprintw (6, 15, "[%d,%d]", xsect + 1, ysect + 1); X break; X case ENERGY : X (void) mvprintw (7, 15, "%-4d", energy); X break; X case TORPS : X (void) mvprintw (8, 15, "%-2d", torps); X break; X case SHIELDS : X (void) mvprintw (9, 15, "%-4d", shields); X break; X } X } X } X} X X/* plot short range scan */ Xplt_srs(op, xs, ys) Xint op, xs, ys; X{ X static char *htext = "-1--2--3--4--5--6--7--8-"; X static char *stext[6] = { X " ", "<K>", "<S>", " * ", "???", " + " X }; X int i, j; X X if (op & TEXT) { X mvaddstr (0, 27, htext); X for (i = 1; i < 9; i++) { X (void) mvprintw (i, 26, "%d", i); X (void) mvprintw (i, 51, "%d", i); X } X mvaddstr (9, 27, htext); X } X X (void) strcpy(stext[PLAYER], playership); X X if (op & INFO) { X for (i = 0; i < 8; i++) { X move (i + 1, 27); X for (j = 0; j < 8; j++) X (void) printw ("%s", stext[(damage[SRS] <= 0) ? EMPTY : quadrant[j][i]]); X } X } X else if (op & ELEMENT) { X (void) mvprintw (ys + 1, 27 + 3 * xs, "%s", stext[(damage[SRS] <= 0) ? EMPTY : quadrant[xs][ys]]); X } X} X X/* plot damage info */ Xplt_dam(op, item) Xint op, item; X{ X static char *text[10] = { X " Damage Report", " -------------", X "Warp engines :", "S.R. sensors :", "L.R. sensors :", X "Phaser control :", "Damage control :", "Defense control :", X "Computer :", "Photon tubes :" X }; X int i; X X if (op & TEXT) X for (i = 0; i < 10; i++) X mvaddstr (i, 55, text[i]); X X if (op & INFO) X for (i = 0; i < 8; i++) { X move (i + 2, 73); X if (damage[DAMAGE] <= 0) X (void) printw (" "); X else X (void) printw ("%4d", damage[i]); X } X else if (op & ELEMENT) { X move (item + 2, 73); X if (damage[DAMAGE] <= 0) X (void) printw (" "); X else X (void) printw ("%4d", damage[item]); X } X} X X/* plot galaxy map */ Xplt_gal(op, xq, yq) Xint op, xq, yq; X{ X static char *htext = "-1- -2- -3- -4- -5- -6- -7- -8-"; X int i, j, fedquad; X X if (op & TEXT) { X mvaddstr (12, 46, htext); X for (i = 1; i < 9; i++) { X (void) mvprintw (i + 12, 44, "%d:", i); X for (j = 0; j < 7; j++) X mvaddch (i + 12, 49 + (j << 2), ':'); X (void) mvprintw (i + 12, 77, ":%d", i); X } X mvaddstr (21, 46, htext); X } X X if (op & INFO) { X for (i = 0; i < 8; i++) X for (j = 0; j < 8; j++) { X move (i + 13, 46 + (j << 2)); X if (damage[COMPUTER] <= 0 || !galaxy[j][i].known) X (void) printw (" "); X else X (void) printw ("%01d%01d%01d", galaxy[j][i].nkling, galaxy[j][i].nbase, X galaxy[j][i].nstar); X } X mvaddch (yquad + 13, 45 + (xquad << 2), '['); X mvaddch (yquad + 13, 49 + (xquad << 2), ']'); X } X else if (op & ELEMENT) { X move (yq + 13, 45 + (xq << 2)); X fedquad = (xq == xquad && yq == yquad); X addch (fedquad ? '[' : ':'); X if (damage[COMPUTER] <= 0) X (void) printw (" "); X else X (void) printw ("%01d%01d%01d", galaxy[xq][yq].nkling, galaxy[xq][yq].nbase, galaxy[xq][yq].nstar); X addch (fedquad ? ']' : ':'); X } X} X X/* plot number of star bases & klingons */ Xplt_num(op) Xint op; X{ X float kf; X X if (op & TEXT) { X mvaddstr (22, 46, "Base stars = "); X mvaddstr (22, 62, "Klingons = "); X mvaddstr (23, 53, "Kill Factor = "); X } X X if (op & INFO) { X (void) mvprintw (22, 58, " %d", numbases); X (void) mvprintw (22, 72, " %d/%d ", numkling, begkling); X move (23, 67); X if (begdate != stardate) X kf = (begkling - numkling) / (stardate - begdate); X else X kf = 0.0; X (void) printw ("%5.3f ", kf); X } X} X X/* change readout */ Xreadout(op, str) Xint op; Xchar *str; X{ X int i, j; X X switch (op) { X X case CLEAR : /* clear readout */ X for (i = 14; i <= 13 + rolines; i++) { X move (i-1, 0); X for (j = 0; j < 44; j++) X addch (' '); X } X rolines = 0; X break; X X case ADDLINE : /* add line to readout */ X if (rolines >= 10) X readout(CLEAR, (char *) 0); X (void) mvprintw (13 + rolines, 0, "%-.44s", str); X rolines++; X break; X } X} --End_of_plot.c-- if test 5228 -ne `wc -c < 'plot.c'` then echo "`basename $0`: error in" 'plot.c' ": sent 5228 chars, received `wc -c < 'plot.c'`" 1>&2 fi fi if test -f 'sub1.c' then echo "`basename $0`: can't extract" 'sub1.c' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_sub1.c--' > 'sub1.c' X/* sub1.c -- subroutines for visual star trek */ X X#include "vtrek.h" X#ifdef BSD X#include <strings.h> X#else X#include <string.h> X#endif X X#ifndef BSD Xextern void srand (); X#endif Xextern long time (); X X/* print short help information */ Xhelp() X{ X if (rolines > 5) X readout(CLEAR, (char *) 0); X readout(ADDLINE, "Directions = Q,W,E,A,D,Z,X,C"); X readout(ADDLINE, "H = Hyper-space S = Short range scan"); X readout(ADDLINE, "L = Long range scan P = Fire phasers"); X readout(ADDLINE, "T = Fire torpedo U = Defense control"); X readout(ADDLINE, "R = Redraw screen F = Fix devices"); X} X X/* get command character */ Xgetcmd() X{ X int ch; X char str[40]; X X (void) sprintf(str, "Command %s ? ", captain); X prompt(str); X X refresh (); X ch = getch(); X X return Toupper(ch); X} X X/* give option to see instructions */ Xinstructions() X{ X FILE *fp; X char line[80]; X int n, ch; X X (void) printf("Instructions ? "); X X randomize(); X X if (fgets(line, 80, stdin) == NULL) X vexit(0); X ch = Toupper(line[0]); X if (ch == 'Y') { X if ((fp = fopen(VTREKINS, "r")) == NULL) X (void) printf("Error: Missing instruction file\n"); X else { X for (;;) { X for (n = 0; n < 22; n++) { X if (fgets(line, 80, fp) == NULL) X break; X (void) printf ("%s", line); X } X if (n < 22) { X (void) printf ("(Hit RETURN)"); X (void) getchar (); X break; X } X (void) printf ("(Hit RETURN)"); X (void) getchar (); X } X (void) fclose(fp); X } X } X} X X/* get captain's name and ship's name */ Xgetnames() X{ X int tmp; X X (void) printf("Your name captain ? "); X if (fgets(captain, 11, stdin) == NULL) X vexit(1); X if (captain[tmp = strlen(captain) - 1] == '\n') X captain[tmp] = '\0'; X else X while (getchar() != '\n'); X if (*captain == '\0') X (void) strcpy(captain, "Duncel"); X X (void) printf("Your ship's name captain ? "); X if (fgets(shipname, 11, stdin) == NULL) X vexit(1); X if (shipname[tmp = strlen(shipname) - 1] == '\n') X shipname[tmp] = '\0'; X else X while (getchar() != '\n'); X if (*shipname == '\0') X (void) strcpy(shipname, "Fruit"); X} X X/* get skill level */ Xgetskill() X{ X char level[10]; X X (void) printf("Skill level (0-5, 0=easy, 5=hard) ? "); X if (fgets(level, 10, stdin) == NULL) X vexit(1); X if (isdigit(level[0])) X skill = level[0] - '0'; X else X skill = 3; X} X X/* initialize galaxy */ Xinitgal() X{ X int i, j, k, r, n; X X numkling = 0; X X for (i = 0; i < 8; i++) { X for (j = 0; j < 8; j++) { X if ((r = rnd(100)) < 10) X k = 3; X else if (r < 20) X k = 2; X else if (r < 30) X k = 1; X else X k = 0; X numkling += k; X galaxy[i][j].nkling = k; X galaxy[i][j].nstar = rnd(8) + 1; X galaxy[i][j].nbase = 0; X galaxy[i][j].known = 0; X } X } X X numbases = rnd(3) + 2; X X for (n = 0; n < numbases; n++) { X for (;;) { X if (galaxy[i = rnd(7)][j = rnd(7)].nbase == 0) { X galaxy[i][j].nbase = 1; X break; X } X } X } X} X X/* initialize variables */ Xinitvars() X{ X int i; X X getnames(); X getskill(); X initgal(); X X numkmove = skill; X begkling = numkling; X xquad = rnd(7); X yquad = rnd(7); X old_xsect = (xsect = rnd(7)); X old_ysect = (ysect = rnd(7)); X shields = 0; X energy = 3000; X stardate = 2000.0; X begdate = stardate; X lastdate = stardate + (float)numkling; X torps = 10; X playership[1] = *shipname; X condition = YELLOW; X X for (i = 0; i < 8; i++) X damage[i] = 100; X X old_xquad = -1; X old_yquad = -1; X (void) setpos(); X} X X/* set new position -- check for outside galaxy, set up new quadrant */ Xsetpos() X{ X int dam = 0, i, j, n, status = 0; X static int notfirstcall = 0; X X if (xsect > 7) { X xsect = 0; X xquad++; X } X else if (xsect < 0) { X xsect = 7; X xquad--; X } X X if (ysect > 7) { X ysect = 0; X yquad++; X } X else if (ysect < 0) { X ysect = 7; X yquad--; X } X X if (xquad > 7) { X dam = 1; X xquad = 7; X xsect = 7; X } X else if (xquad < 0) { X dam = 1; X xquad = 0; X xsect = 0; X } X X if (yquad > 7) { X dam = 1; X yquad = 7; X ysect = 7; X } X else if (yquad < 0) { X dam = 1; X yquad = 0; X ysect = 0; X } X X if (dam) { X readout(ADDLINE, "You encounter a force field."); X shields -= rnd(20) + 90; X plt_stat(ELEMENT, SHIELDS); X status = DAMAGE; X if (shields < 0) X die(); X } X X if (xquad != old_xquad || yquad != old_yquad) { X galaxy[xquad][yquad].known = 1; X if (notfirstcall) { X plt_gal(ELEMENT, old_xquad, old_yquad); X plt_gal(ELEMENT, xquad, yquad); X } X X for (i = 0; i < 8; i++) X for (j = 0; j < 8; j++) X quadrant[i][j] = EMPTY; X X quadrant[xsect][ysect] = PLAYER; X X for (n = 0; n < galaxy[xquad][yquad].nkling; n++) { X for (;;) { X if (quadrant[i = rnd(7)][j = rnd(7)] == EMPTY) { X quadrant[i][j] = KLINGON; X break; X } X } X klingon[n].xs = i; X klingon[n].ys = j; X klingon[n].sh = 200; X } X X for (; n < 3; n++) X klingon[n].xs = klingon[n].ys = klingon[n].sh = -1; X X for (n = 0; n < galaxy[xquad][yquad].nbase; n++) X for (;;) { X if (quadrant[i = rnd(7)][j = rnd(7)] == EMPTY) { X quadrant[i][j] = STARBASE; X base_xsect = i; X base_ysect = j; X break; X } X } X X for (n = 0; n < galaxy[xquad][yquad].nstar; n++) X for (;;) { X if (quadrant[i = rnd(7)][j = rnd(7)] == EMPTY) { X quadrant[i][j] = STAR; X break; X } X } X X old_xquad = xquad; X old_yquad = yquad; X if (notfirstcall) { X plt_srs(INFO, 0, 0); X plt_stat(ELEMENT, CONDITION); X plt_stat(ELEMENT, QUADRANT); X plt_gal(ELEMENT, xquad, yquad); X } X } X else { X switch (quadrant[xsect][ysect]) { X X case KLINGON: X dam = rnd(20) + 90; X if (damkling(xsect, ysect, dam) != DEAD) { X xsect = old_xsect; X ysect = old_ysect; X } X dam >>= 1; X if ((shields -= dam) < 0) X die(); X fixdev(REL, RND, -dam); X plt_stat(ELEMENT, SHIELDS); X break; X X case STAR: X readout(ADDLINE, "There's a star in the way, Duncel!"); X if (damage[SRS] > 0) X (void) strcpy(captain, "Duncel"); X xsect = old_xsect; X ysect = old_ysect; X break; X X case STARBASE: X xsect = old_xsect; X ysect = old_ysect; X readout(ADDLINE, "There's a star base in the way!"); X break; X } X X status = quadrant[xsect][ysect]; X quadrant[old_xsect][old_ysect] = EMPTY; X quadrant[xsect][ysect] = PLAYER; X plt_srs(ELEMENT, old_xsect, old_ysect); X plt_srs(ELEMENT, xsect, ysect); X } X old_xsect = xsect; X old_ysect = ysect; X if (notfirstcall) X plt_stat(ELEMENT, SECTOR); X notfirstcall = 1; X X return status; X} X X/* "So this is it. We're going to die." -- Arthur Dent */ Xdie() X{ X char c; X X plt_stat(ELEMENT, SHIELDS); X prompt("(Press RETURN)"); X refresh (); X while ((c = getch()) != '\n' && c != '\r') X ; X erase (); X (void) mvprintw (10, 20, "Your ship the %s has been destroyed.", shipname); X mvaddstr (11, 20, "The Federation will be conquered."); X refresh (); X while ((c = getch()) != '\n' && c != '\r') X ; X vexit(0); X} X Xwin() X{ X char c; X X readout(ADDLINE, "Congratulations!"); X prompt("(Press RETURN)"); X refresh (); X while ((c = getch()) != '\n' && c != '\r') X ; X erase (); X move (10, 15); X (void) printw ("The last of the Klingon battle cruisers have been\n"); X (void) printw ("%15sdestroyed. You alone have saved the Federation. You\n", ""); X (void) printw ("%15sare promoted to Admiral %s !!!\n", "", captain); X refresh (); X while ((c = getch()) != '\n' && c != '\r') X ; X vexit(0); X} X X/* random (?) number generator */ Xrnd(max) Xint max; X{ X return (int)(rand() % max); X} X X/* randomize */ Xrandomize() X{ X#ifdef BSD X srand((int) time((long *) 0)); X#else X srand((unsigned int) time((long *) 0)); X#endif X} X X/* impulse drive -- move one sector */ Ximpulse(dir) Xint dir; X{ X int dx, dy, status; X X if (energy <= 0) { X readout(ADDLINE, "Insufficient energy for command."); X return ERROR; X } X X if (checkdir(dir, &dx, &dy) != ERROR) { X xsect += dx; X ysect += dy; X } X X energy--; X status = setpos(); X plt_stat(ELEMENT, ENERGY); X X return status; X} X X/* defense -- set shield level */ Xdefense() X{ X if (damage[DEFENSE] <= 0) X readout(ADDLINE, "Defense control is damaged."); X else { X energy += shields; X for (;;) { X prompt("Shield level ? "); X if ((shields = getnum()) >= 0 && shields <= energy) { X energy -= shields; X break; X } X } X if (shields > 0) { X playership[0] = '('; X playership[2] = ')'; X } X else { X playership[0] = ' '; X playership[2] = ' '; X } X plt_srs(ELEMENT, xsect, ysect); X plt_stat(ELEMENT, SHIELDS); X plt_stat(ELEMENT, ENERGY); X } X} X X/* get a number */ Xgetnum() X{ X int num = 0, ch; X X refresh (); X while ((ch = getch()) != '\n') { X addch (ch); X if (isdigit(ch)) X num = num * 10 + ch - '0'; X else if (ch == '\b') { X num = num / 10; X addch (' '); X addch ('\b'); X } X else X break; X refresh (); X } X X return num; X} X X/* damage a klingon */ Xdamkling(xs, ys, dam) Xint xs, ys, dam; X{ X char str[40]; X int k; X X if ((k = findkling(xs, ys)) == ERROR) X readout(ADDLINE, "damkling: error"); X else { X if (dam != AUTOKILL) { X (void) sprintf(str, "You did %d to the Klingon.", dam); X readout(ADDLINE, str); X } X X if ((klingon[k].sh -= dam) < 0) { X readout(ADDLINE, "Klingon destroyed."); X klingon[k].xs = klingon[k].ys = -1; X quadrant[xs][ys] = EMPTY; X plt_srs(ELEMENT, xs, ys); X numkling--; X plt_num(INFO); X galaxy[xquad][yquad].nkling--; X plt_gal(ELEMENT, xquad, yquad); X X return DEAD; X } X } X X return ALIVE; X} X X/* fix/damage a device */ Xfixdev(type, dev, value) Xint type; /* ABSolution fix or RELative fix */ Xint dev; /* device (if RND then pick a damaged device) */ Xint value; /* new device value for ABS, amount to add for REL */ X{ X int i, old_dam; X X if (dev == RND) { X dev = rnd(8); X if (value > 0 && damage[dev] >= 100) { X for (i = 0; i < 8; i++) { X if (++dev > 7) X dev = 0; X if (damage[dev] < 100) X break; X } X } X } X X old_dam = damage[dev]; X X if (type == ABS) X damage[dev] = value; X else X damage[dev] += value; X X if (damage[dev] > 100) X damage[dev] = 100; X X plt_dam(ELEMENT, dev); X X /* see if device changed from fixed <==> broken */ X if ((old_dam <= 0 && damage[dev] > 0) || (old_dam > 0 && damage[dev] <= 0)) { X switch (dev) { X case SRS : X plt_srs(INFO, 0, 0); X break; X case DAMAGE : X plt_dam(INFO, 0); X break; X case COMPUTER : X plt_gal(INFO, 0, 0); X break; X } X } X} X X/* print a prompt in the upper left hand corner */ Xprompt(str) Xchar *str; X{ X int i; X X move (0, 0); X for (i = 0; i < 26; i++) X addch (' '); X (void) mvprintw (0, 0, "%-.26s", str); X} X X/* check a direction for validity and return delta-x and delta-y */ Xcheckdir(dir, dx, dy) Xint dir, *dx, *dy; X{ X static struct { X int d, x, y; X } dirs[8] = { X {'Q', -1, -1}, {'W', 0, -1}, {'E', 1, -1}, {'D', 1, 0}, X {'C', 1, 1}, {'X', 0, 1}, {'Z', -1, 1}, {'A', -1, 0} X }; X int i; X X for (i = 0; i < 8; i++) X if (dirs[i].d == dir) { X *dx = dirs[i].x; X *dy = dirs[i].y; X return 0; X } X X return ERROR; X} X X/* hyperspace drive */ Xhyperspace() X{ X int dir, dx, dy, w, tmp, savex, savey; X X if (damage[WARP] <= 0) X readout(ADDLINE, "Warp engines are damaged."); X else { X prompt("Direction ? "); X refresh (); X if (islower(dir = getch())) X dir = toupper(dir); X if (checkdir(dir, &dx, &dy) == ERROR) { X readout(ADDLINE, "Illegal direction."); X return; X } X X prompt("Warp ? "); X refresh (); X addch (w = getch()); X if (isdigit(w)) { X w -= '0'; X if (w <= 0) X return; X savex = xsect; X savey = ysect; X while ((tmp = xsect + dx) >= 0 && tmp <= 7 && (tmp = ysect + dy) >= 0 && tmp <= 7) { X if (impulse(dir)) X return; X } X if (energy < 20 * w) X readout(ADDLINE, "Insufficient energy for command."); X else { X xquad += w * dx; X yquad += w * dy; X energy -= 20 * w; X stardate += (double)(w) / 5.0; X xsect = savex; X ysect = savey; X (void) setpos(); X plt_stat(ELEMENT, ENERGY); X } X } X else if (w == '.' && (refresh (), isdigit(w = getch()) )) { X addch (w); X w -= '0'; X stardate += (double)(w) / 50.0; X for (; w > 0; w--) X if (impulse(dir)) X break; X } X else X readout(ADDLINE, "Illegal warp factor."); X } X} X X/* long range scan */ Xlrs() X{ X int x, y; X char str[20]; X X if (damage[LRS] <= 0) X readout(ADDLINE, "Long range sensors are damaged."); X else { X if (rolines > 3) X readout(CLEAR, (char *) 0); X X for (y = yquad - 1; y <= yquad + 1; y++) { X readout(ADDLINE, "+---+---+---+"); X (void) strcpy(str, "|"); X for (x = xquad - 1; x <= xquad + 1; x++) { X if (x < 0 || x > 7 || y < 0 || y > 7) X (void) strcat(str, "XXX"); X else { X if (damage[COMPUTER] > 0) X galaxy[x][y].known = 1; X (void) sprintf(str + strlen(str), "%d%d%d", galaxy[x][y].nkling, X galaxy[x][y].nbase, galaxy[x][y].nstar); X plt_gal(ELEMENT, x, y); X } X (void) strcat(str, "|"); X } X str[13] = '\0'; X readout(ADDLINE, str); X } X X readout(ADDLINE, "+---+---+---+"); X plt_gal(ELEMENT, xquad, yquad); X } X} X X/* short range scan */ Xsrs() X{ X int k, dx, dy; X double dir, dist; X char str[40]; X X if (damage[SRS] <= 0) X readout(ADDLINE, "Short range sensors are damaged."); X else { X if (rolines > 6) X readout(CLEAR, (char *) 0); X readout(ADDLINE, "Sector Direction Distance"); X for (k = 0; k < 3; k++) { X if (klingon[k].sh >= 0) { X if (damage[COMPUTER] <= 0) X (void) sprintf(str, "[%d,%d]", klingon[k].xs+1, klingon[k].ys+1); X else { X dx = klingon[k].xs - xsect; X dy = klingon[k].ys - ysect; X dist = sqrt((double)(dx*dx) + (double)(dy*dy)); X if (dx) { X dir = atan2(-(double)dy, (double)dx) * 180.0 / PI; X if (dir < 0.0) X dir += 360.0; X } X else if (dy > 0) X dir = 270.0; X else X dir = 90.0; X (void) sprintf(str, "[%d,%d] %5.1f %4.1f", klingon[k].xs+1, X klingon[k].ys+1, dir, dist); X } X readout(ADDLINE, str); X } X } X } X} X Xfindkling(x, y) Xint x, y; X{ X int i; X X for (i = 0; i < 3; i++) X if (x == klingon[i].xs && y == klingon[i].ys) X return i; X X return ERROR; X} --End_of_sub1.c-- if test 14221 -ne `wc -c < 'sub1.c'` then echo "`basename $0`: error in" 'sub1.c' ": sent 14221 chars, received `wc -c < 'sub1.c'`" 1>&2 fi fi if test -f 'sub2.c' then echo "`basename $0`: can't extract" 'sub2.c' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_sub2.c--' > 'sub2.c' X/* sub2.c -- subroutines for visual star trek */ X X#include "vtrek.h" X X#ifndef BSD Xextern void exit (); X#endif X X/* klingon movement and firing */ Xklingmove() X{ X int k, dx, dy, dam, kx, ky, nx, ny, i, j; X int minj, mind, d, sk; X static int dirx[9] = {1, 1, 0, -1, -1, -1, 0, 1, 0}; X static int diry[9] = {0, 1, 1, 1, 0, -1, -1, -1, 0}; X double dist; X char str[40]; X X for (k = 0; k < 3; k++) { X if (klingon[k].sh < 0) X continue; X kx = klingon[k].xs; X ky = klingon[k].ys; X X /* movement */ X if (rnd(100) < 30 + skill * 5) { X for (i = 0; i < numkmove; i++) { X mind = 999; X minj = -1; X for (j = 0; j < 9; j++) { X nx = kx + dirx[j]; X ny = ky + diry[j]; X if (nx < 0 || nx > 7 || ny < 0 || ny > 7) X continue; X if (quadrant[nx][ny] != EMPTY) X continue; X dx = xsect - nx; X dy = ysect - ny; X d = dx * dx + dy * dy; X if (d < mind) { X mind = d; X minj = j; X } X } X X if (minj < 0) X break; X X nx = kx + dirx[minj]; X ny = ky + diry[minj]; X quadrant[kx][ky] = EMPTY; X quadrant[nx][ny] = KLINGON; X plt_srs(ELEMENT, nx, ny); X plt_srs(ELEMENT, kx, ky); X kx = nx; X ky = ny; X } X klingon[k].xs = kx; X klingon[k].ys = ky; X } X X /* fire disrupters */ X dx = kx - xsect; X dy = ky - ysect; X dist = sqrt((double)(dx * dx) + (double)(dy * dy)); X dam = (rnd(100) + 100 + skill * 20) / dist; X if (damage[SRS] > 0) X (void) sprintf(str, "Klingon at [%d,%d] hits with %d units.", kx+1, X ky+1, dam); X else X (void) sprintf(str, "Klingon hits with %d units.", dam); X readout(ADDLINE, str); X if (condition == DOCKED) X readout(ADDLINE, "Starbase shields protect you!"); X else { X if ((shields -= dam) < 0) X die(); X sk = skill * 250; X if (shields <= 500 + sk) X fixdev(REL, RND, -dam / 2); X else if (shields < 1500 + sk) X fixdev(REL, RND, -(1500 + sk - shields) * dam / 2000); X } X } X X plt_stat(ELEMENT, SHIELDS); X} X X/* fire phasers */ Xphasers() X{ X int dam, k, dx, dy, e, kx, ky; X char str[40]; X double dist; X X if (damage[PHASER] < 0) X readout(ADDLINE, "Phasers are damaged."); X else { X for (k = 0; k < 3; k++) { X if (klingon[k].sh < 0) X continue; X kx = klingon[k].xs; X ky = klingon[k].ys; X X if (damage[SRS] > 0) { X (void) sprintf(str, "Units aimed at [%d,%d] : ", kx + 1, ky + 1); X prompt(str); X } X else X prompt("Units aimed at [?,?] : "); X e = getnum(); X dx = kx - xsect; X dy = ky - ysect; X dist = sqrt((double)(dx * dx) + (double)(dy * dy)); X dam = e / dist; X X if (energy < e) X readout(ADDLINE, "Insufficient energy for command."); X else { X energy -= e; X (void) damkling(kx, ky, dam); X plt_stat(ELEMENT, ENERGY); X } X } X } X} X X/* set condition */ Xsetcondition() X{ X int dx, dy, i, oldcond; X int plotgal, plotsrs; X X oldcond = condition; X X if (galaxy[xquad][yquad].nkling) X condition = RED; X else if (shields < 100) { X condition = YELLOW; X if (oldcond != DOCKED) X readout(ADDLINE, "Captain, shields are dangerously low."); X } X else X condition = GREEN; X X if (galaxy[xquad][yquad].nbase) { X dx = xsect - base_xsect; X dy = ysect - base_ysect; X if (abs(dx) <= 1 && abs(dy) <= 1) { X condition = DOCKED; X if (oldcond != DOCKED) { X energy = 3000; X torps = 10; X shields = 0; X plotsrs = damage[SRS] <= 0; X plotgal = damage[COMPUTER] <= 0; X for (i = 0; i < 8; i++) X damage[i] = 100; X readout(ADDLINE, "Shields lowered for docking."); X playership[0] = playership[2] = ' '; X plt_srs(ELEMENT, xsect, ysect); X plt_stat(INFO, 0); X plt_dam(INFO, 0); X if (plotsrs) X plt_srs(INFO, 0, 0); X if (plotgal) X plt_gal(INFO, 0, 0); X oldcond = DOCKED; X } X } X } X X if (oldcond != condition) X plt_stat(ELEMENT, CONDITION); X} X X/* move torp to a sector and see if it hit */ Xmvtorp(x, y) Xint x, y; X{ X int ch, status = ALIVE; X char str[40]; X X ch = quadrant[x][y]; X quadrant[x][y] = TBLAST; X plt_srs(ELEMENT, x, y); X X switch (ch) { X case EMPTY : X break; X case KLINGON : X (void) damkling(x, y, AUTOKILL); X status = DEAD; X break; X case STARBASE : X readout(ADDLINE, "Starbase destroyed."); X galaxy[xquad][yquad].nbase--; X numbases--; X plt_num(INFO); X status = DEAD; X break; X case STAR : X (void) sprintf(str, "Star at [%d,%d] has gone supernova.", x + 1, y + 1); X readout(ADDLINE, str); X galaxy[xquad][yquad].nstar--; X status = DEAD; X break; X } X X if (status == DEAD) X ch = EMPTY; X quadrant[x][y] = ch; X plt_srs(ELEMENT, x, y); X X return status; X} X X/* fire a torpedo */ Xtorpedo() X{ X int dir, i, ch, x, y; X int dx, dy; X double th; X static char dirstr[] = "DEWQAZXC"; X X if (damage[TUBES] < 0) X readout(ADDLINE, "Photon torpedo tubes are damaged."); X else if (torps < 1) X readout(ADDLINE, "You're out of photon torpedos!"); X else { X torps--; X plt_stat(ELEMENT, TORPS); X prompt("Direction ? "); X refresh (); X dir = getch(); X if (isdigit(dir)) { X addch (dir); X dir -= '0'; X refresh (); X while ((ch = getch()) != '\n') { X addch (ch); X if (isdigit(ch)) X dir = dir * 10 + ch - '0'; X else X break; X refresh (); X } X } X else { X ch = Toupper(dir); X dir = 0; X for (i = 0; i < 8; i++) { X if (ch == dirstr[i]) X break; X dir += 45; X } X if (i >= 8) { X readout(ADDLINE, "Illegal direction."); X return; X } X } X X th = dir / 180.0 * PI; X if (dir >= 315 || dir <= 45 || (dir >= 135 && dir <= 225)) { X dx = (dir >= 315 || dir <= 45) ? 1 : -1; X for (x = xsect + dx; x >= 0 && x <= 7; x += dx) { X y = ysect - (x - xsect) * tan(th) + 0.5; X if (y < 0 || y > 7) X break; X if (mvtorp(x, y) == DEAD) { X break; X } X } X } X else { X th -= PI / 2.0; X dy = (dir >= 45 && dir <= 135) ? -1 : 1; X for (y = ysect + dy; y >= 0 && y <= 7; y += dy) { X x = xsect + (y - ysect) * tan(th) + 0.5; X if (x < 0 || x > 7) X break; X if (mvtorp(x, y) == DEAD) X break; X } X } X } X} X X/* repair devices somewhat */ Xrepdevices() X{ X int i; X X for (i = 0; i < 8; i++) X fixdev(REL, i, 5); X} X X/* out of star dates */ Xtimeout() X{ X char str[44]; X X readout(CLEAR, (char *) 0); X readout(ADDLINE, "You have run out of stardates an there"); X (void) sprintf(str, "are still %d Klingons left. Some captain you", numkling); X readout(ADDLINE, str); X readout(ADDLINE, "are."); X die(); X} X X/* out of energy */ Xdead() X{ X readout(CLEAR, (char *) 0); X readout(ADDLINE, "Your ship is dead in space. Eventually,"); X readout(ADDLINE, "Klingons show up and relieve you of your"); X readout(ADDLINE, "task . . ."); X die(); X} X X/* reset terminal and exit program */ Xvexit(status) X{ X termreset(); X exit(status); X} --End_of_sub2.c-- if test 6782 -ne `wc -c < 'sub2.c'` then echo "`basename $0`: error in" 'sub2.c' ": sent 6782 chars, received `wc -c < 'sub2.c'`" 1>&2 fi fi if test -f 'termio.c' then echo "`basename $0`: can't extract" 'termio.c' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_termio.c--' > 'termio.c' X/* terminal I/O */ X X#include "vtrek.h" X X/* initialize the termimal mode */ Xterminit() X{ X (void) initscr (); X#ifndef BSD X idlok (stdscr, TRUE); X#endif X scrollok (stdscr, TRUE); X#ifdef BSD X crmode (); X#else X cbreak (); X#endif X noecho (); X nonl (); X} X X/* reset the terminal mode */ Xtermreset() X{ X endwin (); X} --End_of_termio.c-- if test 311 -ne `wc -c < 'termio.c'` then echo "`basename $0`: error in" 'termio.c' ": sent 311 chars, received `wc -c < 'termio.c'`" 1>&2 fi fi if test -f 'vtrek.doc' then echo "`basename $0`: can't extract" 'vtrek.doc' "- file exists" 1>&2 else sed 's/^X//' << '--End_of_vtrek.doc--' > 'vtrek.doc' X X X X X <<< Instructions for Star Trek >>> X X The galaxy is divided into a 8 X 8 quadrant grid, and X each quadrant is further divided into a 8 X 8 sector grid. X You will be assigned a starting point somewhere in the X galaxy. Your mission : To seek out and destroy the fleet of X Klingon warships which are menacing the Federation of Planets. X X You will have the following commands available to you as X captain : X X 'D','E','W','Q','A','Z','X','C' , the keys around the X 'S' on the keyboard control your direction. When X you are asked for the direction, type one of these. X X Q W E X \ | / X \|/ X A --S-- D X /|\ X / | \ X Z X C X X 'H' , Hyper-space , used when you want to travel a X large distance. The direction is set by typing X one of the keys around the 'S'. The warp factor X can be a number from 0-8. X X 'S' , Short range scan , tells you the direction and X the distance that the Klingons are from you. X Anytime that your Short range sensors are working, X you will have a display of your quadrant on the X screen. The following symbols are used on the X display : X X <K> - Klingon X <S> - Star Base (refuel/repair/re-arm here) X * - star X ? or (?) - you (? is the 1st letter of your X ship name.) X X 'L' Long range scan. Shows conditions in space for X one quadrant on each side of you (your in the X middle of the scan). The scan prints out up to X three digits for each quadrant. The one's digit X is the number of stars, then tens digit is the X number of star bases, and the hundred's digit is X the number of Kilngons. X X EXAMPLE : 207 , 2 Klingons, 0 star bases, 7 stars X X 'P' Fire phasers. Allows you to destroy the Klingon X warships by zapping them with suitable amounts of X energy. X X 'T' Fire photon torpedo's. Torpedo course is selected X by typing one of the keys around the 'S'. If the X torpedo hits the Klingon, he will be destroyed. X X 'U' Defense control. Allows you to raise or lower your X shields. The power to your shields drops as you are X hit. If you are hit with your shields all the way X down (0), you WILL be destroyed. When your shields X up you will have paretheses around your ship. X X 'F' Fix devices. This allows you to repair damaged devices X at a faster pace than normally. X X 'R' Redraw the screen. X X Impulse power can be used by typing one of the direction X keys around the 'S'. This moves you the same distance as X Hyper-space with a warp of 0.1. X In the upper right of the screen is a damage report. If X something is damaged it will have a negative number beside it. X If an item is damaged, you won't be able to use it. X --End_of_vtrek.doc-- if test 3718 -ne `wc -c < 'vtrek.doc'` then echo "`basename $0`: error in" 'vtrek.doc' ": sent 3718 chars, received `wc -c < 'vtrek.doc'`" 1>&2 fi fi exit