diff --git a/code/controllers/Processes/sun.dm b/code/controllers/Processes/sun.dm index f09806cef53..93e626af3bb 100644 --- a/code/controllers/Processes/sun.dm +++ b/code/controllers/Processes/sun.dm @@ -1,7 +1,51 @@ +var/global/datum/controller/process/sun/sun + +/datum/controller/process/sun + var/angle + var/dx + var/dy + var/rate + var/list/solars = list() // for debugging purposes, references solars list at the constructor + /datum/controller/process/sun/setup() name = "sun" - schedule_interval = 20 // every second - sun = new + schedule_interval = 600 // every 60 seconds + sun = src + + 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/process/sun/doWork() - sun.calc_position() + calc_position() + update_solar_machinery() + + +// 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/controller/process/sun/proc/calc_position() + 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 +/datum/controller/process/sun/proc/update_solar_machinery() + for(var/obj/machinery/power/solar_control/SC in solars) + if(!SC.powernet) + solars.Remove(SC) + continue + SC.update() diff --git a/code/datums/sun.dm b/code/datums/sun.dm deleted file mode 100644 index eafbcd1ee0c..00000000000 --- a/code/datums/sun.dm +++ /dev/null @@ -1,61 +0,0 @@ -#define SOLAR_UPDATE_TIME 600 //duration between two updates of the whole sun/solars positions - -var/global/datum/sun/sun - -/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 - -/* HANDLED IN PROCESS SCHEDULER -/hook/startup/proc/createSun() - 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) - 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_list) - if(!SC.powernet) - solars_list.Remove(SC) - continue - SC.update() diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 5002f258cac..f8eeff8c5f1 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -978,8 +978,8 @@ var/list/slot_equipment_priority = list( \ process = processScheduler.getProcess("garbage") stat(null, "GAR\t - #[process.getTicks()]\t - [process.getLastRunTime()]") - //process = processScheduler.getProcess("sun") - //stat(null, "SUN\t - #[process.getTicks()]\t - [process.getLastRunTime()]") + process = processScheduler.getProcess("sun") + stat(null, "SUN([sun.solars.len])\t - #[process.getTicks()]\t - [process.getLastRunTime()]") //process = processScheduler.getProcess("garbage") //stat(null, "GAR\t - #[process.getTicks()]\t - [process.getLastRunTime()]") diff --git a/code/modules/power/solar.dm b/code/modules/power/solar.dm index 93c1a961073..43f0911d41c 100644 --- a/code/modules/power/solar.dm +++ b/code/modules/power/solar.dm @@ -1,8 +1,6 @@ #define SOLAR_MAX_DIST 40 #define SOLARGENRATE 1500 -var/list/solars_list = list() - /obj/machinery/power/solar name = "solar panel" desc = "A solar electrical generator." @@ -308,12 +306,12 @@ var/list/solars_list = list() /obj/machinery/power/solar_control/disconnect_from_network() ..() - solars_list.Remove(src) + sun.solars.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 + if(powernet) //if connected and not already in solar list... + sun.solars |= src return to_return //search for unconnected panels and trackers in the computer powernet and connect them diff --git a/paradise.dme b/paradise.dme index e2b6c726137..e4f7845b468 100644 --- a/paradise.dme +++ b/paradise.dme @@ -184,7 +184,6 @@ #include "code\datums\periodic_news.dm" #include "code\datums\recipe.dm" #include "code\datums\spell.dm" -#include "code\datums\sun.dm" #include "code\datums\supplypacks.dm" #include "code\datums\uplink_item.dm" #include "code\datums\helper_datums\construction_datum.dm"