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.
This commit is contained in:
Lohikar
2017-08-09 19:56:45 +03:00
committed by Erki
parent f9076f48f2
commit 4544637b48
+45 -33
View File
@@ -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)