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

the next map is chosen based on player/map_size ratio #1192

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 20 additions & 2 deletions mods/ctf/ctf_modebase/map_catalog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,33 @@ end
init()
assert(#ctf_modebase.map_catalog.maps > 0 or ctf_core.settings.server_mode == "mapedit")

function ctf_modebase.map_catalog.select_map(filter)
function ctf_modebase.map_catalog.select_map(filter, player_map_size_ratio)
local ratio = player_map_size_ratio or (20 / 139 / 139)
-- This reference ratio is from the walls map. 20 player per 139x139
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)
end
end

local selected = maps[math.random(1, #maps)]
local selected_one = { ratio_difference = -1, map = -1 }
for _i = 1, 10, 1 do
local map = maps[math.random(1, #maps)]
local new_one_map = ctf_modebase.map_catalog.maps[maps_pool[map]]
local size = new_one_map.size
local new_one_ratio = #minetest.get_connected_players() / (size.x * size.z)
local ratio_difference = math.abs(new_one_ratio - ratio)
if ratio_difference < selected_one.ratio_difference then
selected_one.ratio_difference = ratio_difference
selected_one.map = map
end
end
local selected = selected_one.map
if selected == -1 then
selected = maps[math.random(1, #maps)]
end

ctf_modebase.map_catalog.current_map = maps_pool[selected]

if map_repeat_interval > 0 then
Expand Down
Loading