From 5c4f4ec5e5ee087fb46fd46efcf41a04bf97d5b3 Mon Sep 17 00:00:00 2001 From: uraniummeltdown Date: Sat, 4 Nov 2017 18:21:51 +0400 Subject: [PATCH] effect/system to effect_system effect/effect to effect/particle_effect make foam an effect again move explosion_particles.dm to effect_system folder OOP effect code, addtimers, QDEL_IN fixed reagent explosions never having a flash range due to a typo --- .../effects/effect_system/effect_system.dm | 53 +++++-- .../effect_system/effects_explosion.dm | 61 ++++++++ .../effects/effect_system/effects_foam.dm | 31 ++-- .../effects/effect_system/effects_other.dm | 136 +++++++++++------- .../effects/effect_system/effects_smoke.dm | 85 ++++++----- .../effects/effect_system/effects_sparks.dm | 133 +++-------------- .../effects/effect_system/effects_water.dm | 94 ++---------- .../objects/effects/explosion_particles.dm | 68 --------- paradise.dme | 2 +- 9 files changed, 273 insertions(+), 390 deletions(-) create mode 100644 code/game/objects/effects/effect_system/effects_explosion.dm delete mode 100644 code/game/objects/effects/explosion_particles.dm diff --git a/code/game/objects/effects/effect_system/effect_system.dm b/code/game/objects/effects/effect_system/effect_system.dm index a558c7933f2..1669d9b09d2 100644 --- a/code/game/objects/effects/effect_system/effect_system.dm +++ b/code/game/objects/effects/effect_system/effect_system.dm @@ -5,43 +5,68 @@ it needs to create more trails.A beaker could have a steam_trail_follow system s would spawn and follow the beaker, even if it is carried or thrown. */ -/obj/effect/effect - name = "effect" - icon = 'icons/effects/effects.dmi' +/obj/effect/particle_effect + name = "particle effect" mouse_opacity = 0 - unacidable = 1//So effect are not targeted by alien acid. + unacidable = 1//So effects are not targeted by alien acid. -/obj/effect/effect/New() +/obj/effect/particle_effect/New() ..() if(ticker) cameranet.updateVisibility(src) -/obj/effect/effect/Destroy() +/obj/effect/particle_effect/Destroy() if(ticker) cameranet.updateVisibility(src) return ..() -/datum/effect/system +/datum/effect_system var/number = 3 var/cardinals = 0 var/turf/location var/atom/holder - var/setup = 0 + var/effect_type + var/total_effects = 0 -/datum/effect/system/Destroy() +/datum/effect_system/Destroy() holder = null location = null return ..() -/datum/effect/system/proc/set_up(n = 3, c = 0, turf/loc) +/datum/effect_system/proc/set_up(n = 3, c = 0, loca) if(n > 10) n = 10 number = n cardinals = c - location = loc - setup = 1 + if(isturf(loca)) + location = loca + else + location = get_turf(loca) -/datum/effect/system/proc/attach(atom/atom) +/datum/effect_system/proc/attach(atom/atom) holder = atom -/datum/effect/system/proc/start() +/datum/effect_system/proc/start() + for(var/i in 1 to number) + if(total_effects > 20) + return + addtimer(src, "generate_effect", 0) + +/datum/effect_system/proc/generate_effect() + if(holder) + location = get_turf(holder) + var/obj/effect/E = new effect_type(location) + total_effects++ + var/direction + if(cardinals) + direction = pick(cardinal) + else + direction = pick(alldirs) + var/steps_amt = pick(1,2,3) + for(var/j in 1 to steps_amt) + sleep(5) + step(E,direction) + addtimer(src, "decrement_total_effect", 20) + +/datum/effect_system/proc/decrement_total_effect() + total_effects-- diff --git a/code/game/objects/effects/effect_system/effects_explosion.dm b/code/game/objects/effects/effect_system/effects_explosion.dm new file mode 100644 index 00000000000..63b3d4d5271 --- /dev/null +++ b/code/game/objects/effects/effect_system/effects_explosion.dm @@ -0,0 +1,61 @@ +/obj/effect/particle_effect/expl_particles + name = "explosive particles" + icon_state = "explosion_particle" + opacity = 1 + anchored = 1 + +/obj/effect/particle_effect/expl_particles/New() + ..() + QDEL_IN(src, 15) + +/datum/effect_system/expl_particles + number = 10 + +/datum/effect_system/expl_particles/start() + for(var/i in 1 to number) + spawn(0) + var/obj/effect/particle_effect/expl_particles/expl = new /obj/effect/particle_effect/expl_particles(location) + var/direct = pick(alldirs) + var/steps_amt = pick(1;25,2;50,3,4;200) + for(var/j in 1 to steps_amt) + sleep(1) + step(expl,direct) + +/obj/effect/explosion + name = "explosive particles" + icon = 'icons/effects/96x96.dmi' + icon_state = "explosion" + opacity = 1 + anchored = 1 + mouse_opacity = 0 + pixel_x = -32 + pixel_y = -32 + +/obj/effect/explosion/New() + ..() + QDEL_IN(src, 10) + +/datum/effect_system/explosion + +/datum/effect_system/explosion/set_up(loca) + if(isturf(loca)) + location = loca + else + location = get_turf(loca) + +/datum/effect_system/explosion/start() + new/obj/effect/explosion(location) + var/datum/effect_system/expl_particles/P = new/datum/effect_system/expl_particles() + P.set_up(10,location) + P.start() + +/datum/effect_system/explosion/smoke + +/datum/effect_system/explosion/smoke/proc/create_smoke() + var/datum/effect_system/smoke_spread/S = new + S.set_up(5,0,location,null) + S.start() + +/datum/effect_system/explosion/smoke/start() + ..() + addtimer(src, "create_smoke", 5) diff --git a/code/game/objects/effects/effect_system/effects_foam.dm b/code/game/objects/effects/effect_system/effects_foam.dm index 06546ab9e86..814f264b23e 100644 --- a/code/game/objects/effects/effect_system/effects_foam.dm +++ b/code/game/objects/effects/effect_system/effects_foam.dm @@ -2,21 +2,19 @@ // Similar to smoke, but spreads out more // metal foams leave behind a foamed metal wall -/obj/structure/foam +/obj/effect/particle_effect/foam name = "foam" - icon = 'icons/effects/effects.dmi' icon_state = "foam" opacity = 0 anchored = 1 density = 0 layer = OBJ_LAYER + 0.9 - mouse_opacity = 0 animate_movement = 0 var/amount = 3 var/expand = 1 var/metal = 0 -/obj/structure/foam/New(loc, ismetal=0) +/obj/effect/particle_effect/foam/New(loc, ismetal=0) ..(loc) icon_state = "[ismetal ? "m":""]foam" if(!ismetal && reagents) @@ -47,7 +45,7 @@ return // on delete, transfer any reagents to the floor -/obj/structure/foam/Destroy() +/obj/effect/particle_effect/foam/Destroy() if(!metal && reagents) reagents.handle_reactions() for(var/atom/A in oview(1, src)) @@ -58,7 +56,7 @@ reagents.reaction(A, TOUCH, fraction) return ..() -/obj/structure/foam/process() +/obj/effect/particle_effect/foam/process() if(--amount < 0) return @@ -71,11 +69,11 @@ if(!T.Enter(src)) continue - var/obj/structure/foam/F = locate() in T + var/obj/effect/particle_effect/foam/F = locate() in T if(F) continue - F = new /obj/structure/foam(T, metal) + F = new /obj/effect/particle_effect/foam(T, metal) F.amount = amount if(!metal) F.create_reagents(15) @@ -86,14 +84,14 @@ // foam disolves when heated // except metal foams -/obj/structure/foam/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume) +/obj/effect/particle_effect/foam/temperature_expose(datum/gas_mixture/air, exposed_temperature, exposed_volume) if(!metal && prob(max(0, exposed_temperature - 475))) flick("[icon_state]-disolve", src) spawn(5) qdel(src) -/obj/structure/foam/Crossed(atom/movable/AM) +/obj/effect/particle_effect/foam/Crossed(atom/movable/AM) if(metal) return @@ -109,16 +107,17 @@ var/fraction = 5 / reagents.total_volume reagents.reaction(M, TOUCH, fraction) -/datum/effect/system/foam_spread +/datum/effect_system/foam_spread + effect_type = /obj/effect/particle_effect/foam var/amount = 5 // the size of the foam spread. var/list/carried_reagents // the IDs of reagents present when the foam was mixed var/metal = 0 // 0=foam, 1=metalfoam, 2=ironfoam var/temperature = T0C var/list/banned_reagents = list("smoke_powder", "fluorosurfactant", "stimulants") -/datum/effect/system/foam_spread/set_up(amt=5, loca, datum/reagents/carry = null, metalfoam = 0) +/datum/effect_system/foam_spread/set_up(amt=5, loca, datum/reagents/carry = null, metalfoam = 0) amount = min(round(amt/5, 1), 7) - if(istype(loca, /turf/)) + if(isturf(loca)) location = loca else location = get_turf(loca) @@ -135,15 +134,15 @@ for(var/datum/reagent/R in carry.reagent_list) carried_reagents[R.id] = R.volume -/datum/effect/system/foam_spread/start() +/datum/effect_system/foam_spread/start() spawn(0) - var/obj/structure/foam/F = locate() in location + var/obj/effect/particle_effect/foam/F = locate() in location if(F) F.amount += amount F.amount = min(F.amount, 27) return - F = new /obj/structure/foam(location, metal) + F = new /obj/effect/particle_effect/foam(location, metal) F.amount = amount if(!metal) // don't carry other chemicals if a metal foam diff --git a/code/game/objects/effects/effect_system/effects_other.dm b/code/game/objects/effects/effect_system/effects_other.dm index 8785c3c610b..ef9ed8ac11a 100644 --- a/code/game/objects/effects/effect_system/effects_other.dm +++ b/code/game/objects/effects/effect_system/effects_other.dm @@ -1,69 +1,96 @@ ///////////////////////////////////////////// -//////// Attach an Ion trail to any object, that spawns when it moves (like for the jetpack) +//////// Attach a trail to any object, that spawns when it moves (like for the jetpack) /// just pass in the object to attach it to in set_up /// Then do start() to start it and stop() to stop it, obviously /// and don't call start() in a loop that will be repeated otherwise it'll get spammed! ///////////////////////////////////////////// -/obj/effect/effect/ion_trails - name = "ion trails" - icon_state = "ion_trails" - anchored = 1.0 - -/datum/effect/system/ion_trail_follow +/datum/effect_system/trail_follow var/turf/oldposition var/processing = 1 var/on = 1 -/datum/effect/system/ion_trail_follow/Destroy() +/datum/effect_system/trail_follow/set_up(atom/atom) + attach(atom) + oldposition = get_turf(atom) + +/datum/effect_system/trail_follow/Destroy() oldposition = null return ..() -/datum/effect/system/ion_trail_follow/set_up(atom/atom) - attach(atom) +/datum/effect_system/trail_follow/proc/stop() + processing = 0 + on = 0 + oldposition = null -/datum/effect/system/ion_trail_follow/start() //Whoever is responsible for this abomination of code should become an hero - if(!src.on) - src.on = 1 - src.processing = 1 - if(src.processing) - src.processing = 0 +/datum/effect_system/trail_follow/steam + effect_type = /obj/effect/particle_effect/steam + +/datum/effect_system/trail_follow/steam/start() //Whoever is responsible for this abomination of code should become an hero + if(!on) + on = 1 + processing = 1 + if(!oldposition) + oldposition = get_turf(holder) + if(processing) + processing = 0 + if(number < 3) + var/obj/effect/particle_effect/steam/I = new effect_type(oldposition) + number++ + I.dir = holder.dir + oldposition = get_turf(holder) + spawn(10) + qdel(I) + number-- + spawn(2) + if(on) + processing = 1 + start() + +/obj/effect/particle_effect/ion_trails + name = "ion trails" + icon_state = "ion_trails" + anchored = 1 + +/datum/effect_system/trail_follow/ion + effect_type = /obj/effect/particle_effect/ion_trails + +/datum/effect_system/trail_follow/ion/start() //Whoever is responsible for this abomination of code should become an hero + if(!on) + on = 1 + processing = 1 + if(processing) + processing = 0 var/turf/T = get_turf(src.holder) - if(T != src.oldposition) + if(T != oldposition) if(!has_gravity(T)) - var/obj/effect/effect/ion_trails/I = new /obj/effect/effect/ion_trails(src.oldposition) - I.dir = src.holder.dir + var/obj/effect/particle_effect/ion_trails/I = new effect_type(oldposition) + I.dir = holder.dir flick("ion_fade", I) I.icon_state = "" spawn(20) - if(I) - qdel(I) - src.oldposition = T + qdel(I) + oldposition = T spawn(2) - if(src.on) - src.processing = 1 - src.start() + if(on) + processing = 1 + start() -/datum/effect/system/ion_trail_follow/proc/stop() - src.processing = 0 - src.on = 0 - oldposition = null - -/datum/effect/system/ion_trail_follow/space_trail +/datum/effect_system/trail_follow/ion/space_trail var/turf/oldloc // secondary ion trail loc var/turf/currloc -/datum/effect/system/ion_trail_follow/space_trail/Destroy() +/datum/effect_system/trail_follow/ion/space_trail/Destroy() oldloc = null currloc = null return ..() -/datum/effect/system/ion_trail_follow/space_trail/start() - if(!src.on) - src.on = 1 - src.processing = 1 - if(src.processing) - src.processing = 0 +/datum/effect_system/trail_follow/ion/space_trail/start() + if(!on) + on = 1 + processing = 1 + if(processing) + processing = 0 spawn(0) var/turf/T = get_turf(src.holder) if(currloc != T) @@ -89,11 +116,11 @@ src.oldloc = get_step(oldposition,NORTH) //src.oldloc = get_step(oldloc,EAST) if(istype(T, /turf/space)) - var/obj/effect/effect/ion_trails/I = new /obj/effect/effect/ion_trails(src.oldposition) - var/obj/effect/effect/ion_trails/II = new /obj/effect/effect/ion_trails(src.oldloc) + var/obj/effect/particle_effect/ion_trails/I = new effect_type(oldposition) + var/obj/effect/particle_effect/ion_trails/II = new effect_type(oldloc) //src.oldposition = T - I.dir = src.holder.dir - II.dir = src.holder.dir + I.dir = holder.dir + II.dir = holder.dir flick("ion_fade", I) flick("ion_fade", II) I.icon_state = "" @@ -104,32 +131,31 @@ if(II) qdel(II) spawn(2) - if(src.on) - src.processing = 1 - src.start() + if(on) + processing = 1 + start() currloc = T //Reagent-based explosion effect -/datum/effect/system/reagents_explosion +/datum/effect_system/reagents_explosion var/amount // TNT equivalent var/flashing = 0 // does explosion creates flash effect? var/flashing_factor = 0 // factor of how powerful the flash effect relatively to the explosion -/datum/effect/system/reagents_explosion/set_up(amt, loc, flash = 0, flash_fact = 0) +/datum/effect_system/reagents_explosion/set_up(amt, loca, flash = 0, flash_fact = 0) amount = amt - if(istype(loc, /turf/)) - location = loc + if(isturf(loca)) + location = loca else - location = get_turf(loc) + location = get_turf(loca) flashing = flash flashing_factor = flash_fact - return -/datum/effect/system/reagents_explosion/start() +/datum/effect_system/reagents_explosion/start() if(amount <= 2) - var/datum/effect/system/spark_spread/s = new /datum/effect/system/spark_spread + var/datum/effect_system/spark_spread/s = new /datum/effect_system/spark_spread s.set_up(2, 1, location) s.start() @@ -156,7 +182,7 @@ if(round(amount/3) > 0) light = min (MAX_EX_LIGHT_RANGE, light + round(amount/3)) - if(flash && flashing_factor) + if(flashing && flashing_factor) flash += (round(amount/4) * flashing_factor) for(var/mob/M in viewers(8, location)) @@ -164,7 +190,7 @@ explosion(location, devastation, heavy, light, flash) -/datum/effect/system/reagents_explosion/proc/holder_damage(atom/holder) +/datum/effect_system/reagents_explosion/proc/holder_damage(atom/holder) if(holder) var/dmglevel = 4 diff --git a/code/game/objects/effects/effect_system/effects_smoke.dm b/code/game/objects/effects/effect_system/effects_smoke.dm index cc0259c6c6f..64421b35fe9 100644 --- a/code/game/objects/effects/effect_system/effects_smoke.dm +++ b/code/game/objects/effects/effect_system/effects_smoke.dm @@ -4,7 +4,7 @@ // in case you wanted a vent to always smoke north for example ///////////////////////////////////////////// -/obj/effect/effect/smoke +/obj/effect/particle_effect/smoke name = "smoke" icon_state = "smoke" icon = 'icons/effects/96x96.dmi' @@ -12,12 +12,11 @@ pixel_y = -32 opacity = 1 anchored = 0 - mouse_opacity = 0 var/steps = 0 var/lifetime = 5 var/direction -/obj/effect/effect/smoke/proc/fade_out(frames = 16) +/obj/effect/particle_effect/smoke/proc/fade_out(frames = 16) if(alpha == 0) //Handle already transparent case return if(frames == 0) @@ -29,21 +28,21 @@ set_opacity(0) stoplag() -/obj/effect/effect/smoke/New() +/obj/effect/particle_effect/smoke/New() ..() processing_objects |= src lifetime += rand(-1,1) -/obj/effect/effect/smoke/Destroy() +/obj/effect/particle_effect/smoke/Destroy() processing_objects.Remove(src) return ..() -/obj/effect/effect/smoke/proc/kill_smoke() +/obj/effect/particle_effect/smoke/proc/kill_smoke() processing_objects.Remove(src) addtimer(src, "fade_out", 0) QDEL_IN(src, 10) -/obj/effect/effect/smoke/process() +/obj/effect/particle_effect/smoke/process() lifetime-- if(lifetime < 1) kill_smoke() @@ -53,12 +52,12 @@ steps-- return 1 -/obj/effect/effect/smoke/Crossed(mob/living/M) +/obj/effect/particle_effect/smoke/Crossed(mob/living/M) if(!istype(M)) return smoke_mob(M) -/obj/effect/effect/smoke/proc/smoke_mob(mob/living/carbon/C) +/obj/effect/particle_effect/smoke/proc/smoke_mob(mob/living/carbon/C) if(!istype(C)) return FALSE if(lifetime<1) @@ -71,31 +70,31 @@ addtimer(src, "remove_smoke_delay", 10, FALSE, C) return TRUE -/obj/effect/effect/smoke/proc/remove_smoke_delay(mob/living/carbon/C) +/obj/effect/particle_effect/smoke/proc/remove_smoke_delay(mob/living/carbon/C) if(C) C.smoke_delay = 0 -/datum/effect/system/smoke_spread +/datum/effect_system/smoke_spread + effect_type = /obj/effect/particle_effect/smoke var/direction - var/smoke_type = /obj/effect/effect/smoke -/datum/effect/system/smoke_spread/set_up(n = 5, c = 0, loca, direct) +/datum/effect_system/smoke_spread/set_up(n = 5, c = 0, loca, direct) if(n > 20) n = 20 number = n cardinals = c - if(istype(loca, /turf/)) + if(isturf(loca)) location = loca else location = get_turf(loca) if(direct) direction = direct -/datum/effect/system/smoke_spread/start() +/datum/effect_system/smoke_spread/start() for(var/i=0, i 20) n = 20 number = n cardinals = c - if(istype(loca, /turf/)) + if(isturf(loca)) location = loca else location = get_turf(loca) @@ -273,9 +272,9 @@ msg_admin_attack("A chemical smoke reaction has taken place in ([whereLink]). No associated key. CODERS: carry.my_atom may be null.", 0, 1) log_game("A chemical smoke reaction has taken place in ([where])[contained]. No associated key. CODERS: carry.my_atom may be null.") -/datum/effect/system/smoke_spread/chem/start(effect_range = 2) +/datum/effect_system/smoke_spread/chem/start(effect_range = 2) var/color = mix_color_from_reagents(chemholder.reagents.reagent_list) - var/obj/effect/effect/smoke/chem/smokeholder = new smoke_type(location) + var/obj/effect/particle_effect/smoke/chem/smokeholder = new effect_type(location) for(var/atom/A in view(effect_range, smokeholder)) chemholder.reagents.reaction(A) if(iscarbon(A)) @@ -286,7 +285,7 @@ for(var/i=0, i 10) - n = 10 - number = n - cardinals = c - if(istype(loca, /turf/)) - location = loca - else - location = get_turf(loca) - -/datum/effect/system/spark_spread/start() - var/i = 0 - for(i=0, i 20) - return - spawn(0) - if(holder) - src.location = get_turf(holder) - var/obj/effect/effect/sparks/sparks = new /obj/effect/effect/sparks(src.location) - src.total_sparks++ - var/direction - if(src.cardinals) - direction = pick(cardinal) - else - direction = pick(alldirs) - for(i=0, i 10) - n = 10 - number = n - cardinals = c - if(istype(loca, /turf/)) - location = loca - else - location = get_turf(loca) - -/datum/effect/system/sparkle_spread/start() - var/i = 0 - for(i=0, i 20) - return - spawn(0) - if(holder) - src.location = get_turf(holder) - var/obj/effect/sparkles/sparks = new(src.location) - src.total_sparks++ - var/direction - if(src.cardinals) - direction = pick(cardinal) - else - direction = pick(alldirs) - for(i=0, i 10) - n = 10 - number = n - cardinals = c - location = loc - -/datum/effect/system/steam_spread/start() - var/i = 0 - for(i=0, i