Skip to content

Commit 020534b

Browse files
authored
Merge branch 'master' into patch-6
2 parents 84af8ec + 18d0b00 commit 020534b

File tree

21 files changed

+366
-277
lines changed

21 files changed

+366
-277
lines changed

docs/ctf-api.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ ctf_settings.register("my_setting", {
3939

4040
---
4141
# mods/ctf/
42-
TODO
42+
TODO, below is a collection of quick notes for later
43+
44+
## ctf_teams
45+
* https://modern.ircdocs.horse/formatting.html#colors-16-98
4346

4447
---
4548
# mods/mtg/

mods/apis/ctf_gui/dev.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local unset_function = "[f]\nreturn "
1+
local unset_function = "return "
22

33
function ctf_gui.show_formspec_dev(player, formname, formspec, formcontext)
44
local filepath = minetest.get_worldpath().."/ctf_gui/"
@@ -20,8 +20,8 @@ function ctf_gui.show_formspec_dev(player, formname, formspec, formcontext)
2020
local function interval()
2121
if type(formspec) == "function" then
2222
ctf_gui.show_formspec(player, formname, formspec(formcontext))
23-
elseif formspec:sub(1, 3) == "[f]" then
24-
local result, form = pcall((loadstring(formspec:sub(4)) or function() return function() end end)(), formcontext)
23+
elseif formspec:match("^%s*return") then
24+
local result, form = pcall((loadstring(formspec) or function() return function() end end)(), formcontext)
2525

2626
ctf_gui.show_formspec(player, formname,
2727
result and form or "size[10,10]hypertext[0,0;10,10;err;"..minetest.formspec_escape(form or "").."]"

mods/apis/ctf_settings/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function ctf_settings.get(player, setting)
4040
local value = player:get_meta():get_string("ctf_settings:"..setting)
4141
local info = ctf_settings.settings[setting]
4242

43-
return value == "" and info.default or value
43+
return value == "" and (info and info.default) or value
4444
end
4545

4646
-- This Function MIT by Rubenwardy

mods/ctf/ctf_combat/ctf_ranged/init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ local function process_ray(ray, user, look_dir, def)
7777
end
7878
end
7979
elseif hitpoint.type == "object" then
80-
hitpoint.ref:punch(user, 1, {
81-
full_punch_interval = 1,
80+
hitpoint.ref:punch(user, def.fire_interval or 0.1, {
81+
full_punch_interval = def.fire_interval or 0.1,
8282
damage_groups = {ranged = 1, [def.type] = 1, fleshy = def.damage}
8383
}, look_dir)
8484
end

mods/ctf/ctf_map/ctf_traps.lua

+26-24
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,31 @@ minetest.register_node("ctf_map:spike", {
6868
})
6969

7070
for _, team in ipairs(ctf_teams.teamlist) do
71-
local spikecolor = ctf_teams.team[team].color
72-
73-
minetest.register_node("ctf_map:spike_"..team, {
74-
description = HumanReadable(team).." Team Spike",
75-
drawtype = "plantlike",
76-
tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"},
77-
inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150",
78-
use_texture_alpha = "clip",
79-
paramtype = "light",
80-
paramtype2 = "meshoptions",
81-
sunlight_propagates = true,
82-
walkable = false,
83-
damage_per_second = 7,
84-
groups = {cracky=1, level=2},
85-
drop = "ctf_map:spike",
86-
selection_box = {
87-
type = "fixed",
88-
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
89-
},
90-
on_place = function(itemstack, placer, pointed_thing)
91-
return minetest.item_place(itemstack, placer, pointed_thing, 34)
92-
end
93-
})
71+
if not ctf_teams.team[team].not_playing then
72+
local spikecolor = ctf_teams.team[team].color
73+
74+
minetest.register_node("ctf_map:spike_"..team, {
75+
description = HumanReadable(team).." Team Spike",
76+
drawtype = "plantlike",
77+
tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"},
78+
inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150",
79+
use_texture_alpha = "clip",
80+
paramtype = "light",
81+
paramtype2 = "meshoptions",
82+
sunlight_propagates = true,
83+
walkable = false,
84+
damage_per_second = 7,
85+
groups = {cracky=1, level=2},
86+
drop = "ctf_map:spike",
87+
selection_box = {
88+
type = "fixed",
89+
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
90+
},
91+
on_place = function(itemstack, placer, pointed_thing)
92+
return minetest.item_place(itemstack, placer, pointed_thing, 34)
93+
end
94+
})
95+
end
9496
end
9597

9698
minetest.register_on_player_hpchange(function(player, hp_change, reason)
@@ -129,7 +131,7 @@ local function damage_cobble_dig(pos, node, digger)
129131
local placerobj = minetest.get_player_by_name(placer_name)
130132

131133
if placerobj then
132-
digger:punch(placerobj, 10, {
134+
digger:punch(placerobj, 1, {
133135
damage_groups = {
134136
fleshy = 7,
135137
damage_cobble = 1,

mods/ctf/ctf_map/map_functions.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,10 @@ local function prepare_nodes(pos1, pos2, data, team_chest_items, blacklisted_nod
213213
end
214214

215215
for _, team in ipairs(ctf_teams.teamlist) do
216-
local node = "ctf_teams:chest_" .. team
217-
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
216+
if not ctf_teams.team[team].not_playing then
217+
local node = "ctf_teams:chest_" .. team
218+
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
219+
end
218220
end
219221

220222
for i, v in ipairs(data) do

mods/ctf/ctf_modebase/build_timer.lua

+9-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ local function timer_func(time_left)
2929
end
3030

3131
local pteam = ctf_teams.get(player)
32-
if pteam and not ctf_core.pos_inside(player:get_pos(), ctf_teams.get_team_territory(pteam)) then
32+
local tpos1, tpos2 = ctf_teams.get_team_territory(pteam)
33+
if pteam and tpos1 and not ctf_core.pos_inside(player:get_pos(), tpos1, tpos2) then
3334
hud_events.new(player, {
3435
quick = true,
3536
text = "You can't cross the barrier until build time is over!",
@@ -47,6 +48,13 @@ local function timer_func(time_left)
4748
timer = minetest.after(1, timer_func, time_left - 1)
4849
end
4950

51+
function ctf_modebase.build_timer.start(build_time)
52+
local time = build_time or ctf_modebase:get_current_mode().build_timer or DEFAULT_BUILD_TIME
53+
54+
if time > 0 then
55+
timer = timer_func(time)
56+
end
57+
end
5058

5159
function ctf_modebase.build_timer.finish()
5260
if timer == nil then return end
@@ -76,10 +84,6 @@ function ctf_modebase.build_timer.finish()
7684
end
7785
end
7886

79-
ctf_api.register_on_new_match(function()
80-
timer = minetest.after(1, timer_func, ctf_modebase:get_current_mode().build_timer or DEFAULT_BUILD_TIME)
81-
end)
82-
8387
ctf_api.register_on_match_end(function()
8488
if timer == nil then return end
8589
timer:cancel()
@@ -119,4 +123,3 @@ minetest.register_chatcommand("ctf_start", {
119123
return true, "Build time ended"
120124
end,
121125
})
122-

mods/ctf/ctf_modebase/features.lua

+30-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ctf_core.testing = {
2222
end
2323
}
2424

25-
local hud = mhud.init()
25+
local mapload_huds = mhud.init()
2626
local LOADING_SCREEN_TARGET_TIME = 7
2727
local loading_screen_time
2828

@@ -121,25 +121,27 @@ local old_announce = ctf_modebase.map_chosen
121121
function ctf_modebase.map_chosen(map, ...)
122122
set_playertags_state(PLAYERTAGS_OFF)
123123

124+
mapload_huds:clear_all()
125+
124126
for _, p in pairs(minetest.get_connected_players()) do
125127
if ctf_teams.get(p) then
126-
hud:add(p, "loading_screen", {
128+
mapload_huds:add(p, "loading_screen", {
127129
hud_elem_type = "image",
128130
position = {x = 0.5, y = 0.5},
129131
image_scale = -100,
130132
z_index = 1000,
131133
texture = "[combine:1x1^[invert:rgba^[opacity:1^[colorize:#141523:255"
132134
})
133135

134-
hud:add(p, "map_image", {
136+
mapload_huds:add(p, "map_image", {
135137
hud_elem_type = "image",
136138
position = {x = 0.5, y = 0.5},
137139
image_scale = -100,
138140
z_index = 1001,
139141
texture = map.dirname.."_screenshot.png^[opacity:30",
140142
})
141143

142-
hud:add(p, "loading_text", {
144+
mapload_huds:add(p, "loading_text", {
143145
hud_elem_type = "text",
144146
position = {x = 0.5, y = 0.5},
145147
alignment = {x = "center", y = "up"},
@@ -148,7 +150,7 @@ function ctf_modebase.map_chosen(map, ...)
148150
color = 0x7ec5ff,
149151
z_index = 1002,
150152
})
151-
hud:add(p, {
153+
mapload_huds:add(p, {
152154
hud_elem_type = "text",
153155
position = {x = 0.5, y = 0.75},
154156
alignment = {x = "center", y = "center"},
@@ -252,14 +254,22 @@ local function tp_player_near_flag(player)
252254
local tname = ctf_teams.get(player)
253255
if not tname then return end
254256

255-
local pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos,
256-
math.random(-1, 1),
257-
0.5,
258-
math.random(-1, 1)
259-
)
260-
local rotation_y = vector.dir_to_rotation(
261-
vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center)
262-
).y
257+
local rotation_y
258+
local pos
259+
260+
if ctf_map.current_map.teams[tname] then
261+
pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos,
262+
math.random(-1, 1),
263+
0.5,
264+
math.random(-1, 1)
265+
)
266+
rotation_y = vector.dir_to_rotation(
267+
vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center)
268+
).y
269+
else
270+
pos = vector.add(ctf_map.current_map.pos1, vector.divide(ctf_map.current_map.size, 2))
271+
rotation_y = player:get_look_horizontal()
272+
end
263273

264274
local function apply()
265275
player:set_pos(pos)
@@ -424,6 +434,8 @@ local delete_queue = {}
424434
local team_switch_after_capture = false
425435

426436
return {
437+
tp_player_near_flag = tp_player_near_flag,
438+
427439
on_new_match = function()
428440
team_list = {}
429441
for tname in pairs(ctf_map.current_map.teams) do
@@ -467,8 +479,10 @@ return {
467479
local total_time = (minetest.get_us_time() - loading_screen_time) / 1e6
468480

469481
minetest.after(math.max(0, LOADING_SCREEN_TARGET_TIME - total_time), function()
470-
hud:clear_all()
482+
mapload_huds:clear_all()
471483
set_playertags_state(PLAYERTAGS_ON)
484+
485+
ctf_modebase.build_timer.start()
472486
end)
473487
end
474488
end,
@@ -480,6 +494,8 @@ return {
480494
delete_queue = {ctf_map.current_map.pos1, ctf_map.current_map.pos2}
481495
end
482496
end,
497+
-- If you set this in a mode def it will replace the call to ctf_teams.allocate_teams() in match.lua
498+
-- allocate_teams = function()
483499
team_allocator = function(player)
484500
player = PlayerName(player)
485501

mods/ctf/ctf_modebase/init.lua

+11-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ ctf_modebase = {
22
-- Table containing all registered modes and their definitions
33
modes = {}, ---@type table
44

5-
-- Same as ctf_modebase.modes but in list form
5+
-- Same as ctf_modebase.modes but in list form.
6+
-- Exception: Disabled modes that show up in ctf_modebase.modes won't show up in the modelist
67
modelist = {}, ---@type list
78

89
-- Name of the mode currently being played. On server start this will be false
@@ -104,13 +105,15 @@ minetest.register_on_mods_loaded(function()
104105
end
105106

106107
for _, name in pairs(ctf_modebase.modelist) do
107-
ctf_settings.register("ctf_modebase:default_vote_"..name, {
108-
type = "list",
109-
description = "Match count vote for the mode '"..HumanReadable(name).."'",
110-
list = {HumanReadable(name).." - Ask", "0", "1", "2", "3", "4", "5"},
111-
_list_map = {"ask", 0, 1, 2, 3, 4, 5},
112-
default = "1", -- "Ask"
113-
})
108+
if not ctf_modebase.modes[name].rounds then
109+
ctf_settings.register("ctf_modebase:default_vote_"..name, {
110+
type = "list",
111+
description = "Match count vote for the mode '"..HumanReadable(name).."'",
112+
list = {HumanReadable(name).." - Ask", "0", "1", "2", "3", "4", "5"},
113+
_list_map = {"ask", 0, 1, 2, 3, 4, 5},
114+
default = "1", -- "Ask"
115+
})
116+
end
114117
end
115118
end)
116119

mods/ctf/ctf_modebase/map_catalog.lua

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ function ctf_modebase.map_catalog.select_map(filter)
4242
end
4343

4444
local selected = maps[math.random(1, #maps)]
45+
46+
if not selected then
47+
selected = ctf_modebase.map_catalog.map_dirnames["plains"]
48+
end
49+
4550
ctf_modebase.map_catalog.current_map = maps_pool[selected]
4651

4752
if map_repeat_interval > 0 then

mods/ctf/ctf_modebase/match.lua

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ function ctf_modebase.start_match_after_vote()
4444
ctf_modebase.on_new_match()
4545

4646
ctf_modebase.in_game = true
47-
ctf_teams.allocate_teams(ctf_map.current_map.teams)
47+
local team_alloc = ctf_modebase:get_current_mode().allocate_teams
48+
49+
if team_alloc then
50+
team_alloc(ctf_map.current_map.teams)
51+
else
52+
ctf_teams.allocate_teams(ctf_map.current_map.teams)
53+
end
4854

4955
ctf_modebase.current_mode_matches_played = ctf_modebase.current_mode_matches_played + 1
5056

mods/ctf/ctf_modebase/mode_vote.lua

+22-11
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ local function player_vote(name, length)
2626
end
2727

2828
local function show_modechoose_form(player)
29-
local vote_setting = ctf_settings.get(minetest.get_player_by_name(player), "ctf_modebase:default_vote_"..new_mode)
29+
local vote_setting = "ask"
3030

31-
vote_setting = ctf_settings.settings["ctf_modebase:default_vote_"..new_mode]._list_map[tonumber(vote_setting)]
31+
if ctf_settings.settings["ctf_modebase:default_vote_"..new_mode] then
32+
vote_setting = ctf_settings.get(minetest.get_player_by_name(player), "ctf_modebase:default_vote_"..new_mode)
33+
34+
vote_setting = ctf_settings.settings["ctf_modebase:default_vote_"..new_mode]._list_map[tonumber(vote_setting)]
35+
end
3236

3337
if vote_setting ~= "ask" then
3438
minetest.after(0, function()
@@ -109,19 +113,26 @@ function ctf_modebase.mode_vote.start_vote()
109113
new_mode = ctf_modebase.modelist[mode_index + 1]
110114
end
111115

112-
for _, player in pairs(minetest.get_connected_players()) do
113-
if ctf_teams.get(player) ~= nil or not ctf_modebase.current_mode then
114-
local pname = player:get_player_name()
116+
local mode_defined_rounds = ctf_modebase.modes[new_mode].rounds
117+
if not mode_defined_rounds then
118+
for _, player in pairs(minetest.get_connected_players()) do
119+
if ctf_teams.get(player) ~= nil or not ctf_modebase.current_mode then
120+
local pname = player:get_player_name()
115121

116-
show_modechoose_form(pname)
122+
show_modechoose_form(pname)
117123

118-
voted[pname] = false
119-
voters_count = voters_count + 1
124+
voted[pname] = false
125+
voters_count = voters_count + 1
126+
end
120127
end
121-
end
122128

123-
timer = minetest.after(VOTING_TIME, ctf_modebase.mode_vote.end_vote)
124-
formspec_send_timer = minetest.after(2, send_formspec)
129+
timer = minetest.after(VOTING_TIME, ctf_modebase.mode_vote.end_vote)
130+
formspec_send_timer = minetest.after(2, send_formspec)
131+
else
132+
ctf_modebase.current_mode_matches = mode_defined_rounds
133+
ctf_modebase.mode_on_next_match = new_mode
134+
ctf_modebase.start_match_after_vote()
135+
end
125136
end
126137

127138
function ctf_modebase.mode_vote.end_vote()

0 commit comments

Comments
 (0)