From fea07d8ae81b5c647213d7f23c9ca943468e4de5 Mon Sep 17 00:00:00 2001 From: ANAND Date: Wed, 10 Apr 2019 15:37:31 +0530 Subject: [PATCH] Exclude map's initial_stuff from list of treasures (#385) --- mods/ctf/ctf_map/schem_map.lua | 30 +++++++++++++++++++---- mods/ctf/ctf_treasure/init.lua | 44 ++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/mods/ctf/ctf_map/schem_map.lua b/mods/ctf/ctf_map/schem_map.lua index 7e55c22..8191244 100644 --- a/mods/ctf/ctf_map/schem_map.lua +++ b/mods/ctf/ctf_map/schem_map.lua @@ -207,9 +207,9 @@ function ctf_match.load_map_meta(idx, name) i = i + 1 end - -- Register per-map treasures or the default set of treasures + -- Register per-map treasures, or the default set of treasures -- if treasures field hasn't been defined in map meta - if treasurer and ctf_treasure then + if ctf_treasure then treasurer.treasures = {} if treasures then for _, item in pairs(treasures) do @@ -232,7 +232,28 @@ function ctf_match.load_map_meta(idx, name) end end else - ctf_treasure.register_default_treasures() + -- If treasure is a part of map's initial stuff, don't register it + local blacklist = map.initial_stuff or give_initial_stuff.get_stuff() + for _, def in pairs(ctf_treasure.get_default_treasures()) do + local is_valid = true + for _, b_item in pairs(blacklist) do + local b_stack = ItemStack(b_item) + local t_stack = ItemStack(def[1]) + if b_stack:get_name() == t_stack:get_name() and + t_stack:get_count() == 1 then + is_valid = false + minetest.log("action", + "ctf_map: Omitting treasure - " .. def[1]) + break + end + end + + if is_valid then + minetest.log("info", + "ctf_map: Registering treasure - " .. def[1]) + treasurer.register_treasure(def[1], def[2], def[3], def[4]) + end + end end end @@ -241,7 +262,8 @@ function ctf_match.load_map_meta(idx, name) while meta:get("chests." .. i .. ".from") do local from = minetest.string_to_pos(meta:get("chests." .. i .. ".from")) local to = minetest.string_to_pos(meta:get("chests." .. i .. ".to")) - assert(from and to, "Positions needed for chest zone " .. i .. " in map " .. map.name) + assert(from and to, "Positions needed for chest zone " .. + i .. " in map " .. map.name) map.chests[i] = { from = vector.add(offset, from), diff --git a/mods/ctf/ctf_treasure/init.lua b/mods/ctf/ctf_treasure/init.lua index 9bc84e3..88e7e53 100644 --- a/mods/ctf/ctf_treasure/init.lua +++ b/mods/ctf/ctf_treasure/init.lua @@ -1,27 +1,29 @@ ctf_treasure = {} -function ctf_treasure.register_default_treasures() - treasurer.register_treasure("default:ladder",0.3,5,{1,20}) - treasurer.register_treasure("default:torch",0.3,5,{1,20}) - treasurer.register_treasure("default:cobble",0.4,5,{45,99}) - treasurer.register_treasure("default:wood",0.3,5,{30,60}) - treasurer.register_treasure("doors:door_steel",0.3,5,{1,3}) +function ctf_treasure.get_default_treasures() + return { + {"default:ladder",0.3,5,{1,20}}, + {"default:torch",0.3,5,{1,20}}, + {"default:cobble",0.4,5,{45,99}}, + {"default:wood",0.3,5,{30,60}}, + {"doors:door_steel",0.3,5,{1,3}}, - treasurer.register_treasure("default:pick_steel",0.5,5,{1,10}) - treasurer.register_treasure("default:sword_stone",0.6,5,{1,10}) - treasurer.register_treasure("default:sword_steel",0.4,5,{1,4}) - treasurer.register_treasure("default:shovel_stone",0.6,5,{1,10}) - treasurer.register_treasure("default:shovel_steel",0.3,5,{1,10}) + {"default:pick_steel",0.5,5,{1,10}}, + {"default:sword_stone",0.6,5,{1,10}}, + {"default:sword_steel",0.4,5,{1,4}}, + {"default:shovel_stone",0.6,5,{1,10}}, + {"default:shovel_steel",0.3,5,{1,10}}, - treasurer.register_treasure("shooter:crossbow",0.5,2,{1,5}) - treasurer.register_treasure("shooter:pistol",0.4,2,{1,5}) - treasurer.register_treasure("shooter:rifle",0.1,2,{1,2}) - treasurer.register_treasure("shooter:shotgun",0.04,2,1) - treasurer.register_treasure("shooter:grenade",0.08,2,1) - treasurer.register_treasure("shooter:machine_gun",0.02,2,1) - treasurer.register_treasure("shooter:ammo",0.3,2,{1,10}) - treasurer.register_treasure("shooter:arrow_white",0.5,2,{2,18}) + {"shooter:crossbow",0.5,2,{1,5}}, + {"shooter:pistol",0.4,2,{1,5}}, + {"shooter:rifle",0.1,2,{1,2}}, + {"shooter:shotgun",0.04,2,1}, + {"shooter:grenade",0.08,2,1}, + {"shooter:machine_gun",0.02,2,1}, + {"shooter:ammo",0.3,2,{1,10}}, + {"shooter:arrow_white",0.5,2,{2,18}}, - treasurer.register_treasure("ctf_bandages:bandage",0.3,5,{1,6}) - treasurer.register_treasure("medkits:medkit",0.8,5,2) + {"ctf_bandages:bandage",0.3,5,{1,6}}, + {"medkits:medkit",0.8,5,2} + } end