From 4544637b48c7e6cbc3418ecc09a6dcc6f8e9996f Mon Sep 17 00:00:00 2001 From: Lohikar Date: Wed, 9 Aug 2017 11:56:45 -0500 Subject: [PATCH] Make wall object check saner & compile-time-checked (#3252) Makes /proc/gotwallitem use typecaches & a compile-time checked list of types instead of a list of strings. Probably faster, not that it really matters here. --- code/_helpers/unsorted.dm | 78 ++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/code/_helpers/unsorted.dm b/code/_helpers/unsorted.dm index d8b3176b969..bbf5565c152 100644 --- a/code/_helpers/unsorted.dm +++ b/code/_helpers/unsorted.dm @@ -969,45 +969,57 @@ proc/is_hot(obj/item/W as obj) /* Checks if that loc and dir has a item on the wall */ -var/list/WALLITEMS = list( - "/obj/machinery/power/apc", "/obj/machinery/alarm", "/obj/item/device/radio/intercom", - "/obj/structure/extinguisher_cabinet", "/obj/structure/reagent_dispensers/peppertank", - "/obj/machinery/status_display", "/obj/machinery/requests_console", "/obj/machinery/light_switch", "/obj/effect/sign", - "/obj/machinery/newscaster", "/obj/machinery/firealarm", "/obj/structure/noticeboard", "/obj/machinery/door_control", - "/obj/machinery/computer/security/telescreen", "/obj/machinery/embedded_controller/radio/simple_vent_controller", - "/obj/item/weapon/storage/secure/safe", "/obj/machinery/door_timer", "/obj/machinery/flasher", "/obj/machinery/keycard_auth", - "/obj/structure/mirror", "/obj/structure/closet/fireaxecabinet", "/obj/machinery/computer/security/telescreen/entertainment" - ) +var/list/wall_items = typecacheof(list( + /obj/machinery/power/apc, + /obj/machinery/alarm, + /obj/item/device/radio/intercom, + /obj/structure/extinguisher_cabinet, + /obj/structure/reagent_dispensers/peppertank, + /obj/machinery/status_display, + /obj/machinery/requests_console, + /obj/machinery/light_switch, + /obj/machinery/newscaster, + /obj/machinery/firealarm, + /obj/structure/noticeboard, + /obj/machinery/computer/security/telescreen, + /obj/machinery/embedded_controller/radio/airlock, + /obj/item/weapon/storage/secure/safe, + /obj/machinery/door_timer, + /obj/machinery/flasher, + /obj/machinery/keycard_auth, + /obj/structure/mirror, + /obj/structure/fireaxecabinet, + /obj/machinery/computer/security/telescreen/entertainment, + /obj/machinery/station_map, + /obj/structure/sign +)) + /proc/gotwallitem(loc, dir) for(var/obj/O in loc) - for(var/item in WALLITEMS) - if(istype(O, text2path(item))) - //Direction works sometimes - if(O.dir == dir) - return 1 - - //Some stuff doesn't use dir properly, so we need to check pixel instead - switch(dir) - if(SOUTH) - if(O.pixel_y > 10) - return 1 - if(NORTH) - if(O.pixel_y < -10) - return 1 - if(WEST) - if(O.pixel_x > 10) - return 1 - if(EAST) - if(O.pixel_x < -10) - return 1 + if (is_type_in_typecache(O, global.wall_items)) + //Direction works sometimes + if(O.dir == dir) + return 1 + //Some stuff doesn't use dir properly, so we need to check pixel instead + switch(dir) + if(SOUTH) + if(O.pixel_y > 10) + return 1 + if(NORTH) + if(O.pixel_y < -10) + return 1 + if(WEST) + if(O.pixel_x > 10) + return 1 + if(EAST) + if(O.pixel_x < -10) + return 1 //Some stuff is placed directly on the wallturf (signs) for(var/obj/O in get_step(loc, dir)) - for(var/item in WALLITEMS) - if(istype(O, text2path(item))) - if(O.pixel_x == 0 && O.pixel_y == 0) - return 1 + if (is_type_in_typecache(O, global.wall_items) && O.pixel_x == 0 && O.pixel_y == 0) + return 1 return 0 /proc/format_text(text)