Skip to content

Commit 049266a

Browse files
authored
Merge branch 'master' into streak
2 parents bb0411f + a08c3cd commit 049266a

File tree

21 files changed

+387
-290
lines changed

21 files changed

+387
-290
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

+48-28
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

@@ -671,15 +687,7 @@ return {
671687

672688
celebrate_team(pteam)
673689

674-
local text = " has captured the flag"
675-
if many_teams then
676-
text = " has captured the flag of team(s) " .. HumanReadable(teamnames)
677-
minetest.chat_send_all(
678-
minetest.colorize(tcolor, pname) ..
679-
minetest.colorize(FLAG_MESSAGE_COLOR, text)
680-
)
681-
end
682-
ctf_modebase.announce(string.format("Player %s (team %s)%s", pname, pteam, text))
690+
683691

684692
ctf_modebase.flag_huds.untrack_capturer(pname)
685693

@@ -690,7 +698,19 @@ return {
690698
score = math.max(75, math.min(500, score))
691699
capture_reward = capture_reward + score
692700
end
693-
701+
local text = " has captured the flag"
702+
if many_teams then
703+
text = string.format(
704+
" has captured the flag of team(s) %s and got %d points",
705+
HumanReadable(teamnames),
706+
capture_reward
707+
)
708+
minetest.chat_send_all(
709+
minetest.colorize(tcolor, pname) ..
710+
minetest.colorize(FLAG_MESSAGE_COLOR, text)
711+
)
712+
end
713+
ctf_modebase.announce(string.format("Player %s (team %s)%s and got %d points", pname, pteam, text, capture_reward))
694714
local team_score = team_scores[pteam].score
695715
for teammate in pairs(ctf_teams.online_players[pteam].players) do
696716
if teammate ~= pname then
@@ -705,12 +725,12 @@ return {
705725
teams_left = teams_left - #teamnames
706726

707727
if teams_left <= 1 then
708-
local capture_text = "Player %s captured"
728+
local capture_text = "Player %s captured and got %d points"
709729
if many_teams then
710-
capture_text = "Player %s captured the last flag"
730+
capture_text = "Player %s captured the last flag and got %d points"
711731
end
712732

713-
ctf_modebase.summary.set_winner(string.format(capture_text, minetest.colorize(tcolor, pname)))
733+
ctf_modebase.summary.set_winner(string.format(capture_text, minetest.colorize(tcolor, pname), capture_reward))
714734

715735
local win_text = HumanReadable(pteam) .. " Team Wins!"
716736

@@ -730,7 +750,7 @@ return {
730750

731751
for lost_player in pairs(ctf_teams.online_players[lost_team].players) do
732752
team_switch_after_capture = true
733-
ctf_teams.allocate_player(lost_player)
753+
ctf_teams.allocate_player(lost_player)
734754
team_switch_after_capture = false
735755
end
736756
end

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
@@ -108,13 +109,15 @@ minetest.register_on_mods_loaded(function()
108109
end
109110

110111
for _, name in pairs(ctf_modebase.modelist) do
111-
ctf_settings.register("ctf_modebase:default_vote_"..name, {
112-
type = "list",
113-
description = "Match count vote for the mode '"..HumanReadable(name).."'",
114-
list = {HumanReadable(name).." - Ask", "0", "1", "2", "3", "4", "5"},
115-
_list_map = {"ask", 0, 1, 2, 3, 4, 5},
116-
default = "1", -- "Ask"
117-
})
112+
if not ctf_modebase.modes[name].rounds then
113+
ctf_settings.register("ctf_modebase:default_vote_"..name, {
114+
type = "list",
115+
description = "Match count vote for the mode '"..HumanReadable(name).."'",
116+
list = {HumanReadable(name).." - Ask", "0", "1", "2", "3", "4", "5"},
117+
_list_map = {"ask", 0, 1, 2, 3, 4, 5},
118+
default = "1", -- "Ask"
119+
})
120+
end
118121
end
119122
end)
120123

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

0 commit comments

Comments
 (0)