From b1b2f4ae926cf6e85b80c7fb7434b4c31740f5a0 Mon Sep 17 00:00:00 2001 From: Markolie Date: Mon, 3 Aug 2015 00:58:10 +0200 Subject: [PATCH] Compile error fix --- code/modules/power/apc.dm | 378 +++++++++++++++++++------------------- 1 file changed, 188 insertions(+), 190 deletions(-) diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index 74863d6b48a..5eca4d081fb 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -54,7 +54,7 @@ var/areastring = null var/obj/item/weapon/stock_parts/cell/cell var/start_charge = 90 // initial cell charge % - var/cell_type = 2500 // 0=no cell, 1=regular, 2=high-cap (x5) <- old, now it's just 0=no cell, otherwise dictate cellcapacity by changing this value. 1 used to be 1000, 2 was 2500 + var/cell_type = 2500 var/opened = 0 //0=closed, 1=opened, 2=cover removed var/shorted = 0 var/lighting = 3 @@ -84,12 +84,13 @@ var/has_electronics = 0 // 0 - none, 1 - plugged in, 2 - secured by screwdriver var/overload = 1 //used for the Blackout malf module var/beenhit = 0 // used for counting how many times it has been hit, used for Aliens at the moment - var/mob/living/silicon/ai/occupant = null + var/mob/living/silicon/ai/occupier = null var/longtermpower = 10 var/update_state = -1 var/update_overlay = -1 var/global/status_overlays = 0 var/updating_icon = 0 + var/standard_max_charge var/datum/wires/apc/wires = null //var/debug = 0 var/global/list/status_overlays_lock @@ -98,19 +99,27 @@ var/global/list/status_overlays_lighting var/global/list/status_overlays_environ var/indestructible = 0 // If set, prevents aliens from destroying it + var/report_power_alarm = 1 /obj/machinery/power/apc/noalarm report_power_alarm = 0 -/obj/machinery/power/apc/updateDialog() - if (stat & (BROKEN|MAINT)) - return - ..() +/obj/machinery/power/apc/connect_to_network() + //Override because the APC does not directly connect to the network; it goes through a terminal. + //The terminal is what the power computer looks for anyway. + if(!terminal) + make_terminal() + if(terminal) + terminal.connect_to_network() /obj/machinery/power/apc/New(turf/loc, var/ndir, var/building=0) ..() wires = new(src) + var/tmp/obj/item/weapon/stock_parts/cell/tmp_cell = new + standard_max_charge = tmp_cell.maxcharge + qdel(tmp_cell) + // offset 24 pixels in direction of dir // this allows the APC to be embedded in a wall, yet still inside an area if (building) @@ -132,8 +141,24 @@ src.update_icon() spawn(5) src.update() - - + +/obj/machinery/power/apc/Destroy() + if(malfai && operating) + if (ticker.mode.config_tag == "malfunction") + if (src.z == ZLEVEL_STATION) + ticker.mode:apcs-- + area.power_light = 0 + area.power_equip = 0 + area.power_environ = 0 + area.power_change() + if(occupier) + malfvacate(1) + qdel(wires) + if(cell) + qdel(cell) // qdel + if(terminal) + disconnect_terminal() + return ..() /obj/machinery/power/apc/proc/make_terminal() // create a terminal object at the same position as original turf loc @@ -273,7 +298,7 @@ if(update & 2) if(overlays.len) - overlays = 0 + overlays.len = 0 if(!(stat & (BROKEN|MAINT)) && update_state & UPSTATE_ALLGOOD) overlays += status_overlays_lock[locked+1] @@ -346,10 +371,11 @@ return 0 if(last_update_state != update_state) results += 1 - if(last_update_overlay != update_overlay && update_overlay != 0) + if(last_update_overlay != update_overlay) results += 2 return results +// Used in process so it doesn't update the icon too much /obj/machinery/power/apc/proc/queue_icon_update() if(!updating_icon) @@ -376,29 +402,30 @@ if (istype(W, /obj/item/weapon/crowbar) && opened) if (has_electronics==1) if (terminal) - user << "\red Disconnect wires first." + user << "Disconnect wires first." return playsound(src.loc, 'sound/items/Crowbar.ogg', 50, 1) user << "You are trying to remove the power control board..." //lpeters - fixed grammar issues if(do_after(user, 50)) - has_electronics = 0 - if ((stat & BROKEN) || malfhack) - user.visible_message(\ - "\red [user.name] has broken the power control board inside [src.name]!",\ - "You broke the charred power control board and remove the remains.", - "You hear a crack!") - //ticker.mode:apcs-- //XSI said no and I agreed. -rastaf0 - else - user.visible_message(\ - "\red [user.name] has removed the power control board from [src.name]!",\ - "You remove the power control board.") - new /obj/item/weapon/module/power_control(loc) + if (has_electronics==1) + has_electronics = 0 + if ((stat & BROKEN) || malfhack) + user.visible_message(\ + "[user.name] has broken the power control board inside [src.name]!",\ + "You broke the charred power control board and remove the remains.", + "You hear a crack!") + //ticker.mode:apcs-- //XSI said no and I agreed. -rastaf0 + else + user.visible_message(\ + "[user.name] has removed the power control board from [src.name]!",\ + "You remove the power control board.") + new /obj/item/weapon/module/power_control(loc) else if (opened!=2) //cover isn't removed opened = 0 update_icon() else if (istype(W, /obj/item/weapon/crowbar) && !((stat & BROKEN) || malfhack) ) if(coverlocked && !(stat & MAINT)) - user << "\red The cover is locked and cannot be opened." + user << "The cover is locked and cannot be opened." return else opened = 1 @@ -409,20 +436,20 @@ return else if (stat & MAINT) - user << "\red There is no connector for your power cell." + user << "There is no connector for your power cell." return user.drop_item() W.loc = src cell = W user.visible_message(\ - "\red [user.name] has inserted the power cell to [src.name]!",\ + "[user.name] has inserted the power cell to [src.name]!",\ "You insert the power cell.") chargecount = 0 update_icon() else if (istype(W, /obj/item/weapon/screwdriver)) // haxing if(opened) if (cell) - user << "\red Close the APC first." //Less hints more mystery! + user << "Close the APC first." //Less hints more mystery! return else if (has_electronics==1 && terminal) @@ -436,7 +463,7 @@ playsound(src.loc, 'sound/items/Screwdriver.ogg', 50, 1) user << "You unfasten the electronics." else /* has_electronics==0 */ - user << "\red There is nothing to secure." + user << "There is nothing to secure." return update_icon() else if(emagged) @@ -461,87 +488,90 @@ user << "You [ locked ? "lock" : "unlock"] the APC interface." update_icon() else - user << "\red Access denied." + user << "Access denied." else if (istype(W, /obj/item/stack/cable_coil) && !terminal && opened && has_electronics!=2) if (src.loc:intact) - user << "\red You must remove the floor plating in front of the APC first." + user << "You must remove the floor plating in front of the APC first." return var/obj/item/stack/cable_coil/C = W if(C.amount < 10) - user << "\red You need more wires." + user << "You need more wires." return user << "You start adding cables to the APC frame..." playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1) - if(do_after(user, 20) && C.amount >= 10) - var/turf/T = get_turf(src) - var/obj/structure/cable/N = T.get_cable_node() - if (prob(50) && electrocute_mob(usr, N, N)) - var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread - s.set_up(5, 1, src) - s.start() - return - C.use(10) - user.visible_message(\ - "\red [user.name] has added cables to the APC frame!",\ - "You add cables to the APC frame.") - make_terminal() - terminal.connect_to_network() + if(do_after(user, 20)) + if (C.amount >= 10 && !terminal && opened && has_electronics != 2) + var/turf/T = get_turf(src) + var/obj/structure/cable/N = T.get_cable_node() + if (prob(50) && electrocute_mob(usr, N, N)) + var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread + s.set_up(5, 1, src) + s.start() + return + C.use(10) + user.visible_message(\ + "[user.name] has added cables to the APC frame!",\ + "You add cables to the APC frame.") + make_terminal() + terminal.connect_to_network() else if (istype(W, /obj/item/weapon/wirecutters) && terminal && opened && has_electronics!=2) if (src.loc:intact) - user << "\red You must remove the floor plating in front of the APC first." + user << "You must remove the floor plating in front of the APC first." return user << "You begin to cut the cables..." playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1) if(do_after(user, 50)) - if (prob(50) && electrocute_mob(usr, terminal.powernet, terminal)) - var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread - s.set_up(5, 1, src) - s.start() - return - new /obj/item/stack/cable_coil(loc,10) - user.visible_message(\ - "\red [user.name] cut the cables and dismantled the power terminal.",\ - "You cut the cables and dismantle the power terminal.") - qdel(terminal) + if(terminal && opened && has_electronics!=2) + if (prob(50) && electrocute_mob(usr, terminal.powernet, terminal)) + var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread + s.set_up(5, 1, src) + s.start() + return + new /obj/item/stack/cable_coil(loc,10) + user << "You cut the cables and dismantle the power terminal." + qdel(terminal) // qdel else if (istype(W, /obj/item/weapon/module/power_control) && opened && has_electronics==0 && !((stat & BROKEN) || malfhack)) user << "You trying to insert the power control board into the frame..." playsound(src.loc, 'sound/items/Deconstruct.ogg', 50, 1) if(do_after(user, 10)) - has_electronics = 1 - user << "You place the power control board inside the frame." - qdel(W) + if(has_electronics==0) + has_electronics = 1 + user << "You place the power control board inside the frame." + qdel(W) // qdel else if (istype(W, /obj/item/weapon/module/power_control) && opened && has_electronics==0 && ((stat & BROKEN) || malfhack)) - user << "\red You cannot put the board inside, the frame is damaged." + user << "You cannot put the board inside, the frame is damaged." return else if (istype(W, /obj/item/weapon/weldingtool) && opened && has_electronics==0 && !terminal) var/obj/item/weapon/weldingtool/WT = W if (WT.get_fuel() < 3) - user << "\blue You need more welding fuel to complete this task." + user << "You need more welding fuel to complete this task." return - user << "You start welding the APC frame..." + user.visible_message("[user.name] welds [src].", \ + "You start welding the APC frame...", \ + "You hear welding.") playsound(src.loc, 'sound/items/Welder.ogg', 50, 1) if(do_after(user, 50)) if(!src || !WT.remove_fuel(3, user)) return if (emagged || malfhack || (stat & BROKEN) || opened==2) new /obj/item/stack/sheet/metal(loc) user.visible_message(\ - "\red [src] has been cut apart by [user.name] with the weldingtool.",\ - "You disassembled the broken APC frame.",\ - "\red You hear welding.") + "[src] has been cut apart by [user.name] with the weldingtool.",\ + "You disassembled the broken APC frame.",\ + "You hear welding.") else new /obj/item/mounted/frame/apc_frame(loc) user.visible_message(\ - "\red [src] has been cut from the wall by [user.name] with the weldingtool.",\ - "You cut the APC frame from the wall.",\ - "\red You hear welding.") - qdel(src) + "[src] has been cut from the wall by [user.name] with the weldingtool.",\ + "You cut the APC frame from the wall.",\ + "You hear welding.") + qdel(src) // qdel return else if (istype(W, /obj/item/mounted/frame/apc_frame) && opened && emagged) emagged = 0 if (opened==2) opened = 1 user.visible_message(\ - "\red [user.name] has replaced the damaged APC frontal panel with a new one.",\ + "[user.name] has replaced the damaged APC frontal panel with a new one.",\ "You replace the damaged APC frontal panel with a new one.") qdel(W) update_icon() @@ -552,7 +582,7 @@ user << "You begin to replace the damaged APC frame..." if(do_after(user, 50)) user.visible_message(\ - "\red [user.name] has replaced the damaged APC frame with new one.",\ + "[user.name] has replaced the damaged APC frame with new one.",\ "You replace the damaged APC frame with new one.") qdel(W) stat &= ~BROKEN @@ -570,8 +600,8 @@ ) \ && prob(20) ) opened = 2 - user.visible_message("\red The APC cover was knocked down with the [W.name] by [user.name]!", \ - "\red You knock down the APC cover with your [W.name]!", \ + user.visible_message("The APC cover was knocked down with the [W.name] by [user.name]!", \ + "You knock down the APC cover with your [W.name]!", \ "You hear bang") update_icon() else @@ -582,8 +612,8 @@ istype(W, /obj/item/weapon/wirecutters) || istype(W, /obj/item/device/assembly/signaler))) return src.attack_hand(user) user.do_attack_animation(src) - user.visible_message("\red The [src.name] has been hit with the [W.name] by [user.name]!", \ - "\red You hit the [src.name] with your [W.name]!", \ + user.visible_message("The [src.name] has been hit with the [W.name] by [user.name]!", \ + "You hit the [src.name] with your [W.name]!", \ "You hear bang") /obj/machinery/power/apc/emag_act(user as mob) @@ -616,7 +646,7 @@ var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread s.set_up(3, 1, src) s.start() - H << "\red The APC power currents surge eratically, damaging your chassis!" + H << "The APC power currents surge eratically, damaging your chassis!" H.adjustFireLoss(10,0) else if(src.cell && src.cell.charge > 0) if(H.nutrition < 450) @@ -628,13 +658,13 @@ H.nutrition += src.cell.charge/10 src.cell.charge = 0 - user << "\blue You slot your fingers into the APC interface and siphon off some of the stored charge for your own use." + user << "You slot your fingers into the APC interface and siphon off some of the stored charge for your own use." if(src.cell.charge < 0) src.cell.charge = 0 if(H.nutrition > 500) H.nutrition = 500 src.charging = 1 else - user << "\blue You are already fully charged." + user << "You are already fully charged." else user << "There is no charge to draw from that APC." return @@ -649,7 +679,7 @@ cell.updateicon() src.cell = null - user.visible_message("\red [user.name] removes the power cell from [src.name]!", "You remove the power cell.") + user.visible_message("[user.name] removes the power cell from [src.name]!", "You remove the power cell.") //user << "You remove the power cell." charging = 0 src.update_icon() @@ -668,7 +698,7 @@ return user.changeNext_move(CLICK_CD_MELEE) user.do_attack_animation(src) - user.visible_message("\red [user.name] slashes at the [src.name]!", "\blue You slash at the [src.name]!") + user.visible_message("[user.name] slashes at the [src.name]!", "You slash at the [src.name]!") playsound(src.loc, 'sound/weapons/slash.ogg', 100, 1) var/allcut = wires.IsAllCut() @@ -676,12 +706,12 @@ if(beenhit >= pick(3, 4) && wiresexposed != 1) wiresexposed = 1 src.update_icon() - src.visible_message("\red The [src.name]'s cover flies open, exposing the wires!") + src.visible_message("The [src.name]'s cover flies open, exposing the wires!") else if(wiresexposed == 1 && allcut == 0) wires.CutAll() src.update_icon() - src.visible_message("\red The [src.name]'s wires are shredded!") + src.visible_message("The [src.name]'s wires are shredded!") else beenhit += 1 return @@ -704,7 +734,7 @@ /obj/machinery/power/apc/proc/get_malf_status(mob/user) if (ticker && ticker.mode && (user.mind in ticker.mode.malf_ai) && istype(user, /mob/living/silicon/ai)) if (src.malfai == (user:parent ? user:parent : user)) - if (src.occupant == user) + if (src.occupier == user) return 3 // 3 = User is shunted in this APC else if (istype(user.loc, /obj/machinery/power/apc)) return 4 // 4 = User is shunted in another APC @@ -805,7 +835,7 @@ /obj/machinery/power/apc/proc/can_use(mob/user as mob, var/loud = 0) //used by attack_hand() and Topic() if (user.stat && !isobserver(user)) - user << "\red You must be conscious to use this [src]!" + user << "You must be conscious to use this [src]!" return 0 if(stat & (NOPOWER|BROKEN)) return 0 @@ -815,13 +845,13 @@ return 0 if ( ! (istype(user, /mob/living/carbon/human) || \ istype(user, /mob/living/silicon))) - user << "\red You don't have the dexterity to use this [src]!" + user << "You don't have the dexterity to use this [src]!" return 0 if(user.restrained()) - user << "\red You must have free hands to use this [src]" + user << "You must have free hands to use this [src]" return 0 if(user.lying) - user << "\red You must stand to use this [src]!" + user << "You must stand to use this [src]!" return 0 autoflag = 5 if (istype(user, /mob/living/silicon)) @@ -836,7 +866,7 @@ ) \ ) if(!loud) - user << "\red \The [src] has AI control disabled!" + user << "\The [src] has AI control disabled!" user << browse(null, "window=apc") user.unset_machine() return 0 @@ -848,10 +878,10 @@ if (istype(H)) if(H.getBrainLoss() >= 60) for(var/mob/M in viewers(src, null)) - M << "\red [H] stares cluelessly at [src] and drools." + M << "[H] stares cluelessly at [src] and drools." return 0 else if(prob(H.getBrainLoss())) - user << "\red You momentarily forget how to use [src]." + user << "You momentarily forget how to use [src]." return 0 return 1 @@ -993,34 +1023,34 @@ return if(!(src.z in config.station_levels)) return - src.occupant = new /mob/living/silicon/ai(src,malf.laws,null,1) - src.occupant.adjustOxyLoss(malf.getOxyLoss()) - if(!findtext(src.occupant.name,"APC Copy")) - src.occupant.name = "[malf.name] APC Copy" + src.occupier = new /mob/living/silicon/ai(src,malf.laws,null,1) + src.occupier.adjustOxyLoss(malf.getOxyLoss()) + if(!findtext(src.occupier.name,"APC Copy")) + src.occupier.name = "[malf.name] APC Copy" if(malf.parent) - src.occupant.parent = malf.parent + src.occupier.parent = malf.parent else - src.occupant.parent = malf - malf.mind.transfer_to(src.occupant) - src.occupant.eyeobj.name = "[src.occupant.name] (AI Eye)" + src.occupier.parent = malf + malf.mind.transfer_to(src.occupier) + src.occupier.eyeobj.name = "[src.occupier.name] (AI Eye)" if(malf.parent) qdel(malf) - src.occupant.verbs += /mob/living/silicon/ai/proc/corereturn - src.occupant.verbs += /datum/game_mode/malfunction/proc/takeover - src.occupant.cancel_camera() + src.occupier.verbs += /mob/living/silicon/ai/proc/corereturn + src.occupier.verbs += /datum/game_mode/malfunction/proc/takeover + src.occupier.cancel_camera() if (seclevel2num(get_security_level()) == SEC_LEVEL_DELTA) for(var/obj/item/weapon/pinpointer/point in world) point.the_disk = src //the pinpointer will detect the shunted AI /obj/machinery/power/apc/proc/malfvacate(var/forced) - if(!src.occupant) + if(!src.occupier) return - if(src.occupant.parent && src.occupant.parent.stat != 2) - src.occupant.mind.transfer_to(src.occupant.parent) - src.occupant.parent.adjustOxyLoss(src.occupant.getOxyLoss()) - src.occupant.parent.cancel_camera() - qdel(src.occupant) + if(src.occupier.parent && src.occupier.parent.stat != 2) + src.occupier.mind.transfer_to(src.occupier.parent) + src.occupier.parent.adjustOxyLoss(src.occupier.getOxyLoss()) + src.occupier.parent.cancel_camera() + del(src.occupier) // qdel if (seclevel2num(get_security_level()) == SEC_LEVEL_DELTA) for(var/obj/item/weapon/pinpointer/point in world) for(var/datum/mind/AI_mind in ticker.mode.malf_ai) @@ -1029,11 +1059,11 @@ point.the_disk = A //The pinpointer tracks the AI back into its core. else - src.occupant << "\red Primary core damaged, unable to return core processes." + src.occupier << "Primary core damaged, unable to return core processes." if(forced) - src.occupant.loc = src.loc - src.occupant.death() - src.occupant.gib() + src.occupier.loc = src.loc + src.occupier.death() + src.occupier.gib() for(var/obj/item/weapon/pinpointer/point in world) point.the_disk = null //the pinpointer will go back to pointing at the nuke disc. @@ -1044,7 +1074,7 @@ if(prob(3)) src.locked = 1 if (src.cell.charge > 0) -// world << "\red blew APC in [src.loc.loc]" +// world << "blew APC in [src.loc.loc]" src.cell.charge = 0 cell.corrupt() src.malfhack = 1 @@ -1057,7 +1087,7 @@ s.set_up(3, 1, src) s.start() for(var/mob/M in viewers(src)) - M.show_message("\red The [src.name] suddenly lets out a blast of smoke and some sparks!", 3, "\red You hear sizzling electronics.", 2) + M.show_message("The [src.name] suddenly lets out a blast of smoke and some sparks!", 3, "You hear sizzling electronics.", 2) /obj/machinery/power/apc/surplus() @@ -1066,9 +1096,14 @@ else return 0 -/obj/machinery/power/apc/add_load(var/amount) +//Returns 1 if the APC should attempt to charge +/obj/machinery/power/apc/proc/attempt_charging() + return (chargemode && charging == 1 && operating) + +/obj/machinery/power/apc/draw_power(var/amount) if(terminal && terminal.powernet) - terminal.powernet.load += amount + return terminal.powernet.draw_power(amount) + return 0 /obj/machinery/power/apc/avail() if(terminal) @@ -1086,8 +1121,7 @@ lastused_light = area.usage(LIGHT) lastused_equip = area.usage(EQUIP) lastused_environ = area.usage(ENVIRON) - if(area.powerupdate) - area.clear_usage() + area.clear_usage() lastused_total = lastused_light + lastused_equip + lastused_environ @@ -1106,33 +1140,24 @@ else main_status = 2 - //if(debug) - //world << "Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light]" + if(debug) + log_debug("Status: [main_status] - Excess: [excess] - Last Equip: [lastused_equip] - Last Light: [lastused_light] - Longterm: [longtermpower]") if(cell && !shorted) - var/cell_charge = cell.charge - var/cell_maxcharge = cell.maxcharge - // draw power from cell as before to power the area - - var/cellused = min(cell_charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell + var/cellused = min(cell.charge, CELLRATE * lastused_total) // clamp deduction to a max, amount left in cell cell.use(cellused) if(excess > lastused_total) // if power excess recharge the cell - // by the same amount just used - cell.give(cellused) - add_load(cellused/CELLRATE) // add the load used to recharge the cell - - + // by the same amount just used + var/draw = draw_power(cellused/CELLRATE) // draw the power needed to charge this cell + cell.give(draw * CELLRATE) else // no excess, and not enough per-apc - - if( (cell_charge/CELLRATE + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage? - - cell_charge = min(cell_maxcharge, cell_charge + CELLRATE * excess) //recharge with what we can - add_load(excess) // so draw what we can from the grid + if( (cell.charge/CELLRATE + excess) >= lastused_total) // can we draw enough from cell+grid to cover last usage? + var/draw = draw_power(excess) + cell.charge = min(cell.maxcharge, cell.charge + CELLRATE * draw) //recharge with what we can charging = 0 - - else if (autoflag != 0) // not enough power available to run the last tick! + else // not enough power available to run the last tick! charging = 0 chargecount = 0 // This turns everything off in the case that there is still a charge left on the battery, just not enough to run the room. @@ -1142,7 +1167,7 @@ autoflag = 0 - // set channels depending on how much charge we have left + // Set channels depending on how much charge we have left // Allow the APC to operate as normal if the cell can charge if(charging && longtermpower < 10) @@ -1150,15 +1175,15 @@ else if(longtermpower > -10) longtermpower -= 2 - - if(cell_charge >= 1250 || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101 + if(cell.charge >= 1250 || longtermpower > 0) // Put most likely at the top so we don't check it last, effeciency 101 if(autoflag != 3) equipment = autoset(equipment, 1) lighting = autoset(lighting, 1) environ = autoset(environ, 1) autoflag = 3 - power_alarm.clearAlarm(loc, src) - else if(cell_charge < 1250 && cell_charge > 750 && longtermpower < 0) // <30%, turn off equipment + if(report_power_alarm) + power_alarm.clearAlarm(loc, src) + else if(cell.charge < 1250 && cell.charge > 750 && longtermpower < 0) // <30%, turn off equipment if(autoflag != 2) equipment = autoset(equipment, 2) lighting = autoset(lighting, 1) @@ -1166,15 +1191,15 @@ if(report_power_alarm) power_alarm.triggerAlarm(loc, src) autoflag = 2 - else if(cell_charge < 750 && cell_charge > 10 && longtermpower < 0) // <15%, turn off lighting & equipment - if(autoflag != 1) + else if(cell.charge < 750 && cell.charge > 10) // <15%, turn off lighting & equipment + if((autoflag > 1 && longtermpower < 0) || (autoflag > 1 && longtermpower >= 0)) equipment = autoset(equipment, 2) lighting = autoset(lighting, 2) environ = autoset(environ, 1) if(report_power_alarm) power_alarm.triggerAlarm(loc, src) autoflag = 1 - else if(cell_charge <= 0) // zero charge, turn all off + else if(cell.charge <= 0) // zero charge, turn all off if(autoflag != 0) equipment = autoset(equipment, 0) lighting = autoset(lighting, 0) @@ -1185,32 +1210,31 @@ // now trickle-charge the cell - if(chargemode && charging == 1 && operating) + if(src.attempt_charging()) if(excess > 0) // check to make sure we have enough to charge // Max charge is capped to % per second constant var/ch = min(excess*CELLRATE, cell.maxcharge*CHARGELEVEL) - add_load(ch/CELLRATE) // Removes the power we're taking from the grid - cell.give(ch) // actually recharge the cell + + ch = draw_power(ch/CELLRATE) // Removes the power we're taking from the grid + cell.give(ch*CELLRATE) // actually recharge the cell else charging = 0 // stop charging chargecount = 0 // show cell as fully charged if so - if(cell.charge >= cell.maxcharge) cell.charge = cell.maxcharge charging = 2 if(chargemode) if(!charging) - if(excess > cell_maxcharge*CHARGELEVEL) + if(excess > cell.maxcharge*CHARGELEVEL) chargecount++ else chargecount = 0 - charging = 0 - if(chargecount == 10) + if(chargecount >= 10) chargecount = 0 charging = 1 @@ -1230,18 +1254,15 @@ power_alarm.triggerAlarm(loc, src) autoflag = 0 - // update icon & area power if anything changed + if(last_lt != lighting || last_eq != equipment || last_en != environ) queue_icon_update() update() else if (last_ch != charging) queue_icon_update() - -// val 0=off, 1=off(auto) 2=on 3=on(auto) -// on 0=off, 1=on, 2=autooff - -obj/machinery/power/apc/proc/autoset(var/val, var/on) + +/obj/machinery/power/apc/proc/autoset(var/val, var/on) if(on==0) if(val==2) // if on, return off return 0 @@ -1257,14 +1278,14 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on) return 1 return val - + // damage and destruction acts /obj/machinery/power/apc/emp_act(severity) if(cell) cell.emp_act(severity) - if(occupant) - occupant.emp_act(severity) + if(occupier) + occupier.emp_act(severity) lighting = 0 equipment = 0 environ = 0 @@ -1299,6 +1320,12 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on) set_broken() if (cell && prob(5)) cell.blob_act() + + +/obj/machinery/power/apc/disconnect_terminal() + if(terminal) + terminal.master = null + terminal = null /obj/machinery/power/apc/proc/set_broken() if(malfai && operating) @@ -1307,7 +1334,7 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on) ticker.mode:apcs-- stat |= BROKEN operating = 0 - if(occupant) + if(occupier) malfvacate(1) update_icon() update() @@ -1326,35 +1353,6 @@ obj/machinery/power/apc/proc/autoset(var/val, var/on) L.broken() sleep(1) -/obj/machinery/power/apc/Destroy() - if(malfai && operating) - if (ticker.mode.config_tag == "malfunction") - if ((src.z in config.station_levels)) //if (is_type_in_list(get_area(src), the_station_areas)) - ticker.mode:apcs-- - area.power_light = 0 - area.power_equip = 0 - area.power_environ = 0 - area.power_change() - if(occupant) - malfvacate(1) - qdel(wires) - if(cell) - qdel(cell) - return ..() - -/obj/machinery/power/apc/proc/shock(mob/user, prb) - if(!prob(prb)) - return 0 - var/datum/effect/effect/system/spark_spread/s = new /datum/effect/effect/system/spark_spread - s.set_up(5, 1, src) - s.start() - if(isalien(user)) - return 0 - if (electrocute_mob(user, src, src)) - return 1 - else - return 0 - /obj/machinery/power/apc/proc/setsubsystem(val) if(cell && cell.charge > 0) return (val==1) ? 0 : val