Skip to content

Commit

Permalink
Merge branch 'MT-CTF:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
a-blob authored Sep 20, 2023
2 parents e67df27 + ae38980 commit ade8057
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 66 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,14 @@ Created by [rubenwardy](https://rubenwardy.com/).
Developed by [LandarVargan](https://github.com/LoneWolfHT).
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

### Textures

* [Header](menu/header.png): CC BY-SA 4.0 by xenonca
* [Background Image](menu/background.png): CC0 (where applicable) by Apelta (Uses [Minetest Game](https://github.com/minetest/minetest_game) textures, the majority of which are licensed CC-BY-SA 3.0). The player skin used is licensed CC-BY-SA 3.0

### Mods

Check out [mods/](mods/) to see all the installed mods and their respective licenses.
* [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)
Binary file modified menu/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified menu/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mods/ctf/ctf_core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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,
}
}

Expand Down
14 changes: 7 additions & 7 deletions mods/ctf/ctf_map/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ ctf_core.include_files(
)

local directory = minetest.get_modpath(minetest.get_current_modname()) .. "/maps/"

for _, entry in ipairs(minetest.get_dir_list(directory, true)) do
for _, filename in ipairs(minetest.get_dir_list(directory .. "/" .. entry .. "/", false)) do
if filename == "init.lua" then
dofile(directory .. "/" .. entry .. "/"..filename)
minetest.register_on_mods_loaded(function()
for _, entry in ipairs(minetest.get_dir_list(directory, true)) do
for _, filename in ipairs(minetest.get_dir_list(directory .. "/" .. entry .. "/", false)) do
if filename == "init.lua" then
dofile(directory .. "/" .. entry .. "/"..filename)
end
end
end
end

end)

minetest.register_chatcommand("ctf_map", {
description = "Run map related commands",
Expand Down
8 changes: 5 additions & 3 deletions mods/ctf/ctf_map/map_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ 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)
local pos1, pos2 = mapmeta.barrier_area.pos1, mapmeta.barrier_area.pos2

if not mapmeta.barriers then
minetest.log("action", "Clearing barriers using mapmeta.barrier_area")

local pos1, pos2 = mapmeta.barrier_area.pos1, mapmeta.barrier_area.pos2

local vm = VoxelManip(pos1, pos2)
local data = vm:get_data()

Expand Down Expand Up @@ -112,7 +114,7 @@ function ctf_map.remove_barrier(mapmeta, callback)
end

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

callback()
Expand Down
55 changes: 30 additions & 25 deletions mods/ctf/ctf_map/map_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,44 +156,43 @@ function ctf_map.load_map_meta(idx, dirname)
phys_gravity = tonumber(meta:get("phys_gravity")),
chests = minetest.deserialize(meta:get("chests")),
teams = minetest.deserialize(meta:get("teams")),
barrier_area = minetest.deserialize(meta:get("barrier_area")),
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 then
local f = assert(io.open(ctf_map.maps_dir .. dirname .. "/barriers.data", "rb"))
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")

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

f:close()
f:close()

assert(barriers and barriers ~= "")
assert(barriers and barriers ~= "")

barriers = minetest.deserialize(minetest.decompress(barriers, "deflate"))
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)
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])
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
end

map.barriers = barriers
else
if ctf_core.settings.server_mode ~= "mapedit" then
assert(false, "Map "..dirname.." has a corrupted barriers file. Re-save map to fix")
map.barriers = barriers
else
minetest.log("error", "Map "..dirname.." has a corrupted barriers file. Re-save map to fix")
end

minetest.log("error", "Map "..dirname.." has a corrupted barriers file. Re-save map to fix")
else
minetest.log("error", "Map "..dirname.." is missing its barriers file. Re-save map to fix")
end
else
map.barrier_area = minetest.deserialize(meta:get("barrier_area"))
end

for id, def in pairs(map.chests) do
Expand Down Expand Up @@ -287,6 +286,7 @@ function ctf_map.save_map(mapmeta)
pos2.y = pos1.y + BARRIER_Y_SIZE
end

