Code rework of placing things on walls.

Stuff goes under types.
Types have procs.
Never have 500 lines of repeated code again.

I came very close to crying while editing this. You should appreciate
that.

----

This commit entirely reworks how placing things on walls work- Posters
have intentionally been left alone to reduce the amount of lines
changed. With this commit, wall-mounted objects are no longer snowflaked
into the wall file.
This commit is contained in:
ComicIronic
2015-04-19 14:29:42 -07:00
committed by Tigercat2000
parent 35664b8708
commit 44aa2ba225
20 changed files with 217 additions and 310 deletions
@@ -0,0 +1,16 @@
/*
AIR ALARM ITEM
Handheld air alarm frame, for placing on walls
Code shamelessly copied from apc_frame
*/
/obj/item/mounted/frame/alarm_frame
name = "air alarm frame"
desc = "Used for building Air Alarms"
icon = 'icons/obj/monitors.dmi'
icon_state = "alarm_bitem"
m_amt = 2000
mount_reqs = list("simfloor", "nospace")
/obj/item/mounted/frame/alarm_frame/do_build(turf/on_wall, mob/user)
new /obj/machinery/alarm(get_turf(src), get_dir(on_wall, user), 1)
qdel(src)
@@ -0,0 +1,29 @@
/obj/item/mounted/frame/apc_frame
name = "APC frame"
desc = "Used for repairing or building APCs"
icon = 'icons/obj/apc_repair.dmi'
icon_state = "apc_frame"
mount_reqs = list("simfloor", "nospace")
/obj/item/mounted/frame/apc_frame/try_build(turf/on_wall, mob/user)
if(..())
var/turf/turf_loc = get_turf(user)
var/area/area_loc = turf_loc.loc
if (area_loc.get_apc())
user << "<span class='rose'>This area already has an APC.</span>"
return //only one APC per area
for(var/obj/machinery/power/terminal/T in turf_loc)
if (T.master)
user << "<span class='rose'>There is another network terminal here.</span>"
return
else
var/obj/item/stack/cable_coil/C = new /obj/item/stack/cable_coil(turf_loc)
C.amount = 10
user << "You cut the cables and disassemble the unused power terminal."
qdel(T)
return 1
return
/obj/item/mounted/frame/apc_frame/do_build(turf/on_wall, mob/user)
new /obj/machinery/power/apc(get_turf(src), get_dir(user, on_wall), 1)
qdel(src)
@@ -0,0 +1,10 @@
/obj/item/mounted/frame/firealarm
name = "fire alarm frame"
desc = "Used for building Fire Alarms"
icon = 'icons/obj/monitors.dmi'
icon_state = "fire_bitem"
mount_reqs = list("simfloor", "nospace")
/obj/item/mounted/frame/firealarm/do_build(turf/on_wall, mob/user)
new /obj/machinery/firealarm(get_turf(src), get_dir(on_wall, user), 1)
qdel(src)
@@ -0,0 +1,25 @@
/obj/item/mounted/frame
name = "mountable frame"
desc = "Place it on a wall."
var/sheets_refunded = 2
var/list/mount_reqs = list() //can contain simfloor, nospace. Used in try_build to see if conditions are needed, then met
/obj/item/mounted/frame/attackby(obj/item/weapon/W, mob/user)
..()
if (istype(W, /obj/item/weapon/wrench) && sheets_refunded)
//new /obj/item/stack/sheet/metal( get_turf(src.loc), sheets_refunded )
var/obj/item/stack/sheet/metal/M = getFromPool(/obj/item/stack/sheet/metal, get_turf(src))
M.amount = sheets_refunded
qdel(src)
/obj/item/mounted/frame/try_build(turf/on_wall, mob/user)
if(..()) //if we pass the parent tests
var/turf/turf_loc = get_turf(user)
if (src.mount_reqs.Find("simfloor") && !istype(turf_loc, /turf/simulated/floor))
user << "<span class='rose'>[src] cannot be placed on this spot.</span>"
return
if (src.mount_reqs.Find("nospace") && (areaMaster.requires_power == 0 || areaMaster.name == "Space"))
user << "<span class='rose'>[src] cannot be placed in this area.</span>"
return
return 1
@@ -0,0 +1,39 @@
/obj/item/mounted/frame/light_fixture
name = "light fixture frame"
desc = "Used for building lights."
icon = 'icons/obj/lighting.dmi'
icon_state = "tube-construct-item"
var/fixture_type = "tube"
mount_reqs = list("simfloor")
/obj/item/mounted/frame/light_fixture/do_build(turf/on_wall, mob/user)
user << "You begin attaching [src] to \the [on_wall]."
playsound(get_turf(src), 'sound/machines/click.ogg', 75, 1)
var/constrdir = user.dir
var/constrloc = get_turf(user)
if (!do_after(user, 30))
return
var/obj/machinery/light_construct/newlight
switch(fixture_type)
if("bulb")
newlight = new /obj/machinery/light_construct/small(constrloc)
if("tube")
newlight = new /obj/machinery/light_construct(constrloc)
else
newlight = new /obj/machinery/light_construct/small(constrloc)
newlight.dir = constrdir
newlight.fingerprints = src.fingerprints
newlight.fingerprintshidden = src.fingerprintshidden
newlight.fingerprintslast = src.fingerprintslast
user.visible_message("[user] attaches \the [src] to \the [on_wall].", \
"You attach \the [src] to \the [on_wall].")
qdel(src)
/obj/item/mounted/frame/light_fixture/small
name = "small light fixture frame"
desc = "Used for building small lights."
icon = 'icons/obj/lighting.dmi'
icon_state = "bulb-construct-item"
fixture_type = "bulb"
sheets_refunded = 1
@@ -0,0 +1,34 @@
/obj/item/mounted
var/list/buildon_types = list(/turf/simulated/wall)
/obj/item/mounted/afterattack(var/atom/A, mob/user, proximity_flag)
var/found_type = 0
for(var/turf_type in src.buildon_types)
if(istype(A, turf_type))
found_type = 1
break
if(found_type)
if(try_build(A, user, proximity_flag))
return do_build(A, user)
else
..()
/obj/item/mounted/proc/try_build(turf/on_wall, mob/user, proximity_flag) //checks
if(!on_wall || !user)
return
if (proximity_flag != 1) //if we aren't next to the wall
return
if (!( get_dir(on_wall,user) in cardinal))
user << "<span class='rose'>You need to be standing next to a wall to place \the [src].</span>"
return
if(gotwallitem(get_turf(user), get_dir(on_wall,user)))
user << "<span class='rose'>There's already an item on this wall!</span>"
return
return 1
/obj/item/mounted/proc/do_build(turf/on_wall, mob/user) //the buildy bit after we pass the checks
return
@@ -0,0 +1,32 @@
/obj/item/mounted/frame/newscaster_frame
name = "newscaster frame"
desc = "Used to build newscasters, just secure to the wall."
icon_state = "newscaster"
item_state = "syringe_kit"
m_amt = 14000
g_amt = 8000
mount_reqs = list("simfloor", "nospace")
/obj/item/mounted/frame/newscaster_frame/try_build(turf/on_wall, mob/user)
if(..())
var/turf/loc = get_turf(usr)
var/area/A = loc.loc
if (!istype(loc, /turf/simulated/floor))
usr << "<span class='alert'>Newscaster cannot be placed on this spot.</span>"
return
if (A.requires_power == 0 || A.name == "Space")
usr << "<span class='alert'>Newscaster cannot be placed in this area.</span>"
return
for(var/obj/machinery/newscaster/T in loc)
usr << "<span class='alert'>There is another newscaster here.</span>"
return
return 1
return
/obj/item/mounted/frame/newscaster_frame/do_build(turf/on_wall, mob/user)
var/obj/machinery/newscaster/N = new /obj/machinery/newscaster(get_turf(src), get_dir(on_wall, user), 1)
N.pixel_y -= (loc.y - on_wall.y) * 32
N.pixel_x -= (loc.x - on_wall.x) * 32
qdel(src)