From c29bce03c6d9098fdb971e1664f83db8d96e95c0 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sun, 12 Jul 2015 14:43:03 +0100 Subject: [PATCH] Setting changes --- minetest.conf.example | 40 ++-- mods/capturetheflag/ctf/core.lua | 29 ++- mods/capturetheflag/ctf/diplomacy.lua | 34 +-- mods/capturetheflag/ctf_chat/init.lua | 7 + mods/capturetheflag/ctf_turret/init.lua | 261 ++++++++++++------------ mods/default/mapgen.lua | 1 + 6 files changed, 204 insertions(+), 168 deletions(-) diff --git a/minetest.conf.example b/minetest.conf.example index 1e4cb2c..7550d6f 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -1,64 +1,64 @@ # Whether teams own the nodes around their flag -#ctf_node_ownership = true -#ctf_flag_protect_distance = 25 +#ctf.node_ownership = true +#ctf.flag_protect_distance = 25 # Can teams have multiple flags? -#ctf_multiple_flags = true +#ctf.multiple_flags = true # Whether flags need to be taken to other teams flag to win -#ctf_flag_capture_take = false +#ctf.flag_capture_take = false # Are GUIs enabled -#ctf_gui = true +#ctf.gui = true # Is the HUD enabled -#ctf_hud = true +#ctf.hud = true # Team GUI on /team -#ctf_team_gui = true +#ctf.team_gui = true # Default tab when opening Team GUI # news # flags # diplo # admin -#ctf_team_gui_initial = news +#ctf.team_gui_initial = news # Enable tabs in Team GUI -#ctf_flag_teleport_gui = true -#ctf_news_gui = true -#ctf_diplomacy = true +#ctf.flag_teleport_gui = true +#ctf.news_gui = true +#ctf.diplomacy = true # Show the spawn as a target in flag teleport Team GUI -#ctf_spawn_in_flag_teleport_gui = false +#ctf.spawn_in_flag_teleport_gui = false # Can flags have names? -#ctf_flag_names = true +#ctf.flag_names = true # Do teams have their own chat channel? -#ctf_team_channel = true +#ctf.team_channel = true # Can players chat with other teams on /all. If team_channel is disabled, this setting does nothing. -#ctf_global_channel = true +#ctf.global_channel = true # Can players change teams using /join? -#ctf_players_can_change_team",true) +#ctf.players_can_change_team",true) # How are players allocated to teams? # 0: none, # 1: random, # 2: one of first two largest groups, # 3 smallest group -#ctf_allocate_mode = 0 +#ctf.allocate_mode = 0 # Maximum number in team, obeyed by allocation and /join. Admins don't obey this -#ctf_maximum_in_team = -1 +#ctf.maximum_in_team = -1 # The default Diplomacy state (if diplomacy is enabled) # war # peace # alliance -#ctf_default_diplo_state = war +#ctf.default_diplo_state = war # Chatplus distance - how far players can hear each other -#ctf_chatplus_distance = -1 +#ctf.chatplus_distance = -1 diff --git a/mods/capturetheflag/ctf/core.lua b/mods/capturetheflag/ctf/core.lua index 322cdfc..c21cf71 100644 --- a/mods/capturetheflag/ctf/core.lua +++ b/mods/capturetheflag/ctf/core.lua @@ -6,6 +6,10 @@ ctf.registered_on_save = {} function ctf.register_on_save(func) table.insert(ctf.registered_on_save, func) end +ctf.registered_on_init = {} +function ctf.register_on_init(func) + table.insert(ctf.registered_on_init, func) +end function ctf.error(area, msg) minetest.log("error", "CTF::" .. area .. " - " ..msg) @@ -36,22 +40,24 @@ function ctf.init() -- Settings: Feature enabling ctf.log("init", "Creating Default Settings") + + -- Settings: Flags and Territory ctf._set("node_ownership", true) ctf._set("multiple_flags", true) ctf._set("flag_capture_take", false) + ctf._set("flag_names", true) + + -- Settings: User Interface ctf._set("gui", true) ctf._set("hud", true) ctf._set("team_gui", true) ctf._set("flag_teleport_gui", true) ctf._set("spawn_in_flag_teleport_gui", false) ctf._set("news_gui", true) - ctf._set("diplomacy", true) - ctf._set("flag_names", true) - ctf._set("team_channel", true) - ctf._set("global_channel", true) - ctf._set("players_can_change_team", true) -- Settings: Teams + ctf._set("diplomacy", true) + ctf._set("players_can_change_team", true) ctf._set("allocate_mode", 0) ctf._set("maximum_in_team", -1) ctf._set("default_diplo_state", "war") @@ -60,6 +66,10 @@ function ctf.init() ctf._set("flag_protect_distance", 25) ctf._set("team_gui_initial", "news") + for i = 1, #ctf.registered_on_init do + ctf.registered_on_init[i]() + end + ctf.load() ctf.log("init", "Done!") @@ -69,13 +79,18 @@ end function ctf._set(setting, default) ctf._defsettings[setting] = default - if minetest.setting_get("ctf_"..setting) then + if minetest.setting_get("ctf."..setting) then + ctf.log("init", "- " .. setting .. ": " .. minetest.setting_get("ctf."..setting)) + elseif minetest.setting_get("ctf_"..setting) then ctf.log("init", "- " .. setting .. ": " .. minetest.setting_get("ctf_"..setting)) + ctf.warning("init", "deprecated setting ctf_"..setting.. + " used, use ctf."..setting.." instead.") end end function ctf.setting(name) - local set = minetest.setting_get("ctf_"..name) + local set = minetest.setting_get("ctf."..name) or + minetest.setting_get("ctf_"..name) local dset = ctf._defsettings[name] if set ~= nil then if type(dset) == "number" then diff --git a/mods/capturetheflag/ctf/diplomacy.lua b/mods/capturetheflag/ctf/diplomacy.lua index f504e02..a753c8c 100644 --- a/mods/capturetheflag/ctf/diplomacy.lua +++ b/mods/capturetheflag/ctf/diplomacy.lua @@ -13,12 +13,13 @@ end) function ctf.diplo.get(one,two) if not ctf.diplo.diplo then - return ctf.setting("default_diplo_state") + return ctf.setting("default_diplo_state") end - for i=1,#ctf.diplo.diplo do + for i = 1, #ctf.diplo.diplo do local dip = ctf.diplo.diplo[i] - if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then + if (dip.one == one and dip.two == two) or + (dip.one == two and dip.two == one) then return dip.state end end @@ -26,24 +27,25 @@ function ctf.diplo.get(one,two) return ctf.setting("default_diplo_state") end -function ctf.diplo.set(one,two,state) - if not ctf.diplo.diplo then - ctf.diplo.diplo = {} - else - for i=1,#ctf.diplo.diplo do +function ctf.diplo.set(one, two, state) + if ctf.diplo.diplo then + -- Check the table for an existing diplo state + for i = 1, #ctf.diplo.diplo do local dip = ctf.diplo.diplo[i] - if (dip.one == one and dip.two == two) or (dip.one == two and dip.two == one) then + if (dip.one == one and dip.two == two) or + (dip.one == two and dip.two == one) then dip.state = state return end end + else + ctf.diplo.diplo = {} end table.insert(ctf.diplo.diplo,{one=one,two=two,state=state}) - return end -function ctf.diplo.check_requests(one,two) +function ctf.diplo.check_requests(one, two) local team = ctf.team(two) if not team.log then @@ -51,7 +53,9 @@ function ctf.diplo.check_requests(one,two) 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 + 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 @@ -59,7 +63,7 @@ function ctf.diplo.check_requests(one,two) return nil end -function ctf.diplo.cancel_requests(one,two) +function ctf.diplo.cancel_requests(one, two) local team = ctf.team(two) if not team.log then @@ -67,7 +71,9 @@ function ctf.diplo.cancel_requests(one,two) 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 + 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 diff --git a/mods/capturetheflag/ctf_chat/init.lua b/mods/capturetheflag/ctf_chat/init.lua index 6eb6742..9adba1e 100644 --- a/mods/capturetheflag/ctf_chat/init.lua +++ b/mods/capturetheflag/ctf_chat/init.lua @@ -1,3 +1,10 @@ +function init() + -- Settings: Chat + ctf._set("team_channel", true) + ctf._set("global_channel", true) +end +init() + local function team_console_help(name) minetest.chat_send_player(name,"Try:", false) minetest.chat_send_player(name,"/team - show team panel", false) diff --git a/mods/capturetheflag/ctf_turret/init.lua b/mods/capturetheflag/ctf_turret/init.lua index c79091d..2e53d95 100644 --- a/mods/capturetheflag/ctf_turret/init.lua +++ b/mods/capturetheflag/ctf_turret/init.lua @@ -1,139 +1,146 @@ -ARROW_DAMAGE = 2 -ARROW_VELOCITY = 2 -minetest.register_node("ctf_turret:turret", { - description = "Team Turret", - tiles = { - "default_stone.png", - "default_stone.png", - "default_stone.png", - "default_stone.png", - "default_stone.png", - "default_stone.png", - }, - drawtype="nodebox", - groups={attached_node=1}, - paramtype = "light", - node_box = { - type = "fixed", - fixed = { - {-0.500000,-0.500000,-0.500000,0.500000,0.000000,0.500000}, --NodeBox 1 - {-0.437500,0.000000,-0.437500,0.431250,0.187500,0.431250}, --NodeBox 2 - {-0.187500,0.187500,-0.187500,0.187500,0.500000,0.187500}, --NodeBox 3 - } - }, - groups = {cracky=3, stone=1}, - on_construct = function(pos) - local meta = minetest.env:get_meta(pos) - meta:set_string("infotext", "Unowned turret") - end, - after_place_node = function(pos, placer) - local meta = minetest.env:get_meta(pos) +function init() + ctf._set("turrets", true) +end +init() - if meta and ctf.players and ctf.player(placer:get_player_name()) and ctf.player(placer:get_player_name()).team then - local team = ctf.player(placer:get_player_name()).team - meta:set_string("team", team) - meta:set_string("infotext", "Owned by "..team) - else - minetest.env:set_node(pos,{name="air"}) - end - end -}) +if ctf.setting("turrets") then + ARROW_DAMAGE = 2 + ARROW_VELOCITY = 2 + minetest.register_node("ctf_turret:turret", { + description = "Team Turret", + tiles = { + "default_stone.png", + "default_stone.png", + "default_stone.png", + "default_stone.png", + "default_stone.png", + "default_stone.png", + }, + drawtype="nodebox", + groups={attached_node=1}, + paramtype = "light", + node_box = { + type = "fixed", + fixed = { + {-0.500000,-0.500000,-0.500000,0.500000,0.000000,0.500000}, --NodeBox 1 + {-0.437500,0.000000,-0.437500,0.431250,0.187500,0.431250}, --NodeBox 2 + {-0.187500,0.187500,-0.187500,0.187500,0.500000,0.187500}, --NodeBox 3 + } + }, + groups = {cracky=3, stone=1}, + on_construct = function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string("infotext", "Unowned turret") + end, + after_place_node = function(pos, placer) + local meta = minetest.env:get_meta(pos) -minetest.register_abm({ - nodenames = {"ctf_turret:turret"}, - interval = 0.25, - chance = 4, - action = function(pos, node) - local meta = minetest.env:get_meta(pos) - if not meta then - return - end - - local team = meta:get_string("team") - if not team then - return - end - - local app = ctf.area.get_area(pos) - if app and app~=team then - team = app - meta:set_string("team",team) - meta:set_string("infotext", "Owned by "..team) - end - - if not team then - return - end - - local objects = minetest.env:get_objects_inside_radius(pos, 15) - for _,obj in ipairs(objects) do - if ( - obj:is_player() and - ctf.players and - ctf.player(obj:get_player_name()) and - ctf.player(obj:get_player_name()).team ~= team - )then - -- Calculate stuff - local obj_p = obj:getpos() - local calc = { - x=obj_p.x - pos.x, - y=obj_p.y+1 - pos.y, - z=obj_p.z - pos.z - } - - -- Create bullet entity - local bullet=minetest.env:add_entity({x=pos.x,y=pos.y+0.5,z=pos.z}, "ctf_turret:arrow_entity") - - -- Set velocity - bullet:setvelocity({x=calc.x * ARROW_VELOCITY,y=calc.y * ARROW_VELOCITY,z=calc.z * ARROW_VELOCITY}) - - -- Play sound - minetest.sound_play("laser", {pos = pos, gain = 1.0, max_hear_distance = 50,}) + if meta and ctf.players and ctf.player(placer:get_player_name()) and ctf.player(placer:get_player_name()).team then + local team = ctf.player(placer:get_player_name()).team + meta:set_string("team", team) + meta:set_string("infotext", "Owned by "..team) + else + minetest.env:set_node(pos,{name="air"}) end end - end -}) + }) --- The Arrow Entity -THROWING_ARROW_ENTITY={ - physical = false, - timer=0, - visual_size = {x=0.2, y=0.2}, - textures = {"bullet.png"}, - lastpos={}, - collisionbox = {-0.17,-0.17,-0.17,0.17,0.17,0.17}, - on_step = function(self, dtime) - self.timer=self.timer+dtime - local pos = self.object:getpos() - if self.timer > 2 then - self.object:remove() - end + minetest.register_abm({ + nodenames = {"ctf_turret:turret"}, + interval = 0.25, + chance = 4, + action = function(pos, node) + local meta = minetest.env:get_meta(pos) + if not meta then + return + end - if self.timer > 0.2 then - local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1.5) - for k, obj in pairs(objs) do - if obj:is_player() then - obj:set_hp(obj:get_hp() - ARROW_DAMAGE) - self.object:remove() + local team = meta:get_string("team") + if not team then + return + end + + local app = ctf.area.get_area(pos) + if app and app~=team then + team = app + meta:set_string("team",team) + meta:set_string("infotext", "Owned by "..team) + end + + if not team then + return + end + + local objects = minetest.env:get_objects_inside_radius(pos, 15) + for _,obj in ipairs(objects) do + if ( + obj:is_player() and + ctf.players and + ctf.player(obj:get_player_name()) and + ctf.player(obj:get_player_name()).team ~= team + )then + -- Calculate stuff + local obj_p = obj:getpos() + local calc = { + x=obj_p.x - pos.x, + y=obj_p.y+1 - pos.y, + z=obj_p.z - pos.z + } + + -- Create bullet entity + local bullet=minetest.env:add_entity({x=pos.x,y=pos.y+0.5,z=pos.z}, "ctf_turret:arrow_entity") + + -- Set velocity + bullet:setvelocity({x=calc.x * ARROW_VELOCITY,y=calc.y * ARROW_VELOCITY,z=calc.z * ARROW_VELOCITY}) + + -- Play sound + minetest.sound_play("laser", {pos = pos, gain = 1.0, max_hear_distance = 50,}) end end end + }) - local node = minetest.env:get_node(pos) - if node.name ~= "air" and node.name ~= "ctf_turret:turret" then - --minetest.env:add_item(self.lastpos, "throwing:arrow") - self.object:remove() + -- The Arrow Entity + THROWING_ARROW_ENTITY={ + physical = false, + timer=0, + visual_size = {x=0.2, y=0.2}, + textures = {"bullet.png"}, + lastpos={}, + collisionbox = {-0.17,-0.17,-0.17,0.17,0.17,0.17}, + on_step = function(self, dtime) + self.timer=self.timer+dtime + local pos = self.object:getpos() + if self.timer > 2 then + self.object:remove() + end + + if self.timer > 0.2 then + local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1.5) + for k, obj in pairs(objs) do + if obj:is_player() then + obj:set_hp(obj:get_hp() - ARROW_DAMAGE) + self.object:remove() + end + end + end + + local node = minetest.env:get_node(pos) + if node.name ~= "air" and node.name ~= "ctf_turret:turret" then + --minetest.env:add_item(self.lastpos, "throwing:arrow") + self.object:remove() + end end - end -} - -minetest.register_entity("ctf_turret:arrow_entity", THROWING_ARROW_ENTITY) - -minetest.register_craft({ - output = "ctf_turret:turret", - recipe = { - {"default:mese_crystal", "default:gold_ingot", "default:mese_crystal"}, - {"default:gold_ingot", "default:mese_crystal", "default:gold_ingot"}, - {"default:mese_crystal", "default:gold_ingot", "default:mese_crystal"} } -}) + + minetest.register_entity("ctf_turret:arrow_entity", THROWING_ARROW_ENTITY) + + minetest.register_craft({ + output = "ctf_turret:turret", + recipe = { + {"default:mese_crystal", "default:gold_ingot", "default:mese_crystal"}, + {"default:gold_ingot", "default:mese_crystal", "default:gold_ingot"}, + {"default:mese_crystal", "default:gold_ingot", "default:mese_crystal"} + } + }) +end diff --git a/mods/default/mapgen.lua b/mods/default/mapgen.lua index 386ba41..232ed4d 100644 --- a/mods/default/mapgen.lua +++ b/mods/default/mapgen.lua @@ -11,6 +11,7 @@ minetest.register_alias("mapgen_jungletree", "default:jungletree") minetest.register_alias("mapgen_jungleleaves", "default:jungleleaves") minetest.register_alias("mapgen_apple", "default:apple") minetest.register_alias("mapgen_water_source", "default:water_source") +minetest.register_alias("mapgen_river_water_source", "default:water_source") minetest.register_alias("mapgen_dirt", "default:dirt") minetest.register_alias("mapgen_sand", "default:sand") minetest.register_alias("mapgen_gravel", "default:gravel")