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 += "