home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / COMMANDS.E < prev    next >
Text File  |  1993-06-08  |  6KB  |  293 lines

  1. -- commands.e
  2. -- process user commands
  3.  
  4. global positive_int nchars
  5.  
  6. positive_int pen
  7.  
  8. type keycode(integer x)  -- input keyboard code
  9.     return x >= -1 and x < 512
  10. end type
  11.  
  12. keycode curcom
  13.  
  14. direction dir
  15.  
  16. type digit_char(integer x)
  17.     return x >= '0' and x <= '9'
  18. end type
  19.  
  20. procedure echo(char com)
  21. -- echo first char of new command
  22.     set_bk_color(WHITE)
  23.     set_color(BLUE)
  24.     position(CMD_LINE, CMD_POS)
  25.     puts(CRT, com)
  26.     puts(CRT, "        ")
  27. end procedure
  28.  
  29. procedure dircom(digit_char dir)
  30. -- process direction change commands
  31.     nchars = 0
  32.     if dir != '9' then
  33.     echo(dir)
  34.     end if
  35.     if reptime[GUIDANCE] then
  36.     errbeep()
  37.     msg("GUIDANCE SYSTEM DAMAGED")
  38.     elsif dir = '1' then
  39.     exi = 3
  40.     eyi = 0
  41.     esym = esymr
  42.     elsif dir = '2' then
  43.     exi = 3
  44.     eyi = -1
  45.     esym = esymr
  46.     elsif dir = '3' then
  47.     exi = 0
  48.     eyi = -1
  49.     elsif dir = '4' then
  50.     exi = -3
  51.     eyi = -1
  52.     esym = esyml
  53.     elsif dir = '5' then
  54.     exi = -3
  55.     eyi = 0
  56.     esym = esyml
  57.     elsif dir = '6' then
  58.     exi = -3
  59.     eyi = 1
  60.     esym = esyml
  61.     elsif dir = '7' then
  62.     exi = 0
  63.     eyi = 1
  64.     elsif dir = '8' then
  65.     exi = 3
  66.     eyi = 1
  67.     esym = esymr
  68.     end if
  69. end procedure
  70.  
  71. function docom(keycode com, keycode chr)
  72. -- process commands
  73.     positive_int t
  74.  
  75.     set_bk_color(WHITE)
  76.     set_color(BLUE)
  77.     if com = 'p' then      -- phasor
  78.     if nchars = 0 then
  79.         echo(chr)
  80.         nchars = 1
  81.     elsif nchars = 1 then
  82.         position(CMD_LINE, CMD_POS+2)
  83.         pen = 100 * (chr - '0')
  84.         printf(CRT, "%s00", chr)
  85.         nchars = 2
  86.     elsif nchars = 2 then
  87.         position(CMD_LINE, CMD_POS+6)
  88.         printf(CRT, "%s.", chr)
  89.         dir = chr - '0'
  90.         nchars = 3
  91.     else
  92.         position(CMD_LINE, CMD_POS+8)
  93.         puts(CRT, chr)
  94.         if reptime[PHASORS] then
  95.         errbeep()
  96.         msg("PHASORS DAMAGED")
  97.         else
  98.         dir = dir + (chr - '0')/10
  99.         p_energy(-pen)
  100.         esetpt(dir)
  101.         weapon(W_PHASOR, pen)
  102.         end if
  103.         nchars = 0
  104.     end if
  105.  
  106.     elsif com = 'w' then    -- warp change
  107.     if nchars = 0 then
  108.         echo(chr)
  109.         nchars = 1
  110.     else
  111.         if chr < '6' then
  112.         position(CMD_LINE, CMD_POS+2)
  113.         puts(CRT, chr)
  114.         nchars = 0
  115.         if wlimit then
  116.             position(WARP_LINE, 8)
  117.             puts(CRT, chr)
  118.             setwarp(chr - '0')
  119.         else
  120.             errbeep()
  121.             msg("ALL ENGINES DAMAGED")
  122.         end if
  123.         end if
  124.     end if
  125.  
  126.     elsif com = 't' then    -- torpedo
  127.     if nchars = 0 then
  128.         echo(chr)
  129.         nchars = 1
  130.     elsif nchars = 1 then
  131.         position(CMD_LINE, CMD_POS+2)
  132.         printf(CRT, "%s.", chr)
  133.         dir = chr - '0'
  134.         nchars = 2
  135.     else
  136.         position(CMD_LINE, CMD_POS+4)
  137.         puts(CRT, chr)
  138.         dir = dir + (chr - '0')/10
  139.         if reptime[TORPEDOS] then
  140.         errbeep()
  141.         msg("TORPEDO LAUNCHER DAMAGED")
  142.         else
  143.         t = f[ENTERPRISE][F_TORP]
  144.         if t then
  145.             t = t - 1
  146.             f[ENTERPRISE][F_TORP] = t
  147.             ts = ts[2..length(ts)]
  148.             wtext()
  149.             esetpt(dir)
  150.             weapon(W_TORPEDO, 4000)
  151.         else
  152.             errbeep()
  153.             msg("OUT OF TORPEDOS")
  154.         end if
  155.         end if
  156.         nchars = 0
  157.     end if
  158.  
  159.     elsif com = 'g' then    -- galaxy scan
  160.     chr = ' '
  161.     echo(chr)
  162.     if scanon then
  163.         setg1()
  164.     else
  165.         if reptime[GALAXY_SENSORS] then
  166.         errbeep()
  167.         msg("SENSORS DAMAGED")
  168.         else
  169.         set_bk_color(BLUE)
  170.         set_color(WHITE)
  171.         BlankScreen(FALSE)
  172.         scanon = TRUE
  173.         for r = 1 to G_SIZE do
  174.             for c = 1 to G_SIZE do
  175.             gquad(r, c)
  176.             end for
  177.         end for
  178.         gtext()
  179.         dsyms()
  180.         gsbox(qrow, qcol)
  181.         set_bk_color(0)
  182.         end if
  183.     end if
  184.     nchars = 0
  185.  
  186.     elsif com = 'a' then   -- antimatter pod
  187.     if nchars = 0 then
  188.         echo(chr)
  189.         nchars = 1
  190.     elsif nchars = 1 then
  191.         position(CMD_LINE, CMD_POS+2)
  192.         printf(CRT, "%s.", chr)
  193.         dir = chr - '0'
  194.         nchars = 2
  195.     else
  196.         position(CMD_LINE, CMD_POS+4)
  197.         puts(CRT, chr)
  198.         dir = dir + (chr - '0')/10
  199.         if length(ps) > 0 then
  200.         ps = ps[2..length(ps)]
  201.         wtext()
  202.         esetpt(dir)
  203.         weapon(W_POD, 1500)
  204.         else
  205.         errbeep()
  206.         msg("OUT OF PODS")
  207.         end if
  208.         nchars = 0
  209.     end if
  210.  
  211.     elsif com = '$' then   -- shuttlecraft
  212.     echo(chr)
  213.     if not gal then
  214.         sounde(15, 20, 1)
  215.         if esym[1] = esymr[1] then
  216.         esym = SHUTTLE_R
  217.         else
  218.         esym = SHUTTLE_L
  219.         end if
  220.         esyml = SHUTTLE_L
  221.         esymr = SHUTTLE_R
  222.         otype[G_EN] = "SHUTTLE"
  223.         write_screen(f[ENTERPRISE][F_X], f[ENTERPRISE][F_Y], esym)
  224.         for r = 1 to NSYS do
  225.         if reptime[r] then
  226.             reptime[r] = 0
  227.             repair(r)
  228.         end if
  229.         end for
  230.         f[ENTERPRISE][F_DEFL] = 1
  231.         ds = repeat(DEFLECTOR, 1)
  232.         f[ENTERPRISE][F_TORP] = 0
  233.         f[ENTERPRISE][F_EN] = 5000
  234.         ts = ""
  235.         ps = ""
  236.         wtext()
  237.         puts(CRT, "         ")
  238.         gal = TRUE
  239.         p_energy(0)
  240.     end if
  241.  
  242.     elsif com = 'x' then   -- cancel
  243.     chr = ' '
  244.     echo(chr)
  245.     nchars = 0
  246.  
  247.     elsif com = '@' then   -- pause
  248.     while get_key() != 'x' do
  249.     end while
  250.     -- need to adjust scheduler time to avoid
  251.     -- all tasks being ready to go ?
  252.     nchars = 0
  253.  
  254.     else
  255.     return FALSE
  256.  
  257.     end if
  258.  
  259.     return TRUE
  260. end function
  261.  
  262. without warning
  263. global procedure t1keyb()
  264. -- task 1: check the keyboard for input - perform the command
  265.     boolean x
  266.     positive_int tempchars
  267.     keycode chr
  268.  
  269.     while TRUE do
  270.     chr = get_key()
  271.     if not char(chr) then
  272.         exit
  273.     end if
  274.     if chr >= '0' and chr <= '9' then
  275.         if nchars then
  276.         x = docom(curcom, chr)
  277.         else
  278.         dircom(chr)
  279.         end if
  280.     else
  281.         tempchars = nchars
  282.         nchars = 0
  283.         if docom(chr, chr) then
  284.         curcom = chr
  285.         else
  286.         nchars = tempchars
  287.         end if
  288.     end if
  289.     end while
  290. end procedure
  291. with warning
  292.  
  293.