Skip to content

Commit a7abaf6

Browse files
committed
Allow teams that aren't a part of the gameplay loop
1 parent 04884d0 commit a7abaf6

File tree

8 files changed

+261
-230
lines changed

8 files changed

+261
-230
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/ctf/ctf_map/ctf_traps.lua

+25-23
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)

mods/ctf/ctf_map/map_functions.lua

+4-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ local function prepare_nodes(pos1, pos2, data, team_chest_items, blacklisted_nod
193193
end
194194

195195
for _, team in ipairs(ctf_teams.teamlist) do
196-
local node = "ctf_teams:chest_" .. team
197-
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
196+
if not ctf_teams.team[team].not_playing then
197+
local node = "ctf_teams:chest_" .. team
198+
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
199+
end
198200
end
199201

200202
for i, v in ipairs(data) do

mods/ctf/ctf_modebase/build_timer.lua

+2-1
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!",

mods/ctf/ctf_modebase/features.lua

+16-8
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,22 @@ local function tp_player_near_flag(player)
247247
local tname = ctf_teams.get(player)
248248
if not tname then return end
249249

250-
local pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos,
251-
math.random(-1, 1),
252-
0.5,
253-
math.random(-1, 1)
254-
)
255-
local rotation_y = vector.dir_to_rotation(
256-
vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center)
257-
).y
250+
local rotation_y
251+
local pos
252+
253+
if ctf_map.current_map.teams[tname] then
254+
pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos,
255+
math.random(-1, 1),
256+
0.5,
257+
math.random(-1, 1)
258+
)
259+
rotation_y = vector.dir_to_rotation(
260+
vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center)
261+
).y
262+
else
263+
pos = vector.add(ctf_map.current_map.pos1, vector.divide(ctf_map.current_map.size, 2))
264+
rotation_y = player:get_look_horizontal()
265+
end
258266

259267
local function apply()
260268
player:set_pos(pos)

mods/ctf/ctf_teams/functions.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ end
118118
--- Example usage: `pos1, pos2 = ctf_teams.get_team_territory("red")`
119119
function ctf_teams.get_team_territory(teamname)
120120
local current_map = ctf_map.current_map
121-
if not current_map then return false end
121+
if not current_map or not current_map.teams[teamname] then return false end
122122

123123
return current_map.teams[teamname].pos1, current_map.teams[teamname].pos2
124124
end

mods/ctf/ctf_teams/init.lua

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
ctf_teams = {
22
team = {
3+
--[[
4+
tname = {
5+
color = "#ffffff",
6+
color_hex = 0x000, -- Generated from 'color' above
7+
irc_color = 16, -- optional, default: 16
8+
not_playing = false, --optional, default: false
9+
}
10+
]]
311
red = {
412
color = "#dc0f0f",
513
color_hex = 0x000,

0 commit comments

Comments
 (0)