Advertisement
EditorRUS

Explosion.dm

Aug 14th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. //----------------------------------------------
  2. //Raycast explosion system
  3. //----------------------------------------------
  4.  
  5. var/datum/explosions/controller/the_controller = new
  6.  
  7. #define IDLE 0
  8. #define STARTING 1
  9. #define MERGE 2
  10. #define PROCESSING 3
  11. #define INPROCESSING 4
  12.  
  13. /datum/explosions
  14. controller
  15. var/list/datum/explosions/explosion/explosions = list()
  16.  
  17. //var/list/datum/explosions/explosion_data/data_by_turf = list()
  18. var/list/list/datum/explosions/explosion_data/data_by_step = list()
  19.  
  20. var/explosion_step = 0
  21. var/state = IDLE
  22.  
  23. var/atom/movable/ray
  24.  
  25. New()
  26. ray = new
  27. ray.invisibility = 101
  28. ..()
  29. start()
  30.  
  31. proc
  32. AddExplosion(datum/explosions/explosion/exp)
  33. if (exp)
  34. sleep(0)
  35. explosions += exp
  36. state = STARTING //Activate
  37.  
  38. AddData(datum/explosions/explosion_data/expdata, datum/explosions/explosion/exp)
  39. var/dist = get_dist(expdata.object, exp.ground_zero)
  40. var/step = explosion_step + round(dist)
  41. data_by_step[step] += expdata
  42.  
  43. start()
  44. //----------------------------------------------------
  45. // Asynchonous machine. Explosion can be added intime.
  46. //----------------------------------------------------
  47. spawn while (1)
  48. if (state == STARTING)
  49. for (var/datum/explosions/explosion/exp in explosions)
  50. exp.calculate_explosion()
  51. state = MERGE
  52. if (state == MERGE)
  53. merge()
  54. state = PROCESSING
  55. if (state == PROCESSING)
  56. state = INPROCESSING
  57. start_processing()
  58.  
  59. start_processing()
  60. spawn while (data_by_step[explosion_step+1])
  61. explosion_step++
  62. recalculate()
  63. for (var/datum/explosions/explosion_data/expdata in data_by_step[explosion_step])
  64. expdata.object.ex_act(expdata.power)
  65. data_by_step[explosion_step] -= expdata
  66. explosion_step = 0
  67. state = IDLE
  68.  
  69. recalculate()
  70. for (var/list/datum/explosions/explosion_data/expdata in data_by_step)
  71. for (var/datum/explosions/explosion_data/check in expdata)
  72. if (get_turf(check.object) == check.location) continue
  73. check.power = check.explosion.cast_ray(get_turf(check.object)) //Find new power for moved object
  74. data_by_step[data_by_step.Find(expdata)] -= check //Delete old
  75. AddData(check, check.explosion) //Add old in new place
  76.  
  77. merge()
  78. for (var/list/datum/explosions/explosion_data/expdata in data_by_step)
  79. for (var/datum/explosions/explosion_data/first in expdata)
  80. for (var/datum/explosions/explosion_data/second in expdata)
  81. if (first == second) continue
  82. if (first.object != second.object) continue
  83. if (first.power > second.power)
  84. first.power = second.power
  85. expdata -= second
  86. del(second)
  87.  
  88.  
  89.  
  90. explosion
  91. var/turf/ground_zero
  92. var/radius = 0
  93.  
  94. New(turf/loc, radius)
  95. if (loc && radius > 0)
  96. src.ground_zero = loc
  97. src.radius = radius
  98. the_controller.AddExplosion(src)
  99. return 1
  100. del(src)
  101. CRASH("/datum/explosions/explosion has crashed at NEW")
  102.  
  103. proc
  104. cast_ray(turf/target)
  105. spawn(-1)
  106. if (!target) return 0
  107.  
  108. var/atom/ray = the_controller.ray
  109. var/remain_radius = radius
  110. the_controller.ray.loc = ground_zero
  111.  
  112. do
  113. var/taken_radius = 0
  114. for (var/atom/A in get_turf(ray))
  115. if (A == ray) continue
  116. if (A.vars["explosion_resistance"]) taken_radius += A:explosion_resistance
  117. step_towards(ray, target)
  118. remain_radius -= taken_radius
  119. while (get_turf(ray) != target && remain_radius > 0)
  120. the_controller.ray.loc = null
  121.  
  122. return get_severity(remain_radius)
  123.  
  124. cast_ray_trace(turf/target)
  125. spawn(-1)
  126. if (!target) return 0
  127. var/atom/ray = the_controller.ray
  128. var/remain_radius = radius
  129. var/list/datum/explosions/explosion_data/data = list()
  130.  
  131. the_controller.ray.loc = ground_zero
  132.  
  133. do
  134. for (var/atom/A in get_turf(ray))
  135. if (A == ray) continue
  136. var/datum/explosions/explosion_data/new_data = new
  137. new_data.object = A
  138. new_data.location = get_turf(A)
  139. new_data.power = get_severity(remain_radius)
  140. new_data.explosion = src
  141. data += new_data
  142. step_towards(ray, target)
  143. var/taken_radius = 0
  144. for (var/atom/A in get_turf(ray))
  145. if (A == ray) continue
  146. if (A.vars["explosion_resistance"]) taken_radius += A:explosion_resistance
  147. remain_radius -= taken_radius
  148. while (get_turf(ray) != target && remain_radius > 0)
  149. the_controller.ray.loc = null
  150.  
  151. return data
  152.  
  153. calculate_explosion()
  154. var/list/turf/corners = range(radius+1, ground_zero) - range(radius, ground_zero)
  155.  
  156. for (var/turf/corner in corners)
  157. var/list/datum/explosions/explosion_data/data = cast_ray_trace(corner)
  158. the_controller.AddData(data, src)
  159.  
  160. get_severity(radius)
  161. var/const/max_dest = 1 - 3/14
  162. var/const/hev_dest = 1 - 7/14
  163. var/const/lig_dest = 1 - 14/14
  164. if (radius >= src.radius * max_dest) return 1
  165. if (radius >= src.radius * hev_dest) return 2
  166. if (radius >= src.radius * lig_dest) return 3
  167. return 0
  168.  
  169. explosion_data
  170. var/atom/object
  171. var/power = 0
  172. var/turf/location
  173. var/datum/explosions/explosion/explosion
  174.  
  175. /datum/explosions/debug_panel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement