#define AUTOLATHE_MAIN_MENU 1 #define AUTOLATHE_CATEGORY_MENU 2 #define AUTOLATHE_SEARCH_MENU 3 /obj/machinery/autolathe name = "autolathe" desc = "It produces items using metal and glass." icon_state = "autolathe" density = TRUE anchored = TRUE use_power = IDLE_POWER_USE idle_power_usage = 10 active_power_usage = 100 circuit = /obj/item/circuitboard/machine/autolathe var/operating = FALSE var/list/L = list() var/list/LL = list() var/hacked = FALSE var/disabled = 0 var/shocked = FALSE var/hack_wire var/disable_wire var/shock_wire var/busy = FALSE var/prod_coeff = 1 var/datum/design/being_built var/datum/techweb/stored_research var/list/datum/design/matching_designs var/selected_category var/screen = 1 var/list/categories = list( "Tools", "Electronics", "Construction", "T-Comm", "Security", "Machinery", "Medical", "Misc", "Dinnerware", "Imported" ) /obj/machinery/autolathe/Initialize() AddComponent(/datum/component/material_container, list(MAT_METAL, MAT_GLASS), 0, FALSE, null, null, CALLBACK(src, .proc/AfterMaterialInsert)) . = ..() wires = new /datum/wires/autolathe(src) stored_research = new /datum/techweb/specialized/autounlocking/autolathe matching_designs = list() /obj/machinery/autolathe/Destroy() QDEL_NULL(wires) return ..() /obj/machinery/autolathe/interact(mob/user) if(!is_operational()) return if(shocked && !(stat & NOPOWER)) shock(user,50) var/dat switch(screen) if(AUTOLATHE_MAIN_MENU) dat = main_win(user) if(AUTOLATHE_CATEGORY_MENU) dat = category_win(user,selected_category) if(AUTOLATHE_SEARCH_MENU) dat = search_win(user) var/datum/browser/popup = new(user, "autolathe", name, 400, 500) popup.set_content(dat) popup.open() /obj/machinery/autolathe/on_deconstruction() GET_COMPONENT(materials, /datum/component/material_container) materials.retrieve_all() /obj/machinery/autolathe/attackby(obj/item/O, mob/user, params) if (busy) to_chat(user, "The autolathe is busy. Please wait for completion of previous operation.") return TRUE if(default_deconstruction_screwdriver(user, "autolathe_t", "autolathe", O)) updateUsrDialog() return TRUE if(exchange_parts(user, O)) return TRUE if(default_deconstruction_crowbar(O)) return TRUE if(panel_open && is_wire_tool(O)) wires.interact(user) return TRUE if(user.a_intent == INTENT_HARM) //so we can hit the machine return ..() if(stat) return TRUE if(istype(O, /obj/item/disk/design_disk)) user.visible_message("[user] begins to load \the [O] in \the [src]...", "You begin to load a design from \the [O]...", "You hear the chatter of a floppy drive.") busy = TRUE var/obj/item/disk/design_disk/D = O if(do_after(user, 14.4, target = src)) for(var/B in D.blueprints) if(B) stored_research.add_design(B) busy = FALSE return TRUE return ..() /obj/machinery/autolathe/proc/AfterMaterialInsert(type_inserted, id_inserted, amount_inserted) if(ispath(type_inserted, /obj/item/stack/ore/bluespace_crystal)) use_power(MINERAL_MATERIAL_AMOUNT / 10) else switch(id_inserted) if (MAT_METAL) flick("autolathe_o",src)//plays metal insertion animation if (MAT_GLASS) flick("autolathe_r",src)//plays glass insertion animation use_power(min(1000, amount_inserted / 100)) updateUsrDialog() /obj/machinery/autolathe/Topic(href, href_list) if(..()) return if (!busy) if(href_list["menu"]) screen = text2num(href_list["menu"]) updateUsrDialog() if(href_list["category"]) selected_category = href_list["category"] updateUsrDialog() if(href_list["make"]) ///////////////// //href protection being_built = stored_research.isDesignResearchedID(href_list["make"]) if(!being_built) return var/multiplier = text2num(href_list["multiplier"]) var/is_stack = ispath(being_built.build_path, /obj/item/stack) ///////////////// var/coeff = (is_stack ? 1 : prod_coeff) //stacks are unaffected by production coefficient var/metal_cost = being_built.materials[MAT_METAL] var/glass_cost = being_built.materials[MAT_GLASS] var/power = max(2000, (metal_cost+glass_cost)*multiplier/5) GET_COMPONENT(materials, /datum/component/material_container) if((materials.amount(MAT_METAL) >= metal_cost*multiplier*coeff) && (materials.amount(MAT_GLASS) >= glass_cost*multiplier*coeff)) busy = TRUE use_power(power) icon_state = "autolathe_n" var/time = is_stack ? 32 : 32*coeff*multiplier addtimer(CALLBACK(src, .proc/make_item, power, metal_cost, glass_cost, multiplier, coeff, is_stack), time) if(href_list["search"]) matching_designs.Cut() for(var/v in stored_research.researched_designs) var/datum/design/D = stored_research.researched_designs[v] if(findtext(D.name,href_list["to_search"])) matching_designs.Add(D) updateUsrDialog() else to_chat(usr, "The autolathe is busy. Please wait for completion of previous operation.") updateUsrDialog() return /obj/machinery/autolathe/proc/make_item(power, metal_cost, glass_cost, multiplier, coeff, is_stack) GET_COMPONENT(materials, /datum/component/material_container) var/atom/A = drop_location() use_power(power) var/list/materials_used = list(MAT_METAL=metal_cost*coeff*multiplier, MAT_GLASS=glass_cost*coeff*multiplier) materials.use_amount(materials_used) if(is_stack) var/obj/item/stack/N = new being_built.build_path(A, multiplier) N.update_icon() N.autolathe_crafted(src) else for(var/i=1, i<=multiplier, i++) var/obj/item/new_item = new being_built.build_path(A) for(var/mat in materials_used) new_item.materials[mat] = materials_used[mat] / multiplier new_item.autolathe_crafted(src) icon_state = "autolathe" busy = FALSE updateDialog() /obj/machinery/autolathe/RefreshParts() var/T = 0 for(var/obj/item/stock_parts/matter_bin/MB in component_parts) T += MB.rating*75000 GET_COMPONENT(materials, /datum/component/material_container) materials.max_amount = T T=1.2 for(var/obj/item/stock_parts/manipulator/M in component_parts) T -= M.rating*0.2 prod_coeff = min(1,max(0,T)) // Coeff going 1 -> 0,8 -> 0,6 -> 0,4 /obj/machinery/autolathe/proc/main_win(mob/user) var/dat = "
| [C] | " line_length++ dat += "