From 032511a03e7a787e9d5670361fad36104ea35cbf Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Mon, 5 Mar 2018 15:02:10 -0600 Subject: [PATCH] [MIRROR] Added a cooldown to being shown hud images (#5810) * Merge pull request #36144 from Cruix/hud_images_cd Added a cooldown to being shown hud images * Added a cooldown to being shown hud images --- code/__DEFINES/atom_hud.dm | 2 ++ code/datums/hud.dm | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/code/__DEFINES/atom_hud.dm b/code/__DEFINES/atom_hud.dm index 017a3f8bfe..0c5edf5b99 100644 --- a/code/__DEFINES/atom_hud.dm +++ b/code/__DEFINES/atom_hud.dm @@ -55,3 +55,5 @@ #define NOTIFY_JUMP "jump" #define NOTIFY_ATTACK "attack" #define NOTIFY_ORBIT "orbit" + +#define ADD_HUD_TO_COOLDOWN 20 //cooldown for being shown the images for any particular data hud diff --git a/code/datums/hud.dm b/code/datums/hud.dm index fc6c09be14..17632acba0 100644 --- a/code/datums/hud.dm +++ b/code/datums/hud.dm @@ -32,6 +32,9 @@ GLOBAL_LIST_INIT(huds, list( var/list/mob/hudusers = list() //list with all mobs who can see the hud var/list/hud_icons = list() //these will be the indexes for the atom's hud_list + var/list/next_time_allowed = list() //mobs associated with the next time this hud can be added to them + var/list/queued_to_see = list() //mobs that have triggered the cooldown and are queued to see the hud, but do not yet + /datum/atom_hud/New() GLOB.all_huds += src @@ -48,8 +51,11 @@ GLOBAL_LIST_INIT(huds, list( return if (!--hudusers[M]) hudusers -= M - for(var/atom/A in hudatoms) - remove_from_single_hud(M, A) + if(queued_to_see[M]) + queued_to_see -= M + else + for(var/atom/A in hudatoms) + remove_from_single_hud(M, A) /datum/atom_hud/proc/remove_from_hud(atom/A) if(!A) @@ -68,13 +74,26 @@ GLOBAL_LIST_INIT(huds, list( /datum/atom_hud/proc/add_hud_to(mob/M) if(!M) return - if (!hudusers[M]) + if(!hudusers[M]) hudusers[M] = 1 - for(var/atom/A in hudatoms) - add_to_single_hud(M, A) + if(next_time_allowed[M] > world.time) + if(!queued_to_see[M]) + addtimer(CALLBACK(src, .proc/show_hud_images_after_cooldown, M), next_time_allowed[M] - world.time) + queued_to_see[M] = TRUE + else + next_time_allowed[M] = world.time + ADD_HUD_TO_COOLDOWN + for(var/atom/A in hudatoms) + add_to_single_hud(M, A) else hudusers[M]++ +/datum/atom_hud/proc/show_hud_images_after_cooldown(M) + if(queued_to_see[M]) + queued_to_see -= M + next_time_allowed[M] = world.time + ADD_HUD_TO_COOLDOWN + for(var/atom/A in hudatoms) + add_to_single_hud(M, A) + /datum/atom_hud/proc/add_to_hud(atom/A) if(!A) return FALSE