2 DIM D(7),K(2,2),S(7,7),Q(7,7)
3 DIM A$[20]V,G$[126]V,D$[92]V,S$[40]V
90 DEF FND(D)=SQR((K(I,0)-S1)^2+(K(I,1)-S2)^2)
100 GOSUB 5100 : GOTO 500
200 FOR I=S1-1TOS1+1: FOR J=S2-1TOS2+1: IF I<0ORI>7ORJ<0ORJ>7THEN208
204 IF S(I,J)=4THEN210
208 NEXT J: NEXT I : GOTO 220
210C$="DOCKED":E=3000:P=10
212 PRINT "SHIELDS DROPPED FOR DOCKING PURPOSES":S8=0: GOTO 300
220 IF K3>0THENC$="RED": GOTO 300
222 IF E<300THENC$="YELLOW": GOTO 300
224C$="GREEN"
300 IF D(1)>0THEN PRINT "*** SHORT RANGE SENSORS ARE OUT ***": RETURN 
310 PRINT STRING$("-",33)
320 FOR I=0TO7: S$=SPACE$(32): FOR J=0TO7
330 S=S(I,J): IF S<>1 THEN CALL "INSTRG"(S$,MID(Q$,(S-1)*3+1,3),J*4+1)
332 NEXT J: PRINT S$;TAB(35);
335 ON I+1 GOTO 341,342,343,344,345,346,347,348
341 PRINT " " : GOTO 350
342 PRINT "STARDATE";TAB(54);T : GOTO 350
343 PRINT "CONDITION";TAB(55);C$ : GOTO 350
344 PRINT "QUADRANT";TAB(54);Q1+1;"-";Q2+1 : GOTO 350
345 PRINT "SECTOR";TAB(54);S1+1;"-";S2+1 : GOTO 350
346 PRINT "ENERGY";TAB(54);E : GOTO 350
347 PRINT "PHOTON TORPEDOES";TAB(54);P : GOTO 350
348 PRINT "SHIELDS";TAB(54);S8 : GOTO 350
350 NEXT I: PRINT STRING$("-",33): RETURN 
500K3=0:B3=0:S3=0: GOSUB 4400: IF T<>T0THEN530
522 PRINT "YOUR MISSION BEGINS WITH YOUR STARSHIP LOCATED"
524 PRINT "IN THE GALACTIC QUADRANT, ";S$: GOTO 540
530 PRINT "NOW ENTERING ";S$;" QUADRANT..."
540 Q(Q1,Q2)=ABS(Q(Q1,Q2)):N=Q(Q1,Q2):X=N*.01
550 K3=INT(X):B3=INT((X-K3)*10):S3=N-INT(N*.1)*10
570 IF S8<200THEN PRINT "   SHIELDS DANGEROUSLY LOW"
590 FOR I=0TO7: FOR J=0TO7:S(I,J)=1:K(INT(I/3),INT(J/3))=0: NEXT J: NEXT I
600 GOSUB 4200:S1=Y2:S2=X2:S(Y2,X2)=2: IF K3=0THEN800
700 FOR I=0TOK3-1: GOSUB 4100:S(Y2,X2)=3:K(I,0)=Y2:K(I,1)=X2:K(I,2)=200
710 NEXT I
800 IF B3<>0THEN FOR I=1TOB3: GOSUB 4100:S(Y2,X2)=4:B7=Y2:B8=X2: NEXT I
900 FOR I=1TOS3: GOSUB 4100:S(Y2,X2)=5: NEXT I
990 GOSUB 200
1000 IF S8+E>10AND(E>10ORD(6)=0)THEN1100
1010 PRINT "** FATAL ERROR **  YOU'VE JUST STRANDED YOUR SHIP IN SPACE!!"
1020 PRINT "YOU HAVE INSUFFICIENT MANEUVERING ENERGY, AND SHIELD CONTROL"
1030 PRINT "IS PRESENTLY INCAPABLE OF CROSS-CIRCUITING TO ENGINE ROOM!"
1040 GOTO 2300
1100 INPUT "COMMAND",S$
1110 I=(POS(A$,LEFT(S$,2))+1)/2 : IF I > .5 AND I < 10 THEN 1150
1120 PRINT "SCIENCE OFFICER SPOCK REPORTS:"
1122 PRINT "'THAT'S TOTALLY ILLOGICAL, CAPTAIN!'": GOTO 1000
1150 ON I GOTO 1200,990,1700,1800,1900,2000,2100,2800,2300
1200 PRINT "COURSE (1-8.9)";: INPUT C: IF C >= 1 AND C < 9 THEN 1230
1210 PRINT "LT. SULU REPORTS, 'INCORRECT COURSE DATA, SIR!'": GOTO 1000
1230 PRINT "WARP (0-12)";: INPUT W: IF W > 0 AND W <= 12 THEN 1250
1240 PRINT "CHIEF ENGINEER SCOTT REPORTS, 'THE ENGINES WON'T";
1242 PRINT " TAKE WARP";W;"'": GOTO 1200
1250 IF D(0)=0ORW<=.2THEN1270
1260 PRINT "WARP ENGINES ARE DAMAGED, MAXIMUM SPEED = WARP 0.2": GOTO 1200
1270N=INT(W*8+.5): IF E-N>=0THEN1300
1272 PRINT "ENGINEERING REPORTS,": PRINT "INSUFFICIENT ENERGY AVAILABLE ";
1274 PRINT "FOR MANEUVERING AT WARP";W;"!'": IF S<N-EORD(6)>0THEN1000
1280 PRINT "DEFLECTOR CONTROL ROOM ACKNOWLEDGES,"
1300 IF K3<=0THEN1500
1310 FOR I=0TO2: IF K(I,2)>0THENS(K(I,0),K(I,1))=1: GOSUB 4100:S(Y2,X2)=3
1320K(I,0)=Y2:K(I,1)=X2: NEXT I
1400 GOSUB 2200
1500J=-1: GOSUB 4500: IF RND(1)>.2THEN1600
1510 IF RND(1)<.6THENJ=1
1520 GOSUB 4510
1600 S(S1,S2)=1:Y1=S1+.5:X1=S2+.5:N=INT(W*8)
1602 FOR I=1TON: GOSUB 4300: IF J=0THEN1650
1604 IF S(Y2,X2)=1THEN NEXT I:S1=Y2:S2=X2: GOTO 1620
1610S1=INT(Y1-Y):S2=INT(X1-X): PRINT "WARP ENGINES SHUT DOWN AT SECTOR";
1615 PRINT S1+1;"-";S2+1;"DUE TO BAD NAVIGATION."
1620 S(S1,S2)=2: GOSUB 4000: GOTO 990
1650 X1=Q1:X2=Q2:Q1=INT(Q1+W*Y+(S1+.5)/8):Q2=INT(Q2+W*X+(S2+.5)/8):N=0
1660 IF Q1<0ORQ1>7THENN=1:Q1=Q1-(SGN(Q1)+SGN(Q1-7))/2:S1=Q1: GOTO 1660
1662 IF Q2<0ORQ2>7THENN=1:Q2=Q2-(SGN(Q2)+SGN(Q2-7))/2:S2=Q2: GOTO 1662
1670 IF N=0THEN1695
1680 PRINT "LT. UHURA REPORTS MESSAGE FROM STARFLEET COMMAND:"
1682 PRINT "'PERMISSION TO ATTEMPT CROSSING OF GALACTIC PERIMETER"
1684 PRINT "IS HEREBY *DENIED*.  SHUT DOWN YOUR ENGINES.'"
1690 IF X1=Q1ANDX2=Q2THEN1620
1695 GOSUB 4000: GOTO 500
1700 IF D(2)>0THEN PRINT "LONG RANGE SENSORS ARE INOPERABLE": GOTO 1000
1710 PRINT "LONG RANGE SENSOR SCAN FOR QUADRANT";Q1+1;"-";Q2+1
1720 FOR I=Q1-1TOQ1+1: FOR J=Q2-1TOQ2+1: PRINT "   ";
1730 IF I<0ORI>7ORJ<0ORJ>7THEN PRINT "***";: GOTO 1760
1740 PRINT RJS$(STR$(ABS(Q(I,J))),3);
1750 IF D(7)=0THENQ(I,J)=ABS(Q(I,J))
1760 NEXT J: PRINT : NEXT I: GOTO 1000
1800 IF K3>0THEN1805
1802 PRINT "SCIENCE OFFICER SPOCK REPORTS,"
1804 PRINT "'SENSORS SHOW NO ENEMY SHIPS IN THIS QUADRANT.'": GOTO 1000
1805 IF D(3)>0THEN PRINT "PHASERS INOPERATIVE": GOTO 1000
1806 IF D(7)>0THEN PRINT "COMPUTER FAILURE HAMPERS ACCURACY."
1810 PRINT "PHASERS LOCKED ON TARGET, ENERGY AVAILABLE=";E
1812 INPUT "NUMBER OF UNITS TO FIRE",W:IF W<=0THEN1000
1814 IF E-W<0THEN1810
1820E=E-W: GOSUB 2200: IF D(7)>0THENW=W*RND(1)
1830 FOR I=0TO2: IF K(I,2)<=0THEN1890
1832H=INT(W/K3):H=INT((W/FND(0))*(RND(1)+2)): IF H>.15*K(I,2)THEN1840
1835 ? "SENSORS SHOW 0 DAMAGE TO ENEMY AT";K(I,0)+1;"-";K(I,1)+1: GOTO 1890
1840K(I,2)=K(I,2)-H
1842 PRINT H;"UNIT HIT ON KLINGON AT SECTOR";K(I,0)+1;"-";K(I,1)+1
1845 IF K(I,2)>0THEN PRINT "  (";K(I,2);"UNITS REMAINING)": GOTO 1890
1860 GOSUB 4600
1890 NEXT I: GOTO 1000
1900 IF D(4)>0THEN PRINT "PHOTON TUBES ARE NOT OPERATIONAL": GOTO 1000
1902 IF P=0THEN PRINT "ALL PHOTON TORPEDOES EXPENDED": GOTO 1000
1905 PRINT "TORPEDO COURSE (1-8.9)";: INPUT C: IF C>=1 AND C<9 THEN 1910
1907 PRINT "ENSIGN CHEKOV REPORTS, 'INCORRECT COURSE DATA, SIR!'": GOTO 1000
1910P=P-1: PRINT "TORPEDO TRACK:":Y1=S1+.5:X1=S2+.5
1912 GOSUB 4300: IF J=0THEN PRINT "TORPEDO MISSED": GOTO 1990
1915 PRINT TAB(15);Y2+1;"-";X2+1
1917 ON S(Y2,X2) GOTO 1912,0,1920,1942,1950
1920 FOR I=0TO2: IF INT(Y2)<>K(I,0)ORINT(X2)<>K(I,1)THEN NEXT I
1930 GOSUB 4600: GOTO 1990
1942 PRINT "*** STAR BASE DESTROYED ***":B3=B3-1:B9=B9-1: GOSUB 4700
1944 IF B3>0THEN1990
1945 PRINT "THAT DOES IT CAPTAIN!! YOU ARE HEREBY RELIEVED OF COMMAND"
1946 GOTO 2300
1950 IF S(Y2,X2)=5THEN PRINT "STAR AT";Y2+1;"-";X2+1;"ABSORBED TORPEDO ENERGY."
1960 S3=S3-1: GOSUB 4700
1990 GOSUB 2200: GOTO 1000
2000 IF D(6)>0THEN PRINT "SHIELD CONTROL IS NON-OPERATIONAL": GOTO 1000
2010 PRINT "ENERGY AVAILABLE =";E+S;
2020 INPUT "NUMBER OF UNITS TO SHIELDS:",N
2022 IF N > 0 AND S8 <> N THEN 2030
2025 PRINT "SHIELDS UNCHANGED": GOTO 1000
2030 IF E+S8-N<0THEN2010
2050E=E+S8-N:S8=N: PRINT "DEFLECTOR CONTROL ROOM REPORT:"
2060 PRINT "'SHIELDS NOW AT";S8;"PER YOUR COMMAND'": GOTO 1000
2100 IF D(5)>0THEN PRINT "DAMAGE CONTROL REPORT IS NOT AVAILABLE": GOTO 1000
2110N=0: FOR I=0TO7: IF D(I)>0THENN=N+.1
2120 NEXT I: IF N=0ORC$<>"DOCKED"THEN2190
2150N=N+.5*RND(1): IF N>=1THENN=.9
2160 PRINT "TECHNICIANS STANDING BY TO EFFECT REPAIRS TO YOUR SHIP;"
2162 PRINT "ESTIMATED TIME TO REPAIR: ";N;"STARDATES."
2163 INPUT "WILL YOU AUTHORIZE THE REPAIRS",S$
2165 IF LEFT(S$,1)<>"Y"THEN1000
2170T=T+N+.1:J=-100: GOSUB 4500: GOTO 1000
2190 PRINT : PRINT "DEVICE";TAB(14);"STATE OF REPAIR"
2195J=0: GOSUB 4500: PRINT : GOTO 1000
2200 IF K3<=0THEN RETURN 
2210 IF C$="DOCKED"THEN PRINT "STAR BASE SHIELDS THE ENTERPRISE": RETURN 
2220 FOR I=0TO2: IF K(I,2)<=0THEN2290
2230H=FND(0):H=INT(K(I,2)/H):H=H*(2+RND(1)):S8=S8-H
2240 PRINT H;"UNIT HIT ON ENTERPRISE FROM SECTOR";K(I,0)+1;"-";K(I,1)+1
2250 IF S8<0THEN2400
2260 PRINT "  (SHIELDS DOWN TO";S8;"UNITS.)"
2270 IF H<20ORRND(1)>.6ORH/S8<.02THEN2290
2280J=H/S8+.5*RND(1): GOSUB 4510
2290 NEXT I: RETURN 
2300 PRINT "IT IS STARDATE";T: GOTO 2450
2400 PRINT "THE ENTERPRISE HAS BEEN DESTROYED.  THE FEDERATION"
2410 PRINT "WILL BE CONQUERED."
2450 ? "THERE WERE";K9;"BATTLE CRUISERS LEFT AT THE END OF YOUR MISSION."
2495 END 
2500 PRINT "CONGRATULATIONS, CAPTAIN!  THE LAST KLINGON BATTLE CRUISER"
2510 PRINT "MENACING THE FEDERATION HAS BEEN DESTROYED."
2520 PRINT "YOUR RATING IS";INT(K0/(T-T0)*1000): GOTO 2495
2800J=0: IF D(7)>0THEN PRINT "COMPUTER DISABLED": GOTO 1000
2810 INPUT "COMPUTER ACTIVE AND AWAITING COMMAND:",N
2820 ON N GOTO 2900,3000,3100,3200,3300
2830 PRINT "LIBRARY COMPUTER REPORTS:"
2835 PRINT "'I DON'T UNDERSTAND, SIR!'": GOTO 1000
2900 PRINT "COMPUTER RECORD OF GALAXY FOR QUADRANT ";Q1+1;"-";Q2+1
2910 FOR I=0TO7: FOR J=0TO7: PRINT "  ";: IF Q(I,J)<0THEN PRINT "***";: GOTO 2950
2930 PRINT RJS$(STR$(Q(I,J)),3);
2950 NEXT J: PRINT : NEXT I: GOTO 1000
3000 PRINT "  STATUS REPORT": PRINT K9;"KLINGONS LEFT"
3010 PRINT T0+30-T;"STARDATES LEFT": PRINT B9;"STARBASES LEFT": GOTO 2100
3100 PRINT :J=1: FOR I=0TO2: IF K(I,2)<=0THEN3399
3110 Y1=S1:X1=S2:Y2=K(I,0):X2=K(I,1): GOTO 3320
3200 Y1=S1:X1=S2:Y2=B7:X2=B8: IF B3 > 0 THEN 3320
3210 ? "MR. SPOCK REPORTS, 'SENSORS SHOW NO STARBASES IN THIS QUADRANT'"
3220 GOTO 1000
3300 INPUT "INITIAL COORDINATES",Y1,X1
3310 INPUT "FINAL COORDINATES",Y2,X2
3320Y2=Y1-Y2:X2=X2-X1:N=0:C=7: IF X2<0THENC=5: GOTO 3380
3330 IF X2>0ANDY2>=0THENC=1: GOTO 3380
3340 IF X2>0THENC=9: GOTO 3380
3350 IF Y2>0THENC=3
3380 IF Y2<>0ANDX2<>0THENN=1.27324*ATN(Y2/X2)
3390 PRINT "DIRECTION =";C+N
3395 PRINT "DISTANCE =";SQR(Y2^2+X2^2): IF J=0THEN1000
3399 NEXT I: GOTO 1000
4000E=E-INT(W*8+.5)-10:J=1: IF E>=0THEN4050
4010 PRINT "SHIELD CONTROL SUPPLIED ENERGY TO COMPLETE THE MANEUVER."
4020 S8=S8+E:E=0: IF S8<=0THENS8=0
4050 IF W<1THENJ=.1*INT(10*W)
4060T=T+J: IF T>T0+30THEN2300
4090 RETURN 
4100 GOSUB 4200: IF S(Y2,X2)<>1THEN4100
4110 RETURN 
4200Y2=INT(RND(1)*8):X2=INT(RND(1)*8): RETURN 
4300J=1:Y=(C-1)*.785398:X=COS(Y):Y=-SIN(Y)
4310Y1=Y1+Y:X1=X1+X:Y2=INT(Y1):X2=INT(X1)
4320 IF X2<0ORX2>7ORY2<0ORY2>7THENJ=0
4330 RETURN 
4400 J=Q1*2+1 : IF Q2 > 3 THEN J=J+1
4410 S$=PIECE$(G$," ",J)
4450 N=Q2*3+1 : IF Q2 > 3 THEN N=N-12
4455 S$=S$+" "+MID(H$,N,3) : RETURN 
4500 FOR X=0TO7:N=X: GOTO 4520
4510N=INT(RND(1)*8):X=7
4520 IF J=0THEN PRINT MID(D$,N*12+1,11),D(N): GOTO 4590
4530Y=D(N):D(N)=Y+J: IF D(N)<0THEND(N)=0
4540 IF (J>0ANDY>0)OR(J<0ANDY=0)THEN4590
4550 PRINT "DAMAGE CONTROL REPORT:";: PRINT "  ";MID(D$,N*12+1,11);" ";
4560 IF J>0THEN PRINT "DAMAGED": GOTO 4590
4570 IF D(N)=0THEN PRINT "REPAIR COMPLETED": GOTO 4590
4580 PRINT "STATE OF REPAIR IMPROVED"
4590 IF X <> 7 THEN NEXT X
4595 RETURN 
4600 PRINT "*** KLINGON DESTROYED ***":K3=K3-1:K9=K9-1:Y2=K(I,0):X2=K(I,1)
4610K(I,2)=0: IF K9<1THEN2500
4700N=SGN(Q(Q1,Q2)):Q(Q1,Q2)=N*(K3*100+B3*10+S3):S(Y2,X2)=1
4710 RETURN 
5100 PRINT TAB(21);"* * * STAR TREK * * *"
5105 RANDOMIZE 
5110 ? : ? : ? :T0=INT(RND(1)*20+20)*100:T=T0:E=3000:P=10:S8=0:S9=200
5150 GOSUB 4200:Q2=Y2:Q1=X2: GOSUB 4200:S2=Y2:S1=X2: FOR I=0TO7:D(I)=0: NEXT I
5200Q$="   <*>+++>!< * ":A$="NASRLRPHTOSHDACORE":H$="I  II IIIIV "
5220D$="WARP ENGINESS.R. SENSORSL.R. SENSORSPHASER CNTRL"
5225D$=D$+"PHOTON TUBESDAMAGE CNTRLSHIELD CNTRLCOMPUTER"
5250G$="ANTARES SIRIUS RIGEL DENEB PROCYON CAPELLA VEGA "
5255G$=G$+"BETELGEUSE CANOPUS ALDEBARAN ALTAIR REGULUS "
5260G$=G$+"SAGITTARIUS ARCTURUS POLLUX SPICA "
5300 B9=0:K9=0
5310 FOR I=0 TO 7 : FOR J=0 TO 7
5320 N=RND(1) : K3=0
5325 IF N>.8 THEN K3=K3+1
5330 IF N >.95 THEN K3=K3+1
5335 IF N >.98 THEN K3=K3+1
5350K9=K9+K3:B3=0:N=RND(1): IF N>.96THENB3=1:B9=B9+1
5380S3=INT(RND(1)*8+1):Q(I,J)=-(K3*100+B3*10+S3)
5390 NEXT J: NEXT I
5395 IF B9=0 THEN Q(5,2)=-114 : B9=1 : K9=K9+1
5400K0=K9: PRINT "YOUR ORDERS ARE AS FOLLOWS:": PRINT 
5410 PRINT "  DESTROY THE";K9;"KLINGON WARSHIPS WHICH HAVE INVADED"
5420 PRINT "  THE GALAXY BEFORE THEY CAN ATTACK FEDERATION HEADQUARTERS"
5430 PRINT "  ON STARDATE";T0+30;"; THIS GIVES YOU 30 DAYS. THERE ARE"
5440 PRINT " ";B9;"STARBASES IN THE GALAXY FOR RESUPPLYING YOUR SHIP."
5450 RETURN
