diff --git a/docs/ctf-api.md b/docs/ctf-api.md index a3c9e12339..93a8f67d2d 100644 --- a/docs/ctf-api.md +++ b/docs/ctf-api.md @@ -39,7 +39,10 @@ ctf_settings.register("my_setting", { --- # mods/ctf/ -TODO +TODO, below is a collection of quick notes for later + +## ctf_teams +* https://modern.ircdocs.horse/formatting.html#colors-16-98 --- # mods/mtg/ diff --git a/mods/ctf/ctf_map/ctf_traps.lua b/mods/ctf/ctf_map/ctf_traps.lua index 8439bf3618..b58808dd83 100644 --- a/mods/ctf/ctf_map/ctf_traps.lua +++ b/mods/ctf/ctf_map/ctf_traps.lua @@ -68,29 +68,31 @@ minetest.register_node("ctf_map:spike", { }) for _, team in ipairs(ctf_teams.teamlist) do - local spikecolor = ctf_teams.team[team].color - - minetest.register_node("ctf_map:spike_"..team, { - description = HumanReadable(team).." Team Spike", - drawtype = "plantlike", - tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"}, - inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150", - use_texture_alpha = "clip", - paramtype = "light", - paramtype2 = "meshoptions", - sunlight_propagates = true, - walkable = false, - damage_per_second = 7, - groups = {cracky=1, level=2}, - drop = "ctf_map:spike", - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, - }, - on_place = function(itemstack, placer, pointed_thing) - return minetest.item_place(itemstack, placer, pointed_thing, 34) - end - }) + if not ctf_teams.team[team].not_playing then + local spikecolor = ctf_teams.team[team].color + + minetest.register_node("ctf_map:spike_"..team, { + description = HumanReadable(team).." Team Spike", + drawtype = "plantlike", + tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"}, + inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150", + use_texture_alpha = "clip", + paramtype = "light", + paramtype2 = "meshoptions", + sunlight_propagates = true, + walkable = false, + damage_per_second = 7, + groups = {cracky=1, level=2}, + drop = "ctf_map:spike", + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5}, + }, + on_place = function(itemstack, placer, pointed_thing) + return minetest.item_place(itemstack, placer, pointed_thing, 34) + end + }) + end end minetest.register_on_player_hpchange(function(player, hp_change, reason) diff --git a/mods/ctf/ctf_map/map_functions.lua b/mods/ctf/ctf_map/map_functions.lua index 9068983638..4c8f0fb000 100644 --- a/mods/ctf/ctf_map/map_functions.lua +++ b/mods/ctf/ctf_map/map_functions.lua @@ -193,8 +193,10 @@ local function prepare_nodes(pos1, pos2, data, team_chest_items, blacklisted_nod end for _, team in ipairs(ctf_teams.teamlist) do - local node = "ctf_teams:chest_" .. team - nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node] + if not ctf_teams.team[team].not_playing then + local node = "ctf_teams:chest_" .. team + nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node] + end end for i, v in ipairs(data) do diff --git a/mods/ctf/ctf_modebase/build_timer.lua b/mods/ctf/ctf_modebase/build_timer.lua index e30a60e628..5cce002dc5 100644 --- a/mods/ctf/ctf_modebase/build_timer.lua +++ b/mods/ctf/ctf_modebase/build_timer.lua @@ -29,7 +29,8 @@ local function timer_func(time_left) end local pteam = ctf_teams.get(player) - if pteam and not ctf_core.pos_inside(player:get_pos(), ctf_teams.get_team_territory(pteam)) then + local tpos1, tpos2 = ctf_teams.get_team_territory(pteam) + if pteam and tpos1 and not ctf_core.pos_inside(player:get_pos(), tpos1, tpos2) then hud_events.new(player, { quick = true, text = "You can't cross the barrier until build time is over!", diff --git a/mods/ctf/ctf_modebase/features.lua b/mods/ctf/ctf_modebase/features.lua index afef247a26..8ec648e9ba 100644 --- a/mods/ctf/ctf_modebase/features.lua +++ b/mods/ctf/ctf_modebase/features.lua @@ -247,14 +247,22 @@ local function tp_player_near_flag(player) local tname = ctf_teams.get(player) if not tname then return end - local pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos, - math.random(-1, 1), - 0.5, - math.random(-1, 1) - ) - local rotation_y = vector.dir_to_rotation( - vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center) - ).y + local rotation_y + local pos + + if ctf_map.current_map.teams[tname] then + pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos, + math.random(-1, 1), + 0.5, + math.random(-1, 1) + ) + rotation_y = vector.dir_to_rotation( + vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center) + ).y + else + pos = vector.add(ctf_map.current_map.pos1, vector.divide(ctf_map.current_map.size, 2)) + rotation_y = player:get_look_horizontal() + end local function apply() player:set_pos(pos) diff --git a/mods/ctf/ctf_teams/functions.lua b/mods/ctf/ctf_teams/functions.lua index 3b8a06a253..e61b8a2a80 100644 --- a/mods/ctf/ctf_teams/functions.lua +++ b/mods/ctf/ctf_teams/functions.lua @@ -118,7 +118,7 @@ end --- Example usage: `pos1, pos2 = ctf_teams.get_team_territory("red")` function ctf_teams.get_team_territory(teamname) local current_map = ctf_map.current_map - if not current_map then return false end + if not current_map or not current_map.teams[teamname] then return false end return current_map.teams[teamname].pos1, current_map.teams[teamname].pos2 end diff --git a/mods/ctf/ctf_teams/init.lua b/mods/ctf/ctf_teams/init.lua index 5dfcf27333..d282d746e8 100644 --- a/mods/ctf/ctf_teams/init.lua +++ b/mods/ctf/ctf_teams/init.lua @@ -1,5 +1,13 @@ ctf_teams = { team = { + --[[ + tname = { + color = "#ffffff", + color_hex = 0x000, -- Generated from 'color' above + irc_color = 16, -- optional, default: 16 + not_playing = false, --optional, default: false + } + ]] red = { color = "#dc0f0f", color_hex = 0x000, diff --git a/mods/ctf/ctf_teams/team_chest.lua b/mods/ctf/ctf_teams/team_chest.lua index 8bc8256716..1b08885ae0 100644 --- a/mods/ctf/ctf_teams/team_chest.lua +++ b/mods/ctf/ctf_teams/team_chest.lua @@ -27,234 +27,241 @@ function ctf_teams.is_allowed_in_team_chest(listname, stack, player) end for _, team in ipairs(ctf_teams.teamlist) do - local chestcolor = ctf_teams.team[team].color - local function get_chest_texture(chest_side, color, mask, extra) - return string.format( - "(default_chest_%s.png^[colorize:%s:130)^(default_chest_%s.png^[mask:ctf_teams_chest_%s_mask.png^[colorize:%s:60)%s", - chest_side, - color, - chest_side, - mask, - color, - extra or "" - ) - end - - local def = { - description = HumanReadable(team).." Team's Chest", - tiles = { - get_chest_texture("top", chestcolor, "top"), - get_chest_texture("top", chestcolor, "top"), - get_chest_texture("side", chestcolor, "side"), - get_chest_texture("side", chestcolor, "side"), - get_chest_texture("side", chestcolor, "side"), - get_chest_texture("front", chestcolor, "side", "^ctf_teams_lock.png"), - }, - paramtype2 = "facedir", - groups = {immortal = 1, team_chest=1}, - legacy_facedir_simple = true, - is_ground_content = false, - sounds = default.node_sound_wood_defaults(), - } - - function def.on_construct(pos) - local meta = minetest.get_meta(pos) - meta:set_string("infotext", string.format("%s Team's Chest", HumanReadable(team))) - - local inv = meta:get_inventory() - inv:set_size("main", 6 * 7) - inv:set_size("pro", 4 * 7) - inv:set_size("helper", 1 * 1) - end - - function def.can_dig(pos, player) - return false - end + if not ctf_teams.team[team].not_playing then + local chestcolor = ctf_teams.team[team].color + local function get_chest_texture(chest_side, color, mask, extra) + return string.format( + "(default_chest_%s.png" .. + "^[colorize:%s:130)" .. + "^(default_chest_%s.png" .. + "^[mask:ctf_teams_chest_%s_mask.png" .. + "^[colorize:%s:60)" .. + "%s", + chest_side, + color, + chest_side, + mask, + color, + extra or "" + ) + end - function def.on_rightclick(pos, node, player) - local name = player:get_player_name() - - local flag_captured = ctf_modebase.flag_captured[team] - if not flag_captured and team ~= ctf_teams.get(name) then - hud_events.new(player, { - quick = true, - text = "You're not on team " .. team, - color = "warning", - }) - return + local def = { + description = HumanReadable(team).." Team's Chest", + tiles = { + get_chest_texture("top", chestcolor, "top"), + get_chest_texture("top", chestcolor, "top"), + get_chest_texture("side", chestcolor, "side"), + get_chest_texture("side", chestcolor, "side"), + get_chest_texture("side", chestcolor, "side"), + get_chest_texture("front", chestcolor, "side", "^ctf_teams_lock.png"), + }, + paramtype2 = "facedir", + groups = {immortal = 1, team_chest=1}, + legacy_facedir_simple = true, + is_ground_content = false, + sounds = default.node_sound_wood_defaults(), + } + + function def.on_construct(pos) + local meta = minetest.get_meta(pos) + meta:set_string("infotext", string.format("%s Team's Chest", HumanReadable(team))) + + local inv = meta:get_inventory() + inv:set_size("main", 6 * 7) + inv:set_size("pro", 4 * 7) + inv:set_size("helper", 1 * 1) end - local formspec = table.concat({ - "size[10,12]", - default.get_hotbar_bg(1,7.85), - "list[current_player;main;1,7.85;8,1;]", - "list[current_player;main;1,9.08;8,3;8]", - }, "") - - local reg_access, pro_access - if not flag_captured then - reg_access, pro_access = get_chest_access(name) - else - reg_access, pro_access = true, true + function def.can_dig(pos, player) + return false end - if reg_access ~= true then - formspec = formspec .. "label[0.75,3;" .. - minetest.formspec_escape(minetest.wrap_text( - reg_access or "You aren't allowed to access the team chest", - 60 - )) .. - "]" + function def.on_rightclick(pos, node, player) + local name = player:get_player_name() + + local flag_captured = ctf_modebase.flag_captured[team] + if not flag_captured and team ~= ctf_teams.get(name) then + hud_events.new(player, { + quick = true, + text = "You're not on team " .. team, + color = "warning", + }) + return + end - minetest.show_formspec(name, "ctf_teams:no_access", formspec) - return - end + local formspec = table.concat({ + "size[10,12]", + default.get_hotbar_bg(1,7.85), + "list[current_player;main;1,7.85;8,1;]", + "list[current_player;main;1,9.08;8,3;8]", + }, "") - local chestinv = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z - - formspec = formspec .. "list[" .. chestinv .. ";main;0,0.3;6,7;]" .. - "background[6,-0.2;4.15,7.7;ctf_map_pro_section.png;false]" - - if pro_access == true then - formspec = formspec .. "list[" .. chestinv .. ";pro;6,0.3;4,7;]" .. - "listring[" .. chestinv ..";pro]" .. - "listring[" .. chestinv .. ";helper]" .. - "label[7,-0.2;" .. - minetest.formspec_escape("Pro players only") .. "]" - else - formspec = formspec .. "label[6.5,2;" .. - minetest.formspec_escape(minetest.wrap_text( - pro_access or "You aren't allowed to access the pro section", - 20 - )) .. - "]" - end + local reg_access, pro_access + if not flag_captured then + reg_access, pro_access = get_chest_access(name) + else + reg_access, pro_access = true, true + end - formspec = formspec .. - "listring[" .. chestinv ..";main]" .. - "listring[current_player;main]" + if reg_access ~= true then + formspec = formspec .. "label[0.75,3;" .. + minetest.formspec_escape(minetest.wrap_text( + reg_access or "You aren't allowed to access the team chest", + 60 + )) .. + "]" - minetest.show_formspec(name, "ctf_teams:chest", formspec) - end + minetest.show_formspec(name, "ctf_teams:no_access", formspec) + return + end + + local chestinv = "nodemeta:" .. pos.x .. "," .. pos.y .. "," .. pos.z + + formspec = formspec .. "list[" .. chestinv .. ";main;0,0.3;6,7;]" .. + "background[6,-0.2;4.15,7.7;ctf_map_pro_section.png;false]" + + if pro_access == true then + formspec = formspec .. "list[" .. chestinv .. ";pro;6,0.3;4,7;]" .. + "listring[" .. chestinv ..";pro]" .. + "listring[" .. chestinv .. ";helper]" .. + "label[7,-0.2;" .. + minetest.formspec_escape("Pro players only") .. "]" + else + formspec = formspec .. "label[6.5,2;" .. + minetest.formspec_escape(minetest.wrap_text( + pro_access or "You aren't allowed to access the pro section", + 20 + )) .. + "]" + end + + formspec = formspec .. + "listring[" .. chestinv ..";main]" .. + "listring[current_player;main]" - function def.allow_metadata_inventory_move(pos, from_list, from_index, - to_list, to_index, count, player) - local name = player:get_player_name() - - if team ~= ctf_teams.get(name) then - hud_events.new(player, { - quick = true, - text = "You're not on team " .. team, - color = "warning", - }) - return 0 + minetest.show_formspec(name, "ctf_teams:chest", formspec) end - local reg_access, pro_access = get_chest_access(name) + function def.allow_metadata_inventory_move(pos, from_list, from_index, + to_list, to_index, count, player) + local name = player:get_player_name() - if reg_access == true and (pro_access == true or from_list ~= "pro" and to_list ~= "pro") 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 + if team ~= ctf_teams.get(name) then + hud_events.new(player, { + quick = true, + text = "You're not on team " .. team, + color = "warning", + }) return 0 + end + + local reg_access, pro_access = get_chest_access(name) + + if reg_access == true and (pro_access == true or from_list ~= "pro" and to_list ~= "pro") 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 count + return 0 end - else - return 0 end - end - function def.allow_metadata_inventory_put(pos, listname, index, stack, player) - local name = player:get_player_name() + function def.allow_metadata_inventory_put(pos, listname, index, stack, player) + local name = player:get_player_name() - if team ~= ctf_teams.get(name) then - hud_events.new(player, { - quick = true, - text = "You're not on team " .. team, - color = "warning", - }) - return 0 - end + if team ~= ctf_teams.get(name) then + hud_events.new(player, { + quick = true, + text = "You're not on team " .. team, + color = "warning", + }) + return 0 + end - if not ctf_teams.is_allowed_in_team_chest(listname, stack, player) then - return 0 - end + if not ctf_teams.is_allowed_in_team_chest(listname, stack, player) then + return 0 + end - local reg_access, pro_access = get_chest_access(name) + local reg_access, pro_access = get_chest_access(name) - if reg_access == true and (pro_access == true or listname ~= "pro") then - local chestinv = minetest.get_inventory({type = "node", pos = pos}) - if chestinv:room_for_item("pro", stack) then - return stack:get_count() + if reg_access == true and (pro_access == true or listname ~= "pro") 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 - -- 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 - function def.allow_metadata_inventory_take(pos, listname, index, stack, player) - if listname == "helper" then - return 0 - end + function def.allow_metadata_inventory_take(pos, listname, index, stack, player) + if listname == "helper" then + return 0 + end - if ctf_modebase.flag_captured[team] then - return stack:get_count() - end + if ctf_modebase.flag_captured[team] then + return stack:get_count() + end - local name = player:get_player_name() + local name = player:get_player_name() - if team ~= ctf_teams.get(name) then - hud_events.new(player, { - quick = true, - text = "You're not on team " .. team, - color = "warning", - }) - return 0 - end + if team ~= ctf_teams.get(name) then + hud_events.new(player, { + quick = true, + text = "You're not on team " .. team, + color = "warning", + }) + return 0 + end - local reg_access, pro_access = get_chest_access(name) + local reg_access, pro_access = get_chest_access(name) - if reg_access == true and (pro_access == true or listname ~= "pro") then - return stack:get_count() - else - return 0 + if reg_access == true and (pro_access == true or listname ~= "pro") then + return stack:get_count() + else + return 0 + end end - end - function def.on_metadata_inventory_put(pos, listname, index, stack, player) - minetest.log("action", string.format("%s puts %s to team chest at %s", - player:get_player_name(), - stack:to_string(), - minetest.pos_to_string(pos) - )) - end + function def.on_metadata_inventory_put(pos, listname, index, stack, player) + minetest.log("action", string.format("%s puts %s to team chest at %s", + player:get_player_name(), + stack:to_string(), + minetest.pos_to_string(pos) + )) + end - function def.on_metadata_inventory_take(pos, listname, index, stack, player) - minetest.log("action", string.format("%s takes %s from team chest at %s", - player:get_player_name(), - stack:to_string(), - minetest.pos_to_string(pos) - )) - end + function def.on_metadata_inventory_take(pos, listname, index, stack, player) + minetest.log("action", string.format("%s takes %s from team chest at %s", + player:get_player_name(), + stack:to_string(), + minetest.pos_to_string(pos) + )) + end - minetest.register_node("ctf_teams:chest_" .. team, def) + minetest.register_node("ctf_teams:chest_" .. team, def) + end end