Diplomacy gui, rely less on meta data, and fixes

master
Rubenwardy 2013-08-16 19:25:42 +01:00
parent 9b57579fb9
commit cc724a9d81
6 changed files with 188 additions and 91 deletions

View File

@ -74,17 +74,24 @@ The fire arms mod is installed
Commands
========
Admin only
----------
Uses priv "team"
* /ateam <name> - add a team called <name>.
* /team_owner <name> - make a player the mod or not off the team (toggle)
* (coming soon) /join <name> <team> - add player <name> to team <team>.
* (coming soon) /lock <team> - stop any players joining team <team>
* (coming soon) /unlock <team> - allow players to join team <team>
Players
-------
* /team - view team panel
* /list_teams - list all teams and their statistics
* /join <team> - join the team <team>
* /join <team> - join the team <team>
* /all <msg> - chat on the global channel
Team owners
-----------
(coming soon) All these commands can be disabled from team owner's using settings
* /post <msg> - posts a msg to the news board (team owners can use this as well if ctf_team_owners_post is true)
* (coming soon) /lock <team> - stop any players joining team <team>
* (coming soon) /unlock <team> - allow players to join team <team>
Administrators only
-------------------
Uses priv "team"
* /ateam <name> - add a team called <name>
* /team_owner <name> - make a player the mod or not off the team (toggle)
* /reload_ctf - reload the core and settings
*/ctf - run debug functions and clean functions

View File

@ -38,7 +38,7 @@ function cf.area.get_flag(pos)
print(dump(team.flags[i]))
print("----------------")
else
result = {pos=team.flags[i],team=team.data.name}
result = team.flags[i]
end
end
end
@ -100,17 +100,15 @@ end
-- gets the name of the owner of that location
function cf.area.get_area(pos)
local closest = cf.area.nearest_flag(pos)
if not closest then
return false
end
local meta = minetest.env:get_meta(closest)
if not meta then
return false
local flag = cf.area.get_flag(closest)
if flag then
return flag.team
end
return meta:get_string("team")
return false
end
-- updates the spawn position for a team
@ -119,12 +117,13 @@ function cf.area.get_spawn(team)
if team and cf.teams and cf.team(team) then
if cf.team(team).spawn and minetest.env:get_node(cf.team(team).spawn).name == "capturetheflag:flag" then
-- Get meta data
local meta = minetest.env:get_meta(cf.team(team).spawn)
local _team = nil
if meta then
_team = meta:get_string("team")
local flag = cf.area.get_flag(cf.team(team).spawn)
if not flag then
return false
end
local _team = flag.team
-- Check to see if spawn is already defined
if team == _team then
@ -149,25 +148,10 @@ function cf.area.asset_flags(team)
print("Checking the flags of "..team)
local tmp = cf.team(team).flags
local new = {}
for i=1,#tmp do
if tmp[i] and minetest.env:get_node(tmp[i]) and minetest.env:get_node(tmp[i]).name == "capturetheflag:flag" then
-- Get meta data
local meta = minetest.env:get_meta(tmp[i])
local _team = nil
if meta then
_team = meta:get_string("team")
end
-- Check to see if spawn is already defined
if team == _team then
table.insert(new,tmp[i])
else
print(_team.." is not "..team.." at "..dump(tmp[i]))
end
if tmp[i] and (not minetest.env:get_node(tmp[i]) or not minetest.env:get_node(tmp[i]).name == "capturetheflag:flag") then
print("Replacing flag...")
end
end
cf.team(team).flags = new
end

View File

