Merge pull request #4538 from VOREStation/upstream-merge-5726

[MIRROR] Refactors Sun and Inactivity processes to subsystems, and a few globa lvariables to be managed
This commit is contained in:
Spades
2019-02-23 12:01:38 -05:00
committed by GitHub
9 changed files with 45 additions and 66 deletions

View File

@@ -1,7 +0,0 @@
/datum/controller/process/sun/setup()
name = "sun"
schedule_interval = 20 // every second
sun = new
/datum/controller/process/sun/doWork()
sun.calc_position()

View File

@@ -1,11 +1,12 @@
/datum/controller/process/inactivity/setup()
name = "inactivity"
schedule_interval = 600 // Once every minute (approx.)
SUBSYSTEM_DEF(inactivity)
name = "AFK Kick"
wait = 600
flags = SS_BACKGROUND | SS_NO_TICK_CHECK
/datum/controller/process/inactivity/doWork()
/datum/controller/subsystem/inactivity/fire()
if(config.kick_inactive)
for(last_object in clients)
var/client/C = last_object
for(var/i in clients)
var/client/C = i
if(C.is_afk(config.kick_inactive MINUTES) && !C.holder) // VOREStation Edit - Allow admins to idle
to_chat(C,"<span class='warning'>You have been inactive for more than [config.kick_inactive] minute\s and have been disconnected.</span>")
var/information
@@ -33,4 +34,3 @@
log_and_message_admins("being kicked for AFK[information][adminlinks]", C.mob)
qdel(C)
SCHECK

View File

@@ -0,0 +1,7 @@
SUBSYSTEM_DEF(sun)
name = "Sun"
wait = 600
var/static/datum/sun/sun = new
/datum/controller/subsystem/sun/fire()
sun.calc_position()

View File

@@ -85,9 +85,6 @@
if("Jobs")
debug_variables(job_master)
feedback_add_details("admin_verb","DJobs")
if("Sun")
debug_variables(sun)
feedback_add_details("admin_verb","DSun")
if("Radio")
debug_variables(radio_controller)
feedback_add_details("admin_verb","DRadio")

View File

@@ -1,38 +1,21 @@
#define SOLAR_UPDATE_TIME 600 //duration between two updates of the whole sun/solars positions
/datum/sun
var/angle
var/dx
var/dy
var/rate
var/list/solars // for debugging purposes, references solars_list at the constructor
var/solar_next_update // last time the sun position was checked and adjusted
/datum/sun/New()
solars = solars_list
rate = rand(50,200)/100 // 50% - 200% of standard rotation
if(prob(50)) // same chance to rotate clockwise than counter-clockwise
rate = -rate
solar_next_update = world.time // init the timer
angle = rand (0,360) // the station position to the sun is randomised at round start
/*/hook/startup/proc/createSun() // handled in scheduler
sun = new /datum/sun()
return 1*/
// calculate the sun's position given the time of day
// at the standard rate (100%) the angle is increase/decreased by 6 degrees every minute.
// a full rotation thus take a game hour in that case
/datum/sun/proc/calc_position()
if(world.time < solar_next_update) //if less than 60 game secondes have passed, do nothing
return;
angle = (360 + angle + rate * 6) % 360 // increase/decrease the angle to the sun, adjusted by the rate
solar_next_update += SOLAR_UPDATE_TIME // since we updated the angle, set the proper time for the next loop
// now calculate and cache the (dx,dy) increments for line drawing
var/s = sin(angle)
@@ -51,8 +34,8 @@
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_list)
for(var/obj/machinery/power/solar_control/SC in GLOB.solars_list)
if(!SC.powernet)
solars_list.Remove(SC)
GLOB.solars_list.Remove(SC)
continue
SC.update()

View File

@@ -91,7 +91,6 @@ var/list/reverse_dir = list( // reverse_dir[dir] = reverse of dir
)
var/datum/configuration/config = null
var/datum/sun/sun = null
var/list/combatlog = list()
var/list/IClog = list()

View File

@@ -13,8 +13,8 @@
adjust_solar_output(1.5)
/datum/event/solar_storm/proc/adjust_solar_output(var/mult = 1)
if(isnull(base_solar_gen_rate)) base_solar_gen_rate = solar_gen_rate
solar_gen_rate = mult * base_solar_gen_rate
if(isnull(base_solar_gen_rate)) base_solar_gen_rate = GLOB.solar_gen_rate
GLOB.solar_gen_rate = mult * base_solar_gen_rate
/datum/event/solar_storm/start()

