Skip to content

Commit

Permalink
Allow teams that aren't a part of the gameplay loop
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Feb 6, 2024
1 parent 04884d0 commit a7abaf6
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 230 deletions.
5 changes: 4 additions & 1 deletion docs/ctf-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ ctf_settings.register("my_setting", {

---
# mods/ctf/
TODO
TODO, below is a collection of quick notes for later

## ctf_teams
* https://modern.ircdocs.horse/formatting.html#colors-16-98

---
# mods/mtg/
Expand Down
48 changes: 25 additions & 23 deletions mods/ctf/ctf_map/ctf_traps.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,31 @@ minetest.register_node("ctf_map:spike", {
})

for _, team in ipairs(ctf_teams.teamlist) do
local spikecolor = ctf_teams.team[team].color

minetest.register_node("ctf_map:spike_"..team, {
description = HumanReadable(team).." Team Spike",
drawtype = "plantlike",
tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"},
inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150",
use_texture_alpha = "clip",
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
walkable = false,
damage_per_second = 7,
groups = {cracky=1, level=2},
drop = "ctf_map:spike",
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
return minetest.item_place(itemstack, placer, pointed_thing, 34)
end
})
if not ctf_teams.team[team].not_playing then
local spikecolor = ctf_teams.team[team].color

minetest.register_node("ctf_map:spike_"..team, {
description = HumanReadable(team).." Team Spike",
drawtype = "plantlike",
tiles = {"ctf_map_spike.png^[colorize:"..spikecolor..":150"},
inventory_image = "ctf_map_spike.png^[colorize:"..spikecolor..":150",
use_texture_alpha = "clip",
paramtype = "light",
paramtype2 = "meshoptions",
sunlight_propagates = true,
walkable = false,
damage_per_second = 7,
groups = {cracky=1, level=2},
drop = "ctf_map:spike",
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
return minetest.item_place(itemstack, placer, pointed_thing, 34)
end
})
end
end

minetest.register_on_player_hpchange(function(player, hp_change, reason)
Expand Down
6 changes: 4 additions & 2 deletions mods/ctf/ctf_map/map_functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ local function prepare_nodes(pos1, pos2, data, team_chest_items, blacklisted_nod
end

for _, team in ipairs(ctf_teams.teamlist) do
local node = "ctf_teams:chest_" .. team
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
if not ctf_teams.team[team].not_playing then
local node = "ctf_teams:chest_" .. team
nodes[minetest.get_content_id(node)] = minetest.registered_nodes[node]
end
end

for i, v in ipairs(data) do
Expand Down
3 changes: 2 additions & 1 deletion mods/ctf/ctf_modebase/build_timer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ local function timer_func(time_left)
end

local pteam = ctf_teams.get(player)
if pteam and not ctf_core.pos_inside(player:get_pos(), ctf_teams.get_team_territory(pteam)) then
local tpos1, tpos2 = ctf_teams.get_team_territory(pteam)
if pteam and tpos1 and not ctf_core.pos_inside(player:get_pos(), tpos1, tpos2) then
hud_events.new(player, {
quick = true,
text = "You can't cross the barrier until build time is over!",
Expand Down
24 changes: 16 additions & 8 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,22 @@ local function tp_player_near_flag(player)
local tname = ctf_teams.get(player)
if not tname then return end

local pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos,
math.random(-1, 1),
0.5,
math.random(-1, 1)
)
local rotation_y = vector.dir_to_rotation(
vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center)
).y
local rotation_y
local pos

if ctf_map.current_map.teams[tname] then
pos = vector.offset(ctf_map.current_map.teams[tname].flag_pos,
math.random(-1, 1),
0.5,
math.random(-1, 1)
)
rotation_y = vector.dir_to_rotation(
vector.direction(pos, ctf_map.current_map.teams[tname].look_pos or ctf_map.current_map.flag_center)
).y
else
pos = vector.add(ctf_map.current_map.pos1, vector.divide(ctf_map.current_map.size, 2))
rotation_y = player:get_look_horizontal()
end

local function apply()
player:set_pos(pos)
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_teams/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ end
--- Example usage: `pos1, pos2 = ctf_teams.get_team_territory("red")`
function ctf_teams.get_team_territory(teamname)
local current_map = ctf_map.current_map
if not current_map then return false end
if not current_map or not current_map.teams[teamname] then return false end

return current_map.teams[teamname].pos1, current_map.teams[teamname].pos2
end
Expand Down
8 changes: 8 additions & 0 deletions mods/ctf/ctf_teams/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
ctf_teams = {
team = {
--[[
tname = {
color = "#ffffff",
color_hex = 0x000, -- Generated from 'color' above
irc_color = 16, -- optional, default: 16
not_playing = false, --optional, default: false
}
]]
red = {
color = "#dc0f0f",
color_hex = 0x000,
Expand Down
Loading

0 comments on commit a7abaf6

Please sign in to comment.