// Overhauled the generator to incorporate APC.cell charging. // It used to in the past, but that feature was reverted for reasons unknown. // However, it's not a C&P job of the old code (Convair880). /obj/machinery/power/lgenerator name = "Experimental Local Generator" desc = "This machine generates power through the combustion of plasma, charging either the local APC or an inserted power cell." icon_state = "ggenoff" anchored = 0 density = 1 //layer = FLOOR_EQUIP_LAYER1 //why was this set to this mats = 10 deconstruct_flags = DECON_SCREWDRIVER | DECON_WRENCH | DECON_WELDER | DECON_MULTITOOL var/mode = 1 // 1 = charge APC, 2 = charge inserted power cell. var/active = 0 // If either of these values aren't competitive, nobody will bother with the generator. // Remember, there's quite a bit of hassle involved when buying (i.e. QM) and using one of these. // And you can't even fully recharge a 15000 cell with these parameters and stock plasma tank. var/CL_charge_rate = 100 // Units per tick. Comparison: ~20 (APC), 250 (regular cell charger). var/P_drain_rate = 0.08 // Per tick. Stock (304 kPa) tank will last about 6 min when charging non-stop. var/obj/item/cell/CL = null var/obj/item/tank/P = null var/obj/machinery/power/apc/our_APC = null // Linked APC if mode == 1. var/last_APC_check = 1 // In relation to world time. Ideally, we don't want to run this every tick. var/datum/light/light New() ..() light = new /datum/light/point light.attach(src) light.set_brightness(0.8) attackby(obj/item/W, mob/user) if (istype(W, /obj/item/tank/)) if (src.P) user.show_text("There appears to be a tank loaded already.", "red") return if (src.check_tank(W) == 0) user.show_text("The tank doesn't contain any plasma.", "red") return src.visible_message("[user] loads [W] into the [src].") user.u_equip(W) W.set_loc(src) src.P = W else if (istype(W, /obj/item/cell)) if (src.CL) user.show_text("There appears to be a power cell inserted already.", "red") return src.visible_message("[user] loads [W] into the [src].") user.u_equip(W) W.set_loc(src) src.CL = W else ..() if (user.machine == src) src.updateUsrDialog() return proc/update_icon() if (src.active) src.icon_state = "ggen" light.enable() else src.icon_state = "ggenoff" light.disable() return proc/APC_check() if (!src) return 0 var/area/A = get_area(src) if (!A || !A.requires_power) return 0 var/obj/machinery/power/apc/AC = get_local_apc(src) if (!AC) return 0 if (AC && !AC.cell) return 2 return 1 proc/check_tank(var/obj/item/tank/T) if (!src || !T || !T.air_contents) return 0 if (T.air_contents.toxins <= 0) return 0 return 1 proc/eject_tank(var/mob/user as mob) if (!src) return if (src.P) src.P.set_loc(get_turf(src)) if (istype(user)) user.put_in_hand_or_eject(src.P) // try to eject it into the users hand, if we can src.P = null src.active = 0 src.update_icon() return proc/eject_cell(var/mob/user as mob) if (!src) return if (src.CL) src.CL.set_loc(get_turf(src)) if (istype(user)) user.put_in_hand_or_eject(src.CL) // try to eject it into the users hand, if we can src.CL = null if (src.mode == 2) // Generator doesn't need to shut down when in APC mode. src.active = 0 src.update_icon() return process() if (!src) return if (src.active) if (!src.anchored) src.visible_message("[src]'s retention bolts fail, triggering an emergency shutdown!") playsound(src.loc, "sound/machines/buzz-two.ogg", 100, 0) src.active = 0 src.update_icon() src.updateDialog() return if (!istype(src.loc, /turf/simulated/floor/)) src.visible_message("[src]'s retention bolts fail, triggering an emergency shutdown!") playsound(src.loc, "sound/machines/buzz-two.ogg", 100, 0) src.anchored = 0 // It might have happened, I guess? src.active = 0 src.update_icon() src.updateDialog() return if (src.check_tank(src.P) == 0) src.visible_message("[src] runs out of fuel and shuts down! [src.P] is ejected!") playsound(src.loc, "sound/machines/buzz-two.ogg", 100, 0) src.eject_tank(null) src.updateDialog() return switch (src.mode) if (1) if (!src.our_APC) src.visible_message("[src] doesn't detect a local APC and shuts down!") playsound(src.loc, "sound/machines/buzz-two.ogg", 100, 0) src.active = 0 src.our_APC = null src.update_icon() src.updateDialog() return if (src.last_APC_check && world.time > src.last_APC_check + 50) if (src.APC_check() != 1) src.visible_message("[src] can't charge the local APC and shuts down!") playsound(src.loc, "sound/machines/buzz-two.ogg", 100, 0) src.active = 0 src.our_APC = null src.update_icon() src.updateDialog() src.last_APC_check = world.time return var/obj/item/cell/APC_cell = src.our_APC.cell if (APC_cell) // Because we don't run the check every tick. if (APC_cell.charge < 0) APC_cell.charge = 0 if (APC_cell.charge > APC_cell.maxcharge) APC_cell.charge = APC_cell.maxcharge // Don't combust plasma if we don't have to. if (APC_cell.charge < APC_cell.maxcharge) APC_cell.give(src.CL_charge_rate) src.P.air_contents.toxins = max(0, (P.air_contents.toxins - src.P_drain_rate)) // Call proc to trigger rigged cell and log entries. if (2) if (!src.CL) src.visible_message("[src] doesn't have a cell to charge and shuts down!") playsound(src.loc, "sound/machines/buzz-two.ogg", 100, 0) src.active = 0 src.CL = null src.update_icon() src.updateDialog() return if (src.CL.charge < 0) src.CL.charge = 0 if (src.CL.charge > src.CL.maxcharge) src.CL.charge = src.CL.maxcharge if (src.CL.charge == src.CL.maxcharge) src.visible_message("[src.CL] is fully charged. [src] ejects the cell and shuts down!") playsound(src.loc, "sound/machines/ding.ogg", 100, 1) src.eject_cell(null) src.updateDialog() return if (src.CL.charge < src.CL.maxcharge) src.CL.give(src.CL_charge_rate) src.P.air_contents.toxins = max(0, (P.air_contents.toxins - src.P_drain_rate)) // Call proc to trigger rigged cell and log entries. src.update_icon() src.updateDialog() return attack_hand(var/mob/user as mob) src.add_fingerprint(user) user.machine = src var/dat = "