mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-08-23 03:57:13 +01:00
Sun Controller Scheduler Integration
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
@@ -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()]")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user