mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-20 10:37:17 +01:00
* cell, charger, and wire update * overlays * only do this once * IPC hunger thingy
173 lines
4.5 KiB
Plaintext
173 lines
4.5 KiB
Plaintext
/obj/machinery/cell_charger
|
|
name = "cell charger"
|
|
desc = "It charges power cells."
|
|
icon = 'icons/obj/power.dmi'
|
|
icon_state = "ccharger"
|
|
anchored = TRUE
|
|
idle_power_consumption = 5
|
|
active_power_consumption = 60
|
|
power_channel = PW_CHANNEL_EQUIPMENT
|
|
pass_flags = PASSTABLE
|
|
var/obj/item/stock_parts/cell/charging = null
|
|
var/chargelevel = -1
|
|
var/charge_rate = 500
|
|
|
|
/obj/machinery/cell_charger/Initialize(mapload)
|
|
. = ..()
|
|
component_parts = list()
|
|
component_parts += new /obj/item/circuitboard/cell_charger(null)
|
|
component_parts += new /obj/item/stock_parts/capacitor(null)
|
|
RefreshParts()
|
|
if(!mapload)
|
|
return
|
|
|
|
for(var/obj/item/stock_parts/cell/I in get_turf(src)) //suck any cells in at roundstart
|
|
I.forceMove(src)
|
|
charging = I
|
|
check_level()
|
|
update_icon(UPDATE_OVERLAYS)
|
|
break
|
|
|
|
/obj/machinery/cell_charger/deconstruct()
|
|
if(charging)
|
|
charging.forceMove(drop_location())
|
|
return ..()
|
|
|
|
/obj/machinery/cell_charger/Destroy()
|
|
QDEL_NULL(charging)
|
|
return ..()
|
|
|
|
/obj/machinery/cell_charger/update_overlays()
|
|
. = ..()
|
|
if(!charging)
|
|
return
|
|
. += "[charging.icon_state]"
|
|
|
|
switch(charging.charge / charging.maxcharge)
|
|
if(0.1 to 0.995)
|
|
. += "cell-o1"
|
|
if(0.995 to 1)
|
|
. += "cell-o2"
|
|
|
|
if(stat & (BROKEN|NOPOWER))
|
|
return
|
|
. += "ccharger-o[chargelevel]"
|
|
|
|
/obj/machinery/cell_charger/examine(mob/user)
|
|
. = ..()
|
|
. += "There's [charging ? "a" : "no"] cell in the charger."
|
|
if(charging)
|
|
. += "Current charge: [round(charging.percent(), 1)]%"
|
|
|
|
/obj/machinery/cell_charger/attackby(obj/item/I, mob/user, params)
|
|
if(istype(I, /obj/item/stock_parts/cell) && !panel_open)
|
|
if(stat & BROKEN)
|
|
to_chat(user, "<span class='warning'>[src] is broken!</span>")
|
|
return
|
|
if(!anchored)
|
|
to_chat(user, "<span class='warning'>[src] isn't attached to the ground!</span>")
|
|
return
|
|
if(charging)
|
|
to_chat(user, "<span class='warning'>There is already a cell in the charger!</span>")
|
|
return
|
|
else
|
|
var/area/a = loc.loc // Gets our locations location, like a dream within a dream
|
|
if(!isarea(a))
|
|
return
|
|
if(!a.powernet.equipment_powered) // There's no APC in this area, don't try to cheat power!
|
|
to_chat(user, "<span class='warning'>[src] blinks red as you try to insert the cell!</span>")
|
|
return
|
|
if(!user.drop_item())
|
|
return
|
|
|
|
I.forceMove(src)
|
|
charging = I
|
|
user.visible_message("[user] inserts a cell into the charger.", "<span class='notice'>You insert a cell into the charger.</span>")
|
|
check_level()
|
|
update_icon(UPDATE_OVERLAYS)
|
|
else
|
|
return ..()
|
|
|
|
/obj/machinery/cell_charger/crowbar_act(mob/user, obj/item/I)
|
|
if(panel_open && !charging && default_deconstruction_crowbar(user, I))
|
|
return TRUE
|
|
|
|
/obj/machinery/cell_charger/screwdriver_act(mob/user, obj/item/I)
|
|
if(anchored && !charging && default_deconstruction_screwdriver(user, icon_state, icon_state, I))
|
|
return TRUE
|
|
|
|
/obj/machinery/cell_charger/wrench_act(mob/user, obj/item/I)
|
|
. = TRUE
|
|
if(charging)
|
|
to_chat(user, "<span class='warning'>Remove the cell first!</span>")
|
|
return
|
|
if(!I.use_tool(src, user, 0, volume = I.tool_volume))
|
|
return
|
|
anchored = !anchored
|
|
if(anchored)
|
|
WRENCH_ANCHOR_MESSAGE
|
|
else
|
|
WRENCH_UNANCHOR_MESSAGE
|
|
|
|
/obj/machinery/cell_charger/proc/removecell()
|
|
charging.update_icon()
|
|
charging = null
|
|
chargelevel = -1
|
|
update_icon(UPDATE_OVERLAYS)
|
|
|
|
/obj/machinery/cell_charger/attack_hand(mob/user)
|
|
if(!charging)
|
|
return
|
|
|
|
user.put_in_hands(charging)
|
|
charging.add_fingerprint(user)
|
|
|
|
user.visible_message("[user] removes [charging] from [src].", "<span class='notice'>You remove [charging] from [src].</span>")
|
|
|
|
removecell()
|
|
|
|
/obj/machinery/cell_charger/attack_tk(mob/user)
|
|
if(!charging)
|
|
return
|
|
|
|
charging.forceMove(loc)
|
|
to_chat(user, "<span class='notice'>You telekinetically remove [charging] from [src].</span>")
|
|
|
|
removecell()
|
|
|
|
/obj/machinery/cell_charger/attack_ai(mob/user)
|
|
return
|
|
|
|
/obj/machinery/cell_charger/emp_act(severity)
|
|
if(stat & (BROKEN|NOPOWER))
|
|
return
|
|
|
|
if(charging)
|
|
charging.emp_act(severity)
|
|
|
|
..(severity)
|
|
|
|
/obj/machinery/cell_charger/RefreshParts()
|
|
charge_rate = 500
|
|
for(var/obj/item/stock_parts/capacitor/C in component_parts)
|
|
charge_rate *= C.rating
|
|
|
|
/obj/machinery/cell_charger/process()
|
|
if(!charging || !anchored || (stat & (BROKEN|NOPOWER)))
|
|
return
|
|
|
|
if(charging.percent() >= 100)
|
|
return
|
|
|
|
use_power(charge_rate)
|
|
charging.give(charge_rate)
|
|
|
|
if(check_level())
|
|
update_icon(UPDATE_OVERLAYS)
|
|
|
|
/obj/machinery/cell_charger/proc/check_level()
|
|
var/newlevel = round(charging.percent() * 4 / 100)
|
|
if(chargelevel != newlevel)
|
|
chargelevel = newlevel
|
|
return TRUE
|