Reworks solars

This commit is contained in:
Artur
2020-02-07 10:59:43 +02:00
parent 34f43dccb4
commit cf22596477
8 changed files with 241 additions and 273 deletions
+4
View File
@@ -33,6 +33,10 @@
#define COMSIG_GLOB_NEW_Z "!new_z" //from base of datum/controller/subsystem/mapping/proc/add_new_zlevel(): (list/args)
#define COMSIG_GLOB_VAR_EDIT "!var_edit" //called after a successful var edit somewhere in the world: (list/args)
#define COMSIG_GLOB_LIVING_SAY_SPECIAL "!say_special" //global living say plug - use sparingly: (mob/speaker , message)
// signals from globally accessible objects
/// from SSsun when the sun changes position : (azimuth)
#define COMSIG_SUN_MOVED "sun_moved"
//////////////////////////////////////////////////////////////////
// /datum signals
+3
View File
@@ -0,0 +1,3 @@
#define SOLAR_TRACK_OFF 0
#define SOLAR_TRACK_TIMED 1
#define SOLAR_TRACK_AUTO 2
+25 -42
View File
@@ -1,49 +1,32 @@
SUBSYSTEM_DEF(sun)
name = "Sun"
wait = 600
flags = SS_NO_TICK_CHECK|SS_NO_INIT
var/angle
var/dx
var/dy
var/rate
var/list/solars = list()
/datum/controller/subsystem/sun/PreInit()
angle = rand (0,360) // the station position to the sun is randomised at round start
rate = rand(50,200)/100 // 50% - 200% of standard rotation
if(prob(50)) // same chance to rotate clockwise than counter-clockwise
rate = -rate
/datum/controller/subsystem/sun/stat_entry(msg)
..("P:[solars.len]")
/datum/controller/subsystem/sun/fire()
angle = (360 + angle + rate * 6) % 360 // increase/decrease the angle to the sun, adjusted by the rate
// now calculate and cache the (dx,dy) increments for line drawing
var/s = sin(angle)
var/c = cos(angle)
// Either "abs(s) < abs(c)" or "abs(s) >= abs(c)"
// In both cases, the greater is greater than 0, so, no "if 0" check is needed for the divisions
if(abs(s) < abs(c))
dx = s / abs(c)
dy = c / abs(c)
else
dx = s / abs(s)
dy = c / abs(s)
//now tell the solar control computers to update their status and linked devices
for(var/obj/machinery/power/solar_control/SC in solars)
if(!SC.powernet)
solars.Remove(SC)
continue
SC.update()
wait = 1 MINUTES
flags = SS_NO_TICK_CHECK
var/azimuth = 0 ///clockwise, top-down rotation from 0 (north) to 359
var/azimuth_mod = 1 ///multiplier against base_rotation
var/base_rotation = 6 ///base rotation in degrees per fire
/datum/controller/subsystem/sun/Initialize(start_timeofday)
azimuth = rand(0, 359)
azimuth_mod = round(rand(50, 200)/100, 0.01) // 50% - 200% of standard rotation
if(prob(50))
azimuth_mod *= -1
return ..()
/datum/controller/subsystem/sun/fire(resumed = FALSE)
azimuth += azimuth_mod * base_rotation
azimuth = round(azimuth, 0.01)
if(azimuth >= 360)
azimuth -= 360
if(azimuth < 0)
azimuth += 360
complete_movement()
/datum/controller/subsystem/sun/proc/complete_movement()
SEND_SIGNAL(src, COMSIG_SUN_MOVED, azimuth)
/datum/controller/subsystem/sun/vv_edit_var(var_name, var_value)
. = ..()
if(var_name == NAMEOF(src, azimuth))
complete_movement()
@@ -208,7 +208,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
// Destroy the Solar Arrays
/datum/objective/bloodsucker/solars
@@ -228,7 +228,7 @@
if (SC && SC.lastgen > 0 && SC.connected_panels.len > 0 && SC.connected_tracker)
return FALSE
return TRUE
*/
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -379,20 +379,21 @@
protege_objective.generate_objective()
add_objective(protege_objective)
if (rand(0,1) == 0)
//if (rand(0,1) == 0)
// Heart Thief Objective
var/datum/objective/bloodsucker/heartthief/heartthief_objective = new
heartthief_objective.owner = owner
heartthief_objective.generate_objective()
add_objective(heartthief_objective)
var/datum/objective/bloodsucker/heartthief/heartthief_objective = new
heartthief_objective.owner = owner
heartthief_objective.generate_objective()
add_objective(heartthief_objective)
/*
else
// Solars Objective
// Solars Objective, doesnt work due to TG updates.
var/datum/objective/bloodsucker/solars/solars_objective = new
solars_objective.owner = owner
solars_objective.generate_objective()
add_objective(solars_objective)
*/
// Survive Objective
var/datum/objective/bloodsucker/survive/survive_objective = new
survive_objective.owner = owner
+170 -187
View File
@@ -1,5 +1,5 @@
#define SOLAR_MAX_DIST 40
#define SOLARGENRATE 1500
#define SOLAR_GEN_RATE 1500
#define OCCLUSION_DISTANCE 20
/obj/machinery/power/solar
name = "solar panel"
@@ -10,40 +10,51 @@
use_power = NO_POWER_USE
idle_power_usage = 0
active_power_usage = 0
var/id = 0
max_integrity = 150
integrity_failure = 50
var/obscured = 0
var/sunfrac = 0
var/adir = SOUTH // actual dir
var/ndir = SOUTH // target dir
var/turn_angle = 0
var/obj/machinery/power/solar_control/control = null
integrity_failure = 0.33
var/id
var/obscured = FALSE
var/sunfrac = 0 //[0-1] measure of obscuration -- multipllier against power generation
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()
#if DM_VERSION >= 513
panel.vis_flags = VIS_INHERIT_ID|VIS_INHERIT_ICON|VIS_INHERIT_PLANE
vis_contents += panel
#endif
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 if closer than SOLAR_MAX_DIST
//set the control of the panel to a given computer
/obj/machinery/power/solar/proc/set_control(obj/machinery/power/solar_control/SC)
if(!SC || (get_dist(src, SC) > SOLAR_MAX_DIST))
return 0
unset_control()
control = SC
SC.connected_panels |= src
return 1
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.Remove(src)
control = null
control.connected_panels -= src
control = null
/obj/machinery/power/solar/proc/Make(obj/item/solar_assembly/S)
if(!S)
@@ -57,11 +68,11 @@
update_icon()
/obj/machinery/power/solar/crowbar_act(mob/user, obj/item/I)
playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
user.visible_message("[user] begins to take the glass off [src].", "<span class='notice'>You begin to take the glass off [src]...</span>")
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, 1)
user.visible_message("[user] takes the glass off [src].", "<span class='notice'>You take the glass off [src].</span>")
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
@@ -69,11 +80,11 @@
switch(damage_type)
if(BRUTE)
if(stat & BROKEN)
playsound(loc, 'sound/effects/hit_on_shattered_glass.ogg', 60, 1)
playsound(loc, 'sound/effects/hit_on_shattered_glass.ogg', 60, TRUE)
else
playsound(loc, 'sound/effects/glasshit.ogg', 90, 1)
playsound(loc, 'sound/effects/glasshit.ogg', 90, TRUE)
if(BURN)
playsound(loc, 'sound/items/welder.ogg', 100, 1)
playsound(loc, 'sound/items/welder.ogg', 100, TRUE)
/obj/machinery/power/solar/obj_break(damage_flag)
@@ -96,81 +107,95 @@
new shard(loc)
qdel(src)
/obj/machinery/power/solar/update_icon()
..()
cut_overlays()
/obj/machinery/power/solar/update_overlays()
. = ..()
var/matrix/turner = matrix()
turner.Turn(azimuth_current)
panel.transform = turner
if(stat & BROKEN)
add_overlay(mutable_appearance(icon, "solar_panel-b", FLY_LAYER))
panel.icon_state = "solar_panel-b"
else
add_overlay(mutable_appearance(icon, "solar_panel", FLY_LAYER))
src.setDir(angle2dir(adir))
panel.icon_state = "solar_panel"
#if DM_VERSION <= 512
. += new /mutable_appearance(panel)
#endif
//calculates the fraction of the sunlight that the panel receives
/obj/machinery/power/solar/proc/queue_turn(azimuth)
needs_to_turn = TRUE
azimuth_target = azimuth
/obj/machinery/power/solar/proc/queue_update_solar_exposure()
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_icon()
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(hit.opacity)
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)
sunfrac = 0
return
return 0
//find the smaller angle between the direction the panel is facing and the direction of the sun (the sign is not important here)
var/p_angle = min(abs(adir - SSsun.angle), 360 - abs(adir - SSsun.angle))
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 = .
if(p_angle > 90) // if facing more than 90deg from sun, zero output
sunfrac = 0
return
sunfrac = cos(p_angle) ** 2
//isn't the power received from the incoming light proportionnal to cos(p_angle) (Lambert's cosine law) rather than cos(p_angle)^2 ?
/obj/machinery/power/solar/process()//TODO: remove/add this from machines to save on processing as needed ~Carn PRIORITY
/obj/machinery/power/solar/process()
if(stat & BROKEN)
return
if(!control) //if there's no sun or the panel is not linked to a solar control computer, no need to proceed
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
if(powernet)
if(powernet == control.powernet)//check if the panel is still connected to the computer
if(obscured) //get no light from the sun, so don't generate power
return
var/sgen = SOLARGENRATE * sunfrac * efficiency
add_avail(sgen)
control.gen += sgen
else //if we're no longer on the same powernet, remove from control computer
unset_control()
var/sgen = SOLAR_GEN_RATE * sunfrac
add_avail(sgen)
if(control)
control.gen += sgen
/obj/machinery/power/solar/fake/New(var/turf/loc, var/obj/item/solar_assembly/S)
..(loc, S, 0)
//Bit of a hack but this whole type is a hack
/obj/machinery/power/solar/fake/Initialize(turf/loc, obj/item/solar_assembly/S)
. = ..()
UnregisterSignal(SSsun, COMSIG_SUN_MOVED)
/obj/machinery/power/solar/fake/process()
. = PROCESS_KILL
return
//trace towards sun to see if we're in shadow
/obj/machinery/power/solar/proc/occlusion()
var/ax = x // start at the solar panel
var/ay = y
var/turf/T = null
var/dx = SSsun.dx
var/dy = SSsun.dy
for(var/i = 1 to 20) // 20 steps is enough
ax += dx // do step
ay += dy
T = locate( round(ax,0.5),round(ay,0.5),z)
if(T.x == 1 || T.x==world.maxx || T.y==1 || T.y==world.maxy) // not obscured if we reach the edge
break
if(T.density) // if we hit a solid turf, panel is obscured
obscured = 1
return
obscured = 0 // if hit the edge or stepped 20 times, not obscured
update_solar_exposure()
return PROCESS_KILL
//
// Solar Assembly - For construction of solar arrays.
@@ -204,21 +229,22 @@
forceMove(glass_type, Tsec)
glass_type = null
/obj/item/solar_assembly/attackby(obj/item/W, mob/user, params)
if(istype(W, /obj/item/wrench) && isturf(loc))
if(W.tool_behaviour == TOOL_WRENCH && isturf(loc))
if(isinspace())
to_chat(user, "<span class='warning'>You can't secure [src] here.</span>")
return
anchored = !anchored
if(anchored)
user.visible_message("[user] wrenches the solar assembly into place.", "<span class='notice'>You wrench the solar assembly into place.</span>")
user.visible_message("<span class='notice'>[user] wrenches the solar assembly into place.</span>", "<span class='notice'>You wrench the solar assembly into place.</span>")
W.play_tool_sound(src, 75)
else
user.visible_message("[user] unwrenches the solar assembly from its place.", "<span class='notice'>You unwrench the solar assembly from its place.</span>")
user.visible_message("<span class='notice'>[user] unwrenches the solar assembly from its place.</span>", "<span class='notice'>You unwrench the solar assembly from its place.</span>")
W.play_tool_sound(src, 75)
return 1
if(is_type_in_typecache(W, allowed_sheets))
if(istype(W, /obj/item/stack/sheet/glass) || istype(W, /obj/item/stack/sheet/rglass))
if(!anchored)
to_chat(user, "<span class='warning'>You need to secure the assembly before you can add glass.</span>")
return
@@ -226,8 +252,8 @@
var/obj/item/stack/sheet/G = S.change_stack(null, 2)
if(G)
glass_type = G
playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
user.visible_message("[user] places the glass on the solar assembly.", "<span class='notice'>You place the glass on the solar assembly.</span>")
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
@@ -243,13 +269,13 @@
return
tracker = 1
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>")
user.visible_message("<span class='notice'>[user] inserts the electronics into the solar assembly.</span>", "<span class='notice'>You insert the electronics into the solar assembly.</span>")
return 1
else
if(istype(W, /obj/item/crowbar))
if(W.tool_behaviour == TOOL_CROWBAR)
new /obj/item/electronics/tracker(src.loc)
tracker = 0
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>")
user.visible_message("<span class='notice'>[user] takes out the electronics from the solar assembly.</span>", "<span class='notice'>You take out the electronics from the solar assembly.</span>")
return 1
return ..()
@@ -270,21 +296,23 @@
var/icon_screen = "solar"
var/icon_keyboard = "power_key"
var/id = 0
var/currentdir = 0
var/targetdir = 0 // target angle in manual tracking (since it updates every game minute)
var/gen = 0
var/lastgen = 0
var/track = 0 // 0= off 1=timed 2=auto (tracker)
var/trackrate = 600 // 300-900 seconds
var/nexttime = 0 // time for a panel to rotate of 1 degree in manual tracking
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()
. = ..()
if(powernet)
set_panels(currentdir)
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)
@@ -293,16 +321,6 @@
connected_tracker.unset_control()
return ..()
/obj/machinery/power/solar_control/disconnect_from_network()
..()
SSsun.solars.Remove(src)
/obj/machinery/power/solar_control/connect_to_network()
var/to_return = ..()
if(powernet) //if connected and not already in solar_list...
SSsun.solars |= src //... add it
return to_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)
@@ -317,22 +335,6 @@
if(!T.control) //i.e unconnected
T.set_control(src)
//called by the sun controller, update the facing angle (either manually or via tracking) and rotates the panels accordingly
/obj/machinery/power/solar_control/proc/update()
if(stat & (NOPOWER | BROKEN))
return
switch(track)
if(1)
if(trackrate) //we're manual tracking. If we set a rotation speed...
currentdir = targetdir //...the current direction is the targetted one (and rotates panels to it)
if(2) // auto-tracking
if(connected_tracker)
connected_tracker.set_angle(SSsun.angle)
set_panels(currentdir)
updateDialog()
/obj/machinery/power/solar_control/update_icon()
cut_overlays()
if(stat & NOPOWER)
@@ -353,68 +355,55 @@
/obj/machinery/power/solar_control/ui_data()
var/data = list()
data["generated"] = round(lastgen)
data["angle"] = currentdir
data["direction"] = angle2text(currentdir)
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["tracking_rate"] = trackrate
data["rotating_way"] = (trackrate<0 ? "CCW" : "CW")
data["connected_panels"] = connected_panels.len
data["connected_tracker"] = (connected_tracker ? 1 : 0)
data["connected_tracker"] = (connected_tracker ? TRUE : FALSE)
return data
/obj/machinery/power/solar_control/ui_act(action, params)
if(..())
return
if(action == "angle")
if(action == "azimuth")
var/adjust = text2num(params["adjust"])
var/value = text2num(params["value"])
if(adjust)
value = currentdir + adjust
value = azimuth_target + adjust
if(value != null)
currentdir = CLAMP((360 + value) % 360, 0, 359)
targetdir = currentdir
set_panels(currentdir)
set_panels(value)
return TRUE
return FALSE
if(action == "rate")
if(action == "azimuth_rate")
var/adjust = text2num(params["adjust"])
var/value = text2num(params["value"])
if(adjust)
value = trackrate + adjust
value = azimuth_rate + adjust
if(value != null)
trackrate = CLAMP(value, -7200, 7200)
if(trackrate)
nexttime = world.time + 36000 / abs(trackrate)
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 == 2 && connected_tracker)
connected_tracker.set_angle(SSsun.angle)
set_panels(currentdir)
else if(mode == 1)
targetdir = currentdir
if(trackrate)
nexttime = world.time + 36000 / abs(trackrate)
set_panels(targetdir)
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()
if(connected_tracker && track == 2)
connected_tracker.set_angle(SSsun.angle)
set_panels(currentdir)
return TRUE
return FALSE
/obj/machinery/power/solar_control/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/screwdriver))
if(I.tool_behaviour == TOOL_SCREWDRIVER)
if(I.use_tool(src, user, 20, volume=50))
if (src.stat & BROKEN)
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 )
@@ -446,15 +435,15 @@
switch(damage_type)
if(BRUTE)
if(stat & BROKEN)
playsound(src.loc, 'sound/effects/hit_on_shattered_glass.ogg', 70, 1)
playsound(src.loc, 'sound/effects/hit_on_shattered_glass.ogg', 70, TRUE)
else
playsound(src.loc, 'sound/effects/glasshit.ogg', 75, 1)
playsound(src.loc, 'sound/effects/glasshit.ogg', 75, TRUE)
if(BURN)
playsound(src.loc, 'sound/items/welder.ogg', 100, 1)
playsound(src.loc, 'sound/items/welder.ogg', 100, TRUE)
/obj/machinery/power/solar_control/obj_break(damage_flag)
if(!(stat & BROKEN) && !(flags_1 & NODECONSTRUCT_1))
playsound(loc, 'sound/effects/glassbr3.ogg', 100, 1)
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
stat |= BROKEN
update_icon()
@@ -462,35 +451,26 @@
lastgen = gen
gen = 0
if(stat & (NOPOWER | BROKEN))
return
if(connected_tracker && (!powernet || connected_tracker.powernet != powernet))
connected_tracker.unset_control()
if(connected_tracker) //NOTE : handled here so that we don't add trackers to the processing list
if(connected_tracker.powernet != powernet)
connected_tracker.unset_control()
///Ran every time the sun updates.
/obj/machinery/power/solar_control/proc/timed_track()
if(track == SOLAR_TRACK_TIMED)
azimuth_target += azimuth_rate
set_panels(azimuth_target)
if(track==1 && trackrate) //manual tracking and set a rotation speed
if(nexttime <= world.time) //every time we need to increase/decrease the angle by 1...
targetdir = (targetdir + trackrate/abs(trackrate) + 360) % 360 //... do it
nexttime += 36000/abs(trackrate) //reset the counter for the next 1
//rotates the panel to the passed angle
/obj/machinery/power/solar_control/proc/set_panels(currentdir)
///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.adir = currentdir //instantly rotates the panel
S.occlusion()//and
S.update_icon() //update it
update_icon()
/obj/machinery/power/solar_control/power_change()
..()
update_icon()
S.queue_turn(azimuth)
//
// MISC
@@ -499,3 +479,6 @@
/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
#undef OCCLUSION_DISTANCE
+27 -34
View File
@@ -1,6 +1,6 @@
//Solar tracker
//Machine that tracks the sun and reports it's direction to the solar controllers
//Machine that tracks the sun and reports its direction to the solar controllers
//As long as this is working, solar panels on same powernet will track automatically
/obj/machinery/power/tracker
@@ -11,35 +11,39 @@
density = TRUE
use_power = NO_POWER_USE
max_integrity = 250
integrity_failure = 50
integrity_failure = 0.2
var/id = 0
var/sun_angle = 0 // sun angle as set by sun datum
var/obj/machinery/power/solar_control/control = null
var/obj/item/solar_assembly/assembly
var/obj/machinery/power/solar_control/control
/obj/machinery/power/tracker/Initialize(mapload, obj/item/solar_assembly/S)
. = ..()
Make(S)
connect_to_network()
RegisterSignal(SSsun, COMSIG_SUN_MOVED, .proc/sun_update)
/obj/machinery/power/tracker/Destroy()
unset_control() //remove from control computer
return ..()
//set the control of the tracker to a given computer if closer than SOLAR_MAX_DIST
/obj/machinery/power/tracker/proc/set_control(obj/machinery/power/solar_control/SC)
if(!SC || (get_dist(src, SC) > SOLAR_MAX_DIST))
return 0
unset_control()
control = SC
SC.connected_tracker = src
return 1
//set the control of the tracker to null and removes it from the previous control computer if needed
/obj/machinery/power/tracker/proc/unset_control()
if(control)
if(control.track == SOLAR_TRACK_AUTO)
control.track = SOLAR_TRACK_OFF
control.connected_tracker = null
control = null
control = null
///Tell the controller to turn the solar panels
/obj/machinery/power/tracker/proc/sun_update(datum/source, azimuth)
setDir(angle2dir(azimuth))
if(control && control.track == SOLAR_TRACK_AUTO)
control.set_panels(azimuth)
/obj/machinery/power/tracker/proc/Make(obj/item/solar_assembly/S)
if(!S)
@@ -51,42 +55,31 @@
S.moveToNullspace()
update_icon()
//updates the tracker icon and the facing angle for the control computer
/obj/machinery/power/tracker/proc/set_angle(angle)
sun_angle = angle
//set icon dir to show sun illumination
setDir(turn(NORTH, -angle - 22.5) )// 22.5 deg bias ensures, e.g. 67.5-112.5 is EAST
if(powernet && (powernet == control.powernet)) //update if we're still in the same powernet
control.currentdir = angle
/obj/machinery/power/tracker/crowbar_act(mob/user, obj/item/I)
playsound(src.loc, 'sound/machines/click.ogg', 50, 1)
user.visible_message("[user] begins to take the glass off [src].", "<span class='notice'>You begin to take the glass off [src]...</span>")
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, 1)
user.visible_message("[user] takes the glass off [src].", "<span class='notice'>You take the glass off [src].</span>")
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/tracker/obj_break(damage_flag)
if(!(stat & BROKEN) && !(flags_1 & NODECONSTRUCT_1))
playsound(loc, 'sound/effects/glassbr3.ogg', 100, 1)
stat |= BROKEN
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
unset_control()
/obj/machinery/power/solar/deconstruct(disassembled = TRUE)
/obj/machinery/power/tracker/deconstruct(disassembled = TRUE)
if(!(flags_1 & NODECONSTRUCT_1))
if(disassembled)
if(assembly)
assembly.forceMove(loc)
assembly.give_glass(stat & BROKEN)
var/obj/item/solar_assembly/S = locate() in src
if(S)
S.forceMove(loc)
S.give_glass(stat & BROKEN)
else
playsound(src, "shatter", 70, 1)
var/shard = assembly?.glass_type ? assembly.glass_type.shard_type : /obj/item/shard
new shard(loc)
new shard(loc)
playsound(src, "shatter", 70, TRUE)
new /obj/item/shard(src.loc)
new /obj/item/shard(src.loc)
qdel(src)
// Tracker Electronic
+1
View File
@@ -77,6 +77,7 @@
#include "code\__DEFINES\obj_flags.dm"
#include "code\__DEFINES\pinpointers.dm"
#include "code\__DEFINES\pipe_construction.dm"
#include "code\__DEFINES\power.dm"
#include "code\__DEFINES\preferences.dm"
#include "code\__DEFINES\procpath.dm"
#include "code\__DEFINES\profile.dm"