Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var/datum/explosions/controller/the_controller = new
- /datum/explosions/controller
- var/list/datum/explosions/explosion/to_process = list()
- var/list/datum/explosions/explosion/being_processed = list()
- var/explosion_step = 0
- /datum/explosions/controller/proc/make_explosion()
- explosion_step = 0
- for (var/datum/explosions/explosion/X in to_process)
- X.calculate_all()
- for (var/datum/explosions/explosion/X in to_process)
- X.merge()
- for (var/datum/explosions/explosion/X in to_process)
- being_processed += X
- to_process -= X
- do_explosion()
- /datum/explosions/controller/proc/do_explosion()
- var/started_at = explosion_step
- var/still_going = 1
- spawn while (still_going)
- still_going = 0
- var/list/list/datum/explosions/data/sorted = list()
- for (var/datum/explosions/explosion/EXP in being_processed)
- if (EXP.affected.len)
- still_going = 1
- for (var/datum/explosions/data/D in EXP.affected)
- sorted[round(get_dist(D.old_turf,EXP.ground_center))] += D
- if (still_going)
- explosion_step++
- for (var/datum/explosions/data/D in sorted[explosion_step - started_at])
- D.affected.ex_act(D.power)
- /datum/explosions/controller/proc/add(datum/explosions/explosion/exp)
- exp.taken_place_at = explosion_step
- to_process += exp
- spawn(0) do_explosion()
- //
- // 3,7,14,35 - ideal explosion
- // 14 is max. radius
- // Therefore 21% of radius is max destruction.
- // Therefore 50% of radius is heavy destruction
- // The rest is light destruction
- //
- #define MAX_DESTRUCTION .21
- #define HEV_DESTRUCTION .50
- #define LIG_DESTRUCTION 1.0
- datum/explosions/explosion
- var/turf/ground_center
- var/list/datum/explosions/data/affected = list()
- var/atom/movable/ray = new
- var/taken_place_at = 0
- var/initial_radius = 0
- var/maxi_radius = 0
- var/heav_radius = 0
- var/ligh_radius = 0
- New(turf/loc, power)
- if (loc)
- ground_center = loc
- initial_radius = power
- maxi_radius = initial_radius * MAX_DESTRUCTION
- heav_radius = initial_radius * HEV_DESTRUCTION
- ligh_radius = initial_radius * LIG_DESTRUCTION
- if (the_controller)
- the_controller.to_process += src
- //
- // By casting rays calculate which tiles are affected.
- // If one of tiles are affected by different waves - use the strongest one.
- //
- datum/explosions/data
- var/atom/affected
- var/turf/old_turf
- var/power = 0
- New (what, power, datum/explosions/explosion/callback)
- src.affected = what
- src.old_turf = get_turf(what)
- src.power = power
- datum/explosions/explosion/proc/calculate_all()
- var/list/turf/borders = range(initial_radius, ground_center) - range(initial_radius-1, ground_center)
- for (var/turf/target in borders)
- calculate_trace(ground_center, target, initial_radius)
- datum/explosions/explosion/proc/calculate_trace(atom/target, initial)
- ray.loc = ground_center
- var/remain_force = initial
- do
- if (target)
- step_to(ray,target)
- var/resistance = 0
- for (var/atom/A in get_turf(ray))
- if ( (isobj(A) || isturf(A) ) && A != ray) resistance += A:explosion_resistance
- remain_force -= resistance
- for (var/atom/A in get_turf(ray))
- affected += new (A, calc_exact(remain_force), src)
- while (remain_force > 0 || ray.loc != get_turf(target))
- return 0
- datum/explosions/explosion/proc/calculate_power(atom/target, initial)
- ray.loc = ground_center
- var/remain_force = initial
- do
- if (target)
- step_to(ray,target)
- var/resistance = 0
- for (var/atom/A in get_turf(ray))
- if ( (isobj(A) || isturf(A) ) && A != ray) resistance += A:explosion_resistance
- remain_force -= resistance
- while (remain_power > 0 || ray.loc != get_turf(target))
- return calc_exact (remain_power)
- datum/explosions/explosion/proc/calc_exact(force)
- if (force >= initial_radius - maxi_radius) return 1
- if (force >= initial_radius - heav_radius) return 2
- if (force >= initial_radius - ligh_radius) return 3
- return 0
- datum/explosions/explosion/proc/merge()
- for (var/datum/explosions/data/chosen in affected)
- for (var/datum/explosions/data/second in affected)
- if (chosen != second && chosen.old_turf == second.old_turf)
- if (second.power > chosen.power)
- second.power = chosen.power
- affected -= chosen
- del(chosen)
- else
- affected -= second
- del(second)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement