Port SSnightshift from Paradise

Makes the station have a night mode.
This commit is contained in:
Aronai Sieyes
2020-05-03 17:50:58 -04:00
parent 3c2b4c9865
commit aa6d22097b
11 changed files with 197 additions and 20 deletions

View File

@@ -82,6 +82,7 @@
#define LIGHT_COLOR_INCANDESCENT_TUBE "#FFFEB8" #define LIGHT_COLOR_INCANDESCENT_TUBE "#FFFEB8"
#define LIGHT_COLOR_INCANDESCENT_BULB "#FFDDBB" #define LIGHT_COLOR_INCANDESCENT_BULB "#FFDDBB"
#define LIGHT_COLOR_INCANDESCENT_FLASHLIGHT "#FFCC66" #define LIGHT_COLOR_INCANDESCENT_FLASHLIGHT "#FFCC66"
#define LIGHT_COLOR_NIGHTSHIFT "#EFCC86"
//Fake ambient occlusion filter //Fake ambient occlusion filter
#define AMBIENT_OCCLUSION filter(type="drop_shadow", x=0, y=-1, size=2, offset=2, color="#04080F55") //VOREStation Edit for prettier visuals. #define AMBIENT_OCCLUSION filter(type="drop_shadow", x=0, y=-1, size=2, offset=2, color="#04080F55") //VOREStation Edit for prettier visuals.

View File

