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

  1. -- damage.e
  2. -- compute effects of damage
  3.  
  4. global function tholian_target(valid_f_row r)
  5. -- select target for tholian at row r
  6.     sequence flive
  7.  
  8.     flive = {ENTERPRISE}
  9.     for i = fb1 to fnext-1 do
  10.     if i != r and f[i][F_TYPE] 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_f_row newtarg)
  18. -- set Romulan target
  19.  
  20.     rtarg = newtarg
  21.     if rstat = TRUCE then
  22.     if rtarg = ENTERPRISE or f[rtarg][F_TYPE] = G_BS then
  23.         truce_broken = TRUE
  24.         sched(TASK_RSTAT, 2.5)
  25.     end if
  26.     end if
  27.     for row = fr1 to fnext-1 do
  28.     if f[row][F_TYPE] = G_RM then
  29.         f[row][F_TARG] = rtarg
  30.     end if
  31.     end for
  32. end procedure
  33.  
  34. procedure setnt()
  35. -- target is dead - pick new target
  36.     positive_int t -- object_type t or t = 0
  37.     valid_f_row targ
  38.  
  39.     for row = fb1 to fnext-1 do
  40.     if f[row][F_TARG] = victim then
  41.         t = f[row][F_TYPE]
  42.         if t = G_BS then
  43.         f[row][F_FRATE] = 0
  44.         else
  45.         if t = G_TH then
  46.             targ = tholian_target(row)
  47.         else
  48.             targ = ENTERPRISE
  49.         end if
  50.         f[row][F_TARG] = targ
  51.         end if
  52.     end if
  53.     end for
  54.     if victim = rtarg then
  55.     rtarg = ENTERPRISE
  56.     end if
  57. end procedure
  58.  
  59. global procedure repair(subsystem sys)
  60. -- repair a subsystem
  61.     if sys = ENGINES then
  62.     wlimit = 5
  63.     set_bk_color(WHITE)
  64.     set_color(BLACK)
  65.     position(WARP_LINE, 8)
  66.     printf(CRT, "%d   ", curwarp)
  67.     end if
  68.     ndmg = ndmg - 1
  69. end procedure
  70.  
  71. procedure edmg(positive_atom blast)
  72. -- Enterprise damage
  73.     subsystem sys
  74.  
  75.     if blast > rand(256) * 60 then
  76.     sys = rand(NSYS)
  77.     if reptime[sys] = 0 then
  78.         sounde(11, 12, 5)
  79.         reptime[sys] = rand(81) + 9
  80.         if sys = GALAXY_SENSORS then
  81.         setg1()
  82.         end if
  83.         msg("")
  84.         if sys = ENGINES then
  85.         wlimit = rand(4) - 1
  86.         if curwarp > wlimit then
  87.             setwarp(wlimit)
  88.             msg("")
  89.             if wlimit = 0 then
  90.             puts(CRT, "ALL ")
  91.             end if
  92.         end if
  93.         end if
  94.         printf(CRT, "%s DAMAGED", {dtype[sys]})
  95.         wait[TASK_DAMAGE] = 2.0
  96.         ndmg = ndmg + 1
  97.         sched(TASK_DAMAGE, 2.0)
  98.     end if
  99.     end if
  100. end procedure
  101.  
  102. global procedure drep()
  103. -- damage report update
  104.     set_bk_color(GREEN)
  105.     set_color(BRIGHT_WHITE)
  106.     position(WARP_LINE, 50)
  107.     puts(CRT, repeat(' ', 13))
  108.     position(WARP_LINE+1, 50)
  109.     puts(CRT, repeat(' ', 13))
  110.     position(WARP_LINE, 51)
  111.     printf(CRT, "P%d T%d S%d", {reptime[PHASORS],
  112.                 reptime[TORPEDOS],
  113.                 reptime[GALAXY_SENSORS]})
  114.     position(CMD_LINE, 51)
  115.     printf(CRT, "G%d E%d", {reptime[GUIDANCE], reptime[ENGINES]})
  116.     if reptime[ENGINES] > 0 then
  117.     printf(CRT, ":%d", wlimit)
  118.     end if
  119. end procedure
  120.  
  121. global procedure t9dmg()
  122. -- task 9: damage countdown
  123.  
  124.     if ndmg = 0 then
  125.     wait[TASK_DAMAGE] = 0
  126.     set_bk_color(WHITE)
  127.     position(WARP_LINE, 50)
  128.     puts(CRT, repeat(' ', 13))
  129.     position(WARP_LINE+1, 50)
  130.     puts(CRT, repeat(' ', 13))
  131.     else
  132.     for i = 1 to NSYS do
  133.         if reptime[i] then
  134.         reptime[i] = reptime[i] - 1
  135.         if reptime[i] = 0 then
  136.             sounde(6, 20, 1)
  137.             repair(i)
  138.             msg("")
  139.             printf(CRT, "%s REPAIRED", {dtype[i]})
  140.         end if
  141.         end if
  142.     end for
  143.     drep()
  144.     end if
  145. end procedure
  146.  
  147. global function fstart(object_type t)
  148. -- choose a starting point for f search
  149.     if t <= G_JM then
  150.     return fk1
  151.     elsif t = G_RM then
  152.     return fr1
  153.     elsif t = G_TH then
  154.     return ft1
  155.     elsif t = G_PL then
  156.     return ENTERPRISE + 1
  157.     else
  158.     return fb1
  159.     end if
  160. end function
  161.  
  162. global function flook(h_coord x, v_coord y, boolean src_chk)
  163. -- map (x,y) screen coordinate to f array row
  164. -- src_chk is true when we just want to see if we are docking
  165.  
  166.     extended_h_coord ix
  167.     extended_v_coord iy
  168.     positive_int t, len, xend
  169.  
  170.     xend = x + length(esym) - 1
  171.     for i = ENTERPRISE + src_chk to fnext-1 do
  172.     ix = f[i][F_X]
  173.     iy = f[i][F_Y]
  174.     t = f[i][F_TYPE]
  175.  
  176.     if t = G_BS then
  177.         if x >= ix and x < ix + length(BASE) and
  178.            y >= iy and y < iy + 2 then
  179.            return i
  180.         end if
  181.         if src_chk then
  182.         -- check other end of Enterprise too
  183.         -- (assumes base is reasonably wide)
  184.         if xend >= ix and xend < ix + length(BASE) and
  185.            y >= iy and y < iy + 2 then
  186.             return i
  187.         end if
  188.         end if
  189.  
  190.     elsif t = G_PL then
  191.         if x >= ix and x < ix + length(PLANET_MIDDLE) and
  192.            y >= iy and y < iy + 3 then
  193.         return i
  194.         end if
  195.         if src_chk then
  196.         -- check other end of Enterprise too
  197.         -- (assumes planet is reasonably wide)
  198.         if xend >= ix and xend < ix + length(PLANET_MIDDLE) and
  199.            y >= iy and y < iy + 3 then
  200.             return i
  201.         end if
  202.         end if
  203.  
  204.     elsif t then
  205.         if i = ENTERPRISE then
  206.         len = length(esym)
  207.         else
  208.         len = length(ship[t][1])
  209.         end if
  210.         if x >= ix and x < ix + len and y = iy then
  211.         return i
  212.         end if
  213.         if src_chk then
  214.         -- check other end too
  215.         if xend >= ix and xend < ix + len and y = iy then
  216.             return i
  217.         end if
  218.         end if
  219.     end if
  220.     end for
  221. end function
  222.  
  223.  
  224. procedure dead(valid_f_row row)
  225. -- process a dead object
  226.  
  227.     object_type t
  228.     h_coord x
  229.     v_coord y
  230.     pb_row pbx
  231.     positive_int len
  232.  
  233.     t = f[row][F_TYPE]
  234.     if row = ENTERPRISE then
  235.     -- Enterprise destroyed !
  236.     f[ENTERPRISE][F_EN] = 0
  237.     p_energy(-1)
  238.     else
  239.     sounde(10,3,1)
  240.     urt = t
  241.     ur = 0
  242.     nobj[t] = nobj[t] - 1
  243.     g[qrow][qcol][urt] = g[qrow][qcol][urt] - 1
  244.     x = f[row][F_X]
  245.     y = f[row][F_Y]
  246.     set_bk_color(BLACK)
  247.     set_color(BRIGHT_WHITE)
  248.     if t >= G_PL then
  249.         pbx = f[row][F_PBX]
  250.         pb[pbx][P_EXIST] = DESTROYED
  251.         if scanon then
  252.         dsyms()
  253.         end if
  254.         if t = G_BS then
  255.         len = length(BASE)
  256.         for i = 0 to 1 do
  257.             display_screen(x, y + i, repeat('*', len))
  258.             wipeout = append(wipeout, {x, y + i, len})
  259.         end for
  260.         else
  261.         len = length(PLANET_MIDDLE)
  262.         for i = 0 to 2 do
  263.             display_screen(x, y + i, repeat('*', len))
  264.             wipeout = append(wipeout, {x, y + i, len})
  265.         end for
  266.         end if
  267.     else
  268.         len = length(ship[t][1])
  269.         display_screen(x, y, repeat('*', len))
  270.         wipeout = append(wipeout, {x, y, len})
  271.         if nkl() = 0 then
  272.         gameover = TRUE
  273.         end if
  274.     end if
  275.     f[row][F_TYPE] = 0 -- indicates dead guy
  276.     f[row][F_X] = HSIZE + 1
  277.     f[row][F_Y] = VSIZE + 1
  278.     setnt()
  279.     sched(TASK_UREM, 1.0)
  280.     sched(TASK_DEAD, 1.6)
  281.     end if
  282.     explosion_sound()
  283.     if scanon then
  284.     upg(qrow, qcol)
  285.     gsbox(qrow, qcol)
  286.     gtext()
  287.     end if
  288. end procedure
  289.  
  290. global procedure dodmg(positive_atom blast, boolean wtorp)
  291. -- damage a struck object
  292.     object_type t
  293.     positive_int d
  294.     positive_atom ven
  295.  
  296.     msg("")
  297.     t = f[victim][F_TYPE]
  298.     if t = G_RM then
  299.     setrmt(shooter)
  300.     else
  301.     f[victim][F_TARG] = shooter
  302.     end if
  303.     if wtorp then
  304.     -- torpedo
  305.     d = f[victim][F_DEFL]
  306.     if d then
  307.         puts(CRT, "DEFLECTED")
  308.         f[victim][F_DEFL] = d-1
  309.         ds = repeat(DEFLECTOR, f[ENTERPRISE][F_DEFL])
  310.         wtext()
  311.         blast = 0
  312.     end if
  313.     end if
  314.     if blast then
  315.     if t <= G_TH then
  316.         printf(CRT, "%d UNIT HIT ON %s", {blast, otype[t]})
  317.     end if
  318.     ven = f[victim][F_EN]
  319.     if blast >= ven then
  320.         dead(victim)
  321.     else
  322.         ven = ven - blast
  323.         f[victim][F_EN] = ven
  324.         if t <= G_TH then
  325.         if victim = ENTERPRISE then
  326.             p_energy(0)
  327.             edmg(blast)
  328.         else
  329.             ur = ven
  330.             sched(TASK_UREM, 1.0)
  331.         end if
  332.         end if
  333.     end if
  334.     end if
  335. end procedure
  336.  
  337. global constant ASPECT_RATIO = 3 -- roughly
  338.  
  339. global function bcalc(positive_atom energy)
  340. -- calculate amount of phasor blast
  341.     atom xdiff, ydiff
  342.  
  343.     xdiff = f[victim][F_X] - f[shooter][F_X]
  344.     ydiff = (f[victim][F_Y] - f[shooter][F_Y]) * ASPECT_RATIO
  345.     return 200 * energy / (5 + sqrt(xdiff * xdiff + ydiff * ydiff))
  346. end function
  347.