Spawners are now randomised when a match starts

master
Marco 2020-06-01 00:17:45 +02:00
parent 3e65800291
commit 1000feb6e8
2 changed files with 15 additions and 6 deletions

20
api.lua
View File

@ -12,7 +12,7 @@ local storage = minetest.get_mod_storage()
local function init_storage() end
local function update_storage() end
local function new_arena() end
local function copy_table() end
local function next_available_ID() end
local function timer_start() end
@ -198,7 +198,7 @@ function arena_lib.create_arena(sender, mod, arena_name, min_players, max_player
return end
-- creo l'arena
mod_ref.arenas[ID] = new_arena(arena_default)
mod_ref.arenas[ID] = copy_table(arena_default)
local arena = mod_ref.arenas[ID]
@ -499,6 +499,14 @@ function arena_lib.load_arena(mod, arena_ID)
arena.in_loading = true
arena_lib.update_sign(arena.sign, arena)
local shuffled_spawners = copy_table(arena.spawn_points)
-- randomizzo gli spawner
for i = #shuffled_spawners, 2, -1 do
local j = math.random(i)
shuffled_spawners[i], shuffled_spawners[j] = shuffled_spawners[j], shuffled_spawners[i]
end
-- per ogni giocatore...
for pl_name, _ in pairs(arena.players) do
@ -520,7 +528,7 @@ function arena_lib.load_arena(mod, arena_ID)
})
-- teletrasporto i giocatori
player:set_pos(arena.spawn_points[count])
player:set_pos(arena.shuffled_spawners[count])
-- svuoto eventualmente l'inventario
if not mod_ref.keep_inventory then
@ -1068,15 +1076,15 @@ end
--[[ Dato che in Lua non è possibile istanziare le tabelle copiandole, bisogna istanziare ogni campo in una nuova tabella.
Ricorsivo per le sottotabelle. Codice da => http://lua-users.org/wiki/CopyTable]]
function new_arena(orig)
function copy_table(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[new_arena(orig_key)] = new_arena(orig_value)
copy[copy_table(orig_key)] = copy_table(orig_value)
end
setmetatable(copy, new_arena(getmetatable(orig)))
setmetatable(copy, copy_table(getmetatable(orig)))
else -- number, string, boolean, etc
copy = orig
end

View File

@ -5,6 +5,7 @@ dofile(minetest.get_modpath("arena_lib") .. "/hud.lua")
dofile(minetest.get_modpath("arena_lib") .. "/items.lua")
dofile(minetest.get_modpath("arena_lib") .. "/player_manager.lua")
dofile(minetest.get_modpath("arena_lib") .. "/signs.lua")
dofile(minetest.get_modpath("arena_lib") .. "/utils.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_edit_tools/editor_main.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_edit_tools/editor_icons.lua")
dofile(minetest.get_modpath("arena_lib") .. "/_edit_tools/tools_sign.lua")