Skip to content

Commit

Permalink
Add map voting (#44244)
Browse files Browse the repository at this point in the history
- Add map voting
- Rename config option for preferred map weighted map selection
  • Loading branch information
TheChosenEvilOne authored and AnturK committed Jun 4, 2019
1 parent 9ec48dc commit a66126d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 10 deletions.
2 changes: 2 additions & 0 deletions code/controllers/configuration/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions code/controllers/configuration/entries/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions code/controllers/subsystem/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 41 additions & 3 deletions code/controllers/subsystem/vote.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -248,6 +264,16 @@ SUBSYSTEM_DEF(vote)
if(trialmin)
. += "\t(<a href='?src=[REF(src)];vote=toggle_gamemode'>[avm ? "Allowed" : "Disallowed"]</a>)"

. += "</li>"
//map
var/avmap = CONFIG_GET(flag/allow_vote_map)
if(trialmin || avmap)
. += "<a href='?src=[REF(src)];vote=map'>Map</a>"
else
. += "<font color='grey'>Map (Disallowed)</font>"
if(trialmin)
. += "\t(<a href='?src=[REF(src)];vote=toggle_map'>[avmap ? "Allowed" : "Disallowed"]</a>)"

. += "</li>"
//custom
if(trialmin)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
P.player_actions -= src
1 change: 1 addition & 0 deletions code/datums/map_config.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 3 additions & 1 deletion code/modules/client/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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 += "<b>Preferred Map:</b> <a href='?_src_=prefs;preference=preferred_map;task=input'>[p_map]</a><br>"

dat += "</td><td width='300px' height='300px' valign='top'>"
Expand Down Expand Up @@ -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)"
Expand Down
9 changes: 6 additions & 3 deletions config/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions config/maps.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a66126d

Please sign in to comment.