Skip to content

Commit

Permalink
Merge branch 'master' into class-change
Browse files Browse the repository at this point in the history
  • Loading branch information
a-blob authored Apr 18, 2024
2 parents 3a1705c + 5c1b73c commit 7a7e4a5
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 117 deletions.
3 changes: 3 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@


- [ ] This PR has been tested locally
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ Previous Developers: [savilli](https://github.com/savilli).

Check out [mods/](mods/) to see all the installed mods and their respective licenses.

Licenses where not specified:
Code: LGPLv2.1+
Textures: CC-BY-SA 3.0
Licenses where not specified:\
Code: [GNU LGPLv2.1+](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html)\
Media: [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)

### Textures

* [Header](menu/header.png): CC-BY-3.0 by [SuddenSFD](https://github.com/SuddenSFD)
* [Background Image](menu/background.png): CC BY-SA 4.0 (where applicable) by [GreenBlob](https://github.com/a-blob) (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed CC-BY-SA 3.0). The player skins used are licensed CC-BY-SA 3.0
* [Icon](menu/icon.png): CC-BY-3.0 by [SuddenSFD](https://github.com/SuddenSFD)
* [Header](menu/header.png): [CC BY 3.0 Unported](https://creativecommons.org/licenses/by/3.0/) by [SuddenSFD](https://github.com/SuddenSFD)
* [Background Image](menu/background.png): [CC BY-SA 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/) (where applicable) by [GreenBlob](https://github.com/a-blob) (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)). The player skins used are licensed under [CC BY-SA 3.0 Unported](https://creativecommons.org/licenses/by-sa/3.0/)
* [Icon](menu/icon.png): [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/) by [SuddenSFD](https://github.com/SuddenSFD)
10 changes: 8 additions & 2 deletions mods/apis/ctf_gui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,16 @@ function ctf_gui.old_show_formspec(player, formname, formdef)
formdef._info = formdef
context[player] = formdef

minetest.log("action", "Showing formspec "..dump(formname).." to "..dump(player))
minetest.show_formspec(player, formname, formspec)
if minetest.get_player_by_name(player) then
minetest.log("action", "Showing formspec "..dump(formname).." to "..dump(player))
minetest.show_formspec(player, formname, formspec)
end
end,
formdef, ctf_gui.ELEM_SIZE, ctf_gui.SCROLLBAR_WIDTH)
end

minetest.register_on_leaveplayer(function(player)
context[player:get_player_name()] = nil
end)

dofile(minetest.get_modpath("ctf_gui").."/dev.lua")
2 changes: 1 addition & 1 deletion mods/apis/hud_events/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ local function show_quick_hud_event(player, huddef)
end

if quick_event_timer[pname] then
quick_event_timer[pname].cancel()
quick_event_timer[pname]:cancel()
end
quick_event_timer[pname] = minetest.after(HUD_SHOW_QUICK_TIME, function()
if not player:is_player() then return end
Expand Down
12 changes: 0 additions & 12 deletions mods/ctf/ctf_chat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ minetest.override_chatcommand("me", {
end
})

minetest.override_chatcommand("donate", {
func = function(name, param)
local old_func = minetest.registered_chatcommands["donate"].func
if filter and not filter.check_message(name, param) then
filter.on_violation(name, param)
return false, "No swearing"
end

return old_func(name, param)
end
})

minetest.register_chatcommand("t", {
params = "msg",
description = "Send a message on the team channel",
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ctf_core = {
settings = {
-- server_mode = minetest.settings:get("ctf_server_mode") or "play",
server_mode = minetest.settings:get_bool("creative_mode", false) and "mapedit" or "play",
low_ram_mode = minetest.settings:get("ctf_low_ram_mode") or false,
low_ram_mode = minetest.settings:get("ctf_low_ram_mode") == "true" or false,
}
}

Expand Down
32 changes: 26 additions & 6 deletions mods/ctf/ctf_map/map_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ function ctf_map.place_map(mapmeta, callback)
local dirname = mapmeta.dirname
local schempath = ctf_map.maps_dir .. dirname .. "/map.mts"

local barrier_data = mapmeta.barriers and mapmeta.barriers()

ctf_map.emerge_with_callbacks(nil, mapmeta.pos1, mapmeta.pos2, function(ctx)
local rotation = (mapmeta.rotation and mapmeta.rotation ~= "z") and "90" or "0"
local res = minetest.place_schematic(mapmeta.pos1, schempath, rotation, {["ctf_map:chest"] = "air"})

minetest.log("action", string.format(
"Placed map %s in %.2fs", dirname, (minetest.get_us_time() - ctx.start_time) / 1000000
"Placed map %s in %.2fs", dirname, (minetest.get_us_time() - ctx.start_time) / 1e6
))

for name, def in pairs(mapmeta.teams) do
Expand Down Expand Up @@ -46,6 +48,10 @@ function ctf_map.place_map(mapmeta, callback)

ctf_map.current_map = mapmeta

if barrier_data then
ctf_map.current_map.barrier_data = barrier_data
end

callback()
end)
end
Expand All @@ -61,7 +67,7 @@ local ID_WATER = minetest.get_content_id("default:water_source")
---@param mapmeta table Map meta table
---@param callback function
function ctf_map.remove_barrier(mapmeta, callback)
if not mapmeta.barriers then
if not mapmeta.barrier_data then
minetest.log("action", "Clearing barriers using mapmeta.barrier_area")

local pos1, pos2 = mapmeta.barrier_area.pos1, mapmeta.barrier_area.pos2
Expand Down Expand Up @@ -94,14 +100,26 @@ function ctf_map.remove_barrier(mapmeta, callback)
vm2:update_liquids()
end)
else
minetest.log("action", "Clearing barriers using barriers.data")

local i = 0
for _, barrier_area in pairs(mapmeta.barriers) do
for _, barrier_area in pairs(mapmeta.barrier_data) do
minetest.after(i, function()
local vm = VoxelManip()
vm:read_from_map(barrier_area.pos1, barrier_area.pos2)

local data = vm:get_data()
assert(#data == barrier_area.max)

if #data ~= barrier_area.max then
-- minetest.log(dump(mapmeta.barrier_data)) -- Used for debugging issues
minetest.log("error", "Potential issue with barriers.data. Aborting... | " ..
"Debug: "..dump(#data)..", "..dump(barrier_area.max))

mapmeta.barrier_data = nil
ctf_map.remove_barrier(mapmeta, callback)
return
end

for idx in pairs(data) do
data[idx] = barrier_area.reps[idx] or ID_IGNORE
end
Expand All @@ -110,13 +128,15 @@ function ctf_map.remove_barrier(mapmeta, callback)
vm:write_to_map(false)
end)

i = i + 0.04
i = i + 0.05
end

minetest.after(i - 0.04, function()
minetest.after(i - 0.05, function()
local vm = VoxelManip(mapmeta.pos1, mapmeta.pos2)
vm:update_liquids()

mapmeta.barrier_data = nil -- Contains a large amount of data, free it up now that it's not needed

callback()
end)

Expand Down
74 changes: 40 additions & 34 deletions mods/ctf/ctf_map/map_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@ local function calc_flag_center(map)
return flag_center
end

local function connect_barriers_file(map_name, offset, barriers_filepath)
return function()
local f, err = io.open(barriers_filepath, "rb")

if (ctf_core.settings.server_mode ~= "mapedit" and assert(f, err)) or f then
local barriers = f:read("*all")

f:close()

assert(barriers and barriers ~= "")

barriers = minetest.deserialize(minetest.decompress(barriers, "deflate"))

if barriers then
for _, barrier_area in pairs(barriers) do
barrier_area.pos1 = vector.add(barrier_area.pos1, offset)
barrier_area.pos2 = vector.add(barrier_area.pos2, offset)

for i = 1, barrier_area.max do
if not barrier_area.reps[i] then
barrier_area.reps[i] = minetest.CONTENT_IGNORE
else
barrier_area.reps[i] = minetest.get_content_id(barrier_area.reps[i])
end
end
end

return barriers
else
minetest.log("error", "Map "..map_name.." has a corrupted barriers file. Re-save map to fix")
end
else
minetest.log("error", "Map "..map_name.." is missing its barriers file. Re-save map to fix")
end
end
end

function ctf_map.load_map_meta(idx, dirname)
local meta = Settings(ctf_map.maps_dir .. dirname .. "/map.conf")

Expand Down Expand Up @@ -134,7 +171,7 @@ function ctf_map.load_map_meta(idx, dirname)
offset.y = -size.y/2

map = {
map_version = CURRENT_MAP_VERSION,
map_version = tonumber(meta:get("map_version") or "0"),
pos1 = offset,
pos2 = vector.add(offset, size),
offset = offset,
Expand All @@ -160,39 +197,8 @@ function ctf_map.load_map_meta(idx, dirname)
game_modes = minetest.deserialize(meta:get("game_modes")),
enable_shadows = tonumber(meta:get("enable_shadows") or "0.26"),
}
if tonumber(meta:get("map_version")) > 2 and not ctf_core.settings.low_ram_mode then
local f, err = io.open(ctf_map.maps_dir .. dirname .. "/barriers.data", "rb")

if (ctf_core.settings.server_mode ~= "mapedit" and assert(f, err)) or f then
local barriers = f:read("*all")

f:close()

assert(barriers and barriers ~= "")

barriers = minetest.deserialize(minetest.decompress(barriers, "deflate"))

if barriers then
for _, barrier_area in pairs(barriers) do
barrier_area.pos1 = vector.add(barrier_area.pos1, offset)
barrier_area.pos2 = vector.add(barrier_area.pos2, offset)

for i = 1, barrier_area.max do
if not barrier_area.reps[i] then
barrier_area.reps[i] = minetest.CONTENT_IGNORE
else
barrier_area.reps[i] = minetest.get_content_id(barrier_area.reps[i])
end
end
end

map.barriers = barriers
else
minetest.log("error", "Map "..dirname.." has a corrupted barriers file. Re-save map to fix")
end
else
minetest.log("error", "Map "..dirname.." is missing its barriers file. Re-save map to fix")
end
if tonumber(meta:get("map_version")) >= 3 and not ctf_core.settings.low_ram_mode then
map.barriers = connect_barriers_file(dirname, offset, ctf_map.maps_dir .. dirname .. "/barriers.data")
end

for id, def in pairs(map.chests) do
Expand Down
37 changes: 21 additions & 16 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ ctf_core.testing = {
local one_third = math.ceil(0.34 * total_players)
local one_fourth = math.ceil(0.25 * total_players)
local avg = (kd_diff + actual_kd_diff) / 2
local pcount_diff_limit = (
(players_diff <= math.min(one_fourth, 2)) or
(pkd >= 1.8 and players_diff <= math.min(one_third, 4))
)
if best_kd.kills + worst_kd.kills >= 30 then
avg = actual_kd_diff
end
return (best_kd.kills + worst_kd.kills >= 30 and best_kd.t == best_players.t) or
(
pkd >= math.min(1, kd_diff/2) and avg >= 0.4 and
(
players_diff <= math.min(one_fourth, 3) or
(pkd >= 1.5 and players_diff <= math.min(one_third, 6))
)
)
return pcount_diff_limit and ((best_kd.kills + worst_kd.kills >= 30 and best_kd.t == best_players.t) or
(pkd >= math.min(1, kd_diff/2) and avg >= 0.4))
end
}

Expand All @@ -29,6 +27,13 @@ local LOADING_SCREEN_TARGET_TIME = 7
local loading_screen_time

local function update_playertag(player, t, nametag, team_nametag, symbol_nametag)
if not nametag.object.set_observers or
not team_nametag.object.set_observers or
not symbol_nametag.object.set_observers
then
return
end

local entity_players = {}
local nametag_players = table.copy(ctf_teams.online_players[t].players)
local symbol_players = {}
Expand All @@ -53,9 +58,9 @@ local function update_playertag(player, t, nametag, team_nametag, symbol_nametag
end

-- Occasionally crashes in singleplayer, so call it safely
pcall( team_nametag.object.set_observers, team_nametag.object, nametag_players)
pcall(symbol_nametag.object.set_observers, symbol_nametag.object, symbol_players )
pcall( nametag.object.set_observers, nametag.object, entity_players )
nametag.object:set_observers(entity_players )
team_nametag.object:set_observers(nametag_players)
symbol_nametag.object:set_observers(symbol_players )
end

local tags_hidden = false
Expand Down Expand Up @@ -101,11 +106,11 @@ local function set_playertags_state(state)
local nametag = playertag.entity
local symbol_entity = playertag.symbol_entity

if nametag and team_nametag and symbol_entity then
-- Occasionally crashes in singleplayer, so call it safely
pcall( team_nametag.object.set_observers, team_nametag.object, {})
pcall(symbol_entity.object.set_observers, symbol_entity.object, {})
pcall( nametag.object.set_observers, nametag.object, {})
if nametag and team_nametag and symbol_entity and
nametag.object.set_observers and team_nametag.object.set_observers and symbol_entity.object.set_observers then
team_nametag.object:set_observers({})
symbol_entity.object:set_observers({})
nametag.object:set_observers({})
end
end
end
Expand Down
Loading

0 comments on commit 7a7e4a5

Please sign in to comment.