From a66126d7e335c5c1098438b4caa85ad57db6923d Mon Sep 17 00:00:00 2001 From: TheChosenEvilOne <34602646+TheChosenEvilOne@users.noreply.github.com> Date: Wed, 5 Jun 2019 00:55:14 +0300 Subject: [PATCH] Add map voting (#44244) - Add map voting - Rename config option for preferred map weighted map selection --- .../configuration/configuration.dm | 2 + .../configuration/entries/general.dm | 8 ++++ code/controllers/subsystem/mapping.dm | 12 +++-- code/controllers/subsystem/vote.dm | 44 +++++++++++++++++-- code/datums/map_config.dm | 1 + code/modules/client/preferences.dm | 4 +- config/config.txt | 9 ++-- config/maps.txt | 6 +++ 8 files changed, 76 insertions(+), 10 deletions(-) diff --git a/code/controllers/configuration/configuration.dm b/code/controllers/configuration/configuration.dm index 5e3bf6c6eaf923..3a57cfe81ceb55 100644 --- a/code/controllers/configuration/configuration.dm +++ b/code/controllers/configuration/configuration.dm @@ -290,6 +290,8 @@ currentmap.voteweight = text2num(data) if ("default","defaultmap") defaultmap = currentmap + if ("votable") + currentmap.votable = TRUE if ("endmap") LAZYINITLIST(maplist) maplist[currentmap.map_name] = currentmap diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm index ee4e05e7429363..999b5738b40e4c 100644 --- a/code/controllers/configuration/entries/general.dm +++ b/code/controllers/configuration/entries/general.dm @@ -91,6 +91,8 @@ /datum/config_entry/flag/allow_vote_mode // allow votes to change mode +/datum/config_entry/flag/allow_vote_map // allow votes to change map + /datum/config_entry/number/vote_delay // minimum time between voting sessions (deciseconds, 10 minute default) config_entry_value = 6000 integer = FALSE @@ -362,6 +364,12 @@ /datum/config_entry/flag/announce_admin_login /datum/config_entry/flag/allow_map_voting + deprecated_by = /datum/config_entry/flag/preference_map_voting + +/datum/config_entry/flag/allow_map_voting/DeprecationUpdate(value) + return value + +/datum/config_entry/flag/preference_map_voting /datum/config_entry/number/client_warn_version config_entry_value = null diff --git a/code/controllers/subsystem/mapping.dm b/code/controllers/subsystem/mapping.dm index aa97b16655706b..7c481485f23821 100644 --- a/code/controllers/subsystem/mapping.dm +++ b/code/controllers/subsystem/mapping.dm @@ -9,6 +9,8 @@ SUBSYSTEM_DEF(mapping) var/datum/map_config/config var/datum/map_config/next_map_config + var/map_voted = FALSE + var/list/map_templates = list() var/list/ruins_templates = list() @@ -274,11 +276,15 @@ GLOBAL_LIST_EMPTY(the_station_areas) log_world("ERROR: Station areas list failed to generate!") /datum/controller/subsystem/mapping/proc/maprotate() + if(map_voted) + map_voted = FALSE + return + var/players = GLOB.clients.len var/list/mapvotes = list() //count votes - var/amv = CONFIG_GET(flag/allow_map_voting) - if(amv) + var/pmv = CONFIG_GET(flag/preference_map_voting) + if(pmv) for (var/client/c in GLOB.clients) var/vote = c.prefs.preferred_map if (!vote) @@ -311,7 +317,7 @@ GLOBAL_LIST_EMPTY(the_station_areas) mapvotes.Remove(map) continue - if(amv) + if(pmv) mapvotes[map] = mapvotes[map]*VM.voteweight var/pickedmap = pickweight(mapvotes) diff --git a/code/controllers/subsystem/vote.dm b/code/controllers/subsystem/vote.dm index e78be6641d327d..a623736fbbf3d9 100644 --- a/code/controllers/subsystem/vote.dm +++ b/code/controllers/subsystem/vote.dm @@ -71,6 +71,13 @@ SUBSYSTEM_DEF(vote) choices[GLOB.master_mode] += non_voters.len if(choices[GLOB.master_mode] >= greatest_votes) greatest_votes = choices[GLOB.master_mode] + else if(mode == "map") + for (var/non_voter_ckey in non_voters) + var/client/C = non_voters[non_voter_ckey] + if(C.prefs.preferred_map) + choices[C.prefs.preferred_map] += 1 + else + choices[global.config.defaultmap.map_name] += 1 //get all options with that many votes and return them in a list . = list() if(greatest_votes) @@ -123,6 +130,9 @@ SUBSYSTEM_DEF(vote) restart = 1 else GLOB.master_mode = . + if("map") + SSmapping.changemap(global.config.maplist[.]) + SSmapping.map_voted = TRUE if(restart) var/active_admins = 0 for(var/client/C in GLOB.admins) @@ -171,6 +181,12 @@ SUBSYSTEM_DEF(vote) choices.Add("Restart Round","Continue Playing") if("gamemode") choices.Add(config.votable_modes) + if("map") + for(var/map in global.config.maplist) + var/datum/map_config/VM = config.maplist[map] + if(!VM.votable) + continue + choices.Add(VM.map_name) if("custom") question = stripped_input(usr,"What is the vote for?") if(!question) @@ -248,6 +264,16 @@ SUBSYSTEM_DEF(vote) if(trialmin) . += "\t([avm ? "Allowed" : "Disallowed"])" + . += "" + //map + var/avmap = CONFIG_GET(flag/allow_vote_map) + if(trialmin || avmap) + . += "Map" + else + . += "Map (Disallowed)" + if(trialmin) + . += "\t([avmap ? "Allowed" : "Disallowed"])" + . += "" //custom if(trialmin) @@ -260,6 +286,12 @@ SUBSYSTEM_DEF(vote) /datum/controller/subsystem/vote/Topic(href,href_list[],hsrc) if(!usr || !usr.client) return //not necessary but meh...just in-case somebody does something stupid + + var/trialmin = 0 + if(usr.client.holder) + if(check_rights_for(usr.client, R_ADMIN)) + trialmin = 1 + switch(href_list["vote"]) if("close") voting -= usr.client @@ -269,17 +301,23 @@ SUBSYSTEM_DEF(vote) if(usr.client.holder) reset() if("toggle_restart") - if(usr.client.holder) + if(usr.client.holder && trialmin) CONFIG_SET(flag/allow_vote_restart, !CONFIG_GET(flag/allow_vote_restart)) if("toggle_gamemode") - if(usr.client.holder) + if(usr.client.holder && trialmin) CONFIG_SET(flag/allow_vote_mode, !CONFIG_GET(flag/allow_vote_mode)) + if("toggle_map") + if(usr.client.holder && trialmin) + CONFIG_SET(flag/allow_vote_map, !CONFIG_GET(flag/allow_vote_map)) if("restart") if(CONFIG_GET(flag/allow_vote_restart) || usr.client.holder) initiate_vote("restart",usr.key) if("gamemode") if(CONFIG_GET(flag/allow_vote_mode) || usr.client.holder) initiate_vote("gamemode",usr.key) + if("map") + if(CONFIG_GET(flag/allow_vote_map) || usr.client.holder) + initiate_vote("map",usr.key) if("custom") if(usr.client.holder) initiate_vote("custom",usr.key) @@ -325,4 +363,4 @@ SUBSYSTEM_DEF(vote) else if(owner.ckey) var/datum/player_details/P = GLOB.player_details[owner.ckey] if(P) - P.player_actions -= src \ No newline at end of file + P.player_actions -= src diff --git a/code/datums/map_config.dm b/code/datums/map_config.dm index aabcc19fcc02df..78bff840fe0e4d 100644 --- a/code/datums/map_config.dm +++ b/code/datums/map_config.dm @@ -11,6 +11,7 @@ var/config_max_users = 0 var/config_min_users = 0 var/voteweight = 1 + var/votable = FALSE // Config actually from the JSON - should default to Box var/map_name = "Box Station" diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 9ff74310366e9a..7274257f9c561e 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -522,7 +522,7 @@ GLOBAL_LIST_EMPTY(preferences_datums) p_map = VM.map_name else p_map += " (No longer exists)" - if(CONFIG_GET(flag/allow_map_voting)) + if(CONFIG_GET(flag/preference_map_voting)) dat += "Preferred Map: [p_map]
" dat += "" @@ -1291,6 +1291,8 @@ GLOBAL_LIST_EMPTY(preferences_datums) default += " ([config.defaultmap.map_name])" for (var/M in config.maplist) var/datum/map_config/VM = config.maplist[M] + if(!VM.votable) + continue var/friendlyname = "[VM.map_name] " if (VM.voteweight <= 0) friendlyname += " (disabled)" diff --git a/config/config.txt b/config/config.txt index 83265ddba2e596..140860924e6247 100644 --- a/config/config.txt +++ b/config/config.txt @@ -164,9 +164,12 @@ ID_CONSOLE_JOBSLOT_DELAY 30 ## allow players to initiate a restart vote #ALLOW_VOTE_RESTART -## allow players to initate a mode-change start +## allow players to initiate a mode-change vote #ALLOW_VOTE_MODE +## allow players to initiate a map-change vote +#ALLOW_VOTE_MAP + ## min delay (deciseconds) between voting sessions (default 10 minutes) VOTE_DELAY 6000 @@ -371,9 +374,9 @@ ANNOUNCE_ADMIN_LOGOUT MAPROTATION ## Map voting -## Allows players to vote for their preffered map +## Allows players to vote with their preffered map setting ## When it's set to zero, the map will be randomly picked each round -ALLOW_MAP_VOTING 1 +PREFERENCE_MAP_VOTING 1 ## Map rotate chance delta ## This is the chance of map rotation factored to the round length. diff --git a/config/maps.txt b/config/maps.txt index 710e3d12b0a4ea..ec91772fd2353f 100644 --- a/config/maps.txt +++ b/config/maps.txt @@ -10,27 +10,33 @@ Format: default (The last map with this defined will get all votes of players who have not explicitly voted for a map) voteweight [number] (How much to count each player vote as, defaults to 1, setting to 0.5 counts each vote as half a vote, 2 as double, etc, Setting to 0 disables the map but allows players to still pick it) disabled (disables the map) + votable (is this map votable) endmap map boxstation default #voteweight 1.5 + votable endmap map metastation minplayers 25 #voteweight 0.5 + votable endmap map pubbystation + votable endmap map deltastation minplayers 50 + votable endmap map donutstation minplayers 50 + votable endmap map runtimestation