mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-26 18:13:35 +00:00
Chem smoke refactor
This commit is contained in:
@@ -538,7 +538,7 @@ Turf and target are seperate in case you want to teleport some distance from a t
|
|||||||
var/y = min(world.maxy, max(1, A.y + dy))
|
var/y = min(world.maxy, max(1, A.y + dy))
|
||||||
return locate(x,y,A.z)
|
return locate(x,y,A.z)
|
||||||
|
|
||||||
//Makes sure MIDDLE is between LOW and HIGH. If not, it adjusts it. Returns the adjusted value.
|
//Makes sure MIDDLE is between LOW and HIGH. If not, it adjusts it. Returns the adjusted value. Lower bound takes priority.
|
||||||
/proc/between(var/low, var/middle, var/high)
|
/proc/between(var/low, var/middle, var/high)
|
||||||
return max(min(middle, high), low)
|
return max(min(middle, high), low)
|
||||||
|
|
||||||
|
|||||||
@@ -4,26 +4,40 @@
|
|||||||
/obj/effect/effect/smoke/chem
|
/obj/effect/effect/smoke/chem
|
||||||
icon = 'icons/effects/chemsmoke.dmi'
|
icon = 'icons/effects/chemsmoke.dmi'
|
||||||
opacity = 0
|
opacity = 0
|
||||||
|
layer = 6
|
||||||
time_to_live = 300
|
time_to_live = 300
|
||||||
pass_flags = PASSTABLE | PASSGRILLE | PASSGLASS //PASSGLASS is fine here, it's just so the visual effect can "flow" around glass
|
pass_flags = PASSTABLE | PASSGRILLE | PASSGLASS //PASSGLASS is fine here, it's just so the visual effect can "flow" around glass
|
||||||
var/splash_amount = 10 //atoms moving through a smoke cloud get splashed with up to 10 units of reagent
|
var/splash_amount = 10 //atoms moving through a smoke cloud get splashed with up to 10 units of reagent
|
||||||
var/turf/destination
|
var/turf/destination
|
||||||
|
|
||||||
/obj/effect/effect/smoke/chem/New(var/newloc, turf/dest = null)
|
/obj/effect/effect/smoke/chem/New(var/newloc, smoke_duration, turf/dest_turf = null, icon/cached_icon = null)
|
||||||
|
time_to_live = smoke_duration
|
||||||
//Calculate time to live
|
|
||||||
var/pressure = 0
|
|
||||||
var/datum/gas_mixture/environment = loc.return_air()
|
|
||||||
if(environment) pressure = environment.return_pressure()
|
|
||||||
|
|
||||||
time_to_live = max(5, time_to_live*min(pressure/(ONE_ATMOSPHERE/3), 1))
|
|
||||||
|
|
||||||
..()
|
..()
|
||||||
|
|
||||||
create_reagents(500)
|
create_reagents(500)
|
||||||
destination = dest
|
|
||||||
|
if(cached_icon)
|
||||||
|
icon = cached_icon
|
||||||
|
|
||||||
|
set_dir(pick(cardinal))
|
||||||
|
pixel_x = -32 + rand(-8, 8)
|
||||||
|
pixel_y = -32 + rand(-8, 8)
|
||||||
|
|
||||||
|
//switching opacity on after the smoke has spawned, and then turning it off before it is deleted results in cleaner
|
||||||
|
//lighting and view range updates (Is this still true with the new lighting system?)
|
||||||
|
opacity = 1
|
||||||
|
|
||||||
|
//float over to our destination, if we have one
|
||||||
|
destination = dest_turf
|
||||||
if(destination)
|
if(destination)
|
||||||
walk_to(src, destination)
|
walk_to(src, destination)
|
||||||
|
|
||||||
|
/obj/effect/effect/smoke/chem/Destroy()
|
||||||
|
opacity = 0
|
||||||
|
fadeOut()
|
||||||
|
..()
|
||||||
|
|
||||||
/obj/effect/effect/smoke/chem/Move()
|
/obj/effect/effect/smoke/chem/Move()
|
||||||
var/list/oldlocs = view(1, src)
|
var/list/oldlocs = view(1, src)
|
||||||
. = ..()
|
. = ..()
|
||||||
@@ -41,6 +55,25 @@
|
|||||||
if(!istype(AM, /obj/effect/effect/smoke/chem))
|
if(!istype(AM, /obj/effect/effect/smoke/chem))
|
||||||
reagents.splash(AM, splash_amount, copy = 1)
|
reagents.splash(AM, splash_amount, copy = 1)
|
||||||
|
|
||||||
|
/obj/effect/effect/smoke/chem/proc/initial_splash()
|
||||||
|
for(var/turf/T in view(1, src))
|
||||||
|
for(var/atom/movable/AM in T)
|
||||||
|
if(!istype(AM, /obj/effect/effect/smoke/chem))
|
||||||
|
reagents.splash(AM, splash_amount, copy = 1)
|
||||||
|
|
||||||
|
// Fades out the smoke smoothly using it's alpha variable.
|
||||||
|
/obj/effect/effect/smoke/chem/proc/fadeOut(var/frames = 16)
|
||||||
|
if(!alpha) return //already transparent
|
||||||
|
|
||||||
|
frames = max(frames, 1) //We will just assume that by 0 frames, the coder meant "during one frame".
|
||||||
|
var/alpha_step = round(alpha / frames)
|
||||||
|
while(alpha > 0)
|
||||||
|
alpha = max(0, alpha - alpha_step)
|
||||||
|
sleep(world.tick_lag)
|
||||||
|
|
||||||
|
/////////////////////////////////////////////
|
||||||
|
// Chem Smoke Effect System
|
||||||
|
/////////////////////////////////////////////
|
||||||
/datum/effect/effect/system/smoke_spread/chem
|
/datum/effect/effect/system/smoke_spread/chem
|
||||||
smoke_type = /obj/effect/effect/smoke/chem
|
smoke_type = /obj/effect/effect/smoke/chem
|
||||||
var/obj/chemholder
|
var/obj/chemholder
|
||||||
@@ -144,13 +177,21 @@
|
|||||||
else
|
else
|
||||||
I = icon('icons/effects/96x96.dmi', "smoke")
|
I = icon('icons/effects/96x96.dmi', "smoke")
|
||||||
|
|
||||||
|
//Calculate smoke duration
|
||||||
|
var/smoke_duration = 150
|
||||||
|
|
||||||
|
var/pressure = 0
|
||||||
|
var/datum/gas_mixture/environment = location.return_air()
|
||||||
|
if(environment) pressure = environment.return_pressure()
|
||||||
|
smoke_duration = between(5, smoke_duration*pressure/(ONE_ATMOSPHERE/3), smoke_duration)
|
||||||
|
|
||||||
var/const/arcLength = 2.3559 //distance between each smoke cloud
|
var/const/arcLength = 2.3559 //distance between each smoke cloud
|
||||||
|
|
||||||
for(var/i = 0, i < range, i++) //calculate positions for smoke coverage - then spawn smoke
|
for(var/i = 0, i < range, i++) //calculate positions for smoke coverage - then spawn smoke
|
||||||
var/radius = i * 1.5
|
var/radius = i * 1.5
|
||||||
if(!radius)
|
if(!radius)
|
||||||
spawn(0)
|
spawn(0)
|
||||||
spawnSmoke(location, I, 1)
|
spawnSmoke(location, I, 1, 1)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
var/offset = 0
|
var/offset = 0
|
||||||
@@ -175,43 +216,26 @@
|
|||||||
// Randomizes and spawns the smoke effect.
|
// Randomizes and spawns the smoke effect.
|
||||||
// Also handles deleting the smoke once the effect is finished.
|
// Also handles deleting the smoke once the effect is finished.
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
/datum/effect/effect/system/smoke_spread/chem/proc/spawnSmoke(var/turf/T, var/icon/I, var/dist = 1, var/obj/effect/effect/smoke/chem/passed_smoke)
|
/datum/effect/effect/system/smoke_spread/chem/proc/spawnSmoke(var/turf/T, var/icon/I, var/smoke_duration, var/dist = 1, var/splash_initial=0, var/obj/effect/effect/smoke/chem/passed_smoke)
|
||||||
|
|
||||||
var/obj/effect/effect/smoke/chem/smoke
|
var/obj/effect/effect/smoke/chem/smoke
|
||||||
if(passed_smoke)
|
if(passed_smoke)
|
||||||
smoke = passed_smoke
|
smoke = passed_smoke
|
||||||
else
|
else
|
||||||
smoke = PoolOrNew(/obj/effect/effect/smoke/chem, list(location, T))
|
smoke = PoolOrNew(/obj/effect/effect/smoke/chem, list(location, smoke_duration + rand(0, 20), T, I))
|
||||||
|
|
||||||
if(chemholder.reagents.reagent_list.len)
|
if(chemholder.reagents.reagent_list.len)
|
||||||
chemholder.reagents.trans_to_obj(smoke, chemholder.reagents.total_volume / dist, copy = 1) //copy reagents to the smoke so mob/breathe() can handle inhaling the reagents
|
chemholder.reagents.trans_to_obj(smoke, chemholder.reagents.total_volume / dist, copy = 1) //copy reagents to the smoke so mob/breathe() can handle inhaling the reagents
|
||||||
|
|
||||||
smoke.icon = I
|
//Kinda ugly, but needed unless the system is reworked
|
||||||
smoke.layer = 6
|
if(splash_initial)
|
||||||
smoke.set_dir(pick(cardinal))
|
smoke.initial_splash()
|
||||||
smoke.pixel_x = -32 + rand(-8, 8)
|
|
||||||
smoke.pixel_y = -32 + rand(-8, 8)
|
|
||||||
smoke.opacity = 1 //switching opacity on after the smoke has spawned, and then
|
|
||||||
sleep(150+rand(0,20)) // turning it off before it is deleted results in cleaner
|
|
||||||
smoke.opacity = 0 // lighting and view range updates
|
|
||||||
fadeOut(smoke)
|
|
||||||
qdel(src)
|
|
||||||
|
|
||||||
/datum/effect/effect/system/smoke_spread/chem/spores/spawnSmoke(var/turf/T, var/icon/I, var/dist = 1)
|
|
||||||
|
/datum/effect/effect/system/smoke_spread/chem/spores/spawnSmoke(var/turf/T, var/smoke_duration, var/icon/I, var/dist = 1)
|
||||||
var/obj/effect/effect/smoke/chem/spores = PoolOrNew(/obj/effect/effect/smoke/chem, location)
|
var/obj/effect/effect/smoke/chem/spores = PoolOrNew(/obj/effect/effect/smoke/chem, location)
|
||||||
spores.name = "cloud of [seed.seed_name] [seed.seed_noun]"
|
spores.name = "cloud of [seed.seed_name] [seed.seed_noun]"
|
||||||
..(T, I, dist, spores)
|
..(T, I, smoke_duration, dist, spores)
|
||||||
|
|
||||||
/datum/effect/effect/system/smoke_spread/chem/proc/fadeOut(var/atom/A, var/frames = 16) // Fades out the smoke smoothly using it's alpha variable.
|
|
||||||
if(A.alpha == 0) //Handle already transparent case
|
|
||||||
return
|
|
||||||
if(frames == 0)
|
|
||||||
frames = 1 //We will just assume that by 0 frames, the coder meant "during one frame".
|
|
||||||
var/step = A.alpha / frames
|
|
||||||
for(var/i = 0, i < frames, i++)
|
|
||||||
A.alpha -= step
|
|
||||||
sleep(world.tick_lag)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
/datum/effect/effect/system/smoke_spread/chem/proc/smokeFlow() // Smoke pathfinder. Uses a flood fill method based on zones to quickly check what turfs the smoke (airflow) can actually reach.
|
/datum/effect/effect/system/smoke_spread/chem/proc/smokeFlow() // Smoke pathfinder. Uses a flood fill method based on zones to quickly check what turfs the smoke (airflow) can actually reach.
|
||||||
|
|||||||
Reference in New Issue
Block a user