Creates SSplanets subsystem

For SPEEDYNESS

It probably works. I mean it's hard to sit there for 8 hours and test it. But it seems to work okay. At worst if it doesn't you'll have weather that doesn't make sense. ;v
This commit is contained in:
Arokha Sieyes
2018-06-02 19:09:35 -04:00
parent 6d8c607850
commit 462effc1d2
13 changed files with 212 additions and 133 deletions

View File

@@ -30,6 +30,7 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
#define INIT_ORDER_DEFAULT 0 #define INIT_ORDER_DEFAULT 0
#define INIT_ORDER_LIGHTING 0 #define INIT_ORDER_LIGHTING 0
#define INIT_ORDER_AIR -1 #define INIT_ORDER_AIR -1
#define INIT_ORDER_PLANETS -4
#define INIT_ORDER_OVERLAY -6 #define INIT_ORDER_OVERLAY -6
#define INIT_ORDER_XENOARCH -20 #define INIT_ORDER_XENOARCH -20
@@ -42,6 +43,7 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
#define FIRE_PRIORITY_AIRFLOW 30 #define FIRE_PRIORITY_AIRFLOW 30
#define FIRE_PRIORITY_AIR 35 #define FIRE_PRIORITY_AIR 35
#define FIRE_PRIORITY_DEFAULT 50 #define FIRE_PRIORITY_DEFAULT 50
#define FIRE_PRIORITY_PLANETS 75
#define FIRE_PRIORITY_MACHINES 100 #define FIRE_PRIORITY_MACHINES 100
#define FIRE_PRIORITY_OVERLAYS 500 #define FIRE_PRIORITY_OVERLAYS 500

View File

@@ -1,96 +0,0 @@
var/datum/controller/process/planet/planet_controller = null
/datum/controller/process/planet
var/list/planets = list()
var/list/z_to_planet = list()
/datum/controller/process/planet/setup()
name = "planet controller"
planet_controller = src
schedule_interval = 1 MINUTE
start_delay = 20 SECONDS
var/list/planet_datums = typesof(/datum/planet) - /datum/planet
for(var/P in planet_datums)
var/datum/planet/NP = new P()
planets.Add(NP)
allocateTurfs()
/datum/controller/process/planet/proc/allocateTurfs()
for(var/turf/simulated/OT in outdoor_turfs)
for(var/datum/planet/P in planets)
if(OT.z in P.expected_z_levels)
P.planet_floors |= OT
OT.vis_contents |= P.weather_holder.visuals
break
outdoor_turfs.Cut() //Why were you in there INCORRECTLY?
for(var/turf/unsimulated/wall/planetary/PW in planetary_walls)
for(var/datum/planet/P in planets)
if(PW.type == P.planetary_wall_type)
P.planet_walls |= PW
break
planetary_walls.Cut()
/datum/controller/process/planet/proc/unallocateTurf(var/turf/T)
for(var/planet in planets)
var/datum/planet/P = planet
if(T.z in P.expected_z_levels)
P.planet_floors -= T
T.vis_contents -= P.weather_holder.visuals
/datum/controller/process/planet/doWork()
if(outdoor_turfs.len || planetary_walls.len)
allocateTurfs()
for(var/datum/planet/P in planets)
P.process(schedule_interval / 10)
SCHECK //Your process() really shouldn't take this long...
//Sun light needs changing
if(P.needs_work & PLANET_PROCESS_SUN)
P.needs_work &= ~PLANET_PROCESS_SUN
// Remove old value from corners
var/list/sunlit_corners = P.sunlit_corners
var/old_lum_r = -P.sun["lum_r"]
var/old_lum_g = -P.sun["lum_g"]
var/old_lum_b = -P.sun["lum_b"]
if(old_lum_r || old_lum_g || old_lum_b)
for(var/C in P.sunlit_corners)
var/datum/lighting_corner/LC = C
LC.update_lumcount(old_lum_r, old_lum_g, old_lum_b)
SCHECK
sunlit_corners.Cut()
// Calculate new values to apply
var/new_brightness = P.sun["brightness"]
var/new_color = P.sun["color"]
var/lum_r = new_brightness * GetRedPart (new_color) / 255
var/lum_g = new_brightness * GetGreenPart(new_color) / 255
var/lum_b = new_brightness * GetBluePart (new_color) / 255
var/static/update_gen = -1 // Used to prevent double-processing corners. Otherwise would happen when looping over adjacent turfs.
for(var/I in P.planet_floors)
var/turf/simulated/T = I
if(!T.lighting_corners_initialised)
T.generate_missing_corners()
for(var/C in T.get_corners())
var/datum/lighting_corner/LC = C
if(LC.update_gen != update_gen && LC.active)
sunlit_corners += LC
LC.update_gen = update_gen
LC.update_lumcount(lum_r, lum_g, lum_b)
SCHECK
update_gen--
P.sun["lum_r"] = lum_r
P.sun["lum_g"] = lum_g
P.sun["lum_b"] = lum_b
//Temperature needs updating
if(P.needs_work & PLANET_PROCESS_TEMP)
P.needs_work &= ~PLANET_PROCESS_TEMP
//Set new temperatures
for(var/W in P.planet_walls)
var/turf/unsimulated/wall/planetary/wall = W
wall.set_temperature(P.weather_holder.temperature)
SCHECK

