Modernize the automatic pipe layer

* Upgrades the automatic pipe layer to modernize its code a bit towards latest standards and fixing various bugs.
* Make it constructable so it can acutally be used by someone!
This commit is contained in:
Leshana
2017-03-30 17:56:15 -04:00
parent 9a9849d56c
commit ab4c63791a
4 changed files with 99 additions and 42 deletions

View File

@@ -74,6 +74,10 @@
name = "request console electronics"
path =/obj/item/weapon/circuitboard/request
/datum/category_item/autolathe/engineering/pipelayer
name = "pipe layer electronics"
path =/obj/item/weapon/circuitboard/pipelayer
/datum/category_item/autolathe/engineering/motor
name = "motor"
path =/obj/item/weapon/stock_parts/motor

View File

@@ -1,57 +1,101 @@
/obj/machinery/pipelayer
name = "automatic pipe layer"
icon = 'icons/obj/stationobjs.dmi'
icon_state = "pipe_d"
density = 1
var/turf/old_turf
var/old_dir
var/on = 0
var/a_dis = 0
var/P_type = 0
var/P_type_t = ""
var/max_metal = 50
var/metal = 10
var/obj/item/weapon/wrench/W
circuit = /obj/item/weapon/circuitboard/pipelayer
var/turf/old_turf // Last turf we were on.
var/old_dir // Last direction we were facing.
var/on = 0 // Pipelaying online?
var/a_dis = 0 // Auto-dismantling - If enabled it will remove floor tiles
var/P_type = 0 // Currently selected pipe type
var/P_type_t = "" // Name of currently selected pipe type
var/max_metal = 50 // Max capacity for internal metal storage
var/metal = 10 // Current amount in internal metal storage
var/pipe_cost = 0.25 // Cost in steel for each pipe.
var/obj/item/weapon/wrench/W // Internal wrench used for wrenching down the pipes
var/list/Pipes = list("regular pipes"=0,"scrubbers pipes"=31,"supply pipes"=29,"heat exchange pipes"=2)
/obj/machinery/pipelayer/New()
W = new(src)
..()
default_apply_parts()
update_icon()
/obj/machinery/pipelayer/Destroy()
qdel(W)
W = null
..()
/obj/machinery/pipelayer/RefreshParts()
var/mb_rating = 0
for(var/obj/item/weapon/stock_parts/matter_bin/M in component_parts)
mb_rating += M.rating
max_metal = mb_rating * initial(max_metal)
/obj/machinery/pipelayer/dismantle()
eject_metal()
..()
// Whenever we move, if enabled try and lay pipe
/obj/machinery/pipelayer/Move(new_turf,M_Dir)
..()
if(on && a_dis)
dismantleFloor(old_turf)
layPipe(old_turf,M_Dir,old_dir)
layPipe(old_turf, M_Dir, old_dir)
old_turf = new_turf
old_dir = turn(M_Dir,180)
old_dir = turn(M_Dir, 180)
/obj/machinery/pipelayer/attack_hand(mob/user as mob)
if(!metal&&!on)
if(..())
return
if(panel_open)
if(metal < 1)
user << "\The [src] is empty."
return
var/answer = alert(user, "Do you want to eject all the metal in \the [src]?", , "Yes","No")
if(answer == "Yes")
var/amount_ejected = eject_metal()
user.visible_message("<span class='notice'>[user] removes [amount_ejected] sheet\s of [DEFAULT_WALL_MATERIAL] from the \the [src].</span>",
"<span class='notice'>You remove [amount_ejected] sheet\s of [DEFAULT_WALL_MATERIAL] from \the [src].</span>")
return
if(!metal && !on)
user << "<span class='warning'>\The [src] doesn't work without metal.</span>"
return
on=!on
on = !on
old_turf = get_turf(src)
old_dir = dir
user.visible_message("<span class='notice'>[user] has [!on?"de":""]activated \the [src].</span>", "<span class='notice'>You [!on?"de":""]activate \the [src].</span>")
return
/obj/machinery/pipelayer/attackby(var/obj/item/W as obj, var/mob/user as mob)
if (istype(W, /obj/item/weapon/wrench))
if(default_deconstruction_screwdriver(user, W))
return
if(default_deconstruction_crowbar(user, W))
return
if(default_part_replacement(user, W))
return
if (!panel_open && iswrench(W))
P_type_t = input("Choose pipe type", "Pipe type") as null|anything in Pipes
P_type = Pipes[P_type_t]
user.visible_message("<span class='notice'>[user] has set \the [src] to manufacture [P_type_t].</span>", "<span class='notice'>You set \the [src] to manufacture [P_type_t].</span>")
return
if(istype(W, /obj/item/weapon/crowbar))
a_dis=!a_dis
if(!panel_open && iscrowbar(W))
a_dis = !a_dis
user.visible_message("<span class='notice'>[user] has [!a_dis?"de":""]activated auto-dismantling.</span>", "<span class='notice'>You [!a_dis?"de":""]activate auto-dismantling.</span>")
return
if(istype(W, /obj/item/pipe))
if(metal + pipe_cost > max_metal)
user << "<span class='notice'>\The [src] is full.</span>"
else
user.drop_from_inventory(W)
metal += pipe_cost
usr << "<span class='notice'>You recycle \the [W].</span>"
qdel(W)
return
if(istype(W, /obj/item/stack/material) && W.get_material_name() == DEFAULT_WALL_MATERIAL)
var/result = load_metal(W)
if(isnull(result))
user << "<span class='warning'>Unable to load [W] - no metal found.</span>"
@@ -59,23 +103,8 @@
user << "<span class='notice'>\The [src] is full.</span>"
else
user.visible_message("<span class='notice'>[user] has loaded metal into \the [src].</span>", "<span class='notice'>You load metal into \the [src]</span>")
return
if(istype(W, /obj/item/weapon/screwdriver))
if(metal)
var/m = round(input(usr,"Please specify the amount of metal to remove","Remove metal",min(round(metal),50)) as num, 1)
m = min(m, 50)
m = min(m, round(metal))
m = round(m)
if(m)
use_metal(m)
var/obj/item/stack/material/steel/MM = new (get_turf(src))
MM.amount = m
user.visible_message("<span class='notice'>[user] removes [m] sheet\s of metal from the \the [src].</span>", "<span class='notice'>You remove [m] sheet\s of metal from \the [src]</span>")
else
user << "\The [src] is empty."
return
..()
/obj/machinery/pipelayer/examine(mob/user)
@@ -83,7 +112,7 @@
user << "\The [src] has [metal] sheet\s, is set to produce [P_type_t], and auto-dismantling is [!a_dis?"de":""]activated."
/obj/machinery/pipelayer/proc/reset()
on=0
on = 0
return
/obj/machinery/pipelayer/proc/load_metal(var/obj/item/stack/MM)
@@ -100,12 +129,22 @@
return
/obj/machinery/pipelayer/proc/use_metal(amount)
if(!metal || metal<amount)
if(!metal || metal < amount)
visible_message("\The [src] deactivates as its metal source depletes.")
return
metal-=amount
metal -= amount
return 1
/obj/machinery/pipelayer/proc/eject_metal()
var/amount_ejected = 0
while (metal >= 1)
var/material/M = get_material_by_name(DEFAULT_WALL_MATERIAL)
var/obj/item/stack/material/S = new M.stack_type(get_turf(src))
S.amount = min(metal, S.max_amount)
metal -= S.amount
amount_ejected += S.amount
return amount_ejected
/obj/machinery/pipelayer/proc/dismantleFloor(var/turf/new_turf)
if(istype(new_turf, /turf/simulated/floor))
var/turf/simulated/floor/T = new_turf
@@ -114,11 +153,11 @@
return new_turf.is_plating()
/obj/machinery/pipelayer/proc/layPipe(var/turf/w_turf,var/M_Dir,var/old_dir)
if(!on || !(M_Dir in list(1, 2, 4, 8)) || M_Dir==old_dir)
if(!on || !(M_Dir in list(NORTH, SOUTH, EAST, WEST)) || M_Dir==old_dir)
return reset()
if(!use_metal(0.25))
if(!use_metal(pipe_cost))
return reset()
var/fdirn = turn(M_Dir,180)
var/fdirn = turn(M_Dir, 180)
var/p_type
var/p_dir

View File

@@ -0,0 +1,13 @@
#ifndef T_BOARD
#error T_BOARD macro is not defined but we need it!
#endif
/obj/item/weapon/circuitboard/pipelayer
name = T_BOARD("pipe layer")
build_path = /obj/machinery/pipelayer
board_type = new /datum/frame/frame_types/machine
matter = list(DEFAULT_WALL_MATERIAL = 50, "glass" = 50)
req_components = list(
/obj/item/weapon/stock_parts/motor = 1,
/obj/item/weapon/stock_parts/gear = 1,
/obj/item/weapon/stock_parts/matter_bin = 1)

View File

@@ -862,6 +862,7 @@
#include "code\game\objects\items\weapons\circuitboards\computer\telecomms.dm"
#include "code\game\objects\items\weapons\circuitboards\machinery\biogenerator.dm"
#include "code\game\objects\items\weapons\circuitboards\machinery\cloning.dm"
#include "code\game\objects\items\weapons\circuitboards\machinery\engineering.dm"
#include "code\game\objects\items\weapons\circuitboards\machinery\jukebox.dm"
#include "code\game\objects\items\weapons\circuitboards\machinery\mech_recharger.dm"
#include "code\game\objects\items\weapons\circuitboards\machinery\mining_drill.dm"