Merge pull request #7655 from VOREStation/aro-doingafter

Make some progress bar activities exclusive
This commit is contained in:
Aronai Sieyes
2020-05-05 19:47:08 -04:00
committed by GitHub
9 changed files with 86 additions and 37 deletions

View File

@@ -14,6 +14,7 @@
#define GODMODE 0x1000 #define GODMODE 0x1000
#define FAKEDEATH 0x2000 // Replaces stuff like changeling.changeling_fakedeath. #define FAKEDEATH 0x2000 // Replaces stuff like changeling.changeling_fakedeath.
#define DISFIGURED 0x4000 // Set but never checked. Remove this sometime and replace occurences with the appropriate organ code #define DISFIGURED 0x4000 // Set but never checked. Remove this sometime and replace occurences with the appropriate organ code
#define DOING_TASK 0x8000 // Performing a do_after or do_mob that's exclusive
// Grab levels. // Grab levels.
#define GRAB_PASSIVE 1 #define GRAB_PASSIVE 1

View File

@@ -142,9 +142,14 @@ Proc for attack log creation, because really why not
else else
return pick("chest", "groin") return pick("chest", "groin")
/proc/do_mob(mob/user , mob/target, time = 30, target_zone = 0, uninterruptible = FALSE, progress = TRUE, ignore_movement = FALSE) /proc/do_mob(mob/user , mob/target, time = 30, target_zone = 0, uninterruptible = FALSE, progress = TRUE, ignore_movement = FALSE, exclusive = FALSE)
if(!user || !target) if(!user || !target)
return 0 return 0
if(!time)
return 1 //Done!
if(user.status_flags & DOING_TASK)
to_chat(user, "<span class='warning'>You're in the middle of doing something else already.</span>")
return 0 //Performing an exclusive do_after or do_mob already
var/user_loc = user.loc var/user_loc = user.loc
var/target_loc = target.loc var/target_loc = target.loc
@@ -155,6 +160,10 @@ Proc for attack log creation, because really why not
var/endtime = world.time+time var/endtime = world.time+time
var/starttime = world.time var/starttime = world.time
if(exclusive)
user.status_flags |= DOING_TASK
. = TRUE . = TRUE
while (world.time < endtime) while (world.time < endtime)
stoplag(1) stoplag(1)
@@ -186,14 +195,20 @@ Proc for attack log creation, because really why not
. = FALSE . = FALSE
break break
if(exclusive)
user.status_flags &= ~DOING_TASK
if (progbar) if (progbar)
qdel(progbar) qdel(progbar)
/proc/do_after(mob/user, delay, atom/target = null, needhand = TRUE, progress = TRUE, incapacitation_flags = INCAPACITATION_DEFAULT, ignore_movement = FALSE, max_distance = null) /proc/do_after(mob/user, delay, atom/target = null, needhand = TRUE, progress = TRUE, incapacitation_flags = INCAPACITATION_DEFAULT, ignore_movement = FALSE, max_distance = null, exclusive = FALSE)
if(!user) if(!user)
return 0 return 0
if(!delay) if(!delay)
return 1 //Okay. Done. return 1 //Okay. Done.
if(user.status_flags & DOING_TASK)
to_chat(user, "<span class='warning'>You're in the middle of doing something else already.</span>")
return 0 //Performing an exclusive do_after or do_mob already
var/atom/target_loc = null var/atom/target_loc = null
if(target) if(target)
target_loc = target.loc target_loc = target.loc
@@ -214,6 +229,10 @@ Proc for attack log creation, because really why not
var/endtime = world.time + delay var/endtime = world.time + delay
var/starttime = world.time var/starttime = world.time
if(exclusive)
user.status_flags |= DOING_TASK
. = 1 . = 1
while (world.time < endtime) while (world.time < endtime)
stoplag(1) stoplag(1)
@@ -250,6 +269,9 @@ Proc for attack log creation, because really why not
. = FALSE . = FALSE
break break
if(exclusive)
user.status_flags &= ~DOING_TASK
if(progbar) if(progbar)
qdel(progbar) qdel(progbar)

View File

