diff --git a/code/__defines/subsystems.dm b/code/__defines/subsystems.dm index d790514614..44137b0431 100644 --- a/code/__defines/subsystems.dm +++ b/code/__defines/subsystems.dm @@ -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 diff --git a/code/controllers/Processes/planet.dm b/code/controllers/Processes/planet.dm deleted file mode 100644 index 770b3a5e87..0000000000 --- a/code/controllers/Processes/planet.dm +++ /dev/null @@ -1,95 +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 - - 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 diff --git a/code/controllers/subsystems/planets.dm b/code/controllers/subsystems/planets.dm new file mode 100644 index 0000000000..2bb09050f4 --- /dev/null +++ b/code/controllers/subsystems/planets.dm @@ -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("Initializing planetary weather.", 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("Z[Z] is shared by more than one planet!", 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) diff --git a/code/controllers/verbs.dm b/code/controllers/verbs.dm index 8d02fda2eb..f1249cfe0c 100644 --- a/code/controllers/verbs.dm +++ b/code/controllers/verbs.dm @@ -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 diff --git a/code/game/objects/effects/decals/Cleanable/humans.dm b/code/game/objects/effects/decals/Cleanable/humans.dm index 90f708ff9d..0369b91d63 100644 --- a/code/game/objects/effects/decals/Cleanable/humans.dm +++ b/code/game/objects/effects/decals/Cleanable/humans.dm @@ -248,6 +248,6 @@ var/global/list/image/splatter_cache=list() //This version should be used for admin spawns and pre-mapped virus vectors (e.g. in PoIs), this version does not dry /obj/effect/decal/cleanable/mucus/mapped/New() - ...() + ..() virus2 = new /datum/disease2/disease virus2.makerandom() diff --git a/code/game/objects/items/devices/communicator/UI.dm b/code/game/objects/items/devices/communicator/UI.dm index 4d6ff75c50..fca4cf4866 100644 --- a/code/game/objects/items/devices/communicator/UI.dm +++ b/code/game/objects/items/devices/communicator/UI.dm @@ -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 = "