home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / ARexx / startrek.rexx < prev    next >
OS/2 REXX Batch file  |  1988-04-28  |  34KB  |  1,364 lines

  1. /* *****************************************************
  2.    **                                                 **
  3.    **  STAR TREK - THE FINAL FRONTIER                 **
  4.    **                                                 **
  5.    **  Written By Steve Berry                         **
  6.    **                                                 **
  7.    **  Rev A - 4/24/87   IBM 370                      **
  8.    **                                                 **
  9.    **  Inputs: filename (saved game)                  **
  10.    **                                                 **
  11.    **  Rev B - 5/21/88                                **
  12.    **       modified to run on Amiga                  **
  13.    **                                                 **
  14.    ***************************************************** */
  15.  
  16. arg fn .
  17.  
  18. address command
  19.  
  20. call time 'R'        /* reset timer */
  21. stardate = time('E')
  22. junk = randu(time('S'))
  23.  
  24. /* Begining of main routine */
  25.  
  26. say ''
  27. say ' Please be patient... making galaxy'
  28. say ''
  29.  
  30. mission = 1
  31.  
  32. /* Are we playing an OLD Game? */
  33.  
  34. if fn ~= '' then
  35.     call load_old_game fn
  36. else
  37.  
  38. newmission:
  39.  select
  40.   when mission = 1 then call init_variables_1
  41.   when mission = 2 then call init_variables_2
  42.   when mission = 3 then call init_variables_3
  43.   when mission = 4 then call init_variables_4
  44.   when mission = 5 then call init_variables_5
  45.   when mission = 6 then call init_variables_6
  46.   when mission = 7 then call init_variables_7
  47.   when mission = 8 then call init_variables_8
  48.   when mission = 9 then call init_variables_9
  49.   when mission = 10 then call init_variables_10
  50. /*  otherwise */
  51.  end
  52.  
  53.  
  54. /* ************ */
  55. /* Main do loop */
  56. /* ************ */
  57.  
  58. do until energy = 0
  59.  
  60.  'cls'
  61.  call print_quadrent x,y,ex,ey
  62.  t0 = time('R')
  63.  
  64. /* get user input and parse the commands */
  65.  
  66.  say 'Your command Captain?'
  67.  pull instring
  68.  rc = parse_command(instring)
  69.  
  70. /* process the commands */
  71.  
  72.   if rc = 0 then do
  73.     do loop = 1 to 3
  74.      if arg1.loop = '' then leave
  75.      call process_command arg1.loop,arg2.loop
  76.      if alive = 'no' | energy <= 0 then leave
  77.     end
  78.    end
  79.   else say 'Captain I am sorry but I cant understand you.'
  80. /* Check for illegal input */
  81.  
  82.   if missstat = 'completed' then do
  83.     'cls'
  84.     say ''
  85.     say ' CONGRATULATIONS !!! You have completed Mission' mission
  86.     say ''
  87.     mission = mission + 1
  88.     if mission = 11 then do
  89.      say ' WOW YOU ARE AWESOME !! Ever think of running for office?'
  90.      say ' game over.'
  91.      exit 0
  92.     end
  93.    end
  94.  
  95. /* Did player kill himself? */
  96.  
  97.  If alive = 'no' | energy <= 0 then do
  98.    'cls'
  99.    say ''
  100.    say ''
  101.    say ''
  102.    say ''
  103.    say ' Suicide is not in the BEST interests of the FEDERATION.'
  104.    say ''
  105.    say ' But you did get 'points' points.'
  106.    say ''
  107.    say ''
  108.    say ''
  109.    say 'game over.'
  110.    say ''
  111.    say ''
  112.    exit
  113.   end
  114.  
  115. /* Time for a little wear and tear on the enterprize */
  116.  
  117.  call wear_and_tear
  118.  
  119. /* Is the Enterprize DEAD in Space? */
  120.  
  121.  If alive = 'no' then do
  122.    'cls'
  123.    say ''
  124.    say ''
  125.    say ''
  126.    say ''
  127.    say ' Sorry but you let the Enterprize deterioriate into '
  128.    say ' into a rusting hunk of space debris.'
  129.    say ''
  130.    say ' But you did get 'points' points.'
  131.    say ''
  132.    say ''
  133.    say ''
  134.    say 'game over.'
  135.    say ''
  136.    say ''
  137.    exit
  138.   end
  139.  
  140. /* Ok. now it's the Bad guy's turn */
  141.  
  142. /* now call mission specific routine */
  143. /* for bad guy routine and points awarded */
  144.  
  145.  select
  146.   when mission = 1 then call mission1
  147.   when mission = 2 then call mission2
  148.   when mission = 3 then call mission3
  149.   when mission = 4 then call mission4
  150.   when mission = 5 then call mission5
  151.   when mission = 6 then call mission6
  152.   when mission = 7 then call mission7
  153.   when mission = 8 then call mission8
  154.   when mission = 9 then call mission9
  155.   when mission = 10 then call mission10
  156.  end
  157.  
  158. /* Is the Enterprize KILLED? KRUSHED? DESTROYED? */
  159.  
  160.  If alive = 'no' then do
  161.    say ''
  162.    say ''
  163.    say ''
  164.    say ''
  165.    say ' Sorry but you let Your crew and the Federation down.'
  166.    say ' Perhaps you should consider another career.'
  167.    say ''
  168.    say ' But you did get 'points' points.'
  169.    say ''
  170.    say ''
  171.    say ''
  172.    say 'game over.'
  173.    say ''
  174.    say ''
  175.    exit
  176.   end
  177.  
  178. /* end of the loop - now go print the screen */
  179. end
  180.  
  181.  
  182. /* ********************************************** */
  183. /* ********************************************** */
  184. /*          SUBROUTINE SECTION                    */
  185. /* ********************************************** */
  186. /* ********************************************** */
  187.  
  188.  
  189.  
  190. /* ********************************************** */
  191. /* ********************************************** */
  192. /*          SUBROUTINE LOAD_OLD_GAME              */
  193. /*  PASSED VALUES - fn                            */
  194. /* ********************************************** */
  195. /* ********************************************** */
  196.  
  197. load_old_game:
  198.  
  199. arg fn
  200.  
  201. bstr = '   <*> * |o|(B))\_ # '
  202. missstat = 'not yet'
  203.  
  204. /* get variables */
  205.  
  206.  if ~Open(fnn,fn,'R') then exit -99
  207.  inn = Readln(fnn)
  208.  push inn
  209.  parse pull stardate mission energy points x y ex ey shields klshields docked kltot
  210.  inn = Readln(fnn)
  211.  push inn
  212.  pull status.0 status.1 status.2 status.3 status.4 status.5
  213.  
  214. /* start interval timer */
  215.  
  216. stardate = stardate + time('E')
  217.  
  218. /* Load galactic map */
  219.  
  220.  do l = 0 to 9
  221.   inn1 = Readln(fnn)
  222.   inn2 = Readln(fnn)
  223.   push inn1; push inn2
  224.   pull map.l.5 map.l.6 map.l.7 map.l.8 map.l.9
  225.   pull map.l.0 map.l.1 map.l.2 map.l.3 map.l.4
  226.  end
  227.  
  228.  do l = 0 to 9
  229.   inn1 = Readln(fnn)
  230.   inn2 = Readln(fnn)
  231.   push inn1; push inn2
  232.   pull quad.l.5 quad.l.6 quad.l.7 quad.l.8 quad.l.9
  233.   pull quad.l.0 quad.l.1 quad.l.2 quad.l.3 quad.l.4
  234.  end
  235. alive = 'yes'
  236. junk = Close(fnn)
  237. call newscreen
  238. return
  239.  
  240. /* ********************************************** */
  241. /* ********************************************** */
  242. /*          SUBROUTINE INIT_VARIABLES_1           */
  243. /*  PASSED VALUES - none                          */
  244. /* ********************************************** */
  245. /* ********************************************** */
  246.  
  247. init_variables_1:
  248.  
  249. bstr = '   <*> * |o|(B))\_ # '
  250. alive = 'yes'
  251. energy = 1000000
  252. x = 0
  253. y = 0
  254. points = 0
  255. mission = 1
  256. shields = 'down'
  257. kltot = 0
  258. missstat = 'not yet'
  259.  
  260. do a = 0 to 9
  261.  do b = 0 to 9
  262.    map.a.b = random(0,1) * 100 + random(0,1)*10 + random(0,9)
  263.    if map.a.b > 99 then kltot = kltot + 1
  264.  end
  265. end
  266.  
  267. klshields = 5000
  268. status.0 = 0
  269. status.1 = 0
  270. status.2 = 0
  271. status.3 = 0
  272. status.4 = 0
  273. status.5 = 0
  274. ex = 5
  275. ey = 4
  276.  
  277. /* Welcome the player */
  278.  
  279. 'cls'
  280. say 'Star Trek'
  281. say ''
  282. say '                      ___---___'
  283. say '                   --           --'
  284. say '                 --               --'
  285. say '                 -                 -'
  286. say '                 --      ( )      --'
  287. say '                  --             --'
  288. say '                 (*)--    _    --(*)'
  289. say '                 | |   --| |--   | |'
  290. say '                 | |    / | \    | |'
  291. say '                 | |\  |\___/|  /| |'
  292. say '                 | |\ \|     |/ /| |'
  293. say '                 | |  \|     |/  | |'
  294. say '                 |_|   |     |   |_|'
  295. say '                        \___/'
  296. say ''
  297. say ''
  298. say ''
  299. say ' Welcome to MISSION 1'
  300. say '                                             hit return to continue '
  301. pull junk
  302. 'cls'
  303. say ''
  304. say 'MISSION1: WAR with the KLINGONS!'
  305. say ''
  306. say ' OBJECTIVE: Destroy all Klingon invaders in this galaxy.'
  307. say ''
  308. say 'Good luck Jim!'
  309. say ''
  310. say ' Starfleet transmission ended.'
  311. say '                                             hit return to continue '
  312. pull junk
  313.  
  314. newscreen:
  315. /* initialize quadrent matrix */
  316.  
  317. enemies = map.x.y%100
  318. bases = (map.x.y - enemies * 100)%10
  319. stars = map.x.y - enemies * 100 - bases * 10
  320.  
  321. /* zero quad matrix */
  322.  
  323. do i = 0 to 9
  324.  do j = 0 to 9
  325.   quad.i.j = 0
  326.  end
  327. end
  328.  
  329. /* locate the enterprize */
  330.  
  331. quad.ex.ey = 1
  332.  
  333. /* put the stars in */
  334.  
  335. do a = 0 to stars - 1
  336.  rx = random(0,9)
  337.  ry = random(0,9)
  338.  if quad.rx.ry = 0 then quad.rx.ry = 2
  339.  else a=a-1
  340. end
  341.  
  342. /* enemies? */
  343.  
  344. if enemies ~= 0 then do
  345.  do a = 0 to enemies - 1
  346.    rx = random(0,9)
  347.    ry = random(0,9)
  348.    if quad.rx.ry = 0 then quad.rx.ry = 3
  349.    else a=a-1
  350.  end
  351. end
  352. /* bases ? */
  353.  
  354. if bases ~= 0 then do
  355.  do a = 0 to bases - 1
  356.    rx = random(0,9)
  357.    ry = random(0,9)
  358.    if quad.rx.ry = 0 then quad.rx.ry = 4
  359.    else a=a-1
  360.  end
  361. end
  362. docked = 'no'
  363.  
  364. return
  365.  
  366. /* ********************************************** */
  367. /* ********************************************** */
  368. /*          SUBROUTINE PRINT_QUARDENT             */
  369. /*  PASSED VALUES - x, y ,ex ,ey                  */
  370. /* ********************************************** */
  371. /* ********************************************** */
  372.  
  373. print_quadrent:
  374.  
  375. call dock?  /* check to see if the Enterprize is docked */
  376.  
  377. stardate = stardate + time('E')
  378.  
  379. if status.5 < 1 | docked = 'yes' then astr = bstr
  380. else   astr = 'XXX<*>XXXXXXXXXXXXXXX'
  381. say '          -------------Y->--------------'
  382. do i0 = 0 to 9
  383.  line = '         :'
  384.  do j0 = 0 to 9
  385.   line = line || substr(astr,quad.i0.j0 * 3 + 1,3)
  386.  end
  387.  select
  388.   when i0 = 0 then line = line || ': Stardate 'stardate
  389.   when i0 = 1 then line = line || 'X Energy 'energy
  390.   when i0 = 2 then line = line || ': Quadrent' x',' y
  391.   when i0 = 3 then line = line || ': Sector 'ex',' ey
  392.   when i0 = 4 & docked = 'yes' then line = line || ': CONDITION DOCKED'
  393.   when i0 = 4 & map.x.y > 99 & docked = 'no' then line = line || ': CONDITION RED'
  394.   when i0 = 4 & map.x.y < 100 & docked = 'no' then line = line || ': Condition Green'
  395.   when i0 = 5 then line = line || ': Shields' shields
  396.   when i0 = 6 then line = line || ': Mission' mission
  397.   when i0 = 7 then line = line || ': Klingons left' kltot
  398.   when i0 = 9 then line = line || ': Points' points
  399.   otherwise line = line || ':'
  400.  end
  401. say line
  402. end
  403. say '          ------------------------------'
  404. say ''
  405.  
  406. return
  407.  
  408. /* ********************************************** */
  409. /* ********************************************** */
  410. /*           SUBROUTINE PARSE_COMMAND             */
  411. /*  PASSED VALUES - INSTRING                      */
  412. /* ********************************************** */
  413. /* ********************************************** */
  414.  
  415. parse_command:
  416.  
  417. parse arg arg1.1 arg2.1 arg1.2 arg2.2 arg1.3 arg2.3
  418.  
  419. /* string for recognition of commands */
  420.  
  421. comstr = 'COMFIRTORPHADISMAPSHOSENLONRAILOWSHIWARIMPLAUPROCAPLOGTRASHIDOWSAVGAMINSQUIDRISTAHEL'
  422.  
  423. /* Check for no input */
  424.  
  425. if arg1.1 = '' then return -1
  426.  
  427. /* trash all but the first three letters of each command */
  428.  
  429. do i = 1 to 3
  430.  arg1.i = left(arg1.i,3)
  431.  arg2.i = left(arg2.i,3)
  432.  if arg1.i = '' then leave
  433.  do j = 0 to 27
  434.   if arg1.i = substr(comstr,j * 3 + 1,3) then leave
  435.  end
  436.  if j > 27  then return -1
  437.  if arg2.i = '' then return 0
  438.   do j = 0 to 27
  439.    if arg2.i = substr(comstr,j * 3 + 1,3) then leave
  440.   end
  441.  if j > 27  then return -1
  442. end
  443.  
  444. return 0
  445.  
  446. /* ********************************************** */
  447. /* ********************************************** */
  448. /*           SUBROUTINE PROCESS_COMMAND           */
  449. /*  PASSED VALUES - word1 , word2                 */
  450. /* ********************************************** */
  451. /* ********************************************** */
  452.  
  453. process_command:
  454.  
  455. arg word1,word2
  456. select
  457.   when word1 = 'FIR' then call weapon_control word2
  458.   when word1 = 'COM' then call compute word2
  459.   when word2 = 'SEN' then call sensors word1
  460.   when word2 = 'SHI' then call shield_control word1
  461.   when word2 = 'DRI' then call engine_control word1
  462.   when word1 = 'INS' then call instructions
  463.   when word2 = 'INS' then call instructions
  464.   when word1 = 'HEL' then call instructions
  465.   when word1 = 'SAV' then call save_game word2
  466.   when word1 = 'DIS' then call display_info word2
  467.   when word1 = 'LAU' then call launch_probe word2
  468.   when word1 = 'CAP' then call captains_log word2
  469.   when word1 = 'QUI' then exit
  470.   otherwise say 'Sorry - that function is not ready yet'
  471. end
  472.  
  473. return
  474.  
  475. /* ********************************************** */
  476. /* ********************************************** */
  477. /*           SUBROUTINE WEAPON_CONTROL            */
  478. /*  PASSED VALUES - weapon                        */
  479. /* ********************************************** */
  480. /* ********************************************** */
  481.  
  482. weapon_control:
  483.  
  484. arg weapon
  485.  
  486. if (weapon ~= 'PHA') & (weapon ~= 'TOR') then do
  487.    say ''
  488.    say 'You want to fire what? What the hell is that?'
  489.    return
  490.   end
  491.  
  492. /* Phasers section */
  493.  
  494. if weapon = 'PHA' then do
  495.   if map.x.y < 100 then do
  496.     say ''
  497.     say 'Excuse me captain but there really is nothing to fire on!'
  498.     say ''
  499.     return
  500.    end
  501.  
  502.  /* compute the distance  between Enterprize and Klingon */
  503.  
  504.  kx = 0
  505.  ky = 0
  506.  do i = 0 to 9
  507.   do j = 0 to 9
  508.    if quad.i.j = 3 then do
  509.      kx = i
  510.      ky = j
  511.     end
  512.   end
  513.  end
  514. /* compute the distance (rough approximation) */
  515.  distance = ((ex-kx)**2 + (ey-ky)**2)
  516.  do i = 1 to 13 by .5
  517.   t0 = distance/i
  518.   if t0 < i then leave
  519.  end
  520.  distance = i
  521.  energy = energy - 5000
  522.  hit = (1 - status.1)* 5000 - (distance * 500)
  523.  if hit < 0 then hit = 0
  524.  klshields = klshields - hit
  525.  say ''
  526.  say 'PHASERS LOCKED ON TARGET CAPTAIN'
  527.  say ''
  528.  say 'Phasers fired - '
  529.  if klshields <= 0 then do
  530.     say 'KILINGON HIT WITH -' hit ' units of energy'
  531.     say '*** KLINGON DESTROYED! ***'
  532.     points = points + 50
  533.     klshields = 5000
  534.     quad.kx.ky = 0
  535.     map.x.y = map.x.y - 100
  536.     kltot = kltot - 1
  537.     say ''
  538.     say ''
  539.     say ''
  540.    end
  541.  else
  542.    do
  543.     say 'KILINGON HIT WITH -' hit ' units of energy'
  544.     say ' He is still alive Captain!'
  545.     say ''
  546.     say ''
  547.    end
  548.  end /* end of phaser routine */
  549. else
  550.   /* Torpedo routine */
  551.     do
  552.      say ''
  553.      say 'Torpedoes ready Captain.'
  554.      say ''
  555.      do until c = 0
  556.       say 'Vectors Captain?'
  557.       pull dx dy
  558.       if dx = '' then dx = 0
  559.       if dy = '' then dy = 0
  560.       if (dx = -1 | dx = 0 | dx = 1) & (dy = -1|dy = 0|dy = 1) then c = 0
  561.       else
  562.        do
  563.         c = 1
  564.         say ''
  565.         say 'Jim are you feeling all right? You know what a vector is!'
  566.        end
  567.      end
  568.     tx = ex
  569.     ty = ey
  570.     do lp = 0 to 9
  571.      t0 = tx+dx
  572.      t1 = ty+dy
  573.      if (t0 < 0) | (t0 > 9) | (t1 < 0) | (t1 > 9) then do
  574.        say ''
  575.        say ' Torpedoe missed sir!'
  576.        say ''
  577.        return
  578.       end
  579.      space = quad.t0.t1
  580.      if space ~= 0 then select
  581.        when space = 2 then do
  582.          say '*** Torpedoe hits a STAR ***'
  583.          say ''
  584.          return
  585.         end
  586.        when space = 3 then do
  587.          say '*** Torpedo hits a KLINGON ***'
  588.          say '*** KLINGON DESTROYED ***'
  589.          say 'Good shot Captain!'
  590.          quad.t0.t1 = 0
  591.          map.x.y = map.x.y - 100
  592.          kltot = kltot - 1
  593.          points = points + 100
  594.          return
  595.         end
  596.        when space = 4 then do
  597.          say '*** Torpedoe hits a BASE ***'
  598.          say 'COURT MARTIAL IS IMMENENT!'
  599.          return
  600.         end
  601.        otherwise do
  602.          say '*** Torpedoe hits the DEATHSTAR ***'
  603.          say 'Torpedoe seems to have no affect!'
  604.          return
  605.         end
  606.        end
  607.       quad.t0.t1 = 6
  608.       tx = t0
  609.       ty = t1
  610.       'cls'
  611.       call print_quadrent
  612.       quad.tx.ty = 0
  613.      end
  614.     end
  615. return
  616.  
  617. /* ********************************************** */
  618. /* ********************************************** */
  619. /*           SUBROUTINE WEAR_AND_TEAR             */
  620. /*  PASSED VALUES - none                          */
  621. /* ********************************************** */
  622. /* ********************************************** */
  623.  
  624. wear_and_tear:
  625.  
  626. pick = random(0,5)
  627. if docked = 'yes' then
  628.  if status.pick = 0 then return
  629.  else status.pick = status.pick - .1
  630. else if status.pick < 1 then do
  631.   status.pick = status.pick + .1
  632.   if status.pick = 1 then do
  633.     say 'Status report sir -'
  634.     select
  635.      when pick = 0 then say 'Computer is in need of repair!'
  636.      when pick = 1 then say 'Phasers are in need of repair!'
  637.      when pick = 2 then say 'Torpedoes are in need of repair!'
  638.      when pick = 3 then say 'Warp Drive is in need of repair!'
  639.      when pick = 4 then say 'Impulse Drive is in need of repair!'
  640.      when pick = 5 then say 'Sensors are out of order!'
  641.     end
  642.    if status.3 > .9 & status.4 > .9 then do
  643.      say ''
  644.      say 'Captain sir ... we seem to be dead in space!'
  645.      say 'The warp drive and the impulse drive are out!'
  646.      say ''
  647.      alive = 'no'
  648.     end
  649.   end
  650.  end
  651. return
  652.  
  653.  
  654. /* ********************************************** */
  655. /* ********************************************** */
  656. /*           SUBROUTINE engine_control            */
  657. /*  PASSED VALUES - power                         */
  658. /* ********************************************** */
  659. /* ********************************************** */
  660.  
  661. engine_control:
  662.  
  663. arg power
  664.  
  665. say 'Scotty here captain.'
  666. if power = 'WAR' then do
  667.   if status.3 > 1.2 then return
  668.   say 'What Warp factor Captain?'
  669.   pull warp
  670.   if warp = '' then warp = 0
  671.   do forever
  672.    say 'Destination?'
  673.    parse pull dx ',' dy
  674.    if datatype(dx,'W') & datatype(dy,'W') then leave
  675.    say 'Where?'
  676.   end
  677.    if x > 9 | y < 0 | x  < 0 | y > 9 then do
  678.     energy = energy - 5000
  679.     say 'Captain the warp drive is in a bad way!'
  680.     say 'And we are losing energy fast!'
  681.    end
  682.  /* if warp drive damaged degrade efficiency of energy consumption */
  683.   energy = energy - ((((dx-x)**2 + (dy-y)**2)/2.5)*1000+status.3*5000)
  684.   if dx > 9 | dy < 0 | dx < 0 | dy > 9 then do
  685.      say ''
  686.      say 'Warping out of the galaxy is not a good idea.'
  687.      say ''
  688.      if shields = 'down' then do
  689.         say ' SHIELDS are DOWN --- the ENTERPRIZE is caught, in the void of intergalatic space'
  690.         say ' Damage control report - WARP drive damaged,Impulse drive damaged, sensors out!'
  691.         status.3 = status.3 + 1
  692.         status.4 = status.4 + 1
  693.         status.5 = 1.1
  694.       end
  695.      else energy = energy - 5000
  696.     end
  697.   x = dx
  698.   y = dy
  699.   if x > -1 & x < 10 & y > -1 & y < 10 then call newscreen
  700.   end
  701.  else
  702.   do
  703.    if power ~= 'IMP' | status.4 > .9 then do
  704.      say ''
  705.      say ' Im a sorrye Captin, I canna do That!'
  706.      say ''
  707.      return
  708.     end
  709.    else
  710.     do
  711.      say ''
  712.      say 'Aye Captain - Impulse power it is'
  713.      say 'What factor Captain?'
  714.      do forever
  715.       pull factor
  716.       if datatype(factor,'W') then leave
  717.       say 'Whats that Captain?'
  718.      end
  719.      if factor <= 0 & num = 'yes' then return
  720.      do until c = 0
  721.       say 'Vectors Captain?'
  722.       pull dx dy
  723.       if dx = '' then dx = 0
  724.       if dy = '' then dy = 0
  725.       if (dx = -1 | dx = 0 | dx = 1) & (dy = -1|dy = 0|dy = 1) then c = 0
  726.       else
  727.        do
  728.         c = 1
  729.         say ''
  730.         say 'Jim are you feeling all right? You know what a vector is!'
  731.        end
  732.      end
  733.     do i = 0 to factor - 1
  734.      if ((ex+dx) < 0) | ((ex+dx) > 9) | ((ey+dy) < 0) |((ey+dy) > 9) then
  735.       do
  736.        say ''
  737.        say ' You have to use the Warp drive to exit the quadrent sir!'
  738.        say ''
  739.        return
  740.       end
  741.      t0 = ex+dx
  742.      t1 = ey+dy
  743.      space = quad.t0.t1
  744.      if space ~= 0 then select
  745.        when space = 2 then do
  746.          say '*** COLLISION with STAR ***'
  747.          say 'Its a hot time in the old ship tonight!'
  748.          alive = 'no'
  749.         end
  750.        when space = 3 then do
  751.          say '*** COLLISION with KLINGON ***'
  752.          say 'This wont do your complection any good at all!'
  753.          alive = 'no'
  754.         end
  755.        when space = 4 then do
  756.          say '*** COLLISION with BASE ***'
  757.          say 'I dont think you will see your paycheck this week!'
  758.          alive = 'no'
  759.         end
  760.        otherwise do
  761.          say '*** SWALLOWED BY THE DEATHSTAR ***'
  762.          say 'Johova you are not.'
  763.          alive = 'no'
  764.         end
  765.        end
  766.       quad.ex.ey = 0
  767.       quad.t0.t1 = 1
  768.       ex = t0
  769.       ey = t1
  770.       if alive = 'yes' then do
  771.         'cls'
  772.         call print_quadrent
  773.       end
  774.      end
  775.     end
  776.    end
  777.  
  778. /* Got to check to see if Enterprize is docked */
  779. dock?:
  780.  
  781. docked = 'no'
  782. do i1 = -1 to 1
  783.  do j1 = -1 to 1
  784.   if i1+ex > -1 & i1+ex < 10 & j1+ey > -1 & j1+ey < 10 then do
  785.     ta = i1+ex
  786.     tb = j1+ey
  787.     if quad.ta.tb = 4 then do
  788.  
  789.      docked = 'yes'
  790.      t = status.0 + status.1 + status.2 + status.3 + status.4 + status.5
  791.      stardate = stardate + t
  792.      status.0 = 0
  793.      status.1 = 0
  794.      status.2 = 0
  795.      status.3 = 0
  796.      status.4 = 0
  797.      status.5 = 0
  798.     end
  799.    end
  800.  end
  801. end
  802. if kltot = 0 then missstat = 'completed'
  803.  
  804. return
  805.  
  806. /* ********************************************** */
  807. /* ********************************************** */
  808. /*           SUBROUTINE SAVE_GAME                 */
  809. /*  PASSED VALUES - filename                      */
  810. /* ********************************************** */
  811. /* ********************************************** */
  812.  
  813. save_game:
  814.  
  815. arg file
  816.  
  817. if file = 'GAM' then
  818.  do
  819.   say 'Enter filename'
  820.   pull fn
  821.   if fn = '' then fn = 'startrek.saved'
  822.  end
  823. else fn = 'startrek.saved'
  824.  
  825. missstat = 'not yet'
  826.  
  827. /* save variables */
  828.  
  829.  
  830.  if ~Open(fnn,fn,'W') then do
  831.   say '***Open return code = ' rc
  832.   say 'File may be in use, or is unable to be opened. Try again.'
  833.   return
  834.  end
  835.  
  836. say 'Saving startrek in file ' fn
  837.  push stardate mission energy points x y ex ey shields klshields docked kltot
  838.  pull outt
  839.  if Writeln(fnn,outt) < 1 then exit -99
  840.  push status.0 status.1 status.2 status.3 status.4 status.5
  841.  pull outt
  842.  if Writeln(fnn,outt) < 1 then exit -99
  843.  
  844. /* Load galactic map */
  845.  
  846.  do l = 0 to 9
  847.   push map.l.0 map.l.1 map.l.2 map.l.3 map.l.4
  848.   push map.l.5 map.l.6 map.l.7 map.l.8 map.l.9
  849.   pull outt
  850.   if Writeln(fnn,outt) < 1 then exit -99
  851.   pull outt
  852.   if Writeln(fnn,outt) < 1 then exit -99
  853.  end
  854.  
  855.  do l = 0 to 9
  856.   push quad.l.0 quad.l.1 quad.l.2 quad.l.3 quad.l.4
  857.   push quad.l.5 quad.l.6 quad.l.7 quad.l.8 quad.l.9
  858.   pull outt
  859.   if Writeln(fnn,outt) < 1 then exit -99
  860.   pull outt
  861.   if Writeln(fnn,outt) < 1 then exit -99
  862.  end
  863.  if ~Close(fnn) then exit -99
  864. return
  865.  
  866. /* ********************************************** */
  867. /* ********************************************** */
  868. /*           SUBROUTINE SENSORS                   */
  869. /*  PASSED VALUES - type                          */
  870. /* ********************************************** */
  871. /* ********************************************** */
  872.  
  873. sensors:
  874.  
  875. arg type
  876.  
  877. if type = 'LON' & status.5 < 1.1 then do
  878.   do i = -1 to 1
  879.    say '-------------------'
  880.    line = ': '
  881.    do j = -1 to 1
  882.      t0 = x+i
  883.      t1 = y+j
  884.      if t0 < 0 | t0 > 9 | t1 < 0 | t1 > 9 then line = line || 'XXX :'
  885.      else
  886.       do
  887.        if map.t0.t1 < 100 & map.t0.t1 > 9 then line = line || ' '
  888.        if map.t0.t1 < 10 then line = line || '  '
  889.        line = line || map.t0.t1 || ' :'
  890.       end
  891.    end
  892.    say line
  893.   end
  894.  end
  895. else
  896.   if status.5 > 1 then do
  897.     say ' Long-range Sensors are out captain !!'
  898.     say ''
  899.    end
  900.   else say ' Sense this ....'
  901.  say '-------------------'
  902.  
  903. return
  904.  
  905.  
  906. /* ********************************************** */
  907. /* ********************************************** */
  908. /*           SUBROUTINE SHIELD_CONTROL            */
  909. /*  PASSED VALUES - direction                     */
  910. /* ********************************************** */
  911. /* ********************************************** */
  912.  
  913. shield_control:
  914.  
  915. arg direction
  916.  
  917. if direction = 'RAI' then
  918.  if shields = 'UP' then do
  919.    say 'But the shields are already up Captain!'
  920.    say ''
  921.    say ''
  922.   end
  923.  else
  924.   do
  925.    shields = 'UP'
  926.    say 'Deflectors up Captain'
  927.    energy = energy - 3000
  928.   end
  929. else
  930.  if direction = 'LOW' then
  931.   if shields = 'down' then do
  932.     say 'But the shields are already down Captain!'
  933.     say ''
  934.     say ''
  935.    end
  936.   else
  937.    do
  938.     shields = 'down'
  939.     say 'Shields down Captain'
  940.     energy = energy + 3000
  941.    end
  942.  else
  943.   do
  944.    say ' I am confused by that order Captain.'
  945.    return
  946.   end
  947. return
  948.  
  949. /* ********************************************** */
  950. /* ********************************************** */
  951. /*           SUBROUTINE DISPLAY_INFO              */
  952. /*  PASSED VALUES - what                          */
  953. /* ********************************************** */
  954. /* ********************************************** */
  955.  
  956. display_info:
  957.  
  958. arg what
  959.  
  960. if what = 'STA' then do
  961.   'cls'
  962.   say ''
  963.   say ' Status report for Enterprize - Stardate ' stardate
  964.   say ' ----------------------------------'
  965.   c = 100 - status.0*100
  966.   say ' Computer      status ' c'%'
  967.   say ' ----------------------------------'
  968.   c = 100 - status.1*100
  969.   say ' Phasers       status ' c'%'
  970.   say ' ----------------------------------'
  971.   c = 100 - status.2*100
  972.   say ' Torpedoes     status ' c'%'
  973.   say ' ----------------------------------'
  974.   c = 100 - status.3*100
  975.   say ' Warp drive    status ' c'%'
  976.   say ' ----------------------------------'
  977.   c = 100 - status.4*100
  978.   say ' Impulse drive status ' c'%'
  979.   say ' ----------------------------------'
  980.   c = 100 - status.5*100
  981.   say ' Sensors       status ' c'%'
  982.   say ' ----------------------------------'
  983.   'wait 10 sec'
  984.  end
  985. else say 'Sorry Captain ... that has not been installed yet!'
  986. return
  987.  
  988. /* ********************************************** */
  989. /* ********************************************** */
  990. /*           SUBROUTINE INSTRUCTIONS              */
  991. /*  PASSED VALUES - none                          */
  992. /* ********************************************** */
  993. /* ********************************************** */
  994.  
  995. instructions:
  996.  
  997. 'cls'
  998. say 'STARTREK INSTRUCTIONS'
  999. say ''
  1000. say 'Welcome to the world of Startrek! I hope you have a nice stay.'
  1001. say 'These instructions are not complete yet, because the game is'
  1002. say 'still evolving, but you should get the jist of things.'
  1003. say ''
  1004. say 'YOUR MISSION:'
  1005. say ' There are plans for 10 different missions in the game. Your'
  1006. say 'job will be to complete them as best as you can and accumulate'
  1007. say 'as many points as possible. Points are awarded based on the'
  1008. say 'mission objective.'
  1009. say ''
  1010. say 'THE SCREEN:'
  1011. say ' Firstoff the screen is a 10 by 10 matrix with 0,0 being in the'
  1012. say 'upper left hand corner and 9,9 in the lower right. The horizontal'
  1013. say 'axis is the first number and the vertical is the second for spacial
  1014. '
  1015. say 'representations. This also goes for the galaxy matrix as a hole.'
  1016. say ' Second is the status conditions on the right hand side of the'
  1017. say 'screen whitch depicts some useful information at a glance. If you'
  1018. say 'are familiar with the STARTREK series at all they are self explanatory'
  1019. say '                                             hit return to continue '
  1020. pull junk
  1021. 'cls'
  1022. say 'THE COMMAND LINE:'
  1023. say ' The command line will accept english words for actions you wish'
  1024. say 'to do. For example if you wish to shoot at a klingon all you have'
  1025. say 'to say is "fire phasers". There is a two word limit for any'
  1026. say 'particular command and a three command limit.'
  1027. say 'What follows are some of the words STARTREK will recognize.'
  1028. say ''
  1029. say ' RAISE  WARP     DISPLAY     CAPTAIN  LAUNCH  TRANSPORT    SHIP'
  1030. say ' FIRE   IMPULSE  SHORT_RANGE COMPUTER PHASERS LONG_RANGE   DOWN'
  1031. say ' LOG    PROBE    TORPEDOES   LOWER    HELP    INSTRUCTIONS SAVE'
  1032. say ' GAME   QUIT     STATUS      MAP      SENSORS DRIVE        SHIELDS'
  1033. say ''
  1034. say 'These are all that STARTREK will understand currently and some'
  1035. say 'have as of yet not been implemented.'
  1036. say 'Certain commands such as QUIT, SAVE, HELP, INSTRUCTIONS are'
  1037. say 'single word commands. The descriptions of these four follow.'
  1038. say ''
  1039. say 'QUIT : Terminates the game with extreme predjudice.'
  1040. say ''
  1041. say 'SAVE {GAME} : saves startrek for future play.'
  1042. say '                                             hit return to continue '
  1043. pull junk
  1044. 'cls'
  1045. say 'SAVE {GAME} continued'
  1046. say 'If the option GAME is entered you will be prompted for a filename.'
  1047. say 'If SAVE is entered without arguments {eg GAME} then the file is'
  1048. say 'saved in a CMS file called STARTREK SAVED A.'
  1049. say ''
  1050. say 'HELP or INSTRUCTIONS: this must be obvious since you are running'
  1051. say 'this routine (duh).'
  1052. say ''
  1053. say 'IN ORDER TO STAY ALIVE you must NOT, run out of energy, exceed'
  1054. say 'Stardate 5000.0 for each mission, or be caught with your'
  1055. say 'gaurd down (hint).'
  1056. say ''
  1057. say 'One final note: commands are only checked for the first three'
  1058. say 'characters in each string and the rest is ignored.'
  1059. say ''
  1060. say 'Well (as Ronnie would say) may the Force be with you!'
  1061. say ''
  1062. say ' Whoops wrong decade! Anyway good luck!'
  1063. say '                                             hit return to continue'
  1064. pull junk
  1065. 'cls'
  1066. return
  1067.  
  1068. /* ********************************************** */
  1069. /* ********************************************** */
  1070. /*           SUBROUTINE CAPTAINS_LOG              */
  1071. /*  PASSED VALUES - word2                         */
  1072. /* ********************************************** */
  1073. /* ********************************************** */
  1074.  
  1075. captains_log:
  1076.  
  1077. say 'Sorry, I havent done this command yet! Any suggestions?'
  1078.  
  1079. return
  1080.  
  1081. /* ********************************************** */
  1082. /* ********************************************** */
  1083. /*           SUBROUTINE LAUNCH_PROBE              */
  1084. /*  PASSED VALUES - word2                         */
  1085. /* ********************************************** */
  1086. /* ********************************************** */
  1087.  
  1088. launch_probe:
  1089.  
  1090. say 'Sorry, I havent done this command yet! Any suggestions?'
  1091.  
  1092. return
  1093.  
  1094. /* ********************************************** */
  1095. /* ********************************************** */
  1096. /*           SUBROUTINE COMPUTE                   */
  1097. /*  PASSED VALUES - word2                         */
  1098. /* ********************************************** */
  1099. /* ********************************************** */
  1100.  
  1101. compute:
  1102.  
  1103. say 'Sorry, I havent done this command yet! Any suggestions?'
  1104.  
  1105. return
  1106.  
  1107. /* ********************************************** */
  1108. /* ********************************************** */
  1109. /*           SUBROUTINE MISSION1                  */
  1110. /*  PASSED VALUES - none                          */
  1111. /* ********************************************** */
  1112. /* ********************************************** */
  1113.  
  1114. mission1:
  1115.  
  1116. /* make the klingons active aggressors */
  1117. /* Mission 1 - WAR with the KLINGONS! */
  1118.  
  1119. /* Any Klingons in the sector? */
  1120.  
  1121. if map.x.y > 99 then do
  1122.   do i = 0 to 9     /* locate the klingon in the quadrent */
  1123.    do j = 0 to 9
  1124.     if quad.i.j = 3 then
  1125.      do
  1126.       tx = i
  1127.       ty = j
  1128.      end
  1129.    end
  1130.   end
  1131.  
  1132.  /* got him - now move and fire */
  1133.  if tx > ex then t0 = -1
  1134.  if tx = ex then t0 = 0
  1135.  if tx < ex then t0 = 1
  1136.  if ty > ey then t1 = -1
  1137.  if ty = ey then t1 = 0
  1138.  if ty < ey then t1 = 1
  1139.  /* now how much? */
  1140.  factor = ((tx-ex)**2 + (ty-ey)**2)
  1141.  do i = 1 to 13 by .5
  1142.   tm = factor/i
  1143.   if tm < i then leave
  1144.  end
  1145.  factor = i%1
  1146.  /* now move him */
  1147.  
  1148. kl = 'yes'
  1149.  do i = 0 to factor - 1
  1150.   if factor < 1 then leave
  1151.   t2 = tx+t0
  1152.   t3 = ty+t1
  1153.   if t2 < 0 | t2 > 9 | t3 < 0 | t3 > 9 then leave
  1154.   space = quad.t2.t3
  1155.   if space = 1 then leave
  1156.   if space ~= 0 & kl = 'yes' then select
  1157.     when space = 2 then do
  1158.       say '*** KILINGON COLLIDES with STAR ***'
  1159.       say 'Gee ... that was pretty dumb huh?'
  1160.       quad.tx.ty = 0
  1161.       map.x.y = map.x.y - 100
  1162.       kltot = kltot - 1
  1163.       kl = 'no'
  1164.      end
  1165.     when space = 3 then do
  1166.       say '*** KLINGON COLLIDES with KLINGON ***'
  1167.       say 'Ha ha ha. Wow they are stupid!'
  1168.       quad.tx.ty = 0
  1169.       quad.t2.t3 = 0
  1170.       map.x.y = map.x.y - 200
  1171.       kltot = kltot - 2
  1172.       kl = 'no'
  1173.      end
  1174.     when space = 4 then do
  1175.       say '*** KLINGON COLLIDES with BASE ***'
  1176.       say 'I wonder if they yelled BONZAI!'
  1177.       quad.tx.ty = 0
  1178.       quad.t2.t3 = 0
  1179.       map.x.y = map.x.y - 100
  1180.       kltot = kltot - 1
  1181.       kl = 'no'
  1182.      end
  1183.     otherwise
  1184.      do
  1185.       say space
  1186.       say '*** KLINGON EATEN FOR LUNCH! ***'
  1187.       say 'The deathstar will probably have indesgestion.'
  1188.       points = points + 50
  1189.       quad.tx.ty = 0
  1190.       map.x.y = map.x.y - 100
  1191.       kltot = kltot - 1
  1192.       kl = 'no'
  1193.      end
  1194.    end
  1195.   if kl = 'yes' then do
  1196.     quad.tx.ty = 0
  1197.     quad.t2.t3 = 3
  1198.     tx = t2
  1199.     ty = t3
  1200.     'cls'
  1201.     call print_quadrent
  1202.    end
  1203.  end
  1204. if docked = 'yes' then return
  1205. /* now fire */
  1206. if kl = 'yes' then do
  1207.   amount = klshields/5000 * random(100,500) * 10
  1208.   if amount > 1000 & shields = 'down' then do
  1209.    say ''
  1210.    say '--- KLINGON FIRES PHASERS ---'
  1211.    say '*** ENTERPRIZE SHIELDS ARE DOWN ***'
  1212.    say '*** ENTERPRIZE HIT with 'amount ' UNITS of energy.'
  1213.    say '*** ENTERPRIZE DESTROYED ***'
  1214.    alive = 'no'
  1215.    say ''
  1216.   end
  1217.   if amount < 3000 & shields = 'UP' then do
  1218.    say ''
  1219.    say '--- KLINGON FIRES PHASERS ---'
  1220.    say '*** ENTERPRIZE SHIELDS ARE UP '
  1221.    say '*** DEFLECTORS Absorbe impact --- no Damage ***'
  1222.    say ''
  1223.    energy = energy - amount
  1224.   end
  1225.   if amount > 3000 & shields = 'UP' then do
  1226.    say ''
  1227.    say '--- KLINGON FIRES PHASERS ---'
  1228.    say '*** ENTERPRIZE SHIELDS ARE UP '
  1229.    hit = amount - 3000
  1230.    say '*** ENTERPRIZE HIT WITH' hit ' UNITS OF ENERGY'
  1231.    say ''
  1232.    energy = energy - amount
  1233.    do i = 0 to hit/100
  1234.     call wear_and_tear
  1235.    end
  1236.   end
  1237.   if amount < 1001 & shields = 'down' then do
  1238.     say ''
  1239.     say '--- KLINGON FIRES PHASERS ---'
  1240.     say '*** ENTERPRIZE SHIELDS ARE DOWN '
  1241.     hit = amount
  1242.     say '*** ENTERPRIZE HIT WITH' hit ' UNITS OF ENERGY'
  1243.     say ''
  1244.     do i = 0 to hit/100
  1245.      call wear_and_tear
  1246.     end
  1247.    end
  1248.   end
  1249. end
  1250.  
  1251. /* end for Klingons in sector ... if < 3 here go get some */
  1252.  
  1253. if map.x.y < 299 & alive = 'yes' then do
  1254.  found = 'no'
  1255.  
  1256.   do i = -1 to 1     /* locate a klingon in the Galaxy */
  1257.    do j = -1 to 1
  1258.      tx = i+x
  1259.      ty = j+y
  1260.      if (tx > -1) & (tx < 10) & (ty > -1) & (ty < 10) then do
  1261.        if (map.tx.ty > 99) & ((i ~=0 )|(j ~=0 )) then do
  1262.          found = 'yes'
  1263.          i = 1
  1264.          j = 1
  1265.         end
  1266.       end
  1267.    end
  1268.   end
  1269. if found = 'yes' then do
  1270.   say ' CAPTAIN a Klingon warship has just warped into the quadrent!'
  1271.   map.tx.ty = map.tx.ty - 100
  1272.   map.x.y = map.x.y + 100
  1273.   do until a = 1
  1274.    rx = random(0,9)
  1275.    ry = random(0,9)
  1276.    if quad.rx.ry = 0 then do
  1277.      quad.rx.ry = 3
  1278.      a = 1
  1279.     end
  1280.    else a = 0
  1281.   end
  1282.  end
  1283. end
  1284. if kltot = 0 then missstat = 'completed'
  1285. return
  1286.  
  1287. /* MISSION 2 */
  1288.  
  1289. init_variables_2:
  1290.  
  1291. return
  1292.  
  1293.  
  1294. mission2:
  1295.  
  1296. return
  1297.  
  1298. /* MISSION3 */
  1299.  
  1300. init_variables_3:
  1301.  
  1302. return
  1303.  
  1304. mission3:
  1305.  
  1306.  
  1307. /* MISSION4 */
  1308.  
  1309. init_variables_4:
  1310.  
  1311. return
  1312.  
  1313. mission4:
  1314.  
  1315.  
  1316. /* MISSION5 */
  1317.  
  1318. init_variables_5:
  1319.  
  1320. return
  1321.  
  1322. mission5:
  1323.  
  1324. /* MISSION6 */
  1325.  
  1326. init_variables_6:
  1327.  
  1328. return
  1329.  
  1330. mission6:
  1331.  
  1332. /* MISSION7 */
  1333.  
  1334. init_variables_7:
  1335.  
  1336. return
  1337.  
  1338. mission7:
  1339.  
  1340. /* MISSION8 */
  1341.  
  1342. init_variables_8:
  1343.  
  1344. return
  1345.  
  1346. mission8:
  1347.  
  1348. /* MISSION9 */
  1349.  
  1350. init_variables_9:
  1351.  
  1352. return
  1353.  
  1354. mission9:
  1355.  
  1356. /* MISSION10 */
  1357.  
  1358. init_variables_10:
  1359.  
  1360. return
  1361.  
  1362. mission10:
  1363.  
  1364.