mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
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:
@@ -30,6 +30,7 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
|
||||
#define INIT_ORDER_DEFAULT 0
|
||||
#define INIT_ORDER_LIGHTING 0
|
||||
#define INIT_ORDER_AIR -1
|
||||
#define INIT_ORDER_PLANETS -4
|
||||
#define INIT_ORDER_OVERLAY -6
|
||||
#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_AIR 35
|
||||
#define FIRE_PRIORITY_DEFAULT 50
|
||||
#define FIRE_PRIORITY_PLANETS 75
|
||||
#define FIRE_PRIORITY_MACHINES 100
|
||||
#define FIRE_PRIORITY_OVERLAYS 500
|
||||
|
||||
|
||||
@@ -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
|
||||
183
code/controllers/subsystems/planets.dm
Normal file
183
code/controllers/subsystems/planets.dm
Normal 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)
|
||||
@@ -133,8 +133,5 @@
|
||||
if("Vote")
|
||||
debug_variables(vote)
|
||||
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.")
|
||||
return
|
||||
|
||||
@@ -69,17 +69,16 @@
|
||||
im_list_ui[++im_list_ui.len] = list("address" = I["address"], "to_address" = I["to_address"], "im" = I["im"])
|
||||
|
||||
//Weather reports.
|
||||
if(planet_controller)
|
||||
for(var/datum/planet/planet in planet_controller.planets)
|
||||
if(planet.weather_holder && planet.weather_holder.current_weather)
|
||||
var/list/W = list(
|
||||
"Planet" = planet.name,
|
||||
"Time" = planet.current_time.show_time("hh:mm"),
|
||||
"Weather" = planet.weather_holder.current_weather.name,
|
||||
"Temperature" = planet.weather_holder.temperature - T0C,
|
||||
"High" = planet.weather_holder.current_weather.temp_high - T0C,
|
||||
"Low" = planet.weather_holder.current_weather.temp_low - T0C)
|
||||
weather[++weather.len] = W
|
||||
for(var/datum/planet/planet in SSplanets.planets)
|
||||
if(planet.weather_holder && planet.weather_holder.current_weather)
|
||||
var/list/W = list(
|
||||
"Planet" = planet.name,
|
||||
"Time" = planet.current_time.show_time("hh:mm"),
|
||||
"Weather" = planet.weather_holder.current_weather.name,
|
||||
"Temperature" = planet.weather_holder.temperature - T0C,
|
||||
"High" = planet.weather_holder.current_weather.temp_high - T0C,
|
||||
"Low" = planet.weather_holder.current_weather.temp_low - T0C)
|
||||
weather[++weather.len] = W
|
||||
|
||||
injection = "<div>Test</div>"
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
var/list/turf_edge_cache = list()
|
||||
var/list/outdoor_turfs = list()
|
||||
|
||||
/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,
|
||||
@@ -24,24 +23,21 @@ var/list/outdoor_turfs = list()
|
||||
|
||||
/turf/simulated/floor/New()
|
||||
if(outdoors)
|
||||
outdoor_turfs.Add(src)
|
||||
SSplanets.addTurf(src)
|
||||
..()
|
||||
|
||||
/turf/simulated/floor/Destroy()
|
||||
if(outdoors)
|
||||
planet_controller.unallocateTurf(src)
|
||||
SSplanets.removeTurf(src)
|
||||
return ..()
|
||||
|
||||
/turf/simulated/proc/make_outdoors()
|
||||
outdoors = TRUE
|
||||
outdoor_turfs.Add(src)
|
||||
SSplanets.addTurf(src)
|
||||
|
||||
/turf/simulated/proc/make_indoors()
|
||||
outdoors = FALSE
|
||||
if(planet_controller)
|
||||
planet_controller.unallocateTurf(src)
|
||||
else // This is happening during map gen, if there's no planet_controller (hopefully).
|
||||
outdoor_turfs -= src
|
||||
SSplanets.removeTurf(src)
|
||||
|
||||
/turf/simulated/post_change()
|
||||
..()
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
/turf/simulated/sky/initialize()
|
||||
. = ..()
|
||||
outdoor_turfs.Add(src)
|
||||
SSplanets.addTurf(src)
|
||||
set_light(2, 2, "#FFFFFF")
|
||||
|
||||
/turf/simulated/sky/north
|
||||
|
||||
@@ -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
|
||||
// are opened or other strange things occur.
|
||||
var/list/planetary_walls = list()
|
||||
|
||||
/turf/unsimulated/wall/planetary
|
||||
name = "railroading"
|
||||
desc = "Choo choo!"
|
||||
@@ -21,10 +19,10 @@ var/list/planetary_walls = list()
|
||||
|
||||
/turf/unsimulated/wall/planetary/New()
|
||||
..()
|
||||
planetary_walls.Add(src)
|
||||
SSplanets.addTurf(src)
|
||||
|
||||
/turf/unsimulated/wall/planetary/Destroy()
|
||||
planetary_walls.Remove(src)
|
||||
SSplanets.removeTurf(src)
|
||||
..()
|
||||
|
||||
/turf/unsimulated/wall/planetary/proc/set_temperature(var/new_temperature)
|
||||
|
||||
@@ -637,7 +637,7 @@
|
||||
if(!check_rights(R_DEBUG))
|
||||
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
|
||||
if(new_weather)
|
||||
planet.weather_holder.change_weather(new_weather)
|
||||
@@ -653,7 +653,7 @@
|
||||
if(!check_rights(R_DEBUG))
|
||||
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/new_hour = input(usr, "What hour do you want to change to?", "Change Time", text2num(current_time_datum.show_time("hh"))) as null|num
|
||||
|
||||
@@ -6,9 +6,8 @@
|
||||
endWhen = rand(15, 60)
|
||||
// Setup which levels we will disrupt gravit on.
|
||||
zLevels = using_map.station_levels.Copy()
|
||||
if (planet_controller)
|
||||
for(var/datum/planet/P in planet_controller.planets)
|
||||
zLevels -= P.expected_z_levels
|
||||
for(var/datum/planet/P in SSplanets.planets)
|
||||
zLevels -= P.expected_z_levels
|
||||
|
||||
/datum/event/gravity/announce()
|
||||
command_announcement.Announce("Feedback surge detected in mass-distributions systems. Artificial gravity has been disabled whilst the system \
|
||||
|
||||
@@ -30,9 +30,10 @@
|
||||
current_time = current_time.make_random_time()
|
||||
update_sun()
|
||||
|
||||
/datum/planet/proc/process(amount)
|
||||
/datum/planet/proc/process(last_fire)
|
||||
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.
|
||||
if(sun_last_process <= world.time - sun_process_interval)
|
||||
update_sun()
|
||||
|
||||
@@ -184,7 +184,7 @@ datum/weather/sif
|
||||
)
|
||||
|
||||
/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)
|
||||
for(var/dir_checked in cardinal)
|
||||
var/turf/simulated/floor/T = get_step(S, dir_checked)
|
||||
@@ -207,7 +207,7 @@ datum/weather/sif
|
||||
)
|
||||
|
||||
/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)
|
||||
for(var/dir_checked in cardinal)
|
||||
var/turf/simulated/floor/T = get_step(S, dir_checked)
|
||||
|
||||
@@ -171,7 +171,6 @@
|
||||
#include "code\controllers\Processes\mob.dm"
|
||||
#include "code\controllers\Processes\nanoui.dm"
|
||||
#include "code\controllers\Processes\obj.dm"
|
||||
#include "code\controllers\Processes\planet.dm"
|
||||
#include "code\controllers\Processes\radiation.dm"
|
||||
#include "code\controllers\Processes\scheduler.dm"
|
||||
#include "code\controllers\Processes\sun.dm"
|
||||
@@ -189,6 +188,7 @@
|
||||
#include "code\controllers\subsystems\machines.dm"
|
||||
#include "code\controllers\subsystems\orbits.dm"
|
||||
#include "code\controllers\subsystems\overlays.dm"
|
||||
#include "code\controllers\subsystems\planets.dm"
|
||||
#include "code\controllers\subsystems\shuttles.dm"
|
||||
#include "code\controllers\subsystems\xenoarch.dm"
|
||||
#include "code\datums\ai_law_sets.dm"
|
||||
|
||||
Reference in New Issue
Block a user