Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactors timed actions + hydraulic clamp fix #22819

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/__DEFINES/dcs/signals/signals_mob/signals_mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
///from base of /mob/living/start_pulling: (atom/movable/AM, state, force)
#define COMSIG_MOB_PULL "mob_pull"
#define COMPONENT_BLOCK_PULL (1<<0) // blocks pulling
///from base of /obj/item/pickup: (obj/item/item)
#define COMSIG_MOB_PICKUP_ITEM "mob_pickup_item"
///Mob is trying to open the wires of a target [/atom], from /datum/wires/interactable(): (atom/target)
#define COMSIG_TRY_WIRES_INTERACT "try_wires_interact"
#define COMPONENT_CANT_INTERACT_WIRES (1<<0)
Expand Down
30 changes: 2 additions & 28 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -333,21 +333,12 @@ GLOBAL_LIST_EMPTY(species_list)
return
LAZYSET(user.do_afters, interaction_key, current_interaction_count + 1)

var/atom/user_loc = user.loc
var/atom/target_loc = target?.loc

var/drifting = FALSE
if(!user.Process_Spacemove() && user.inertia_dir)
drifting = TRUE

var/holding = user.get_active_held_item()

if(!(timed_action_flags & IGNORE_SLOWDOWNS))
delay *= user.action_speed_modifier * user.do_after_coefficent() //yogs: darkspawn

var/datum/progressbar/progbar
if(progress)
progbar = new(user, delay, target || user)
progbar = new(user, delay, target || user, timed_action_flags, extra_checks)

SEND_SIGNAL(user, COMSIG_DO_AFTER_BEGAN)

Expand All @@ -357,24 +348,7 @@ GLOBAL_LIST_EMPTY(species_list)
while (world.time < endtime)
stoplag(1)

if(!QDELETED(progbar))
progbar.update(world.time - starttime)

if(drifting && !user.inertia_dir)
drifting = FALSE
user_loc = user.loc

if(QDELETED(user) \
|| (!(timed_action_flags & IGNORE_USER_LOC_CHANGE) && !drifting && user.loc != user_loc) \
|| (!(timed_action_flags & IGNORE_HELD_ITEM) && user.get_active_held_item() != holding) \
|| (!(timed_action_flags & IGNORE_INCAPACITATED) && HAS_TRAIT(user, TRAIT_INCAPACITATED)) \
|| (extra_checks && !extra_checks.Invoke()))
. = FALSE
break

if(target && (user != target) && \
(QDELETED(target) \
|| (!(timed_action_flags & IGNORE_TARGET_LOC_CHANGE) && target.loc != target_loc)))
if(QDELETED(progbar) || !progbar.update(world.time - starttime))
. = FALSE
break

Expand Down
41 changes: 39 additions & 2 deletions code/datums/progressbar.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
var/mob/user
///The client seeing the progress bar.
var/client/user_client
///Extra checks for whether to stop the progress.
var/datum/callback/extra_checks
///Effectively the number of steps the progress bar will need to do before reaching completion.
var/goal = 1
///Control check to see if the progress was interrupted before reaching its goal.
var/last_progress = 0
///Variable to ensure smooth visual stacking on multiple progress bars.
var/listindex = 0
///Whether progress has already been ended.
var/progress_ended = FALSE