@ -95,6 +95,7 @@ minetest.register_chatcommand("all", {
description = "Send a message on the global channel",
func = function(name, param)
if not cf.settings.global_channel then
minetest.chat_send_player(name,"The global channel is disabled")
return
end
@ -133,6 +134,10 @@ minetest.register_chatcommand("post", {
-- Chat plus stuff
if chatplus then
chatplus.register_handler(function(from,to,msg)
if not cf.settings.team_channel then
return nil
end
local fromp = cf.player(from)
local top = cf.player(to)

View File

@ -15,13 +15,13 @@ cf.flag_func = {
if not puncher or not player then
return
end
local meta = minetest.env:get_meta(pos)
if not meta then
local flag = cf.area.get_flag(pos)
if not flag then
return
end
local team = meta:get_string("team")
local team = flag.team
if not team then
return
end
@ -52,8 +52,7 @@ cf.flag_func = {
cf.team(team).spawn = nil
if cf.settings.multiple_flags == true then
meta:set_string("team",cf.player(player).team)
meta:set_string("infotext", meta:get_string("team").."'s flag")
meta:set_string("infotext", team.."'s flag")
cf.area.delete_flag(team,pos)
cf.area.add_flag(cf.player(player).team,pos)
else
@ -82,8 +81,7 @@ cf.flag_func = {
if cf.players and cf.players[placer:get_player_name()] and cf.players[placer:get_player_name()].team then
local team = cf.players[placer:get_player_name()].team
meta:set_string("team", team)
meta:set_string("infotext", meta:get_string("team").."'s flag")
meta:set_string("infotext", team.."'s flag")
-- add flag
cf.area.add_flag(team,pos)
@ -121,8 +119,7 @@ cf.flag_func = {
local meta2 = minetest.env:get_meta(pos2)
meta2:set_string("team", team)
meta2:set_string("infotext", meta:get_string("team").."'s flag")
meta2:set_string("infotext", team.."'s flag")
else
minetest.chat_send_player(placer:get_player_name(),"You are not part of a team!")
minetest.env:set_node(pos,{name="air"})
@ -219,13 +216,9 @@ minetest.register_abm({
minetest.env:set_node(top,{name="air"})
return
end
flagmeta:set_string("team", flag_team_data.team)
local topmeta = minetest.env:get_meta(top)
local flag_name = nil
if topmeta then
flag_name = flagmeta:get_string("flag_name")
end
if flag_name then
local flag_name = flag_team_data.name
if flag_name and flag_name ~= "" then
flagmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
else
flagmeta:set_string("infotext", flag_team_data.team.."'s flag")
@ -238,9 +231,7 @@ minetest.register_abm({
minetest.env:set_node(top,{name="capturetheflag:flag_top_"..cf.team(flag_team_data.team).data.color})
topmeta = minetest.env:get_meta(top)
topmeta:set_string("team", flag_team_data.team)
topmeta:set_string("flag_name", flag_name)
if flag_name then
if flag_name and flag_name ~= "" then
topmeta:set_string("infotext", flag_name.." - "..flag_team_data.team)
else
topmeta:set_string("infotext", flag_team_data.team.."'s flag")

View File

@ -108,10 +108,15 @@ if cf.settings.team_gui and cf.settings.gui then -- check if team guis are enabl
for key,value in pairs(cf.teams) do
if key ~= team then
table.insert(data,{team=key,state=cf.diplo.get(team,key)})
table.insert(data,{
team = key,
state = cf.diplo.get(team,key),
to = cf.diplo.check_requests(team,key),
from = cf.diplo.check_requests(key,team)
})
end
end
result = result .. "label[1,1;Diplomacy from the perspective of "..team.."]"
for i=1,#data do
@ -126,14 +131,21 @@ if cf.settings.team_gui and cf.settings.gui then -- check if team guis are enabl
result = result .. "button[1.25,".. height ..";2,1;team_".. data[i].team ..";".. data[i].team .."]"
result = result .. "label[3.75,".. height ..";".. data[i].state .."]"
if cf.can_mod(name,team)==true then
if data[i].state == "war" then
result = result .. "button[7.5,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
elseif data[i].state == "peace" then
result = result .. "button[6,".. height ..";1.5,1;war_".. data[i].team ..";War]"
result = result .. "button[7.5,".. height ..";1.5,1;alli_".. data[i].team ..";Alliance]"
elseif data[i].state == "alliance" then
result = result .. "button[6,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
if cf.can_mod(name,team)==true and cf.player(name).team == team then
if not data[i].from and not data[i].to then
if data[i].state == "war" then
result = result .. "button[7.5,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
elseif data[i].state == "peace" then
result = result .. "button[6,".. height ..";1.5,1;war_".. data[i].team ..";War]"
result = result .. "button[7.5,".. height ..";1.5,1;alli_".. data[i].team ..";Alliance]"
elseif data[i].state == "alliance" then
result = result .. "button[6,".. height ..";1.5,1;peace_".. data[i].team ..";Peace]"
end
elseif data[i].from ~= nil then
result = result .. "label[6,".. height ..";request recieved]"
elseif data[i].to ~= nil then
result = result .. "label[5.5,".. height ..";request sent]"
result = result .. "button[7.5,".. height ..";1.5,1;cancel_".. data[i].team ..";Cancel]"
end
end
end
@ -243,6 +255,9 @@ if cf.settings.team_gui and cf.settings.gui then -- check if team guis are enabl
if cf.player(name) and cf.player(name).team and cf.team(cf.player(name).team) then
if ok == "y" then
cf.diplo.set(cf.player(name).team, cf.team(cf.player(name).team).log[tonumber(id)].team, cf.team(cf.player(name).team).log[tonumber(id)].msg)
cf.post(cf.player(name).team,{msg="You have accepted the "..cf.team(cf.player(name).team).log[tonumber(id)].msg.." request from "..cf.team(cf.player(name).team).log[tonumber(id)].team})
cf.post(cf.team(cf.player(name).team).log[tonumber(id)].team,{msg=cf.player(name).team.." has accepted your "..cf.team(cf.player(name).team).log[tonumber(id)].msg.." request"})
id = id + 1
end
table.remove(cf.team(cf.player(name).team).log,id)
@ -264,6 +279,62 @@ if cf.settings.team_gui and cf.settings.gui then -- check if team guis are enabl
cf.gui.team_dip(name,newteam)
return true
end
newteam = string.match(key, "peace_(.+)")
if newteam and cf.player(name) then
local team = cf.player(name).team
if team then
if cf.diplo.get(team,newteam) == "war" then
cf.post(newteam,{type="request",msg="peace",team=team,mode="diplo"})
else
cf.diplo.set(team,newteam,"peace")
cf.post(team,{msg="You have cancelled the alliance treaty with "..newteam})
cf.post(newteam,{msg=team.." has cancelled the alliance treaty"})
end
end
cf.gui.team_dip(name,team)
return true
end
newteam = string.match(key, "war_(.+)")
if newteam and cf.player(name) then
local team = cf.player(name).team
if team then
cf.diplo.set(team,newteam,"war")
cf.post(team,{msg="You have declared war on "..newteam})
cf.post(newteam,{msg=team.." has declared war on you"})
end
cf.gui.team_dip(name,team)
return true
end
newteam = string.match(key, "alli_(.+)")
if newteam and cf.player(name) then
local team = cf.player(name).team
if team then
cf.post(newteam,{type="request",msg="alliance",team=team,mode="diplo"})
end
cf.gui.team_dip(name,team)
return true
end
newteam = string.match(key, "cancel_(.+)")
if newteam and cf.player(name) then
local team = cf.player(name).team
if team then
cf.diplo.cancel_requests(team,newteam)
end
cf.gui.team_dip(name,team)
return true
end
end
end
end)
@ -271,24 +342,27 @@ end -- end of check if team guis are enabled
-- Flag interface
function cf.gui.flag_board(name,pos)
local meta = minetest.env:get_meta(pos)
if not meta then
local flag = cf.area.get_flag(pos)
if not flag then
return
end
local team = meta:get_string("team")
local team = flag.team
if not team then
return
end
if cf.can_mod(name,team) == false then
if cf.player(name) and cf.player(name).team and cf.player(name).team == team then
cf.gui.team_board(name,team)
end
return
end
local flag_name = meta:get_string("flag_name")
local flag_name = flag.name
if not cf.settings.flag_names then
meta:set_string("flag_name",nil)
flag.name = nil
return
end
@ -321,12 +395,12 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
if fields.save and fields.flag_name then
local meta = minetest.env:get_meta(cf.gui.flag_data[name].pos)
if not meta then
local flag = cf.area.get_flag(cf.gui.flag_data[name].pos)
if not flag then
return false
end
local team = meta:get_string("team")
local team = flag.team
if not team then
return false
end
@ -334,13 +408,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if cf.can_mod(name,team) == false then
return false
end
local flag_name = meta:get_string("flag_name")
local flag_name = flag.name
if not flag_name then
flag_name = ""
end
meta:set_string("flag_name",fields.flag_name)
flag.name = fields.flag_name
local msg = flag_name.." was renamed to "..fields.flag_name
@ -355,15 +429,10 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
return true
elseif fields.delete then
local pos = cf.gui.flag_data[name].pos
local meta = minetest.env:get_meta(cf.gui.flag_data[name].pos)
if not meta then
return false
end
local team = meta:get_string("team")
local team = cf.area.get_flag(cf.gui.flag_data[name].pos).team
if not team then
return false
return
end
if cf.can_mod(name,team) == false then

View File

@ -148,6 +148,14 @@ end
-- Sees if the player can change stuff in a team
function cf.can_mod(player,team)
local privs = minetest.get_player_privs(player)
if privs then
if privs.team == true then
return true
end
end
if player and cf.teams[team] and cf.teams[team].players and cf.teams[team].players[player] then
if cf.teams[team].players[player].auth == true then
return true
@ -205,6 +213,39 @@ function cf.diplo.set(one,two,state)
return
end
function cf.diplo.check_requests(one,two)
local team = cf.team(two)
if not team.log then
return nil
end
for i=1,#team.log do
if team.log[i].team == one and team.log[i].type=="request" and team.log[i].mode=="diplo" then
return team.log[i].msg
end
end
return nil
end
function cf.diplo.cancel_requests(one,two)
local team = cf.team(two)
if not team.log then
return
end
for i=1,#team.log do
if team.log[i].team == one and team.log[i].type=="request" and team.log[i].mode=="diplo" then
table.remove(team.log,i)
return
end
end
return
end
-- Vector stuff
v3={}
function v3.distance(v, w)