home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / euphor10.zip / ENEMY.E < prev    next >
Text File  |  1993-04-21  |  8KB  |  363 lines

  1. -- enemy.e
  2. -- operate the enemy ships
  3.  
  4. global procedure t5rstat()
  5. -- task 5: Romulan status change
  6.  
  7.     positive_atom w
  8.  
  9.     w = rand(256) + rand(256) + 3
  10.     if rstat = TRUCE then
  11.     sounde(3,100,1)
  12.     if truce_broken then
  13.         truce_broken = FALSE
  14.         msg("TRUCE BROKEN!")
  15.     else
  16.         msg("BASIC STATUS: HOSTILE")
  17.     end if
  18.     if rand(20) < 15 then
  19.         w = w * 1.2
  20.         ship[G_RM] = {ROMULAN_L, ROMULAN_R}
  21.         rstat = HOSTILE
  22.     else
  23.         w = w * .67
  24.         ship[G_RM] = repeat(repeat(INVISIBLE_CHAR, length(ROMULAN_L)), 2)
  25.         rstat = CLOAKING
  26.     end if
  27.     else
  28.     if rand(20) < 10 then
  29.         sounde(2, 100, 1)
  30.         rstat = TRUCE
  31.         msg("BASIC STATUS: TRUCE")
  32.         w = w * .83
  33.         ship[G_RM] = {ROMULAN_L, ROMULAN_R}
  34.     else
  35.         if rstat = HOSTILE then
  36.         w = w * .67
  37.         rstat = CLOAKING
  38.         ship[G_RM] = repeat(repeat(INVISIBLE_CHAR, length(ROMULAN_L)), 2)
  39.         else
  40.         w = w * 1.2
  41.         rstat = HOSTILE
  42.         ship[G_RM] = {ROMULAN_L, ROMULAN_R}
  43.         end if
  44.     end if
  45.     end if
  46.     wait[TASK_RSTAT] = w
  47.     if scanon then
  48.     gtext()
  49.     end if
  50. end procedure
  51.  
  52. procedure orient(valid_f_row row)
  53. -- point the ship toward its target
  54.  
  55.     f_row targ
  56.     h_coord targx, rowx
  57.     v_coord rowy
  58.     object_type t
  59.  
  60.     targ = f[row][F_TARG]
  61.     if targ = -1 then
  62.     -- no target
  63.     return
  64.     end if
  65.     targx = f[targ][F_X]
  66.     rowx = f[row][F_X]
  67.     rowy = f[row][F_Y]
  68.     t = f[row][F_TYPE]
  69.     if rowx < targx then
  70.     write_screen(rowx, rowy, ship[t][2])
  71.     else
  72.     write_screen(rowx, rowy, ship[t][1])
  73.     end if
  74. end procedure
  75.  
  76. procedure shoot(valid_f_row row)
  77. -- select torpedo or phasor for enemy shot
  78.  
  79.     positive_int torp
  80.     positive_atom pen
  81.  
  82.     shooter = row
  83.     if f[shooter][F_TYPE] != G_BS then
  84.     orient(shooter)
  85.     end if
  86.     setpt(shooter)
  87.     torp = f[shooter][F_TORP]
  88.     if torp > 0 and rand(4) = 1 then
  89.     f[shooter][F_TORP] = torp - 1
  90.     weapon(W_TORPEDO, 4000)
  91.     else
  92.     pen = f[shooter][F_EN] / 8
  93.     if f[shooter][F_TYPE] = G_TH then
  94.         tholian_phasor(pen)
  95.     else
  96.         weapon(W_PHASOR, pen)
  97.     end if
  98.     f[shooter][F_EN] = f[shooter][F_EN] - pen
  99.     end if
  100. end procedure
  101.  
  102.  
  103. global procedure t6fire()
  104. -- task 6: select an enemy ship for firing
  105.  
  106.     f_row row
  107.     positive_int rate
  108.     f_row targ
  109.  
  110.     if fnext = 2 then
  111.     return -- nobody in the quadrant
  112.     end if
  113.  
  114.     row = rand(fnext-2) + ENTERPRISE  -- choose a random ship
  115.     if f[row][F_TYPE] then
  116.     rate = f[row][F_FRATE]
  117.     if rate > rand(256) then
  118.         -- shoot
  119.         if f[row][F_TYPE] = G_RM then
  120.         if rstat != TRUCE then
  121.             shoot(row)
  122.         else
  123.             if rtarg != ENTERPRISE then
  124.             if f[rtarg][F_TYPE] != G_BS then
  125.                 shoot(row)
  126.             end if
  127.             end if
  128.         end if
  129.  
  130.         elsif f[row][F_TYPE] = G_BS then
  131.         targ = f[row][F_TARG]
  132.         if targ != -1 then
  133.             if rstat != TRUCE then
  134.             shoot(row)
  135.             elsif f[targ][F_TYPE] != G_RM then
  136.             shoot(row)
  137.             end if
  138.         end if
  139.  
  140.         else
  141.         shoot(row)
  142.         end if
  143.     end if
  144.     end if
  145. end procedure
  146.  
  147.  
  148. global procedure t7move()
  149. -- select an enemy ship for moving
  150.  
  151.     f_row row
  152.     positive_int mrate
  153.     h_coord fx
  154.     v_coord fy
  155.     extended_h_coord xtry
  156.     extended_v_coord ytry
  157.     sequence uchar, schar
  158.     positive_int t
  159.     positive_int len
  160.  
  161.     if fnext = 2 then
  162.     return -- nobody in the quadrant
  163.     end if
  164.  
  165.     row = rand(fnext-2) + ENTERPRISE  -- choose a random ship
  166.     t = f[row][F_TYPE]
  167.     if t then
  168.     mrate = f[row][F_MRATE]
  169.     if mrate > rand(256) then
  170.         -- try to move
  171.         fx = f[row][F_X]
  172.         xtry = fx + rand(5) - 3
  173.         len = length(ship[t][1])
  174.         if xtry >= 2 and xtry <= HSIZE - len then
  175.         fy = f[row][F_Y]
  176.         ytry = fy + rand(3) - 2
  177.         if ytry >= 1 and ytry <= VSIZE then
  178.             schar = read_screen({xtry, len}, ytry)
  179.             if not find(FALSE, schar = ' ' or schar = STAR) then
  180.             sounde(13,2,1)
  181.             uchar = f[row][F_UNDER]
  182.             f[row][F_UNDER] = schar
  183.             schar = read_screen({fx, len}, fy)
  184.             write_screen(fx, fy, uchar)
  185.             write_screen(xtry , ytry, schar)
  186.             f[row][F_X] = xtry
  187.             f[row][F_Y] = ytry
  188.             end if
  189.         end if
  190.         end if
  191.         orient(row)
  192.     end if
  193.     end if
  194. end procedure
  195.  
  196. global procedure t8ur()
  197. -- task 8: print UNITS REMAIN
  198.     msg("")
  199.     if ur then
  200.     printf(CRT, "%d UNITS REMAIN", ur)
  201.     else
  202.     printf(CRT, "%s DESTROYED", {otype[urt]})
  203.     end if
  204. end procedure
  205.  
  206. function add2f(object_type t, h_coord x, v_coord y)
  207. -- add a ship to the f array (enter it into the active quadrant)
  208.  
  209.     f_row targ
  210.     valid_f_row row
  211.     sequence c, s
  212.  
  213.     -- find a place in f array
  214.     if fnext >= FROWS then
  215.     return FALSE -- too many guys in already
  216.     end if
  217.     row = fstart(t)
  218.     while row < fnext and f[row][F_TYPE] do
  219.     row = row + 1
  220.     if row > FROWS then
  221.         return FALSE
  222.     end if
  223.     end while
  224.  
  225.     -- choose his target
  226.     if t < G_RM then
  227.     if g[qrow][qcol][G_BS] then
  228.         for r = fb1 to  fr1-1 do
  229.         if f[r][F_TYPE] then
  230.             targ = r
  231.         end if
  232.         end for
  233.     else
  234.         targ = ENTERPRISE
  235.     end if
  236.     elsif t = G_RM then
  237.     if rtarg = -1 then
  238.         if g[qrow][qcol][G_BS] then
  239.         for r = fb1 to fr1-1 do
  240.             if f[r][F_TYPE] then
  241.             rtarg = r
  242.             end if
  243.         end for
  244.         else
  245.         rtarg = ENTERPRISE
  246.         end if
  247.     end if
  248.     targ = rtarg
  249.     else
  250.     targ = tholian_target(row)
  251.     end if
  252.  
  253.     sounde(12,2,1)
  254.     s = stdtype[t]
  255.     f[row][1..length(s)] = s
  256.     f[row][F_X] = x
  257.     f[row][F_Y] = y
  258.     f[row][F_UNDER] = read_screen({x, length(ship[t][1])}, y)
  259.     f[row][F_TARG] = targ
  260.     if row = fnext then
  261.     fnext = fnext + 1
  262.     end if
  263.     if x < f[ENTERPRISE][F_X] then
  264.     c = ship[t][2]
  265.     else
  266.     c = ship[t][1]
  267.     end if
  268.     write_screen(x, y, c)
  269.     return TRUE
  270. end function
  271.  
  272. global procedure t10enter()
  273. -- enemy ship enters quadrant
  274.  
  275.     positive_int q
  276.     h_coord enterx
  277.     v_coord entery
  278.     positive_int entert
  279.     sequence enterc
  280.     g_index randcol, randrow, fromcol, fromrow
  281.  
  282.     fromrow = qrow
  283.     fromcol = qcol
  284.     enterx = 2
  285.     entery = 1
  286.     q = rand(8)
  287.     if q = 1 then     -- left
  288.     fromcol = gmod(qcol-1)
  289.     entery = rand(VSIZE)
  290.     elsif q = 2 then  -- top left
  291.     fromrow = gmod(qrow-1)
  292.     fromcol = gmod(qcol-1)
  293.     elsif q = 3 then  -- top
  294.     enterx = 1 + rand(HSIZE - 6) -- for now
  295.     fromrow = gmod(qrow-1)
  296.     elsif q = 4 then  -- top right
  297.     enterx = HSIZE - 6 -- for now
  298.     fromrow = gmod(qrow-1)
  299.     fromcol = gmod(qcol+1)
  300.     elsif q = 5 then  -- right
  301.     enterx = HSIZE - 6 -- for now
  302.     entery = rand(VSIZE)
  303.     fromcol = gmod(qcol+1)
  304.     elsif q = 6 then  -- bottom right
  305.     enterx = HSIZE - 6
  306.     entery = VSIZE
  307.     fromrow = gmod(qrow+1)
  308.     fromcol = gmod(qcol+1)
  309.     elsif q = 7 then  -- bottom
  310.     enterx = 1 + rand(HSIZE - 6)
  311.     entery = VSIZE
  312.     fromrow = gmod(qrow+1)
  313.     else              -- bottom left
  314.     entery = VSIZE
  315.     fromrow = gmod(qrow+1)
  316.     fromcol = gmod(qcol-1)
  317.     end if
  318.     entert = 0
  319.     if g[fromrow][fromcol][G_JM] then
  320.     entert = G_JM
  321.     elsif g[fromrow][fromcol][G_BK] then
  322.     entert = G_BK
  323.     elsif g[fromrow][fromcol][G_SK] then
  324.     entert = G_SK
  325.     else
  326.     randcol = rand(G_SIZE)
  327.     randrow = rand(G_SIZE)
  328.     if randcol != qrow or randcol != qcol then
  329.         if g[randrow][randcol][G_TH] then
  330.         fromrow = randrow
  331.         fromcol = randcol
  332.         enterx = 1 + rand(HSIZE-6)
  333.         entery = rand(VSIZE)
  334.         entert = G_TH
  335.         end if
  336.     end if
  337.     end if
  338.     if entert = 0 then
  339.     if g[fromrow][fromcol][G_RM] then
  340.         entert = G_RM
  341.     end if
  342.     end if
  343.     enterc = read_screen({enterx, 5}, entery)
  344.     if find(TRUE, enterc != ' ' and enterc != STAR) then
  345.     entert = 0
  346.     end if
  347.     if entert then
  348.     if add2f(entert, enterx, entery) then
  349.         g[qrow][qcol][entert] = g[qrow][qcol][entert] + 1
  350.         g[fromrow][fromcol][entert] = g[fromrow][fromcol][entert] - 1
  351.         if entert < G_RM then
  352.         upg(qrow, qcol)
  353.         gsbox(qrow, qcol)
  354.         upg(fromrow, fromcol)
  355.         end if
  356.         msg("")
  357.         printf(CRT, "%s HAS ENTERED QUADRANT", {otype[entert]})
  358.     end if
  359.     end if
  360.     wait[TASK_ENTER] = rand(10) * curwarp + f[ENTERPRISE][F_EN]/rand(1000)
  361. end procedure
  362.  
  363.