Skip to content

Commit

Permalink
Convert some spawn() to timers and asyncs. (#630)
Browse files Browse the repository at this point in the history
* 5 files

* 5 files 2

* Update abilities_predalien.dm

* 5 files

* Update lattice.dm

* Update barricade.dm

* vendors

* Update broadcaster.dm

* Update error_handler.dm

* 5 files 5

* Update fireaxe.dm

* 5 files 6

* Update power_cells.dm

* other stuff
  • Loading branch information
Helg2 authored Nov 11, 2024
1 parent 8785d06 commit 34035dd
Show file tree
Hide file tree
Showing 40 changed files with 583 additions and 585 deletions.
165 changes: 84 additions & 81 deletions code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ modules/mob/living/carbon/human/life.dm if you die, you will be zoomed out.
A.update_button_icon()

/obj/item/proc/extinguish(atom/target, mob/user)
if (reagents.total_volume < 1)
if(reagents.total_volume < 1)
to_chat(user, span_warning("\The [src]'s water reserves are empty."))
return

Expand All @@ -964,91 +964,95 @@ modules/mob/living/carbon/human/life.dm if you die, you will be zoomed out.

playsound(user.loc, 'sound/effects/extinguish.ogg', 52, 1, 7)

var/direction = get_dir(user,target)

if(user.buckled && isobj(user.buckled) && !user.buckled.anchored )
spawn(0)
var/obj/structure/bed/chair/C = null
if(istype(user.buckled, /obj/structure/bed/chair))
C = user.buckled
var/obj/B = user.buckled
var/movementdirection = REVERSE_DIR(direction)
if(C)
C.propelled = 4
B.Move(get_step(user,movementdirection), movementdirection)
sleep(0.1 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
if(C)
C.propelled = 3
sleep(0.1 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
sleep(0.1 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
if(C)
C.propelled = 2
sleep(0.2 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
if(C)
C.propelled = 1
sleep(0.2 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
if(C)
C.propelled = 0
sleep(0.3 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
sleep(0.3 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
sleep(0.3 SECONDS)
B.Move(get_step(user,movementdirection), movementdirection)
var/direction = get_dir(user, target)

var/turf/T = get_turf(target)
var/turf/T1 = get_step(T,turn(direction, 90))
var/turf/T2 = get_step(T,turn(direction, -90))
if(user.buckled && isobj(user.buckled) && !user.buckled.anchored)
INVOKE_ASYNC(src, PROC_REF(propelle), target, user, direction)

var/list/the_targets = list(T,T1,T2)

for(var/a=0, a<7, a++)
spawn(0)
var/obj/effect/particle_effect/water/W = new /obj/effect/particle_effect/water( get_turf(user) )
var/turf/my_target = pick(the_targets)
var/datum/reagents/R = new/datum/reagents(5)
if(!W)
return
W.reagents = R
R.my_atom = WEAKREF(W)
if(!W || !src)
return
reagents.trans_to(W,1)
for(var/b=0, b<7, b++)
step_towards(W,my_target)
if(!(W?.reagents))
return
W.reagents.reaction(get_turf(W))
for(var/atom/atm in get_turf(W))
if(!W)
return
if(!W.reagents)
break
W.reagents.reaction(atm)
if(isfire(atm))
var/obj/fire/FF = atm
FF.set_fire(FF.burn_ticks - EXTINGUISH_AMOUNT)
continue
if(isliving(atm)) //For extinguishing mobs on fire
var/mob/living/M = atm
M.ExtinguishMob()
for(var/obj/item/clothing/mask/cigarette/C in M.contents)
if(C.item_state == C.icon_on)
C.die()
if(W.loc == my_target)
break
sleep(0.2 SECONDS)
qdel(W)
for(var/a = 0, a < 7, a++)
INVOKE_ASYNC(src, PROC_REF(extinguish_stage_two), target, user, direction)

if(isspaceturf(user.loc))
user.inertia_dir = get_dir(target, user)
step(user, user.inertia_dir)

/obj/item/proc/propelle(atom/target, mob/user, direction)
var/obj/structure/bed/chair/C = null
if(istype(user.buckled, /obj/structure/bed/chair))
C = user.buckled
var/obj/B = user.buckled
var/movementdirection = REVERSE_DIR(direction)
if(C)
C.propelled = 4
B.Move(get_step(user, movementdirection), movementdirection)
sleep(0.1 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
if(C)
C.propelled = 3
sleep(0.1 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
sleep(0.1 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
if(C)
C.propelled = 2
sleep(0.2 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
if(C)
C.propelled = 1
sleep(0.2 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
if(C)
C.propelled = 0
sleep(0.3 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
sleep(0.3 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)
sleep(0.3 SECONDS)
B.Move(get_step(user, movementdirection), movementdirection)

/obj/item/proc/extinguish_stage_two(atom/target, mob/user, direction)
var/turf/T = get_turf(target)
var/turf/T1 = get_step(T, turn(direction, 90))
var/turf/T2 = get_step(T, turn(direction, -90))

var/list/the_targets = list(T, T1, T2)

var/obj/effect/particle_effect/water/W = new /obj/effect/particle_effect/water( get_turf(user) )
var/turf/my_target = pick(the_targets)
var/datum/reagents/R = new/datum/reagents(5)
if(!W)
return
W.reagents = R
R.my_atom = WEAKREF(W)
if(!W || !src)
return
reagents.trans_to(W, 1)
for(var/b = 0, b < 7, b++)
step_towards(W,my_target)
if(!(W?.reagents))
return
W.reagents.reaction(get_turf(W))
for(var/atom/atm in get_turf(W))
if(!W)
return
if(!W.reagents)
break
W.reagents.reaction(atm)
if(isfire(atm))
var/obj/fire/FF = atm
FF.set_fire(FF.burn_ticks - EXTINGUISH_AMOUNT)
continue
if(isliving(atm)) //For extinguishing mobs on fire
var/mob/living/M = atm
M.ExtinguishMob()
for(var/obj/item/clothing/mask/cigarette/C in M.contents)
if(C.item_state != C.icon_on)
continue
C.die()
if(W.loc == my_target)
break
sleep(0.2 SECONDS)
qdel(W)

// Called when a mob tries to use the item as a tool.
// Handles most checks.
Expand Down Expand Up @@ -1265,8 +1269,7 @@ modules/mob/living/carbon/human/life.dm if you die, you will be zoomed out.
basic_spin_trick(arglist(arguments))
if(7)
if(istype(double))
spawn(0)
double.throw_catch_trick(user)
INVOKE_ASYNC(double, PROC_REF(throw_catch_trick), user)
throw_catch_trick(user)
else
throw_catch_trick(user)
Expand Down
8 changes: 5 additions & 3 deletions code/game/objects/items/power_cells.dm
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@
var/mob/living/carbon/C = user
C.throw_mode_on()
overlays += new/obj/effect/overlay/danger
spawn(rand(3,50))
spark_system.start(src)
explode()
addtimer(CALLBACK(src, PROC_REF(delayed_explosion), spark_system), rand(3, 50))

/obj/item/cell/proc/delayed_explosion(datum/effect_system/spark_spread/spark_system)
spark_system.start(src)
explode()

/obj/item/cell/attackby(obj/item/I, mob/user, params)
. = ..()
Expand Down
20 changes: 12 additions & 8 deletions code/game/objects/items/reagent_containers/food/snacks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -545,21 +545,25 @@
icon_state = "donkpocket"
filling_color = "#DEDEAB"
list_reagents = list(/datum/reagent/consumable/nutriment = 4)
var/warm = 0
tastes = list("meat" = 2, "dough" = 2, "laziness" = 1)
var/warm = FALSE

/obj/item/reagent_containers/food/snacks/donkpocket/proc/cooltime()
if(warm)
spawn( 4200 )
if(!gc_destroyed) //not cdel'd
warm = 0
reagents.del_reagent(/datum/reagent/medicine/tricordrazine)
name = "donk-pocket"
if(!warm)
return
addtimer(CALLBACK(src, PROC_REF(cool_down)), 7 MINUTES)

/obj/item/reagent_containers/food/snacks/donkpocket/proc/cool_down()
if(QDELETED(src))
return
warm = FALSE
reagents.del_reagent(/datum/reagent/medicine/tricordrazine)
name = "donk-pocket"

/obj/item/reagent_containers/food/snacks/human
filling_color = "#D63C3C"
var/hname = ""
var/job = null
filling_color = "#D63C3C"

/obj/item/reagent_containers/food/snacks/omelette
name = "Omelette Du Fromage"
Expand Down
77 changes: 39 additions & 38 deletions code/game/objects/items/reagent_containers/spray.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,26 @@
/obj/item/reagent_containers/spray/proc/Spray_at(atom/A)
var/obj/effect/decal/chempuff/D = new/obj/effect/decal/chempuff(get_turf(src))
D.create_reagents(amount_per_transfer_from_this)
reagents.trans_to(D, amount_per_transfer_from_this, 1/spray_size)
reagents.trans_to(D, amount_per_transfer_from_this, 1 / spray_size)
D.color = mix_color_from_reagents(D.reagents.reagent_list)

var/turf/A_turf = get_turf(A)//BS12
INVOKE_ASYNC(src, PROC_REF(spray_step), A, D)

/obj/item/reagent_containers/spray/proc/spray_step(atom/our_atom, obj/effect/decal/chempuff/our_decal)
var/turf/A_turf = get_turf(our_atom)//BS12
var/spray_dist = spray_size
spawn(0)
for(var/i=0, i<spray_dist, i++)
step_towards(D,A)
D.reagents.reaction(get_turf(D))
for(var/atom/T in get_turf(D))
D.reagents.reaction(T, VAPOR)
// When spraying against the wall, also react with the wall, but
// not its contents. BS12
if(get_dist(D, A_turf) == 1 && A_turf.density)
D.reagents.reaction(A_turf)
sleep(0.2 SECONDS)
sleep(0.3 SECONDS)
qdel(D)

for(var/i = 0, i < spray_dist, i++)
step_towards(our_decal, our_atom)
our_decal.reagents.reaction(get_turf(our_decal))
for(var/atom/T in get_turf(our_decal))
our_decal.reagents.reaction(T, VAPOR)
// When spraying against the wall, also react with the wall, but
// not its contents. BS12
if(get_dist(our_decal, A_turf) == 1 && A_turf.density)
our_decal.reagents.reaction(A_turf)
sleep(0.2 SECONDS)
sleep(0.3 SECONDS)
qdel(our_decal)

/obj/item/reagent_containers/spray/attack_self(mob/user)
if(!possible_transfer_amounts)
Expand Down Expand Up @@ -169,7 +169,7 @@
//this is a big copypasta clusterfuck, but it's still better than it used to be!
/obj/item/reagent_containers/spray/chemsprayer/Spray_at(atom/A as mob|obj)
var/Sprays[3]
for(var/i=1, i<=3, i++) // intialize sprays
for(var/i = 1, i <= 3, i++) // intialize sprays
if(src.reagents.total_volume < 1) break
var/obj/effect/decal/chempuff/D = new/obj/effect/decal/chempuff(get_turf(src))
D.create_reagents(amount_per_transfer_from_this)
Expand All @@ -179,29 +179,30 @@

Sprays[i] = D

var/direction = get_dir(src, A)
var/turf/T = get_turf(A)
INVOKE_ASYNC(src, PROC_REF(spray_step), A, null, Sprays)

/obj/item/reagent_containers/spray/chemspray/spray_step(atom/our_atom, obj/effect/decal/chempuff/our_decal, Sprays)
var/direction = get_dir(src, our_atom)
var/turf/T = get_turf(our_atom)
var/turf/T1 = get_step(T,turn(direction, 90))
var/turf/T2 = get_step(T,turn(direction, -90))
var/list/the_targets = list(T,T1,T2)

for(var/i=1, length(i<=Sprays), i++)
spawn()
var/obj/effect/decal/chempuff/D = Sprays[i]
if(!D) continue

// Spreads the sprays a little bit
var/turf/my_target = pick(the_targets)
the_targets -= my_target

for(var/j=1, j<=rand(6,8), j++)
step_towards(D, my_target)
D.reagents.reaction(get_turf(D))
for(var/atom/t in get_turf(D))
D.reagents.reaction(t, VAPOR)
sleep(0.2 SECONDS)
qdel(D)

var/list/the_targets = list(T, T1, T2)

for(var/i = 1, length(i <= Sprays), i++)
var/obj/effect/decal/chempuff/D = Sprays[i]
if(!D)
continue
// Spreads the sprays a little bit
var/turf/my_target = pick(the_targets)
the_targets -= my_target

for(var/j = 1, j <= rand(6, 8), j++)
step_towards(D, my_target)
D.reagents.reaction(get_turf(D))
for(var/atom/t in get_turf(D))
D.reagents.reaction(t, VAPOR)
sleep(0.2 SECONDS)
qdel(D)

// Plant-B-Gone
/obj/item/reagent_containers/spray/plantbgone // -- Skie
Expand Down
14 changes: 8 additions & 6 deletions code/game/objects/items/scanners.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ REAGENT SCANNER
if(O.invisibility == INVISIBILITY_MAXIMUM)
O.invisibility = 0
O.alpha = 128
spawn(10)
if(O && !O.gc_destroyed)
var/turf/U = O.loc
if(U.intact_tile)
O.invisibility = INVISIBILITY_MAXIMUM
O.alpha = 255
addtimer(CALLBACK(src, PROC_REF(scan_for_items), O), 1 SECONDS)

/obj/item/t_scanner/proc/scan_for_items(obj/our_object)
if(our_object.gc_destroyed)
return
var/turf/U = our_object.loc
if(U.intact_tile)
our_object.invisibility = INVISIBILITY_MAXIMUM
our_object.alpha = 255

/obj/item/healthanalyzer
name = "\improper HF2 health analyzer"
Expand Down
Loading

0 comments on commit 34035dd

Please sign in to comment.