Files
Bubberstation/code/modules/power/solar.dm
LemonInTheDark 4b4e9dff1d Wallening [IDB IGNORE] [MDB IGNORE] (#85491)
## What's going on here

Kept you waitin huh!

This pr resprites most all walls, windows and other "wall adjacent"
things to a 3/4th perspective, technical term is "tall" walls (we are
very smart).

If you're trying to understand the technical details here, much of the
"rendering tech" is built off the idea of split-vis. Basically, split a
sprite up and render it on adjacent turfs, to prevent seeing "through"
walls/doors, and to support seeing "edges" without actually seeing the
atom itself.

Most of the rest of it is pipelining done to accommodate how icons are
cut.

## Path To Merge

Almost* all sprites and code is done at this point. 
There are some things missing both on and off the bounty list, but that
will be the case forever unless we force upstream (you guys) to stop
adding new shit that doesn't fit the style.
I plan on accepting and integrating prs to the current working repo
<https://github.com/wall-nerds/wallening> up until a merge, to make
contribution simpler and allow things like bounties to close out more
easily

This pr is quite bulky, even stripping away map changes it's maybe 7000
LOC (We have a few maps that were modified with UpdatePaths, I am also
tentatively pring our test map, for future use.)
This may inhibit proper review, although that is part of why I am
willing to make it despite my perfectionism. Apologies in advance.

Due to the perspective shift, a lot of mapping work is going to need to
be done at some point. This comes in varying levels of priority. Many
wallmounts are offset by hand, some are stuck in the wall/basically
cannot be placed on the east/west/north edges of walls (posters), some
just don't look great good in their current position.

Tests are currently a minor bit yorked, I thought it was more important
to get this up then to clean them fully.

## What does it look like?


![dreamseeker_hBsU6wCu91](https://github.com/user-attachments/assets/5392fa3b-60f6-40ea-876f-e686f25f996a)

![dreamseeker_CTiK0Je5iR](https://github.com/user-attachments/assets/1aee23bd-a5ec-4679-b094-d044401b7222)

![dreamseeker_HYkS1Q9GRq](https://github.com/user-attachments/assets/bad8844b-3179-4856-8684-f912e14e844a)

![dreamseeker_Pa18tgyKYp](https://github.com/user-attachments/assets/c2e1d222-9e5c-4500-8829-dd065428644a)

![dreamseeker_BfOBwS2mjH](https://github.com/user-attachments/assets/7dc51153-111d-4b17-93c3-8389daa6b60b)

![dreamseeker_iJazOumiMQ](https://github.com/user-attachments/assets/5837e203-3865-4f60-854e-62b4875c6b99)

## Credits

<details>
<summary>Historical Mumbojumbo</summary>

I am gonna do my best to document how this project came to be. I am
operating off third party info and half remembered details, so if I'm
wrong please yell at me.

This project started sometime in late 2020, as a product of Rohesie
trying to integrate and make easier work from Mojave Sun (A recently
defunct fallout server) with /tg/.

Mojave Sun (Apparently this was LITERALLY JUST infrared baron, that man
is insane) was working with tall walls, IE walls that are 48px tall
instead of the normal 32. This was I THINK done based off a technical
prototype from aao7 proving A it was possible and B it didn't look like
dogwater.

This alongside oranges begging the art team for 3/4th walls (he meant
TGMC style) lead to Rohesie bringing on contributors from general /tg/,
including actionninja who would eventually take over as technical lead
and Kryson, who would define /tg/'s version of the artstyle. Much of the
formative aspects of this project are their work.

The project was coming along pretty well for a few months, but ran into
serious technical issues with `SIDE_MAP`, a byond map_format that allows
for simpler 3/4th rendering.
Due to BULLSHIT I will not detail here, the map format caused issues
both at random with flickering and heavily with multiz.

Concurrent with this, action stepped down after hacking out the
rendering tech and starting work on an icon cutter that would allow for
simpler icon generation, leaving ninjanomnom to manage the project.

Some time passed, and the project stalled out due to the technical
issues. Eventually I built a test case for the issues we had with
`SIDE_MAP` and convinced lummox jr (byond's developer) to explain how
the fuckin thing actually worked. This understanding made the project
theoretically possible, but did not resolve the problems with multi-z.
Resolving those required a full rework of how rendering like, worked. I
(alongside tattle) took over project development from ninjanomnom at
this time, and started work on Plane Cube (#69115), which when finished
would finally make the project technically feasible.

The time between then and now has been slow, progressive work. Many many
artists and technical folks have dumped their time into this (as you can
see from the credits). I will get into this more below but I would like
to explicitly thank (in no particular order) tattle, draco, arcanemusic,
actionninja, imaginos, viro and kylerace for keeping the project alive
in this time period. I would have curled up into a ball and died if I
had to do this all myself, your help has been indispensable.

</details>

<details>
<summary>Detailed Credits</summary>

Deep apologies if I have forgotten someone (I am sure I have, if someone
is you please contact me). I've done my best to collate from the git
log/my memory.

Thanks to (In no particular order):
Raccoff: Being funny to bully, creating threshold decals for airlocks
aa07: (I think) inspiring the project
ActionNinja: Laying the technical rock we build off, supporting me
despite byond trying to kill him, building the icon cutter that makes
this possible
ArcaneMusic: Artistic and technical work spanning from the project's
start to literally today, being a constant of motivation and positivity.
I can't list all the stuff he's done
Armhulen: Key rendering work (he's the reason thindows render right), an
upbeat personality and a kick in the ass. Love you arm
Azlan: Damn cool sprites, consistently
Ben10Omintrix: You know ben showed up just to make basic mobs work, he's
just fuckin like that man
BigBimmer: A large amount of bounty work, alongside just like, throwing
shit around. An absolute joy to work with
Capsandi: Plaques, blastdoors, artistic work early on
CapybaraExtravagante: Rendering work on wall frames
Draco: SO MUCH STUFF. Much of the spritework done over the past two
years is his, constantly engaged and will take on anything. I would have
given up if not for you
Floyd: Early rendering work, so early I don't even know the details.
Enjoy freedom brother
Imaginos16: A guiding hand through the middle years, handled much of the
sprite review and contribution for a good bit there
Iamgoofball: A dedication to detail and aesthetic goals, spends a lot of
effort dissecting feedback with a focus on making things as good as they
can be at the jump
Infrared: Part of the impetus for the project, made all the xenomorph
stuff in the MS style
Jacquerel: A bunch of little upkeep/technical things, has done so much
sprite gruntwork (WHY ARE THERE SO MANY PAINTING TYPES)
Justice12354: Solved a bunch of error sprites (and worked out how to
actually make prs to the project) Thanks bro!
Kryson: Built the artstyle of the project, carrying on for years even
when it was technically dying, only stopping to casually beat cancer. So
much of our style and art is Kryson
KylerAce: Handled annoying technical stuff for me, built window frame
logic and fully got rid of grilles.
LemonInTheDark: Rendering dirtywork, project management and just so much
fucking time in dreammaker editing sprites
Meyhazah: Table buttons, brass windows and alll the old style doors
Mothblocks: Has provided constant support, gave me a deadline and
motivation, erased worries about "it not being done", gave just SO much
money to fill in the critical holes in sprites. Thanks moth
MTandi: Contributed art despite his own blackjack and hookers club
opening right down the road, I'm sorry I rolled over some of your
sprites man I wish we had finished earlier
Ninjanomnomnom: Consulted on gags issues, kept things alive through some
truly shit times
oranges: This is his fault
Rohesie: Organized the effort, did much of the initial like, proof of
concept stuff. I hope you're doin well whatever you're up to.
san7890: Consulting on mapper UX/design problems, being my pet mapper
Senefi: Offsetting items with a focus on detail/the more unused
canidates
SimplyLogan: Detailed map work and mapper feedback, personally very kind
even if we end up talking past each other sometimes. Thank you!
SpaceSmithers: Just like, random mapping support out of nowhere, and
bein a straight up cool dude
Tattle: A bunch of misc project management stuff, organizing the
discord, managing the test server, dealing with all the mapping bullshit
for me, being my backup in case of bus. I know you think you didn't do
much but your presence and work have been a great help
Thunder12345: Came out of nowhere and just so much of the random
bounties, I'm kind of upset about how much we paid him
Time-Green: I hooked him in by fucking with stuff he made and now he's
just doin shit, thanks for helping out man!
Twaticus: Provided artistic feedback and authority for my poor feeble
coder brain, believed in the project for YEARS, was a constant source of
❤️ and affirmation
unit0016: I have no god damn idea who she is, popped out of nowhere on
the github one day and dealt with a bunch of annoying
rendering/refactoring. Godspeed random furry thank you for all your
effort and issue reports
Viro: A bunch of detailed spriting moving towards 3/4ths, both on and
off the wallening fork. If anyone believed this project would be done,
it was viro
Wallem: Artistic review and consultation, was my go-to guy for a long
time when the other two spritetainers were inactive
Waltermeldon: Cracked out a bunch of rendering work, he's the reason
windows look like not dogwater. Alongside floyd and action spent a TON
of time speaking to lummox/unearthing how byond rendering worked trying
to make this thing happen
ZephyrTFA: Added directional airlock helpers, dealt with a big fuckin
bugaboo that was living in my brain like it was nothing. Love you
brother

And finally:
The Mojave Sun development team. They provided a testbed for the idea,
committed hundreds and hundreds of hours to the artstyle, and were a
large reason we caught issues early enough to meaningfully deal with
them. Your work is a testament to what longterm effort and deep detailed
care produce. I hope you're doing well whatever you're up to. Go out
with a bang!
</details>

## Changelog
🆑 Raccoff, aa07, ActionNinja, ArcaneMusic, Armhulen, Azlan,
Ben10Omintrix, BigBimmer, Capsandi, CapybaraExtravagante, Draco, Floyd,
Iamgoofball, Imaginos16, Infrared, Jacquerel, Justice12354, Kryson,
KylerAce, LemonInTheDark, Meyhazah, Mothblocks, MTandi, Ninjanomnom,
oranges, Rohesie, Runi-c, san7890, Senefi, SimplyLogan, SomeAngryMiner,
SpaceSmithers, Tattle, Thunder12345, Time-Green, Twaticus, unit0016,
Viro, Waltermeldon, ZephyrTFA with thanks to the Mojave Sun team!
add: Resprites or offsets almost all "tall" objects in the game to match
a 3/4ths perspective
add: Bunch of rendering mumbo jumbo to make said 3/4ths perspective work
/🆑

---------

Co-authored-by: Jacquerel <hnevard@gmail.com>
Co-authored-by: san7890 <the@san7890.com>
Co-authored-by: = <stewartareid@outlook.com>
Co-authored-by: Capsandi <dansullycc@gmail.com>
Co-authored-by: ArcaneMusic <hero12290@aol.com>
Co-authored-by: tattle <66640614+dragomagol@users.noreply.github.com>
Co-authored-by: SomeAngryMiner <53237389+SomeAngryMiner@users.noreply.github.com>
Co-authored-by: KylerAce <kylerlumpkin1@gmail.com>
Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com>
Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com>
Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com>
Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
Co-authored-by: Runi-c <5150427+Runi-c@users.noreply.github.com>
Co-authored-by: Roryl-c <5150427+Roryl-c@users.noreply.github.com>
Co-authored-by: tattle <article.disaster@gmail.com>
Co-authored-by: Senefi <20830349+Peliex@users.noreply.github.com>
Co-authored-by: Justice <42555530+Justice12354@users.noreply.github.com>
Co-authored-by: BluBerry016 <50649185+unit0016@users.noreply.github.com>
Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com>
Co-authored-by: Emmett Gaines <ninjanomnom@gmail.com>
Co-authored-by: Rob Bailey <github@criticalaction.net>
Co-authored-by: MMMiracles <lolaccount1@hotmail.com>
2024-08-14 09:07:45 +00:00

611 lines
21 KiB
Plaintext

#define SOLAR_GEN_RATE 1500
#define OCCLUSION_DISTANCE 20
#define PANEL_Z_OFFSET 13
#define PANEL_EDGE_Z_OFFSET (PANEL_Z_OFFSET - 2)
/obj/machinery/power/solar
name = "solar panel"
desc = "A solar panel. Generates electricity when in contact with sunlight."
icon = 'icons/obj/machines/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_Z_OFFSET)
panel = add_panel_overlay("solar_panel", PANEL_Z_OFFSET)
Make(S)
connect_to_network()
RegisterSignal(SSsun, COMSIG_SUN_MOVED, PROC_REF(queue_update_solar_exposure))
/obj/machinery/power/solar/Destroy()
unset_control() //remove from control computer
QDEL_NULL(panel)
QDEL_NULL(panel_edge)
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/effect/overlay/solar_panel
vis_flags = VIS_INHERIT_ID | VIS_INHERIT_ICON
appearance_flags = TILE_BOUND
blocks_emissive = EMISSIVE_BLOCK_UNIQUE
/obj/machinery/power/solar/proc/add_panel_overlay(icon_state, z_offset)
var/obj/effect/overlay/solar_panel/overlay = new(src)
overlay.icon_state = icon_state
SET_PLANE_EXPLICIT(overlay, GAME_PLANE, src)
overlay.pixel_z = z_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/on_deconstruction(disassembled)
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)
/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
// space vines block out sunlight
var/obj/structure/spacevine/vine = locate(/obj/structure/spacevine) in loc
if(istype(vine) && !(/datum/spacevine_mutation/transparency in vine.mutations))
unset_control()
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(power_to_energy(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/machines/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
SET_BASE_VISUAL_PIXEL(0, DEPTH_OFFSET)
name = "solar panel control"
desc = "A controller for solar panel arrays."
icon = 'icons/obj/machines/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()
///History of power supply
var/list/history = list()
///Size of history, should be equal or bigger than the solar cycle
var/record_size = 0
///Interval between records
var/record_interval = 60 SECONDS
///History record timer
var/next_record = 0
/obj/machinery/power/solar_control/Initialize(mapload)
. = ..()
RegisterSignal(SSsun, COMSIG_SUN_MOVED, PROC_REF(timed_track))
connect_to_network()
if(powernet)
set_panels(azimuth_target)
azimuth_rate = SSsun.base_rotation
record_interval = SSsun.wait
history["supply"] = list()
history["capacity"] = list()
/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))
// space vines block out sunlight
var/obj/structure/spacevine/vine = locate(/obj/structure/spacevine) in loc
if(istype(vine) && !(/datum/spacevine_mutation/transparency in vine.mutations))
continue
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)
///Record the generated power supply and capacity for history
/obj/machinery/power/solar_control/proc/record()
if(record_size == 0)
record_size = 1 + ROUND_UP(360 / (azimuth_rate * abs(SSsun.azimuth_mod))) //History contains full sun cycle
if(world.time >= next_record)
next_record = world.time + record_interval
var/list/supply = history["supply"]
if(powernet)
supply += round(lastgen)
if(supply.len > record_size)
supply.Cut(1, 2)
var/list/capacity = history["capacity"]
if(powernet)
capacity += round(max(connected_panels.len, 1) * SOLAR_GEN_RATE)
if(capacity.len > record_size)
capacity.Cut(1, 2)
/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["supply"] = round(lastgen)
data["capacity"] = connected_panels.len * 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)
data["history"] = history
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()
record()
///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_Z_OFFSET
#undef PANEL_EDGE_Z_OFFSET