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

  1. -- emove.e
  2. -- move the Enterprise
  3.  
  4. -- energy consumed per ship movement at warp 0..5
  5. constant fuel = {0, 5, 8, 12, 30, 60}
  6.  
  7. global function gmod(positive_int x)
  8. -- quadrant wraparound
  9.     if x = 0 then
  10.     return G_SIZE
  11.     elsif x > G_SIZE then
  12.     return 1
  13.     else
  14.     return x
  15.     end if
  16. end function
  17.  
  18.  
  19. -- standard row in f array for a type
  20. global constant stdtype =
  21. -- TYPE    EN    TORP    DEFL  FRATE  MRATE TARG
  22.    {{}, -- dummy (Enterprise)
  23.    {G_SK,  4000,  1,       0,   100,   140,   ENTERPRISE}, -- small Klingon
  24.    {G_BK,  8000,  2,       0,   100,   180,   ENTERPRISE}, -- big Klingon
  25.    {G_JM, 16000,  4,       0,   150,   220,   ENTERPRISE}, -- Jumbo
  26.    {G_RM,  2000,  1,       0,    70,   150,   ENTERPRISE}, -- Romulan
  27.    {G_TH,  3000,  0,       0,    50,    80,   -1},         -- Tholian
  28.    {G_PL,  3000,  0,       0,     0,     0,   -1},         -- planet
  29.    {G_BS,  3500,  2,       1,   120,     0,   -1}}         -- base
  30.  
  31. procedure setupf()
  32. -- set up f array for a new quadrant
  33.  
  34.     positive_int slen
  35.     sequence g_info
  36.  
  37.     slen = length(stdtype[G_PL])
  38.     g_info = g[qrow][qcol]
  39.  
  40.     fb1 = g_info[G_PL] + 2
  41.     for row = 2 to fb1-1 do
  42.     f[row][1..slen] = stdtype[G_PL]
  43.     f[row][F_DOCK] = FALSE
  44.     end for
  45.  
  46.     fr1 = g_info[G_BS] + fb1
  47.     for row = fb1 to fr1-1 do
  48.     f[row][1..slen] = stdtype[G_BS]
  49.     f[row][F_DOCK] = FALSE
  50.     end for
  51.  
  52.     ft1 = g_info[G_RM] + fr1
  53.     rtarg = -1
  54.     for row = fr1 to ft1-1 do
  55.     f[row][1..slen] = stdtype[G_RM]
  56.     f[row][F_UNDER] = repeat(' ', length(ship[G_RM][1]))
  57.     rtarg = ENTERPRISE
  58.     end for
  59.  
  60.     fk1 = g_info[G_TH] + ft1
  61.     for row = ft1 to fk1-1 do
  62.     f[row][1..slen] = stdtype[G_TH]
  63.     f[row][F_UNDER] = repeat(' ', length(ship[G_TH][1]))
  64.     end for
  65.  
  66.     fnext = g_info[G_JM] + fk1
  67.     for row = fk1 to fnext-1 do
  68.     f[row][1..slen] = stdtype[G_JM]
  69.     f[row][F_UNDER] = repeat(' ', length(ship[G_JM][1]))
  70.     end for
  71.  
  72.     for row = fnext to fnext + g_info[G_BK] - 1 do
  73.     f[row][1..slen] = stdtype[G_BK]
  74.     f[row][F_UNDER] = repeat(' ', length(ship[G_BK][1]))
  75.     end for
  76.     fnext = fnext + g_info[G_BK]
  77.  
  78.     for row = fnext to fnext + g_info[G_SK] - 1 do
  79.     f[row][1..slen] = stdtype[G_SK]
  80.     f[row][F_UNDER] = repeat(' ', length(ship[G_SK][1]))
  81.     end for
  82.     fnext = fnext + g_info[G_SK]
  83. end procedure
  84.  
  85. function dock(h_coord x, v_coord y)
  86. -- Enterprise docks with a base or planet
  87.  
  88.     object_type t
  89.     valid_f_row r
  90.     pb_row pbr
  91.     positive_int maxen, torp, availtorp
  92.     positive_atom energy, availen
  93.  
  94.     if curwarp != 1 then
  95.     return FALSE
  96.     else
  97.     r = flook(x, y, TRUE)
  98.     t = f[r][F_TYPE]
  99.     if t = G_PL or t = G_BS then
  100.         if not f[r][F_DOCK] then
  101.         f[r][F_DOCK] = TRUE
  102.         pbr = f[r][F_PBX]
  103.         pb[pbr][P_EXIST] = DOCKED_WITH
  104.         if pb[pbr][P_POD] > 0 then
  105.             pb[pbr][P_POD] = pb[pbr][P_POD] - 1
  106.             ps = ps & POD
  107.         end if
  108.         torp = 5 - f[ENTERPRISE][F_TORP]
  109.         availtorp = pb[pbr][P_TORP]
  110.         if torp > availtorp then
  111.             torp = availtorp
  112.         end if
  113.         pb[pbr][P_TORP] = availtorp - torp
  114.         torp = torp + f[ENTERPRISE][F_TORP]
  115.         f[ENTERPRISE][F_TORP] = torp
  116.         ts = repeat(TORPEDO, torp)
  117.         if t = G_BS then
  118.             for i = 1 to NSYS do
  119.             if reptime[i] then
  120.                 reptime[i] = 0
  121.                 repair(i)
  122.             end if
  123.             end for
  124.             if gal then
  125.             esyml = ENTERPRISE_L
  126.             esymr = ENTERPRISE_R
  127.             if esym[1] = SHUTTLE_L[1] then
  128.                 esym = ENTERPRISE_L
  129.             else
  130.                 esym = ENTERPRISE_R
  131.             end if
  132.             otype[G_EN] = "EUPHORIA"
  133.             gal = FALSE
  134.             end if
  135.         end if
  136.         if gal then
  137.             maxen = 5000
  138.         else
  139.             maxen = 30000
  140.         end if
  141.         energy = maxen - f[ENTERPRISE][F_EN]
  142.         availen = pb[pbr][P_EN]
  143.         if energy > availen then
  144.             energy = availen
  145.         end if
  146.         if t = G_BS then
  147.             if torp > 0 or energy > 0 then
  148.             f[ENTERPRISE][F_DEFL] = 3
  149.             ds = repeat(DEFLECTOR, 3)
  150.             end if
  151.         end if
  152.         pb[pbr][P_EN] = availen - energy
  153.         energy = energy + f[ENTERPRISE][F_EN]
  154.         if energy > maxen then
  155.             energy = maxen
  156.         end if
  157.         f[ENTERPRISE][F_EN] = energy
  158.         p_energy(0)
  159.         wtext()
  160.         docking_sound()
  161.         msg("DOCKING COMPLETED")
  162.         if scanon then
  163.             dsyms()
  164.         end if
  165.         return TRUE
  166.         end if
  167.     end if
  168.     end if
  169.     return FALSE
  170. end function
  171.  
  172. type increment(integer x)
  173.     return x = -1 or x = 0 or x = +1
  174. end type
  175.  
  176. global procedure t2emove()
  177. -- task 2: move the Enterprise
  178.     h_coord x, exold
  179.     v_coord y, eyold
  180.     increment eqx, eqy
  181.     sequence c, sc1
  182.  
  183.     if curwarp > wlimit then
  184.     if curwarp - wlimit > rand(12) then
  185.         sounde(5, 20, 1)
  186.         msg("ALL ENGINES DAMAGED")
  187.         wlimit = 0
  188.         reptime[ENGINES] = reptime[ENGINES] + rand(11)
  189.         setwarp(0)
  190.         return
  191.     end if
  192.     end if
  193.     sounde(4, 3, 1)
  194.     eqx = 0
  195.     eqy = 0
  196.     exold = f[ENTERPRISE][F_X]
  197.     eyold = f[ENTERPRISE][F_Y]
  198.     f[ENTERPRISE][F_X] = f[ENTERPRISE][F_X] + exi
  199.     f[ENTERPRISE][F_Y] = f[ENTERPRISE][F_Y] + eyi
  200.  
  201.     -- check for switching quadrants:
  202.  
  203.     if f[ENTERPRISE][F_X] > HSIZE - length(esym) + 1 then
  204.     f[ENTERPRISE][F_X] = 1
  205.     eqx = 1
  206.     elsif f[ENTERPRISE][F_X] < 1 then
  207.     f[ENTERPRISE][F_X] = HSIZE - length(esym) + 1
  208.     eqx = -1
  209.     end if
  210.  
  211.     if f[ENTERPRISE][F_Y] = VSIZE + 1 then
  212.     f[ENTERPRISE][F_Y] = 1
  213.     eqy = 1
  214.     elsif f[ENTERPRISE][F_Y] = 0 then
  215.     f[ENTERPRISE][F_Y] = VSIZE
  216.     eqy = -1
  217.     end if
  218.  
  219.     if gal then
  220.     p_energy(-fuel[curwarp+1]/6)
  221.     else
  222.     p_energy(-fuel[curwarp+1])
  223.     end if
  224.  
  225.     c = f[ENTERPRISE][F_UNDER]
  226.     write_screen(exold, eyold, c)
  227.     if eqx != 0 or eqy != 0 then
  228.     -- new quadrant
  229.     qcol = gmod(qcol + eqx)
  230.     qrow = gmod(qrow + eqy)
  231.     setupf()
  232.     for i = ft1 to fk1-1 do
  233.         f[i][F_TARG] = tholian_target(i)
  234.     end for
  235.     position(QUAD_LINE, 44)
  236.     set_bk_color(CYAN)
  237.     set_color(MAGENTA)
  238.     printf(CRT, "%d.%d", {qrow, qcol})
  239.     g[qrow][qcol][1] = TRUE
  240.     msg("")
  241.     gsbox(qrow, qcol)
  242.     pobj()
  243.     end if
  244.     x = f[ENTERPRISE][F_X]
  245.     y = f[ENTERPRISE][F_Y]
  246.     sc1 = read_screen({x, length(esym)}, y)
  247.     if find(TRUE, sc1 != ' ' and sc1 != STAR) then
  248.     -- there's something in our way
  249.     if not dock(x, y) then
  250.         if scanon then
  251.         setg1()
  252.         end if
  253.     end if
  254.     f[ENTERPRISE][F_X] = exold
  255.     f[ENTERPRISE][F_Y] = eyold
  256.     end if
  257.     c = read_screen({f[ENTERPRISE][F_X], length(esym)}, f[ENTERPRISE][F_Y])
  258.     f[ENTERPRISE][F_UNDER] = c
  259.     write_screen(f[ENTERPRISE][F_X], f[ENTERPRISE][F_Y], esym)
  260. end procedure
  261.  
  262.  
  263.