Skip to content

Commit

Permalink
fix(multitasking): removes ability to perform identical do_after() an…
Browse files Browse the repository at this point in the history
…d do_mob()

PR #11254
  • Loading branch information
Filatelele authored Dec 21, 2023
1 parent ac24306 commit b046f2a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions code/_global_vars/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ GLOBAL_LIST_EMPTY(silicon_mob_list) //List of all silicon mobs, including client
GLOBAL_LIST_EMPTY(living_mob_list_) //List of all alive mobs, including clientless. Excludes /mob/new_player
GLOBAL_LIST_EMPTY(dead_mob_list_) //List of all dead mobs, including clientless. Excludes /mob/new_player
GLOBAL_LIST_EMPTY(ghost_mob_list) //List of all ghosts, including clientless. Excludes /mob/new_player

/// List of mobs currently using do_mob() to prevent duplicated actions
GLOBAL_LIST_EMPTY(domobs)
/// List of mobs currently using do_after() to prevent duplicated actions
GLOBAL_LIST_EMPTY(doafters)
31 changes: 26 additions & 5 deletions code/_helpers/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,18 @@
/proc/get_exposed_defense_zone(atom/movable/target)
return pick(BP_HEAD, BP_L_HAND, BP_R_HAND, BP_L_FOOT, BP_R_FOOT, BP_L_ARM, BP_R_ARM, BP_L_LEG, BP_R_LEG, BP_CHEST, BP_GROIN)

/proc/do_mob(atom/movable/affecter, mob/target, time = 30, target_zone = 0, uninterruptible = 0, progress = 1, incapacitation_flags = INCAPACITATION_DEFAULT)
/proc/do_mob(atom/movable/affecter, mob/target, time = 30, target_zone = 0, uninterruptible = 0, progress = 1, incapacitation_flags = INCAPACITATION_DEFAULT, can_multitask = FALSE)
if(!affecter || !target)
return 0
return FALSE

var/uniqueid
if(!can_multitask)
uniqueid = "domob_\ref[affecter]_\ref[target]"
if(uniqueid in GLOB.domobs)
return FALSE

LAZYADD(GLOB.domobs, uniqueid)

var/mob/user = affecter
var/is_mob_type = istype(user)
var/user_loc = affecter.loc
Expand Down Expand Up @@ -183,9 +192,19 @@
if(progbar)
qdel(progbar)

/proc/do_after(mob/user, delay, atom/target = null, needhand = 1, progress = 1, incapacitation_flags = INCAPACITATION_DEFAULT, same_direction = 0, can_move = 0)
if(!can_multitask)
LAZYREMOVE(GLOB.domobs, uniqueid)

/proc/do_after(mob/user, delay, atom/target = null, needhand = TRUE, progress = TRUE, incapacitation_flags = INCAPACITATION_DEFAULT, same_direction = FALSE, can_move = FALSE)
if(!user)
return 0
return FALSE

var/uniqueid = "doafter_\ref[user]_\ref[target]"
if(uniqueid in GLOB.doafters)
return FALSE

LAZYADD(GLOB.doafters, uniqueid)

var/atom/target_loc = null
var/target_type = null

Expand Down Expand Up @@ -229,9 +248,11 @@
. = 0
break

if (progbar)
if(progbar)
qdel(progbar)

LAZYREMOVE(GLOB.doafters, uniqueid)

/proc/is_species(A, species_datum)
. = FALSE
if(ishuman(A))
Expand Down
2 changes: 1 addition & 1 deletion code/datums/surgery/surgery_step.dm
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@

var/success_chance = calc_success_chance(user, target, tool)
var/surgery_duration = SURGERY_DURATION_DELTA * duration * tool.surgery_speed
if(prob(success_chance) && do_mob(user, target, surgery_duration))
if(prob(success_chance) && do_mob(user, target, surgery_duration, can_multitask = TRUE))
success(parent_organ, target_organ, target, tool, user)
else
failure(parent_organ, target_organ, target, tool, user)
Expand Down

0 comments on commit b046f2a

Please sign in to comment.