Add custom autoalloc mode (#30)
Adds a new alloc_mode 4. Setting config key `allocate_mode` to 4 will make `ctf.autoalloc` invoke `ctf.custom_alloc`. If unimplemented, `ctf.custom_alloc` will throw an error when invoked.
This commit is contained in:
parent
3d5421ae7c
commit
8f341538f4
@ -275,6 +275,7 @@ end
|
||||
|
||||
-- Automatic Allocation
|
||||
function ctf.autoalloc(name, alloc_mode)
|
||||
alloc_mode = alloc_mode or ctf.setting("allocate_mode")
|
||||
if alloc_mode == 0 then
|
||||
return
|
||||
end
|
||||
@ -365,11 +366,21 @@ function ctf.autoalloc(name, alloc_mode)
|
||||
else
|
||||
return smallest
|
||||
end
|
||||
elseif alloc_mode == 4 then
|
||||
return ctf.custom_alloc(name)
|
||||
else
|
||||
ctf.error("autoalloc", "Unknown allocation mode: "..ctf.setting("allocate_mode"))
|
||||
ctf.error("autoalloc",
|
||||
"Unknown allocation mode: " .. alloc_mode)
|
||||
end
|
||||
end
|
||||
|
||||
-- Custom team allocation function. Throws error
|
||||
-- if unimplemented, and autoalloc mode 4 is selected
|
||||
function ctf.custom_alloc()
|
||||
error("Allocation mode set to custom while " ..
|
||||
"ctf.custom_alloc hasn't been overridden!")
|
||||
end
|
||||
|
||||
-- updates the spawn position for a team
|
||||
function ctf.get_spawn(team)
|
||||
if ctf.team(team) then
|
||||
@ -423,12 +434,8 @@ function ctf.get_territory_owner(pos)
|
||||
end
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
||||
if alloc_mode == 0 then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local team = ctf.autoalloc(name, alloc_mode)
|
||||
local team = ctf.autoalloc(name)
|
||||
if team then
|
||||
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
||||
ctf.join(name, team)
|
||||
@ -447,11 +454,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
return
|
||||
end
|
||||
|
||||
local alloc_mode = tonumber(ctf.setting("allocate_mode"))
|
||||
if alloc_mode == 0 then
|
||||
return
|
||||
end
|
||||
local team = ctf.autoalloc(name, alloc_mode)
|
||||
local team = ctf.autoalloc(name)
|
||||
if team then
|
||||
ctf.log("autoalloc", name .. " was allocated to " .. team)
|
||||
ctf.join(name, team)
|
||||
|
Loading…
x
Reference in New Issue
Block a user