home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / euphoria / weapons.e < prev    next >
Text File  |  1994-03-10  |  7KB  |  296 lines

  1. -- weapons.e
  2. -- phasors, torpedos, antimatter pods
  3.  
  4. global constant W_PHASOR = 1,
  5.         W_TORPEDO = 2,
  6.         W_POD = 3
  7.  
  8. type weapon_system(integer x)
  9.     return find(x, {W_PHASOR, W_TORPEDO, W_POD})
  10. end type
  11.  
  12. extended_h_coord x0
  13. extended_v_coord y0
  14. atom xinc
  15. atom yinc
  16.  
  17. function diftype(valid_quadrant_row shooter, valid_quadrant_row victim)
  18. -- return TRUE if shooter and victim are on opposing sides
  19.  
  20.     if quadrant[shooter][Q_TYPE] = G_BS then
  21.     return victim != EUPHORIA
  22.     else
  23.     if find(quadrant[shooter][Q_TYPE], {G_KRC, G_ANC, G_CPP}) and
  24.        find(quadrant[victim][Q_TYPE] , {G_KRC, G_ANC, G_CPP}) then
  25.         -- both are C ships
  26.         return FALSE
  27.     else
  28.         return quadrant[shooter][Q_TYPE] != quadrant[victim][Q_TYPE]
  29.     end if
  30.     end if
  31. end function
  32.  
  33. procedure pod_effect(h_coord rx,v_coord ry)
  34. -- Detonate an antimatter pod. All objects in the quadrant are
  35. -- affected. It's like a 1000-unit phasor blast directed toward everyone
  36. -- *including* the Euphoria and all planets and bases in the quadrant.
  37. -- The closer an object is to the pod when it explodes, the more
  38. -- of a blast that object will feel.
  39.  
  40.     position(CMD_LINE, CMD_POS+6)
  41.     set_bk_color(WHITE)
  42.     puts(CRT, "     ")
  43.     for c = 0 to 15 do
  44.         set_bk_color(c)
  45.         BlankScreen(FALSE)
  46.     delay(.03)
  47.     end for
  48.     set_bk_color(BLACK)
  49.     scanon = TRUE
  50.     setg1()
  51.     -- add POD to the quadrant temporarily
  52.     quadrant = append(quadrant, repeat(0, length(quadrant[1]))) 
  53.     shooter = length(quadrant)    
  54.     quadrant[shooter][Q_TYPE] = G_POD
  55.     quadrant[shooter][Q_X] = rx
  56.     quadrant[shooter][Q_Y] = ry
  57.     
  58.     for i = length(quadrant)-1 to 1 by -1 do
  59.     if quadrant[i][Q_TYPE] != DEAD then
  60.         victim = i
  61.             dodmg(bcalc(1000), FALSE)
  62.     end if
  63.     end for
  64.     quadrant = quadrant[1..length(quadrant)-1] -- delete POD
  65. end procedure
  66.  
  67. global procedure weapon(weapon_system w, positive_atom strength)
  68. -- fire a phasor, torpedo or pod from shooter starting from (x0,y0) and
  69. -- proceeding in steps of xinc, yinc until something is hit or the
  70. -- edge of the screen is reached
  71.  
  72.     extended_h_coord x
  73.     extended_v_coord y
  74.     h_coord rx
  75.     v_coord ry
  76.     extended_h_coord prev_rx
  77.     extended_v_coord prev_ry
  78.     boolean ahit
  79.     char c
  80.     natural freq
  81.     positive_atom units
  82.     sequence under
  83.  
  84.     prev_rx = 0
  85.     prev_ry = 0
  86.     x = x0
  87.     y = y0
  88.     ahit = FALSE
  89.     under = {}
  90.     if w = W_TORPEDO then
  91.     freq = 3500
  92.     sound(freq)
  93.     end if
  94.     while x >= .5 and x < HSIZE + 0.5 and
  95.       y >= .5 and y < VSIZE + 0.5 do
  96.     rx = floor(x + 0.5)
  97.     ry = floor(y + 0.5)
  98.     if rx != prev_rx or ry != prev_ry then
  99.         c = read_screen(rx, ry)
  100.         if c = ' ' or c = STAR or w = W_POD then
  101.         prev_rx = rx
  102.         prev_ry = ry
  103.         if w = W_PHASOR then
  104.             under = prepend(under, {rx, ry, c})
  105.             write_screen(rx, ry, '*')
  106.             delay(0.003)
  107.         else
  108.             -- POD or TORPEDO
  109.             if length(under) != 0 then
  110.             write_screen(under[1][1], under[1][2], under[1][3])
  111.             end if
  112.             if w = W_TORPEDO then
  113.                 under = {{rx, ry, c}}
  114.             write_screen(rx, ry, '*')
  115.                 delay(0.008)
  116.                 sound(freq)
  117.                 if freq > 600 then
  118.                 freq = freq - 50
  119.                 end if
  120.             else
  121.             -- POD
  122.             if c = ' ' or c = STAR then
  123.                 under = {{rx, ry, c}}
  124.                 write_screen(rx, ry, POD)
  125.             else
  126.                 under = {} -- don't overwrite other objects 
  127.             end if
  128.             if get_key() = 13 then
  129.                   pod_effect(rx, ry)
  130.                 exit
  131.             end if
  132.             sound(290)
  133.             delay(0.06)
  134.             sound(0)
  135.             delay(0.06)
  136.             end if
  137.         end if
  138.         else
  139.         ahit = TRUE
  140.         exit
  141.         end if
  142.     end if
  143.     x = x + xinc
  144.     y = y + yinc
  145.     end while
  146.  
  147.     if w != W_PHASOR then
  148.     sound(0)
  149.     end if
  150.     if w != W_POD then
  151.     if ahit then
  152.         victim = who_is_it(rx, ry, FALSE)
  153.         if diftype(shooter, victim) then
  154.         if w = W_TORPEDO then
  155.             dodmg(strength, TRUE)
  156.         else
  157.             units = bcalc(strength)
  158.             phasor_sound(units)
  159.             dodmg(units, FALSE)
  160.         end if
  161.         end if
  162.     end if
  163.     end if
  164.     for i = length(under) to 1 by -1 do
  165.     write_screen(under[i][1], under[i][2], under[i][3])
  166.     end for
  167. end procedure
  168.  
  169. type object_height(integer x)
  170.     return x >= 1 and x <= 3
  171. end type
  172.  
  173. global procedure fortran_phasor(positive_atom pen)
  174. -- perform Fortran phasor: no phasor drawn, can't miss
  175.  
  176.     positive_atom blast
  177.     h_coord targx
  178.     v_coord targy
  179.     sequence c
  180.     natural len
  181.     object_type t
  182.     object_height height
  183.  
  184.     victim = quadrant[shooter][Q_TARG]
  185.     targx = quadrant[victim][Q_X]
  186.     targy = quadrant[victim][Q_Y]
  187.     t = quadrant[victim][Q_TYPE]
  188.     if victim = EUPHORIA then
  189.     len = length(esym)
  190.     height = 1
  191.     elsif t = G_BS then
  192.     len = length(BASE)
  193.     height = 2
  194.     elsif t = G_PL then
  195.     len = length(PLANET_MIDDLE)
  196.     height = 3
  197.     else
  198.     len = length(ship[quadrant[victim][Q_TYPE]][1])
  199.     height = 1
  200.     end if
  201.     blast = bcalc(pen)
  202.     for i = -2 to blast / 300 do
  203.     sound(500 + 500 * (integer(i / 2)))
  204.     write_screen(quadrant[shooter][Q_X]+1, quadrant[shooter][Q_Y], '-')
  205.     c = repeat(0, height)
  206.     for j = 0 to height - 1 do
  207.         c[j+1] = read_screen({targx, len}, targy + j)
  208.         write_screen(targx, targy + j, repeat(' ', len))
  209.     end for
  210.     delay(0.07)
  211.     write_screen(quadrant[shooter][Q_X]+1, quadrant[shooter][Q_Y], '+')
  212.     for j = 0 to height - 1 do
  213.         write_screen(targx, targy + j, c[j+1])
  214.     end for
  215.     delay(0.07)
  216.     end for
  217.     sound(0)
  218.     dodmg(blast, FALSE)
  219. end procedure
  220.  
  221. global procedure setpt(valid_quadrant_row r)
  222. -- set up enemy (or base) phasor or torpedo
  223.  
  224.     positive_atom dist
  225.     valid_quadrant_row targ
  226.     h_coord targx
  227.     v_coord targy
  228.     object_type t
  229.  
  230.     x0 = quadrant[r][Q_X]
  231.     y0 = quadrant[r][Q_Y]
  232.     targ = quadrant[r][Q_TARG]
  233.     targx = quadrant[targ][Q_X]
  234.     targy = quadrant[targ][Q_Y]
  235.     t = quadrant[r][Q_TYPE]
  236.  
  237.     -- decide which side to shoot from
  238.     if t = G_BS then
  239.     if x0 < targx then
  240.         x0 = x0 + length(BASE)
  241.     else
  242.         x0 = x0 - 1
  243.     end if
  244.     if y0 < targy then
  245.         y0 = y0 + 2
  246.     else
  247.         y0 = y0 - 1
  248.     end if
  249.     else
  250.     if x0 < targx  then
  251.         x0 = x0 + length(ship[t][1])
  252.     else
  253.         x0 = x0 - 1
  254.     end if
  255.     end if
  256.  
  257.     -- add a bit of randomness so they might miss
  258.     xinc = targx - x0 + rand(5) - 3
  259.     yinc = targy - y0 + rand(3) - 2
  260.     if xinc = 0 and yinc = 0 then
  261.     xinc = 1 -- prevent infinite loop
  262.     end if
  263.     dist = sqrt(1 + xinc * xinc + yinc * yinc)
  264.     xinc = xinc/dist
  265.     yinc = yinc/dist
  266. end procedure
  267.  
  268. constant PI = 3.14159265
  269.  
  270. type angle(atom x)
  271.     return x >= 0 and x < 2 * PI
  272. end type
  273.  
  274. global procedure esetpt(direction dir)
  275. -- set up for euphoria phasor/torpedo/pod firing
  276.  
  277.     angle theta
  278.  
  279.     shooter = EUPHORIA
  280.     x0 = quadrant[EUPHORIA][Q_X]
  281.     y0 = quadrant[EUPHORIA][Q_Y]
  282.     theta = (dir - 1)/8.0 * 2 * PI
  283.     xinc = cos(theta)
  284.     yinc = -sin(theta) / ASPECT_RATIO
  285.     if xinc < -0.00001 then
  286.     write_screen(x0, y0, esyml)
  287.     elsif xinc > 0.00001 then
  288.     write_screen(x0, y0, esymr)
  289.     end if
  290.     if read_screen(x0, y0) = esyml[1] then
  291.     x0 = x0 - 1
  292.     else
  293.     x0 = x0 + length(esym)
  294.     end if
  295. end procedure
  296.