Merge pull request #8122 from VOREStation/Arokha/access

Make req_[one_]access lazy
This commit is contained in:
Atermonera
2021-06-14 00:22:04 -07:00
committed by GitHub
12 changed files with 56 additions and 62 deletions
+1 -1
View File
@@ -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() )
+2 -1
View File
@@ -200,10 +200,11 @@ 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()
A.req_access.Cut()
LAZYCLEARLIST(A.req_access)
else if(islist(SP.access) && !SP.one_access)
var/list/L = SP.access
A.req_access = L.Copy()
LAZYCLEARLIST(A.req_one_access)
else
log_debug("<span class='danger'>Supply pack with invalid access restriction [SP.access] encountered!</span>")
+1 -1
View File
@@ -102,7 +102,7 @@ datum/hSB
var/accesses = get_all_accesses()
for(var/A in accesses)
if(alert(usr, "Will this airlock require [get_access_desc(A)] access?", "Sandbox:", "Yes", "No") == "Yes")
hsb.req_access += A
LAZYADD(hsb.req_access, A)
hsb.loc = usr.loc
to_chat(usr, "<b>Sandbox: Created an airlock.</b>")
+26 -27
View File
@@ -1,21 +1,9 @@
//This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31
/obj/var/list/req_access = list()
/obj/var/list/req_one_access = list()
/obj/var/list/req_access
/obj/var/list/req_one_access
//returns 1 if this mob has sufficient access to use this object
/obj/proc/allowed(mob/M)
//check if it doesn't require any access at all
if(src.check_access(null))
return 1
var/id = M.GetIdCard()
if(id)
return check_access(id)
return 0
///obj/item/proc/GetAccess()
// return list()
return check_access(M?.GetIdCard())
/atom/movable/proc/GetAccess()
var/obj/item/weapon/card/id/id = GetIdCard()
@@ -25,25 +13,36 @@
return null
/obj/proc/check_access(obj/item/I)
return check_access_list(I ? I.GetAccess() : list())
return check_access_list(I ? I.GetAccess() : null)
/obj/proc/check_access_list(var/list/L)
if(!req_access) req_access = list()
if(!req_one_access) req_one_access = list()
if(!L) return 0
if(!istype(L, /list)) return 0
// We don't require access
if(!LAZYLEN(req_access) && !LAZYLEN(req_one_access))
return TRUE
// They passed nothing, but we are something that requires access
if(!LAZYLEN(L))
return FALSE
// Run list comparisons
return has_access(req_access, req_one_access, L)
/proc/has_access(var/list/req_access, var/list/req_one_access, var/list/accesses)
// req_access list has priority if set
// Requires at least every access in list
for(var/req in req_access)
if(!(req in accesses)) //doesn't have this access
return 0
if(req_one_access.len)
if(!(req in accesses))
return FALSE
// req_one_access is secondary if set
// Requires at least one access in list
if(LAZYLEN(req_one_access))
for(var/req in req_one_access)
if(req in accesses) //has an access from the single access list
return 1
return 0
return 1
if(req in accesses)
return TRUE
return FALSE
return TRUE
/proc/get_centcom_access(job)
switch(job)
+2 -2
View File
@@ -130,8 +130,8 @@ Deployable items
/obj/machinery/deployable/barrier/emag_act(var/remaining_charges, var/mob/user)
if(emagged == 0)
emagged = 1
req_access.Cut()
req_one_access.Cut()
LAZYCLEARLIST(req_access)
LAZYCLEARLIST(req_one_access)
to_chat(user, "You break the ID authentication lock on \the [src].")
var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread
s.set_up(2, 1, src)
+3 -3
View File
@@ -28,9 +28,9 @@
return attack_hand(user)
/obj/machinery/button/remote/emag_act(var/remaining_charges, var/mob/user)
if(req_access.len || req_one_access.len)
req_access = list()
req_one_access = list()
if(LAZYLEN(req_access) || LAZYLEN(req_one_access))
LAZYCLEARLIST(req_access)
LAZYCLEARLIST(req_one_access)
playsound(src, "sparks", 100, 1)
return 1
+6 -8
View File
@@ -1388,10 +1388,10 @@ About the new airlock wires panel:
//update the door's access to match the electronics'
secured_wires = electronics.secure
if(electronics.one_access)
req_access.Cut()
LAZYCLEARLIST(req_access)
req_one_access = src.electronics.conf_access
else
req_one_access.Cut()
LAZYCLEARLIST(req_one_access)
req_access = src.electronics.conf_access
//get the name from the assembly
@@ -1437,12 +1437,10 @@ About the new airlock wires panel:
src.electronics = new/obj/item/weapon/airlock_electronics( src.loc )
//update the electronics to match the door's access
if(!src.req_access)
src.check_access()
if(src.req_access.len)
electronics.conf_access = src.req_access
else if (src.req_one_access.len)
electronics.conf_access = src.req_one_access
if(LAZYLEN(req_access))
electronics.conf_access = req_access
else if (LAZYLEN(req_one_access))
electronics.conf_access = req_one_access
electronics.one_access = 1
/obj/machinery/door/airlock/emp_act(var/severity)
+9 -13
View File
@@ -20,7 +20,7 @@
/obj/machinery/door/window/New()
..()
update_nearby_tiles()
if (src.req_access && src.req_access.len)
if(LAZYLEN(req_access))
src.icon_state = "[src.icon_state]"
src.base_state = src.icon_state
return
@@ -38,12 +38,10 @@
var/obj/item/weapon/airlock_electronics/ae
if(!electronics)
ae = new/obj/item/weapon/airlock_electronics( src.loc )
if(!src.req_access)
src.check_access()
if(src.req_access.len)
ae.conf_access = src.req_access
else if (src.req_one_access.len)
ae.conf_access = src.req_one_access
if(LAZYLEN(req_access))
ae.conf_access = req_access
else if (LAZYLEN(req_one_access))
ae.conf_access = req_one_access
ae.one_access = 1
else
ae = electronics
@@ -241,12 +239,10 @@
else
if(!electronics)
wa.electronics = new/obj/item/weapon/airlock_electronics()
if(!src.req_access)
src.check_access()
if(src.req_access.len)
wa.electronics.conf_access = src.req_access
else if (src.req_one_access.len)
wa.electronics.conf_access = src.req_one_access
if(LAZYLEN(req_access))
wa.electronics.conf_access = req_access
else if (LAZYLEN(req_one_access))
wa.electronics.conf_access = req_one_access
wa.electronics.one_access = 1
else
wa.electronics = electronics
+1 -1
View File
@@ -119,7 +119,7 @@
item_state = icon_state
wires = new(src)
if((!req_access || !req_access.len) && (!req_one_access || !req_one_access.len))
if(!LAZYLEN(req_access) && !LAZYLEN(req_one_access))
locked = 0
spark_system = new()
@@ -17,7 +17,7 @@
to_chat(user, "<span class='danger'>It looks like the locking system has been shorted out.</span>")
return
if((!req_access || !req_access.len) && (!req_one_access || !req_one_access.len))
if(!LAZYLEN(req_access) && !LAZYLEN(req_one_access))
locked = 0
to_chat(user, "<span class='danger'>\The [src] doesn't seem to have a locking mechanism.</span>")
return
@@ -190,8 +190,8 @@
/obj/item/weapon/rig/emag_act(var/remaining_charges, var/mob/user)
if(!subverted)
req_access.Cut()
req_one_access.Cut()
LAZYCLEARLIST(req_access)
LAZYCLEARLIST(req_one_access)
locked = 0
subverted = 1
to_chat(user, "<span class='danger'>You short out the access protocol for the suit.</span>")
+1 -1
View File
@@ -190,7 +190,7 @@
// Check for required access.
var/obj/item/weapon/card/id/current_id = M.wear_id
if(citem.req_access && citem.req_access > 0)
if(citem.req_access && citem.req_access > 0) // These are numbers, not lists
if(!(istype(current_id) && (citem.req_access in current_id.access)))
log_debug("Custom Item: [key_name(M)] Does not have required access.")
continue
+1 -1
View File
@@ -523,7 +523,7 @@
if(lockdown)
to_chat(user, "<span class='notice'>\The [src]'s control panel thunks, as its cover retracts.</span>")
lockdown = 0
if(req_access || req_one_access)
if(LAZYLEN(req_access) || LAZYLEN(req_one_access))
req_access = list()
req_one_access = list()
to_chat(user, "<span class='warning'>\The [src]'s access mechanism shorts out.</span>")