diff --git a/code/controllers/Processes/planet.dm b/code/controllers/Processes/planet.dm index f9fd57f788..63c7c8ad53 100644 --- a/code/controllers/Processes/planet.dm +++ b/code/controllers/Processes/planet.dm @@ -61,6 +61,13 @@ var/datum/controller/process/planet/planet_controller = null if(P.needs_work & PLANET_PROCESS_SUN) P.needs_work &= ~PLANET_PROCESS_SUN //Redraw sun overlay + var/new_brightness = P.sun["brightness"] + var/new_color = P.sun["color"] + for(var/A in P.planet_suns) + var/obj/effect/sun/sun = A + sun.set_light(sun.light_range, new_brightness, new_color) + SCHECK + /* var/new_range = P.sun["range"] var/new_brightness = P.sun["brightness"] var/new_color = P.sun["color"] @@ -68,6 +75,7 @@ var/datum/controller/process/planet/planet_controller = null var/turf/simulated/turf = T turf.set_light(new_range, new_brightness, new_color) SCHECK + */ //Temperature needs updating if(P.needs_work & PLANET_PROCESS_TEMP) diff --git a/code/modules/lighting/lighting_atom.dm b/code/modules/lighting/lighting_atom.dm index 8700a65c6e..2742d7590b 100644 --- a/code/modules/lighting/lighting_atom.dm +++ b/code/modules/lighting/lighting_atom.dm @@ -5,6 +5,7 @@ var/datum/light_source/light var/list/light_sources + var/light_datum_type = /datum/light_source // Nonsensical value for l_color default, so we can detect if it gets set to null. #define NONSENSICAL_VALUE -99999 @@ -41,7 +42,7 @@ if(light) light.update(.) else - light = new /datum/light_source(src, .) + light = new light_datum_type(src, .) /atom/New() . = ..() @@ -109,3 +110,19 @@ /obj/item/dropped() . = ..() update_light() + +/obj/effect/sun + name = "sun" + desc ="SUNTHESUNTHESUNTHESUNTHE" + icon = 'icons/effects/effects.dmi' + icon_state = "sun" + invisibility = 100 + anchored = TRUE + light_datum_type = /datum/light_source/sun + light_color = "#FFFFFF" + light_range = 65 + +/obj/effect/sun/Destroy(force = FALSE) + if(!force) + return QDEL_HINT_LETMELIVE + return ..() \ No newline at end of file diff --git a/code/modules/lighting/lighting_source.dm b/code/modules/lighting/lighting_source.dm index d878d8c4b6..e4d58466f2 100644 --- a/code/modules/lighting/lighting_source.dm +++ b/code/modules/lighting/lighting_source.dm @@ -284,6 +284,106 @@ C.affecting -= src effect_str -= C +#define APPLY_CORNER_NO_FALLOFF(C) \ + . = 1; \ + . *= light_power; \ + \ + effect_str[C] = .; \ + \ + C.update_lumcount \ + ( \ + . * applied_lum_r, \ + . * applied_lum_g, \ + . * applied_lum_b \ + ); + +// Special snowflake subtype used to light the Surface. +// The big differences is that this ignores FOV calculations (and as such doesn't use DVIEW) and instead applies it to all +// 'outdoor' turfs within range. +// Another difference is it has no falloff, meaning that it creates a big flat square instead of a circle that gets darker towards the edges. +/datum/light_source/sun + +/datum/light_source/sun/recalc_corner(var/datum/lighting_corner/C) + if(effect_str.Find(C)) // Already have one. + REMOVE_CORNER(C) + + APPLY_CORNER_NO_FALLOFF(C) + +/datum/light_source/sun/apply_lum() + var/static/update_gen = 1 + applied = 1 + + // Keep track of the last applied lum values so that the lighting can be reversed + applied_lum_r = lum_r + applied_lum_g = lum_g + applied_lum_b = lum_b + + for(var/thing in RANGE_TURFS(light_range, source_turf) ) + var/turf/T = thing + if(!T.lighting_corners_initialised) + T.generate_missing_corners() + + if(!T.outdoors) + continue + + for(var/datum/lighting_corner/C in T.get_corners()) + if(C.update_gen == update_gen) + continue + + C.update_gen = update_gen + C.affecting += src + + if(!C.active) + effect_str[C] = 0 + continue + + APPLY_CORNER_NO_FALLOFF(C) + + if(!T.affecting_lights) + T.affecting_lights = list() + + T.affecting_lights += src + affecting_turfs += T + + update_gen++ + +/datum/light_source/sun/smart_vis_update() + var/list/datum/lighting_corner/corners = list() + var/list/turf/turfs = list() + + for(var/thing in RANGE_TURFS(light_range, source_turf) ) + var/turf/T = thing + if(!T.lighting_corners_initialised) + T.generate_missing_corners() + corners |= T.get_corners() + turfs += T + + var/list/L = turfs - affecting_turfs // New turfs, add us to the affecting lights of them. + affecting_turfs += L + for(var/turf/T in L) + if(!T.affecting_lights) + T.affecting_lights = list(src) + else + T.affecting_lights += src + + L = affecting_turfs - turfs // Now-gone turfs, remove us from the affecting lights. + affecting_turfs -= L + for(var/turf/T in L) + T.affecting_lights -= src + + for(var/datum/lighting_corner/C in corners - effect_str) // New corners + C.affecting += src + if(!C.active) + effect_str[C] = 0 + continue + + APPLY_CORNER_NO_FALLOFF(C) + + for(var/datum/lighting_corner/C in effect_str - corners) // Old, now gone, corners. + REMOVE_CORNER(C) + C.affecting -= src + effect_str -= C + #undef effect_update #undef LUM_FALLOFF #undef REMOVE_CORNER diff --git a/code/modules/planet/planet.dm b/code/modules/planet/planet.dm index 97c7847fde..59183c8a98 100644 --- a/code/modules/planet/planet.dm +++ b/code/modules/planet/planet.dm @@ -13,12 +13,13 @@ var/sun_position = 0 // 0 means midnight, 1 means noon. var/list/sun = list("range","brightness","color") - var/expected_z_levels = list() + var/list/expected_z_levels = list() var/turf/unsimulated/wall/planetary/planetary_wall_type = /turf/unsimulated/wall/planetary var/list/turf/simulated/floor/planet_floors = list() var/list/turf/unsimulated/wall/planetary/planet_walls = list() + var/list/obj/effect/sun/planet_suns = list() var/needs_work = 0 // Bitflags to signal to the planet controller these need (properly deferrable) work. Flags defined in controller. @@ -27,6 +28,8 @@ ..() weather_holder = new(src) current_time = current_time.make_random_time() + if(expected_z_levels.len) + build_suns() update_sun() /datum/planet/proc/process(amount) @@ -50,3 +53,17 @@ sun["color"] = new_color needs_work |= PLANET_PROCESS_SUN +/datum/planet/proc/build_suns() + var/desired_suns_per_row = 15 + + var/sun_spacing = Ceiling(max(world.maxx, world.maxy) / desired_suns_per_row) + + for(var/z_level in expected_z_levels) // Z + for(var/i = 1 to desired_suns_per_row) // X + for(var/j = 1 to desired_suns_per_row) // Y + var/turf/T = locate(i * sun_spacing, j * sun_spacing, z_level) + if(T) // We might've walked off the map if this is null. + var/obj/effect/sun/new_sun = new(T) + new_sun.light_range = sun_spacing-1 + planet_suns += new_sun + diff --git a/icons/effects/effects.dmi b/icons/effects/effects.dmi index adcd4fbee2..93ff2d2ff9 100644 Binary files a/icons/effects/effects.dmi and b/icons/effects/effects.dmi differ