Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: New map voting mode "Notriples" - next map can't be selected if played twice in a row #5452

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion code/controllers/subsystem/non-firing/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ SUBSYSTEM_DEF(mapping)
var/list/critical_planes
/// The largest plane offset we've generated so far
var/max_plane_offset = 0
/// Maps played in previous rounds, stores typepaths
var/list/previous_maps


// This has to be here because world/New() uses [station_name()], which looks this datum up
Expand All @@ -57,17 +59,51 @@ SUBSYSTEM_DEF(mapping)
catch
map_datum = fallback_map // Assume delta if non-existent
fdel("data/next_map.txt") // Remove to avoid the same map existing forever

return

map_datum = fallback_map // Assume delta if non-existent

/datum/controller/subsystem/mapping/Shutdown()
if(next_map) // Save map for next round
var/F = file("data/next_map.txt")
F << next_map.type


/datum/controller/subsystem/mapping/proc/convert_map_datums()
var/list/map_subtypes = subtypesof(/datum/map)
var/list/result = list()
for(var/datum/map/subtype as anything in map_subtypes)
result[initial(subtype.name)] = subtype

return result

/datum/controller/subsystem/mapping/proc/find_last_played_maps()
if(CONFIG_GET(flag/sql_enabled))
var/datum/db_query/query = \
SSdbcore.NewQuery("SELECT id, map_name \
FROM [format_table_name("round")] \
WHERE server_port=[world.port] \
AND end_state IS NOT NULL \
ORDER BY id DESC LIMIT 1") //Generally gets the last played map, but can be configured to get any count.

if(!query.warn_execute())
qdel(query)
return

var/list/map_names = convert_map_datums()
var/list/maps = list()
//Query row structure: id, map_name
for(var/map in query.rows)
var/map_path = map_names[map[2]]
if(map_path)
maps += map_path

previous_maps = maps

/datum/controller/subsystem/mapping/Initialize()
setupPlanes()

find_last_played_maps()
var/datum/lavaland_theme/lavaland_theme_type = pick(subtypesof(/datum/lavaland_theme))
ASSERT(lavaland_theme_type)
lavaland_theme = new lavaland_theme_type
Expand Down
6 changes: 6 additions & 0 deletions code/modules/vote/vote_presets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
if(CONFIG_GET(string/map_vote_mode) == "nodoubles")
map_pool -= SSmapping.map_datum.type

if(CONFIG_GET(string/map_vote_mode) == "notriples")
if(SSmapping.previous_maps && length(SSmapping.previous_maps))
var/current_map = SSmapping.map_datum.type
if(current_map == SSmapping.previous_maps[1])
map_pool -= current_map

for(var/datum/map/possible_map as anything in map_pool)
if(initial(possible_map.admin_only))
continue
Expand Down
1 change: 1 addition & 0 deletions config/example/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ MAP_ROTATE none
## Server map voting mode:
## all - all maps can be selected
## nodoubles - current map can't be selected as next
## notriples - current map can't be selected as next if played twice in a row
MAP_VOTE_MODE all

## Default server map
Expand Down