Skip to content

Commit

Permalink
sql solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladisvell committed Oct 11, 2024
1 parent ea9e838 commit 7015005
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
44 changes: 34 additions & 10 deletions code/controllers/subsystem/non-firing/mapping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ SUBSYSTEM_DEF(mapping)
var/list/critical_planes
/// The largest plane offset we've generated so far
var/max_plane_offset = 0
/// Map played in previous round, stores typepath
var/played_map
/// 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 @@ -60,13 +60,6 @@ SUBSYSTEM_DEF(mapping)
map_datum = fallback_map // Assume delta if non-existent
fdel("data/next_map.txt") // Remove to avoid the same map existing forever

if(fexists("data/played_map.txt"))
var/list/lines_played = file2list("data/played_map.txt")
var/path = text2path(lines_played[1])
if(path)
played_map = path

fdel("data/played_map.txt")
return

map_datum = fallback_map // Assume delta if non-existent
Expand All @@ -79,9 +72,40 @@ SUBSYSTEM_DEF(mapping)
var/played_map = file("data/played_map.txt")
played_map << map_datum.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
7 changes: 3 additions & 4 deletions code/modules/vote/vote_presets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@
map_pool -= SSmapping.map_datum.type

if(CONFIG_GET(string/map_vote_mode) == "notriples")
if(SSmapping.played_map)
if(SSmapping.previous_maps && length(SSmapping.previous_maps))
var/current_map = SSmapping.map_datum.type
var/previous_map = SSmapping.played_map
if(current_map == previous_map)
map_pool -= previous_map
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))
Expand Down

0 comments on commit 7015005

Please sign in to comment.