Skip to content

Commit

Permalink
Day night cycle map config setting (#10283)
Browse files Browse the repository at this point in the history
* Day night cycle

* Update natural_light_cycle.dm
  • Loading branch information
PowerfulBacon authored Dec 19, 2023
1 parent 167d1ce commit ff56526
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions beestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@
#include "code\controllers\subsystem\minor_mapping.dm"
#include "code\controllers\subsystem\mobs.dm"
#include "code\controllers\subsystem\moods.dm"
#include "code\controllers\subsystem\natural_light_cycle.dm"
#include "code\controllers\subsystem\nightshift.dm"
#include "code\controllers\subsystem\npcpool.dm"
#include "code\controllers\subsystem\overlays.dm"
Expand Down
3 changes: 3 additions & 0 deletions code/__DEFINES/maps.dm
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,6 @@ require only minor tweaks.
#define SHELTER_DEPLOY_BAD_AREA "bad area"
/// Shelter spot has anchored objects that restrict deployment
#define SHELTER_DEPLOY_ANCHORED_OBJECTS "anchored objects"

#define STARLIGHT_MODE_STARLIGHT "starlight"
#define STARLIGHT_MODE_CYCLE "cycle"
1 change: 1 addition & 0 deletions code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
#define INIT_ORDER_PATH -50
#define INIT_ORDER_EXPLOSIONS -69
#define INIT_ORDER_ELEVATOR -70
#define INIT_ORDER_NATURAL_LIGHT -120
#define INIT_ORDER_CHAT -150 //Should be last to ensure chat remains smooth during init.

// Subsystem fire priority, from lowest to highest priority
Expand Down
3 changes: 3 additions & 0 deletions code/__DEFINES/time.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

#define DECISECONDS_IN_DAY 864000 //number of deciseconds in a day
#define MIDNIGHT_ROLLOVER 864000 //number of deciseconds in a day

#define JANUARY 1
Expand Down Expand Up @@ -59,3 +61,4 @@ When using time2text(), please use "DDD" to find the weekday. Refrain from using

/// Amount of years from the current year to offset in-universe
#define YEAR_OFFSET 540

4 changes: 2 additions & 2 deletions code/__HELPERS/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/// Returns the station time in deciseconds
/proc/station_time(display_only = FALSE, wtime=world.time)
return (((wtime - SSticker.round_start_time) * SSticker.station_time_rate_multiplier) + SSticker.gametime_offset) % 864000
return (((wtime - SSticker.round_start_time) * SSticker.station_time_rate_multiplier) + SSticker.gametime_offset) % DECISECONDS_IN_DAY

/// Returns the station time in hh:mm:ss
/proc/station_time_timestamp(format = "hh:mm:ss", wtime)
Expand All @@ -25,7 +25,7 @@
if(isnum_safe(force_set))
SSticker.gametime_offset = force_set
return
SSticker.gametime_offset = rand(0, 864000) //hours in day * minutes in hour * seconds in minute * deciseconds in second
SSticker.gametime_offset = rand(0, DECISECONDS_IN_DAY) //hours in day * minutes in hour * seconds in minute * deciseconds in second
if(prob(50))
SSticker.gametime_offset = FLOOR(SSticker.gametime_offset, 3600)
else
Expand Down
28 changes: 28 additions & 0 deletions code/controllers/subsystem/natural_light_cycle.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SUBSYSTEM_DEF(natural_light_cycle)
name = "Natural Light Cycle"
wait = 600
flags = SS_KEEP_TIMING
init_order = INIT_ORDER_NATURAL_LIGHT
var/list/cycle_colours = null

/datum/controller/subsystem/natural_light_cycle/Initialize(start_timeofday)
. = ..()
if (SSmapping.config.starlight_mode != STARLIGHT_MODE_CYCLE)
flags |= SS_NO_FIRE
return
cycle_colours = SSmapping.config.cycle_colours
if (!islist(cycle_colours) || !length(cycle_colours))
to_chat(world, "<span class='boldannounce'>WARNING: Starlight is set to cycle, yet the colours that are set to be cycled is undefined.</span>");
log_world("WARNING: Starlight is set to cycle, yet the colours that are set to be cycled is undefined.")
flags |= SS_NO_FIRE
return

/datum/controller/subsystem/natural_light_cycle/fire(resumed)
var/time = station_time()
var/next_proportion = min((((time + wait) % DECISECONDS_IN_DAY) / DECISECONDS_IN_DAY) * length(cycle_colours) + 1, length(cycle_colours))
var/next_index = FLOOR(next_proportion, 1)
var/next_offset = next_proportion - next_index
var/lower_colour = cycle_colours[next_index]
var/upper_colour = cycle_colours[((next_index - 1) % length(cycle_colours)) + 1]
var/blended_colour = BlendRGB(lower_colour, upper_colour, next_offset)
set_starlight_colour(blended_colour, wait)
10 changes: 10 additions & 0 deletions code/datums/map_config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
/// Is night lighting allowed to occur on this station?
var/allow_night_lighting = TRUE

//======
// Starlight Settings
//======

var/starlight_mode = STARLIGHT_MODE_STARLIGHT
var/list/cycle_colours = null

//======
// planetary Settings
//======
Expand Down Expand Up @@ -164,6 +171,9 @@
else
log_world("map_link missing from json!")

starlight_mode = json["starlight"] || STARLIGHT_MODE_STARLIGHT
cycle_colours = json["starlight_colours"] || null

allow_custom_shuttles = json["allow_custom_shuttles"] != FALSE
allow_night_lighting = json["allow_night_lighting"] != FALSE
planetary_station = !isnull(json["planetary_station"]) && json["planetary_station"] != FALSE
Expand Down
4 changes: 2 additions & 2 deletions code/modules/holiday/holidays.dm
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ Since Ramadan is an entire month that lasts 29.5 days on average, the start and
*/

/datum/holiday/ramadan/shouldCelebrate(dd, mm, yy, ww, ddd)
if (round(((world.realtime - 285984000) / 864000) % 354.373435326843) == 0)
if (round(((world.realtime - 285984000) / DECISECONDS_IN_DAY) % 354.373435326843) == 0)
return TRUE
return FALSE

Expand All @@ -499,7 +499,7 @@ Since Ramadan is an entire month that lasts 29.5 days on average, the start and
name = "End of Ramadan"

/datum/holiday/ramadan/end/shouldCelebrate(dd, mm, yy, ww, ddd)
if (round(((world.realtime - 312768000) / 864000) % 354.373435326843) == 0)
if (round(((world.realtime - 312768000) / DECISECONDS_IN_DAY) % 354.373435326843) == 0)
return TRUE
return FALSE

Expand Down

0 comments on commit ff56526

Please sign in to comment.