From ad0cbe4b1d2c469fb8c8ae0fd23cf1f93bc24553 Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sun, 6 Nov 2022 19:52:19 +0000 Subject: [PATCH] Different day? Different map rotation rules. (#19159) * Different day? Different rotation rules. * Make this mergeable * Tweaks * Styling --- code/__DEFINES/misc.dm | 6 ++ .../sections/vote_configuration.dm | 9 +++ code/controllers/subsystem/maprotate.dm | 78 +++++++++++++++++++ code/controllers/subsystem/ticker.dm | 5 +- code/modules/vote/vote_presets.dm | 9 ++- config/example/config.toml | 18 +++++ paradise.dme | 1 + 7 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 code/controllers/subsystem/maprotate.dm diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index f1f2b8e461a..500d64b746b 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -495,6 +495,12 @@ #define LINDA_SPAWN_AGENT_B 128 #define LINDA_SPAWN_AIR 256 +// Throwing these defines here for the TM to minimise conflicts +#define MAPROTATION_MODE_NORMAL_VOTE "Vote" +#define MAPROTATION_MODE_NO_DUPLICATES "Nodupes" +#define MAPROTATION_MODE_FULL_RANDOM "Random" + + /// Send to the primary Discord webhook #define DISCORD_WEBHOOK_PRIMARY "PRIMARY" diff --git a/code/controllers/configuration/sections/vote_configuration.dm b/code/controllers/configuration/sections/vote_configuration.dm index 1f83c8c7ce5..dca4a78c241 100644 --- a/code/controllers/configuration/sections/vote_configuration.dm +++ b/code/controllers/configuration/sections/vote_configuration.dm @@ -14,6 +14,8 @@ var/enable_map_voting = FALSE /// If TRUE, you will not be able to vote for the current map var/non_repeating_maps = TRUE + /// Dictionary of day number (string) to vote string + var/list/map_vote_day_types = list() /datum/configuration_section/vote_configuration/load_data(list/data) // Use the load wrappers here. That way the default isnt made 'null' if you comment out the config line @@ -25,3 +27,10 @@ CONFIG_LOAD_NUM(vote_time, data["vote_time"]) CONFIG_LOAD_NUM(autotransfer_initial_time, data["autotransfer_initial_time"]) CONFIG_LOAD_NUM(autotransfer_interval_time, data["autotransfer_interval_time"]) + + // Load map vote data + if(islist(data["map_vote_day_types"])) + map_vote_day_types.Cut() + for(var/list/kvset in data["map_vote_day_types"]) + map_vote_day_types["[kvset["day_number"]]"] = kvset["rotation_type"] + diff --git a/code/controllers/subsystem/maprotate.dm b/code/controllers/subsystem/maprotate.dm new file mode 100644 index 00000000000..04851383707 --- /dev/null +++ b/code/controllers/subsystem/maprotate.dm @@ -0,0 +1,78 @@ +SUBSYSTEM_DEF(maprotate) + name = "Maprotate" + flags = SS_NO_FIRE + + var/rotation_mode = MAPROTATION_MODE_NORMAL_VOTE + var/setup_done = FALSE + +// Debugging purposes. Im not having people change this on the fly. +/datum/controller/subsystem/maprotate/vv_edit_var(var_name, var_value) + if(((var_name == "rotation_mode") || (var_name == "setup_done")) && !check_rights(R_MAINTAINER)) + return FALSE + + . = ..() + +/datum/controller/subsystem/maprotate/Initialize(start_timeofday) + if(!SSdbcore.IsConnected()) + return ..() + + // Make a quick list for number to date lookups + var/list/days = list("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday") + + // Make a map of rotation modes to descriptions + var/list/rotation_descs = list() + rotation_descs[MAPROTATION_MODE_NORMAL_VOTE] = "there is normal map voting." + rotation_descs[MAPROTATION_MODE_NO_DUPLICATES] = "map votes will not include the current map." + rotation_descs[MAPROTATION_MODE_FULL_RANDOM] = "the map for next round is randomised." + + // Yes. I am using the DB server to get a numerical weekday + // 0 = Monday + // 1 = Tuesday + // 2 = Wednesday + // 3 = Thursday + // 4 = Friday + // 5 = Saturday + // 6 = Sunday + + var/datum/db_query/dbq = SSdbcore.NewQuery("SELECT WEEKDAY(NOW()) AS d") + if(!dbq.warn_execute()) + log_startup_progress("Somehow, we failed to extract a numerical day from the DB. ?????????????") + return ..() + + var/day_index = 0 + + // Were gonna increase the DB value by 1 so we have 1-7, therefore we can use 0 as fail + + if(dbq.NextRow()) + day_index = text2num(dbq.item[1]) + 1 + + qdel(dbq) + + if(!day_index) + log_startup_progress("Somehow, we failed to extract a valid numerical day from the DB. ?????????????") + return ..() + + + // String interpolation is faster than num2text() for some reason + var/dindex_str = "[day_index]" + + // Special is defined for this day + if(dindex_str in GLOB.configuration.vote.map_vote_day_types) + var/vote_type = GLOB.configuration.vote.map_vote_day_types[dindex_str] + // We have an index, but is it valid + if(vote_type in list(MAPROTATION_MODE_NORMAL_VOTE, MAPROTATION_MODE_NO_DUPLICATES, MAPROTATION_MODE_FULL_RANDOM)) + log_startup_progress("It is [days[day_index]], which means [rotation_descs[vote_type]]") + rotation_mode = vote_type + setup_done = TRUE + + // Its not valid + else + log_startup_progress("The defined rotation mode for this day is invalid. Please inform AA.") + + // No special defined for this day + else + log_startup_progress("There is no special rotation defined for this day") + + + return ..() + diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 35598ab3944..22fa2595aaa 100644 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -134,7 +134,10 @@ SUBSYSTEM_DEF(ticker) auto_toggle_ooc(TRUE) // Turn it on declare_completion() addtimer(CALLBACK(src, .proc/call_reboot), 5 SECONDS) - if(GLOB.configuration.vote.enable_map_voting) + // Start a map vote IF + // - Map rotate doesnt have a mode for today and map voting is enabled + // - Map rotate has a mode for the day and it ISNT full random + if(((!SSmaprotate.setup_done) && GLOB.configuration.vote.enable_map_voting) || (SSmaprotate.setup_done && (SSmaprotate.rotation_mode != MAPROTATION_MODE_FULL_RANDOM))) SSvote.start_vote(new /datum/vote/map) else // Pick random map diff --git a/code/modules/vote/vote_presets.dm b/code/modules/vote/vote_presets.dm index 85e67c13aa9..06998674628 100644 --- a/code/modules/vote/vote_presets.dm +++ b/code/modules/vote/vote_presets.dm @@ -23,8 +23,13 @@ var/datum/map/M = x if(!initial(M.voteable)) continue - if(GLOB.configuration.vote.non_repeating_maps && istype(SSmapping.map_datum, M)) - continue + // Skip the current map if IF + // - Map rotate doesnt have a mode for today and the config is enabled for it + // - Map rotate has a mode for the day and it ISNT full random + if(((!SSmaprotate.setup_done) && GLOB.configuration.vote.non_repeating_maps) || (SSmaprotate.setup_done && (SSmaprotate.rotation_mode == MAPROTATION_MODE_NO_DUPLICATES))) + // And of course, if the current map is the same + if(istype(SSmapping.map_datum, M)) + continue choices.Add("[initial(M.fluff_name)] ([initial(M.technical_name)])") /datum/vote/map/announce() diff --git a/config/example/config.toml b/config/example/config.toml index b22297610d3..59d2582b9d9 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -815,6 +815,24 @@ disable_default_vote = true enable_map_voting = false # Set to true to prevent the same map from being voted on twice in a row non_repeating_maps = true +# Setup configuration here for specific rotation modes on specific days +# This will trump above options +# day_number = Numeric day of the week (1 = Mon, 7 = Sun) +# rotation_type = Rotation mode. +# - "Vote" = regular voting +# - "Nodupes" = voting wont include current map +# - "Random" = no vote, map is random +# If you dont enter one correctly, it will whine on startup +map_vote_day_types = [ + { day_number = 1, rotation_type = "Vote" }, # Monday + { day_number = 2, rotation_type = "Random" }, # Tuesday + { day_number = 3, rotation_type = "Vote" }, # Wednesday + { day_number = 4, rotation_type = "Random" }, # Thursday + { day_number = 5, rotation_type = "Vote" }, # Friday + { day_number = 6, rotation_type = "Nodupes" }, # Saturday + { day_number = 7, rotation_type = "Nodupes" }, # Sunday +] + ################################################################ diff --git a/paradise.dme b/paradise.dme index 7acb9ca86f6..43ca618c8e6 100644 --- a/paradise.dme +++ b/paradise.dme @@ -260,6 +260,7 @@ #include "code\controllers\subsystem\lighting.dm" #include "code\controllers\subsystem\machinery.dm" #include "code\controllers\subsystem\mapping.dm" +#include "code\controllers\subsystem\maprotate.dm" #include "code\controllers\subsystem\medals.dm" #include "code\controllers\subsystem\metrics.dm" #include "code\controllers\subsystem\mobs.dm"