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

  1. -- emove.e
  2. -- move the Euphoria
  3.  
  4. -- Energy consumed per ship movement at warp 0 thru 5.
  5. -- WARP 4 is the most efficient after you take life support
  6. -- energy into account. WARP 5 is good if you can use it to avoid
  7. -- getting blasted.
  8. constant fuel = {0, 5, 8, 12, 30, 80}
  9.  
  10. global function gmod(natural x)
  11. -- quadrant wraparound
  12.     if x = 0 then
  13.     return G_SIZE
  14.     elsif x > G_SIZE then
  15.     return 1
  16.     else
  17.     return x
  18.     end if
  19. end function
  20.  
  21.  
  22. constant ZERO_FILL = repeat(0, QCOLS-7)
  23.  
  24. -- standard row in quadrant array for a type
  25. global constant stdtype =
  26. -- TYPE    EN    TORP    DEFL  FRATE  MRATE   TARG
  27. {{}, -- dummy (Euphoria)
  28.  {G_KRC,  4000,  1,       0,   100,   140,  EUPHORIA} & ZERO_FILL, -- K&R C
  29.  {G_ANC,  8000,  2,       0,   100,   180,  EUPHORIA} & ZERO_FILL, -- ANSI C
  30.  {G_CPP, 20000,  4,       0,   150,   250,  EUPHORIA} & ZERO_FILL, -- C++
  31.  {G_BAS,  2000,  1,       0,    70,   150,  EUPHORIA} & ZERO_FILL, -- BASIC
  32.  {G_FOR,  3000,  0,       0,    40,    80,   -1}      & ZERO_FILL, -- Fortran
  33.  {G_PL,   5000,  0,       0,     0,     0,   -1}      & ZERO_FILL, -- planet
  34.  {G_BS,   6000,  3,       1,   120,     0,   -1}      & ZERO_FILL  -- base
  35. }
  36. procedure setup_quadrant()
  37. -- set up quadrant sequence for a new quadrant
  38.  
  39.     sequence g_info
  40.  
  41.     g_info = galaxy[qrow][qcol]
  42.     quadrant = quadrant[EUPHORIA..EUPHORIA]
  43.  
  44.     for i = 1 to g_info[G_PL] do
  45.     quadrant = append(quadrant, stdtype[G_PL])
  46.     end for
  47.  
  48.     for i = 1 to g_info[G_BS] do
  49.     quadrant = append(quadrant, stdtype[G_BS])
  50.     end for
  51.  
  52.     basic_targ = -1
  53.     for i = 1 to g_info[G_BAS] do
  54.     quadrant = append(quadrant, stdtype[G_BAS])
  55.     quadrant[length(quadrant)][Q_UNDER] = 
  56.                 repeat(' ', length(ship[G_BAS][1]))
  57.     basic_targ = EUPHORIA
  58.     end for
  59.  
  60.     for i = 1 to g_info[G_FOR] do
  61.     quadrant = append(quadrant, stdtype[G_FOR])
  62.     quadrant[length(quadrant)][Q_UNDER] = 
  63.                 repeat(' ', length(ship[G_FOR][1]))
  64.     end for
  65.  
  66.     for i = 1 to g_info[G_CPP] do
  67.     quadrant = append(quadrant, stdtype[G_CPP])
  68.     quadrant[length(quadrant)][Q_UNDER] = 
  69.                 repeat(' ', length(ship[G_CPP][1]))
  70.     end for
  71.  
  72.     for i = 1 to g_info[G_ANC] do
  73.     quadrant = append(quadrant, stdtype[G_ANC])
  74.     quadrant[length(quadrant)][Q_UNDER] = 
  75.                 repeat(' ', length(ship[G_ANC][1]))
  76.     end for
  77.  
  78.     for i = 1 to g_info[G_KRC] do
  79.     quadrant = append(quadrant, stdtype[G_KRC])
  80.     quadrant[length(quadrant)][Q_UNDER] = 
  81.                 repeat(' ', length(ship[G_KRC][1]))
  82.     end for
  83. end procedure
  84.  
  85. function dock(h_coord x, v_coord y)
  86. -- Euphoria docks with a base or planet at (x,y)
  87.  
  88.     object_type t
  89.     valid_quadrant_row r
  90.     pb_row pbr
  91.     natural maxen, torp, availtorp
  92.     positive_atom energy, availen
  93.  
  94.     if curwarp != 1 then
  95.     return FALSE
  96.     else
  97.     r = who_is_it(x, y, TRUE)
  98.     t = quadrant[r][Q_TYPE]
  99.     if t = G_PL or t = G_BS then
  100.         if not quadrant[r][Q_DOCK] then
  101.         quadrant[r][Q_DOCK] = TRUE
  102.         pbr = quadrant[r][Q_PBX]
  103.         if pb[pbr][P_POD] > 0 then
  104.             pb[pbr][P_POD] = pb[pbr][P_POD] - 1
  105.             ps = ps & POD
  106.         end if
  107.         torp = 5 - quadrant[EUPHORIA][Q_TORP]
  108.         availtorp = pb[pbr][P_TORP]
  109.         if torp > availtorp then
  110.             torp = availtorp
  111.         end if
  112.         pb[pbr][P_TORP] = availtorp - torp
  113.         torp = torp + quadrant[EUPHORIA][Q_TORP]
  114.         quadrant[EUPHORIA][Q_TORP] = torp
  115.         ts = repeat(TORPEDO, torp)
  116.         if t = G_BS then
  117.             for i = 1 to NSYS do
  118.             if reptime[i] then
  119.                 reptime[i] = 0
  120.                 repair(i)
  121.             end if
  122.             end for
  123.             if shuttle then
  124.             esyml = EUPHORIA_L
  125.             esymr = EUPHORIA_R
  126.             if esym[1] = SHUTTLE_L[1] then
  127.                 esym = EUPHORIA_L
  128.             else
  129.                 esym = EUPHORIA_R
  130.             end if
  131.             otype[G_EU] = "EUPHORIA"
  132.             shuttle = FALSE
  133.             end if
  134.         end if
  135.         if shuttle then
  136.             maxen = 5000
  137.         else
  138.             maxen = 30000
  139.         end if
  140.         energy = maxen - quadrant[EUPHORIA][Q_EN]
  141.         availen = pb[pbr][P_EN]
  142.         if energy > availen then
  143.             energy = availen
  144.         end if
  145.         pb[pbr][P_EN] = availen - energy
  146.         quadrant[EUPHORIA][Q_EN] = quadrant[EUPHORIA][Q_EN] + energy
  147.         p_energy(0)
  148.         if t = G_BS then
  149.             quadrant[EUPHORIA][Q_DEFL] = 3
  150.             ds = repeat(DEFLECTOR, 3)
  151.         end if
  152.         wtext()
  153.         docking_sound()
  154.         upg(qrow, qcol)
  155.         msg("DOCKING COMPLETED")
  156.         return TRUE
  157.         end if
  158.     end if
  159.     end if
  160.     return FALSE
  161. end function
  162.  
  163. type increment(integer x)
  164.     return x = -1 or x = 0 or x = +1
  165. end type
  166.  
  167. global procedure task_emove()
  168. -- independent task: move the Euphoria
  169.     h_coord x, exold
  170.     v_coord y, eyold
  171.     increment eqx, eqy
  172.     sequence c, sc1
  173.  
  174.     if curwarp > wlimit then
  175.     if curwarp - wlimit > rand(12) then
  176.         msg("ALL ENGINES DAMAGED")
  177.         wlimit = 0
  178.         reptime[ENGINES] = reptime[ENGINES] + rand(11)
  179.         setwarp(0)
  180.         return
  181.     end if
  182.     end if
  183.     eqx = 0
  184.     eqy = 0
  185.     exold = quadrant[EUPHORIA][Q_X]
  186.     eyold = quadrant[EUPHORIA][Q_Y]
  187.     quadrant[EUPHORIA][Q_X] = quadrant[EUPHORIA][Q_X] + exi
  188.     quadrant[EUPHORIA][Q_Y] = quadrant[EUPHORIA][Q_Y] + eyi
  189.  
  190.     -- check for switching quadrants:
  191.  
  192.     if quadrant[EUPHORIA][Q_X] > HSIZE - length(esym) + 1 then
  193.     quadrant[EUPHORIA][Q_X] = 1
  194.     eqx = 1
  195.     elsif quadrant[EUPHORIA][Q_X] < 1 then
  196.     quadrant[EUPHORIA][Q_X] = HSIZE - length(esym) + 1
  197.     eqx = -1
  198.     end if
  199.  
  200.     if quadrant[EUPHORIA][Q_Y] = VSIZE + 1 then
  201.     quadrant[EUPHORIA][Q_Y] = 1
  202.     eqy = 1
  203.     elsif quadrant[EUPHORIA][Q_Y] = 0 then
  204.     quadrant[EUPHORIA][Q_Y] = VSIZE
  205.     eqy = -1
  206.     end if
  207.  
  208.     if shuttle then
  209.     p_energy(-fuel[curwarp+1]/6)
  210.     else
  211.     p_energy(-fuel[curwarp+1])
  212.     end if
  213.  
  214.     c = quadrant[EUPHORIA][Q_UNDER]
  215.     write_screen(exold, eyold, c)
  216.     if eqx != 0 or eqy != 0 then
  217.     -- new quadrant
  218.     qcol = gmod(qcol + eqx)
  219.     qrow = gmod(qrow + eqy)
  220.     setup_quadrant()
  221.     for i = 2 to length(quadrant) do
  222.         if quadrant[i][Q_TYPE] = G_FOR then
  223.             quadrant[i][Q_TARG] = fortran_target(i)
  224.         end if
  225.     end for
  226.     position(QUAD_LINE, 44)
  227.     set_bk_color(CYAN)
  228.     set_color(MAGENTA)
  229.     printf(CRT, "%d.%d", {qrow, qcol})
  230.     galaxy[qrow][qcol][1] = TRUE
  231.     msg("")
  232.     gsbox(qrow, qcol)
  233.     pobj()
  234.     end if
  235.     x = quadrant[EUPHORIA][Q_X]
  236.     y = quadrant[EUPHORIA][Q_Y]
  237.     sc1 = read_screen({x, length(esym)}, y)
  238.     if find(TRUE, sc1 != ' ' and sc1 != STAR) then
  239.     -- there's something in our way
  240.     if not dock(x, y) then
  241.         if scanon then
  242.         setg1()
  243.         end if
  244.     end if
  245.     quadrant[EUPHORIA][Q_X] = exold
  246.     quadrant[EUPHORIA][Q_Y] = eyold
  247.     end if
  248.     c = read_screen({quadrant[EUPHORIA][Q_X], length(esym)}, 
  249.              quadrant[EUPHORIA][Q_Y])
  250.     quadrant[EUPHORIA][Q_UNDER] = c
  251.     write_screen(quadrant[EUPHORIA][Q_X], quadrant[EUPHORIA][Q_Y], esym)
  252. end procedure
  253.  
  254.