View File

@@ -0,0 +1,183 @@
SUBSYSTEM_DEF(planets)
name = "Planets"
init_order = INIT_ORDER_PLANETS
priority = FIRE_PRIORITY_PLANETS
wait = 2 SECONDS
flags = SS_BACKGROUND
runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME
var/list/new_outdoor_turfs = list()
var/list/new_outdoor_walls = list()
var/list/planets = list()
var/list/z_to_planet = list()
var/list/currentrun = list()
var/list/needs_sun_update = list()
var/list/needs_temp_update = list()
/datum/controller/subsystem/planets/Initialize(timeofday)
admin_notice("<span class='danger'>Initializing planetary weather.</span>", R_DEBUG)
createPlanets()
allocateTurfs(TRUE)
..()
/datum/controller/subsystem/planets/proc/createPlanets()
var/list/planet_datums = subtypesof(/datum/planet)
for(var/P in planet_datums)
var/datum/planet/NP = new P()
planets.Add(NP)
for(var/Z in NP.expected_z_levels)
if(Z > z_to_planet.len)
z_to_planet.len = Z
if(z_to_planet[Z])
admin_notice("<span class='danger'>Z[Z] is shared by more than one planet!</span>", R_DEBUG)
continue
z_to_planet[Z] = NP
/datum/controller/subsystem/planets/proc/addTurf(var/turf/T,var/is_edge)
if(is_edge)
new_outdoor_walls |= T
else
new_outdoor_turfs |= T
/datum/controller/subsystem/planets/proc/removeTurf(var/turf/T,var/is_edge)
if(is_edge)
new_outdoor_walls -= T
else
new_outdoor_turfs -= T
if(z_to_planet.len >= T.z)
var/datum/planet/P = z_to_planet[T.z]
if(!P)
return
if(is_edge)
P.planet_floors -= T
else
P.planet_walls -= T
/datum/controller/subsystem/planets/proc/allocateTurfs(var/initial = FALSE)
var/list/currentlist = new_outdoor_turfs
while(currentlist.len)
var/turf/simulated/OT = currentlist[currentlist.len]
currentlist.len--
if(istype(OT) && z_to_planet[OT.z])
var/datum/planet/P = z_to_planet[OT.z]
P.planet_floors |= OT
OT.vis_contents |= P.weather_holder.visuals
if(!initial && MC_TICK_CHECK)
return
currentlist = new_outdoor_walls
while(currentlist.len)
var/turf/unsimulated/wall/planetary/PW = currentlist[currentlist.len]
currentlist.len--
if(istype(PW) && z_to_planet[PW.z])
var/datum/planet/P = z_to_planet[PW.z]
P.planet_walls |= PW
if(!initial && MC_TICK_CHECK)
return
/datum/controller/subsystem/planets/proc/unallocateTurf(var/turf/simulated/T)
if(istype(T) && z_to_planet[T.z])
var/datum/planet/P = z_to_planet[T.z]
P.planet_floors -= T
T.vis_contents -= P.weather_holder.visuals
/datum/controller/subsystem/planets/fire(resumed = 0)
if(new_outdoor_turfs.len || new_outdoor_walls.len)
allocateTurfs()
if(!resumed)
src.currentrun = planets.Copy()
var/list/needs_sun_update = src.needs_sun_update
while(needs_sun_update.len)
var/datum/planet/P = needs_sun_update[needs_sun_update.len]
needs_sun_update.len--
updateSunlight(P)
if(MC_TICK_CHECK)
return
var/list/needs_temp_update = src.needs_temp_update
while(needs_temp_update.len)
var/datum/planet/P = needs_temp_update[needs_temp_update.len]
needs_temp_update.len--
updateTemp(P)
if(MC_TICK_CHECK)
return
var/list/currentrun = src.currentrun
while(currentrun.len)
var/datum/planet/P = currentrun[currentrun.len]
currentrun.len--
P.process(last_fire)
//Sun light needs changing
if(P.needs_work & PLANET_PROCESS_SUN)
P.needs_work &= ~PLANET_PROCESS_SUN
needs_sun_update |= P
//Temperature needs updating
if(P.needs_work & PLANET_PROCESS_TEMP)
P.needs_work &= ~PLANET_PROCESS_TEMP
needs_temp_update |= P
if(MC_TICK_CHECK)
return
/datum/controller/subsystem/planets/proc/updateSunlight(var/datum/planet/P)
// Remove old value from corners
var/list/sunlit_corners = P.sunlit_corners
var/old_lum_r = -P.sun["lum_r"]
var/old_lum_g = -P.sun["lum_g"]
var/old_lum_b = -P.sun["lum_b"]
if(old_lum_r || old_lum_g || old_lum_b)
for(var/C in sunlit_corners)
var/datum/lighting_corner/LC = C
LC.update_lumcount(old_lum_r, old_lum_g, old_lum_b)
CHECK_TICK
sunlit_corners.Cut()
// Calculate new values to apply
var/new_brightness = P.sun["brightness"]
var/new_color = P.sun["color"]
var/lum_r = new_brightness * GetRedPart (new_color) / 255
var/lum_g = new_brightness * GetGreenPart(new_color) / 255
var/lum_b = new_brightness * GetBluePart (new_color) / 255
var/static/update_gen = -1 // Used to prevent double-processing corners. Otherwise would happen when looping over adjacent turfs.
for(var/I in P.planet_floors)
var/turf/simulated/T = I
if(!T.lighting_corners_initialised)
T.generate_missing_corners()
for(var/C in T.get_corners())
var/datum/lighting_corner/LC = C
if(LC.update_gen != update_gen && LC.active)
sunlit_corners += LC
LC.update_gen = update_gen
LC.update_lumcount(lum_r, lum_g, lum_b)
CHECK_TICK
update_gen--
P.sun["lum_r"] = lum_r
P.sun["lum_g"] = lum_g
P.sun["lum_b"] = lum_b
/datum/controller/subsystem/planets/proc/updateTemp(var/datum/planet/P)
//Set new temperatures
for(var/W in P.planet_walls)
var/turf/unsimulated/wall/planetary/wall = W
wall.set_temperature(P.weather_holder.temperature)
CHECK_TICK
/datum/controller/subsystem/planets/proc/weatherDisco()
var/count = 100000
while(count > 0)
count--
for(var/planet in planets)
var/datum/planet/P = planet
if(P.weather_holder)
P.weather_holder.change_weather(pick(P.weather_holder.allowed_weather_types))
sleep(3)

