From b9a1195de719ec097adb658726e33b176047ed7a Mon Sep 17 00:00:00 2001 From: Chompstation Bot Date: Mon, 14 Jun 2021 17:35:25 +0000 Subject: [PATCH] [MIRROR] Make req_[one_]access lazy --- code/__defines/_lists.dm | 2 +- code/controllers/subsystems/supply.dm | 8 +++++++- code/game/jobs/access.dm | 29 +++++++++------------------ 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/code/__defines/_lists.dm b/code/__defines/_lists.dm index 247e9dfeb0..582c026f3c 100644 --- a/code/__defines/_lists.dm +++ b/code/__defines/_lists.dm @@ -39,7 +39,7 @@ #define LAZYACCESSASSOC(L, I, K) L ? L[I] ? L[I][K] ? L[I][K] : null : null : null // Null-safe L.Cut() -#define LAZYCLEARLIST(L) if(L) L.Cut() +#define LAZYCLEARLIST(L) if(L) { L.Cut(); L = null; } // Reads L or an empty list if L is not a list. Note: Does NOT assign, L may be an expression. #define SANITIZE_LIST(L) ( islist(L) ? L : list() ) diff --git a/code/controllers/subsystems/supply.dm b/code/controllers/subsystems/supply.dm index 90a37fa6f0..cd3c9c3db7 100644 --- a/code/controllers/subsystems/supply.dm +++ b/code/controllers/subsystems/supply.dm @@ -205,13 +205,19 @@ SUBSYSTEM_DEF(supply) else if(islist(SP.access) && SP.one_access) var/list/L = SP.access // access var is a plain var, we need a list A.req_one_access = L.Copy() +<<<<<<< HEAD if(A.req_access) //Chompstation Edit (TODO: Figure out why the fuck this works for others but not us) A.req_access.Cut() //Chompstation Edit A.req_access = null +||||||| parent of 8973063282... Merge pull request #10640 from VOREStation/upstream-merge-8122 + A.req_access = null +======= + LAZYCLEARLIST(A.req_access) +>>>>>>> 8973063282... Merge pull request #10640 from VOREStation/upstream-merge-8122 else if(islist(SP.access) && !SP.one_access) var/list/L = SP.access A.req_access = L.Copy() - A.req_one_access = null + LAZYCLEARLIST(A.req_one_access) else log_debug("Supply pack with invalid access restriction [SP.access] encountered!") diff --git a/code/game/jobs/access.dm b/code/game/jobs/access.dm index 1539fb5227..abf3b5712c 100644 --- a/code/game/jobs/access.dm +++ b/code/game/jobs/access.dm @@ -28,32 +28,21 @@ return has_access(req_access, req_one_access, L) /proc/has_access(var/list/req_access, var/list/req_one_access, var/list/accesses) - // Doesn't have access lists, always works - if(!LAZYLEN(req_access) && !LAZYLEN(req_one_access)) - return TRUE - - // Didn't pass anything to compare - if(!LAZYLEN(accesses)) - return FALSE - // req_access list has priority if set // Requires at least every access in list - if(LAZYLEN(req_access)) - for(var/req in req_access) - if(!(req in accesses)) - return FALSE - // Wasn't missing any accesses - return TRUE + for(var/req in req_access) + if(!(req in accesses)) + return FALSE // req_one_access is secondary if set // Requires at least one access in list - for(var/req in req_one_access) - if(req in accesses) - // Found at least one - return TRUE + if(LAZYLEN(req_one_access)) + for(var/req in req_one_access) + if(req in accesses) + return TRUE + return FALSE - // Didn't find anything that matched - return FALSE + return TRUE /proc/get_centcom_access(job) switch(job)