mirror of
https://github.com/SPLURT-Station/S.P.L.U.R.T-Station-13.git
synced 2025-12-10 09:54:52 +00:00
480 lines
17 KiB
Plaintext
480 lines
17 KiB
Plaintext
#define SOLAR_GEN_RATE 1500
|
|
|
|
/obj/machinery/power/solar
|
|
name = "solar panel"
|
|
desc = "A solar panel. Generates electricity when in contact with sunlight."
|
|
icon = 'goon/icons/obj/power.dmi'
|
|
icon_state = "sp_base"
|
|
minimap_override_color = "#02026a"
|
|
density = TRUE
|
|
use_power = NO_POWER_USE
|
|
idle_power_usage = 0
|
|
active_power_usage = 0
|
|
max_integrity = 150
|
|
integrity_failure = 0.33
|
|
|
|
var/id
|
|
var/list/obscured = list()
|
|
var/total_flux = 0 // multipllier against power generation -- measured by obscuration of all suns
|
|
var/azimuth_current = 0 //[0-360) degrees, which direction are we facing?
|
|
var/azimuth_target = 0 //same but what way we're going to face next time we turn
|
|
var/obj/machinery/power/solar_control/control
|
|
var/needs_to_turn = TRUE //do we need to turn next tick?
|
|
var/needs_to_update_solar_exposure = TRUE //do we need to call update_solar_exposure() next tick?
|
|
var/obj/effect/overlay/panel
|
|
var/obj/item/solar_assembly/assembly
|
|
var/efficiency = 1
|
|
|
|
/obj/machinery/power/solar/Initialize(mapload, obj/item/solar_assembly/S)
|
|
. = ..()
|
|
panel = new()
|
|
panel.vis_flags = VIS_INHERIT_ID|VIS_INHERIT_ICON|VIS_INHERIT_PLANE
|
|
vis_contents += panel
|
|
panel.icon = icon
|
|
panel.icon_state = "solar_panel"
|
|
panel.layer = FLY_LAYER
|
|
Make(S)
|
|
connect_to_network()
|
|
RegisterSignal(SSsun, COMSIG_SUN_MOVED, .proc/queue_update_solar_exposure)
|
|
|
|
/obj/machinery/power/solar/Destroy()
|
|
unset_control() //remove from control computer
|
|
return ..()
|
|
|
|
//set the control of the panel to a given computer
|
|
/obj/machinery/power/solar/proc/set_control(obj/machinery/power/solar_control/SC)
|
|
unset_control()
|
|
control = SC
|
|
SC.connected_panels += src
|
|
queue_turn(SC.azimuth_target)
|
|
|
|
//set the control of the panel to null and removes it from the control list of the previous control computer if needed
|
|
/obj/machinery/power/solar/proc/unset_control()
|
|
if(control)
|
|
control.connected_panels -= src
|
|
control = null
|
|
|
|
/obj/machinery/power/solar/proc/Make(obj/item/solar_assembly/S)
|
|
if(!S)
|
|
assembly = new /obj/item/solar_assembly
|
|
assembly.glass_type = new /obj/item/stack/sheet/glass(null, 2)
|
|
assembly.anchored = TRUE
|
|
else
|
|
S.moveToNullspace()
|
|
assembly = S
|
|
assembly.glass_type.on_solar_construction(src)
|
|
obj_integrity = max_integrity
|
|
update_appearance()
|
|
|
|
/obj/machinery/power/solar/crowbar_act(mob/user, obj/item/I)
|
|
playsound(src.loc, 'sound/machines/click.ogg', 50, TRUE)
|
|
user.visible_message("<span class='notice'>[user] begins to take the glass off [src].</span>", "<span class='notice'>You begin to take the glass off [src]...</span>")
|
|
if(I.use_tool(src, user, 50))
|
|
playsound(src.loc, 'sound/items/deconstruct.ogg', 50, TRUE)
|
|
user.visible_message("<span class='notice'>[user] takes the glass off [src].</span>", "<span class='notice'>You take the glass off [src].</span>")
|
|
deconstruct(TRUE)
|
|
return TRUE
|
|
|
|
/obj/machinery/power/solar/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
|
|
switch(damage_type)
|
|
if(BRUTE)
|
|
if(stat & BROKEN)
|
|
playsound(loc, 'sound/effects/hit_on_shattered_glass.ogg', 60, TRUE)
|
|
else
|
|
playsound(loc, 'sound/effects/glasshit.ogg', 90, TRUE)
|
|
if(BURN)
|
|
playsound(loc, 'sound/items/welder.ogg', 100, TRUE)
|
|
|
|
|
|
/obj/machinery/power/solar/obj_break(damage_flag)
|
|
. = ..()
|
|
if(.)
|
|
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
|
|
unset_control()
|
|
|
|
/obj/machinery/power/solar/deconstruct(disassembled = TRUE)
|
|
if(!(flags_1 & NODECONSTRUCT_1))
|
|
if(disassembled)
|
|
if(assembly)
|
|
assembly.forceMove(loc)
|
|
assembly.give_glass(stat & BROKEN)
|
|
else
|
|
playsound(src, "shatter", 70, TRUE)
|
|
var/shard = assembly?.glass_type ? assembly.glass_type.shard_type : /obj/item/shard
|
|
new shard(loc)
|
|
new shard(loc)
|
|
qdel(src)
|
|
|
|
/obj/machinery/power/solar/update_overlays()
|
|
. = ..()
|
|
var/matrix/turner = matrix()
|
|
turner.Turn(azimuth_current)
|
|
panel.transform = turner
|
|
panel.icon_state = "solar_panel[(stat & BROKEN) ? "-b" : null]"
|
|
|
|
/obj/machinery/power/solar/proc/queue_turn(azimuth)
|
|
needs_to_turn = TRUE
|
|
azimuth_target = azimuth
|
|
|
|
/obj/machinery/power/solar/proc/queue_update_solar_exposure()
|
|
SIGNAL_HANDLER
|
|
|
|
needs_to_update_solar_exposure = TRUE //updating right away would be wasteful if we're also turning later
|
|
|
|
/obj/machinery/power/solar/proc/update_turn()
|
|
needs_to_turn = FALSE
|
|
if(azimuth_current != azimuth_target)
|
|
azimuth_current = azimuth_target
|
|
occlusion_setup()
|
|
update_appearance()
|
|
needs_to_update_solar_exposure = TRUE
|
|
|
|
///trace towards sun to see if we're in shadow
|
|
/obj/machinery/power/solar/proc/occlusion_setup()
|
|
obscured = list()
|
|
for(var/S in SSsun.suns)
|
|
if(check_obscured(S))
|
|
obscured |= S
|
|
|
|
///calculates the fraction of the sunlight that the panel receives
|
|
/obj/machinery/power/solar/proc/update_solar_exposure()
|
|
needs_to_update_solar_exposure = FALSE
|
|
total_flux = 0
|
|
for(var/S in SSsun.suns)
|
|
if(S in obscured)
|
|
continue
|
|
var/datum/sun/sun = S
|
|
var/sun_azimuth = sun.azimuth
|
|
var/cur_pow = 0
|
|
if(azimuth_current == sun_azimuth) //just a quick optimization for the most frequent case
|
|
cur_pow = sun.power_mod
|
|
else
|
|
//dot product of sun and panel -- Lambert's Cosine Law
|
|
cur_pow = cos(azimuth_current - sun_azimuth) * sun.power_mod
|
|
cur_pow = clamp(round(cur_pow, 0.01), 0, sun.power_mod)
|
|
total_flux += cur_pow
|
|
|
|
/obj/machinery/power/solar/process()
|
|
if(stat & BROKEN)
|
|
return
|
|
if(control && (!powernet || control.powernet != powernet))
|
|
unset_control()
|
|
if(needs_to_turn)
|
|
update_turn()
|
|
if(needs_to_update_solar_exposure)
|
|
update_solar_exposure()
|
|
if(total_flux <= 0)
|
|
return
|
|
|
|
var/sgen = SOLAR_GEN_RATE * total_flux * efficiency
|
|
add_avail(sgen)
|
|
if(control)
|
|
control.gen += sgen
|
|
|
|
//Bit of a hack but this whole type is a hack
|
|
/obj/machinery/power/solar/fake/Initialize(mapload, obj/item/solar_assembly/S)
|
|
. = ..()
|
|
UnregisterSignal(SSsun, COMSIG_SUN_MOVED)
|
|
|
|
/obj/machinery/power/solar/fake/process()
|
|
return PROCESS_KILL
|
|
|
|
//
|
|
// Solar Assembly - For construction of solar arrays.
|
|
//
|
|
|
|
/obj/item/solar_assembly
|
|
name = "solar panel assembly"
|
|
desc = "A solar panel assembly kit, allows constructions of a solar panel, or with a tracking circuit board, a solar tracker."
|
|
icon = 'goon/icons/obj/power.dmi'
|
|
icon_state = "sp_base"
|
|
item_state = "electropack"
|
|
lefthand_file = 'icons/mob/inhands/misc/devices_lefthand.dmi'
|
|
righthand_file = 'icons/mob/inhands/misc/devices_righthand.dmi'
|
|
w_class = WEIGHT_CLASS_BULKY // Pretty big!
|
|
anchored = FALSE
|
|
var/tracker = 0
|
|
var/obj/item/stack/sheet/glass_type
|
|
var/static/list/allowed_sheets = typecacheof(list(/obj/item/stack/sheet/glass, /obj/item/stack/sheet/rglass,
|
|
/obj/item/stack/sheet/plasmaglass, /obj/item/stack/sheet/plasmarglass,
|
|
/obj/item/stack/sheet/titaniumglass, /obj/item/stack/sheet/plastitaniumglass))
|
|
var/random_offset = 6 //amount in pixels an unanchored assembly may be offset by
|
|
|
|
/obj/item/solar_assembly/Initialize(mapload)
|
|
. = ..()
|
|
if(!anchored && !pixel_x && !pixel_y)
|
|
randomise_offset(random_offset)
|
|
|
|
/obj/item/solar_assembly/proc/randomise_offset(amount)
|
|
pixel_x = rand(-amount, amount)
|
|
pixel_y = rand(-amount, amount)
|
|
|
|
// Give back the glass type we were supplied with
|
|
/obj/item/solar_assembly/proc/give_glass(device_broken)
|
|
var/atom/Tsec = drop_location()
|
|
if(device_broken)
|
|
var/shard = glass_type ? glass_type.shard_type : /obj/item/shard
|
|
if(shard)
|
|
new shard(Tsec)
|
|
new shard(Tsec)
|
|
else if(glass_type)
|
|
glass_type.forceMove(Tsec)
|
|
glass_type = null
|
|
|
|
/obj/item/solar_assembly/set_anchored(anchorvalue)
|
|
. = ..()
|
|
if(isnull(.))
|
|
return
|
|
randomise_offset(anchored ? 0 : random_offset)
|
|
|
|
/obj/item/solar_assembly/attackby(obj/item/W, mob/user, params)
|
|
if(W.tool_behaviour == TOOL_WRENCH && isturf(loc))
|
|
if(isinspace())
|
|
to_chat(user, "<span class='warning'>You can't secure [src] here.</span>")
|
|
return
|
|
set_anchored(!anchored)
|
|
user.visible_message("[user] [anchored ? null : "un"]wrenches the solar assembly into place.", "You [anchored ? null : "un"]wrench the solar assembly into place.")
|
|
W.play_tool_sound(src, 75)
|
|
return TRUE
|
|
|
|
if(is_type_in_typecache(W, allowed_sheets))
|
|
if(!anchored)
|
|
to_chat(user, "<span class='warning'>You need to secure the assembly before you can add glass.</span>")
|
|
return
|
|
var/obj/item/stack/sheet/S = W
|
|
S = S.split_stack(amount=2)
|
|
if(S)
|
|
glass_type = S
|
|
S.moveToNullspace()
|
|
playsound(src.loc, 'sound/machines/click.ogg', 50, TRUE)
|
|
user.visible_message("<span class='notice'>[user] places the glass on the solar assembly.</span>", "<span class='notice'>You place the glass on the solar assembly.</span>")
|
|
if(tracker)
|
|
new /obj/machinery/power/tracker(get_turf(src), src)
|
|
else
|
|
new /obj/machinery/power/solar(get_turf(src), src)
|
|
else
|
|
to_chat(user, "<span class='warning'>You need two sheets of glass to put them into a solar panel!</span>")
|
|
return
|
|
return TRUE
|
|
|
|
if(!tracker)
|
|
if(istype(W, /obj/item/electronics/tracker))
|
|
if(!user.temporarilyRemoveItemFromInventory(W))
|
|
return
|
|
tracker = TRUE
|
|
qdel(W)
|
|
user.visible_message("[user] inserts the electronics into the solar assembly.", "<span class='notice'>You insert the electronics into the solar assembly.</span>")
|
|
return 1
|
|
else
|
|
if(W.tool_behaviour == TOOL_CROWBAR)
|
|
new /obj/item/electronics/tracker(src.loc)
|
|
tracker = FALSE
|
|
user.visible_message("[user] takes out the electronics from the solar assembly.", "<span class='notice'>You take out the electronics from the solar assembly.</span>")
|
|
return TRUE
|
|
return ..()
|
|
|
|
//
|
|
// Solar Control Computer
|
|
//
|
|
|
|
/obj/machinery/power/solar_control
|
|
name = "solar panel control"
|
|
desc = "A controller for solar panel arrays."
|
|
icon = 'icons/obj/computer.dmi'
|
|
icon_state = "computer"
|
|
density = TRUE
|
|
use_power = IDLE_POWER_USE
|
|
idle_power_usage = 250
|
|
max_integrity = 200
|
|
integrity_failure = 0.5
|
|
var/icon_screen = "solar"
|
|
var/icon_keyboard = "power_key"
|
|
var/id = 0
|
|
var/gen = 0
|
|
var/lastgen = 0
|
|
var/azimuth_target = 0
|
|
var/azimuth_rate = 1 ///degree change per minute
|
|
|
|
var/track = SOLAR_TRACK_OFF ///SOLAR_TRACK_OFF, SOLAR_TRACK_TIMED, SOLAR_TRACK_AUTO
|
|
|
|
var/obj/machinery/power/tracker/connected_tracker = null
|
|
var/list/connected_panels = list()
|
|
|
|
/obj/machinery/power/solar_control/Initialize(mapload)
|
|
. = ..()
|
|
azimuth_rate = SSsun.base_rotation
|
|
RegisterSignal(SSsun, COMSIG_SUN_MOVED, .proc/timed_track)
|
|
connect_to_network()
|
|
if(powernet)
|
|
set_panels(azimuth_target)
|
|
|
|
/obj/machinery/power/solar_control/Destroy()
|
|
for(var/obj/machinery/power/solar/M in connected_panels)
|
|
M.unset_control()
|
|
if(connected_tracker)
|
|
connected_tracker.unset_control()
|
|
return ..()
|
|
|
|
//search for unconnected panels and trackers in the computer powernet and connect them
|
|
/obj/machinery/power/solar_control/proc/search_for_connected()
|
|
if(powernet)
|
|
for(var/obj/machinery/power/M in powernet.nodes)
|
|
if(istype(M, /obj/machinery/power/solar))
|
|
var/obj/machinery/power/solar/S = M
|
|
if(!S.control) //i.e unconnected
|
|
S.set_control(src)
|
|
else if(istype(M, /obj/machinery/power/tracker))
|
|
if(!connected_tracker) //if there's already a tracker connected to the computer don't add another
|
|
var/obj/machinery/power/tracker/T = M
|
|
if(!T.control) //i.e unconnected
|
|
T.set_control(src)
|
|
|
|
/obj/machinery/power/solar_control/update_overlays()
|
|
. = ..()
|
|
if(stat & NOPOWER)
|
|
. += mutable_appearance(icon, "[icon_keyboard]_off")
|
|
return
|
|
|
|
. += mutable_appearance(icon, icon_keyboard)
|
|
if(stat & BROKEN)
|
|
. += mutable_appearance(icon, "[icon_state]_broken")
|
|
return
|
|
. += mutable_appearance(icon, icon_screen)
|
|
|
|
/obj/machinery/power/solar_control/ui_interact(mob/user, datum/tgui/ui)
|
|
ui = SStgui.try_update_ui(user, src, ui)
|
|
if(!ui)
|
|
ui = new(user, src, "SolarControl", name)
|
|
ui.open()
|
|
|
|
/obj/machinery/power/solar_control/ui_data()
|
|
var/data = list()
|
|
data["generated"] = round(lastgen)
|
|
data["generated_ratio"] = data["generated"] / round(max(connected_panels.len, 1) * SOLAR_GEN_RATE)
|
|
data["azimuth_current"] = azimuth_target
|
|
data["azimuth_rate"] = azimuth_rate
|
|
data["max_rotation_rate"] = SSsun.base_rotation * 2
|
|
data["tracking_state"] = track
|
|
data["connected_panels"] = connected_panels.len
|
|
data["connected_tracker"] = (connected_tracker ? TRUE : FALSE)
|
|
return data
|
|
|
|
/obj/machinery/power/solar_control/ui_act(action, params)
|
|
. = ..()
|
|
if(.)
|
|
return
|
|
if(action == "azimuth")
|
|
var/adjust = text2num(params["adjust"])
|
|
var/value = text2num(params["value"])
|
|
if(adjust)
|
|
value = azimuth_target + adjust
|
|
if(value != null)
|
|
set_panels(value)
|
|
return TRUE
|
|
return FALSE
|
|
if(action == "azimuth_rate")
|
|
var/adjust = text2num(params["adjust"])
|
|
var/value = text2num(params["value"])
|
|
if(adjust)
|
|
value = azimuth_rate + adjust
|
|
if(value != null)
|
|
azimuth_rate = round(clamp(value, -2 * SSsun.base_rotation, 2 * SSsun.base_rotation), 0.01)
|
|
return TRUE
|
|
return FALSE
|
|
if(action == "tracking")
|
|
var/mode = text2num(params["mode"])
|
|
track = mode
|
|
if(mode == SOLAR_TRACK_AUTO)
|
|
if(connected_tracker)
|
|
connected_tracker.sun_update(SSsun, SSsun.primary_sun, SSsun.suns)
|
|
else
|
|
track = SOLAR_TRACK_OFF
|
|
return TRUE
|
|
if(action == "refresh")
|
|
search_for_connected()
|
|
return TRUE
|
|
return FALSE
|
|
|
|
/obj/machinery/power/solar_control/attackby(obj/item/I, mob/living/user, params)
|
|
if(I.tool_behaviour == TOOL_SCREWDRIVER)
|
|
if(I.use_tool(src, user, 20, volume=50))
|
|
if (src.stat & BROKEN)
|
|
to_chat(user, "<span class='notice'>The broken glass falls out.</span>")
|
|
var/obj/structure/frame/computer/A = new /obj/structure/frame/computer( src.loc )
|
|
new /obj/item/shard( src.loc )
|
|
var/obj/item/circuitboard/computer/solar_control/M = new /obj/item/circuitboard/computer/solar_control( A )
|
|
for(var/obj/C in src)
|
|
C.forceMove(drop_location())
|
|
A.circuit = M
|
|
A.state = 3
|
|
A.icon_state = "3"
|
|
A.set_anchored(TRUE)
|
|
qdel(src)
|
|
else
|
|
to_chat(user, "<span class='notice'>You disconnect the monitor.</span>")
|
|
var/obj/structure/frame/computer/A = new /obj/structure/frame/computer( src.loc )
|
|
var/obj/item/circuitboard/computer/solar_control/M = new /obj/item/circuitboard/computer/solar_control( A )
|
|
for(var/obj/C in src)
|
|
C.forceMove(drop_location())
|
|
A.circuit = M
|
|
A.state = 4
|
|
A.icon_state = "4"
|
|
A.set_anchored(TRUE)
|
|
qdel(src)
|
|
else if(user.a_intent != INTENT_HARM && !(I.item_flags & NOBLUDGEON))
|
|
attack_hand(user)
|
|
else
|
|
return ..()
|
|
|
|
/obj/machinery/power/solar_control/play_attack_sound(damage_amount, damage_type = BRUTE, damage_flag = 0)
|
|
switch(damage_type)
|
|
if(BRUTE)
|
|
if(stat & BROKEN)
|
|
playsound(src.loc, 'sound/effects/hit_on_shattered_glass.ogg', 70, TRUE)
|
|
else
|
|
playsound(src.loc, 'sound/effects/glasshit.ogg', 75, TRUE)
|
|
if(BURN)
|
|
playsound(src.loc, 'sound/items/welder.ogg', 100, TRUE)
|
|
|
|
/obj/machinery/power/solar_control/obj_break(damage_flag)
|
|
. = ..()
|
|
if(.)
|
|
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
|
|
|
|
/obj/machinery/power/solar_control/process()
|
|
lastgen = gen
|
|
gen = 0
|
|
|
|
if(connected_tracker && (!powernet || connected_tracker.powernet != powernet))
|
|
connected_tracker.unset_control()
|
|
|
|
///Ran every time the sun updates.
|
|
/obj/machinery/power/solar_control/proc/timed_track()
|
|
SIGNAL_HANDLER
|
|
|
|
if(track == SOLAR_TRACK_TIMED)
|
|
azimuth_target += azimuth_rate
|
|
set_panels(azimuth_target)
|
|
|
|
///Rotates the panel to the passed angles
|
|
/obj/machinery/power/solar_control/proc/set_panels(azimuth)
|
|
azimuth = clamp(round(azimuth, 0.01), -360, 719.99)
|
|
if(azimuth >= 360)
|
|
azimuth -= 360
|
|
if(azimuth < 0)
|
|
azimuth += 360
|
|
azimuth_target = azimuth
|
|
|
|
for(var/obj/machinery/power/solar/S in connected_panels)
|
|
S.queue_turn(azimuth)
|
|
|
|
//
|
|
// MISC
|
|
//
|
|
|
|
/obj/item/paper/guides/jobs/engi/solars
|
|
name = "paper- 'Going green! Setup your own solar array instructions.'"
|
|
info = "<h1>Welcome</h1><p>At greencorps we love the environment, and space. With this package you are able to help mother nature and produce energy without any usage of fossil fuel or plasma! Singularity energy is dangerous while solar energy is safe, which is why it's better. Now here is how you setup your own solar array.</p><p>You can make a solar panel by wrenching the solar assembly onto a cable node. Adding a glass panel, reinforced or regular glass will do, will finish the construction of your solar panel. It is that easy!</p><p>Now after setting up 19 more of these solar panels you will want to create a solar tracker to keep track of our mother nature's gift, the sun. These are the same steps as before except you insert the tracker equipment circuit into the assembly before performing the final step of adding the glass. You now have a tracker! Now the last step is to add a computer to calculate the sun's movements and to send commands to the solar panels to change direction with the sun. Setting up the solar computer is the same as setting up any computer, so you should have no trouble in doing that. You do need to put a wire node under the computer, and the wire needs to be connected to the tracker.</p><p>Congratulations, you should have a working solar array. If you are having trouble, here are some tips. Make sure all solar equipment are on a cable node, even the computer. You can always deconstruct your creations if you make a mistake.</p><p>That's all to it, be safe, be green!</p>"
|
|
|
|
#undef SOLAR_GEN_RATE
|