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

  1. -- damage.e
  2. -- compute effects of damage
  3.  
  4. global function fortran_target(valid_quadrant_row r)
  5. -- select target for fortran ship at row r
  6.     sequence flive
  7.  
  8.     flive = {}
  9.     for i = 1 to length(quadrant) do
  10.     if i != r and quadrant[i][Q_TYPE] != DEAD then
  11.         flive = flive & i
  12.     end if
  13.     end for
  14.     return flive[rand(length(flive))]
  15. end function
  16.  
  17. procedure setrmt(valid_quadrant_row newtarg)
  18. -- set BASIC group target
  19.  
  20.     basic_targ = newtarg
  21.     if bstat = TRUCE then
  22.     if basic_targ = EUPHORIA or quadrant[basic_targ][Q_TYPE] = G_BS then
  23.         truce_broken = TRUE
  24.         sched(TASK_BSTAT, 2.5)
  25.     end if
  26.     end if
  27.     for row = 2 to length(quadrant) do
  28.     if quadrant[row][Q_TYPE] = G_BAS then
  29.         quadrant[row][Q_TARG] = basic_targ
  30.     end if
  31.     end for
  32. end procedure
  33.  
  34. procedure setnt()
  35. -- target is dead 
  36. -- set new target for everyone that was shooting at him
  37.     natural t -- type or 0
  38.     valid_quadrant_row targ
  39.  
  40.     for row = 2 to length(quadrant) do
  41.     if quadrant[row][Q_TARG] = victim then
  42.         t = quadrant[row][Q_TYPE]
  43.         if t = G_BS then
  44.         quadrant[row][Q_FRATE] = 0
  45.         else
  46.         if t = G_FOR then
  47.             targ = fortran_target(row)
  48.         else
  49.             targ = EUPHORIA
  50.         end if
  51.         quadrant[row][Q_TARG] = targ
  52.         end if
  53.     end if
  54.     end for
  55.     if victim = basic_targ then
  56.     basic_targ = EUPHORIA
  57.     end if
  58. end procedure
  59.  
  60. global procedure repair(subsystem sys)
  61. -- repair a subsystem
  62.     if sys = ENGINES then
  63.     wlimit = 5
  64.     set_bk_color(WHITE)
  65.     set_color(BLACK)
  66.     position(WARP_LINE, WARP_POS+5)
  67.     printf(CRT, "%d   ", curwarp)
  68.     end if
  69.     ndmg = ndmg - 1
  70. end procedure
  71.  
  72. procedure edmg(positive_atom blast)
  73. -- Euphoria damage
  74.     subsystem sys
  75.  
  76.     if blast > rand(256) * 70 then
  77.     sys = rand(NSYS)
  78.     if reptime[sys] = 0 then
  79.         reptime[sys] = rand(81) + 9
  80.         if sys = GALAXY_SENSORS then
  81.         setg1()
  82.         elsif sys = ENGINES then
  83.         wlimit = rand(4) - 1
  84.         if wlimit = 0 then
  85.             msg("ALL ENGINES DAMAGED")
  86.         else
  87.             msg("ENGINES DAMAGED")
  88.         end if
  89.         if curwarp > wlimit then
  90.             setwarp(wlimit)
  91.         end if
  92.         else
  93.             fmsg("%s DAMAGED", {dtype[sys]})
  94.         end if
  95.         wait[TASK_DAMAGE] = 1.5
  96.         ndmg = ndmg + 1
  97.         sched(TASK_DAMAGE, 1.5)
  98.     end if
  99.     end if
  100. end procedure
  101.  
  102. boolean drep_on
  103. drep_on = FALSE
  104.  
  105. procedure drep_blank()
  106. -- clear the damage report area
  107.     position(WARP_LINE, DREP_POS)
  108.     puts(CRT, repeat(' ', 13))
  109.     position(WARP_LINE+1, DREP_POS)
  110.     puts(CRT, repeat(' ', 13))
  111. end procedure
  112.  
  113. global procedure drep()
  114. -- damage report update
  115.     set_bk_color(GREEN)
  116.     set_color(BRIGHT_WHITE)
  117.     if not drep_on then
  118.     drep_blank()
  119.     drep_on = TRUE
  120.     end if
  121.     position(WARP_LINE, DREP_POS+1)
  122.     printf(CRT, "P%-2d T%-2d S%-2d", {reptime[PHASORS],
  123.                 reptime[TORPEDOS],
  124.                 reptime[GALAXY_SENSORS]})
  125.     position(CMD_LINE, DREP_POS+1)
  126.     printf(CRT, "G%-2d E%d", {reptime[GUIDANCE], reptime[ENGINES]})
  127.     if reptime[ENGINES] > 0 then
  128.     printf(CRT, ":%d ", wlimit)
  129.     else
  130.     puts(CRT, "   ")
  131.     end if
  132. end procedure
  133.  
  134. global procedure task_dmg()
  135. -- independent task: damage countdown
  136.  
  137.     if ndmg = 0 then
  138.     wait[TASK_DAMAGE] = INACTIVE
  139.     set_bk_color(WHITE)
  140.     drep_blank()
  141.     drep_on = FALSE
  142.     else
  143.     for i = 1 to NSYS do
  144.         if reptime[i] then
  145.         reptime[i] = reptime[i] - 1
  146.         if reptime[i] = 0 then
  147.             repair(i)
  148.             fmsg("%s REPAIRED", {dtype[i]})
  149.         end if
  150.         end if
  151.     end for
  152.     drep()
  153.     end if
  154. end procedure
  155.  
  156. global procedure task_dead()
  157. -- independent task: clean dead bodies off the screen
  158.     set_bk_color(BLACK)
  159.     set_color(WHITE)
  160.     for c = 1 to length(wipeout) do
  161.     for i = 0 to wipeout[c][3]-1 do
  162.         if read_screen(wipeout[c][1] + i, wipeout[c][2]) = ' ' then
  163.         display_screen(wipeout[c][1] + i, wipeout[c][2], ' ')
  164.         end if
  165.     end for
  166.     end for
  167.     wipeout = {}
  168. end procedure
  169.  
  170. global function who_is_it(h_coord x, v_coord y, boolean src_chk)
  171. -- map (x,y) screen coordinate to quadrant sequence row
  172. -- src_chk is true when we just want to see if we are docking
  173.  
  174.     extended_h_coord ix
  175.     extended_v_coord iy
  176.     natural t, len, xend
  177.  
  178.     xend = x + length(esym) - 1
  179.     for i = EUPHORIA + src_chk to length(quadrant) do
  180.     ix = quadrant[i][Q_X]
  181.     iy = quadrant[i][Q_Y]
  182.     t = quadrant[i][Q_TYPE]
  183.  
  184.     if t = G_BS then
  185.         if x >= ix and x < ix + length(BASE) and
  186.            y >= iy and y < iy + 2 then
  187.            return i
  188.         end if
  189.         if src_chk then
  190.         -- check other end of Euphoria too
  191.         -- (assumes base is reasonably wide)
  192.         if xend >= ix and xend < ix + length(BASE) and
  193.            y >= iy and y < iy + 2 then
  194.             return i
  195.         end if
  196.         end if
  197.  
  198.     elsif t = G_PL then
  199.         if x >= ix and x < ix + length(PLANET_MIDDLE) and
  200.            y >= iy and y < iy + 3 then
  201.         return i
  202.         end if
  203.         if src_chk then
  204.         -- check other end of Euphoria too
  205.         -- (assumes planet is reasonably wide)
  206.         if xend >= ix and xend < ix + length(PLANET_MIDDLE) and
  207.            y >= iy and y < iy + 3 then
  208.             return i
  209.         end if
  210.         end if
  211.  
  212.     elsif t then
  213.         if i = EUPHORIA then
  214.         len = length(esym)
  215.         else
  216.         len = length(ship[t][1])
  217.         end if
  218.         if x >= ix and x < ix + len and y = iy then
  219.         return i
  220.         end if
  221.         if src_chk then
  222.         -- check other end too
  223.         if xend >= ix and xend < ix + len and y = iy then
  224.             return i
  225.         end if
  226.         end if
  227.     end if
  228.     end for
  229. end function
  230.  
  231.  
  232. procedure dead(valid_quadrant_row row)
  233. -- process a dead object
  234.  
  235.     object_type t
  236.     h_coord x
  237.     v_coord y
  238.     pb_row pbx
  239.     natural len
  240.  
  241.     t = quadrant[row][Q_TYPE]
  242.     if row = EUPHORIA then
  243.     -- Euphoria destroyed !
  244.     quadrant[EUPHORIA][Q_EN] = 0
  245.     p_energy(-1)
  246.     else
  247.     nobj[t] = nobj[t] - 1
  248.     galaxy[qrow][qcol][t] = galaxy[qrow][qcol][t] - 1
  249.     x = quadrant[row][Q_X]
  250.     y = quadrant[row][Q_Y]
  251.     set_bk_color(BLACK)
  252.     set_color(BRIGHT_WHITE)
  253.     if t >= G_PL then
  254.         pbx = quadrant[row][Q_PBX]
  255.         pb[pbx][P_TYPE] = DEAD
  256.         if t = G_BS then
  257.         len = length(BASE)
  258.         for i = 0 to 1 do
  259.             display_screen(x, y + i, repeat('*', len))
  260.             wipeout = append(wipeout, {x, y + i, len})
  261.         end for
  262.         else
  263.         len = length(PLANET_MIDDLE)
  264.         for i = 0 to 2 do
  265.             display_screen(x, y + i, repeat('*', len))
  266.             wipeout = append(wipeout, {x, y + i, len})
  267.         end for
  268.         end if
  269.     else
  270.         len = length(ship[t][1])
  271.         display_screen(x, y, repeat('*', len))
  272.         wipeout = append(wipeout, {x, y, len})
  273.         if c_remaining() = 0 then
  274.         gameover = TRUE
  275.         end if
  276.     end if
  277.     quadrant[row][Q_TYPE] = DEAD
  278.     quadrant[row][Q_X] = HSIZE + 1
  279.     quadrant[row][Q_Y] = VSIZE + 1
  280.     setnt()
  281.     fmsg("%s DESTROYED!", {otype[t]})
  282.     sched(TASK_DEAD, 1.6)
  283.     end if
  284.     explosion_sound()
  285.     if scanon then
  286.     upg(qrow, qcol)
  287.     gsbox(qrow, qcol)
  288.     gtext()
  289.     end if
  290. end procedure
  291.  
  292. global procedure dodmg(positive_atom blast, boolean wtorp)
  293. -- damage a struck object
  294.     object_type t
  295.     natural d
  296.     positive_atom ven
  297.  
  298.     t = quadrant[victim][Q_TYPE]
  299.     if quadrant[shooter][Q_TYPE] = G_POD then
  300.         if t = G_BAS then
  301.         setrmt(EUPHORIA)
  302.         else
  303.         quadrant[victim][Q_TARG] = EUPHORIA
  304.         end if
  305.     else
  306.         if t = G_BAS then
  307.         setrmt(shooter)
  308.         else
  309.         quadrant[victim][Q_TARG] = shooter
  310.         end if
  311.     end if
  312.     if wtorp then
  313.     -- torpedo
  314.     d = quadrant[victim][Q_DEFL]
  315.     if d then
  316.         deflected_sound()
  317.         msg("DEFLECTED")
  318.         quadrant[victim][Q_DEFL] = d-1
  319.         ds = repeat(DEFLECTOR, quadrant[EUPHORIA][Q_DEFL])
  320.         wtext()
  321.         blast = 0
  322.     else
  323.         torpedo_sound()
  324.     end if
  325.     end if
  326.     if blast then
  327.     fmsg("%d UNIT HIT ON %s", {blast, otype[t]})
  328.     ven = quadrant[victim][Q_EN]
  329.     if blast >= ven then
  330.         dead(victim)
  331.     else
  332.         ven = ven - blast
  333.         quadrant[victim][Q_EN] = ven
  334.         if t <= G_FOR then
  335.         if victim = EUPHORIA then
  336.             p_energy(0)
  337.             edmg(blast)
  338.         else
  339.             fmsg("%d UNITS REMAIN", ven)
  340.         end if
  341.         end if
  342.     end if
  343.     end if
  344. end procedure
  345.  
  346. global constant ASPECT_RATIO = 2.6 -- roughly (distance of one line up/down = 
  347.                    -- how many chars left-right) 
  348.  
  349. global function bcalc(positive_atom energy)
  350. -- calculate amount of phasor blast
  351.     atom xdiff, ydiff
  352.  
  353.     xdiff = quadrant[victim][Q_X] - quadrant[shooter][Q_X]
  354.     ydiff = (quadrant[victim][Q_Y] - quadrant[shooter][Q_Y]) * ASPECT_RATIO
  355.     return 200 * energy / (5 + sqrt(xdiff * xdiff + ydiff * ydiff))
  356. end function
  357.