Skip to content

Commit

Permalink
Merge branch 'MT-CTF:master' into ctf-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
a-blob authored Sep 20, 2023
2 parents 5abedf6 + ae38980 commit a0ab547
Show file tree
Hide file tree
Showing 21 changed files with 319 additions and 164 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
38 changes: 19 additions & 19 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)
end
end
end

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)

minetest.register_chatcommand("ctf_map", {
description = "Run map related commands",
Expand Down Expand Up @@ -121,19 +121,19 @@ minetest.register_chatcommand("ctf_map", {
})

minetest.register_chatcommand("map", {
description = "Prints the current map name and map author",
func = function()
local map = ctf_map.current_map
description = "Prints the current map name and map author",
func = function()
local map = ctf_map.current_map

if not map then
return false, "There is no map currently in play"
end
if not map then
return false, "There is no map currently in play"
end

local mapName = map.name or "Unknown"
local mapAuthor = map.author or "Unknown Author"
local mapName = map.name or "Unknown"
local mapAuthor = map.author or "Unknown Author"

return true, string.format("The current map is %s by %s.", mapName, mapAuthor)
end
return true, string.format("The current map is %s by %s.", mapName, mapAuthor)
end
})

-- Attempt to restore user's time speed after server close
Expand Down
128 changes: 60 additions & 68 deletions mods/ctf/ctf_map/map_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,88 +54,80 @@ end
--- VOXELMANIP FUNCTIONS
--

-- Takes [mapmeta] or [pos1, pos2] arguments
function ctf_map.remove_barrier(mapmeta, pos2, callback)
local pos1 = mapmeta
local ID_IGNORE = minetest.CONTENT_IGNORE
local ID_AIR = minetest.CONTENT_AIR
local ID_WATER = minetest.get_content_id("default:water_source")

if type(pos2) == "function" then
callback = pos2
pos2 = nil
end
---@param mapmeta table Map meta table
---@param callback function
function ctf_map.remove_barrier(mapmeta, callback)
if not mapmeta.barriers then
minetest.log("action", "Clearing barriers using mapmeta.barrier_area")

if not pos2 then
pos1, pos2 = mapmeta.barrier_area.pos1, mapmeta.barrier_area.pos2
end
local pos1, pos2 = mapmeta.barrier_area.pos1, mapmeta.barrier_area.pos2

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

local data = vm:get_data()
for i, id in pairs(data) do
local done = false

-- Shave off ~0.1 seconds from the main loop
minetest.handle_async(function(d, p1, p2, barrier_nodes, t)
local mod = {} -- All its contents will be recreated in the loop
local Nx = p2.x - p1.x + 1
local Ny = p2.y - p1.y + 1
local ID_IGNORE = minetest.CONTENT_IGNORE
local ID_AIR = minetest.CONTENT_AIR
local ID_WATER = minetest.get_content_id("default:water_source")

for z = p1.z, p2.z do
for y = p1.y, p2.y do
for x = p1.x, p2.x do
local vi = (z - p1.z) * Ny * Nx + (y - p1.y) * Nx + (x - p1.x) + 1
local done = false

for barriernode_id, replacement_id in pairs(barrier_nodes) do
if d[vi] == barriernode_id then
local replacement_this = replacement_id
if replacement_id == ID_AIR then -- water flow check (for whatever reason vm:update_liquids() failed to work)
local check_pos = {
((z + 1) - p1.z) * Ny * Nx + (y - p1.y) * Nx + (x - p1.x) + 1,
((z - 1) - p1.z) * Ny * Nx + (y - p1.y) * Nx + (x - p1.x) + 1,
(z - p1.z) * Ny * Nx + (y - p1.y) * Nx + ((x + 1) - p1.x) + 1,
(z - p1.z) * Ny * Nx + (y - p1.y) * Nx + ((x - 1) - p1.x) + 1,
}
local water_count = 0
for _,check_vi in ipairs(check_pos) do
if d[check_vi] == ID_WATER then
water_count = water_count + 1
if water_count >= 2 then
replacement_this = ID_WATER
break
end
end
end
end
mod[vi] = replacement_this
done = true
break
end
end
for barriernode_id, replacement_id in pairs(ctf_map.barrier_nodes) do
if id == barriernode_id then

-- Avoid changing nodes players placed during async
if not done then
mod[vi] = ID_IGNORE
end
data[i] = replacement_id
done = true
break
end
end

if not done then
data[i] = ID_IGNORE
end
end

return mod
end, function(d)
vm:set_data(d)
vm:update_liquids()
vm:set_data(data)
vm:write_to_map(false)
callback()
end, data, pos1, pos2, ctf_map.barrier_nodes)

minetest.after(0.1, function()
local vm2 = VoxelManip(pos1, pos2)
vm2:update_liquids()
end)
else
local i = 0
for _, barrier_area in pairs(mapmeta.barriers) 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)
for idx in pairs(data) do
data[idx] = barrier_area.reps[idx] or ID_IGNORE
end

vm:set_data(data)
vm:write_to_map(false)
end)

i = i + 0.04
end

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

callback()
end)

return
end

callback()
end

local ID_AIR = minetest.CONTENT_AIR
local ID_IGNORE = minetest.CONTENT_IGNORE
local ID_CHEST = minetest.get_content_id("ctf_map:chest")
local ID_WATER = minetest.get_content_id("default:water_source")

local ID_CHEST = minetest.get_content_id("ctf_map:chest")
local function get_place_positions(a, data, pos1, pos2)
if a.amount <= 0 then return {} end

Expand Down
Loading

0 comments on commit a0ab547

Please sign in to comment.