Skip to content

Commit

Permalink
Merge branch 'MT-CTF:master' into donation-time-left
Browse files Browse the repository at this point in the history
  • Loading branch information
src4026 authored Nov 3, 2023
2 parents ac48831 + ba9cfc1 commit 205fd78
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 21 deletions.
1 change: 1 addition & 0 deletions mods/apis/ctf_gui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ do
end
end

minetest.log("action", "[ctf_gui] unpacking: "..dump(l))
return format(base, unpck(l))
end

Expand Down
Binary file removed mods/ctf/ctf_map/textures/default_chest_front_blue.png
Binary file not shown.
Binary file removed mods/ctf/ctf_map/textures/default_chest_front_red.png
Binary file not shown.
Binary file removed mods/ctf/ctf_map/textures/default_chest_side_blue.png
Binary file not shown.
Binary file removed mods/ctf/ctf_map/textures/default_chest_side_red.png
Binary file not shown.
Binary file removed mods/ctf/ctf_map/textures/default_chest_top_blue.png
Binary file not shown.
Binary file removed mods/ctf/ctf_map/textures/default_chest_top_red.png
Binary file not shown.
4 changes: 2 additions & 2 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ local function drop_flag(teamname)
if pteam == teamname then
minetest.sound_play("ctf_modebase_drop_flag_negative", {
to_player = pname,
gain = 0.4,
gain = 0.2,
pitch = 1.0,
}, true)
else
minetest.sound_play("ctf_modebase_drop_flag_positive", {
to_player = pname,
gain = 0.4,
gain = 0.2,
pitch = 1.0,
}, true)
end
Expand Down
62 changes: 45 additions & 17 deletions mods/ctf/ctf_modebase/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ local simplify_for_saved_stuff = function(iname)
return "shovel"
elseif iname:match("ctf_mode_nade_fight:") then
return "nade_fight_grenade"
elseif
iname == "ctf_mode_classes:knight_sword" or
iname == "ctf_mode_classes:support_bandage" or
iname == "ctf_mode_classes:ranged_rifle_loaded"
then
return "class_primary"
end

local mod, match = iname:match("(%a+):sword_(%a+)")
Expand All @@ -22,12 +28,31 @@ local simplify_for_saved_stuff = function(iname)
return iname
end

function ctf_modebase.player.save_initial_stuff_order(player, soft)
local function is_initial_stuff(player, i)
local mode = ctf_modebase:get_current_mode()
if mode and mode.stuff_provider then
for _, item in ipairs(mode.stuff_provider(player)) do
if ItemStack(item):get_name() == i then
return true
end
end
end

if ctf_map.current_map and ctf_map.current_map.initial_stuff then
for _, item in ipairs(ctf_map.current_map.initial_stuff) do
if ItemStack(item):get_name() == i then
return true
end
end
end
end

function ctf_modebase.player.save_initial_stuff_positions(player, soft)
if not ctf_modebase.current_mode then return end

local inv = player:get_inventory()
local meta = player:get_meta()
local ssp = meta:get_string("ctf_modebase:player:initial_stuff_order:"..ctf_modebase.current_mode)
local ssp = meta:get_string("ctf_modebase:player:initial_stuff_positions:"..ctf_modebase.current_mode)

if ssp == "" then
ssp = {}
Expand All @@ -37,8 +62,10 @@ function ctf_modebase.player.save_initial_stuff_order(player, soft)

local done = {}
for i, s in pairs(inv:get_list("main")) do
if s:get_name() ~= "" then
local k = simplify_for_saved_stuff(s:get_name():match("[^%s]*"))
local n = s:get_name()

if n ~= "" and is_initial_stuff(player, n) then
local k = simplify_for_saved_stuff(n:match("[^%s]*"))

if not soft or not ssp[k] then
if not done[k] or (i < ssp[k]) then
Expand All @@ -49,9 +76,10 @@ function ctf_modebase.player.save_initial_stuff_order(player, soft)
end
end

meta:set_string("ctf_modebase:player:initial_stuff_order:"..ctf_modebase.current_mode, minetest.serialize(ssp))
meta:set_string("ctf_modebase:player:initial_stuff_positions:"..ctf_modebase.current_mode, minetest.serialize(ssp))
end

-- Changes made to this function should also be made to is_initial_stuff() above
local function get_initial_stuff(player, f)
local mode = ctf_modebase:get_current_mode()
if mode and mode.stuff_provider then
Expand Down Expand Up @@ -113,9 +141,11 @@ function ctf_modebase.player.give_initial_stuff(player)
end)

-- Check for new items not yet in the order list
ctf_modebase.player.save_initial_stuff_order(player, true)
ctf_modebase.player.save_initial_stuff_positions(player, true)

local saved_stuff_positions = meta:get_string("ctf_modebase:player:initial_stuff_order:"..ctf_modebase.current_mode)
local saved_stuff_positions = meta:get_string(
"ctf_modebase:player:initial_stuff_positions:"..ctf_modebase.current_mode
)

if saved_stuff_positions == "" then
saved_stuff_positions = {}
Expand All @@ -140,16 +170,14 @@ function ctf_modebase.player.give_initial_stuff(player)
end

for stack, idx in pairs(tmp) do
for i = 1, #new+1 do
if new[i] then
if idx < tmp[new[i]] then
table.insert(new, i, stack)
break
end
else
new[i] = stack
break
end
if not new[idx] then
new[idx] = stack
end
end

for stack, idx in pairs(tmp) do
if new[idx] ~= stack then
table.insert(new, stack)
end
end

Expand Down
3 changes: 1 addition & 2 deletions mods/other/crafting/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ function crafting.result_select_on_receive_results(player, context, fields)
if key:sub(1, 7) == "result_" then
local num = string.match(key, "result_([0-9]+)")
if num then
local inv = player:get_inventory()
local recipe = crafting.get_recipe(tonumber(num))
local name = player:get_player_name()
if not crafting.can_craft(name, recipe) then
Expand Down Expand Up @@ -215,7 +214,7 @@ if minetest.global_exists("sfinv") then
end

if fields.save_inv_order then
ctf_modebase.player.save_initial_stuff_order(player)
ctf_modebase.player.save_initial_stuff_positions(player)

minetest.sound_play("crafting_save_sound", {
to_player = player:get_player_name(),
Expand Down

0 comments on commit 205fd78

Please sign in to comment.