From 323f7e651fbe7075fdd9ac6e5bb42d7b3193fd50 Mon Sep 17 00:00:00 2001 From: Arokha Sieyes Date: Fri, 8 May 2020 01:51:52 -0400 Subject: [PATCH 1/2] Fix/rename some timing stuff --- code/_helpers/time.dm | 28 ++++++++----------- code/controllers/autotransfer.dm | 6 ++-- code/controllers/subsystems/game_master.dm | 2 +- code/controllers/subsystems/nightshift.dm | 2 +- code/game/gamemodes/game_mode_latespawn.dm | 2 +- code/game/machinery/exonet_node.dm | 2 +- code/game/machinery/newscaster.dm | 2 +- code/modules/events/event_container.dm | 2 +- .../integrated_electronics/subtypes/time.dm | 8 +++--- maps/~map_system/maps.dm | 5 ++-- 10 files changed, 27 insertions(+), 32 deletions(-) diff --git a/code/_helpers/time.dm b/code/_helpers/time.dm index 62d217de4e7..db0a22a721e 100644 --- a/code/_helpers/time.dm +++ b/code/_helpers/time.dm @@ -36,25 +36,25 @@ return wtime + (time_offset + wusage) * world.tick_lag -var/roundstart_hour +GLOBAL_VAR_INIT(roundstart_hour, pick(2,7,12,17)) var/station_date = "" var/next_station_date_change = 1 DAY -#define duration2stationtime(time) time2text(station_time_in_ticks + time, "hh:mm") -#define worldtime2stationtime(time) time2text(roundstart_hour HOURS + time, "hh:mm") -#define round_duration_in_ticks (round_start_time ? world.time - round_start_time : 0) -#define station_time_in_ticks (roundstart_hour HOURS + round_duration_in_ticks) +#define duration2stationtime(time) time2text(station_time_in_ds + time, "hh:mm") +#define worldtime2stationtime(time) time2text(GLOB.roundstart_hour HOURS + time, "hh:mm") +#define round_duration_in_ds (GLOB.round_start_time ? world.time - GLOB.round_start_time : 0) +#define station_time_in_ds (GLOB.roundstart_hour HOURS + round_duration_in_ds) /proc/stationtime2text() - return time2text(station_time_in_ticks, "hh:mm") + return time2text(station_time_in_ds, "hh:mm") //For some reason, this is not accurate. It's expecting some other kind of times, maybe? Like ones from world.realtime? /proc/stationdate2text() var/update_time = FALSE - if(station_time_in_ticks > next_station_date_change) + if(station_time_in_ds > next_station_date_change) next_station_date_change += 1 DAY update_time = TRUE if(!station_date || update_time) - var/extra_days = round(station_time_in_ticks / (1 DAY)) DAYS + var/extra_days = round(station_time_in_ds / (1 DAY)) DAYS var/timeofday = world.timeofday + extra_days station_date = num2text((text2num(time2text(timeofday, "YYYY"))+300)) + "-" + time2text(timeofday, "MM-DD") //VOREStation Edit return station_date @@ -84,19 +84,19 @@ proc/isDay(var/month, var/day) var/next_duration_update = 0 var/last_round_duration = 0 -var/round_start_time = 0 +GLOBAL_VAR_INIT(round_start_time, 0) /hook/roundstart/proc/start_timer() - round_start_time = world.time + GLOB.round_start_time = world.time return 1 /proc/roundduration2text() - if(!round_start_time) + if(!GLOB.round_start_time) return "00:00" if(last_round_duration && world.time < next_duration_update) return last_round_duration - var/mills = round_duration_in_ticks // 1/10 of a second, not real milliseconds but whatever + var/mills = round_duration_in_ds // 1/10 of a second, not real milliseconds but whatever //var/secs = ((mills % 36000) % 600) / 10 //Not really needed, but I'll leave it here for refrence.. or something var/mins = round((mills % 36000) / 600) var/hours = round(mills / 36000) @@ -108,10 +108,6 @@ var/round_start_time = 0 next_duration_update = world.time + 1 MINUTES return last_round_duration -/hook/startup/proc/set_roundstart_hour() - roundstart_hour = pick(2,7,12,17) - return 1 - /var/midnight_rollovers = 0 /var/rollovercheck_last_timeofday = 0 /proc/update_midnight_rollover() diff --git a/code/controllers/autotransfer.dm b/code/controllers/autotransfer.dm index c59d124ab78..3d867473dc9 100644 --- a/code/controllers/autotransfer.dm +++ b/code/controllers/autotransfer.dm @@ -17,14 +17,14 @@ datum/controller/transfer_controller/Destroy() datum/controller/transfer_controller/process() currenttick = currenttick + 1 //VOREStation Edit START - if (round_duration_in_ticks >= shift_last_vote - 2 MINUTES) + if (round_duration_in_ds >= shift_last_vote - 2 MINUTES) shift_last_vote = 999999999999 //Setting to a stupidly high number since it'll be not used again. to_world("Warning: You have one hour left in the shift. Wrap up your scenes in the next 60 minutes before the transfer is called.") //VOREStation Edit - if (round_duration_in_ticks >= shift_hard_end - 1 MINUTE) + if (round_duration_in_ds >= shift_hard_end - 1 MINUTE) init_shift_change(null, 1) shift_hard_end = timerbuffer + config.vote_autotransfer_interval //If shuttle somehow gets recalled, let's force it to call again next time a vote would occur. timerbuffer = timerbuffer + config.vote_autotransfer_interval //Just to make sure a vote doesn't occur immediately afterwords. - else if (round_duration_in_ticks >= timerbuffer - 1 MINUTE) + else if (round_duration_in_ds >= timerbuffer - 1 MINUTE) SSvote.autotransfer() //VOREStation Edit END timerbuffer = timerbuffer + config.vote_autotransfer_interval diff --git a/code/controllers/subsystems/game_master.dm b/code/controllers/subsystems/game_master.dm index d5326bfba61..ce7e8176c31 100644 --- a/code/controllers/subsystems/game_master.dm +++ b/code/controllers/subsystems/game_master.dm @@ -109,7 +109,7 @@ SUBSYSTEM_DEF(game_master) return FALSE // Last minute antagging is bad for humans to do, so the GM will respect the start and end of the round. - var/mills = round_duration_in_ticks + var/mills = round_duration_in_ds var/mins = round((mills % 36000) / 600) var/hours = round(mills / 36000) diff --git a/code/controllers/subsystems/nightshift.dm b/code/controllers/subsystems/nightshift.dm index 9e89a05cee3..3f0d9bfda83 100644 --- a/code/controllers/subsystems/nightshift.dm +++ b/code/controllers/subsystems/nightshift.dm @@ -20,7 +20,7 @@ SUBSYSTEM_DEF(nightshift) return ..() /datum/controller/subsystem/nightshift/fire(resumed = FALSE) - if(round_duration_in_ticks < nightshift_first_check) + if(round_duration_in_ds < nightshift_first_check) return check_nightshift() diff --git a/code/game/gamemodes/game_mode_latespawn.dm b/code/game/gamemodes/game_mode_latespawn.dm index 578c1a0d8c6..9fcb4bd0ea7 100644 --- a/code/game/gamemodes/game_mode_latespawn.dm +++ b/code/game/gamemodes/game_mode_latespawn.dm @@ -34,7 +34,7 @@ if(emergency_shuttle.shuttle && (emergency_shuttle.shuttle.moving_status == SHUTTLE_WARMUP || emergency_shuttle.shuttle.moving_status == SHUTTLE_INTRANSIT)) return // Don't do anything if the shuttle's coming. - var/mills = round_duration_in_ticks + var/mills = round_duration_in_ds var/mins = round((mills % 36000) / 600) var/hours = round(mills / 36000) diff --git a/code/game/machinery/exonet_node.dm b/code/game/machinery/exonet_node.dm index 473ab1977f3..b9b95e103c4 100644 --- a/code/game/machinery/exonet_node.dm +++ b/code/game/machinery/exonet_node.dm @@ -175,7 +175,7 @@ // Description: This writes to the logs list, so that people can see what people are doing on the Exonet ingame. Note that this is not an admin logging function. // Communicators are already logged seperately. /obj/machinery/exonet_node/proc/write_log(var/origin_address, var/target_address, var/data_type, var/content) - //var/timestamp = time2text(station_time_in_ticks, "hh:mm:ss") + //var/timestamp = time2text(station_time_in_ds, "hh:mm:ss") var/timestamp = "[stationdate2text()] [stationtime2text()]" var/msg = "[timestamp] | FROM [origin_address] TO [target_address] | TYPE: [data_type] | CONTENT: [content]" logs.Add(msg) diff --git a/code/game/machinery/newscaster.dm b/code/game/machinery/newscaster.dm index 883a963fa2b..9fd9f749990 100644 --- a/code/game/machinery/newscaster.dm +++ b/code/game/machinery/newscaster.dm @@ -79,7 +79,7 @@ newMsg.body = msg newMsg.time_stamp = "[stationtime2text()]" newMsg.is_admin_message = adminMessage - newMsg.post_time = round_duration_in_ticks // Should be almost universally unique + newMsg.post_time = round_duration_in_ds // Should be almost universally unique if(message_type) newMsg.message_type = message_type if(photo) diff --git a/code/modules/events/event_container.dm b/code/modules/events/event_container.dm index 79c294c5ac9..458fe9fb565 100644 --- a/code/modules/events/event_container.dm +++ b/code/modules/events/event_container.dm @@ -22,7 +22,7 @@ var/global/list/severity_to_string = list(EVENT_LEVEL_MUNDANE = "Mundane", EVENT var/last_world_time = 0 /datum/event_container/process() - if(!round_start_time) + if(!GLOB.round_start_time) return //don't do events if the round hasn't even started yet if(!next_event_time) diff --git a/code/modules/integrated_electronics/subtypes/time.dm b/code/modules/integrated_electronics/subtypes/time.dm index df8e686b1f7..9633ef78813 100644 --- a/code/modules/integrated_electronics/subtypes/time.dm +++ b/code/modules/integrated_electronics/subtypes/time.dm @@ -86,10 +86,10 @@ power_draw_per_use = 4 /obj/item/integrated_circuit/time/clock/do_work() - set_pin_data(IC_OUTPUT, 1, time2text(station_time_in_ticks, "hh:mm:ss") ) - set_pin_data(IC_OUTPUT, 2, text2num(time2text(station_time_in_ticks, "hh") ) ) - set_pin_data(IC_OUTPUT, 3, text2num(time2text(station_time_in_ticks, "mm") ) ) - set_pin_data(IC_OUTPUT, 4, text2num(time2text(station_time_in_ticks, "ss") ) ) + set_pin_data(IC_OUTPUT, 1, time2text(station_time_in_ds, "hh:mm:ss") ) + set_pin_data(IC_OUTPUT, 2, text2num(time2text(station_time_in_ds, "hh") ) ) + set_pin_data(IC_OUTPUT, 3, text2num(time2text(station_time_in_ds, "mm") ) ) + set_pin_data(IC_OUTPUT, 4, text2num(time2text(station_time_in_ds, "ss") ) ) push_data() activate_pin(2) diff --git a/maps/~map_system/maps.dm b/maps/~map_system/maps.dm index a4b9d0f4b1e..ac26b495e6c 100644 --- a/maps/~map_system/maps.dm +++ b/maps/~map_system/maps.dm @@ -153,8 +153,7 @@ var/list/all_maps = list() // 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) + var/datum/time/T = new (station_time_in_ds) return T // Returns a boolean for if it's night or not on a particular zlevel @@ -162,7 +161,7 @@ var/list/all_maps = list() if(!z) z = 1 var/datum/time/now = get_zlevel_time(z) - var/percent = now.seconds_stored / now.seconds_in_day + var/percent = now.seconds_stored / now.seconds_in_day //practically all of these are in DS // First quarter, last quarter if(percent < 0.25 || percent > 0.75) From 6d47c2f95c14e1c679483f68da171817ecc46718 Mon Sep 17 00:00:00 2001 From: Arokha Sieyes Date: Fri, 8 May 2020 10:09:40 -0400 Subject: [PATCH 2/2] Further time fixes --- code/_helpers/time.dm | 9 ++++++++- code/game/world.dm | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/code/_helpers/time.dm b/code/_helpers/time.dm index db0a22a721e..6e63dabb45a 100644 --- a/code/_helpers/time.dm +++ b/code/_helpers/time.dm @@ -46,7 +46,7 @@ var/next_station_date_change = 1 DAY #define station_time_in_ds (GLOB.roundstart_hour HOURS + round_duration_in_ds) /proc/stationtime2text() - return time2text(station_time_in_ds, "hh:mm") //For some reason, this is not accurate. It's expecting some other kind of times, maybe? Like ones from world.realtime? + return time2text(station_time_in_ds + GLOB.timezoneOffset, "hh:mm") /proc/stationdate2text() var/update_time = FALSE @@ -65,6 +65,13 @@ var/next_station_date_change = 1 DAY var/time_portion = time2text(world.timeofday, "hh:mm:ss") return "[date_portion]T[time_portion]" +/proc/get_timezone_offset() + var/midnight_gmt_here = text2num(time2text(0,"hh")) * 36000 + if(midnight_gmt_here > 12 HOURS) + return 24 HOURS - midnight_gmt_here + else + return midnight_gmt_here + /proc/gameTimestamp(format = "hh:mm:ss", wtime=null) if(!wtime) wtime = world.time diff --git a/code/game/world.dm b/code/game/world.dm index e4735c93157..3385a494aea 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -25,7 +25,7 @@ // if(config && config.log_runtime) // log = file("data/logs/runtime/[time2text(world.realtime,"YYYY-MM-DD-(hh-mm-ss)")]-runtime.log") - GLOB.timezoneOffset = text2num(time2text(0,"hh")) * 36000 + GLOB.timezoneOffset = get_timezone_offset() callHook("startup") init_vchat()