diff --git a/code/_onclick/hud/parallax.dm b/code/_onclick/hud/parallax/parallax.dm similarity index 96% rename from code/_onclick/hud/parallax.dm rename to code/_onclick/hud/parallax/parallax.dm index 9fc4f8986a2..ed6d6989556 100644 --- a/code/_onclick/hud/parallax.dm +++ b/code/_onclick/hud/parallax/parallax.dm @@ -17,7 +17,7 @@ C.parallax_layers_cached += new /atom/movable/screen/parallax_layer/layer_2(null, src) C.parallax_layers_cached += new /atom/movable/screen/parallax_layer/planet(null, src) if(SSparallax.random_layer) - C.parallax_layers_cached += new SSparallax.random_layer(null, src) + C.parallax_layers_cached += new SSparallax.random_layer.type(null, src, SSparallax.random_layer) C.parallax_layers_cached += new /atom/movable/screen/parallax_layer/layer_3(null, src) C.parallax_layers = C.parallax_layers_cached.Copy() @@ -271,9 +271,14 @@ INITIALIZE_IMMEDIATE(/atom/movable/screen/parallax_layer) screen_loc = "CENTER-7,CENTER-7" mouse_opacity = MOUSE_OPACITY_TRANSPARENT -/atom/movable/screen/parallax_layer/Initialize(mapload, datum/hud/hud_owner) +/atom/movable/screen/parallax_layer/Initialize(mapload, datum/hud/hud_owner, template = FALSE) . = ..() + + if(template) + return + var/client/boss = hud_owner?.mymob?.canon_client + if(!boss) // If this typepath all starts to harddel your culprit is likely this return INITIALIZE_HINT_QDEL @@ -322,22 +327,6 @@ INITIALIZE_IMMEDIATE(/atom/movable/screen/parallax_layer) speed = 1.4 layer = 3 -/atom/movable/screen/parallax_layer/random - blend_mode = BLEND_OVERLAY - speed = 3 - layer = 3 - -/atom/movable/screen/parallax_layer/random/space_gas - icon_state = "space_gas" - -/atom/movable/screen/parallax_layer/random/space_gas/Initialize(mapload, datum/hud/hud_owner) - . = ..() - add_atom_colour(SSparallax.random_parallax_color, ADMIN_COLOUR_PRIORITY) - -/atom/movable/screen/parallax_layer/random/asteroids - icon_state = "asteroids" - layer = 4 - /atom/movable/screen/parallax_layer/planet icon_state = "planet" blend_mode = BLEND_OVERLAY diff --git a/code/_onclick/hud/parallax/random_layer.dm b/code/_onclick/hud/parallax/random_layer.dm new file mode 100644 index 00000000000..86349aea0a6 --- /dev/null +++ b/code/_onclick/hud/parallax/random_layer.dm @@ -0,0 +1,51 @@ +/// Parallax layers that vary between rounds. Has come code to make sure we all have the same one +/atom/movable/screen/parallax_layer/random + blend_mode = BLEND_OVERLAY + speed = 3 + layer = 3 + +/atom/movable/screen/parallax_layer/random/Initialize(mapload, datum/hud/hud_owner, template, atom/movable/screen/parallax_layer/random/twin) + . = ..() + + if(twin) + copy_parallax(twin) + +/// Make this layer unique, with color or position or something +/atom/movable/screen/parallax_layer/random/proc/get_random_look() + +/// Copy a parallax instance to ensure parity between everyones parallax +/atom/movable/screen/parallax_layer/random/proc/copy_parallax(atom/movable/screen/parallax_layer/random/twin) + +/// For applying minor effects related to parallax. If you want big stuff, put it in a station trait or something +/atom/movable/screen/parallax_layer/random/proc/apply_global_effects() + +/// Gassy background with a few random colors, also tints starlight! +/atom/movable/screen/parallax_layer/random/space_gas + icon_state = "space_gas" + + /// The colors we can be + var/possible_colors = list(COLOR_TEAL, COLOR_GREEN, COLOR_SILVER, COLOR_YELLOW, COLOR_CYAN, COLOR_ORANGE, COLOR_PURPLE) + /// The color we are. If starlight_color is not set, we also become the starlight color + var/parallax_color + /// The color we give to starlight + var/starlight_color + +/atom/movable/screen/parallax_layer/random/space_gas/get_random_look() + parallax_color = parallax_color || pick(possible_colors) + +/atom/movable/screen/parallax_layer/random/space_gas/copy_parallax(atom/movable/screen/parallax_layer/random/space_gas/twin) + parallax_color = twin.parallax_color + add_atom_colour(parallax_color, ADMIN_COLOUR_PRIORITY) + +/atom/movable/screen/parallax_layer/random/space_gas/apply_global_effects() + GLOB.starlight_color = starlight_color || parallax_color + +/// Space gas but green for the radioactive nebula station trait +/atom/movable/screen/parallax_layer/random/space_gas/radioactive + parallax_color = list(0,0,0,0, 0,2,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0) //very vibrant green + starlight_color = COLOR_VIBRANT_LIME + +/// Big asteroid rocks appear in the background +/atom/movable/screen/parallax_layer/random/asteroids + icon_state = "asteroids" + layer = 4 diff --git a/code/controllers/subsystem/parallax.dm b/code/controllers/subsystem/parallax.dm index 1a597de84fb..b0c3b83c0e5 100644 --- a/code/controllers/subsystem/parallax.dm +++ b/code/controllers/subsystem/parallax.dm @@ -1,3 +1,6 @@ +/// Define for the pickweight value where you get no parallax +#define PARALLAX_NONE "parallax_none" + SUBSYSTEM_DEF(parallax) name = "Parallax" wait = 2 @@ -7,16 +10,21 @@ SUBSYSTEM_DEF(parallax) var/list/currentrun var/planet_x_offset = 128 var/planet_y_offset = 128 - var/random_layer - var/random_parallax_color + /// A random parallax layer that we sent to every player + var/atom/movable/screen/parallax_layer/random/random_layer + /// Weighted list with the parallax layers we could spawn + var/random_parallax_weights = list( + /atom/movable/screen/parallax_layer/random/space_gas = 35, + /atom/movable/screen/parallax_layer/random/asteroids = 35, + PARALLAX_NONE = 30, + ) //These are cached per client so needs to be done asap so people joining at roundstart do not miss these. /datum/controller/subsystem/parallax/PreInit() . = ..() - if(prob(70)) //70% chance to pick a special extra layer - random_layer = pick(/atom/movable/screen/parallax_layer/random/space_gas, /atom/movable/screen/parallax_layer/random/asteroids) - random_parallax_color = pick(COLOR_TEAL, COLOR_GREEN, COLOR_SILVER, COLOR_YELLOW, COLOR_CYAN, COLOR_ORANGE, COLOR_PURPLE)//Special color for random_layer1. Has to be done here so everyone sees the same color. + set_random_parallax_layer(pick_weight(random_parallax_weights)) + planet_y_offset = rand(100, 160) planet_x_offset = rand(100, 160) @@ -57,3 +65,32 @@ SUBSYSTEM_DEF(parallax) if (MC_TICK_CHECK) return currentrun = null + +/// Generate a random layer for parallax +/datum/controller/subsystem/parallax/proc/set_random_parallax_layer(picked_parallax) + if(picked_parallax == PARALLAX_NONE) + return + + random_layer = new picked_parallax(null, /* hud_owner = */ null, /* template = */ TRUE) + RegisterSignal(random_layer, COMSIG_QDELETING, PROC_REF(clear_references)) + random_layer.get_random_look() + +/// Change the random parallax layer after it's already been set. update_player_huds = TRUE will also replace them in the players client images, if it was set +/datum/controller/subsystem/parallax/proc/swap_out_random_parallax_layer(atom/movable/screen/parallax_layer/new_type, update_player_huds = TRUE) + set_random_parallax_layer(new_type) + + if(!update_player_huds) + return + + //Parallax is one of the first things to be set (during client join), so rarely is anything fast enough to swap it out + //That's why we need to swap the layers out for fast joining clients :/ + for(var/client/client as anything in GLOB.clients) + client.parallax_layers_cached?.Cut() + client.mob?.hud_used?.update_parallax_pref(client.mob) + +/datum/controller/subsystem/parallax/proc/clear_references() + SIGNAL_HANDLER + + random_layer = null + +#undef PARALLAX_NONE diff --git a/code/controllers/subsystem/processing/station.dm b/code/controllers/subsystem/processing/station.dm index fc07b0acd28..12d0431caca 100644 --- a/code/controllers/subsystem/processing/station.dm +++ b/code/controllers/subsystem/processing/station.dm @@ -21,6 +21,7 @@ PROCESSING_SUBSYSTEM_DEF(station) #endif announcer = new announcer() //Initialize the station's announcer datum + SSparallax.random_layer.apply_global_effects() //Apply station effects that parallax might have return SS_INIT_SUCCESS diff --git a/code/datums/station_traits/negative_traits.dm b/code/datums/station_traits/negative_traits.dm index 8614ac86621..4c4509dd1f0 100644 --- a/code/datums/station_traits/negative_traits.dm +++ b/code/datums/station_traits/negative_traits.dm @@ -429,27 +429,15 @@ show_in_report = TRUE - ///The color of the "nebula" we send to the players client - var/nebula_color ///The parallax layer of the nebula var/nebula_layer = /atom/movable/screen/parallax_layer/random/space_gas - ///The color space 'glows' - var/space_light_color = COLOR_STARLIGHT ///If set, gives the basic carp different colors var/carp_color_override /datum/station_trait/nebula/New() . = ..() - ///We set the parallax layer to give a visual effect - SSparallax.random_layer = nebula_layer - SSparallax.random_parallax_color = nebula_color //give a unique color to tell the player somethings up - GLOB.starlight_color = space_light_color //color starlight in our nebula color - - //parallax is generated for quick-joiners before we can change it, so reset it for them :/ - for(var/client/client as anything in GLOB.clients) - client.parallax_layers_cached?.Cut() - client.mob?.hud_used?.update_parallax_pref(client.mob) + SSparallax.swap_out_random_parallax_layer(nebula_layer) //Color the carp in unique colors to better blend with the nebula if(carp_color_override) @@ -541,8 +529,7 @@ intensity_increment_time = 5 MINUTES maximum_nebula_intensity = 1 HOURS + 40 MINUTES - nebula_color = list(0,0,0,0, 0,2,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0) //very vibrant green - space_light_color = COLOR_VIBRANT_LIME + nebula_layer = /atom/movable/screen/parallax_layer/random/space_gas/radioactive carp_color_override = list( COLOR_CARP_GREEN = 1, COLOR_CARP_TEAL = 1, diff --git a/tgstation.dme b/tgstation.dme index 451b65ce2f4..043a133302a 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -520,7 +520,6 @@ #include "code\_onclick\hud\movable_screen_objects.dm" #include "code\_onclick\hud\new_player.dm" #include "code\_onclick\hud\ooze.dm" -#include "code\_onclick\hud\parallax.dm" #include "code\_onclick\hud\picture_in_picture.dm" #include "code\_onclick\hud\radial.dm" #include "code\_onclick\hud\radial_persistent.dm" @@ -529,6 +528,8 @@ #include "code\_onclick\hud\screen_object_holder.dm" #include "code\_onclick\hud\screen_objects.dm" #include "code\_onclick\hud\screentip.dm" +#include "code\_onclick\hud\parallax\parallax.dm" +#include "code\_onclick\hud\parallax\random_layer.dm" #include "code\_onclick\hud\rendering\plane_master.dm" #include "code\_onclick\hud\rendering\plane_master_controller.dm" #include "code\_onclick\hud\rendering\plane_master_group.dm"