Skip to content

Commit

Permalink
Merge branch 'master' into flag_m
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT authored Aug 17, 2024
2 parents d99e46e + ce50b80 commit 9462928
Show file tree
Hide file tree
Showing 28 changed files with 468 additions and 153 deletions.
37 changes: 36 additions & 1 deletion mods/apis/ctf_settings/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,33 @@ minetest.register_on_mods_loaded(function()
settingdef.description or HumanReadable(setting),
}
lastypos = lastypos + 0.6
elseif settingdef.type == "bar" then
lastypos = lastypos + 0.7
setting_list[k] = {
"label[0,%f;%s: %d%%]"..
"scrollbaroptions[min=%d;max=%d;smallstep=%d]"..
"scrollbar[0,%f;%f,0.4;horizontal;%s;%s]",
lastypos - 0.5,
settingdef.label or HumanReadable(setting),
(
tonumber(context.setting[setting])
/
((settingdef.max - settingdef.min) - tonumber(settingdef.default))
) * 100,
settingdef.min or 0,
settingdef.max or 10,
settingdef.step or 1,
lastypos,
FORMSIZE.x - SCROLLBAR_W -2,
setting,
context.setting[setting],
}
lastypos = lastypos + 0.5
end
end

local form = {
{"box[-0.1,-0.1;%f,%f;#00000055]", FORMSIZE.x - SCROLLBAR_W, FORMSIZE.y},
{"box[-0.1,-0.1;%f,%f;#00000055]", FORMSIZE.x - SCROLLBAR_W, FORMSIZE.y},
{"scroll_container[-0.1,0.3;%f,%f;settings_scrollbar;vertical;0.1]",
FORMSIZE.x - SCROLLBAR_W + 2,
FORMSIZE.y + 0.7
Expand Down Expand Up @@ -168,6 +190,19 @@ minetest.register_on_mods_loaded(function()
setting.on_change(player, tostring(idx))
end

refresh = true
end
elseif setting.type == "bar" then
local scrollevent = minetest.explode_scrollbar_event(value)

if scrollevent.value and context.setting[field] ~= tostring(scrollevent.value) then
context.setting[field] = tostring(scrollevent.value)
ctf_settings.set(player, field, tostring(scrollevent.value))

if setting.on_change then
setting.on_change(player, tostring(scrollevent.value))
end

refresh = true
end
end
Expand Down
3 changes: 2 additions & 1 deletion mods/ctf/ctf_map/map_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ function ctf_map.place_map(mapmeta, callback)
for name, def in pairs(mapmeta.teams) do
local p = def.flag_pos

minetest.load_area(p)
local node = minetest.get_node(p)

if node.name ~= "ctf_modebase:flag" then
if node.name ~= "ignore" and node.name ~= "ctf_modebase:flag" then
minetest.log("error", name.."'s flag was set incorrectly, or there is no flag node placed")
else
minetest.set_node(vector.offset(p, 0, 1, 0), {name="ctf_modebase:flag_top_"..name, param2 = node.param2})
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_map/maps
Submodule maps updated 2 files
+3 −3 plains/map.conf
+1 −1 snowland/map.conf
18 changes: 15 additions & 3 deletions mods/ctf/ctf_map/nodes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,9 @@ local chest_def = {
minetest.set_node(pos, {name = "air"})
end)
end
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
minetest.swap_node(pos, {name = "ctf_map:chest_opened"})
minetest.get_meta(pos):set_string("infotext", chestv)
end
end,
}

local ochest_def = table.copy(chest_def)
Expand All @@ -256,6 +254,20 @@ ochest_def.tiles[6] = "default_chest_inside.png"
ochest_def.mesh = "chest_open.obj"
ochest_def.light_source = 1
ochest_def.on_rightclick = nil
ochest_def.on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", string.format("%s takes %s from treasure chest at %s",
player:get_player_name(),
stack:to_string(),
minetest.pos_to_string(pos)
))
local inv = minetest.get_inventory({type = "node", pos = pos})
if not inv or inv:is_empty("main") then
minetest.close_formspec(player:get_player_name(), "")
minetest.after(0, function()
minetest.set_node(pos, {name = "air"})
end)
end
end

minetest.register_node("ctf_map:chest_opened", ochest_def)
minetest.register_node("ctf_map:chest", chest_def)
38 changes: 21 additions & 17 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -301,19 +301,22 @@ local function celebrate_team(teamname)
for _, player in ipairs(minetest.get_connected_players()) do
local pname = player:get_player_name()
local pteam = ctf_teams.get(pname)
local volume = (tonumber(ctf_settings.get(player, "flag_sound_volume")) or 10.0) / 10