/datum/progressbar/New(mob/User, goal_number, atom/target)
/datum/progressbar/New(mob/User, goal_number, atom/target, timed_action_flags = NONE)
. = ..()
if (!istype(target))
stack_trace("Invalid target [target] passed in")
Expand Down Expand Up @@ -50,6 +54,23 @@
RegisterSignal(user, COMSIG_QDELETING, PROC_REF(on_user_delete))
RegisterSignal(user, COMSIG_MOB_LOGOUT, PROC_REF(clean_user_client))
RegisterSignal(user, COMSIG_MOB_LOGIN, PROC_REF(on_user_login))
if(!(timed_action_flags & IGNORE_USER_LOC_CHANGE))
RegisterSignal(user, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
var/obj/mecha/mech = user.loc
if(ismecha(user.loc) && user == mech.occupant)
RegisterSignal(mech, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
if(!(timed_action_flags & IGNORE_TARGET_LOC_CHANGE))
RegisterSignal(target, COMSIG_MOVABLE_MOVED, PROC_REF(on_moved))
if(!(timed_action_flags & IGNORE_HELD_ITEM))
var/obj/item/held = user.get_active_held_item()
if(held)
RegisterSignal(held, COMSIG_ITEM_EQUIPPED, PROC_REF(end_progress))
RegisterSignal(held, COMSIG_ITEM_DROPPED, PROC_REF(end_progress))
else
RegisterSignal(user, COMSIG_MOB_PICKUP_ITEM, PROC_REF(end_progress))
RegisterSignal(user, COMSIG_MOB_SWAPPING_HANDS, PROC_REF(end_progress))
if(!(timed_action_flags & IGNORE_INCAPACITATED))
RegisterSignal(user, SIGNAL_ADDTRAIT(TRAIT_INCAPACITATED), PROC_REF(end_progress))


/datum/progressbar/Destroy()
Expand Down Expand Up @@ -121,22 +142,38 @@

///Updates the progress bar image visually.
/datum/progressbar/proc/update(progress)
if(progress_ended)
return FALSE
progress = clamp(progress, 0, goal)
if(progress == last_progress)
return
return FALSE
last_progress = progress
if(extra_checks && !extra_checks.Invoke())
return FALSE
bar.icon_state = "prog_bar_[round(((progress / goal) * 100), 5)]"
return TRUE


///Called on progress end, be it successful or a failure. Wraps up things to delete the datum and bar.
/datum/progressbar/proc/end_progress()
if(progress_ended)
return
progress_ended = TRUE

if(last_progress != goal)
bar.icon_state = "[bar.icon_state]_fail"

animate(bar, alpha = 0, time = PROGRESSBAR_ANIMATION_TIME)

QDEL_IN(src, PROGRESSBAR_ANIMATION_TIME)

/datum/progressbar/proc/on_moved(atom/movable/mover, atom/old_loc, movement_dir, forced, list/old_locs, momentum_change, interrupting)
SIGNAL_HANDLER
if(!interrupting)
return
if(!mover.Process_Spacemove() && mover.inertia_dir)
return
INVOKE_ASYNC(src, PROC_REF(end_progress))

#undef PROGRESSBAR_ANIMATION_TIME
#undef PROGRESSBAR_HEIGHT
5 changes: 3 additions & 2 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,9 @@
* * The forced flag indicates whether this was a forced move, which skips many checks of regular movement.
* * The old_locs is an optional argument, in case the moved movable was present in multiple locations before the movement.
* * momentum_change represents whether this movement is due to a "new" force if TRUE or an already "existing" force if FALSE
* * interrupting will cancel any do_after progress bars that should be canceled by moving.
**/
/atom/movable/proc/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE)
/atom/movable/proc/Moved(atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE, interrupting = TRUE)
SHOULD_CALL_PARENT(TRUE)

if (!inertia_moving && momentum_change)
Expand All @@ -755,7 +756,7 @@
if (!moving_diagonally && client_mobs_in_contents)
update_parallax_contents()

SEND_SIGNAL(src, COMSIG_MOVABLE_MOVED, old_loc, movement_dir, forced, old_locs, momentum_change)
SEND_SIGNAL(src, COMSIG_MOVABLE_MOVED, old_loc, movement_dir, forced, old_locs, momentum_change, interrupting)

if(old_loc)
SEND_SIGNAL(old_loc, COMSIG_ATOM_ABSTRACT_EXITED, src, movement_dir)
Expand Down
10 changes: 4 additions & 6 deletions code/game/mecha/equipment/mecha_equipment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
if(!chassis)
return FALSE
set_ready_state(FALSE)
. = do_after(chassis.occupant, equip_cooldown * check_eva(), target, extra_checks = CALLBACK(src, PROC_REF(do_after_checks), target, chassis.loc))
. = do_after(chassis.occupant, equip_cooldown * check_eva(), target, extra_checks = CALLBACK(src, PROC_REF(do_after_checks), target))
set_ready_state(TRUE)
if(!.)
return
Expand All @@ -158,16 +158,14 @@
/obj/item/mecha_parts/mecha_equipment/proc/do_after_mecha(atom/target, delay)
if(!chassis)
return
return do_after(chassis.occupant, delay * check_eva(), target, extra_checks = CALLBACK(src, PROC_REF(do_after_checks), target, chassis.loc))
return do_after(chassis.occupant, delay * check_eva(), target, extra_checks = CALLBACK(src, PROC_REF(do_after_checks), target))

/obj/item/mecha_parts/mecha_equipment/proc/do_after_checks(atom/target, atom/old_loc)
/obj/item/mecha_parts/mecha_equipment/proc/do_after_checks(atom/target)
if(!chassis)
return FALSE
if(chassis.loc != old_loc || chassis.inertia_dir)
return FALSE
if(src != chassis.selected)
return FALSE
if(!(chassis.omnidirectional_attacks || (get_dir(chassis, target) & chassis.dir)))
if(target && !(chassis.omnidirectional_attacks || (get_dir(chassis, target) & chassis.dir)))
return FALSE
return TRUE

Expand Down
1 change: 1 addition & 0 deletions code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ GLOBAL_VAR_INIT(rpg_loot_items, FALSE)
/obj/item/proc/pickup(mob/user)
SHOULD_CALL_PARENT(TRUE)
SEND_SIGNAL(src, COMSIG_ITEM_PICKUP, user)
SEND_SIGNAL(user, COMSIG_MOB_PICKUP_ITEM, src)
item_flags |= IN_INVENTORY

// called when "found" in pockets and storage items. Returns 1 if the search should end.
Expand Down
4 changes: 2 additions & 2 deletions code/modules/modular_computers/computers/item/computer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,8 @@
. = ..()
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)

/obj/item/modular_computer/proc/parent_moved()
SEND_SIGNAL(src, COMSIG_MOVABLE_MOVED)
/obj/item/modular_computer/proc/parent_moved(datum/source, atom/old_loc, movement_dir, forced, list/old_locs, momentum_change = TRUE, interrupting = TRUE)
SEND_SIGNAL(src, COMSIG_MOVABLE_MOVED, old_loc, movement_dir, forced, old_locs, momentum_change, interrupting)

/obj/item/modular_computer/proc/uplink_check(mob/living/M, code)
return SEND_SIGNAL(src, COMSIG_NTOS_CHANGE_RINGTONE, M, code) & COMPONENT_STOP_RINGTONE_CHANGE
Expand Down
Loading