EditorRUS

Untitled

Jan 7th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. //----------------------------------------------
  2. //Raycast explosion system
  3. //----------------------------------------------
  4.  
  5. var/datum/explosions/controller/the_controller = new
  6. var/datum/explosions/debug_panel/debug_panel = new
  7.  
  8. #define IDLE 0
  9. #define NEWDATA 1
  10. #define NEWEXPL 2
  11. #define EXPLOSION 3
  12. #define INPROCESS 4
  13. /list/proc/Append(data)
  14. var/dimensions = args.len-1
  15. var/list/curlst = src
  16. for (var/indx = 2, indx!=dimensions, indx++)
  17. var/curindx = args[indx]
  18. if (isnum(curdim))
  19. if (curlst.len < curindx) curlst.len = curindx
  20. if (!curlst[curindx])
  21. curlst[curdindx] = list()
  22. if (indx==dimensions)
  23. curlst[curindx] += data
  24. src = curlst
  25.  
  26.  
  27. /datum/explosions
  28. controller
  29. var/list/datum/explosions/explosion/explosions = list()
  30. var/list/datum/explosions/explosion_data/data_garbage = list()
  31. var/list/list/datum/explosions/explosion_data/data_sorted = list()
  32.  
  33. var/explosion_step = 1
  34. var/state = IDLE
  35.  
  36. New()
  37. Start()
  38.  
  39. proc
  40. AddData(datum/explosions/explosion_data/data)
  41. if (!data || data in data_garbage || data in data_sorted) return 0
  42. data_garbage += data
  43. state = NEWDATA
  44. return 1
  45.  
  46. AddExplosion(datum/explosions/explosion/exp)
  47. if (!exp || exp in explosions) return 0
  48. explosions += exp
  49. state = NEWEXPL
  50. return 1
  51.  
  52. Start()
  53. spawn(1) .()
  54. switch(state)
  55. if (IDLE)
  56. explosion_step = 1
  57. if (NEWDATA)
  58. SortData()
  59. state = EXPLOSION
  60. if (NEWEXPL)
  61. CalculateExplosions()
  62. if (EXPLOSION)
  63. DoExplosions()
  64. state = INPROCESS
  65.  
  66. SortData()
  67.  
  68.  
  69. CalculateExplosions()
  70. for (var/datum/explosions/explosion/exp in explosions)
  71. exp.calculate_explosion()
  72. state = EXPLOSION
  73.  
  74. DoExplosions()
  75. return 0
  76.  
  77.  
  78.  
  79. explosion
  80. var/turf/ground_zero
  81. var/radius = 0
  82.  
  83. New(turf/loc, radius)
  84. if (loc && radius > 0)
  85. src.ground_zero = loc
  86. src.radius = radius
  87. the_controller.AddExplosion(src)
  88. return 1
  89. del(src)
  90.  
  91. proc
  92. cast_ray(turf/target)
  93. if (!target) return 0
  94.  
  95. var/turf/currturf = ground_zero
  96. var/remain_radius = radius
  97.  
  98. do
  99. var/taken_radius = 0
  100. var/list/atom/stuff = list()
  101. var/turf/newturf = get_step_towards(currturf, target)
  102.  
  103. stuff += currturf.contents
  104. stuff += currturf
  105.  
  106. for (var/atom/A in stuff)
  107. if (isturf(A) || isobj(A)) taken_radius += (A:explosion_resistance ? A:explosion_resistance : 0)
  108. remain_radius -= taken_radius * get_dist_euclidian(currturf, newturf)
  109. currturf = newturf
  110. while (currturf != target && remain_radius > 0)
  111.  
  112. return get_severity(remain_radius)
  113.  
  114. cast_ray_trace(turf/target)
  115. if (!target) return 0
  116.  
  117. var/turf/currturf = ground_zero
  118. var/remain_radius = radius
  119. var/list/datum/explosions/explosion_data/data = list()
  120.  
  121. do
  122. var/list/atom/stuff = list()
  123. var/turf/newturf = get_step_towards(currturf, target)
  124.  
  125. stuff += currturf.contents
  126. stuff += currturf
  127.  
  128. for (var/atom/A in stuff)
  129. var/datum/explosions/explosion_data/new_data = new
  130. new_data.object = A
  131. new_data.location = currturf
  132. new_data.power = get_severity(remain_radius)
  133. new_data.explosion = src
  134. data += new_data
  135. var/taken_radius = 0
  136. for (var/atom/A in stuff)
  137. if (isturf(A) || isobj(A)) taken_radius += (A:explosion_resistance ? A:explosion_resistance : 0)
  138. remain_radius -= taken_radius * get_dist_euclidian(currturf, newturf)
  139. currturf = newturf
  140. while (currturf != target && remain_radius > 0)
  141.  
  142. return data
  143.  
  144. calculate_explosion()
  145. var/xx1 = min(max(1, ground_zero.x-radius), world.maxx)
  146. var/yy1 = min(max(1, ground_zero.y-radius), world.maxy)
  147. var/xx2 = min(max(1, ground_zero.x+radius), world.maxx)
  148. var/yy2 = min(max(1, ground_zero.y+radius), world.maxy)
  149. var/z = ground_zero.z
  150. var/list/turf/corners = block(locate(xx1,yy1,z), locate(xx2,yy2,z))
  151.  
  152. var/list/datum/explosions/explosion_data/return_data = list()
  153. for (var/turf/corner in corners)
  154. var/list/datum/explosions/explosion_data/data = cast_ray_trace(corner)
  155. return_data += data
  156. the_controller.AddData(data)
  157. return return_data
  158.  
  159. get_severity(radius)
  160. var/const/max_dest = 1 - 1/4
  161. var/const/hev_dest = 1 - 1/2
  162. var/const/lig_dest = 1 - 1/1
  163. if (radius >= src.radius * max_dest) return 1
  164. if (radius >= src.radius * hev_dest) return 2
  165. if (radius >= src.radius * lig_dest) return 3
  166. return 0
  167.  
  168. explosion_data
  169. var/atom/object
  170. var/power = 0
  171. var/turf/location
  172. var/datum/explosions/explosion/explosion
  173. var/step = 0
  174.  
  175. proc/get_explosion_step()
  176. return the_controller.explosion_step + round(get_dist_euclidian(object, explosion.ground_zero))
  177.  
  178.  
  179.  
  180.  
  181. /datum/explosions/debug_panel
  182. var/datum/explosions/explosion/virtual
  183.  
  184.  
  185. /datum/explosions/debug_panel/proc/send()
  186. var/dat = {"
  187. Debug:<br>
  188. /datum/explosions/explosion:<br>
  189. <a href='?src=\ref[src];action=1'>Create new splosion</a><br>
  190. <a href='?src=\ref[src];action=2'>cast_ray</a><br>
  191. <a href='?src=\ref[src];action=4'>calculate_explosion</a><br>
  192. <a href='?src=\ref[src];action=5'>get_severity</a><br>
  193. /datum/explosions/controller<br>
  194. <a href='?src=\ref[src];action=6'>AddExplosion</a><br>
  195. <a href='?src=\ref[src];action=7'>SortData</a><br>
  196. <a href='?src=\ref[src];action=8'>Show vars</a><br>
  197. <a href='?src=\ref[src];action=9'>Show sorted</a><br>
  198. "}
  199. usr << browse(dat, "window=debugpanel")
  200.  
  201. /datum/explosions/debug_panel/Topic(href, href_list)
  202. switch (text2num(href_list["action"]))
  203. if (1)
  204. var/turf/center = get_turf(usr)
  205. var/radius = input(usr, "radius") as num
  206. virtual = new (center, radius)
  207. the_controller.explosions -= virtual
  208. the_controller.state = IDLE
  209. if (2)
  210. usr << virtual.cast_ray(get_turf(usr))
  211. if (4)
  212. var/list/datum/explosions/explosion_data/data = virtual.calculate_explosion()
  213. the_controller.data_garbage -= data
  214. for (var/datum/explosions/explosion_data/D in data)
  215. if (isturf(D.object))
  216. D.object.color = debug_color(D)
  217. spawn(20)
  218. for (var/datum/explosions/explosion_data/D in data)
  219. if (isturf(D.object))
  220. D.object.color = null
  221. if (5)
  222. usr << virtual.get_severity(input(usr, "radius") as num)
  223. if (6)
  224. the_controller.AddExplosion(virtual)
  225. sleep(5)
  226. the_controller.state = IDLE
  227. if (7)
  228. the_controller.SortData()
  229. if (8)
  230. var/dat = {"
  231. data_garbage: [the_controller.data_garbage.len]<br>
  232. data_sorted: [the_controller.data_sorted.len]<br>
  233. "}
  234. var/res = "\green OK"
  235. for (var/list/datum/explosions/explosion_data/A in the_controller.data_sorted)
  236. for (var/datum/explosions/explosion_data/B in A)
  237. for (var/datum/explosions/explosion_data/C in A)
  238. if (B == C) continue
  239. if (B.object == C.object) res = "\red ERROR"
  240. dat += res
  241. usr << browse(dat, "window=dms")
  242. if (9)
  243. for (var/list/datum/explosions/explosion_data/A in the_controller.data_sorted)
  244. for (var/datum/explosions/explosion_data/B in A)
  245. if (isturf(B.object))
  246. B.object.color = debug_color(B)
  247. sleep(10)
  248. spawn(10)
  249. for (var/list/datum/explosions/explosion_data/A in the_controller.data_sorted)
  250. for (var/datum/explosions/explosion_data/B in A)
  251. if (isturf(B.object))
  252. B.object.color = null
  253.  
  254. proc/debug_color(datum/explosions/explosion_data/A)
  255. return (A.power == 1 ? "#ffff00" : (A.power == 2 ? "#ff9900" : (A.power == 3 ? "#ff0000" : null)))
  256.  
  257. /mob/verb/debug_explosions()
  258. set name = "Show debug panel"
  259. set category = "Debug"
  260.  
  261. debug_panel.send()
  262.  
  263. #undef IDLE
Add Comment
Please, Sign In to add comment