local barrier_area = {pos1 = pos1:subtract(mapmeta.offset), pos2 = pos2:subtract(mapmeta.offset)}
local queue_break = false
while true do
local tmp = {
Expand All @@ -310,6 +310,10 @@ function ctf_map.save_map(mapmeta)

tmp.max = #data

local _
_, barrier_area.pos1 = vector.sort(barrier_area.pos1, tmp.pos1)
barrier_area.pos2 = vector.sort(barrier_area.pos2, tmp.pos2)

table.insert(barriers, tmp)

if queue_break then
Expand Down Expand Up @@ -344,6 +348,7 @@ function ctf_map.save_map(mapmeta)
meta:set("phys_gravity" , mapmeta.phys_gravity)
meta:set("chests" , minetest.serialize(mapmeta.chests))
meta:set("teams" , minetest.serialize(mapmeta.teams))
meta:set("barrier_area" , minetest.serialize(barrier_area))
meta:set("game_modes" , minetest.serialize(mapmeta.game_modes))
meta:set("enable_shadows", mapmeta.enable_shadows)

Expand All @@ -360,6 +365,6 @@ function ctf_map.save_map(mapmeta)
end

local f = assert(io.open(path .. "barriers.data", "wb"))
f:write(minetest.serialize(barriers))
f:write(minetest.compress(minetest.serialize(barriers), "deflate"))
f:close()
end
2 changes: 1 addition & 1 deletion mods/ctf/ctf_map/maps
Submodule maps updated 60 files
+ abandoned_battlefield/barriers.data
+14 −13 abandoned_battlefield/map.conf
+ ahkmenrah_pyramids/barriers.data
+14 −13 ahkmenrah_pyramids/map.conf
+ ancient_pyramids/barriers.data
+15 −14 ancient_pyramids/map.conf
+ appleton/barriers.data
+16 −15 appleton/map.conf
+ big_ocean/barriers.data
+14 −13 big_ocean/map.conf
+ bridge/barriers.data
+15 −14 bridge/map.conf
+ capture_legend/barriers.data
+4 −3 capture_legend/map.conf
+ caverns/barriers.data
+15 −14 caverns/map.conf
+ coast/barriers.data
+15 −14 coast/map.conf
+ desert_spikes/barriers.data
+16 −15 desert_spikes/map.conf
+ dragons_dance/barriers.data
+13 −12 dragons_dance/map.conf
+ ewok_village/barriers.data
+14 −13 ewok_village/map.conf
+ green_hills/barriers.data
+14 −13 green_hills/map.conf
+ iceage/barriers.data
+4 −3 iceage/map.conf
+ lost_mountains/barriers.data
+4 −3 lost_mountains/map.conf
+ mayan_legend/barriers.data
+4 −3 mayan_legend/map.conf
+ nether_kingdom/barriers.data
+4 −3 nether_kingdom/map.conf
+ pirates_hideout/barriers.data
+4 −3 pirates_hideout/map.conf
+ plain_battle/barriers.data
+4 −3 plain_battle/map.conf
+ plains/barriers.data
+4 −3 plains/map.conf
+ race_day/barriers.data
+4 −3 race_day/map.conf
+ river_valley/barriers.data
+4 −3 river_valley/map.conf
+ sams_mansion/barriers.data
+4 −3 sams_mansion/map.conf
+ savanna_ravine/barriers.data
+4 −3 savanna_ravine/map.conf
+ skies_of_land/barriers.data
+4 −3 skies_of_land/map.conf
+ snowland/barriers.data
+4 −3 snowland/map.conf
+ the_wall/barriers.data
+4 −3 the_wall/map.conf
+ tunnel/barriers.data
+4 −3 tunnel/map.conf
+ two_hills/barriers.data
+4 −3 two_hills/map.conf
+ water_academy/barriers.data
+4 −3 water_academy/map.conf
2 changes: 2 additions & 0 deletions mods/ctf/ctf_modebase/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ ctf_modebase = {

ctf_gui.old_init()

-- Can be added to by other mods, like irc
function ctf_modebase.announce(msg)
minetest.log("action", msg)
end

ctf_core.include_files(
Expand Down
62 changes: 40 additions & 22 deletions mods/ctf/ctf_modebase/markers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ local function add_marker(pname, pteam, message, pos, owner)
end
end

local function check_pointed_entity(pointed, message)
local concat
local obj = pointed.ref
local entity = obj:get_luaentity()
-- If object is a player, append player name to display text
-- Else if obj is item entity, append item description and count to str.
if obj:is_player() then
concat = obj:get_player_name()
elseif entity then
if entity.name == "__builtin:item" then
local stack = ItemStack(entity.itemstring)
local itemdef = minetest.registered_items[stack:get_name()]
-- Fallback to itemstring if description doesn't exist
-- Only use first line of itemstring
concat = string.match(itemdef.description or entity.itemstring, "^([^\n]+)")
concat = concat .. " " .. stack:get_count()
end
end
local pos = obj:get_pos()
if concat then
message = message .. " <" .. concat .. ">"
end
return message, pos
end

function ctf_modebase.markers.remove(pname, no_notify)
if markers[pname] then
markers[pname].timer:cancel()
Expand Down Expand Up @@ -182,34 +207,27 @@ local function marker_func(name, param, specific_player, hpmarker)
else
pos = player:get_pos()
end
if pointed then
if pointed.type == "object" then
message, pos = check_pointed_entity(pointed, message, pos)
end
end

-- If the player places a marker upon death, it will resort to the below
if player:get_hp() == 0 then
message = string.format("m <%s> died here", name)
if param ~= "Look here!" then message = string.format(
"m [%s]: %s", name, param
)
end
end
else
if not pointed then
return false, "Can't find anything to mark, too far away!"
end
message = string.format("m [%s]: %s", name, param)

if pointed.type == "object" then
local concat
local obj = pointed.ref
local entity = obj:get_luaentity()
-- If object is a player, append player name to display text
-- Else if obj is item entity, append item description and count to str.
if obj:is_player() then
concat = obj:get_player_name()
elseif entity then
if entity.name == "__builtin:item" then
local stack = ItemStack(entity.itemstring)
local itemdef = minetest.registered_items[stack:get_name()]
-- Fallback to itemstring if description doesn't exist
-- Only use first line of itemstring
concat = string.match(itemdef.description or entity.itemstring, "^([^\n]+)")
concat = concat .. " " .. stack:get_count()
end
end
pos = obj:get_pos()
if concat then
message = message .. " <" .. concat .. ">"
end
message, pos = check_pointed_entity(pointed, message)
else
pos = pointed.under
end
Expand Down
5 changes: 5 additions & 0 deletions mods/ctf/ctf_modebase/mode_vote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local new_mode
ctf_modebase.mode_vote = {}

local function player_vote(name, length)
if not voted then return end

if not voted[name] then
voters_count = voters_count - 1
end
Expand All @@ -32,6 +34,9 @@ local function show_modechoose_form(player)
minetest.after(0, function()
if not minetest.get_player_by_name(player) then return end

minetest.chat_send_player(player,
string.format("Voting for " .. new_mode .. ". Automatic vote: " .. vote_setting .. "\n" ..
"To change the automatic vote settings, go to the \"Settings\" tab of your inventory."))
player_vote(player, vote_setting)
end)

Expand Down
6 changes: 5 additions & 1 deletion mods/ctf/ctf_modebase/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ minetest.register_on_joinplayer(function(player)
player:set_hp(player:get_properties().hp_max)

local inv = player:get_inventory()
inv:set_list("main", {})

if ctf_core.settings.server_mode == "play" then
inv:set_list("main", {})
end

inv:set_list("craft", {})

inv:set_size("craft", 1)
Expand Down
3 changes: 2 additions & 1 deletion mods/ctf/ctf_teams/team_chest.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
local blacklist = {
"default:pine_needles",
".*leaves$",
"ctf_melee:sword_stone"
"ctf_melee:sword_stone",
"default:pick_stone",
}

local function get_chest_access(name)
Expand Down
4 changes: 4 additions & 0 deletions mods/other/random_messages/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ function random_messages.read_messages()
"Use /mp <player> to send a marker to a specific teammate",
"To check someone's league in all modes, use /league <player>",
"Use /leagues to list leagues and the placement needed to get to them.",
"To place an HP marker, run /mhp or left/right click while holding the zoom key (default: Z) "..
"and looking at your feet",
"Use /map to print the current map name and its author.",
"To check someone's ranking in all modes, use /rank mode:all <player_name>",
}
end

Expand Down
4 changes: 4 additions & 0 deletions settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ ctf_rankings_backend (Rankings Backend) enum default default,redis
# Port the redis server is hosted on.
# This setting is only used when ctf_rankings_backend = redis
ctf_rankings_redis_server_port (Rankings Redis Server Port) int 6379

# CTF can sometimes reduce CPU usage by calculating things once and putting them in RAM.
# Turn on low ram mode if you're getting crashes related to RAM/Memory usage
ctf_low_ram_mode (Low RAM mode) bool false

0 comments on commit ade8057

Please sign in to comment.