@@ -1,46 +1,70 @@
#define PROGRESSBAR_HEIGHT 6
/datum/progressbar /datum/progressbar
var/goal = 1 var/goal = 1
var/image/bar var/image/bar
var/shown = 0 var/shown = 0
var/mob/user var/mob/user
var/client/client var/client/client
var/listindex
/datum/progressbar/New(mob/user, goal_number, atom/target) /datum/progressbar/New(mob/User, goal_number, atom/target)
. = ..() . = ..()
if(!target) target = user
if(!istype(target)) if(!istype(target))
EXCEPTION("Invalid target given") target = User
if(goal_number) if(goal_number)
goal = goal_number goal = goal_number
bar = image('icons/effects/progessbar.dmi', target, "prog_bar_0") bar = image('icons/effects/progressbar.dmi', target, "prog_bar_0")
bar.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA bar.alpha = 0
bar.pixel_y = 32
bar.plane = PLANE_PLAYER_HUD bar.plane = PLANE_PLAYER_HUD
src.user = user bar.appearance_flags = APPEARANCE_UI_IGNORE_ALPHA
user = User
if(user) if(user)
client = user.client client = user.client
/datum/progressbar/Destroy() LAZYINITLIST(user.progressbars)
if (client) LAZYINITLIST(user.progressbars[bar.loc])
client.images -= bar var/list/bars = user.progressbars[bar.loc]
QDEL_NULL(bar) bars.Add(src)
user = null listindex = bars.len
client = null animate(bar, pixel_y = 32 + (PROGRESSBAR_HEIGHT * (listindex - 1)), alpha = 255, time = 5, easing = SINE_EASING)
return ..()
/datum/progressbar/proc/update(progress) /datum/progressbar/proc/update(progress)
//to_world("Update [progress] - [goal] - [(progress / goal)] - [((progress / goal) * 100)] - [round(((progress / goal) * 100), 5)]")
if(!user || !user.client) if(!user || !user.client)
shown = 0 shown = 0
return return
if(user.client != client) if(user.client != client)
if(client) if(client)
client.images -= bar client.images -= bar
shown = 0 if(user.client)
client = user.client user.client.images += bar
progress = CLAMP(progress, 0, goal) progress = clamp(progress, 0, goal)
bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]" bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]"
if(!shown && user.is_preference_enabled(/datum/client_preference/show_progress_bar)) if(!shown && user.is_preference_enabled(/datum/client_preference/show_progress_bar))
user.client.images += bar user.client.images += bar
shown = 1 shown = 1
/datum/progressbar/proc/shiftDown()
--listindex
var/shiftheight = bar.pixel_y - PROGRESSBAR_HEIGHT
animate(bar, pixel_y = shiftheight, time = 5, easing = SINE_EASING)
/datum/progressbar/Destroy()
for(var/I in user.progressbars[bar.loc])
var/datum/progressbar/P = I
if(P != src && P.listindex > listindex)
P.shiftDown()
var/list/bars = user.progressbars[bar.loc]
bars.Remove(src)
if(!bars.len)
LAZYREMOVE(user.progressbars, bar.loc)
animate(bar, alpha = 0, time = 5)
spawn(5)
if(client)
client.images -= bar
qdel(bar)
. = ..()
#undef PROGRESSBAR_HEIGHT

View File

@@ -111,7 +111,7 @@
continue continue
if(used == amount) if(used == amount)
break break
if(!do_mob(user, M, W.damage/3)) if(!do_mob(user, M, W.damage/3, exclusive = TRUE))
to_chat(user, "<span class='notice'>You must stand still to bandage wounds.</span>") to_chat(user, "<span class='notice'>You must stand still to bandage wounds.</span>")
break break
@@ -174,7 +174,7 @@
continue continue
if(used == amount) if(used == amount)
break break
if(!do_mob(user, M, W.damage/5)) if(!do_mob(user, M, W.damage/5, exclusive = TRUE))
to_chat(user, "<span class='notice'>You must stand still to bandage wounds.</span>") to_chat(user, "<span class='notice'>You must stand still to bandage wounds.</span>")
break break
@@ -234,7 +234,7 @@
else else
user.visible_message("<span class='notice'>\The [user] starts salving wounds on [M]'s [affecting.name].</span>", \ user.visible_message("<span class='notice'>\The [user] starts salving wounds on [M]'s [affecting.name].</span>", \
"<span class='notice'>You start salving the wounds on [M]'s [affecting.name].</span>" ) "<span class='notice'>You start salving the wounds on [M]'s [affecting.name].</span>" )
if(!do_mob(user, M, 10)) if(!do_mob(user, M, 10, exclusive = TRUE))
to_chat(user, "<span class='notice'>You must stand still to salve wounds.</span>") to_chat(user, "<span class='notice'>You must stand still to salve wounds.</span>")
return 1 return 1
if(affecting.is_salved()) // We do a second check after the delay, in case it was bandaged after the first check. if(affecting.is_salved()) // We do a second check after the delay, in case it was bandaged after the first check.
@@ -281,7 +281,7 @@
continue continue
//if(used == amount) //VOREStation Edit //if(used == amount) //VOREStation Edit
// break //VOREStation Edit // break //VOREStation Edit
if(!do_mob(user, M, W.damage/5)) if(!do_mob(user, M, W.damage/5, exclusive = TRUE))
to_chat(user, "<span class='notice'>You must stand still to bandage wounds.</span>") to_chat(user, "<span class='notice'>You must stand still to bandage wounds.</span>")
break break
if(affecting.is_bandaged() && affecting.is_disinfected()) // We do a second check after the delay, in case it was bandaged after the first check. if(affecting.is_bandaged() && affecting.is_disinfected()) // We do a second check after the delay, in case it was bandaged after the first check.
@@ -336,7 +336,7 @@
else else
user.visible_message("<span class='notice'>\The [user] starts salving wounds on [M]'s [affecting.name].</span>", \ user.visible_message("<span class='notice'>\The [user] starts salving wounds on [M]'s [affecting.name].</span>", \
"<span class='notice'>You start salving the wounds on [M]'s [affecting.name].</span>" ) "<span class='notice'>You start salving the wounds on [M]'s [affecting.name].</span>" )
if(!do_mob(user, M, 10)) if(!do_mob(user, M, 10, exclusive = TRUE))
to_chat(user, "<span class='notice'>You must stand still to salve wounds.</span>") to_chat(user, "<span class='notice'>You must stand still to salve wounds.</span>")
return 1 return 1
if(affecting.is_salved()) // We do a second check after the delay, in case it was bandaged after the first check. if(affecting.is_salved()) // We do a second check after the delay, in case it was bandaged after the first check.
@@ -383,7 +383,7 @@
to_chat(user, "<span class='danger'>You can't apply a splint to the arm you're using!</span>") to_chat(user, "<span class='danger'>You can't apply a splint to the arm you're using!</span>")
return return
user.visible_message("<span class='danger'>[user] starts to apply \the [src] to their [limb].</span>", "<span class='danger'>You start to apply \the [src] to your [limb].</span>", "<span class='danger'>You hear something being wrapped.</span>") user.visible_message("<span class='danger'>[user] starts to apply \the [src] to their [limb].</span>", "<span class='danger'>You start to apply \the [src] to your [limb].</span>", "<span class='danger'>You hear something being wrapped.</span>")
if(do_after(user, 50, M)) if(do_after(user, 50, M, exclusive = TRUE))
if(affecting.splinted) if(affecting.splinted)
to_chat(user, "<span class='danger'>[M]'s [limb] is already splinted!</span>") to_chat(user, "<span class='danger'>[M]'s [limb] is already splinted!</span>")
return return