View File

@@ -133,8 +133,5 @@
if("Vote") if("Vote")
debug_variables(vote) debug_variables(vote)
feedback_add_details("admin_verb", "DVote") feedback_add_details("admin_verb", "DVote")
if("Planets")
debug_variables(planet_controller)
feedback_add_details("admin_verb", "DPlanets")
message_admins("Admin [key_name_admin(usr)] is debugging the [controller] controller.") message_admins("Admin [key_name_admin(usr)] is debugging the [controller] controller.")
return return

View File

@@ -69,17 +69,16 @@
im_list_ui[++im_list_ui.len] = list("address" = I["address"], "to_address" = I["to_address"], "im" = I["im"]) im_list_ui[++im_list_ui.len] = list("address" = I["address"], "to_address" = I["to_address"], "im" = I["im"])
//Weather reports. //Weather reports.
if(planet_controller) for(var/datum/planet/planet in SSplanets.planets)
for(var/datum/planet/planet in planet_controller.planets) if(planet.weather_holder && planet.weather_holder.current_weather)
if(planet.weather_holder && planet.weather_holder.current_weather) var/list/W = list(
var/list/W = list( "Planet" = planet.name,
"Planet" = planet.name, "Time" = planet.current_time.show_time("hh:mm"),
"Time" = planet.current_time.show_time("hh:mm"), "Weather" = planet.weather_holder.current_weather.name,
"Weather" = planet.weather_holder.current_weather.name, "Temperature" = planet.weather_holder.temperature - T0C,
"Temperature" = planet.weather_holder.temperature - T0C, "High" = planet.weather_holder.current_weather.temp_high - T0C,
"High" = planet.weather_holder.current_weather.temp_high - T0C, "Low" = planet.weather_holder.current_weather.temp_low - T0C)
"Low" = planet.weather_holder.current_weather.temp_low - T0C) weather[++weather.len] = W
weather[++weather.len] = W
injection = "<div>Test</div>" injection = "<div>Test</div>"

