Advertisement
EditorRUS

explosion.dm

Aug 13th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. var/datum/explosions/controller/the_controller = new
  2.  
  3. /datum/explosions/controller
  4. var/list/datum/explosions/explosion/to_process = list()
  5. var/list/datum/explosions/explosion/being_processed = list()
  6.  
  7. var/explosion_step = 0
  8.  
  9.  
  10.  
  11. /datum/explosions/controller/proc/make_explosion()
  12. explosion_step = 0
  13. for (var/datum/explosions/explosion/X in to_process)
  14. X.calculate_all()
  15. for (var/datum/explosions/explosion/X in to_process)
  16. X.merge()
  17. for (var/datum/explosions/explosion/X in to_process)
  18. being_processed += X
  19. to_process -= X
  20. do_explosion()
  21.  
  22. /datum/explosions/controller/proc/do_explosion()
  23. var/started_at = explosion_step
  24. var/still_going = 1
  25. spawn while (still_going)
  26. still_going = 0
  27. var/list/list/datum/explosions/data/sorted = list()
  28. for (var/datum/explosions/explosion/EXP in being_processed)
  29. if (EXP.affected.len)
  30. still_going = 1
  31. for (var/datum/explosions/data/D in EXP.affected)
  32. sorted[round(get_dist(D.old_turf,EXP.ground_center))] += D
  33. if (still_going)
  34. explosion_step++
  35. for (var/datum/explosions/data/D in sorted[explosion_step - started_at])
  36. D.affected.ex_act(D.power)
  37.  
  38.  
  39.  
  40.  
  41. /datum/explosions/controller/proc/add(datum/explosions/explosion/exp)
  42. exp.taken_place_at = explosion_step
  43. to_process += exp
  44. spawn(0) do_explosion()
  45.  
  46. //
  47. // 3,7,14,35 - ideal explosion
  48. // 14 is max. radius
  49. // Therefore 21% of radius is max destruction.
  50. // Therefore 50% of radius is heavy destruction
  51. // The rest is light destruction
  52. //
  53.  
  54. #define MAX_DESTRUCTION .21
  55. #define HEV_DESTRUCTION .50
  56. #define LIG_DESTRUCTION 1.0
  57.  
  58. datum/explosions/explosion
  59. var/turf/ground_center
  60. var/list/datum/explosions/data/affected = list()
  61. var/atom/movable/ray = new
  62. var/taken_place_at = 0
  63. var/initial_radius = 0
  64. var/maxi_radius = 0
  65. var/heav_radius = 0
  66. var/ligh_radius = 0
  67.  
  68. New(turf/loc, power)
  69. if (loc)
  70. ground_center = loc
  71. initial_radius = power
  72. maxi_radius = initial_radius * MAX_DESTRUCTION
  73. heav_radius = initial_radius * HEV_DESTRUCTION
  74. ligh_radius = initial_radius * LIG_DESTRUCTION
  75. if (the_controller)
  76. the_controller.to_process += src
  77.  
  78. //
  79. // By casting rays calculate which tiles are affected.
  80. // If one of tiles are affected by different waves - use the strongest one.
  81. //
  82. datum/explosions/data
  83. var/atom/affected
  84. var/turf/old_turf
  85. var/power = 0
  86. New (what, power, datum/explosions/explosion/callback)
  87. src.affected = what
  88. src.old_turf = get_turf(what)
  89. src.power = power
  90.  
  91. datum/explosions/explosion/proc/calculate_all()
  92. var/list/turf/borders = range(initial_radius, ground_center) - range(initial_radius-1, ground_center)
  93.  
  94. for (var/turf/target in borders)
  95. calculate_trace(ground_center, target, initial_radius)
  96.  
  97. datum/explosions/explosion/proc/calculate_trace(atom/target, initial)
  98. ray.loc = ground_center
  99. var/remain_force = initial
  100. do
  101. if (target)
  102. step_to(ray,target)
  103. var/resistance = 0
  104. for (var/atom/A in get_turf(ray))
  105. if ( (isobj(A) || isturf(A) ) && A != ray) resistance += A:explosion_resistance
  106. remain_force -= resistance
  107. for (var/atom/A in get_turf(ray))
  108. affected += new (A, calc_exact(remain_force), src)
  109. while (remain_force > 0 || ray.loc != get_turf(target))
  110. return 0
  111.  
  112. datum/explosions/explosion/proc/calculate_power(atom/target, initial)
  113. ray.loc = ground_center
  114. var/remain_force = initial
  115. do
  116. if (target)
  117. step_to(ray,target)
  118. var/resistance = 0
  119. for (var/atom/A in get_turf(ray))
  120. if ( (isobj(A) || isturf(A) ) && A != ray) resistance += A:explosion_resistance
  121. remain_force -= resistance
  122. while (remain_power > 0 || ray.loc != get_turf(target))
  123. return calc_exact (remain_power)
  124.  
  125. datum/explosions/explosion/proc/calc_exact(force)
  126. if (force >= initial_radius - maxi_radius) return 1
  127. if (force >= initial_radius - heav_radius) return 2
  128. if (force >= initial_radius - ligh_radius) return 3
  129. return 0
  130.  
  131. datum/explosions/explosion/proc/merge()
  132. for (var/datum/explosions/data/chosen in affected)
  133. for (var/datum/explosions/data/second in affected)
  134. if (chosen != second && chosen.old_turf == second.old_turf)
  135. if (second.power > chosen.power)
  136. second.power = chosen.power
  137. affected -= chosen
  138. del(chosen)
  139. else
  140. affected -= second
  141. del(second)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement