mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-03-30 17:04:06 +01:00
About The Pull Request I've reworked multiz. This was done because our current implementation of multiz flattens planes down into just the openspace plane. This breaks any effects we attach to plane masters (including lighting), but it also totally kills the SIDE_MAP map format, which we NEED for wallening (A major 3/4ths resprite of all wall and wall adjacent things, making them more then one tile high. Without sidemap we would be unable to display things both in from of and behind objects on map. Stupid.) This required MASSIVE changes. Both to all uses of the plane var for reasons I'll discuss later, and to a ton of different systems that interact with rendering. I'll do my best to keep this compact, but there's only so much I can do. Sorry brother. Core idea OK: first thing. vis_contents as it works now squishes the planes of everything inside it down into the plane of the vis_loc. This is bad. But how to do better? It's trivially easy to make copies of our existing plane masters but offset, and relay them to the bottom of the plane above. Not a problem. The issue is how to get the actual atoms on the map to "land" on them properly. We could use FLOAT_PLANE to offset planes based off how they're being seen, in theory this would allow us to create lens for how objects are viewed. But that's not a stable thing to do, because properly "landing" a plane on a desired plane master would require taking into account every bit of how it's being seen, would inherently break this effect. Ok so we need to manually edit planes based off "z layer" (IE: what layer of a z stack are you on). That's the key conceit of this pr. Implementing the plane cube, and ensuring planes are always offset properly. Everything else is just gravy. About the Plane Cube Each plane master (except ones that opt out) is copied down by some constant value equal to the max absolute change between the first and the last plane. We do this based off the max z stack size detected by SSmapping. This is also where updates come from, and where all our updating logic will live. As mentioned, plane masters can choose to opt out of being mirrored down. In this case, anything that interacts with them assuming that they'll be offset will instead just get back the valid plane value. This works for render targets too, since I had to work them into the system as well. Plane masters can also be temporarily hidden from the client's screen. This is done as an attempt at optimization, and applies to anything used in niche cases, or planes only used if there's a z layer below you. About Plane Master Groups BYOND supports having different "maps" on screen at once (IE: groups of items/turfs/etc) Plane masters cannot cover 2 maps at once, since their location is determined by their screen_loc. So we need to maintain a mirror of each plane for every map we have open. This was quite messy, so I've refactored it (and maps too) to be a bit more modular. Rather then storing a list of plane masters, we store a list of plane master group datums. Each datum is in charge of the plane masters for its particular map, both creating them, and managing them. Like I mentioned, I also refactored map views. Adding a new mapview is now as simple as newing a /atom/movable/screen/map_view, calling generate_view with the appropriate map id, setting things you want to display in its vis_contents, and then calling display_to on it, passing in the mob to show ourselves to. Much better then the hardcoded pattern we used to use. So much duplicated code man. Oh and plane master controllers, that system we have that allows for applying filters to sets of plane masters? I've made it use lookups on plane master groups now, rather then hanging references to all impacted planes. This makes logic easier, and prevents the need to manage references and update the controllers. image In addition, I've added a debug ui for plane masters. It allows you to view all of your own plane masters and short descriptions of what they do, alongside tools for editing them and their relays. It ALSO supports editing someone elses plane masters, AND it supports (in a very fragile and incomplete manner) viewing literally through someone else's eyes, including their plane masters. This is very useful, because it means you can debug "hey my X is yorked" issues yourself, on live. In order to accomplish this I have needed to add setters for an ungodly amount of visual impacting vars. Sight flags, eye, see_invis, see_in_dark, etc. It also comes with an info dump about the ui, and plane masters/relays in general. Sort of on that note. I've documented everything I know that's niche/useful about our visual effects and rendering system. My hope is this will serve to bring people up to speed on what can be done more quickly, alongside making my sin here less horrible. See https://github.com/LemonInTheDark/tgstation/blob/multiz-hell/.github/guides/VISUALS.md. "Landing" planes Ok so I've explained the backend, but how do we actually land planes properly? Most of the time this is really simple. When a plane var is set, we need to provide some spokesperson for the appearance's z level. We can use this to derive their z layer, and thus what offset to use. This is just a lot of gruntwork, but it's occasionally more complex. Sometimes we need to cache a list of z layer -> effect, and then use that. Also a LOT of updating on z move. So much z move shit. Oh. and in order to make byond darkness work properly, I needed to add SEE_BLACKNESS to all sight flags. This draws darkness to plane 0, which means I'm able to relay it around and draw it on different z layers as is possible. fun darkness ripple effects incoming someday I also need to update mob overlays on move. I do this by realiizing their appearances, mutating their plane, and then readding the overlay in the correct order. The cost of this is currently 3N. I'm convinced this could be improved, but I've not got to it yet. It can also occasionally cause overlays to corrupt. This is fixed by laying a protective ward of overlays.Copy in the sand, but that spell makes the compiler confused, so I'll have to bully lummy about fixing it at some point. Behavior changes We've had to give up on the already broken gateway "see through" effect. Won't work without managing gateway plane masters or something stupid. Not worth it. So instead we display the other side as a ui element. It's worse, but not that bad. Because vis_contents no longer flattens planes (most of the time), some uses of it now have interesting behavior. The main thing that comes to mind is alert popups that display mobs. They can impact the lighting plane. I don't really care, but it should be fixable, I think, given elbow grease. Ah and I've cleaned up layers and plane defines to make them a bit easier to read/reason about, at least I think. Why It's Good For The Game <visual candy> Fixes #65800 Fixes #68461 Changelog cl refactor: Refactored... well a lot really. Map views, anything to do with planes, multiz, a shit ton of rendering stuff. Basically if you see anything off visually report it admin: VV a mob, and hit View/Edit Planes in the dropdown to steal their view, and modify it as you like. You can do the same to yourself using the Edit/Debug Planes verb /cl
564 lines
19 KiB
Plaintext
564 lines
19 KiB
Plaintext
#define SOLAR_GEN_RATE 1500
|
|
#define OCCLUSION_DISTANCE 20
|
|
#define PANEL_Y_OFFSET 13
|
|
#define PANEL_EDGE_Y_OFFSET (PANEL_Y_OFFSET - 2)
|
|
|
|
/obj/machinery/power/solar
|
|
name = "solar panel"
|
|
desc = "A solar panel. Generates electricity when in contact with sunlight."
|
|
icon = 'icons/obj/solar.dmi'
|
|
icon_state = "sp_base"
|
|
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/obscured = FALSE
|
|
///`[0-1]` measure of obscuration -- multipllier against power generation
|
|
var/sunfrac = 0
|
|
///`[0-360)` degrees, which direction are we facing?
|
|
var/azimuth_current = 0
|
|
var/azimuth_target = 0 //same but what way we're going to face next time we turn
|
|
var/obj/machinery/power/solar_control/control
|
|
///do we need to turn next tick?
|
|
var/needs_to_turn = TRUE
|
|
///do we need to call update_solar_exposure() next tick?
|
|
var/needs_to_update_solar_exposure = TRUE
|
|
var/obj/effect/overlay/panel
|
|
var/obj/effect/overlay/panel_edge
|
|
|
|
/obj/machinery/power/solar/Initialize(mapload, obj/item/solar_assembly/S)
|
|
. = ..()
|
|
|
|
panel_edge = add_panel_overlay("solar_panel_edge", PANEL_EDGE_Y_OFFSET)
|
|
panel = add_panel_overlay("solar_panel", PANEL_Y_OFFSET)
|
|
|
|
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 ..()
|
|
|
|
/obj/machinery/power/solar/on_changed_z_level(turf/old_turf, turf/new_turf, same_z_layer, notify_contents)
|
|
. = ..()
|
|
if(same_z_layer)
|
|
return
|
|
SET_PLANE(panel_edge, PLANE_TO_TRUE(panel_edge.plane), new_turf)
|
|
SET_PLANE(panel, PLANE_TO_TRUE(panel.plane), new_turf)
|
|
|
|
/obj/machinery/power/solar/proc/add_panel_overlay(icon_state, y_offset)
|
|
var/obj/effect/overlay/overlay = new()
|
|
overlay.vis_flags = VIS_INHERIT_ID | VIS_INHERIT_ICON
|
|
overlay.appearance_flags = TILE_BOUND
|
|
overlay.icon_state = icon_state
|
|
overlay.layer = FLY_LAYER
|
|
SET_PLANE_EXPLICIT(overlay, ABOVE_GAME_PLANE, src)
|
|
overlay.pixel_y = y_offset
|
|
vis_contents += overlay
|
|
return overlay
|
|
|
|
/obj/machinery/power/solar/should_have_node()
|
|
return TRUE
|
|
|
|
//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)
|
|
S = new /obj/item/solar_assembly(src)
|
|
S.glass_type = /obj/item/stack/sheet/glass
|
|
S.set_anchored(TRUE)
|
|
else
|
|
S.forceMove(src)
|
|
if(S.glass_type == /obj/item/stack/sheet/rglass) //if the panel is in reinforced glass
|
|
max_integrity *= 2 //this need to be placed here, because panels already on the map don't have an assembly linked to
|
|
atom_integrity = max_integrity
|
|
|
|
/obj/machinery/power/solar/crowbar_act(mob/user, obj/item/I)
|
|
playsound(src.loc, 'sound/machines/click.ogg', 50, TRUE)
|
|
user.visible_message(span_notice("[user] begins to take the glass off [src]."), span_notice("You begin to take the glass off [src]..."))
|
|
if(I.use_tool(src, user, 50))
|
|
playsound(src.loc, 'sound/items/deconstruct.ogg', 50, TRUE)
|
|
user.visible_message(span_notice("[user] takes the glass off [src]."), span_notice("You take the glass off [src]."))
|
|
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(machine_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/atom_break(damage_flag)
|
|
. = ..()
|
|
if(.)
|
|
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
|
|
unset_control()
|
|
// Make sure user can see it's broken
|
|
var/new_angle = rand(160, 200)
|
|
visually_turn(new_angle)
|
|
azimuth_current = new_angle
|
|
|
|
/obj/machinery/power/solar/deconstruct(disassembled = TRUE)
|
|
if(!(flags_1 & NODECONSTRUCT_1))
|
|
if(disassembled)
|
|
var/obj/item/solar_assembly/S = locate() in src
|
|
if(S)
|
|
S.forceMove(loc)
|
|
S.give_glass(machine_stat & BROKEN)
|
|
else
|
|
playsound(src, SFX_SHATTER, 70, TRUE)
|
|
new /obj/item/shard(src.loc)
|
|
new /obj/item/shard(src.loc)
|
|
qdel(src)
|
|
|
|
/obj/machinery/power/solar/update_overlays()
|
|
. = ..()
|
|
panel.icon_state = "solar_panel[(machine_stat & BROKEN) ? "-b" : null]"
|
|
panel_edge.icon_state = "solar_panel[(machine_stat & BROKEN) ? "-b" : "_edge"]"
|
|
|
|
/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
|
|
|
|
/**
|
|
* Get the 2.5D transform for the panel, given an angle
|
|
* Arguments:
|
|
* * angle - the angle the panel is facing
|
|
*/
|
|
/obj/machinery/power/solar/proc/get_panel_transform(angle)
|
|
// 2.5D solar panel works by using a magic combination of transforms
|
|
var/matrix/turner = matrix()
|
|
// Rotate towards sun
|
|
turner.Turn(angle)
|
|
// "Tilt" the panel in 3D towards East and West
|
|
turner.Shear(0, -0.6 * sin(angle))
|
|
// Make it skinny when facing north (away), fat south
|
|
turner.Scale(1, 0.85 * (cos(angle) * -0.5 + 0.5) + 0.15)
|
|
|
|
return turner
|
|
|
|
/obj/machinery/power/solar/proc/visually_turn_part(part, angle)
|
|
var/mid_azimuth = (azimuth_current + angle) / 2
|
|
|
|
// actually flip to other direction?
|
|
if(abs(angle - azimuth_current) > 180)
|
|
mid_azimuth = (mid_azimuth + 180) % 360
|
|
|
|
// Split into 2 parts so it doesn't distort on large changes
|
|
animate(part,
|
|
transform = get_panel_transform(mid_azimuth),
|
|
time = 2.5 SECONDS, easing = CUBIC_EASING|EASE_IN
|
|
)
|
|
animate(
|
|
transform = get_panel_transform(angle),
|
|
time = 2.5 SECONDS, easing = CUBIC_EASING|EASE_OUT
|
|
)
|
|
|
|
/obj/machinery/power/solar/proc/visually_turn(angle)
|
|
visually_turn_part(panel, angle)
|
|
visually_turn_part(panel_edge, angle)
|
|
|
|
/obj/machinery/power/solar/proc/update_turn()
|
|
needs_to_turn = FALSE
|
|
if(azimuth_current != azimuth_target)
|
|
visually_turn(azimuth_target)
|
|
azimuth_current = azimuth_target
|
|
occlusion_setup()
|
|
needs_to_update_solar_exposure = TRUE
|
|
|
|
///trace towards sun to see if we're in shadow
|
|
/obj/machinery/power/solar/proc/occlusion_setup()
|
|
obscured = TRUE
|
|
|
|
var/distance = OCCLUSION_DISTANCE
|
|
var/target_x = round(sin(SSsun.azimuth), 0.01)
|
|
var/target_y = round(cos(SSsun.azimuth), 0.01)
|
|
var/x_hit = x
|
|
var/y_hit = y
|
|
var/turf/hit
|
|
|
|
for(var/run in 1 to distance)
|
|
x_hit += target_x
|
|
y_hit += target_y
|
|
hit = locate(round(x_hit, 1), round(y_hit, 1), z)
|
|
if(IS_OPAQUE_TURF(hit))
|
|
return
|
|
if(hit.x == 1 || hit.x == world.maxx || hit.y == 1 || hit.y == world.maxy) //edge of the map
|
|
break
|
|
obscured = FALSE
|
|
|
|
///calculates the fraction of the sunlight that the panel receives
|
|
/obj/machinery/power/solar/proc/update_solar_exposure()
|
|
needs_to_update_solar_exposure = FALSE
|
|
sunfrac = 0
|
|
if(obscured)
|
|
return 0
|
|
|
|
var/sun_azimuth = SSsun.azimuth
|
|
if(azimuth_current == sun_azimuth) //just a quick optimization for the most frequent case
|
|
. = 1
|
|
else
|
|
//dot product of sun and panel -- Lambert's Cosine Law
|
|
. = cos(azimuth_current - sun_azimuth)
|
|
. = clamp(round(., 0.01), 0, 1)
|
|
sunfrac = .
|
|
|
|
/obj/machinery/power/solar/process()
|
|
if(machine_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(sunfrac <= 0)
|
|
return
|
|
|
|
var/sgen = SOLAR_GEN_RATE * sunfrac
|
|
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 = 'icons/obj/solar.dmi'
|
|
icon_state = "sp_base"
|
|
inhand_icon_state = "electropack"
|
|
lefthand_file = 'icons/mob/inhands/items/devices_lefthand.dmi'
|
|
righthand_file = 'icons/mob/inhands/items/devices_righthand.dmi'
|
|
w_class = WEIGHT_CLASS_BULKY // Pretty big!
|
|
anchored = FALSE
|
|
var/tracker = 0
|
|
var/glass_type = null
|
|
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/update_icon_state()
|
|
. = ..()
|
|
icon_state = tracker ? "tracker_base" : "sp_base"
|
|
|
|
/obj/item/solar_assembly/proc/randomise_offset(amount)
|
|
pixel_x = base_pixel_x + rand(-amount, amount)
|
|
pixel_y = base_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)
|
|
new /obj/item/shard(Tsec)
|
|
new /obj/item/shard(Tsec)
|
|
else if(glass_type)
|
|
new glass_type(Tsec, 2)
|
|
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_warning("You can't secure [src] here."))
|
|
return
|
|
set_anchored(!anchored)
|
|
user.visible_message(
|
|
span_notice("[user] [anchored ? null : "un"]wrenches the solar assembly [anchored ? "into place" : null]."),
|
|
span_notice("You [anchored ? null : "un"]wrench the solar assembly [anchored ? "into place" : null]."),
|
|
)
|
|
W.play_tool_sound(src, 75)
|
|
return TRUE
|
|
|
|
if(istype(W, /obj/item/stack/sheet/glass) || istype(W, /obj/item/stack/sheet/rglass))
|
|
if(!anchored)
|
|
to_chat(user, span_warning("You need to secure the assembly before you can add glass."))
|
|
return
|
|
var/turf/solarturf = get_turf(src)
|
|
if(locate(/obj/machinery/power/solar) in solarturf)
|
|
to_chat(user, span_warning("A solar panel is already assembled here."))
|
|
return
|
|
var/obj/item/stack/sheet/S = W
|
|
if(S.use(2))
|
|
glass_type = W.type
|
|
playsound(src.loc, 'sound/machines/click.ogg', 50, TRUE)
|
|
user.visible_message(span_notice("[user] places the glass on the solar assembly."), span_notice("You place the glass on the solar assembly."))
|
|
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_warning("You need two sheets of glass to put them into a solar panel!"))
|
|
return
|
|
return TRUE
|
|
|
|
if(!tracker)
|
|
if(istype(W, /obj/item/electronics/tracker))
|
|
if(!user.temporarilyRemoveItemFromInventory(W))
|
|
return
|
|
tracker = TRUE
|
|
update_appearance()
|
|
qdel(W)
|
|
user.visible_message(span_notice("[user] inserts the electronics into the solar assembly."), span_notice("You insert the electronics into the solar assembly."))
|
|
return TRUE
|
|
else
|
|
if(W.tool_behaviour == TOOL_CROWBAR)
|
|
new /obj/item/electronics/tracker(src.loc)
|
|
tracker = FALSE
|
|
update_appearance()
|
|
user.visible_message(span_notice("[user] takes out the electronics from the solar assembly."), span_notice("You take out the electronics from the solar assembly."))
|
|
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 = BASE_MACHINE_IDLE_CONSUMPTION
|
|
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(machine_stat & NOPOWER)
|
|
. += mutable_appearance(icon, "[icon_keyboard]_off")
|
|
return
|
|
|
|
. += mutable_appearance(icon, icon_keyboard)
|
|
if(machine_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.azimuth)
|
|
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.machine_stat & BROKEN)
|
|
to_chat(user, span_notice("The broken glass falls out."))
|
|
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_notice("You disconnect the monitor."))
|
|
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.combat_mode && !(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(machine_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/atom_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.'"
|
|
default_raw_text = "<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
|
|
#undef OCCLUSION_DISTANCE
|
|
#undef PANEL_Y_OFFSET
|
|
#undef PANEL_EDGE_Y_OFFSET
|