View File

@@ -1,5 +1,4 @@
var/list/turf_edge_cache = list() var/list/turf_edge_cache = list()
var/list/outdoor_turfs = list()
/turf/ /turf/
// If greater than 0, this turf will apply edge overlays on top of other turfs cardinally adjacent to it, if those adjacent turfs are of a different icon_state, // If greater than 0, this turf will apply edge overlays on top of other turfs cardinally adjacent to it, if those adjacent turfs are of a different icon_state,
@@ -24,24 +23,21 @@ var/list/outdoor_turfs = list()
/turf/simulated/floor/New() /turf/simulated/floor/New()
if(outdoors) if(outdoors)
outdoor_turfs.Add(src) SSplanets.addTurf(src)
..() ..()
/turf/simulated/floor/Destroy() /turf/simulated/floor/Destroy()
if(outdoors) if(outdoors)
planet_controller.unallocateTurf(src) SSplanets.removeTurf(src)
return ..() return ..()
/turf/simulated/proc/make_outdoors() /turf/simulated/proc/make_outdoors()
outdoors = TRUE outdoors = TRUE
outdoor_turfs.Add(src) SSplanets.addTurf(src)
/turf/simulated/proc/make_indoors() /turf/simulated/proc/make_indoors()
outdoors = FALSE outdoors = FALSE
if(planet_controller) SSplanets.removeTurf(src)
planet_controller.unallocateTurf(src)
else // This is happening during map gen, if there's no planet_controller (hopefully).
outdoor_turfs -= src
/turf/simulated/post_change() /turf/simulated/post_change()
..() ..()

View File

@@ -14,7 +14,7 @@
/turf/simulated/sky/initialize() /turf/simulated/sky/initialize()
. = ..() . = ..()
outdoor_turfs.Add(src) SSplanets.addTurf(src)
set_light(2, 2, "#FFFFFF") set_light(2, 2, "#FFFFFF")
/turf/simulated/sky/north /turf/simulated/sky/north

View File

@@ -1,7 +1,5 @@
// This is a wall you surround the area of your "planet" with, that makes the atmosphere inside stay within bounds, even if canisters // This is a wall you surround the area of your "planet" with, that makes the atmosphere inside stay within bounds, even if canisters
// are opened or other strange things occur. // are opened or other strange things occur.
var/list/planetary_walls = list()
/turf/unsimulated/wall/planetary /turf/unsimulated/wall/planetary
name = "railroading" name = "railroading"
desc = "Choo choo!" desc = "Choo choo!"
@@ -21,10 +19,10 @@ var/list/planetary_walls = list()
/turf/unsimulated/wall/planetary/New() /turf/unsimulated/wall/planetary/New()
..() ..()
planetary_walls.Add(src) SSplanets.addTurf(src)
/turf/unsimulated/wall/planetary/Destroy() /turf/unsimulated/wall/planetary/Destroy()
planetary_walls.Remove(src) SSplanets.removeTurf(src)
..() ..()
/turf/unsimulated/wall/planetary/proc/set_temperature(var/new_temperature) /turf/unsimulated/wall/planetary/proc/set_temperature(var/new_temperature)

View File

@@ -637,7 +637,7 @@
if(!check_rights(R_DEBUG)) if(!check_rights(R_DEBUG))
return return
var/datum/planet/planet = input(usr, "Which planet do you want to modify the weather on?", "Change Weather") in planet_controller.planets var/datum/planet/planet = input(usr, "Which planet do you want to modify the weather on?", "Change Weather") in SSplanets.planets
var/datum/weather/new_weather = input(usr, "What weather do you want to change to?", "Change Weather") as null|anything in planet.weather_holder.allowed_weather_types var/datum/weather/new_weather = input(usr, "What weather do you want to change to?", "Change Weather") as null|anything in planet.weather_holder.allowed_weather_types
if(new_weather) if(new_weather)
planet.weather_holder.change_weather(new_weather) planet.weather_holder.change_weather(new_weather)
@@ -653,7 +653,7 @@
if(!check_rights(R_DEBUG)) if(!check_rights(R_DEBUG))
return return
var/datum/planet/planet = input(usr, "Which planet do you want to modify time on?", "Change Time") in planet_controller.planets var/datum/planet/planet = input(usr, "Which planet do you want to modify time on?", "Change Time") in SSplanets.planets
var/datum/time/current_time_datum = planet.current_time var/datum/time/current_time_datum = planet.current_time
var/new_hour = input(usr, "What hour do you want to change to?", "Change Time", text2num(current_time_datum.show_time("hh"))) as null|num var/new_hour = input(usr, "What hour do you want to change to?", "Change Time", text2num(current_time_datum.show_time("hh"))) as null|num

