Merge ctf_team_base into ctf_map

This commit is contained in:
rubenwardy 2019-03-17 01:36:15 +00:00 committed by GitHub
parent 5643fdf802
commit 762682ea80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 28 additions and 47 deletions

43
mods/ctf/ctf_map/base.lua Normal file
View file

@ -0,0 +1,43 @@
function ctf_map.place_base(color, pos)
-- Spawn ind base
for x = pos.x - 2, pos.x + 2 do
for z = pos.z - 2, pos.z + 2 do
minetest.set_node({ x = x, y = pos.y - 1, z = z},
{name = "ctf_map:ind_cobble"})
end
end
-- Check for trees
for y = pos.y, pos.y + 3 do
for x = pos.x - 3, pos.x + 3 do
for z = pos.z - 3, pos.z + 3 do
local pos2 = {x=x, y=y, z=z}
if minetest.get_node(pos2).name == "default:tree" then
minetest.set_node(pos2, {name="air"})
end
end
end
end
-- Spawn chest
local chest = {name = "ctf_map:chest_" .. color}
local dz = 2
if pos.z < 0 then
dz = -2
chest.param2 = minetest.dir_to_facedir({x=0,y=0,z=-1})
end
local pos3 = {
x = pos.x,
y = pos.y,
z = pos.z + dz
}
minetest.set_node(pos3, chest)
local inv = minetest.get_meta(pos3):get_inventory()
inv:add_item("main", ItemStack("default:cobble 99"))
inv:add_item("main", ItemStack("default:cobble 99"))
inv:add_item("main", ItemStack("default:cobble 99"))
inv:add_item("main", ItemStack("default:wood 99"))
inv:add_item("main", ItemStack("default:stick 30"))
inv:add_item("main", ItemStack("default:glass 5"))
inv:add_item("main", ItemStack("default:torch 10"))
end

211
mods/ctf/ctf_map/chest.lua Normal file
View file

@ -0,0 +1,211 @@
local blacklist = {
"default:pick_wood",
"default:axe_wood",
"default:shovel_wood",
"default:sword_wood",
"default:leaves",
"default:jungleleaves",
"default:pine_needles",
"default:acacia_leaves",
"default:aspen_leaves"
}
local function max(a, b)
return (a > b) and a or b
end
local function get_is_player_pro(pstat)
local kd = pstat.kills / max(pstat.deaths, 1)
return pstat.score > 1000 and kd > 1.5
end
local colors = {"red", "blue"}
for _, chest_color in pairs(colors) do
minetest.register_node("ctf_map:chest_" .. chest_color, {
description = "Chest",
tiles = {
"default_chest_top_" .. chest_color .. ".png",
"default_chest_top_" .. chest_color .. ".png",
"default_chest_side_" .. chest_color .. ".png",
"default_chest_side_" .. chest_color .. ".png",
"default_chest_side_" .. chest_color .. ".png",
"default_chest_front_" .. chest_color .. ".png"},
paramtype2 = "facedir",
groups = {immortal = 1, team_chest=1},
legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Chest")
local inv = meta:get_inventory()
inv:set_size("main", 5*4)
inv:set_size("pro", 3*4)
inv:set_size("helper", 1*1)
end,
on_rightclick = function(pos, node, player)
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return
end
local territory_owner = ctf.get_territory_owner(pos)
if chest_color ~= territory_owner then
if not territory_owner then
ctf.warning("ctf_map", "Unowned team chest")
minetest.set_node(pos, { name = "air" })
return
end
ctf.warning("ctf_map", "Wrong chest, changing to " .. territory_owner .. " from " .. chest_color)
minetest.set_node(pos, "ctf_map:chest_" .. territory_owner)
end
local formspec = table.concat({
"size[8,9]",
default.gui_bg,
default.gui_bg_img,
default.gui_slots,
"list[current_player;main;0,4.85;8,1;]",
"list[current_player;main;0,6.08;8,3;8]",
}, "")
local pstat = ctf_stats.player(player:get_player_name())
if not pstat or not pstat.score or pstat.score < 10 then
local msg = "You need at least 10 score to access the team chest.\n" ..
"Try killing an enemy player, or at least attempting to capture the flag.\n" ..
"Find resources in chests scattered around the map."
formspec = formspec .. "label[1,1;" .. minetest.formspec_escape(msg) .. "]"
minetest.show_formspec(player:get_player_name(), "ctf_map:no_access", formspec)
return
end
local is_pro = get_is_player_pro(pstat)
local chestinv = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z
formspec = formspec ..
"label[0,-0.2;" .. minetest.formspec_escape("Any team member can take from here") .. "]" ..
"list[" .. chestinv .. ";main;0,0.3;5,4;]" ..
"background[5,-0.2;3.15,4.7;ctf_map_pro_only.png;false]" ..
"list[" .. chestinv .. ";pro;5,0.3;3,4;]"
if is_pro then
formspec = formspec .. "listring[" .. chestinv ..";pro]" ..
"listring[" .. chestinv .. ";helper]" ..
"label[5,-0.2;" .. minetest.formspec_escape("Pro players only (1k+ score, 1.5+ KD)") .. "]"
else
formspec = formspec ..
"label[5,-0.2;" .. minetest.formspec_escape("You need 1k+ score and 1.5+ KD") .. "]"
end
formspec = formspec ..
"listring[" .. chestinv ..";main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0,4.85)
minetest.show_formspec(player:get_player_name(), "ctf_map:chest", formspec)
end,
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0
end
local pstat = ctf_stats.player(player:get_player_name())
if not pstat or not pstat.score or pstat.score < 10 then
return 0
end
if (from_list ~= "pro" and to_list ~= "pro") or get_is_player_pro(pstat) then
if to_list == "helper" then
-- handle move & overflow
local chestinv = minetest.get_inventory({type = "node", pos = pos})
local playerinv = player:get_inventory()
local stack = chestinv:get_stack(from_list, from_index)
local leftover = playerinv:add_item("main", stack)
local n_stack = stack
n_stack:set_count(stack:get_count() - leftover:get_count())
chestinv:remove_item("helper", stack)
chestinv:remove_item("pro", n_stack)
return 0
elseif from_list == "helper" then
return 0
else
return count
end
else
return 0
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "helper" then
return 0
end
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0
end
for _, itemstring in ipairs(blacklist) do
if stack:get_name() == itemstring then
return 0
end
end
local pstat = ctf_stats.player(player:get_player_name())
if not pstat or not pstat.score or pstat.score < 10 then
return 0
end
if listname ~= "pro" or get_is_player_pro(pstat) then
local chestinv = minetest.get_inventory({type = "node", pos = pos})
if chestinv:room_for_item("pro", stack) then
return stack:get_count()
else
-- handle overflow
local playerinv = player:get_inventory()
local leftovers = chestinv:add_item("pro", stack)
local leftover = chestinv:add_item("main", leftovers)
local n_stack = stack
n_stack:set_count(stack:get_count() - leftover:get_count())
playerinv:remove_item("main", n_stack)
return 0
end
else
return 0
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "helper" then
return 0
end
if chest_color ~= ctf.player(player:get_player_name()).team then
minetest.chat_send_player(player:get_player_name(), "You're not on team " .. chest_color)
return 0
end
local pstat = ctf_stats.player(player:get_player_name())
if not pstat or not pstat.score or pstat.score < 10 then
return 0
end
if listname ~= "pro" or get_is_player_pro(pstat) then
return stack:get_count()
else
return 0
end
end,
can_dig = function(pos, player)
return false
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" moves " .. (stack:get_name() or "stuff") .. " " .. (stack:get_count() or 0) .. " to chest at " .. minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name() ..
" takes " .. (stack:get_name() or "stuff") .. " " .. (stack:get_count() or 0) .. " from chest at " .. minetest.pos_to_string(pos))
end
})
end