@@ -68,8 +68,9 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
#define INIT_ORDER_ASSETS -3 #define INIT_ORDER_ASSETS -3
#define INIT_ORDER_PLANETS -4 #define INIT_ORDER_PLANETS -4
#define INIT_ORDER_HOLOMAPS -5 #define INIT_ORDER_HOLOMAPS -5
#define INIT_ORDER_OVERLAY -6 #define INIT_ORDER_NIGHTSHIFT -6
#define INIT_ORDER_ALARM -7 #define INIT_ORDER_OVERLAY -7
#define INIT_ORDER_ALARM -8
#define INIT_ORDER_OPENSPACE -10 #define INIT_ORDER_OPENSPACE -10
#define INIT_ORDER_XENOARCH -20 #define INIT_ORDER_XENOARCH -20
#define INIT_ORDER_CIRCUIT -21 #define INIT_ORDER_CIRCUIT -21
@@ -84,6 +85,7 @@ var/global/list/runlevel_flags = list(RUNLEVEL_LOBBY, RUNLEVEL_SETUP, RUNLEVEL_G
// If the subsystem isn't listed here it's either DEFAULT or PROCESS (if it's a processing subsystem child) // If the subsystem isn't listed here it's either DEFAULT or PROCESS (if it's a processing subsystem child)
#define FIRE_PRIORITY_SHUTTLES 5 #define FIRE_PRIORITY_SHUTTLES 5
#define FIRE_PRIORITY_SUPPLY 5 #define FIRE_PRIORITY_SUPPLY 5
#define FIRE_PRIORITY_NIGHTSHIFT 5
#define FIRE_PRIORITY_ORBIT 8 #define FIRE_PRIORITY_ORBIT 8
#define FIRE_PRIORITY_VOTE 9 #define FIRE_PRIORITY_VOTE 9
#define FIRE_PRIORITY_AI 10 #define FIRE_PRIORITY_AI 10

View File

@@ -270,6 +270,9 @@ var/list/gamemode_cache = list()
// disables the annoying "You have already logged in this round, disconnect or be banned" popup for multikeying, because it annoys the shit out of me when testing. // disables the annoying "You have already logged in this round, disconnect or be banned" popup for multikeying, because it annoys the shit out of me when testing.
var/static/disable_cid_warn_popup = FALSE var/static/disable_cid_warn_popup = FALSE
// whether or not to use the nightshift subsystem to perform lighting changes
var/static/enable_night_shifts = FALSE
/datum/configuration/New() /datum/configuration/New()
var/list/L = typesof(/datum/game_mode) - /datum/game_mode var/list/L = typesof(/datum/game_mode) - /datum/game_mode
for (var/T in L) for (var/T in L)
@@ -888,6 +891,9 @@ var/list/gamemode_cache = list()
if("disable_cid_warn_popup") if("disable_cid_warn_popup")
config.disable_cid_warn_popup = TRUE config.disable_cid_warn_popup = TRUE
if("enable_night_shifts")
config.enable_night_shifts = TRUE
else else
log_misc("Unknown setting in configuration: '[name]'") log_misc("Unknown setting in configuration: '[name]'")

View File

@@ -0,0 +1,62 @@
SUBSYSTEM_DEF(nightshift)
name = "Night Shift"
init_order = INIT_ORDER_NIGHTSHIFT
priority = FIRE_PRIORITY_NIGHTSHIFT
wait = 60 SECONDS
flags = SS_NO_TICK_CHECK
var/nightshift_active = FALSE
var/nightshift_first_check = 30 SECONDS
var/high_security_mode = FALSE
/datum/controller/subsystem/nightshift/Initialize()
if(!config.enable_night_shifts)
can_fire = FALSE
/*
if(config.randomize_shift_time)
GLOB.gametime_offset = rand(0, 23) HOURS
*/
return ..()
/datum/controller/subsystem/nightshift/fire(resumed = FALSE)
if(round_duration_in_ticks < nightshift_first_check)
return
check_nightshift()
/datum/controller/subsystem/nightshift/proc/announce(message)
var/announce_z
if(using_map.station_levels.len)
announce_z = pick(using_map.station_levels)
priority_announcement.Announce(message, new_title = "Automated Lighting System Announcement", new_sound = 'sound/misc/notice2.ogg', zlevel = announce_z)
/datum/controller/subsystem/nightshift/proc/check_nightshift(check_canfire=FALSE) //This is called from elsewhere, like setting the alert levels
if(check_canfire && !can_fire)
return
var/emergency = security_level > SEC_LEVEL_GREEN
var/announcing = TRUE
var/night_time = using_map.get_nightshift()
if(high_security_mode != emergency)
high_security_mode = emergency
if(night_time)
announcing = FALSE
if(!emergency)
announce("Restoring night lighting configuration to normal operation.")
else
announce("Disabling night lighting: Station is in a state of emergency.")
if(emergency)
night_time = FALSE
if(nightshift_active != night_time)
update_nightshift(night_time, announcing)
/datum/controller/subsystem/nightshift/proc/update_nightshift(active, announce = TRUE)
nightshift_active = active
if(announce)
if(active)
announce("Good evening, crew. To reduce power consumption and stimulate the circadian rhythms of some species, all of the lights aboard the station have been dimmed for the night.")
else
announce("Good morning, crew. As it is now day time, all of the lights aboard the station have been restored to their former brightness.")
for(var/obj/machinery/power/apc/apc in machines)
if(apc.z in using_map.station_levels)
apc.set_nightshift(active, TRUE)
CHECK_TICK

View File

@@ -120,6 +120,9 @@
var/global/list/status_overlays_environ var/global/list/status_overlays_environ
var/alarms_hidden = FALSE //If power alarms from this APC are visible on consoles var/alarms_hidden = FALSE //If power alarms from this APC are visible on consoles
var/nightshift_lights = FALSE
var/last_nightshift_switch = 0
/obj/machinery/power/apc/updateDialog() /obj/machinery/power/apc/updateDialog()
if (stat & (BROKEN|MAINT)) if (stat & (BROKEN|MAINT))
return return
@@ -798,6 +801,7 @@
"coverLocked" = coverlocked, "coverLocked" = coverlocked,
"siliconUser" = issilicon(user) || isobserver(user), //I add observer here so admins can have more control, even if it makes 'siliconUser' seem inaccurate. "siliconUser" = issilicon(user) || isobserver(user), //I add observer here so admins can have more control, even if it makes 'siliconUser' seem inaccurate.
"emergencyLights" = !emergency_lights, "emergencyLights" = !emergency_lights,
"nightshiftLights" = nightshift_lights,
"powerChannels" = list( "powerChannels" = list(
list( list(
@@ -970,6 +974,13 @@
update_icon() update_icon()
update() update()
else if(href_list["nightshift"])
if(last_nightshift_switch > world.time + 10 SECONDS) // don't spam...
to_chat(usr, "<span class='warning'>[src]'s night lighting circuit breaker is still cycling!</span>")
return 0
last_nightshift_switch = world.time
set_nightshift(!nightshift_lights)
else if (href_list["overload"]) else if (href_list["overload"])
if(istype(usr, /mob/living/silicon)) if(istype(usr, /mob/living/silicon))
src.overload_lighting() src.overload_lighting()
@@ -1366,4 +1377,13 @@ obj/machinery/power/apc/proc/autoset(var/cur_state, var/on)
if(src && grid_check == TRUE) if(src && grid_check == TRUE)
grid_check = FALSE grid_check = FALSE
/obj/machinery/power/apc/proc/set_nightshift(on, var/automated)
set waitfor = FALSE
if(automated && istype(area, /area/shuttle))
return
nightshift_lights = on
for(var/obj/machinery/light/L in area)
L.nightshift_mode(on)
CHECK_TICK
#undef APC_UPDATE_ICON_COOLDOWN #undef APC_UPDATE_ICON_COOLDOWN

View File

@@ -245,9 +245,18 @@ var/global/list/light_type_cache = list()
var/bulb_emergency_pow_mul = 0.75 // the multiplier for determining the light's power in emergency mode var/bulb_emergency_pow_mul = 0.75 // the multiplier for determining the light's power in emergency mode
var/bulb_emergency_pow_min = 0.5 // the minimum value for the light's power in emergency mode var/bulb_emergency_pow_min = 0.5 // the minimum value for the light's power in emergency mode
var/nightshift_enabled = FALSE
var/nightshift_allowed = TRUE
var/brightness_range_ns
var/brightness_power_ns
var/brightness_color_ns
/obj/machinery/light/flicker /obj/machinery/light/flicker
auto_flicker = TRUE auto_flicker = TRUE
/obj/machinery/light/no_nightshift
nightshift_allowed = FALSE
// the smaller bulb light fixture // the smaller bulb light fixture
/obj/machinery/light/small /obj/machinery/light/small
@@ -417,7 +426,10 @@ var/global/list/light_type_cache = list()
//VOREStation Edit End //VOREStation Edit End
if(on) if(on)
if(light_range != brightness_range || light_power != brightness_power || light_color != brightness_color) var/correct_range = nightshift_enabled ? brightness_range_ns : brightness_range
var/correct_power = nightshift_enabled ? brightness_power_ns : brightness_power
var/correct_color = nightshift_enabled ? brightness_color_ns : brightness_color
if(light_range != correct_range || light_power != correct_power || light_color != correct_color)
if(!auto_flicker) if(!auto_flicker)
switchcount++ switchcount++
if(rigged) if(rigged)
@@ -435,7 +447,7 @@ var/global/list/light_type_cache = list()
set_light(0) set_light(0)
else else
update_use_power(USE_POWER_ACTIVE) update_use_power(USE_POWER_ACTIVE)
set_light(brightness_range, brightness_power, brightness_color) set_light(correct_range, correct_power, correct_color)
else if(has_emergency_power(LIGHT_EMERGENCY_POWER_USE) && !turned_off()) else if(has_emergency_power(LIGHT_EMERGENCY_POWER_USE) && !turned_off())
update_use_power(USE_POWER_IDLE) update_use_power(USE_POWER_IDLE)
emergency_mode = TRUE emergency_mode = TRUE
@@ -446,6 +458,13 @@ var/global/list/light_type_cache = list()
update_active_power_usage((light_range * light_power) * LIGHTING_POWER_FACTOR) update_active_power_usage((light_range * light_power) * LIGHTING_POWER_FACTOR)
/obj/machinery/light/proc/nightshift_mode(var/state)
if(!nightshift_allowed)
return
if(state != nightshift_enabled)
nightshift_enabled = state
update(FALSE)
/obj/machinery/light/attack_generic(var/mob/user, var/damage) /obj/machinery/light/attack_generic(var/mob/user, var/damage)
if(!damage) if(!damage)
@@ -506,10 +525,15 @@ var/global/list/light_type_cache = list()
status = L.status status = L.status
switchcount = L.switchcount switchcount = L.switchcount
rigged = L.rigged rigged = L.rigged
brightness_range = L.brightness_range brightness_range = L.brightness_range
brightness_power = L.brightness_power brightness_power = L.brightness_power
brightness_color = L.brightness_color brightness_color = L.brightness_color
brightness_range_ns = L.nightshift_range
brightness_power_ns = L.nightshift_power
brightness_color_ns = L.nightshift_color
// attack with item - insert light (if right type), otherwise try to break the light // attack with item - insert light (if right type), otherwise try to break the light
/obj/machinery/light/proc/insert_bulb(obj/item/weapon/light/L) /obj/machinery/light/proc/insert_bulb(obj/item/weapon/light/L)
@@ -872,6 +896,10 @@ var/global/list/light_type_cache = list()
var/brightness_power = 1 var/brightness_power = 1
var/brightness_color = LIGHT_COLOR_INCANDESCENT_TUBE var/brightness_color = LIGHT_COLOR_INCANDESCENT_TUBE
var/nightshift_range = 8
var/nightshift_power = 0.7
var/nightshift_color = LIGHT_COLOR_NIGHTSHIFT
/obj/item/weapon/light/tube /obj/item/weapon/light/tube
name = "light tube" name = "light tube"
desc = "A replacement light tube." desc = "A replacement light tube."
@@ -888,6 +916,9 @@ var/global/list/light_type_cache = list()
brightness_range = 15 brightness_range = 15
brightness_power = 9 brightness_power = 9
nightshift_range = 10
nightshift_power = 0.9
/obj/item/weapon/light/bulb /obj/item/weapon/light/bulb
name = "light bulb" name = "light bulb"
desc = "A replacement light bulb." desc = "A replacement light bulb."
@@ -899,6 +930,9 @@ var/global/list/light_type_cache = list()
brightness_power = 4 brightness_power = 4
brightness_color = LIGHT_COLOR_INCANDESCENT_BULB brightness_color = LIGHT_COLOR_INCANDESCENT_BULB
nightshift_range = 3
nightshift_power = 0.35
/obj/item/weapon/light/throw_impact(atom/hit_atom) /obj/item/weapon/light/throw_impact(atom/hit_atom)
..() ..()
shatter() shatter()

View File

@@ -64,10 +64,6 @@
else else
security_announcement_down.Announce("[config.alert_desc_red_downto]", "Attention! Code red!") security_announcement_down.Announce("[config.alert_desc_red_downto]", "Attention! Code red!")
security_level = SEC_LEVEL_RED security_level = SEC_LEVEL_RED
/* - At the time of commit, setting status displays didn't work properly
var/obj/machinery/computer/communications/CC = locate(/obj/machinery/computer/communications,world)
if(CC)
CC.post_status("alert", "redalert")*/
if(SEC_LEVEL_DELTA) if(SEC_LEVEL_DELTA)
security_announcement_up.Announce("[config.alert_desc_delta]", "Attention! Delta alert level reached!", new_sound = 'sound/effects/siren.ogg') security_announcement_up.Announce("[config.alert_desc_delta]", "Attention! Delta alert level reached!", new_sound = 'sound/effects/siren.ogg')
security_level = SEC_LEVEL_DELTA security_level = SEC_LEVEL_DELTA
@@ -84,6 +80,10 @@
atc.reroute_traffic(yes = 1) // Tell them fuck off we're busy. atc.reroute_traffic(yes = 1) // Tell them fuck off we're busy.
else else
atc.reroute_traffic(yes = 0) atc.reroute_traffic(yes = 0)
spawn()
SSnightshift.check_nightshift()
admin_chat_message(message = "Security level is now: [uppertext(get_security_level())]", color = "#CC2222") //VOREStation Add admin_chat_message(message = "Security level is now: [uppertext(get_security_level())]", color = "#CC2222") //VOREStation Add
/proc/get_security_level() /proc/get_security_level()

View File

@@ -529,3 +529,6 @@ SQLITE_FEEDBACK_MIN_AGE 7
## Uncomment this if you want to disable the popup alert for people on the same CID (Don't do this on a live server if you ban multikeying) ## Uncomment this if you want to disable the popup alert for people on the same CID (Don't do this on a live server if you ban multikeying)
#DISABLE_CID_WARN_POPUP #DISABLE_CID_WARN_POPUP
## Comment this out if you don't want to use the 'nightshift lighting' subsystem to adjust lights based on ingame time
ENABLE_NIGHT_SHIFTS

View File

@@ -22,21 +22,26 @@ var/list/all_maps = list()
var/full_name = "Unnamed Map" var/full_name = "Unnamed Map"
var/path var/path
var/list/zlevels = list()
var/zlevel_datum_type // If populated, all subtypes of this type will be instantiated and used to populate the *_levels lists. var/zlevel_datum_type // If populated, all subtypes of this type will be instantiated and used to populate the *_levels lists.
var/list/station_levels = list() // Z-levels the station exists on
var/list/admin_levels = list() // Z-levels for admin functionality (Centcom, shuttle transit, etc)
var/list/contact_levels = list() // Z-levels that can be contacted from the station, for eg announcements
var/list/player_levels = list() // Z-levels a character can typically reach
var/list/sealed_levels = list() // Z-levels that don't allow random transit at edge
var/list/xenoarch_exempt_levels = list() //Z-levels exempt from xenoarch finds and digsites spawning.
var/list/empty_levels = null // Empty Z-levels that may be used for various things (currently used by bluespace jump)
var/list/map_levels // Z-levels available to various consoles, such as the crew monitor (when that gets coded in). Defaults to station_levels if unset.
var/list/base_turf_by_z = list() // Custom base turf by Z-level. Defaults to world.turf for unlisted Z-levels var/list/base_turf_by_z = list() // Custom base turf by Z-level. Defaults to world.turf for unlisted Z-levels
// Automatically populated lists made static for faster lookups
var/static/list/zlevels = list()
var/static/list/station_levels = list() // Z-levels the station exists on
var/static/list/admin_levels = list() // Z-levels for admin functionality (Centcom, shuttle transit, etc)
var/static/list/contact_levels = list() // Z-levels that can be contacted from the station, for eg announcements
var/static/list/player_levels = list() // Z-levels a character can typically reach
var/static/list/sealed_levels = list() // Z-levels that don't allow random transit at edge
var/static/list/xenoarch_exempt_levels = list() //Z-levels exempt from xenoarch finds and digsites spawning.
var/static/list/empty_levels = null // Empty Z-levels that may be used for various things (currently used by bluespace jump)
// End Static Lists
// Z-levels available to various consoles, such as the crew monitor. Defaults to station_levels if unset.
var/list/map_levels
// E-mail TLDs to use for NTnet modular computer e-mail addresses
var/list/usable_email_tlds = list("freemail.nt") var/list/usable_email_tlds = list("freemail.nt")
//This list contains the z-level numbers which can be accessed via space travel and the percentile chances to get there. //This list contains the z-level numbers which can be accessed via space travel and the percentile chances to get there.
var/list/accessible_z_levels = list() var/list/accessible_z_levels = list()
@@ -137,6 +142,40 @@ var/list/all_maps = list()
else else
default_skybox = new() default_skybox = new()
// Gets the current time on a current zlevel, and returns a time datum
/datum/map/proc/get_zlevel_time(var/z)
if(!z)
z = 1
var/datum/planet/P = SSplanets.z_to_planet[z]
// We found a planet tied to that zlevel, give them the time
if(istype(P))
return P.current_time
// We have to invent a time
else
var/seconds_stationtime = round(station_time_in_ticks*0.1) //Not actually ticks......
var/datum/time/T = new(seconds_stationtime)
return T
// Returns a boolean for if it's night or not on a particular zlevel
/datum/map/proc/get_night(var/z)
if(!z)
z = 1
var/datum/time/now = get_zlevel_time(z)
var/percent = now.seconds_stored / now.seconds_in_day
testing("get_night is [percent] through the day on [z]")
// First quarter, last quarter
if(percent < 0.25 || percent > 0.75)
return TRUE
// Second quarter, third quarter
else
return FALSE
// Boolean for if we should use SSnightshift night hours
/datum/map/proc/get_nightshift()
return get_night(1) //Defaults to z1, customize however you want on your own maps
/datum/map/proc/setup_map() /datum/map/proc/setup_map()
return return

View File

@@ -201,6 +201,15 @@
</div> </div>
</div> </div>
<div class="item">
<div class="itemLabel">
Night Lighting:
</div>
<div class="itemContent">
{{:helper.link(data.nightshiftLights ? 'Enabled' : 'Disabled', data.nightshiftLights ? 'power' : 'close', {'nightshift' : 1}, null)}}
</div>
</div>
{{if data.siliconUser}} {{if data.siliconUser}}
<h3>System Overrides</h3> <h3>System Overrides</h3>

View File

@@ -244,6 +244,7 @@
#include "code\controllers\subsystems\mapping_vr.dm" #include "code\controllers\subsystems\mapping_vr.dm"
#include "code\controllers\subsystems\mobs.dm" #include "code\controllers\subsystems\mobs.dm"
#include "code\controllers\subsystems\nanoui.dm" #include "code\controllers\subsystems\nanoui.dm"
#include "code\controllers\subsystems\nightshift.dm"
#include "code\controllers\subsystems\open_space.dm" #include "code\controllers\subsystems\open_space.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"