View File

@@ -1,7 +1,7 @@
#define SOLAR_MAX_DIST 40
var/solar_gen_rate = 1500
var/list/solars_list = list()
GLOBAL_VAR_INIT(solar_gen_rate, 1500)
GLOBAL_LIST_EMPTY(solars_list)
/obj/machinery/power/solar
name = "solar panel"
@@ -25,8 +25,8 @@ var/list/solars_list = list()
/obj/machinery/power/solar/drain_power()
return -1
/obj/machinery/power/solar/New(var/turf/loc, var/obj/item/solar_assembly/S)
..(loc)
/obj/machinery/power/solar/initialize(mapload, obj/item/solar_assembly/S)
. = ..()
Make(S)
connect_to_network()
@@ -51,7 +51,7 @@ var/list/solars_list = list()
if(!S)
S = new /obj/item/solar_assembly(src)
S.glass_type = /obj/item/stack/material/glass
S.anchored = 1
S.anchored = TRUE
S.loc = src
if(S.glass_type == /obj/item/stack/material/glass/reinforced) //if the panel is in reinforced glass
health *= 2 //this need to be placed here, because panels already on the map don't have an assembly linked to
@@ -102,18 +102,18 @@ var/list/solars_list = list()
src.set_dir(angle2dir(adir))
return
//calculates the fraction of the sunlight that the panel recieves
//calculates the fraction of the SSsun.sunlight that the panel recieves
/obj/machinery/power/solar/proc/update_solar_exposure()
if(!sun)
if(!SSsun.sun)
return
if(obscured)
sunfrac = 0
return
//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 - sun.angle), 360 - abs(adir - sun.angle))
//find the smaller angle between the direction the panel is facing and the direction of the SSsun.sun (the sign is not important here)
var/p_angle = min(abs(adir - SSsun.sun.angle), 360 - abs(adir - SSsun.sun.angle))
if(p_angle > 90) // if facing more than 90deg from sun, zero output
if(p_angle > 90) // if facing more than 90deg from SSsun.sun, zero output
sunfrac = 0
return
@@ -123,14 +123,14 @@ var/list/solars_list = list()
/obj/machinery/power/solar/process()//TODO: remove/add this from machines to save on processing as needed ~Carn PRIORITY
if(stat & BROKEN)
return
if(!sun || !control) //if there's no sun or the panel is not linked to a solar control computer, no need to proceed
if(!SSsun.sun || !control) //if there's no SSsun.sun or the panel is not linked to a solar control computer, no need to proceed
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
if(obscured) //get no light from the SSsun.sun, so don't generate power
return
var/sgen = solar_gen_rate * sunfrac
var/sgen = GLOB.solar_gen_rate * sunfrac
add_avail(sgen)
control.gen += sgen
else //if we're no longer on the same powernet, remove from control computer
@@ -173,7 +173,7 @@ var/list/solars_list = list()
. = PROCESS_KILL
return
//trace towards sun to see if we're in shadow
//trace towards SSsun.sun to see if we're in shadow
/obj/machinery/power/solar/proc/occlusion()
var/ax = x // start at the solar panel
@@ -181,8 +181,8 @@ var/list/solars_list = list()
var/turf/T = null
for(var/i = 1 to 20) // 20 steps is enough
ax += sun.dx // do step
ay += sun.dy
ax += SSsun.sun.dx // do step
ay += SSsun.sun.dy
T = locate( round(ax,0.5),round(ay,0.5),z)
@@ -306,12 +306,12 @@ var/list/solars_list = list()
/obj/machinery/power/solar_control/disconnect_from_network()
..()
solars_list.Remove(src)
GLOB.solars_list.Remove(src)
/obj/machinery/power/solar_control/connect_to_network()
var/to_return = ..()
if(powernet) //if connected and not already in solar_list...
solars_list |= src //... add it
GLOB.solars_list |= src //... add it
return to_return
//search for unconnected panels and trackers in the computer powernet and connect them
@@ -330,7 +330,7 @@ var/list/solars_list = list()
connected_tracker = T
T.set_control(src)
//called by the sun controller, update the facing angle (either manually or via tracking) and rotates the panels accordingly
//called by the SSsun.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
@@ -341,7 +341,7 @@ var/list/solars_list = list()
cdir = targetdir //...the current direction is the targetted one (and rotates panels to it)
if(2) // auto-tracking
if(connected_tracker)
connected_tracker.set_angle(sun.angle)
connected_tracker.set_angle(SSsun.sun.angle)
set_panels(cdir)
updateDialog()
@@ -375,7 +375,7 @@ var/list/solars_list = list()
/obj/machinery/power/solar_control/interact(mob/user)
var/t = "<B><span class='highlight'>Generated power</span></B> : [round(lastgen)] W<BR>"
t += "<B><span class='highlight'>Star Orientation</span></B>: [sun.angle]&deg ([angle2text(sun.angle)])<BR>"
t += "<B><span class='highlight'>Star Orientation</span></B>: [SSsun.sun.angle]&deg ([angle2text(SSsun.sun.angle)])<BR>"
t += "<B><span class='highlight'>Array Orientation</span></B>: [rate_control(src,"cdir","[cdir]&deg",1,15)] ([angle2text(cdir)])<BR>"
t += "<B><span class='highlight'>Tracking:</span></B><div class='statusDisplay'>"
switch(track)
@@ -477,7 +477,7 @@ var/list/solars_list = list()
track = text2num(href_list["track"])
if(track == 2)
if(connected_tracker)
connected_tracker.set_angle(sun.angle)
connected_tracker.set_angle(SSsun.sun.angle)
set_panels(cdir)
else if (track == 1) //begin manual tracking
src.targetdir = src.cdir
@@ -487,7 +487,7 @@ var/list/solars_list = list()
if(href_list["search_connected"])
src.search_for_connected()
if(connected_tracker && track == 2)
connected_tracker.set_angle(sun.angle)
connected_tracker.set_angle(SSsun.sun.angle)
src.set_panels(cdir)
interact(usr)
@@ -537,7 +537,7 @@ var/list/solars_list = list()
spawn(150) // Wait 15 seconds to ensure everything was set up properly (such as, powernets, solar panels, etc.
src.search_for_connected()
if(connected_tracker && track == 2)
connected_tracker.set_angle(sun.angle)
connected_tracker.set_angle(SSsun.sun.angle)
src.set_panels(cdir)
//
@@ -546,7 +546,7 @@ var/list/solars_list = list()
/obj/item/weapon/paper/solar
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 phoron! 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>"
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 phoron! 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 SSsun.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 SSsun.sun's movements and to send commands to the solar panels to change direction with the SSsun.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>"
/proc/rate_control(var/S, var/V, var/C, var/Min=1, var/Max=5, var/Limit=null) //How not to name vars
var/href = "<A href='?src=\ref[S];rate control=1;[V]"

