More explosion optimisations

This commit is contained in:
ZomgPonies
2014-01-05 00:55:24 -05:00
parent 74e6b51b88
commit fdc1f7c455
+21 -42
View File
@@ -1,4 +1,7 @@
/client/proc/kaboom()
set category = "Debug"
var/power = input(src, "power?", "power?") as num
var/turf/T = get_turf(src.mob)
explosion_rec(T, power)
@@ -6,31 +9,12 @@
/obj
var/explosion_resistance
/datum/explosion_turf
var/turf/turf //The turf which will get ex_act called on it
var/max_power //The largest amount of power the turf sustained
New()
..()
max_power = 0
proc/save_power_if_larger(power)
if(power > max_power)
max_power = power
return 1
return 0
var/list/explosion_turfs = list()
var/list/datum/explosion_turf/explosion_turfs = list()
var/explosion_in_progress = 0
proc/get_explosion_turf(var/turf/T)
for( var/datum/explosion_turf/ET in explosion_turfs )
if( T == ET.turf )
return ET
var/datum/explosion_turf/ET = new()
ET.turf = T
explosion_turfs += ET
return ET
proc/explosion_rec(turf/epicenter, power)
@@ -52,9 +36,8 @@ proc/explosion_rec(turf/epicenter, power)
explosion_in_progress = 1
explosion_turfs = list()
var/datum/explosion_turf/ETE = get_explosion_turf()
ETE.turf = epicenter
ETE.max_power = power
explosion_turfs[epicenter] = power
//This steap handles the gathering of turfs which will be ex_act() -ed in the next step. It also ensures each turf gets the maximum possible amount of power dealt to it.
for(var/direction in cardinal)
@@ -62,22 +45,21 @@ proc/explosion_rec(turf/epicenter, power)
T.explosion_spread(power - epicenter.explosion_resistance, direction)
//This step applies the ex_act effects for the explosion, as planned in the previous step.
for( var/datum/explosion_turf/ET in explosion_turfs )
if(ET.max_power <= 0) continue
if(!ET.turf) continue
for(var/turf/T in explosion_turfs)
if(explosion_turfs[T] <= 0) continue
if(!T) continue
//Wow severity looks confusing to calculate... Fret not, I didn't leave you with any additional instructions or help. (just kidding, see the line under the calculation)
var/severity = 4 - round(max(min( 3, ((ET.max_power - ET.turf.explosion_resistance) / (max(3,(power/3)))) ) ,1), 1)
//sanity effective power on tile divided by either 3 or one third the total explosion power
var/severity = 4 - round(max(min( 3, ((explosion_turfs[T] - T.explosion_resistance) / (max(3,(power/3)))) ) ,1), 1) //sanity effective power on tile divided by either 3 or one third the total explosion power
// One third because there are three power levels and I
// want each one to take up a third of the crater
var/x = ET.turf.x
var/y = ET.turf.y
var/z = ET.turf.z
ET.turf.ex_act(severity)
if(!ET.turf)
ET.turf = locate(x,y,z)
for( var/atom/A in ET.turf )
var/x = T.x
var/y = T.y
var/z = T.z
T.ex_act(severity)
if(!T)
T = locate(x,y,z)
for(var/atom/A in T)
A.ex_act(severity)
explosion_in_progress = 0
@@ -97,7 +79,7 @@ proc/explosion_rec(turf/epicenter, power)
/turf/simulated/mineral
explosion_resistance = 2
/turf/unsimulated/mineral
turf/unsimulated/mineral
explosion_resistance = 2
/turf/simulated/shuttle/floor
@@ -116,7 +98,7 @@ proc/explosion_rec(turf/epicenter, power)
explosion_resistance = 5
/turf/simulated/wall/r_wall
explosion_resistance = 25
explosion_resistance = 15
//Code-wise, a safe value for power is something up to ~25 or ~30.. This does quite a bit of damage to the station.
//direction is the direction that the spread took to come to this tile. So it is pointing in the main blast direction - meaning where this tile should spread most of it's force.
@@ -129,10 +111,9 @@ proc/explosion_rec(turf/epicenter, power)
new/obj/effect/debugging/marker(src)
*/
var/datum/explosion_turf/ET = get_explosion_turf(src)
if(ET.max_power >= power)
if(explosion_turfs[src] >= power)
return //The turf already sustained and spread a power greated than what we are dealing with. No point spreading again.
ET.max_power = power
explosion_turfs[src] = power
var/spread_power = power - src.explosion_resistance //This is the amount of power that will be spread to the tile in the direction of the blast
var/side_spread_power = power - 2 * src.explosion_resistance //This is the amount of power that will be spread to the side tiles
@@ -154,7 +135,5 @@ proc/explosion_rec(turf/epicenter, power)
T.explosion_spread(spread_power)
*/
/*
/turf/unsimulated/explosion_spread(power)
return //So it doesn't get to the parent proc, which simulates explosions
*/