Refactored do_after to use a flag-based system for options (#17127)

* Refactored do_after to use a flag-based system for options

* More flags

* Ditto

* Use the HAS_FLAG macro

* do_after pass

* Fix burning paper code

* Resolve issues from Fluffy's code reviews

* .
This commit is contained in:
Cody Brittain
2023-09-27 12:17:14 +00:00
committed by GitHub
parent 085e7c8107
commit 0a3dac31e0
125 changed files with 531 additions and 314 deletions
+10 -10
View File
@@ -25,7 +25,7 @@
"<span class='warning'>[user] begins deploying \the [src].</span>",
"<span class='notice'>You begin deplyoing \the [src].</span>"
)
if (!do_after(user, 0.45 SECONDS, act_target = src))
if (!do_after(user, 0.45 SECONDS))
return
user.visible_message(
"<span class='warning'>[user] deployed \the [src].</span>" ,
@@ -197,7 +197,7 @@
"<span class='warning'>[usr] begins folding up the [src.name].</span>",
"<span class='notice'>You begin folding up the [src.name].</span>"
)
if (!do_after(usr, 0.45 SECONDS, act_target = src))
if (!do_after(usr, 0.45 SECONDS))
return
usr.visible_message(
"<span class='warning'>[usr] folds up the [src.name].</span>" ,
@@ -268,7 +268,7 @@
var/time = 360 * breakout_time * 2
breakout = TRUE
if (!do_after(escapee, time, act_target = src, extra_checks = CALLBACK(src, PROC_REF(breakout_callback), escapee)))
if (!do_after(escapee, time, src, extra_checks = CALLBACK(src, PROC_REF(breakout_callback), escapee)))
breakout = FALSE
return
@@ -312,7 +312,7 @@
"<span class='warning'>[usr] is setting [src] internals.</span>",
"<span class='notice'>You are settting [src] internals.</span>"
)
if (!do_after(usr, 2 SECONDS, act_target = src))
if (!do_after(usr, 2 SECONDS, src))
return
usr.visible_message(
"<span class='warning'>[usr] has set [src] internals.</span>" ,
@@ -345,7 +345,7 @@
"<span class='warning'>[usr] is removing [internal_tank] from [src].</span>",
"<span class='notice'>You are removing [internal_tank] from [src].</span>"
)
if (!do_after(usr, 2 SECONDS, act_target = src))
if (!do_after(usr, 2 SECONDS, src))
return
usr.visible_message(
"<span class='warning'>[usr] has removed [internal_tank] from [src].</span>",
@@ -378,7 +378,7 @@
"<span class='warning'>[usr] is removing [cell] from [src].</span>",
"<span class='notice'>You are removing [cell] from [src].</span>"
)
if (!do_after(usr, 2 SECONDS, act_target = src))
if (!do_after(usr, 2 SECONDS, src))
return
usr.visible_message(
"<span class='warning'>[usr] has removed [cell] from [src].</span>",
@@ -399,7 +399,7 @@
"<span class='warning'>[user] is attaching [W] to [src].</span>",
"<span class='notice'>You are attaching [W] to [src].</span>"
)
if (!do_after(user, 2 SECONDS, act_target = src))
if (!do_after(user, 2 SECONDS, src))
return
user.visible_message(
"<span class='warning'>[user] has attached [W] to [src].</span>",
@@ -430,7 +430,7 @@
"<span class='notice'>You begin putting cable restrains on zipper of [src].</span>"
)
playsound(loc, 'sound/weapons/cablecuff.ogg', 50, 1)
if (!do_after(user, 3 SECONDS, act_target = src, extra_checks = CALLBACK(src, PROC_REF(is_closed))))
if (!do_after(user, 3 SECONDS, src, extra_checks = CALLBACK(src, PROC_REF(is_closed))))
return TRUE
zipped = !zipped
update_icon()
@@ -452,7 +452,7 @@
"<span class='notice'>You begin cutting cable restrains on zipper of [src].</span>"
)
playsound(loc, 'sound/items/Wirecutter.ogg', 50, 1)
if (!do_after(user, 3 SECONDS, act_target = src, extra_checks = CALLBACK(src, PROC_REF(is_closed))))
if (!do_after(user, 3 SECONDS, src, extra_checks = CALLBACK(src, PROC_REF(is_closed))))
return TRUE
zipped = !zipped
update_icon()
@@ -472,7 +472,7 @@
"<span class='warning'>[user] is attaching [W] to [src].</span>",
"<span class='notice'>You are attaching [W] to [src].</span>"
)
if (!do_after(user, 2 SECONDS, act_target = src))
if (!do_after(user, 2 SECONDS, src))
return TRUE
user.visible_message(
"<span class='warning'>[user] has attached [W] to [src].</span>",
+3 -3
View File
@@ -380,7 +380,7 @@
//beginning to place the paddles on patient's chest to allow some time for people to move away to stop the process
user.visible_message(SPAN_WARNING("\The [user] begins to place [src] on [H]'s chest."), SPAN_WARNING("You begin to place [src] on [H]'s chest..."))
if(!do_after(user, 3 SECONDS, act_target = H))
if(!do_after(user, 3 SECONDS, H, DO_DEFAULT | DO_USER_UNIQUE_ACT))
return
user.visible_message(SPAN_NOTICE("\The [user] places [src] on [H]'s chest."), SPAN_WARNING("You place [src] on [H]'s chest."))
playsound(get_turf(src), 'sound/machines/defib_charge.ogg', 50, 0)
@@ -395,7 +395,7 @@
make_announcement("buzzes, \"Warning - Patient is in hypovolemic shock and may require a blood transfusion.\"", "warning") //also includes heart damage
//placed on chest and short delay to shock for dramatic effect, revive time is 5sec total
if(!do_after(user, chargetime, act_target = H))
if(!do_after(user, chargetime, H))
return
//deduct charge here, in case the base unit was EMPed or something during the delay time
@@ -458,7 +458,7 @@
playsound(get_turf(src), 'sound/machines/defib_charge.ogg', 50, 0)
audible_message(SPAN_WARNING("\The [src] lets out a steadily rising hum..."))
if(!do_after(user, chargetime, act_target = H))
if(!do_after(user, chargetime, H))
return
//deduct charge here, in case the base unit was EMPed or something during the delay time
+1 -1
View File
@@ -75,7 +75,7 @@
current_hacks += target
// On average hackin takes ~10 seconds. Fairly small random span to avoid people simply aborting and trying again
var/hack_result = do_after(user, hack_time + rand(-3 SECONDS, 3 SECONDS), use_user_turf = (allow_movement ? -1 : FALSE))
var/hack_result = do_after(user, hack_time + rand(-3 SECONDS, 3 SECONDS), do_flags = DO_DEFAULT & ~DO_SHOW_PROGRESS)
is_hacking = FALSE
current_hacks -= target
@@ -147,7 +147,7 @@
to_chat(user, SPAN_WARNING("There are no more working lights left in the box!"))
return
if (do_after(user, load_interval, needhand = 0) && boxstartloc == box.loc && ourstartloc == src.loc)
if (do_after(user, load_interval, do_flags = DO_DEFAULT & ~DO_USER_SAME_HAND) && boxstartloc == box.loc && ourstartloc == src.loc)
if(uses >= max_uses) //catches loading from multiple boxes
break
uses++
@@ -238,7 +238,7 @@
/obj/item/device/magnetic_lock/process()
if(!processpower)
return
var/obj/item/cell/C = powercell
var/obj/item/cell/C = powercell
var/delta_sec = (world.time - last_process_time) / 10
var/drainamount = drain_per_second * delta_sec
if (C)
@@ -281,7 +281,7 @@
user.visible_message("<span class='notice'>[user] starts mounting [src] onto [newtarget].</span>", "<span class='notice'>You begin mounting [src] onto [newtarget].</span>")
if (do_after(user, 35))
if (do_after(user, 3.5 SECONDS))
if (!check_target(newtarget, user)) return
@@ -63,7 +63,7 @@
to_chat(usr, "You plug \the [src] into your maintenace port.")
else
visible_message("<b>[usr]</b> begins hunting for the maintenance port on \the [over_object]'s chassis.") // The age old question of "where do I put it in!?"
if(do_after(usr, 50))
if(do_after(usr, 5 SECONDS))
plug(over_object)
visible_message("[usr] plugs \the [src] into \the [attached]'s maintenance port.")
@@ -37,7 +37,7 @@
if(G.pin)
to_chat(user, "<span class ='notice'>You begin removing [G.name]'s [G.pin.name] using \the [src.name], it will take 15 seconds.</span>")
if(!do_after(user, 15 SECONDS, act_target = target))
if(!do_after(user, 15 SECONDS, target, DO_UNIQUE))
return
to_chat(user, "<span class ='notice'>You remove [G.name]'s [G.pin.name].</span>")
+2 -3
View File
@@ -621,8 +621,7 @@ BREATH ANALYZER
LAZYADD(src.other_DNA, H.dna.unique_enzymes)
src.other_DNA_type = "saliva"
if (!do_after(user, 2 SECONDS, act_target = H))
to_chat(user,"<span class='notice'>You and the target need to be standing still in order to take a breath sample.</span>")
if (!do_after(user, 2 SECONDS, H, DO_UNIQUE & ~DO_BOTH_CAN_TURN))
return
user.visible_message("<span class='notice'>[user] takes a breath sample from [H].</span>","<span class='notice'>\The [src] clicks as it finishes reading [H]'s breath sample.</span>")
@@ -710,7 +709,7 @@ BREATH ANALYZER
if(!internal_bodyscanner)
return
user.visible_message("<b>[user]</b> starts scanning \the [M] with \the [src].", SPAN_NOTICE("You start scanning \the [M] with \the [src]."))
if(do_after(user, 7 SECONDS, TRUE))
if(do_after(user, 7 SECONDS, M, DO_UNIQUE))
print_scan(M, user)
add_fingerprint(user)
+1 -1
View File
@@ -34,7 +34,7 @@
var/q // recycled from tip of the day code. it just works!(TM)
q = pick(randomquip)
if(do_after(user, 25))
if(do_after(user, 2.5 SECONDS))
to_chat(user, "<span class='notice'>You notice a particular verse: [q]</span>")
reading = FALSE
+1 -1
View File
@@ -34,7 +34,7 @@
to_chat(user, "You start marking a line on [target].")
if (!do_after(user, 1 SECONDS, act_target = target))
if (!do_after(user, 1 SECONDS, target))
return
for (var/obj/effect/decal/cleanable/draftingchalk/C in target)
+1 -1
View File
@@ -101,7 +101,7 @@
working = TRUE
update_icon()
if(!do_after(user,2 MINUTES))
if(!do_after(user, 2 MINUTES, src, DO_UNIQUE))
to_chat(user, SPAN_WARNING("Your concentration is broken!"))
working = FALSE
update_icon()
+1 -1
View File
@@ -406,7 +406,7 @@ Contains:
to_chat(user, SPAN_DANGER("You can't apply a splint to the arm you're using!"))
return
user.visible_message(SPAN_DANGER("[user] starts to apply \the [src] to their [limb]."), SPAN_DANGER("You start to apply \the [src] to your [limb]."), SPAN_DANGER("You hear something being wrapped."))
if(do_after(user, 50))
if(do_after(user, 5 SECONDS, M))
if (M != user)
user.visible_message(SPAN_DANGER("[user] finishes applying \the [src] to [M]'s [limb]."), SPAN_DANGER("You finish applying \the [src] to [M]'s [limb]."), SPAN_DANGER("You hear something being wrapped."))
else
+1 -1
View File
@@ -135,7 +135,7 @@ var/global/list/datum/stack_recipe/rod_recipes = list(
user.visible_message(SPAN_NOTICE("[user] starts assembling a liquidbag barricade."),
SPAN_NOTICE("You start assembling a liquidbag barricade."))
if(!do_after(user, 3 SECONDS))
if(!do_after(user, 3 SECONDS, do_flags = DO_REPAIR_CONSTRUCT))
return
for(var/obj/O in user.loc) //Objects, we don't care about mobs. Turfs are checked elsewhere
@@ -89,7 +89,7 @@
user.visible_message(SPAN_NOTICE("\The [user] starts slicing the [hide_type] from \the [src]."),
SPAN_NOTICE("You start slicing the [hide_type] from \the [src]"),
SPAN_NOTICE("You hear the sound of a knife scraping against flesh."))
if(do_after(user,50, act_target = src))
if(do_after(user, 5 SECONDS, src))
if(amount <= 0) //Ensures we don't get multiple products from queuing clicks.
return
use(1)
@@ -130,7 +130,7 @@
return
user.visible_message(SPAN_NOTICE("\The [user] starts drying \the [src] with \the [WT]."), SPAN_NOTICE("You start drying the wet leather with \the [WT]..."))
being_dried = TRUE
while(do_after(user, 20, act_target = src) && wetness > 0)
while(do_after(user, 2 SECONDS, src) && wetness > 0)
if(!WT.use(1) || !WT.isOn())
break
if(prob(5))
+1 -1
View File
@@ -159,7 +159,7 @@
to_chat(user, SPAN_NOTICE("Building [recipe.title]..."))
if (recipe.time)
if (!do_after(user, recipe.time))
if (!do_after(user, recipe.time, do_flags = DO_REPAIR_CONSTRUCT))
return
if (use(required))
+1 -1
View File
@@ -570,7 +570,7 @@
var/used_energy = 100
to_chat(user, "Fabricating machine...")
playsound(get_turf(src), 'sound/items/rfd_start.ogg', 50, FALSE)
if(do_after(user, 30 SECONDS, act_target = src))
if(do_after(user, 30 SECONDS, src, DO_UNIQUE))
var/obj/product = new /obj/machinery/transformer
malftransformermade = 1
product.forceMove(get_turf(A))
@@ -187,7 +187,7 @@
if(M.stat != DEAD && ishuman(M) && user.a_intent != I_HURT)
var/mob/living/K = M
if(cult && (K.mind in cult.current_antagonists) && prob(75))
if(do_after(user, 15))
if(do_after(user, 1.5 SECONDS))
K.visible_message(SPAN_DANGER("[user] waves \the [src] over \the [K]'s head, [K] looks captivated by it."), SPAN_WARNING("[user] waves the [src] over your head. <b>You see a foreign light, asking you to follow it. Its presence burns and blinds.</b>"))
var/choice = alert(K,"Do you want to give up your goal?","Become cleansed","Resist","Give in")
switch(choice)
+1 -1
View File
@@ -129,7 +129,7 @@
else
user.visible_message("<span class='warning'>[user] begins to do [H]'s lips with \the [src].</span>", \
"<span class='notice'>You begin to apply \the [src].</span>")
if(do_after(user, 20) && do_after(H, 20, 0)) //user needs to keep their active hand, H does not.
if(do_after(user, 4 SECONDS, H, do_flags = DO_DEFAULT & ~DO_SHOW_PROGRESS & ~DO_BOTH_CAN_TURN))
user.visible_message("<span class='notice'>[user] does [H]'s lips with \the [src].</span>", \
"<span class='notice'>You apply \the [src].</span>")
H.lipstick_color = lipstick_color
@@ -111,7 +111,7 @@
spawn(50)
inuse = 0
if(!do_after(user,50))
if(!do_after(user, 5 SECONDS))
return
user.setClickCooldown(DEFAULT_QUICK_COOLDOWN)
@@ -51,7 +51,7 @@
return
to_chat(user, SPAN_NOTICE("Planting explosives..."))
if(do_after(user, 50, TRUE, target))
if(do_after(user, 5 SECONDS, target, DO_UNIQUE))
user.do_attack_animation(target)
deploy_c4(target, user)
@@ -35,7 +35,7 @@
to_chat(user, SPAN_WARNING("\The [src] reads, \"Scanning failure, please submit scanner for repairs.\""))
return
user.visible_message(SPAN_NOTICE("\The [user] starts analyzing \the [M] with \the [src]..."), SPAN_NOTICE("You start analyzing \the [M] with \the [src]..."))
if(do_after(user, 50, TRUE, src))
if(do_after(user, 5 SECONDS, src, DO_UNIQUE))
if(!isipc(M))
to_chat(user, SPAN_WARNING("You analyze \the [M], but find that they're not an IPC at all!"))
return
@@ -59,4 +59,4 @@
else
to_chat(user, SPAN_WARNING("\The [src]'s wires aren't exposed."))
else
..()
..()
+2 -2
View File
@@ -37,7 +37,7 @@
"<span class='danger'>You begin deploying \the [src]!</span>"
)
if (do_after(user, 60))
if (do_after(user, 6 SECONDS, DO_REPAIR_CONSTRUCT))
user.visible_message(
"<span class='danger'>[user] has deployed \the [src].</span>",
"<span class='danger'>You have deployed \the [src]!</span>"
@@ -90,7 +90,7 @@
var/obj/item/stack/cable_coil/C = I
if(C.use(1))
to_chat(user, SPAN_NOTICE("You start carefully start rewiring \the [src]."))
if(do_after(user, 100, TRUE, src))
if(do_after(user, 10 SECONDS, src, DO_REPAIR_CONSTRUCT))
to_chat(user, SPAN_NOTICE("You successfully rewire \the [src], priming it for use."))
deactivated = FALSE
return
@@ -515,7 +515,7 @@
PowerUp(user)
else
playsound(loc, 'sound/weapons/saw/chainsawpull.ogg', 50, 0, 15)
if(!do_after(user, 2 SECONDS, act_target = user))
if(!do_after(user, 2 SECONDS))
break
/obj/item/material/twohanded/chainsaw/pre_attack(var/mob/living/target, var/mob/living/user)
+1 -1
View File
@@ -78,7 +78,7 @@
else
clean_msg = FALSE
playsound(loc, 'sound/effects/mop.ogg', 25, 1)
if (do_after(user, 25, needhand = 0))
if (do_after(user, 2.5 SECONDS, do_flags = DO_DEFAULT & ~DO_USER_SAME_HAND))
target.clean_blood()
if(clean_msg)
to_chat(user, SPAN_NOTICE("You scrub \the [target.name] out."))
@@ -637,7 +637,7 @@
if(empty_delay)
usr.visible_message("\The [usr] starts to empty the contents of \the [src]...", SPAN_NOTICE("You start emptying the contents of \the [src]..."))
if(!do_after(usr, contents.len * empty_delay, act_target=usr))
if(!do_after(usr, contents.len * empty_delay))
return
var/turf/T = get_turf(src)
+2 -2
View File
@@ -25,7 +25,7 @@
return
user.visible_message("<span class='danger'>\The [user] begins taping over \the [H]'s eyes!</span>")
if(!do_after(user, 30))
if(!do_after(user, 3 SECONDS, H, DO_UNIQUE))
return
// Repeat failure checks.
@@ -54,7 +54,7 @@
playsound(src, /singleton/sound_category/rip_sound, 25)
user.visible_message("<span class='danger'>\The [user] begins taping up \the [H]'s mouth!</span>")
if(!do_after(user, 30))
if(!do_after(user, 3 SECONDS, H, DO_UNIQUE))
return
// Repeat failure checks.
+1 -1
View File
@@ -455,7 +455,7 @@
log_and_message_admins("is attempting to welderbomb", user)
to_chat(user, SPAN_ALERT("You start heating the fueltank..."))
tank.armed = 1
if(do_after(user, 100))
if(do_after(user, 10 SECONDS, O, DO_UNIQUE))
if(tank.defuse)
user.visible_message("[user] melts some of the framework on the [O]!", "You melt some of the framework!")
tank.defuse = 0
+3 -3
View File
@@ -249,7 +249,7 @@
var/time = 360 * time_to_escape * 2
breakout = TRUE
if (!do_after(escapee, time, act_target = src, extra_checks = CALLBACK(src, PROC_REF(breakout_callback), escapee)))
if (!do_after(escapee, time, src))
breakout = FALSE
return
@@ -446,7 +446,7 @@
user.visible_message("<span class='notice'>[user] attempts to pass through \the [src] without triggering it.</span>",
"<span class='notice'>You attempt to pass through \the [src] without triggering it. </span>"
)
if(do_after(user, 2 SECONDS, act_target = src))
if(do_after(user, 2 SECONDS, src))
if(prob(pct))
user.forceMove(loc)
user.visible_message("<span class='notice'>[user] passes through \the [src] without triggering it.</span>",
@@ -626,7 +626,7 @@
to_chat(user, "<span class='notice'>You are trying to add metal bars to \the [src].</span>")
if (!do_after(user, 2 SECONDS, act_target = src))
if (!do_after(user, 2 SECONDS, src))
return
to_chat(user, "<span class='notice'>You add metal bars to \the [src].</span>")