cooldown
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Cooldown system based on an datum-level associative lazylist using timers.
|
||||
* If you are running hot procs that require high performance, checking world.time directly through a variable will always be faster.
|
||||
* If you are not, then this should be fine to use, it's not very expensive.
|
||||
* If you want a stoppable timer either make new macros or use a different system. Do not make every timer stoppable, that increases performance cost.
|
||||
*/
|
||||
|
||||
//INDEXES
|
||||
#define COOLDOWN_EMPLOYMENT_CABINET "employment cabinet"
|
||||
|
||||
//MACROS
|
||||
#define COOLDOWN_START(cd_source, cd_index, cd_time) LAZYSET(cd_source.cooldowns, cd_index, addtimer(CALLBACK(GLOBAL_PROC, /proc/end_cooldown, cd_source, cd_index), cd_time))
|
||||
|
||||
#define COOLDOWN_CHECK(cd_source, cd_index) LAZYACCESS(cd_source.cooldowns, cd_index)
|
||||
|
||||
#define COOLDOWN_END(cd_source, cd_index) LAZYREMOVE(cd_source.cooldowns, cd_index)
|
||||
@@ -39,6 +39,9 @@
|
||||
/// A weak reference to another datum
|
||||
var/datum/weakref/weak_reference
|
||||
|
||||
///Lazy associative list of currently active cooldowns.
|
||||
var/list/cooldowns
|
||||
|
||||
#ifdef TESTING
|
||||
var/running_find_references
|
||||
var/last_find_references = 0
|
||||
@@ -201,3 +204,10 @@
|
||||
qdel(D)
|
||||
else
|
||||
return returned
|
||||
|
||||
|
||||
///Callback called by a timer to end an associative-list-indexed cooldown.
|
||||
/proc/end_cooldown(datum/source, index)
|
||||
if(QDELETED(source))
|
||||
return
|
||||
COOLDOWN_END(source, index)
|
||||
|
||||
@@ -186,9 +186,8 @@
|
||||
GLOBAL_LIST_EMPTY(employmentCabinets)
|
||||
|
||||
/obj/structure/filingcabinet/employment
|
||||
var/cooldown = 0
|
||||
icon_state = "employmentcabinet"
|
||||
var/virgin = 1
|
||||
var/virgin = TRUE
|
||||
|
||||
/obj/structure/filingcabinet/employment/Initialize()
|
||||
. = ..()
|
||||
@@ -213,13 +212,12 @@ GLOBAL_LIST_EMPTY(employmentCabinets)
|
||||
new /obj/item/paper/contract/employment(src, employee)
|
||||
|
||||
/obj/structure/filingcabinet/employment/interact(mob/user)
|
||||
if(!cooldown)
|
||||
if(virgin)
|
||||
fillCurrent()
|
||||
virgin = 0
|
||||
cooldown = 1
|
||||
sleep(100) // prevents the devil from just instantly emptying the cabinet, ensuring an easy win.
|
||||
cooldown = 0
|
||||
else
|
||||
if(COOLDOWN_CHECK(src, COOLDOWN_EMPLOYMENT_CABINET))
|
||||
to_chat(user, "<span class='warning'>[src] is jammed, give it a few seconds.</span>")
|
||||
..()
|
||||
return ..()
|
||||
|
||||
COOLDOWN_START(src, COOLDOWN_EMPLOYMENT_CABINET, 10 SECONDS) // prevents the devil from just instantly emptying the cabinet, ensuring an easy win.
|
||||
if(virgin)
|
||||
fillCurrent()
|
||||
virgin = FALSE
|
||||
return ..()
|
||||
|
||||
Reference in New Issue
Block a user