From d8821e542b98624f458e02b1674c7e72303e29ee Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 12 Jul 2015 16:52:50 +0100 Subject: [PATCH] More decoupling of ctf_flag, ctf.area.get_spawn is now the only coupled thing --- mods/capturetheflag/ctf/core.lua | 14 ----------- mods/capturetheflag/ctf/gui.lua | 4 +--- mods/capturetheflag/ctf/init.lua | 8 ++++++- mods/capturetheflag/ctf/teams.lua | 2 +- mods/capturetheflag/ctf_chat/init.lua | 8 ++++--- mods/capturetheflag/ctf_flag/flag_func.lua | 28 +++++++++++----------- mods/capturetheflag/ctf_flag/init.lua | 19 +++++++++++---- 7 files changed, 42 insertions(+), 41 deletions(-) diff --git a/mods/capturetheflag/ctf/core.lua b/mods/capturetheflag/ctf/core.lua index 59577c1..b7cfac1 100644 --- a/mods/capturetheflag/ctf/core.lua +++ b/mods/capturetheflag/ctf/core.lua @@ -60,7 +60,6 @@ function ctf.init() ctf._defsettings = {} ctf.teams = {} ctf.players = {} - ctf.claimed = {} -- See minetest.conf.example in the root of this subgame @@ -163,19 +162,6 @@ function ctf.save() end end --- Get info for ctf.claimed -function ctf.collect_claimed() - ctf.log("utils", "Collecting claimed locations") - ctf.claimed = {} - for _, team in pairs(ctf.teams) do - for i = 1, #team.flags do - if team.flags[i].claimed then - table.insert(ctf.claimed, team.flags[i]) - end - end - end -end - ctf.area = {} function ctf.area.get_territory_owner(pos) local largest = nil diff --git a/mods/capturetheflag/ctf/gui.lua b/mods/capturetheflag/ctf/gui.lua index d0451ca..ad33d2f 100644 --- a/mods/capturetheflag/ctf/gui.lua +++ b/mods/capturetheflag/ctf/gui.lua @@ -6,8 +6,6 @@ ctf.register_on_init(function() ctf._set("gui", true) ctf._set("gui.team", true) ctf._set("gui.team.initial", "news") - ctf._set("gui.team.teleport_to_flag", true) - ctf._set("gui.team.teleport_to_spawn", false) for name, tab in pairs(ctf.gui.tabs) do ctf._set("gui.tab." .. name, true) @@ -246,7 +244,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) ctf.gui.show(name, "settings") end if ctf and ctf.team(ctf.players[name].team) and ctf.team(ctf.players[name].team).data then - if minetest.registered_items["ctf_flag:flag_top_"..fields.color] then + if ctf.flag_colors[fields.color] then ctf.team(ctf.players[name].team).data.color = fields.color ctf.save() else diff --git a/mods/capturetheflag/ctf/init.lua b/mods/capturetheflag/ctf/init.lua index 613ed34..efd38c1 100644 --- a/mods/capturetheflag/ctf/init.lua +++ b/mods/capturetheflag/ctf/init.lua @@ -21,6 +21,13 @@ minetest.register_privilege("ctf_admin", { description = "Can create teams, manage players, assign team owners.", }) +-- Colors +ctf.flag_colors = { + red = "0xFF0000", + green = "0x00FF00", + blue = "0x0000FF" +} + -- Modules dofile(minetest.get_modpath("ctf").."/core.lua") dofile(minetest.get_modpath("ctf").."/teams.lua") @@ -31,4 +38,3 @@ dofile(minetest.get_modpath("ctf").."/hud.lua") -- Init ctf.init() ctf.clean_player_lists() -ctf.collect_claimed() diff --git a/mods/capturetheflag/ctf/teams.lua b/mods/capturetheflag/ctf/teams.lua index 1a31517..14747ca 100644 --- a/mods/capturetheflag/ctf/teams.lua +++ b/mods/capturetheflag/ctf/teams.lua @@ -278,7 +278,7 @@ function ctf.area.get_spawn(team) return nil end - if ctf.team(team).spawn and minetest.env:get_node(ctf.team(team).spawn).name == "ctf:flag" then + if ctf.team(team).spawn and minetest.env:get_node(ctf.team(team).spawn).name == "ctf_flag:flag" then local flag = ctf_flag.get(ctf.team(team).spawn) if not flag then diff --git a/mods/capturetheflag/ctf_chat/init.lua b/mods/capturetheflag/ctf_chat/init.lua index 8361e2f..659f488 100644 --- a/mods/capturetheflag/ctf_chat/init.lua +++ b/mods/capturetheflag/ctf_chat/init.lua @@ -143,17 +143,19 @@ minetest.register_chatcommand("list_teams", { end, }) -minetest.register_chatcommand("ctf", { +minetest.register_chatcommand("ctf_clean", { description = "Do admin cleaning stuff", privs = {ctf_admin=true}, func = function(name, param) ctf.clean_player_lists() - ctf.collect_claimed() + if ctf_flag.collect_claimed then + ctf.collect_claimed() + end minetest.chat_send_player(name, "CTF cleaned!") end, }) -minetest.register_chatcommand("reload_ctf", { +minetest.register_chatcommand("ctf_reload", { description = "reload the ctf main frame and get settings", privs = {team=true}, func = function(name, param) diff --git a/mods/capturetheflag/ctf_flag/flag_func.lua b/mods/capturetheflag/ctf_flag/flag_func.lua index af0d879..863c444 100644 --- a/mods/capturetheflag/ctf_flag/flag_func.lua +++ b/mods/capturetheflag/ctf_flag/flag_func.lua @@ -98,7 +98,7 @@ ctf_flag = { team = ctf.player(player).team, player = player } - table.insert(ctf.claimed, flag) + table.insert(ctf_flag.claimed, flag) else if flag_name and flag_name~="" then minetest.chat_send_all(flag_name.." has been taken from "..team.." by "..player.." (team "..ctf.player(player).team..")") @@ -131,30 +131,30 @@ ctf_flag = { end, _flagret = function(player) minetest.chat_send_player(player,"Own flag") - for i=1, #ctf.claimed do - if ctf.claimed[i].claimed.player == player then + for i=1, #ctf_flag.claimed do + if ctf_flag.claimed[i].claimed.player == player then minetest.chat_send_player(player,"Returning flag") - local fteam = ctf.team(ctf.claimed[i].team) - local flag_name = ctf.claimed[i].name + local fteam = ctf.team(ctf_flag.claimed[i].team) + local flag_name = ctf_flag.claimed[i].name if flag_name and flag_name~="" then - minetest.chat_send_all(flag_name.." has been taken from "..fteam.data.name.." by "..ctf.claimed[i].claimed.player.." (team "..ctf.claimed[i].claimed.team..")") - ctf.post(fteam,{msg=flag_name.." has been captured by "..ctf.claimed[i].claimed.team,icon="flag_red"}) - ctf.post(ctf.claimed[i].claimed.team,{msg=player.." captured '"..flag_name.."' from "..fteam.data.name,icon="flag_green"}) + minetest.chat_send_all(flag_name.." has been taken from "..fteam.data.name.." by "..ctf_flag.claimed[i].claimed.player.." (team "..ctf_flag.claimed[i].claimed.team..")") + ctf.post(fteam,{msg=flag_name.." has been captured by "..ctf_flag.claimed[i].claimed.team,icon="flag_red"}) + ctf.post(ctf_flag.claimed[i].claimed.team,{msg=player.." captured '"..flag_name.."' from "..fteam.data.name,icon="flag_green"}) else - minetest.chat_send_all(fteam.data.name.."'s flag at ("..ctf.claimed[i].x..","..ctf.claimed[i].z..") has been captured by "..player.." (team "..ctf.claimed[i].claimed.team..")") - ctf.post(fteam.data.name,{msg="The flag at ("..ctf.claimed[i].x..","..ctf.claimed[i].z..") has been captured by "..ctf.claimed[i].claimed.team,icon="flag_red"}) - ctf.post(ctf.claimed[i].claimed.team,{msg=player.." captured flag ("..ctf.claimed[i].x..","..ctf.claimed[i].z..") from "..fteam.data.name,icon="flag_green"}) + minetest.chat_send_all(fteam.data.name.."'s flag at ("..ctf_flag.claimed[i].x..","..ctf_flag.claimed[i].z..") has been captured by "..player.." (team "..ctf_flag.claimed[i].claimed.team..")") + ctf.post(fteam.data.name,{msg="The flag at ("..ctf_flag.claimed[i].x..","..ctf_flag.claimed[i].z..") has been captured by "..ctf_flag.claimed[i].claimed.team,icon="flag_red"}) + ctf.post(ctf_flag.claimed[i].claimed.team,{msg=player.." captured flag ("..ctf_flag.claimed[i].x..","..ctf_flag.claimed[i].z..") from "..fteam.data.name,icon="flag_green"}) end fteam.spawn = nil - local fpos = {x=ctf.claimed[i].x,y=ctf.claimed[i].y,z=ctf.claimed[i].z} + local fpos = {x=ctf_flag.claimed[i].x,y=ctf_flag.claimed[i].y,z=ctf_flag.claimed[i].z} if ctf.setting("flag.allow_multiple") == true then ctf_flag.delete(fteam.data.name,fpos) - ctf_flag.add(ctf.claimed[i].claimed.team,fpos) + ctf_flag.add(ctf_flag.claimed[i].claimed.team,fpos) else minetest.env:set_node(fpos,{name="air"}) ctf_flag.delete(fteam.data.name,fpos) end - ctf.collect_claimed() + ctf_flag.collect_claimed() end end end, diff --git a/mods/capturetheflag/ctf_flag/init.lua b/mods/capturetheflag/ctf_flag/init.lua index de430c9..752e9f6 100644 --- a/mods/capturetheflag/ctf_flag/init.lua +++ b/mods/capturetheflag/ctf_flag/init.lua @@ -4,6 +4,8 @@ function init() ctf._set("flag.capture_take", false) ctf._set("flag.names", true) ctf._set("flag.protect_distance", 25) + ctf._set("gui.team.teleport_to_flag", true) + ctf._set("gui.team.teleport_to_spawn", false) end init() ctf.register_on_new_team(function(team) @@ -33,6 +35,18 @@ ctf_flag = {} dofile(minetest.get_modpath("ctf_flag") .. "/gui.lua") dofile(minetest.get_modpath("ctf_flag") .. "/flag_func.lua") +function ctf_flag.collect_claimed() + ctf.log("utils", "Collecting claimed locations") + ctf_flag.claimed = {} + for _, team in pairs(ctf.teams) do + for i = 1, #team.flags do + if team.flags[i].claimed then + table.insert(ctf_flag.claimed, team.flags[i]) + end + end + end +end + -- add a flag to a team function ctf_flag.add(team, pos) if not team or team == "" then @@ -142,11 +156,6 @@ minetest.register_node("ctf_flag:flag", { on_construct = ctf_flag.on_construct, after_place_node = ctf_flag.after_place_node }) -ctf.flag_colors = { - red = "0xFF0000", - green = "0x00FF00", - blue = "0x0000FF" -} for color, _ in pairs(ctf.flag_colors) do minetest.register_node("ctf_flag:flag_top_"..color,{