View file

@ -2,8 +2,8 @@ default
ctf_treasure?
stairs?
wool?
ctf_team_base?
ctf?
ctf_match?
worldedit?
irc?
ctf_stats?

View file

@ -3,9 +3,10 @@ ctf_map = {}
dofile(minetest.get_modpath("ctf_map") .. "/nodes.lua")
dofile(minetest.get_modpath("ctf_map") .. "/emerge.lua")
dofile(minetest.get_modpath("ctf_map") .. "/barrier.lua")
dofile(minetest.get_modpath("ctf_map") .. "/base.lua")
if minetest.get_modpath("ctf") then
dofile(minetest.get_modpath("ctf_map") .. "/chest.lua")
dofile(minetest.get_modpath("ctf_map") .. "/schem_map.lua")
dofile(minetest.get_modpath("ctf_map") .. "/give_initial_stuff.lua")

@ -1 +1 @@
Subproject commit 1595c6532532daf6745e42865db33f1b7dc1bfd8
Subproject commit 9e2581925aed31e5572507a0aba8120c18f41fa0

View file

@ -1,3 +1,12 @@
minetest.register_node("ctf_map:reinforced_cobble", {
description = "Reinforced Cobblestone",
tiles = {"ctf_map_reinforced_cobble.png"},
is_ground_content = false,
groups = {cracky = 1, stone = 2},
sounds = default.node_sound_stone_defaults(),
})
--
-- Special nodes
--
@ -31,13 +40,6 @@ minetest.register_node("ctf_map:ind_glass", {
sounds = default.node_sound_glass_defaults()
})
minetest.register_node("ctf_map:ind_stone", {
description = "Indestructible Stone",
groups = {immortal = 1},
tiles = {"default_stone.png"},
is_ground_content = false
})
minetest.register_node("ctf_map:ind_glass_red", {
description = "Indestructible Red Glass",
drawtype = "glasslike",
@ -109,7 +111,6 @@ minetest.register_node("ctf_map:mossycobble", {
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("ctf_map:desert_stone", {
description = "Indestructible Desert Stone",
tiles = {"default_desert_stone.png"},
@ -761,3 +762,6 @@ for name, nodedef in pairs(minetest.registered_nodes) do
minetest.register_node("ctf_map:" .. name:split(":")[2], nodedef)
end
end
minetest.register_alias("ctf_map:ind_cobble", "ctf_map:cobble")
minetest.register_alias("ctf_map:ind_stone", "ctf_map:stone")

View file

@ -103,7 +103,7 @@ function ctf_map.place_map(map)
assert(res)
for _, value in pairs(ctf_map.map.teams) do
ctf_team_base.place(value.color, value.pos)
ctf_map.place_base(value.color, value.pos)
end
local seed = minetest.get_mapgen_setting("seed")

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 625 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 614 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 587 B