20 HIMEM: 35070:ADRS = 35070: CALL ADRS: POKE 232,0: POKE 233,145: DEF FN DG(H) = (H / 360 - INT (H / 360)) * 360: DEF FN D(H) = FN DG( FN DG(H + 360)): DEF FN RD(X) = INT (X + .5): DEF FN RN(X) = INT ( RND (1) * X + 1):VA$ = CHR$ (129):VN$ = CHR$ (142):VI$ = CHR$ (137):VP$ = CHR$ (144):VY$ = CHR$ (153):VV$ = CHR$ (150):VW$ = CHR$ (151):VK$ = CHR$ (139):VL$ = CHR$ (140) 40 DEF FN RF(X) = ((3700 - X) / 3700 ^ 2.86: GOSUB 19000 # check to see if there is a viable enemy 1000 Z8 = 0: FOR Z = 1 TO 3: IF KC(Z) > 0 AND K(Z) THEN Z8 = 1 1003 NEXT Z # if our crew is all dead, and enemy is all dead, end game (can this happen?) : IF CM(0,0) < = 0 AND Z8 = 0 THEN EG = 1: PRINT : PRINT VA$4;"ALL CREWS ON ALL VESSELS ARE DEAD.": GOTO 3000 1025 IF EG = 1 THEN 2000 1027 PRINT VA$0VN$VK$ 1030 PRINT CHR$ (4);"BLOAD CHAIN,A520": CALL 520"INFO1": STOP 2000 PRINT VA$0VN$VK$: PRINT CHR$ (4);"BLOAD CHAIN,A520": CALL 520"STORE DATA": STOP 3000 PRINT VA$0VN$VK$: PRINT CHR$ (4);"BLOAD CHAIN,A520": CALL 520"BYE": STOP ### show damage assessment 19000 REM # if crew dead, skip medical report 19005 IF CM(0,0) = 0 THEN 19500 19010 GOSUB 36000: PRINT VI$VA$4VK$;" MEDICAL REPORT ";VA$0VN$: PRINT :T1 = 0:T2 = 0:X9 = 0:X = 0 # update shield energy levels based on damage received #$$ suppose we had 500 shields and were increasing them (EN=500, AL=550), and took 300 damage : FOR X1 = 1 TO 4:EN(X1) = EN(X1) - HS(X1):AL(X1) = AL(X1) - HS(X1) #$$ now EN(n) = 200, AL(n) = 250 :X2 = HS(X1) - EN(X1): IF HS(X1) - AL(X1) > X2 THEN X2 = HS(X1) - AL(X1) #$$ now X2 = 100; if (300 - 250 = 50) > 100 then use that (penalizes allocation reduction) #$$ if current/future shield setting were higher, X2 would have gone negative and become zero 19014 IF X2 < 0 THEN X2 = 0 # adjust X2 by defense crew efficiency -- high efficiency reduces X2 19017 X2 = X2 * (2 - CE(4,DT(4))): IF X2 < 20 AND HS(X1) > 50 THEN X2 = FN RN(35) # sum this "overspill" to X 19050 X = X + X2: NEXT X1: IF X = 0 THEN 19090 # set X to number of casualties, capped at 23 19070 X = INT ( FN RN(X / 20) + X / 20):Y4 = 0: IF X > 23 THEN X = 23 19090 IF X < 1 THEN PRINT "NO DEATHS OR INJURIES.": GOTO 19500 19095 W$(11) = "WEP":W$(12) = "ENG":W$(13) = "NAV":W$(14) = "DEF" 19100 W$(0) = "CR":W$(2) = "ENS":W$(3) = "LT.":W$(4) = "LT CMD":W$(5) = "CMD" # pick random start point :Y = FN RN(120):Y3 = Y: PRINT CHR$ (4);"OPEN CREW,L12" ## loop Y4 from 0 to X # Y %= 120 19210 IF Y > = 120 THEN Y = 0 # advance Y; if we wrapped around to start and didn't wound anybody (T1=X, implying T2=0), all are dead 19220 Y = Y + 1: IF Y3 = Y AND T1 = X THEN PRINT CHR$ (4);"CLOSE CREW": GOTO 29500 # if we wrapped around to start, we're done 19225 IF Y3 = Y THEN 19420 # get unadjusted efficiency in Y2; if already dead, continue 19240 Y2 = PEEK (7788 + Y * 2): IF Y2 = < 100 THEN 19210 # X2 is damage to crewmember; subtract it from unadjusted efficiency 19260 X2 = FN RN(120):Y2 = Y2 - X2 # if crewmember efficiency is still positive, and wounding was serious, and efficiency is now < 50%, list as injured : IF Y2 > 100 AND X2 > 20 AND Y2 < = 150 THEN Z$ = "INJURED- " # increase wounded count :T2 = T2 + 1 # if crewmember efficiency remains > 50%, or damage is light and crewmember efficiency is positive, quietly store efficiency and continue 19266 IF Y2 > 150 OR (X2 < = 20 AND Y2 > 100) THEN POKE 7788 + Y * 2,Y2:Y4 = Y4 + 1: GOTO 19410 # if efficiency drops to zero, the crewmember dies 19270 IF Y2 < = 100 THEN Y2 = 0:Z$ = "KILLED - ":T1 = T1 + 1 19280 POKE 7788 + Y * 2,Y2:Y4 = Y4 + 1:Y5 = PEEK (7788 + Y * 2 + 1) # read name and rank (Z1$, W1) : PRINT CHR$ (4);"READ CREW,R";Y5: INPUT Z1$,W1: SPEED= 125: PRINT Z$;W$(W1);" ";Z1$;: GOSUB 38000: SPEED= 255: IF Y2 > 100 THEN 19410 # reduce crew efficiency multiplier and crewmember count # X3 is station index, X4 is team index 19340 X3 = INT (((Y - 1) / 30)) + 1:X4 = INT (((Y - 1) / 10)) + 1:X4 = X4 - (X3 - 1) * 3: IF W1 = 0 THEN W1 = 1 19380 W1 = W1 + 2:CO(X3,X4) = CO(X3,X4) - W1:CM(X3,X4) = CM(X3,X4) - 1 19410 IF Y4 < X THEN 19210 # (end of Y4 loop) 19420 PRINT CHR$ (4);"CLOSE CREW": SPEED= 125: PRINT : PRINT VA$4;"TOTAL CREWPERSONS INJURED: ";T2: PRINT "TOTAL CREWPERSONS KILLED : ";T1: PRINT # update total dead crew; if everybody dead, display that 19430 CM(0,0) = CM(0,0) - T1: IF CM(0,0) < 0 THEN 29500 # # medical done; on to equipment damage report # T2 tracks number of droids destroyed -- damaged systems lose all repair droids 19500 PRINT VI$VA$4: SPEED= 145: PRINT " DAMAGE REPORT "VN$VA$0;: PRINT : PRINT ## compute damage to shield 1 (in Z) :X = 1: GOSUB 40000:T2 = 0: IF Z < 40 THEN 19600 # 35% chance of positron 1 damage (1-15 points) 19530 IF RND (1) > .65 THEN D(6) = 1:RP(6) = RP(6) + FN RN(15):EN(6) = 0:AL(6) = 0: PRINT "POSITRON 1 IS DAMAGED.":T2 = RT(6) + T2:RT(6) = 0 # 60% chance of torpedo tube damage (1-4 tubes damaged, 1-15 points of damage); tubes are unloaded 19535 IF RND (1) < .4 THEN 19570 19540 T2 = RT(5) + T2:RT(5) = 0:D(5) = D(5) + FN RN(4): IF D(5) > 6 THEN D(5) = 6 19545 RP(5) = RP(5) + FN RN(15): FOR X1 = 6 TO 6 - DM(5):LP(X1) = 0: NEXT X1: PRINT "TORPEDO TUBES ARE DAMAGED." # chance of shield 1 damage: 30% for 100-300, 100% for 300+; 1-15 points 19570 IF (Z > 100 AND Z < = 300 AND RND (1) < .3) OR Z > 300 THEN D(1) = 1:RP(1) = FN RN(15) + RP(1): PRINT "SHIELD 1 IS DAMAGED.":EN(1) = 0:AL(1) = 0:AS(1) = 0:T2 = T2 + RT(1):RT(1) = 0 ## compute damage to shield 2 (in Z) 19600 X = 2: GOSUB 40000: IF Z < 40 THEN 19700 # 35% chance of positron 2 damage 19610 IF RND (1) > .65 THEN D(7) = 1:RP(7) = RP(7) + FN RN(15):EN(7) = 0:AL(7) = 0: PRINT "POSITRON 2 IS DAMAGED.":T2 = T2 + RT(7):RT(7) = 0 # 70% chance of damage to port light engine for 100+ damage 19615 IF RND (1) < .3 OR Z < 100 THEN 19670 # update D(11) bit vector 19620 IF D(11) = 2 THEN D(11) = 3: GOTO 19630 19625 IF D(11) < > 3 THEN D(11) = 1 # update power based on whether this is the first engine damaged 19630 RP(11) = RP(11) + FN RN(20): IF D(11) = 3 THEN EN(11) = 0:AL(11) = 0 19635 T2 = T2 + RT(11):RT(11) = 0: IF D(11) = 1 THEN EN(11) = EN(11) / 2:AL(11) = AL(11) / 2 19650 PRINT "PORT ENGINE IS DAMAGED." # 30% chance of damage to shield for 300+ damage 19670 IF Z < 300 OR RND (1) < .7 THEN 19700 19675 DM(2) = 1:RP(2) = RP(2) + FN RN(20):EN(2) = 0:AL(2) = 0: PRINT "SHIELD 2 IS DAMAGED":AS(2) = 0:T2 = T2 + RT(2):RT(2) = 0 ## compute damage to shield 3 (in Z) 19700 X = 3: GOSUB 40000: IF Z < 40 THEN 19800 19720 T2 = T2 + RT(7):RT(7) = 0: IF RND (1) < .3 OR Z < 100 THEN 19770 19728 IF D(11) = 1 THEN D(11) = 3: GOTO 19735 19730 IF D(11) < > 3 THEN D(11) = 2 19735 RP(12) = RP(12) + FN RN(20): IF D(11) = 3 THEN EN(11) = 0:AL(11) = 0 19745 IF D(11) = 2 THEN EN(11) = EN(11) / 2:AL(11) = AL(11) / 2 19750 PRINT "STARBOARD ENGINE IS DAMAGED.":T2 = T2 + RT(12):RT(12) = 0 # 30% chance of damage to shield for 300+ damage 19770 IF Z < 300 OR RND (1) < .7 THEN 19800 19775 D(3) = 1:RP(3) = RP(3) + FN RN(20):EN(3) = 0:AL(3) = 0:AS(3) = 0: PRINT "SHIELD 3 IS DAMAGED.":T2 = T2 + RT(3):RT(3) = 0 ## compute damage to shield 4 (in Z) 19800 X = 4: GOSUB 40000: IF Z < 40 THEN 19900 # 35% chance of damage to positron 4 19820 IF RND (1) > .65 THEN D(9) = 1:RP(9) = RP(9) + FN RN(15):EN(9) = 0:AL(9) = 0: PRINT "POSITRON 4 IS DAMAGED.":T2 = T2 + RT(9):RT(9) = 0 # 30% chance of ion engine damage for 100+ damage 19830 IF RND (1) < .7 OR Z < 100 THEN 19850 19840 D(10) = 1:RP(10) = RP(10) + FN RN(15):EN(10) = 0:AL(10) = 0: PRINT "ION ENGINES ARE DAMAGED.":T2 = RT(10) + T2:RT(10) = 0 # 30% chance of damage to shield for 300+ damage 19850 IF Z > 300 AND RND (1) < .3 THEN D(4) = 1:EN(4) = 0:AL(4) = 0: PRINT "SHIELD 4 IS DAMAGED.":AS(4) = 0:RP(4) = RP(4) + FN RN(15):T2 = RT(4) + T2:RT(4) = 0 19860 IF Z > 0 AND CA > 0 AND RND (1) < .5 THEN T2 = T2 + 1:CA = CA - 1 19900 IF T2 > 0 THEN PRINT T2;" DROIDS DESTROYED." 19910 PRINT "NO FURTHER DAMAGE.": SPEED= 255: RETURN 29500 PRINT "ALL CREWMEMBERS ARE KILLED.":CM(0,0) = 0: GOTO 19500 29600 STOP 35000 PRINT VN$;VY$: VTAB (19): HTAB (39): PRINT VW$;: VTAB (2): HTAB (2): PRINT VV$;: RETURN 36000 GOSUB 35000: PRINT VP$;: RETURN ### given crewmember index Y, compute station name (Z2) and team number (Z3) 38000 Z2 = INT ((Y - 1) / 30) + 1:Z3 = INT (((Y - (Z2 - 1) * 30) - 1) / 10) + 1 38010 PRINT TAB( 28);W$(10 + Z2);"-TEAM "Z3 38020 RETURN ### compute equipment damage based on damage done to shield X # reduces shield efficiency based on damage received # "returns" Z # Z2 is raw damage increased by def team inefficiency and shield inefficiency # (90% and 90% yields dam * 1.1 * 1.1 == +21%) 40000 Z2 = HS(X) * (2 - CE(4,DT(4))) * (2 - E(X)) # Z and Z1 examine damage vs. current/allocated remaining shield (again, penalizes allocation reduction) # because "TARGET" reduced EN/AL, we're comparing against the "over-allocation" :Z = Z2 - EN(X):Z1 = Z2 - AL(X): IF Z1 > Z THEN Z = Z1 # Y6 is based on raw damage; 500 damage = 0.2 40003 Y6 = 0: IF HS(X) > 50 THEN Y6 = HS(X) / 2500 # cap at 0.09 40004 IF Y6 > .09 THEN Y6 = .09 # reduce efficiency of that shield 40005 E(X) = E(X) - Y6: IF E(X) < = .05 THEN E(X) = RND (1) / 20 40010 RETURN