home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / commands.e < prev    next >
Text File  |  1994-01-08  |  7KB  |  352 lines

  1. -- commands.e
  2. -- process user commands
  3.  
  4. global natural nchars
  5.  
  6. natural pen
  7.  
  8. type keycode(integer x)  
  9. -- a keyboard code
  10.     return x >= -1 and x < 512
  11. end type
  12.  
  13. keycode curcom
  14.  
  15. direction dir
  16.  
  17. type digit_char(integer x)
  18.     return x >= '0' and x <= '9'
  19. end type
  20.  
  21. procedure echo(char com)
  22. -- echo first char of new command
  23.     set_bk_color(WHITE)
  24.     set_color(BLUE)
  25.     position(CMD_LINE, CMD_POS)
  26.     puts(CRT, com)
  27.     puts(CRT, "        ")
  28.     position(CMD_LINE, CMD_POS + 2)
  29. end procedure
  30.  
  31. procedure dircom(digit_char dir)
  32. -- process direction change commands
  33.     nchars = 0
  34.     if reptime[GUIDANCE] then
  35.     errbeep()
  36.     msg("GUIDANCE SYSTEM DAMAGED")
  37.     return
  38.     end if
  39.  
  40.     if dir = '9' then
  41.     dir = '1'
  42.     elsif dir = '0' then
  43.     dir = '8'
  44.     end if  
  45.  
  46.     echo(dir)
  47.     curdir = dir - '0'
  48.     dir_box()
  49.  
  50.     if dir = '1' then
  51.     exi = 3
  52.     eyi = 0
  53.     esym = esymr
  54.     elsif dir = '2' then
  55.     exi = 3
  56.     eyi = -1
  57.     esym = esymr
  58.     elsif dir = '3' then
  59.     exi = 0
  60.     eyi = -1
  61.     elsif dir = '4' then
  62.     exi = -3
  63.     eyi = -1
  64.     esym = esyml
  65.     elsif dir = '5' then
  66.     exi = -3
  67.     eyi = 0
  68.     esym = esyml
  69.     elsif dir = '6' then
  70.     exi = -3
  71.     eyi = 1
  72.     esym = esyml
  73.     elsif dir = '7' then
  74.     exi = 0
  75.     eyi = 1
  76.     elsif dir = '8' then
  77.     exi = 3
  78.     eyi = 1
  79.     esym = esymr
  80.     end if
  81. end procedure
  82.  
  83. function docom(keycode com, keycode chr)
  84. -- process commands
  85.     natural t
  86.     positive_atom t_stop
  87.  
  88.     set_bk_color(WHITE)
  89.     set_color(BLUE)
  90.     if com = 'p' then      -- phasor
  91.     if nchars = 0 then
  92.         echo(chr)
  93.         set_color(BLUE+BLINKING)
  94.         puts(CRT, '_')
  95.         set_color(BLUE)
  96.         puts(CRT, "00 _._ ")
  97.         nchars = 1
  98.     elsif nchars = 1 then
  99.         position(CMD_LINE, CMD_POS+2)
  100.         pen = 100 * (chr - '0')
  101.         puts(CRT, chr)
  102.         position(CMD_LINE, CMD_POS+6)
  103.         set_color(BLUE+BLINKING)
  104.         puts(CRT, '_')
  105.         nchars = 2
  106.     elsif nchars = 2 then
  107.         position(CMD_LINE, CMD_POS+6)
  108.         if chr = '0' then
  109.         chr = '8'
  110.         elsif chr = '9' then
  111.         chr = '1'
  112.         end if
  113.         puts(CRT, chr)
  114.         position(CMD_LINE, CMD_POS+8)
  115.         set_color(BLUE+BLINKING)
  116.         puts(CRT, '_')
  117.         dir = chr - '0'
  118.         nchars = 3
  119.     else
  120.         position(CMD_LINE, CMD_POS+8)
  121.         puts(CRT, chr)
  122.         if reptime[PHASORS] then
  123.         errbeep()
  124.         msg("PHASORS DAMAGED")
  125.         elsif quadrant[EUPHORIA][Q_EN] <= pen then
  126.         errbeep()
  127.         msg("NOT ENOUGH ENERGY")
  128.         else
  129.         dir = dir + (chr - '0')/10
  130.         p_energy(-pen)
  131.         esetpt(dir)
  132.         weapon(W_PHASOR, pen)
  133.         end if
  134.         nchars = 0
  135.     end if
  136.  
  137.     elsif com = 'w' then    -- warp change
  138.     if nchars = 0 then
  139.         echo(chr)
  140.         nchars = 1
  141.         set_color(BLUE+BLINKING)
  142.         puts(CRT, '_')
  143.     else
  144.         if chr < '6' then
  145.         position(CMD_LINE, CMD_POS+2)
  146.         puts(CRT, chr)
  147.         nchars = 0
  148.         if wlimit then
  149.             position(WARP_LINE, WARP_POS+5)
  150.             puts(CRT, chr)
  151.             setwarp(chr - '0')
  152.         else
  153.             errbeep()
  154.             msg("ALL ENGINES DAMAGED")
  155.         end if
  156.         end if
  157.     end if
  158.  
  159.     elsif com = 't' then    -- torpedo
  160.     if nchars = 0 then
  161.         echo(chr)
  162.         nchars = 1
  163.         set_color(BLUE+BLINKING)
  164.         puts(CRT, '_')
  165.         set_color(BLUE)
  166.         puts(CRT, "._")
  167.     elsif nchars = 1 then
  168.         position(CMD_LINE, CMD_POS+2)
  169.         if chr = '0' then
  170.         chr = '8'
  171.         elsif chr = '9' then
  172.         chr = '1'
  173.         end if
  174.         puts(CRT, chr)
  175.         position(CMD_LINE, CMD_POS+4)
  176.         set_color(BLUE+BLINKING)
  177.         puts(CRT, '_')
  178.         dir = chr - '0'
  179.         nchars = 2
  180.     else
  181.         position(CMD_LINE, CMD_POS+4)
  182.         puts(CRT, chr)
  183.         dir = dir + (chr - '0')/10
  184.         if reptime[TORPEDOS] then
  185.         errbeep()
  186.         msg("TORPEDO LAUNCHER DAMAGED")
  187.         else
  188.         t = quadrant[EUPHORIA][Q_TORP]
  189.         if t then
  190.             t = t - 1
  191.             quadrant[EUPHORIA][Q_TORP] = t
  192.             ts = ts[2..length(ts)]
  193.             wtext()
  194.             esetpt(dir)
  195.             weapon(W_TORPEDO, 4000)
  196.         else
  197.             errbeep()
  198.             msg("OUT OF TORPEDOS")
  199.         end if
  200.         end if
  201.         nchars = 0
  202.     end if
  203.  
  204.     elsif com = 'g' then    -- galaxy scan
  205.     echo(chr)
  206.     if scanon then
  207.         setg1()
  208.     else
  209.         if reptime[GALAXY_SENSORS] then
  210.         errbeep()
  211.         msg("SENSORS DAMAGED")
  212.         else
  213.         set_bk_color(BLUE)
  214.         set_color(WHITE)
  215.         BlankScreen(FALSE)
  216.         scanon = TRUE
  217.         for r = 1 to G_SIZE do
  218.             for c = 1 to G_SIZE do
  219.             gquad(r, c)
  220.             end for
  221.         end for
  222.         gtext()
  223.         gsbox(qrow, qcol)
  224.         set_bk_color(BLACK)
  225.         end if
  226.     end if
  227.     nchars = 0
  228.  
  229.     elsif com = 'a' then   -- antimatter pod
  230.     if nchars = 0 then
  231.         echo(chr)
  232.         nchars = 1
  233.         set_color(BLUE+BLINKING)
  234.         puts(CRT, '_')
  235.         set_color(BLUE)
  236.         puts(CRT, "._")
  237.     elsif nchars = 1 then
  238.         position(CMD_LINE, CMD_POS+2)
  239.         if chr = '0' then
  240.         chr = '8'
  241.         elsif chr = '9' then
  242.         chr = '1'
  243.         end if
  244.         puts(CRT, chr)
  245.         position(CMD_LINE, CMD_POS+4)
  246.         set_color(BLUE+BLINKING)
  247.         puts(CRT, '_')
  248.         dir = chr - '0'
  249.         nchars = 2
  250.     else
  251.         position(CMD_LINE, CMD_POS+4)
  252.         puts(CRT, chr)
  253.         set_color(BLUE+BLINKING)
  254.         puts(CRT, " Enter")
  255.         dir = dir + (chr - '0')/10
  256.         if length(ps) > 0 then
  257.         ps = ps[2..length(ps)]
  258.         wtext()
  259.         esetpt(dir)
  260.         weapon(W_POD, 1500)
  261.         else
  262.         errbeep()
  263.         msg("OUT OF PODS")
  264.         end if
  265.         nchars = 0
  266.     end if
  267.  
  268.     elsif com = '$' then   -- shuttlecraft
  269.     echo(chr)
  270.     if not shuttle then
  271.         if esym[1] = esymr[1] then
  272.         esym = SHUTTLE_R
  273.         else
  274.         esym = SHUTTLE_L
  275.         end if
  276.         esyml = SHUTTLE_L
  277.         esymr = SHUTTLE_R
  278.         otype[G_EU] = "SHUTTLE"
  279.         write_screen(quadrant[EUPHORIA][Q_X], 
  280.                  quadrant[EUPHORIA][Q_Y], esym)
  281.         for r = 1 to NSYS do
  282.         if reptime[r] then
  283.             reptime[r] = 0
  284.             repair(r)
  285.         end if
  286.         end for
  287.         quadrant[EUPHORIA][Q_DEFL] = 1
  288.         ds = repeat(DEFLECTOR, 1)
  289.         quadrant[EUPHORIA][Q_TORP] = 0
  290.         quadrant[EUPHORIA][Q_EN] = 5000
  291.         ts = ""
  292.         ps = ""
  293.         wtext()
  294.         puts(CRT, "         ")
  295.         shuttle = TRUE
  296.         p_energy(0)
  297.     end if
  298.  
  299.     elsif com = 'x' then   -- cancel
  300.     chr = ' '
  301.     echo(chr)
  302.     nchars = 0
  303.  
  304.     elsif com = '!' then   -- pause
  305.     echo(chr)
  306.     t_stop = time()
  307.     while get_key() != 'x' do
  308.     end while
  309.     tcb = tcb + time() - t_stop -- adjust all task activation times
  310.     echo(' ')
  311.     nchars = 0
  312.  
  313.     else
  314.     return FALSE
  315.  
  316.     end if
  317.  
  318.     return TRUE
  319. end function
  320.  
  321. without warning
  322. global procedure task_keyb()
  323. -- independent task: check the keyboard for command input
  324.     boolean x
  325.     natural tempchars
  326.     keycode chr
  327.  
  328.     while TRUE do
  329.     chr = get_key()
  330.     if not char(chr) then
  331.         exit
  332.     end if
  333.     if chr >= '0' and chr <= '9' then
  334.         if nchars then
  335.         x = docom(curcom, chr)
  336.         else
  337.         dircom(chr)
  338.         end if
  339.     else
  340.         tempchars = nchars
  341.         nchars = 0
  342.         if docom(chr, chr) then
  343.         curcom = chr
  344.         else
  345.         nchars = tempchars
  346.         end if
  347.     end if
  348.     end while
  349. end procedure
  350. with warning
  351.  
  352.