From 47ace5ed3e7ceefea76630f89de27acb776c1bd8 Mon Sep 17 00:00:00 2001 From: mwerezak Date: Fri, 16 Oct 2015 01:07:31 -0400 Subject: [PATCH] Chem smoke refactor --- code/__HELPERS/unsorted.dm | 2 +- code/game/objects/effects/chem/chemsmoke.dm | 94 +++++++++++++-------- 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 7122d32f852..0593e055a9c 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -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)) 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) return max(min(middle, high), low) diff --git a/code/game/objects/effects/chem/chemsmoke.dm b/code/game/objects/effects/chem/chemsmoke.dm index 293992b7354..034ce946864 100644 --- a/code/game/objects/effects/chem/chemsmoke.dm +++ b/code/game/objects/effects/chem/chemsmoke.dm @@ -4,26 +4,40 @@ /obj/effect/effect/smoke/chem icon = 'icons/effects/chemsmoke.dmi' opacity = 0 + layer = 6 time_to_live = 300 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/turf/destination -/obj/effect/effect/smoke/chem/New(var/newloc, turf/dest = null) - - //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)) +/obj/effect/effect/smoke/chem/New(var/newloc, smoke_duration, turf/dest_turf = null, icon/cached_icon = null) + time_to_live = smoke_duration ..() + 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) walk_to(src, destination) +/obj/effect/effect/smoke/chem/Destroy() + opacity = 0 + fadeOut() + ..() + /obj/effect/effect/smoke/chem/Move() var/list/oldlocs = view(1, src) . = ..() @@ -41,6 +55,25 @@ if(!istype(AM, /obj/effect/effect/smoke/chem)) 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 smoke_type = /obj/effect/effect/smoke/chem var/obj/chemholder @@ -144,13 +177,21 @@ else 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 for(var/i = 0, i < range, i++) //calculate positions for smoke coverage - then spawn smoke var/radius = i * 1.5 if(!radius) spawn(0) - spawnSmoke(location, I, 1) + spawnSmoke(location, I, 1, 1) continue var/offset = 0 @@ -175,43 +216,26 @@ // Randomizes and spawns the smoke effect. // 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 if(passed_smoke) smoke = passed_smoke 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) 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 - smoke.layer = 6 - smoke.set_dir(pick(cardinal)) - 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) + //Kinda ugly, but needed unless the system is reworked + if(splash_initial) + smoke.initial_splash() -/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) spores.name = "cloud of [seed.seed_name] [seed.seed_noun]" - ..(T, I, 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 + ..(T, I, smoke_duration, dist, spores) /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.