View File

@@ -16,7 +16,7 @@
if (istype(M,/mob/living/silicon/robot)) //Repairing cyborgs if (istype(M,/mob/living/silicon/robot)) //Repairing cyborgs
var/mob/living/silicon/robot/R = M var/mob/living/silicon/robot/R = M
if (R.getBruteLoss() || R.getFireLoss()) if (R.getBruteLoss() || R.getFireLoss())
if(do_after(user,7 * toolspeed)) if(do_after(user, 7 * toolspeed, exclusive = TRUE))
R.adjustBruteLoss(-15) R.adjustBruteLoss(-15)
R.adjustFireLoss(-15) R.adjustFireLoss(-15)
R.updatehealth() R.updatehealth()
@@ -51,9 +51,9 @@
else if(can_use(1)) else if(can_use(1))
user.setClickCooldown(user.get_attack_speed(src)) user.setClickCooldown(user.get_attack_speed(src))
if(S.open >= 2) if(S.open >= 2)
if(do_after(user,5 * toolspeed)) if(do_after(user, 5 * toolspeed, exclusive = TRUE))
S.heal_damage(restoration_internal, restoration_internal, robo_repair = 1) S.heal_damage(restoration_internal, restoration_internal, robo_repair = 1)
else if(do_after(user,5 * toolspeed)) else if(do_after(user, 5 * toolspeed, exclusive = TRUE))
S.heal_damage(restoration_external,restoration_external, robo_repair =1) S.heal_damage(restoration_external,restoration_external, robo_repair =1)
H.updatehealth() H.updatehealth()
use(1) use(1)

View File

@@ -145,7 +145,7 @@
if (recipe.time) if (recipe.time)
to_chat(user, "<span class='notice'>Building [recipe.title] ...</span>") to_chat(user, "<span class='notice'>Building [recipe.title] ...</span>")
if (!do_after(user, recipe.time)) if (!do_after(user, recipe.time, exclusive = TRUE))
return return
if (use(required)) if (use(required))

View File

@@ -230,3 +230,5 @@
var/attack_icon_state //State for above var/attack_icon_state //State for above
var/registered_z var/registered_z
var/list/progressbars = null //for stacking do_after bars

View File

@@ -162,7 +162,7 @@
// Not staying still fails you too. // Not staying still fails you too.
if(success) if(success)
var/calc_duration = rand(S.min_duration, S.max_duration) var/calc_duration = rand(S.min_duration, S.max_duration)
if(!do_mob(user, M, calc_duration * toolspeed, zone)) if(!do_mob(user, M, calc_duration * toolspeed, zone, exclusive = TRUE))
success = FALSE success = FALSE
to_chat(user, "<span class='warning'>You must remain close to and keep focused on your patient to conduct surgery.</span>") to_chat(user, "<span class='warning'>You must remain close to and keep focused on your patient to conduct surgery.</span>")

View File

Before

Width:  |  Height:  |  Size: 571 B

After

Width:  |  Height:  |  Size: 571 B