View File

@@ -6,9 +6,8 @@
endWhen = rand(15, 60) endWhen = rand(15, 60)
// Setup which levels we will disrupt gravit on. // Setup which levels we will disrupt gravit on.
zLevels = using_map.station_levels.Copy() zLevels = using_map.station_levels.Copy()
if (planet_controller) for(var/datum/planet/P in SSplanets.planets)
for(var/datum/planet/P in planet_controller.planets) zLevels -= P.expected_z_levels
zLevels -= P.expected_z_levels
/datum/event/gravity/announce() /datum/event/gravity/announce()
command_announcement.Announce("Feedback surge detected in mass-distributions systems. Artificial gravity has been disabled whilst the system \ command_announcement.Announce("Feedback surge detected in mass-distributions systems. Artificial gravity has been disabled whilst the system \

View File

@@ -30,9 +30,10 @@
current_time = current_time.make_random_time() current_time = current_time.make_random_time()
update_sun() update_sun()
/datum/planet/proc/process(amount) /datum/planet/proc/process(last_fire)
if(current_time) if(current_time)
current_time = current_time.add_seconds(amount) var/difference = world.time - last_fire
current_time = current_time.add_seconds(difference SECONDS)
update_weather() // We update this first, because some weather types decease the brightness of the sun. update_weather() // We update this first, because some weather types decease the brightness of the sun.
if(sun_last_process <= world.time - sun_process_interval) if(sun_last_process <= world.time - sun_process_interval)
update_sun() update_sun()

View File

@@ -184,7 +184,7 @@ datum/weather/sif
) )
/datum/weather/sif/snow/process_effects() /datum/weather/sif/snow/process_effects()
for(var/turf/simulated/floor/outdoors/snow/S in outdoor_turfs) for(var/turf/simulated/floor/outdoors/snow/S in SSplanets.new_outdoor_turfs) //This didn't make any sense before SSplanets, either
if(S.z in holder.our_planet.expected_z_levels) if(S.z in holder.our_planet.expected_z_levels)
for(var/dir_checked in cardinal) for(var/dir_checked in cardinal)
var/turf/simulated/floor/T = get_step(S, dir_checked) var/turf/simulated/floor/T = get_step(S, dir_checked)
@@ -207,7 +207,7 @@ datum/weather/sif
) )
/datum/weather/sif/blizzard/process_effects() /datum/weather/sif/blizzard/process_effects()
for(var/turf/simulated/floor/outdoors/snow/S in outdoor_turfs) for(var/turf/simulated/floor/outdoors/snow/S in SSplanets.new_outdoor_turfs) //This didn't make any sense before SSplanets, either
if(S.z in holder.our_planet.expected_z_levels) if(S.z in holder.our_planet.expected_z_levels)
for(var/dir_checked in cardinal) for(var/dir_checked in cardinal)
var/turf/simulated/floor/T = get_step(S, dir_checked) var/turf/simulated/floor/T = get_step(S, dir_checked)

View File

@@ -171,7 +171,6 @@
#include "code\controllers\Processes\mob.dm" #include "code\controllers\Processes\mob.dm"
#include "code\controllers\Processes\nanoui.dm" #include "code\controllers\Processes\nanoui.dm"
#include "code\controllers\Processes\obj.dm" #include "code\controllers\Processes\obj.dm"
#include "code\controllers\Processes\planet.dm"
#include "code\controllers\Processes\radiation.dm" #include "code\controllers\Processes\radiation.dm"
#include "code\controllers\Processes\scheduler.dm" #include "code\controllers\Processes\scheduler.dm"
#include "code\controllers\Processes\sun.dm" #include "code\controllers\Processes\sun.dm"
@@ -189,6 +188,7 @@
#include "code\controllers\subsystems\machines.dm" #include "code\controllers\subsystems\machines.dm"
#include "code\controllers\subsystems\orbits.dm" #include "code\controllers\subsystems\orbits.dm"
#include "code\controllers\subsystems\overlays.dm" #include "code\controllers\subsystems\overlays.dm"
#include "code\controllers\subsystems\planets.dm"
#include "code\controllers\subsystems\shuttles.dm" #include "code\controllers\subsystems\shuttles.dm"
#include "code\controllers\subsystems\xenoarch.dm" #include "code\controllers\subsystems\xenoarch.dm"
#include "code\datums\ai_law_sets.dm" #include "code\datums\ai_law_sets.dm"