-
Notifications
You must be signed in to change notification settings - Fork 220
/
daycycle.dm
84 lines (72 loc) · 2.84 KB
/
daycycle.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/datum/daycycle
abstract_type = /datum/daycycle
var/list/suns = list(
new /datum/sun
)
/// Unique string ID used to register a level with a daycycle.
var/daycycle_id
/// How long is a full day and night cycle?
var/day_duration = 30 MINUTES
/// How far are we into the current cycle?
var/time_of_day = 0
/// What world.time did we last update? Used to calculate time progression between ticks.
var/last_update = 0
/// What z-levels are affected by this daycycle? Used for mass updating ambience.
var/list/levels_affected = list()
/// What period of day are we sitting in as of our last update?
var/datum/time_of_day/current_period
/// Mappings of colour and power to % progression points throughout the cycle.
/// Each entry must be arranged in order of earliest to latest.
/// Null values on periods use the general level ambience instead.
var/list/cycle_periods = list(
new /datum/time_of_day/sunrise,
new /datum/time_of_day/daytime,
new /datum/time_of_day/sunset,
new /datum/time_of_day/night
)
/datum/daycycle/New(_cycle_id)
daycycle_id = _cycle_id
last_update = world.time
current_period = cycle_periods[1]
transition_daylight() // pre-populate our values.
/datum/daycycle/proc/add_level(level_z)
levels_affected |= level_z
var/datum/level_data/level = SSmapping.levels_by_z[level_z]
if(level)
level.update_turf_ambience()
/datum/daycycle/proc/remove_level(level_z)
levels_affected -= level_z
var/datum/level_data/level = SSmapping.levels_by_z[level_z]
if(level)
level.update_turf_ambience()
/datum/daycycle/proc/transition_daylight()
time_of_day = (time_of_day + (world.time - last_update)) % day_duration
last_update = world.time
var/datum/time_of_day/last_period = current_period
var/progression_percentage = time_of_day / day_duration
for(var/datum/time_of_day/period in cycle_periods)
if(progression_percentage <= period.period)
current_period = period
break
. = (current_period.color != last_period.color || current_period.power != last_period.power)
if(current_period != last_period && current_period.announcement)
for(var/mob/player in global.player_list)
var/turf/T = get_turf(player)
if(T && (T.z in levels_affected) && T.is_outside())
to_chat(player, SPAN_NOTICE(FONT_SMALL(current_period.announcement)))
/datum/daycycle/proc/tick()
for(var/datum/sun/sun in suns)
sun.calc_position()
if(transition_daylight())
for(var/level_z in levels_affected)
var/datum/level_data/level = SSmapping.levels_by_z[level_z]
if(level)
level.update_turf_ambience()
/datum/daycycle/exoplanet/New()
day_duration = rand(get_config_value(/decl/config/num/exoplanet_min_day_duration), get_config_value(/decl/config/num/exoplanet_max_day_duration)) MINUTES
..()
// Dummy daycycle used solely so the sun datum has a chance to tick.
/datum/daycycle/solars
cycle_periods = list(
new /datum/time_of_day/permanent_daytime
)