View File

@@ -204,12 +204,10 @@
#include "code\controllers\Processes\emergencyShuttle.dm"
#include "code\controllers\Processes\event.dm"
#include "code\controllers\Processes\game_master.dm"
#include "code\controllers\Processes\inactivity.dm"
#include "code\controllers\Processes\nanoui.dm"
#include "code\controllers\Processes\obj.dm"
#include "code\controllers\Processes\radiation.dm"
#include "code\controllers\Processes\scheduler.dm"
#include "code\controllers\Processes\sun.dm"
#include "code\controllers\Processes\supply.dm"
#include "code\controllers\Processes\ticker.dm"
#include "code\controllers\Processes\turf.dm"
@@ -223,6 +221,7 @@
#include "code\controllers\subsystems\circuits.dm"
#include "code\controllers\subsystems\garbage.dm"
#include "code\controllers\subsystems\holomaps.dm"
#include "code\controllers\subsystems\inactivity.dm"
#include "code\controllers\subsystems\lighting.dm"
#include "code\controllers\subsystems\machines.dm"
#include "code\controllers\subsystems\mapping_vr.dm"
@@ -232,6 +231,7 @@
#include "code\controllers\subsystems\persist_vr.dm"
#include "code\controllers\subsystems\planets.dm"
#include "code\controllers\subsystems\shuttles.dm"
#include "code\controllers\subsystems\sun.dm"
#include "code\controllers\subsystems\transcore_vr.dm"
#include "code\controllers\subsystems\vote.dm"
#include "code\controllers\subsystems\xenoarch.dm"