trek: proc; /* files */ declare (sysin, sysprint) file; /* conditions */ declare error condition; /* automatic */ declare (count, count_one, col_coordinate, row_coordinate, klingon init (1), star_base init (2), star init (3), initial_klingons, local_klingons, local_starbases, local_stars, row_sector, col_sector, row_random, initial_energy, col_random, row_quadrant, col_quadrant, col_starbase, row_starbase, nova_col_quadrant, nova_row_quadrant, temp_row_sector, temp_col_sector, number_sectors, total_klingons, temp_row_quadrant, temp_col_quadrant, row_torpedo_track, col_torpedo_track, column, total_starbases, computer_command, record (3), galaxy (8, 8, 3), computer_record (8, 8, 3), klingon_location (3, 4)) fixed binary; declare (energy, initial_stardate, length_of_game, repair_time, stardate, photon_torpedo, float_row_torpedo_track, float_col_torpedo_track, row_increment, col_increment, course, dilation, warp, klingon_hit_energy, row, phaser_energy, distribute_phaser_energy, hit_phaser_energy, torpedo_course, shields, shield_energy, klingon_shield, float_col_sector, float_row_sector, repair, direction, device (8)) float binary (27); /* internal static */ declare quadrant_names (16) character (11) varying static init ("ANTARES", "SIRIUS", "RIGIL", "DENEB", "PROCYON", "CAPELLA", "VEGA", "BETELGUESE", "CANOPUS", "ALDEBRAN", "ALTAIR", "REGULUS", "SAGITTARIUS", "ARCTURUS", "POLLUX", "SPICA"); declare device_name (8) character (20) varying static init ( "warp engines", "short range sensors", "long range sensors", "phaser control", "photon tubes", "damage control", "shield control", "computer"); /* builtins */ declare (time, abs, binary, sqrt, substr, sin, cos, length, unspec, atan) builtin; declare (rando, random, disturbance) float decimal (8); declare rand character (4), quadrant (8, 8) character (3), line (8) character (60) varying, output_quadrant_name character (20) varying, name_suffix character (4) varying, condition_code character (6) varying, answer character (3) varying, command character (3) varying, galaxy_line character (49) init (" ----- ----- ----- ----- ----- ----- ----- -----"); declare fixed_switch bit (1), map_switch bit (1), run bit (1) init ("1"b), exceed_switch bit (1), collision_switch bit (1), first_time bit (1) init ("1"b), docked_code bit (1), docked bit (1) init ("1"b), not_docked bit (1) init ("0"b), game_switch bit (1) init ("1"b), run_switch bit (1), onn bit (1) init ("1"b), off bit (1) init ("0"b); declare static_number fixed binary (35) init (100000000000b); declare pi_over_four fixed decimal (12, 10) init (0.785398164); declare (one init (1b), two init (10b), three init (11b), four init (100b), five init (101b), six init (110b), seven init (111b), eight init (1000b), nine init (1001b), ten init (1010b)) fixed binary (31); /* program */ on error begin; put edit ("*** PROGRAM ERROR HAS OCCURED ***", "THE GAME WILL RESUME IN COMMAND CONTROL") ((2) (skip (2), a)); goto command_entry; end; /* ** start of star trek ** */ do while (game_switch); run_switch = "1"b; put edit ("*** *** *** STAR TREK *** *** ***", "DO YOU NEED INSTRUCTIONS, THEY ARE LONG (yes/no) ? ") (column (25), a, skip (5), a); get edit (answer) (column (1), a (2)); if answer = "ye" then call instructions; else do; put edit ("WOULD YOU LIKE A COMMAND LIST (yes/no)? ") (skip (3), a); get edit (answer) (column (1), a (2)); if answer = "ye" then call command_list; end; rand = time; rand = substr (rand, 2, 2); do count = 1 to binary (rand); random = random_number (); end; quadrant = " "; stardate = random_number ()*20+20*100; initial_stardate = stardate; /* ** beginning stardate ** */ length_of_game = 30; /* ** length of game ** */ docked_code = not_docked; /* ** not docked code ** */ energy, initial_energy = 3000; /* ** units of energy ** */ photon_torpedo = ten; /* ** no. of photon torp. ** */ klingon_shield = 200; /* ** units for klingon ** */ shields = 0; /* ** units for enterprise ** */ row_quadrant = random_number () * eight + one; col_quadrant = random_number () * eight + one; row_sector = random_number () * eight + one; col_sector = random_number () * eight + one; device = 0; computer_record = 0; total_starbases = 0; total_klingons = 0; /* ** set up what exists in galaxy ** */ do count = one to eight; do count_one = one to eight; random = random_number (); if random <= 0.8 then galaxy (count, count_one, klingon) = 0; else galaxy (count, count_one, klingon) = one; if random > 0.95 then galaxy (count, count_one, klingon) = two; if random > 0.98 then galaxy (count, count_one, klingon) = three; total_klingons = total_klingons+galaxy (count, count_one, klingon); random = random_number (); if random > 0.96 then do; galaxy (count, count_one, star_base) = one; total_starbases = total_starbases+one; end; else galaxy (count, count_one, star_base) = 0; galaxy (count, count_one, star) = random_number () * eight + one; end; end; if total_starbases = 0 then do; temp_row_quadrant = random_number () * eight + one; temp_col_quadrant = random_number () * eight + one; galaxy (temp_row_quadrant, temp_col_quadrant, star_base) = one; total_starbases = one; end; initial_klingons = total_klingons; put edit ("YOUR ORDERS ARE AS FOLLOWS:", " DESTROY THE ", total_klingons, " KLINGON BATTLE CRUISERS WHICH", "HAVE INVADED FEDERATION SPACE BEFORE THEY CAN ATTACK", "FEDERATION HEADQUARTERS ON STARDATE ", initial_stardate + length_of_game, ". THIS GIVES", "YOU ", length_of_game, " STARDATES.") (skip (3), a, skip (1), a, f (3), a, skip (1), a, skip (1), a, f (5), a, skip (1), a, f (3), a); if total_starbases = one then put edit ("THERE IS ONE STARBASE") (skip (3), a); else put edit ("THERE ARE ", total_starbases, " STARBASES") (skip (2), a, f (3), a); put edit ("IN THE GALAXY FOR RESUPPLYING YOUR SHIP.") (skip (1), a); call new_quadrant; command_entry: /* ** entry point on errors to continue playing the game ** */ do while (run_switch); if shields + energy <= ten | ((energy <= ten) & (device (7) < 0)) then do; run_switch = off; put edit (" ***FATAL ERROR***", "YOU HAVE STRANDED YOUR SHIP IN SPACE !", "YOU HAVE INSUFFICIENT MANUEVERING ENERGY AND SHIELD CONTROL", "IS INCAPABLE OF CROSS-CIRCUITING TO THE ENGINE ROOM !") ((4) (skip (1), a)); end; else do; put edit ("Command: ") (skip (2), a); get edit (command) (column (1), a (3)); if command = "nav" then call course_control; else if command = "she" then call shield_control; else if command = "srs" then call short_range_sensor_scan; else if command = "lrs" then call long_range_sensor_scan; else if command = "pha" then call phaser_control; else if command = "tor" then call torpedo_control; else if command = "dam" then call damage_control; else if command = "com" then call library_computer; else if command = "xxx" then call end_time_starbases; else if command = "???" then call command_list; else; call super_nova; if docked_code = docked then do; energy = 3000; photon_torpedo = 10; end; end; if total_klingons = 0 then do; call win_game; run_switch = "0"b; end; end; put edit ("THE FEDERATION NEEDS A NEW STARSHIP COMMANDER", "FOR A SIMILAR MISSION -- IF THERE IS A VOLUNTEER,", "LET HIM STEP FOWARD AND ENTER ""aye"", else ""xx"".", "?") ((3) (skip (1), a), skip (3), x (5), a); get edit (answer) (column (1), a (2)); if answer ^= "ay" then game_switch = off; end; new_quadrant: proc; if col_quadrant = one | col_quadrant = five then name_suffix = " I"; else if col_quadrant = two | col_quadrant = six then name_suffix = " II"; else if col_quadrant = three | col_quadrant = seven then name_suffix = " III"; else if col_quadrant = four | col_quadrant = eight then name_suffix = " IV"; if col_quadrant >= five then count = row_quadrant * two; else count = (row_quadrant * two) - one; output_quadrant_name = quadrant_names (count) || name_suffix; if stardate = initial_stardate then put edit ("Your mission begins with your starship located", "in the galactic quadrant """, output_quadrant_name, """.") (skip (2), a, skip, a, a, a); else put edit ("NOW ENTERING """, output_quadrant_name, """ QUADRANT ...") (skip (2), 3 a, skip); local_klingons = galaxy (row_quadrant, col_quadrant, klingon); local_starbases = galaxy (row_quadrant, col_quadrant, star_base); local_stars = galaxy (row_quadrant, col_quadrant, star); if local_klingons ^= 0 then do; put edit ("COMBAT AREA ------ CONDITION RED") (skip (2), a); if shields <= 200 then put edit (" SHIELDS DANGEROUSLY LOW!!") (skip (2), a); end; quadrant = " "; quadrant (row_sector, col_sector) = "EEE"; klingon_location = 0; do count = one to local_klingons; call random_hole; quadrant (row_random, col_random) = "+++"; klingon_location (count, one) = row_random; klingon_location (count, two) = col_random; klingon_location (count, star) = klingon_shield; end; do count = one to local_starbases; call random_hole; quadrant (row_random, col_random) = ">!<"; row_starbase = row_random; col_starbase = col_random; end; do count = one to local_stars; call random_hole; quadrant (row_random, col_random) = " * "; end; call short_range_sensor_scan; end new_quadrant; random_hole: proc; do while (run); row_random = random_number () * eight + one; col_random = random_number () * eight + one; if quadrant (row_random, col_random) = " " then return; end; end random_hole; short_range_sensor_scan: proc; if (quadrant (row_sector - one, col_sector + one) = ">!<" | quadrant (row_sector, col_sector + one) = ">!<" | quadrant (row_sector + one, col_sector + one) = ">!<" | quadrant (row_sector + one, col_sector) = ">!<" | quadrant (row_sector + one, col_sector - one) = ">!<" | quadrant (row_sector, col_sector - one) = ">!<" | quadrant (row_sector - one, col_sector - one) = ">!<" | quadrant (row_sector - one, col_sector) = ">!<") & (docked_code ^ docked) then do; docked_code = docked; condition_code = "DOCKED"; energy = 3000; photon_torpedo = ten; put edit ("***SHIELDS DROPPED FOR DOCKING PURPOSES***") (skip (2), a); shields = 0; end; else do; docked_code = not_docked; if local_klingons > 0 then condition_code = "RED"; else if energy < initial_energy * 0.1 then condition_code = "YELLOW"; else condition_code = "GREEN"; end; if device (2) >= 0 then do; if shields = 0 then quadrant (row_sector, col_sector) = " E "; else if shields >= 200 then quadrant (row_sector, col_sector) = "[E]"; else quadrant (row_sector, col_sector) = ""; line (*) = " "; do count = one to eight; do count_one = one to eight; line (count) = line (count) || quadrant (count, count_one) || " "; end; end; put edit ("---------------------------------", line (1), line (2), " STARDATE ", stardate, line (3), " CONDITION ", condition_code, line (4), " QUADRANT ", row_quadrant, " , ", col_quadrant, line (5), " SECTOR ", row_sector, " , ", col_sector, line (6), " TOTAL ENERGY ", energy, line (7), " PHOTON TORPEDOS ", photon_torpedo, line (8), " SHIELDS ", shields, "---------------------------------") (skip (1), a, skip (2), a, skip (1), a, a, f (6, 1), skip (1), a, a, a, skip (1), a, a, f (1), a, f (1), skip (1), a, a, f (1), a, f (1), skip (1), a, a, f (6, 1), skip (1), a, a, f (2), skip (1), a, a, f (6, 1), skip (2), a); end; else put edit ("***SHORT RANGE SENSORS ARE INOPERATIVE***") (skip (2), a); end short_range_sensor_scan; course_control: proc; if stardate - initial_stardate > two then put edit (" (COURSE (1-9), WARP FACTOR (1-12))? ") (skip (1), a); else put edit ( " 5", " 4 | 6", " \|/", " COURSE 3 <-- --> 7, WARP FACTOR (1 - 12)", " /|\", " 2 | 8", " 1", "?") (skip (3), a, (6) (skip (1), a), skip (1), x (5), a); get list (course, warp); if course < one | course > nine then do; put edit ("LT. SULU REPORTS, ""INCORRECT COURSE DATA, SIR!""") (skip (1), a); return; end; if warp <= 0 | warp > 12 then do; put edit ("CHIEF ENGINEER SCOTT ""THE ENGINES WON""T", " TAKE WARP ", warp, ".""") (skip (2), a, skip (1), a, f (5, 1), a); return; end; if device (1) < 0 & warp > 0.2 then do; put edit ("WARP ENGINES ARE DAMAGED. MAXIMUM WARP IS 0.2") (skip (1), a); return; end; if warp > eight & warp <= 12 then call time_dilation; number_sectors = warp * eight + 0.5; if energy - number_sectors < 0 then do; put edit ("ENGINEERING REPORTS : INSUFFICIENT ENERGY AVAILABLE", "FOR MANEUVERING AT WARP ", warp, " !") (skip (2), a, skip (1), a, f (4, 1), a); if shields < number_sectors - energy | device (7) < 0 then return; else; put edit ("DEFLECTOR CONTROL ROOM ACKNOWLEDGES ", shields, " units") (skip (2), a, f (3), a); put edit (" UNITS OF ENERGY PRESENTLY DEPLOYED TO SHIELDS.") (skip (1), a); return; end; /* ** klingons move/fire on moving starship ** */ do count = one to local_klingons; if (klingon_location (count, 3) > 0) then do; quadrant (klingon_location (count, 1), klingon_location (count, 2)) = " "; call random_hole; klingon_location (count, 1) = row_random; klingon_location (count, 2) = col_random; quadrant (row_random, col_random) = "+++"; end; end; call klingon_fire; repair = warp; if warp >= one then repair = one; /* ** make repairs to ship ** */ fixed_switch = off; do count = one to eight while (fixed_switch = off); if device (count) < 0 then do; device (count) = device (count) + repair; if device (count) >= 0 then do; fixed_switch = onn; put edit ("Damage control reports:", " ""Repairs completed on ", device_name (count), """") (skip (4), a, skip (2), (3) (a)); end; end; end; if (random_number () <= 0.2) & (warp >= 3.0) then do; random = random_number () * eight + one; if random_number () < 0.6 then do; device (random) = device (random) - random_number () * five - one; put edit (device_name (random), " DAMAGED DURING MANUEVER ...") (skip (2), (2) (a)); end; else if device (random) < 0 then do; device (random) = device (random) + random_number () * three + one; if device (random) > 0 then put edit ("Repairs made to ", device_name (random), " during maneuver") (skip (2), ( ) (a)); end; end; /* ** begin moving starship ** */ call gravity_disturbance; quadrant (row_sector, col_sector) = " "; col_increment = -sin ((course - one) * pi_over_four); row_increment = cos ((course - one) * pi_over_four); call maneuver_energy; if warp < one then stardate = stardate + warp; else stardate = stardate + one; if stardate > initial_stardate+length_of_game then do; call end_time_starbases; return; end; float_row_sector = row_sector; float_col_sector = col_sector; collision_switch = off; exceed_switch = off; do count = one to number_sectors while ((collision_switch = off) & (exceed_switch = off)); float_row_sector = float_row_sector + row_increment; float_col_sector = float_col_sector + col_increment; temp_row_sector = float_row_sector; temp_col_sector = float_col_sector; if temp_row_sector < one | temp_row_sector > eight | temp_col_sector < one | temp_col_sector > eight then exceed_switch = onn; else if quadrant (temp_row_sector, temp_col_sector) ^= " " then collision_switch = onn; else; end; if exceed_switch = onn then do; call exceed_quadrant; call new_quadrant; end; else if collision_switch = onn then do; row_sector = float_row_sector - row_increment; col_sector = float_col_sector - col_increment; put edit ("WARP ENGINES SHUT DOWN AT SECTOR ", row_sector, ",", col_sector, " DUE TO BAD NAVIGATION.") (skip (2), a, f (1), a, f (1), a); call short_range_sensor_scan; end; else do; row_sector = temp_row_sector; col_sector = temp_col_sector; call short_range_sensor_scan; end; end course_control; exceed_quadrant: proc; exceed_switch = off; row_quadrant = row_sector + eight * (row_quadrant + warp * row_increment); col_quadrant = col_sector + eight * (col_quadrant + warp * col_increment); row_sector = row_quadrant; col_sector = col_quadrant; row_quadrant = row_quadrant / eight; col_quadrant = col_quadrant / eight; row_sector = row_sector - row_quadrant * eight; col_sector = col_sector - col_quadrant * eight; if row_sector = 0 then do; row_quadrant = row_quadrant-one; row_sector = eight; end; if col_sector = 0 then do; col_quadrant = col_quadrant-one; col_sector = eight; end; if row_quadrant < one then do; exceed_switch = onn; row_quadrant = one; row_sector = one; end; if col_quadrant < one then do; exceed_switch = onn; col_quadrant = one; col_sector = one; end; if row_quadrant > eight then do; exceed_switch = onn; row_quadrant = eight; row_sector = eight; end; if col_quadrant > eight then do; exceed_switch = onn; col_quadrant = eight; col_sector = eight; end; if exceed_switch = onn then do; exceed_switch = off; put skip (2); put edit ("LT. UHURA REPORTS MESSAGE FROM STARFLEET COMMAND ", """PERMISSION TO ATTEMPT CROSSING OF GALACTIC PERIMETER", "IS HEREBY ***DENIED***. SHUT DOWN YOUR ENGINES.""", "CHIEF ENGINEER SCOTT REPORTS "" WARP ENGINES SHUT DOWN", " AT SECTOR ", row_sector, ",", col_sector, " OF QUADRANT ", row_quadrant, ",", col_quadrant, """") ((4) (skip, a), skip, a, f (2), a, f (2), a, f (2), a, f (2), a); if stardate > initial_stardate + length_of_game then do; call end_time_starbases; return; end; end; end exceed_quadrant; maneuver_energy: proc; energy = energy - number_sectors - ten; if energy < 0 then do; put edit ("SHIELD CONTROL SUPPLIED ENERGY TO COMPLETE THE MANEUVER") (skip (1), a); shields = shields - energy; energy = 0; if shields < 0 then shields = 0; end; end maneuver_energy; long_range_sensor_scan: proc; if device (3) < 0 then do; put edit ("***LONG RANGE SENSORS ARE INOPERABLE***") (skip (1), a); return; end; put edit ("LONG RANGE SENSOR SCAN FOR QUADRANT ", row_quadrant, ",", col_quadrant, "...................") (skip (1), a, f (2), a, f (2), skip (1), column (7), a); do count = row_quadrant-one to row_quadrant+one; record (*) = 0; do count_one = col_quadrant-one to col_quadrant+one; if ^ (count < one | count > eight | count_one < one | count_one > eight) then do; record (count_one - col_quadrant + two) = galaxy (count, count_one, klingon) * 100 + galaxy (count, count_one, star_base) * ten + galaxy (count, count_one, star); computer_record (count, count_one, klingon) = galaxy (count, count_one, klingon); computer_record (count, count_one, star_base) = galaxy (count, count_one, star_base); computer_record (count, count_one, star) = galaxy (count, count_one, star); end; end; put edit (": ", record (1), " : ", record (2), " : ", record (3), " : ", "...................") (col (7), a, f (3), a, f (3), a, f (3), a, skip (1), column (7), a); end; end long_range_sensor_scan; library_computer: proc; if device (8) < 0 then do; put edit ("***COMPUTER DISABLED***") (skip (1), a); return; end; put edit ("COMPUTER ACTIVE AND AWAITING COMMAND ? ") (skip (1), a); get list (computer_command); if computer_command < 0 | computer_command > five then do; put edit ("COMMANDS AVAILABLE FROM THE LIBRARY COMPUTER", " 0 - CUMULATIVE GALACTIC RECORD", " 1 - STATUS REPORT", " 2 - PHOTON TORPEDO DATA", " 3 - STARBASE NAV DATA", " 4 - DIRECTION / DISTANCE CALCULATOR", " 5 - GALAXY / REGION NAME MAP", "?") (skip (2), a, (7) (skip (1), a), skip (2), a); get list (computer_command); end; if computer_command = 0 then do; put edit ("COMPUTER RECORD OF GALAXY FOR QUADRANT " , row_quadrant, ",", col_quadrant) (skip (2), a, f (1), a, f (1)); call galaxy_map; end; else if computer_command = 1 then call status_report; else if computer_command = 2 then do; if local_klingons > 0 then put edit ("From Enterprise to Klingon battle cruiser:") (skip (2), a); do count = 1 to local_klingons; if klingon_location (count, 3) > 0 then call direction_and_distance (row_sector, col_sector, klingon_location (count, 1), klingon_location (count, 2)); end; return; end; else if computer_command = 3 then do; if local_starbases ^= 0 then do; put edit ("From Enterprise to starbase:") (skip (1), a); call direction_and_distance (row_sector, col_sector, row_starbase, col_starbase); end; else do; put edit ("Mr. Spock reports: ""Sensor shows no starbases in this quadrant.""") (skip (1), a); end; return; end; else if computer_command = 4 then do; put edit ("DIRECTION / DISTANCE CALCULATOR") (skip (1), a); put edit ("YOU ARE AT QUADRANT (", row_quadrant, ",", col_quadrant, ")", " SECTOR (", row_sector, ",", col_sector, ")") (skip (2), 2 (a, f (1)), a, 2 (a, f (1)), a); put edit ("Enter sector of target (row, col): ") (skip (1), a); get list (row_coordinate, col_coordinate); call direction_and_distance (row_sector, col_sector, row_coordinate, col_coordinate); end; else if computer_command = five then do; map_switch = onn; put edit (" THE GALAXY") (skip (1), a); call galaxy_map; end; end library_computer; galaxy_map: proc; put edit (" ") (skip (5), a); do count = one to eight; put edit (" ", count) (a, f (1)); end; put edit (galaxy_line) (skip (1), a); do count = one to eight; put edit (count, " ") (skip (1), f (1), a); if map_switch = onn then do; output_quadrant_name = quadrant_names ((count * two) - one); put edit (output_quadrant_name) (col (15-length (output_quadrant_name)/2), a); output_quadrant_name = quadrant_names (count * two); put edit (output_quadrant_name) (col (34-length (output_quadrant_name)/2), a); end; else do count_one = one to eight; if count = row_quadrant & count_one = col_quadrant then put edit ("(E) ") (a); else put edit (computer_record (count, count_one, *), " ") (3 f (1), a); end; put edit (galaxy_line) (skip, a); end; map_switch = off; end galaxy_map; status_report: proc; put edit (" STATUS REPORT") (skip (1), a); if total_klingons = one then name_suffix = ""; else name_suffix = "S"; put edit (total_klingons, " KLINGON", name_suffix, " LEFT", "MISSION MUST BE COMPLETED IN ", initial_stardate + length_of_game - stardate, " STARDATES") (skip (2), f (3), (3) (a), skip (1), a, skip (1), f (6, 2), a); if total_starbases = one then name_suffix = ""; else name_suffix = "S"; if total_starbases ^= 0 then put edit ("THE FEDERATION IS MAINTAINING", total_starbases, " STARBASE", name_suffix, " IN THE GALAXY.") (skip (1), a, f (3), 3 a); else do; put edit ("YOUR STUPIDITY HAS LEFT YOU ON YOUR OWN IN", " THE GALAXY -- YOU HAVE NO STARBASES LEFT") (skip (2), a, skip (1), a); end; end status_report; direction_and_distance: procedure (bv_from_row, bv_from_col, bv_to_row, bv_to_col); /* parameters */ declare (bv_from_row, bv_from_col, bv_to_row, bv_to_col) fixed binary parameter; /* program */ if bv_from_row = bv_to_row then if bv_from_col < bv_to_col then direction = seven; else direction = three; else if bv_from_col = bv_to_col then if bv_from_row < bv_to_row then direction = one; else direction = five; else do; column = bv_from_col - bv_to_col; row = bv_from_row - bv_to_row; direction = row / column; direction = atan (direction) / pi_over_four /* ** 45 degrees ** */; if column < 0 then direction = direction + seven; else direction = direction + three; end; put edit ("DIRECTION =", direction, " DISTANCE =", sqrt (column**2 + row**2)) (skip (2), a, f (6, 2), a, f (6, 2)); end direction_and_distance; random_number: proc returns (float decimal (6)); (nofixedoverflow): static_number = static_number*131069; if static_number < 0 then substr (unspec (static_number), 1, 1) = off; rando = static_number*2.9103830e-11; return (rando); end random_number; phaser_control: proc; if local_klingons = 0 then put edit ("SCIENCE OFFICER SPOCK REPORTS", """SENSORS SHOW NO ENEMY SHIPS IN THIS QUADRANT""") (skip (2), x (5), a, skip (1), x (5), a); else if device (4) < 0 then put edit ("***PHASERS INOPERATIVE***") (skip (2), x (5), a); else do; if device (8) < 0 then put edit ("COMPUTER FAILURE HAMPERS ACCURACY ...") (skip (2), x (5), a); put edit ("Phasers locked on target.", "Ship's energy is ", energy, " units.", "Number of units to fire? ") (skip (2), x (5), a, skip (1), x (5), a, f (4), a, skip (1), x (5), a); get list (phaser_energy); if phaser_energy <= 0 | (energy - phaser_energy) < 0 then return; else do; energy = energy - phaser_energy; call klingon_fire; if device (8) < 0 then phaser_energy = phaser_energy * random_number (); distribute_phaser_energy = phaser_energy / local_klingons; do count = one to local_klingons; hit_phaser_energy = (distribute_phaser_energy / (sqrt ((klingon_location (count, one) - row_sector) ** two + (klingon_location (count, two) - col_sector) ** two))) * (random_number ()); if hit_phaser_energy <= 0.15 * klingon_location (count, 3) then put edit ("Sensors show no damage to enemy at ", klingon_location (count, 1), ", ", klingon_location (count, 2)) (skip (2), x (5), a, f (1), a, f (1)); else do; klingon_location (count, 3) = klingon_location (count, 3) - hit_phaser_energy - klingon_location (count, four); put edit (hit_phaser_energy, " UNIT HIT AT KLINGON SECTOR ", klingon_location (count, 1), ", ", klingon_location (count, 2)) (skip (2), x (5), f (4), a, f (1), a, f (1)); if klingon_location (count, 3) <= 0 then do; put edit ("*** KLINGON DESTROYED ***") (skip (2), x (5), a); local_klingons = local_klingons - one; total_klingons = total_klingons - one; quadrant (klingon_location (count, 1), klingon_location (count, 2)) = " "; galaxy (row_quadrant, col_quadrant, klingon) = local_klingons; computer_record (row_quadrant, col_quadrant, klingon) = local_klingons; end; else put edit ("SENSORS SHOW ", klingon_location (count, 3), " UNITS REMAINING") (skip (2), x (5), a, f (4), a); end; end; end; end; end phaser_control; torpedo_control: proc; if device (5) < 0 then put edit ("***PHOTON TUBES NOT OPERATIONAL***") (skip (2), x (5), a); else if photon_torpedo = 0 then put edit ("*** ALL PHOTON TORPEDOS EXPENDED ***") (skip (2), x (5), a); else do; put edit ("TORPEDO COURSE (1 - 9) ? ") (skip (2), a); get list (torpedo_course); if torpedo_course < 1 | torpedo_course > 9 then put edit ("ENSIGN CHECKOV REPORTS", " ""INCORECT COURSE DATA, SIR !""") (skip (2), x (5), a, skip (2), x (5), a); else do; if torpedo_course = 9 then torpedo_course = 1; col_increment = -sin ((torpedo_course - 1e0) * pi_over_four); row_increment = cos ((torpedo_course - 1e0) * pi_over_four); energy = energy - 2; float_row_torpedo_track = row_sector; float_col_torpedo_track = col_sector; photon_torpedo = photon_torpedo - 1; put edit ("TORPEDO TRACK:") (skip (2), x (2), a); float_row_torpedo_track = (float_row_torpedo_track + row_increment); float_col_torpedo_track = (float_col_torpedo_track + col_increment); row_torpedo_track = float_row_torpedo_track + .5e0; col_torpedo_track = float_col_torpedo_track + .5e0; do while ((row_torpedo_track >= 1) & (row_torpedo_track <= 8) & (col_torpedo_track >= 1) & (col_torpedo_track <= 8)); put edit (row_torpedo_track, ", ", col_torpedo_track) (skip (1), x (20), f (1), a, f (1)); if quadrant (row_torpedo_track, col_torpedo_track) = "+++" then do; put edit ("*** KLINGON DESTROYED ***") (skip (2), x (5), a); local_klingons = local_klingons - 1; total_klingons = total_klingons - 1; do count = 1 to 3; if row_torpedo_track = klingon_location (count, 1) & col_torpedo_track = klingon_location (count, 2) then klingon_location (count, *) = 0; end; quadrant (row_torpedo_track, col_torpedo_track) = " "; galaxy (row_quadrant, col_quadrant, klingon) = local_klingons; computer_record (row_quadrant, col_quadrant, klingon) = local_klingons; return; end; if quadrant (row_torpedo_track, col_torpedo_track) = " * " then do; put edit ("*** STAR AT ", row_torpedo_track, ", ", col_torpedo_track, " ABSORBED TORPEDO ENERGY ***") (skip (2), x (5), a, f (1), a, f (1), a); return; end; else; if quadrant (row_torpedo_track, col_torpedo_track) = ">!<" then do; put edit ("*** STARBASE DESTROYED ***") (skip (2), x (5), a); local_starbases = local_starbases - 1; total_starbases = total_starbases - 1; docked_code = not_docked; quadrant (row_torpedo_track, col_torpedo_track) = " "; galaxy (row_quadrant, col_quadrant, star_base) = local_starbases; computer_record (row_quadrant, col_quadrant, star_base) = local_starbases; if total_starbases > 0 then do; put edit ("STARFLEET COMMAND REVIEWING YOUR RECORD TO CONSIDER", "***COURT MARTIAL***") (skip (2), x (5), a, skip (1), x (15), a); return; end; else do; put edit ("THAT DOES IT, CAPTAIN! YOU ARE HEREBY RELIEVED OF COMMAND", "AND SENTENCED TO 99 STARDATES AT HARD LABOR ON CYGNUS 12") (skip (2), x (5), a, skip (1), x (5), a); call end_time_starbases; return; end; end; float_row_torpedo_track = (float_row_torpedo_track + row_increment); float_col_torpedo_track = (float_col_torpedo_track + col_increment); col_torpedo_track = float_col_torpedo_track + .5e0; row_torpedo_track = float_row_torpedo_track + .5e0; end; put edit ("***TORPEDO MISSED***") (skip (2), x (5), a); call klingon_fire; end; end; return; end torpedo_control; shield_control: proc; if device (7) < 0 then put edit ("***SHIELD CONTROL INOPERABLE***") (skip (2), x (5), a); else do; put edit ("ENERGY AVAILABLE = ", energy + shields, ". NUMBER OF UNITS TO SHIELDS ? ") (skip (2), x (5), a, f (7, 1), a); get list (shield_energy); if shield_energy < 0 | shields = shield_energy then put edit ("***SHIELDS UNCHANGED***") (skip (2), x (5), a); else if (energy + shields - shield_energy) >= 0 then do; put edit ("DEFLECTOR CONTROL ROOM REPORT:", " ""SHIELDS NOW AT ", shield_energy, " AS PER YOUR COMMAND"" ") (skip (2), x (5), a, skip (1), x (5), a, f (4), a); energy = energy + shields - shield_energy; shields = shield_energy; end; end; return; end shield_control; damage_control: proc; if docked_code = not_docked & device (6) < 0 then do; put skip edit ("DAMAGE CONTROL REPORT NOT AVAILABLE") (a); return; end; if docked_code = docked then do; repair_time = 0; do count = one to eight; if device (count) < 0 then repair_time = repair_time + 0.1; end; if repair_time = 0 then return; repair_time = repair_time + 0.5 * random_number (); if repair_time >= one then repair_time = 0.9; put edit ("TECHNICIANS STANDING BY TO EFFECT SHIP REPAIRS ", "ESTIMATED REPAIR TIME: ", repair_time, " STARDATES", "WILL YOU AUTHORIZE THE REPAIR ORDER (yes/no) ? ") (skip (3), a, skip (1), a, f (3, 1), a, skip (1), a); get edit (answer) (a (3)); if answer = "yes" then do; stardate = stardate + repair_time + 0.1; do count = one to eight; if device (count) < 0 then device (count) = 0; else; end; end; end; put edit ("DEVICE --- STATE OF REPAIR") (skip (2), a); put skip (1); do count = 1 to 8; put edit (device_name (count), " : ", device (count)) (skip (1), a, column (20), a, f (6, 3)); end; end damage_control; klingon_fire: proc; if local_klingons = 0 then return; if docked_code = docked then do; put edit ("STARBASE SHIELDS PROTECT THE ENTERPRISE") (skip (2), a); return; end; do count = one to local_klingons; if klingon_location (count, 3) > 0 then do; klingon_hit_energy = (klingon_location (count, three) / (sqrt ((klingon_location (count, one) - col_sector) ** two + (klingon_location (count, two) - row_sector) ** two))) * (random_number () + .01); klingon_location (count, four) = klingon_hit_energy; shields = shields - klingon_hit_energy; put edit (klingon_hit_energy, " UNIT HIT ON ENTERPRISE FROM SECTOR ", klingon_location (count, 1), ", ", klingon_location (count, 2)) (skip (2), f (4), a, f (2), a, f (2)); if shields < 0 then do; put edit ("THE ENTERPRISE HAS BEEN DESTROYED !", "THE FEDERATION WILL BE CONQUERED !") (skip (5), (2) (skip (1), a)); call end_time_starbases; return; end; put edit (" SHIELDS DOWN TO ", shields, " UNITS.") (skip (1), a, f (4), a); if klingon_hit_energy >= 20 & random_number () <= 0.6 & klingon_hit_energy / shields >= 0.02 then do; random = (random_number () * eight + one); device (random) = device (random) - (klingon_hit_energy / shields + 0.5 * random_number ( ); put edit ("Damage control reports """, device_name (random), " damaged by Klingon fire!""") (skip (3), (3) (a)); end; end; end; end klingon_fire; end_time_starbases: proc; put edit ("IT IS STARDATE ", stardate, ".", "THERE WERE ", total_klingons, " KLINGON BATTLE CRUISERS LEFT", "THE END OF THE MISSION !") (skip (5), a, f (6, 1), a, skip (1), a, f (2), a, skip (1), a); run_switch = off; end end_time_starbases; win_game: proc; put edit (" Congratulations, Captain!", "The last Klingon battle cruiser", "menacing the Federation has been destroyed.", "Your efficiency rating is ", (initial_klingons/ (stardate - initial_stardate)*1000), ".") (skip (5), x (5), a, skip (2), a, skip (1), a, skip (1), a, f (15, 5), a); run_switch = off; end win_game; time_dilation: proc; dilation = random_number (); if dilation >= 0.8 then do; if dilation > 0.9 then stardate = stardate + random_number () * (warp / two); else stardate = stardate - random_number () * (warp / two) ; put edit ("*** WARNING ***", "Mr. Spock's sensors indicate that warp ", warp, "caused a time dilation.", "It is stardate ", stardate, ".") (skip (2), x (5), a, skip (1), a, f (5, 1), a, skip (1), a, f (6, 1), a); end; end time_dilation; gravity_disturbance: proc; disturbance = random_number (); if disturbance >= 0.95 then do; if random_number () > 0.5 then course = course + random_number (); else course = course - random_number (); if course > nine then course = course - eight; else if abs (course) < one then course = nine - abs (abs (course) - one); put edit ("*** !!!!!WARNING!!!!! ***", "Mr. Spock reports that the sensors detect a gravity", "disturbance in this area!") (skip (2), x (5), a, (2) (skip (1), a)); put edit ("Course has shifted to ", course, ".") (skip (1), a, f (6, 2), a); end; end gravity_disturbance; super_nova: proc; if random_number () <= 0.025 then do; nova_row_quadrant = random_number () * eight + one; nova_col_quadrant = random_number () * eight + one; total_klingons = total_klingons - galaxy (nova_row_quadrant, nova_col_quadrant, klingon); galaxy (nova_row_quadrant, nova_col_quadrant, *) = 0; computer_record (nova_row_quadrant, nova_col_quadrant, *) = 0; if row_quadrant = nova_row_quadrant & col_quadrant = nova_col_quadrant then do; put edit ("STARBASE COMMAND REPORTS :", """THE ENTERPRISE WAS LOST IN QUADRANT ", row_quadrant, ",", col_quadrant, "WITH ALL HANDS ABOARD DUE TO A SUPER NOVA ! """) (skip (5), a, f (1), a, f (1), skip (1), a); call end_time_starbases; end; else do; put edit ("MR. SPOCK REPORTS THAT LONG RANGE SENSORS SHOW A", "SUPER NOVA IN QUADRANT ", nova_row_quadrant, ",", nova_col_quadrant, ".") (skip (5), a, skip (1), a, f (1), a, f (1), a); end; end; end super_nova; command_list: proc; put edit ("ENTER ONE OF THE FOLLOWING :", " nav (FOR COURSE AND SPEED)", " srs (FOR SHORT RANGE SENSORS)", " lrs (FOR LONG RANGE SENSORS)", " pha (FOR PHASER CONTROL)", " tor (FOR PHOTON TORPEDO CONTROL)", " she (FOR SHIELD CONTROL)", " dam (FOR DAMAGE CONTROL)", " com (FOR LIBARY COMPUTER)", " xxx (FOR RESIGNATION OF COMMAND)", " ??? (FOR COMMAND LIST)") (skip (2), (11) (skip (1), a)); end command_list; instructions: proc; put edit (" INSTRUCTIONS FOR STAR TREK ", "THE GALAXY IS DIVIDED INTO AN 8 X 8 QUADRANT GRID", "AND EACH QUADRANT IS FURTHER DIVIDED INTO AN 8 X 8 SECTOR GRID") (skip (4), a, (3) (skip (1), a)); put edit (" YOU WILL BE ASSIGNED A STARTING POINT SOMEWHERE IN THE GALAXY", "TO BEGIN A TOUR OF DUTY AS COMMANDER OF THE STARSHIP ""ENTERPRISE"",", "YOUR MISSION: TO SEEK AND DESTROY THE FLEET OF KLINGON WARSHIPS", "WHICH ARE MENACING THE UNITED FEDERATION OF PLANETS.") (skip (2), (4) (skip (1), a)); put edit ("YOU HAVE THE FOLLOWING COMMANDS AVAILABLE TO YOU AS", "CAPTAIN OF THE STARSHIP ENTERPRISE:", " ""nav"" COMMAND = WARP ENGINE CONTROL --", " COURSE IS IN A CIRCULAR 5", " VECTOR ARRANGEMENT AS SHOWN. 4 | 6", " INTEGER AND REAL VALUES MAY BE \|/", " USED. (THUS, COURSE 1.3 HALF- 3 <-- --> 7", " WAY BETWEEN 1 AND 2.) /|\", " 2 | 8", " VALUES MAY APPROACH 9.0, WHICH 1", " ITSELF IS EQUIVALENT TO 1,0.", " COURSE", " ONE WARP FACTOR IS THE SIZE OF", " ONE QUADRANT. THEREFORE TO GET", " FROM QUADRANT 6,5 TO 6,4, YOU WOULD", " USE COURSE 3, WARP FACTOR 1.") (skip (2), (16) (skip (1), a)); put edit (" ""srs"" COMMAND = SHORT RANGE SENSOR SCAN", " SHOWS YOU A SCAN OF YOUR PRESENT QUADRANT.", " SYMBOLOGY ON YOUR SENSOR SCREEN IS AS FOLLOWS.", " "" E "" = ENTERPRISE WITH ZERO SHIELDS", " """" = ENTERPRISE WITH LESS THAN 200 IN SHIELDS", " ""[E]"" = ENTERPRISE WITH MORE THAN 200 IN SHIELDS", " ""+++"" = KLINGON BATTLE CRUISER", " "">!<"" = FEDERATION STARBASE (REFUEL/REPAIR/RE-ARM HERE !)", " "" * "" = STARS", " A CONDENSED ""STATUS REPORT"" WILL ALSO BE PRESENTED.") (skip (2), (9) (skip (1), a)); put edit (" ""lrs"" COMMAND = LONG RANGE SENSOR SCAN", " SHOWS CONDITIONS IN SPACE FOR THE QUADRANT ON EACH SIDE", " OF THE ENTERPRISE (WHICH IS IN THE MIDDLE OF THE SCAN)", " THE SCAN IS CODED IN THE FORM ""XXX"", WHERE THE UNITS DIGIT", " IS THE NUMBER OF STARS, TENS DIGIT IS THE NUMBER OF STARBASES,", " AND HUNDREDS DIGIT IS THE NUMBER OF KLINGONS.", " EXAMPLE -- 207 = 2 KLINGONS, NO STARBASES, 7 STARS") (skip (2), (7) (skip (1), a)); put edit (" ""pha"" COMMAND = PHASER CONTROL.", " ALLOWS YOU TO DESTROY THE KLINGON BATTLE CRUISERS BY", " ZAPPING THEM WITH SUITABLE LARGE UNITS OF ENERGY TO ", " DEPLETE THEIR SHIELD ENERGY. (REMEMBER, KLINGONS HAVE", " PHASERS TOO !)") (skip (2), (5) (skip (1), a)); put edit (" "" tor"" COMMAND = PHOTON TORPEDO CONTROL", " TORPEDO COURSE IS THE SAME AS USED IN WARP ENGINE CONTROL.", " IF YOU HIT THE KLINGON VESSEL, HE IS DESTROYED AND", " CANNOT FIRE BACK AT YOU. IF YOU MISS, YOU ARE SUBJECT TO ", " HIS PHASER FIRE.", " NOTE: THE LIBARY-COMPUTER (""com"" COMMAND) HAS AN", " OPTION TO COMPUTE TORPEDO TRAJECTORY FOR YOU (OPTION 2)") (skip (2), (7) (skip (1), a)); put edit (" ""she"" COMMAND = SHIELD CONTROL.", " DEFINES NUMBER OF ENERGY UNITS TO BE ASSIGNED TO SHIELDS.", " ENERGY IS TAKEN FROM TOTAL SHIPS""S ENERGY.") (skip (2), (3) (skip (1), a)); put edit (" ""dam"" COMMAND = DAMAGE CONTROL REPORT", " GIVES STATE OF REPAIR OF ALL DEVICES, WHERE A NEGATIVE", " ""STATE OF REPAIR"" SHOWS THAT THE DEVICE IS TEMPORARILY", " DAMAGED.", " NOTE: ""nav"" WILL RANDOMLY DAMAGE OR REPAIR A DEVICE.") (skip (2), (5) (skip (1), a)); put edit (" ""com"" COMMAND = LIBRARY-COMPUTER", " THE LIBRARY-COMUTER CONTAINS SIX OPTIONS:", " OPTION: 0 = CUMULATIVE GALACTIC RECORD", " WHICH SHOWS COMPUTER MEMORY OF THE RESULTS OF ALL PREVIOUS", " LONG RANGE SENSOR SCANS.", " OPTION: 1 = STATUS REPORT", " WHICH SHOWS THE NUMBER OF KLINGONS, STARDATES, AND STARBASES", " REMAINING IN THE GAME.", " OPTION: 2 = PHOTON TORPEDO DATA", " WHICH GIVES DIRECTION AND DISTANCES FROM THE ENTERPRISE", " TO ALL KLINGONS IN YOUR QUADRANT.", " OPTION: 3 = STARBASE NAV DATA", " WHICH GIVES DIRECTION AND DISTANCE TO ANY STARBASE", " WITHIN YOUR QUADRANT", " OPTION: 4 = DIRECTION / DISTANCE CALCULATOR", " WHICH ALLOWS YOU TO ENTER COORDINATES FOR", " DIRECTION / DISTANCE CALCULATIONS.", " OPTION: 5 = GALACTIC ""REGION NAME"" MAP", " WHICH PRINTS THE NAMES OF THE SIXTEEN MAJOR GALACTIC", " REGIONS REFFERRED TO IN THE GAME") (skip (2), (30) (skip (1), a)); call command_list; end instructions; end trek;