if pteam == teamname then
minetest.sound_play("ctf_modebase_trumpet_positive", {
to_player = pname,
gain = 1.0,
pitch = 1.0,
}, true)
else
minetest.sound_play("ctf_modebase_trumpet_negative", {
to_player = pname,
gain = 1.0,
pitch = 1.0,
}, true)
if volume > 0 then
if pteam == teamname then
minetest.sound_play("ctf_modebase_trumpet_positive", {
to_player = pname,
gain = volume,
pitch = 1.0,
}, true)
else
minetest.sound_play("ctf_modebase_trumpet_negative", {
to_player = pname,
gain = volume,
pitch = 1.0,
}, true)
end
end
end
end
Expand All @@ -322,18 +325,19 @@ local function drop_flag(teamname)
for _, player in ipairs(minetest.get_connected_players()) do
local pname = player:get_player_name()
local pteam = ctf_teams.get(pname)
local drop_volume = (tonumber(ctf_settings.get(player, "flag_sound_volume")) or 10.0) / 10

if pteam then
if pteam and drop_volume > 0 then
if pteam == teamname then
minetest.sound_play("ctf_modebase_drop_flag_negative", {
to_player = pname,
gain = 0.2,
gain = math.max(0.1, drop_volume - 0.5),
pitch = 1.0,
}, true)
else
minetest.sound_play("ctf_modebase_drop_flag_positive", {
to_player = pname,
gain = 0.2,
gain = math.max(0.1, drop_volume - 0.5),
pitch = 1.0,
}, true)
end
Expand Down Expand Up @@ -708,7 +712,7 @@ return {
local capture_reward = 0
for _, lost_team in ipairs(teamnames) do
local score = ((team_scores[lost_team] or {}).score or 0) / 4
score = math.max(75, math.min(500, score))
score = math.max(75, score)
capture_reward = capture_reward + score
end
local text = " has captured the flag"
Expand Down Expand Up @@ -827,7 +831,7 @@ return {
local rank = rankings:get(pname)
local player = minetest.get_player_by_name(pname)
local pro_chest = player and player:get_meta():get_int("ctf_rankings:pro_chest:"..
(ctf_modebase.current_mode or "")) == 1
(ctf_modebase.current_mode or "")) >= 1
local deny_pro = "You need to have more than 1.4 kills per death, "..
"5 captures, and at least 8,000 score to access the pro section."
if rank then
Expand Down
4 changes: 4 additions & 0 deletions mods/ctf/ctf_modebase/flags/huds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ local function get_flag_status(you)
end

function ctf_modebase.flag_huds.update_player(player)
local team = ctf_teams.get(player)

if not team or (ctf_teams.team[team] and ctf_teams.team[team].not_playing) then return end

local flag_status = get_flag_status(player:get_player_name())

if hud:exists(player, "flag_status") then
Expand Down
12 changes: 11 additions & 1 deletion mods/ctf/ctf_modebase/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ minetest.register_on_mods_loaded(function()
player:set_nametag_attributes({color = {a = 0, r = 255, g = 255, b = 255}, text = ""})
end)
elseif ctf_core.settings.server_mode == "play" then
minetest.after(3, ctf_modebase.start_new_match)
minetest.chat_send_all("[CTF] Sorting rankings...")
local function check()
if not ctf_rankings:rankings_sorted() then
return minetest.after(1, check)
end

minetest.chat_send_all("[CTF] Rank sorting done. Starting new match...")
ctf_modebase.start_new_match()
end

check()
end

for _, name in pairs(ctf_modebase.modelist) do
Expand Down
11 changes: 10 additions & 1 deletion mods/ctf/ctf_modebase/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ ctf_settings.register("auto_trash_stone_tools", {
default = "false"
})

ctf_settings.register("flag_sound_volume", {
type = "bar",
label = "Flag Sound Volume",
default = "10",
min = 0,
max = 20,
step = 1,
})

local simplify_for_saved_stuff = function(iname)
if not iname or iname == "" then return iname end

Expand Down Expand Up @@ -236,7 +245,7 @@ if minetest.register_on_item_pickup then

if cprio and cprio < priority then
local item, typ = simplify_for_saved_stuff(compare:get_name())
minetest.log(dump(item)..dump(typ))
--minetest.log(dump(item)..dump(typ))
inv:set_stack("main", i, itemstack)

if item == "sword" and typ == "stone" and
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modebase/ranking_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ ctf_api.register_on_match_end(function()
donate_timer = {}
end)

minetest.register_chatcommand("donate", {
ctf_core.register_chatcommand_alias("donate", "d", {
description = "Donate your match score to your teammate\nCan be used only once in 2.5 minutes",
params = "<name [name2 name3 ...]> <score> [message]",
func = function(name, param)
Expand Down
8 changes: 5 additions & 3 deletions mods/ctf/ctf_modes/ctf_mode_classes/classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local class_props = {
color = "grey",
description = "High HP class with a sword capable of short damage bursts",
hp_max = 30,
visual_size = vector.new(1.1, 1.05, 1.1),
visual_size = vector.new(0.1, 0.05, 0.1),
items = {
"ctf_mode_classes:knight_sword",
},
Expand Down Expand Up @@ -47,7 +47,7 @@ local class_props = {
name = "Scout",
color = "orange",
description = "Ranged class with a scoped rifle/grenade launcher and a scaling ladder for reaching high places",
visual_size = vector.new(0.9, 1, 0.9),
visual_size = vector.new(-0.1, 0.0, -0.1),
items = {
"ctf_mode_classes:ranged_rifle_loaded",
"ctf_mode_classes:scaling_ladder"
Expand Down Expand Up @@ -375,10 +375,12 @@ end

function classes.update(player)
local class = classes.get(player)
local base_size = player_api.registered_models['character.b3d'].visual_size
base_size = vector.new(base_size.x, base_size.y, base_size.z or base_size.x)

player:set_properties({
hp_max = class.hp_max or minetest.PLAYER_MAX_HP_DEFAULT,
visual_size = class.visual_size or vector.new(1, 1, 1)
visual_size = vector.add(base_size, class.visual_size or vector.new()) or base_size
})

if class.physics then
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local rankings = ctf_rankings.init()
local rankings = ctf_rankings:init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)

Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/mod.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name = ctf_mode_classes
depends = ctf_modebase, ctf_melee, ctf_gui, ctf_cosmetics, ctf_api, hud_events, ctf_settings, ctf_player
depends = ctf_modebase, ctf_melee, ctf_gui, ctf_cosmetics, ctf_api, hud_events, ctf_settings, ctf_player, player_api
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_classic/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local rankings = ctf_rankings.init()
local rankings = ctf_rankings:init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)

Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modes/ctf_mode_nade_fight/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local rankings = ctf_rankings.init()
local rankings = ctf_rankings:init()
local recent_rankings = ctf_modebase.recent_rankings(rankings)
local features = ctf_modebase.features(rankings, recent_rankings)

Expand Down
55 changes: 48 additions & 7 deletions mods/ctf/ctf_rankings/default.lua
Original file line number Diff line number Diff line change
@@ -1,22 +1,63 @@
return function(prefix, top)
return function(prefix, top, sorting_finished)

local modstorage = assert(minetest.get_mod_storage(), "Can only init rankings at runtime!")

local function op_all(operation)
for k, v in pairs(modstorage:to_table()["fields"]) do
operation(k, v)
-- If callback isn't passed then coroutine will never yield
local function op_all(operation, callback)
if not callback then
minetest.log("warning", "op_all() called without callback, it will block the server step until it finishes")
end

local TARGET_INTERVAL = 0.1
local interval = 0.05
local time = minetest.get_us_time()
local times = 0
local keys = modstorage:to_table()["fields"]
local c = coroutine.wrap(function()
for k, v in pairs(keys) do
times = times + 1
operation(k, v)

if callback and ((minetest.get_us_time()-time) / 1e6) >= interval then
coroutine.yield()
end
end
end)

local function rep()
if ((minetest.get_us_time()-time) / 1e6) > TARGET_INTERVAL then
interval = interval - 0.01
else
interval = interval + 0.01
end
time = minetest.get_us_time()

if c() ~= "done" then
minetest.after(0, rep)
elseif callback then
assert(times == #keys, dump(#keys - times).." | "..dump(times).." | "..dump(#keys))
callback()
end
end

rep()
end

local timer = minetest.get_us_time()
op_all(function(key, value)
op_all(function(noprefix_key, value)
local rank = minetest.parse_json(value)

if rank ~= nil and rank.score then
top:set(key, rank.score)
top:set(noprefix_key, rank.score)
end
end,
function()
minetest.log(
"action",
"Sorted rankings by score '"..prefix:sub(1, -2).."'. Took "..((minetest.get_us_time()-timer) / 1e6)
)
sorting_finished()
end)
minetest.log("action", "Sorted rankings database. Took "..((minetest.get_us_time()-timer) / 1e6))

return {
backend = "default",
Expand Down
Loading

0 comments on commit 9462928

Please sign in to comment.