From bf86b408fae7aece899316947e1fb6f767772c8c Mon Sep 17 00:00:00 2001 From: Atermonera Date: Mon, 3 Dec 2018 17:21:00 -0800 Subject: [PATCH 1/3] Refactors Sun and Inactivity processes to subsystems, and a few globa lvariables to be managed --- code/controllers/Processes/sun.dm | 7 --- .../{Processes => subsystems}/inactivity.dm | 16 ++++-- code/controllers/subsystems/sun.dm | 7 +++ code/controllers/verbs.dm | 3 -- code/datums/sun.dm | 21 +------- code/global.dm | 1 - code/modules/events/solar_storm.dm | 4 +- code/modules/power/solar.dm | 50 +++++++++---------- vorestation.dme | 10 +++- 9 files changed, 56 insertions(+), 63 deletions(-) delete mode 100644 code/controllers/Processes/sun.dm rename code/controllers/{Processes => subsystems}/inactivity.dm (72%) create mode 100644 code/controllers/subsystems/sun.dm diff --git a/code/controllers/Processes/sun.dm b/code/controllers/Processes/sun.dm deleted file mode 100644 index f09806cef5..0000000000 --- a/code/controllers/Processes/sun.dm +++ /dev/null @@ -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() diff --git a/code/controllers/Processes/inactivity.dm b/code/controllers/subsystems/inactivity.dm similarity index 72% rename from code/controllers/Processes/inactivity.dm rename to code/controllers/subsystems/inactivity.dm index 9435a18bf0..399f32fc75 100644 --- a/code/controllers/Processes/inactivity.dm +++ b/code/controllers/subsystems/inactivity.dm @@ -1,12 +1,19 @@ -/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) +<<<<<<< HEAD:code/controllers/Processes/inactivity.dm for(last_object in clients) var/client/C = last_object if(C.is_afk(config.kick_inactive MINUTES) && !C.holder) // VOREStation Edit - Allow admins to idle +======= + for(var/i in clients) + var/client/C = i + if(C.is_afk(config.kick_inactive MINUTES)) +>>>>>>> 414cf71... Merge pull request #5726 from kevinz000/ss_refactor_3:code/controllers/subsystems/inactivity.dm to_chat(C,"You have been inactive for more than [config.kick_inactive] minute\s and have been disconnected.") var/information @@ -33,4 +40,3 @@ log_and_message_admins("being kicked for AFK[information][adminlinks]", C.mob) qdel(C) - SCHECK diff --git a/code/controllers/subsystems/sun.dm b/code/controllers/subsystems/sun.dm new file mode 100644 index 0000000000..551130a20b --- /dev/null +++ b/code/controllers/subsystems/sun.dm @@ -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() diff --git a/code/controllers/verbs.dm b/code/controllers/verbs.dm index 5cd8d2ab08..4adcee3fd0 100644 --- a/code/controllers/verbs.dm +++ b/code/controllers/verbs.dm @@ -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") diff --git a/code/datums/sun.dm b/code/datums/sun.dm index a78c89ac46..69b725f305 100644 --- a/code/datums/sun.dm +++ b/code/datums/sun.dm @@ -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() diff --git a/code/global.dm b/code/global.dm index 0dff5cd610..686d555195 100644 --- a/code/global.dm +++ b/code/global.dm @@ -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() diff --git a/code/modules/events/solar_storm.dm b/code/modules/events/solar_storm.dm index 1f6f820b14..f616ef3c61 100644 --- a/code/modules/events/solar_storm.dm +++ b/code/modules/events/solar_storm.dm @@ -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() diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index 2d9f1803ba..24d36506f0 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -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 = "Generated power : [round(lastgen)] W
" - t += "Star Orientation: [sun.angle]° ([angle2text(sun.angle)])
" + t += "Star Orientation: [SSsun.sun.angle]° ([angle2text(SSsun.sun.angle)])
" t += "Array Orientation: [rate_control(src,"cdir","[cdir]°",1,15)] ([angle2text(cdir)])
" t += "Tracking:
" 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 = "

Welcome

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.

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!

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.

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.

That's all to it, be safe, be green!

" + info = "

Welcome

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.

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!

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.

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.

That's all to it, be safe, be green!

" /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 = "You have been inactive for more than [config.kick_inactive] minute\s and have been disconnected.") var/information diff --git a/vorestation.dme b/vorestation.dme index 831bd3d733..b4803d4350 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -204,11 +204,7 @@ #include "code\controllers\Processes\emergencyShuttle.dm" #include "code\controllers\Processes\event.dm" #include "code\controllers\Processes\game_master.dm" -<<<<<<< HEAD:vorestation.dme -#include "code\controllers\Processes\inactivity.dm" -======= #include "code\controllers\Processes\mob.dm" ->>>>>>> 414cf71... Merge pull request #5726 from kevinz000/ss_refactor_3:polaris.dme #include "code\controllers\Processes\nanoui.dm" #include "code\controllers\Processes\obj.dm" #include "code\controllers\Processes\radiation.dm" @@ -235,11 +231,8 @@ #include "code\controllers\subsystems\persist_vr.dm" #include "code\controllers\subsystems\planets.dm" #include "code\controllers\subsystems\shuttles.dm" -<<<<<<< HEAD:vorestation.dme #include "code\controllers\subsystems\transcore_vr.dm" -======= #include "code\controllers\subsystems\sun.dm" ->>>>>>> 414cf71... Merge pull request #5726 from kevinz000/ss_refactor_3:polaris.dme #include "code\controllers\subsystems\vote.dm" #include "code\controllers\subsystems\xenoarch.dm" #include "code\datums\ai_law_sets.dm" From 7a91a6869edb423b3415e7c5548ceede1286165e Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 17 Feb 2019 18:32:02 -0500 Subject: [PATCH 3/3] AI Refactor leaked onto this a bit --- vorestation.dme | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vorestation.dme b/vorestation.dme index b4803d4350..b482d7b182 100644 --- a/vorestation.dme +++ b/vorestation.dme @@ -204,7 +204,6 @@ #include "code\controllers\Processes\emergencyShuttle.dm" #include "code\controllers\Processes\event.dm" #include "code\controllers\Processes\game_master.dm" -#include "code\controllers\Processes\mob.dm" #include "code\controllers\Processes\nanoui.dm" #include "code\controllers\Processes\obj.dm" #include "code\controllers\Processes\radiation.dm" @@ -231,8 +230,8 @@ #include "code\controllers\subsystems\persist_vr.dm" #include "code\controllers\subsystems\planets.dm" #include "code\controllers\subsystems\shuttles.dm" -#include "code\controllers\subsystems\transcore_vr.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" #include "code\datums\ai_law_sets.dm"