mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
453 lines
15 KiB
Plaintext
453 lines
15 KiB
Plaintext
/obj/machinery/mecha_part_fabricator
|
|
icon = 'icons/obj/robotics.dmi'
|
|
icon_state = "fab-idle"
|
|
name = "exosuit fabricator"
|
|
desc = "Nothing is being built."
|
|
density = TRUE
|
|
anchored = TRUE
|
|
use_power = IDLE_POWER_USE
|
|
idle_power_usage = 20
|
|
active_power_usage = 5000
|
|
req_access = list(ACCESS_ROBOTICS)
|
|
circuit = /obj/item/circuitboard/machine/mechfab
|
|
var/time_coeff = 1
|
|
var/component_coeff = 1
|
|
var/datum/research/files
|
|
var/sync = 0
|
|
var/part_set
|
|
var/datum/design/being_built
|
|
var/list/queue = list()
|
|
var/processing_queue = 0
|
|
var/screen = "main"
|
|
var/temp
|
|
var/list/part_sets = list(
|
|
"Cyborg",
|
|
"Ripley",
|
|
"Firefighter",
|
|
"Odysseus",
|
|
"Gygax",
|
|
"Durand",
|
|
"H.O.N.K",
|
|
"Phazon",
|
|
"Exosuit Equipment",
|
|
"Cyborg Upgrade Modules",
|
|
"Misc"
|
|
)
|
|
|
|
/obj/machinery/mecha_part_fabricator/Initialize()
|
|
var/datum/component/material_container/materials = AddComponent(/datum/component/material_container,
|
|
list(MAT_METAL, MAT_GLASS, MAT_SILVER, MAT_GOLD, MAT_DIAMOND, MAT_PLASMA, MAT_URANIUM, MAT_BANANIUM, MAT_TITANIUM, MAT_BLUESPACE),
|
|
FALSE, list(/obj/item/stack, /obj/item/ore/bluespace_crystal), CALLBACK(src, .proc/is_insertion_ready))
|
|
materials.precise_insertion = TRUE
|
|
. = ..()
|
|
files = new /datum/research(src) //Setup the research data holder.
|
|
|
|
/obj/machinery/mecha_part_fabricator/RefreshParts()
|
|
var/T = 0
|
|
|
|
//maximum stocking amount (default 300000, 600000 at T4)
|
|
for(var/obj/item/stock_parts/matter_bin/M in component_parts)
|
|
T += M.rating
|
|
GET_COMPONENT(materials, /datum/component/material_container)
|
|
materials.max_amount = (200000 + (T*50000))
|
|
|
|
//resources adjustment coefficient (1 -> 0.85 -> 0.7 -> 0.55)
|
|
T = 1.15
|
|
for(var/obj/item/stock_parts/micro_laser/Ma in component_parts)
|
|
T -= Ma.rating*0.15
|
|
component_coeff = T
|
|
|
|
//building time adjustment coefficient (1 -> 0.8 -> 0.6)
|
|
T = -1
|
|
for(var/obj/item/stock_parts/manipulator/Ml in component_parts)
|
|
T += Ml.rating
|
|
time_coeff = round(initial(time_coeff) - (initial(time_coeff)*(T))/5,0.01)
|
|
|
|
|
|
/obj/machinery/mecha_part_fabricator/check_access(obj/item/card/id/I)
|
|
if(istype(I, /obj/item/device/pda))
|
|
var/obj/item/device/pda/pda = I
|
|
I = pda.id
|
|
if(!istype(I) || !I.access) //not ID or no access
|
|
return 0
|
|
for(var/req in req_access)
|
|
if(!(req in I.access)) //doesn't have this access
|
|
return 0
|
|
return 1
|
|
|
|
/obj/machinery/mecha_part_fabricator/emag_act()
|
|
if(emagged)
|
|
return
|
|
emagged = TRUE
|
|
req_access = list()
|
|
say("DB error \[Code 0x00F1\]")
|
|
sleep(10)
|
|
say("Attempting auto-repair...")
|
|
sleep(15)
|
|
say("User DB corrupted \[Code 0x00FA\]. Truncating data structure...")
|
|
sleep(30)
|
|
say("User DB truncated. Please contact your Nanotrasen system operator for future assistance.")
|
|
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/output_parts_list(set_name)
|
|
var/output = ""
|
|
for(var/v in files.known_designs)
|
|
var/datum/design/D = files.known_designs[v]
|
|
if(D.build_type & MECHFAB)
|
|
if(!(set_name in D.category))
|
|
continue
|
|
output += "<div class='part'>[output_part_info(D)]<br>\["
|
|
if(check_resources(D))
|
|
output += "<a href='?src=[REF(src)];part=[D.id]'>Build</a> | "
|
|
output += "<a href='?src=[REF(src)];add_to_queue=[D.id]'>Add to queue</a>\]\[<a href='?src=[REF(src)];part_desc=[D.id]'>?</a>\]</div>"
|
|
return output
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/output_part_info(datum/design/D)
|
|
var/output = "[initial(D.name)] (Cost: [output_part_cost(D)]) [get_construction_time_w_coeff(D)/10]sec"
|
|
return output
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/output_part_cost(datum/design/D)
|
|
var/i = 0
|
|
var/output
|
|
for(var/c in D.materials)
|
|
output += "[i?" | ":null][get_resource_cost_w_coeff(D, c)] [material2name(c)]"
|
|
i++
|
|
return output
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/output_available_resources()
|
|
var/output
|
|
GET_COMPONENT(materials, /datum/component/material_container)
|
|
for(var/mat_id in materials.materials)
|
|
var/datum/material/M = materials.materials[mat_id]
|
|
output += "<span class=\"res_name\">[M.name]: </span>[M.amount] cm³"
|
|
if(M.amount >= MINERAL_MATERIAL_AMOUNT)
|
|
output += "<span style='font-size:80%;'>- Remove \[<a href='?src=[REF(src)];remove_mat=1;material=[mat_id]'>1</a>\]"
|
|
if(M.amount >= (MINERAL_MATERIAL_AMOUNT * 10))
|
|
output += " | \[<a href='?src=[REF(src)];remove_mat=10;material=[mat_id]'>10</a>\]"
|
|
output += " | \[<a href='?src=[REF(src)];remove_mat=50;material=[mat_id]'>All</a>\]</span>"
|
|
output += "<br/>"
|
|
return output
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/get_resources_w_coeff(datum/design/D)
|
|
var/list/resources = list()
|
|
for(var/R in D.materials)
|
|
resources[R] = get_resource_cost_w_coeff(D, R)
|
|
return resources
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/check_resources(datum/design/D)
|
|
if(D.reagents_list.len) // No reagents storage - no reagent designs.
|
|
return 0
|
|
GET_COMPONENT(materials, /datum/component/material_container)
|
|
if(materials.has_materials(get_resources_w_coeff(D)))
|
|
return 1
|
|
return 0
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/build_part(datum/design/D)
|
|
being_built = D
|
|
desc = "It's building \a [initial(D.name)]."
|
|
var/list/res_coef = get_resources_w_coeff(D)
|
|
|
|
GET_COMPONENT(materials, /datum/component/material_container)
|
|
materials.use_amount(res_coef)
|
|
add_overlay("fab-active")
|
|
use_power = ACTIVE_POWER_USE
|
|
updateUsrDialog()
|
|
sleep(get_construction_time_w_coeff(D))
|
|
use_power = IDLE_POWER_USE
|
|
cut_overlay("fab-active")
|
|
desc = initial(desc)
|
|
|
|
var/location = get_step(src,(dir))
|
|
var/obj/item/I = new D.build_path(location)
|
|
I.materials = res_coef
|
|
say("\The [I] is complete.")
|
|
being_built = null
|
|
|
|
updateUsrDialog()
|
|
return 1
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/update_queue_on_page()
|
|
send_byjax(usr,"mecha_fabricator.browser","queue",list_queue())
|
|
return
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/add_part_set_to_queue(set_name)
|
|
if(set_name in part_sets)
|
|
for(var/v in files.known_designs)
|
|
var/datum/design/D = files.known_designs[v]
|
|
if(D.build_type & MECHFAB)
|
|
if(set_name in D.category)
|
|
add_to_queue(D)
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/add_to_queue(D)
|
|
if(!istype(queue))
|
|
queue = list()
|
|
if(D)
|
|
queue[++queue.len] = D
|
|
return queue.len
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/remove_from_queue(index)
|
|
if(!isnum(index) || !IsInteger(index) || !istype(queue) || (index<1 || index>queue.len))
|
|
return 0
|
|
queue.Cut(index,++index)
|
|
return 1
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/process_queue()
|
|
var/datum/design/D = queue[1]
|
|
if(!D)
|
|
remove_from_queue(1)
|
|
if(queue.len)
|
|
return process_queue()
|
|
else
|
|
return
|
|
temp = null
|
|
while(D)
|
|
if(stat&(NOPOWER|BROKEN))
|
|
return 0
|
|
if(!check_resources(D))
|
|
say("Not enough resources. Queue processing stopped.")
|
|
temp = {"<span class='alert'>Not enough resources to build next part.</span><br>
|
|
<a href='?src=[REF(src)];process_queue=1'>Try again</a> | <a href='?src=[REF(src)];clear_temp=1'>Return</a><a>"}
|
|
return 0
|
|
remove_from_queue(1)
|
|
build_part(D)
|
|
D = listgetindex(queue, 1)
|
|
say("Queue processing finished successfully.")
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/list_queue()
|
|
var/output = "<b>Queue contains:</b>"
|
|
if(!istype(queue) || !queue.len)
|
|
output += "<br>Nothing"
|
|
else
|
|
output += "<ol>"
|
|
var/i = 0
|
|
for(var/datum/design/D in queue)
|
|
i++
|
|
var/obj/part = D.build_path
|
|
output += "<li[!check_resources(D)?" style='color: #f00;'":null]>"
|
|
output += initial(part.name) + " - "
|
|
output += "[i>1?"<a href='?src=[REF(src)];queue_move=-1;index=[i]' class='arrow'>↑</a>":null] "
|
|
output += "[i<queue.len?"<a href='?src=[REF(src)];queue_move=+1;index=[i]' class='arrow'>↓</a>":null] "
|
|
output += "<a href='?src=[REF(src)];remove_from_queue=[i]'>Remove</a></li>"
|
|
|
|
output += "</ol>"
|
|
output += "\[<a href='?src=[REF(src)];process_queue=1'>Process queue</a> | <a href='?src=[REF(src)];clear_queue=1'>Clear queue</a>\]"
|
|
return output
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/sync()
|
|
temp = "Updating local R&D database..."
|
|
updateUsrDialog()
|
|
sleep(30) //only sleep if called by user
|
|
|
|
for(var/obj/machinery/computer/rdconsole/RDC in oview(7,src))
|
|
if(!RDC.sync)
|
|
continue
|
|
for(var/v in RDC.files.known_tech)
|
|
var/datum/tech/T = RDC.files.known_tech[v]
|
|
files.AddTech2Known(T)
|
|
for(var/v in RDC.files.known_designs)
|
|
var/datum/design/D = RDC.files.known_designs[v]
|
|
files.AddDesign2Known(D)
|
|
files.RefreshResearch()
|
|
temp = "Processed equipment designs.<br>"
|
|
//check if the tech coefficients have changed
|
|
temp += "<a href='?src=[REF(src)];clear_temp=1'>Return</a>"
|
|
|
|
updateUsrDialog()
|
|
say("Successfully synchronized with R&D server.")
|
|
return
|
|
|
|
temp = "Unable to connect to local R&D Database.<br>Please check your connections and try again.<br><a href='?src=[REF(src)];clear_temp=1'>Return</a>"
|
|
updateUsrDialog()
|
|
return
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/get_resource_cost_w_coeff(datum/design/D, resource, roundto = 1)
|
|
return round(D.materials[resource]*component_coeff, roundto)
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/get_construction_time_w_coeff(datum/design/D, roundto = 1) //aran
|
|
return round(initial(D.construction_time)*time_coeff, roundto)
|
|
|
|
/obj/machinery/mecha_part_fabricator/attack_hand(mob/user)
|
|
if(!(..()))
|
|
return interact(user)
|
|
|
|
/obj/machinery/mecha_part_fabricator/interact(mob/user as mob)
|
|
var/dat, left_part
|
|
if (..())
|
|
return
|
|
user.set_machine(src)
|
|
var/turf/exit = get_step(src,(dir))
|
|
if(exit.density)
|
|
say("Error! Part outlet is obstructed.")
|
|
return
|
|
if(temp)
|
|
left_part = temp
|
|
else if(being_built)
|
|
var/obj/I = being_built.build_path
|
|
left_part = {"<TT>Building [initial(I.name)].<BR>
|
|
Please wait until completion...</TT>"}
|
|
else
|
|
switch(screen)
|
|
if("main")
|
|
left_part = output_available_resources()+"<hr>"
|
|
left_part += "<a href='?src=[REF(src)];sync=1'>Sync with R&D servers</a><hr>"
|
|
for(var/part_set in part_sets)
|
|
left_part += "<a href='?src=[REF(src)];part_set=[part_set]'>[part_set]</a> - \[<a href='?src=[REF(src)];partset_to_queue=[part_set]'>Add all parts to queue</a>\]<br>"
|
|
if("parts")
|
|
left_part += output_parts_list(part_set)
|
|
left_part += "<hr><a href='?src=[REF(src)];screen=main'>Return</a>"
|
|
dat = {"<html>
|
|
<head>
|
|
<title>[name]</title>
|
|
<style>
|
|
.res_name {font-weight: bold; text-transform: capitalize;}
|
|
.red {color: #f00;}
|
|
.part {margin-bottom: 10px;}
|
|
.arrow {text-decoration: none; font-size: 10px;}
|
|
body, table {height: 100%;}
|
|
td {vertical-align: top; padding: 5px;}
|
|
html, body {padding: 0px; margin: 0px;}
|
|
h1 {font-size: 18px; margin: 5px 0px;}
|
|
</style>
|
|
<script language='javascript' type='text/javascript'>
|
|
[js_byjax]
|
|
</script>
|
|
</head><body>
|
|
<body>
|
|
<table style='width: 100%;'>
|
|
<tr>
|
|
<td style='width: 65%; padding-right: 10px;'>
|
|
[left_part]
|
|
</td>
|
|
<td style='width: 35%; background: #ccc;' id='queue'>
|
|
[list_queue()]
|
|
</td>
|
|
<tr>
|
|
</table>
|
|
</body>
|
|
</html>"}
|
|
user << browse(dat, "window=mecha_fabricator;size=1000x430")
|
|
onclose(user, "mecha_fabricator")
|
|
return
|
|
|
|
/obj/machinery/mecha_part_fabricator/Topic(href, href_list)
|
|
if(..())
|
|
return
|
|
var/datum/topic_input/afilter = new /datum/topic_input(href,href_list)
|
|
if(href_list["part_set"])
|
|
var/tpart_set = afilter.getStr("part_set")
|
|
if(tpart_set)
|
|
if(tpart_set=="clear")
|
|
part_set = null
|
|
else
|
|
part_set = tpart_set
|
|
screen = "parts"
|
|
if(href_list["part"])
|
|
var/T = afilter.getStr("part")
|
|
for(var/v in files.known_designs)
|
|
var/datum/design/D = files.known_designs[v]
|
|
if(D.build_type & MECHFAB)
|
|
if(D.id == T)
|
|
if(!processing_queue)
|
|
build_part(D)
|
|
else
|
|
add_to_queue(D)
|
|
break
|
|
if(href_list["add_to_queue"])
|
|
var/T = afilter.getStr("add_to_queue")
|
|
for(var/v in files.known_designs)
|
|
var/datum/design/D = files.known_designs[v]
|
|
if(D.build_type & MECHFAB)
|
|
if(D.id == T)
|
|
add_to_queue(D)
|
|
break
|
|
return update_queue_on_page()
|
|
if(href_list["remove_from_queue"])
|
|
remove_from_queue(afilter.getNum("remove_from_queue"))
|
|
return update_queue_on_page()
|
|
if(href_list["partset_to_queue"])
|
|
add_part_set_to_queue(afilter.get("partset_to_queue"))
|
|
return update_queue_on_page()
|
|
if(href_list["process_queue"])
|
|
spawn(0)
|
|
if(processing_queue || being_built)
|
|
return 0
|
|
processing_queue = 1
|
|
process_queue()
|
|
processing_queue = 0
|
|
if(href_list["clear_temp"])
|
|
temp = null
|
|
if(href_list["screen"])
|
|
screen = href_list["screen"]
|
|
if(href_list["queue_move"] && href_list["index"])
|
|
var/index = afilter.getNum("index")
|
|
var/new_index = index + afilter.getNum("queue_move")
|
|
if(isnum(index) && isnum(new_index) && IsInteger(index) && IsInteger(new_index))
|
|
if(IsInRange(new_index,1,queue.len))
|
|
queue.Swap(index,new_index)
|
|
return update_queue_on_page()
|
|
if(href_list["clear_queue"])
|
|
queue = list()
|
|
return update_queue_on_page()
|
|
if(href_list["sync"])
|
|
sync()
|
|
if(href_list["part_desc"])
|
|
var/T = afilter.getStr("part_desc")
|
|
for(var/v in files.known_designs)
|
|
var/datum/design/D = files.known_designs[v]
|
|
if(D.build_type & MECHFAB)
|
|
if(D.id == T)
|
|
var/obj/part = D.build_path
|
|
temp = {"<h1>[initial(part.name)] description:</h1>
|
|
[initial(part.desc)]<br>
|
|
<a href='?src=[REF(src)];clear_temp=1'>Return</a>
|
|
"}
|
|
break
|
|
|
|
if(href_list["remove_mat"] && href_list["material"])
|
|
GET_COMPONENT(materials, /datum/component/material_container)
|
|
materials.retrieve_sheets(text2num(href_list["remove_mat"]), href_list["material"])
|
|
|
|
updateUsrDialog()
|
|
return
|
|
|
|
/obj/machinery/mecha_part_fabricator/on_deconstruction()
|
|
GET_COMPONENT(materials, /datum/component/material_container)
|
|
materials.retrieve_all()
|
|
..()
|
|
|
|
/obj/machinery/mecha_part_fabricator/ComponentActivated(datum/component/C)
|
|
..()
|
|
if(istype(C, /datum/component/material_container))
|
|
var/datum/component/material_container/M = C
|
|
if(!M.last_insert_success)
|
|
return
|
|
var/stack_name = material2name(M.last_inserted_id)
|
|
add_overlay("fab-load-[stack_name]")
|
|
addtimer(CALLBACK(src, /atom/proc/cut_overlay, "fab-load-[stack_name]"), 10)
|
|
updateUsrDialog()
|
|
|
|
/obj/machinery/mecha_part_fabricator/attackby(obj/item/W, mob/user, params)
|
|
if(default_deconstruction_screwdriver(user, "fab-o", "fab-idle", W))
|
|
return 1
|
|
|
|
if(exchange_parts(user, W))
|
|
return 1
|
|
|
|
if(default_deconstruction_crowbar(W))
|
|
return 1
|
|
|
|
return ..()
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/material2name(ID)
|
|
return copytext(ID,2)
|
|
|
|
/obj/machinery/mecha_part_fabricator/proc/is_insertion_ready(mob/user)
|
|
if(panel_open)
|
|
to_chat(user, "<span class='warning'>You can't load [src] while it's opened!</span>")
|
|
return FALSE
|
|
if(being_built)
|
|
to_chat(user, "<span class='warning'>\The [src] is currently processing! Please wait until completion.</span>")
|
|
return FALSE
|
|
|
|
return TRUE
|