Skip to content

Commit

Permalink
Allow completely overriding next map filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Oct 16, 2024
1 parent 84736cb commit a1aac7d
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions mods/ctf/ctf_modebase/map_catalog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ minetest.register_on_mods_loaded(function()
assert(#ctf_modebase.map_catalog.maps > 0 or ctf_core.settings.server_mode == "mapedit")
end)

function ctf_modebase.map_catalog.select_map(filter)
function ctf_modebase.map_catalog.select_map(filter, full_pool)
local maps = {}
for idx, map in ipairs(maps_pool) do
if not filter or filter(ctf_modebase.map_catalog.maps[map]) then
table.insert(maps, idx)
for _, pool in pairs({maps_pool, full_pool and used_maps}) do
for idx, map in ipairs(pool) do
if not filter or filter(ctf_modebase.map_catalog.maps[map]) then
table.insert(maps, full_pool and map or idx)
end
end
end

Expand All @@ -48,18 +50,22 @@ function ctf_modebase.map_catalog.select_map(filter)
selected = ctf_modebase.map_catalog.map_dirnames["plains"]
end

ctf_modebase.map_catalog.current_map = maps_pool[selected]
if full_pool then
ctf_modebase.map_catalog.current_map = selected
else
ctf_modebase.map_catalog.current_map = maps_pool[selected]

if map_repeat_interval > 0 then
if #used_maps < map_repeat_interval then
table.insert(used_maps, maps_pool[selected])
maps_pool[selected] = maps_pool[#maps_pool]
maps_pool[#maps_pool] = nil
else
used_maps[used_maps_idx], maps_pool[selected] = maps_pool[selected], used_maps[used_maps_idx]
used_maps_idx = used_maps_idx + 1
if used_maps_idx > #used_maps then
used_maps_idx = 1
if map_repeat_interval > 0 then
if #used_maps < map_repeat_interval then
table.insert(used_maps, maps_pool[selected])
maps_pool[selected] = maps_pool[#maps_pool]
maps_pool[#maps_pool] = nil
else
used_maps[used_maps_idx], maps_pool[selected] = maps_pool[selected], used_maps[used_maps_idx]
used_maps_idx = used_maps_idx + 1
if used_maps_idx > #used_maps then
used_maps_idx = 1
end
end
end
end
Expand Down

0 comments on commit a1aac7d

Please sign in to comment.