Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Landmines #1001

Merged
merged 35 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
446e7d2
Add landmine
xenonca Apr 24, 2022
a5d4a20
Add landmine texture
xenonca Apr 24, 2022
02576ab
Update ctf_traps.lua
xenonca Apr 24, 2022
3c23a62
Add landmine recipe
xenonca Apr 25, 2022
cfbfd56
enable landmine classes
xenonca Apr 25, 2022
630c2b6
Enable landmine nadefight
xenonca Apr 25, 2022
139549d
Edit landmine classes
xenonca Apr 25, 2022
6321a17
Update dependencies
xenonca Apr 27, 2022
41f0329
reduce min_y level
xenonca Apr 27, 2022
5eee6fc
Merge branch 'MT-CTF:master' into landmines
xenonca Jul 20, 2022
97bd61b
Update ctf_traps.lua
xenonca Jul 20, 2022
5921b74
Add landmine damage_group texture
xenonca Jul 20, 2022
eea2060
Update ctf_traps.lua
xenonca Aug 8, 2022
f173691
Merge branch 'master' into landmines
xenonca Aug 13, 2022
5e7484c
Merge branch 'master' into landmines
xenonca Oct 10, 2022
096bebb
Fix trigger team detection
xenonca Oct 10, 2022
f28c461
Merge branch 'MT-CTF:master' into landmines
xenonca Feb 25, 2023
a10e502
Save placer team
xenonca Feb 25, 2023
d9c1486
Merge branch 'master' into landmines
farooqkz Jun 11, 2024
861554f
complete landmines
farooqkz Jun 11, 2024
bd87b34
make landmines working fine
farooqkz Jun 11, 2024
cace35f
optimize texture image of landmine
farooqkz Jun 11, 2024
b58fd08
wrong comma
farooqkz Jun 11, 2024
ae4e29e
final corrections
farooqkz Jun 11, 2024
e14a37a
fix some small correction
farooqkz Jun 11, 2024
1146608
clear landmines table on new match
farooqkz Jun 11, 2024
a5e42f1
make luacheck happy
farooqkz Jun 11, 2024
490fc84
refactor the code, iterate over players positions instead of landmines
farooqkz Dec 1, 2024
2292af7
make luacheck happy
farooqkz Dec 1, 2024
4c93cc8
correct maps submodule commit
farooqkz Dec 2, 2024
3cc8fc7
fix errors
farooqkz Dec 2, 2024
1abf184
fixed kill log texture error
farooqkz Dec 2, 2024
07cefa9
Merge branch 'master' into landmines
farooqkz Dec 2, 2024
b8390fc
Update crafting.lua
LoneWolfHT Dec 2, 2024
6fc0bd5
Merge branch 'master' into landmines
LoneWolfHT Dec 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions mods/ctf/ctf_landmine/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
local landmines = {
-- core.hash_node_position(pos) -> true/false
-- like landmines[core.hash_node_position(pos)] = true
}

local number_of_landmines = 0

local add_landmine = function(pos)
landmines[core.hash_node_position(pos)] = true
number_of_landmines = number_of_landmines + 1
end

local clear_landmines = function()
landmines = {}
number_of_landmines = 0
end

local remove_landmine = function(pos)
landmines[core.hash_node_position(pos)] = false
number_of_landmines = number_of_landmines - 1
end

local landmine_globalstep_counter = 0.0
local LANDMINE_COUNTER_THRESHOLD = 0.025

local function is_self_landmine(object_ref, pos)
local meta = core.get_meta(pos)
local team = meta:get_string("pteam")
local placer = meta:get_string("placer")
local pname = object_ref:get_player_name()
if pname == "" then
return nil -- the object ref is not a player
end
if pname == placer then
return true -- it's self landmine
end
if ctf_teams.get(object_ref) == team then
return true -- it's self landmine
end

return false -- it's someone else's landmine
end

local function landmine_explode(pos)
local near_objs = core.get_objects_inside_radius(pos, 3)
local meta = core.get_meta(pos)
local placer = meta:get_string("placer")
local placerobj = placer and core.get_player_by_name(placer)

core.add_particlespawner({
amount = 20,
time = 0.5,
minpos = vector.subtract(pos, 3),
maxpos = vector.add(pos, 3),
minvel = {x = 0, y = 5, z = 0},
maxvel = {x = 0, y = 7, z = 0},
minacc = {x = 0, y = 1, z = 0},
maxacc = {x = 0, y = 1, z = 0},
minexptime = 0.3,
maxexptime = 0.6,
minsize = 7,
maxsize = 10,
collisiondetection = true,
collision_removal = false,
vertical = false,
texture = "grenades_smoke.png",
})

core.add_particle({
pos = pos,
velocity = {x=0, y=0, z=0},
acceleration = {x=0, y=0, z=0},
expirationtime = 0.3,
size = 15,
collisiondetection = false,
collision_removal = false,
object_collision = false,
vertical = false,
texture = "grenades_boom.png",
glow = 10
})

core.sound_play("grenades_explode", {
pos = pos,
gain = 1.0,
max_hear_distance = 64,
})

for _, obj in pairs(near_objs) do
if is_self_landmine(obj, pos) == false then
if placerobj then
obj:punch(
placerobj,
1,
{
damage_groups = {
fleshy = 15,
landmine = 1
}
}
)
else
local chp = obj:get_hp()
obj:set_hp(chp - 15)
end
end
end
core.remove_node(pos)
remove_landmine(pos)
end

core.register_node("ctf_landmine:landmine", {
description = "Landmine",
drawtype = "nodebox",
tiles = {
"ctf_landmine_landmine.png",
"ctf_landmine_landmine.png^[transformFY"
},
inventory_image = "ctf_landmine_landmine.png",
paramtype = "light",
sunlight_propagates = true,
walkable = true,
groups = {cracky=1, level=2},
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -0.4, 0.5},
},
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = core.get_meta(pos)
local name = placer:get_player_name()
local pteam = ctf_teams.get(placer)

meta:set_string("placer", name)
meta:set_string("pteam", pteam)
add_landmine(pos)
end,
on_punch = function(pos, _node, puncher, pointed_thing)
if not is_self_landmine(puncher, pos) then
landmine_explode(pos)
end
end
})




core.register_globalstep(function(dtime)
landmine_globalstep_counter = landmine_globalstep_counter + dtime
if landmine_globalstep_counter < LANDMINE_COUNTER_THRESHOLD then
return
end
landmine_globalstep_counter = 0.0
if number_of_landmines == 0 then
return
end
local start_time = core.get_gametime()
local players_n = #core.get_connected_players()
local landmines_n = number_of_landmines
for _idx, obj in ipairs(core.get_connected_players()) do
local pos = {
x = math.ceil(obj:get_pos().x),
y = math.ceil(obj:get_pos().y),
z = math.ceil(obj:get_pos().z)
}
local positions_to_check = {
pos,
vector.add(pos, { x = 0, y = 0, z = 1}),
vector.add(pos, { x = 1, y = 0, z = 0}),
vector.add(pos, { x = 0, y = 0, z = -1}),
vector.add(pos, { x = -1, y = 0, z = 0}),
vector.add(pos, { x = 0, y = 1, z = 0}),
}
local landmine_positions = {}
for _idx2, pos2 in ipairs(positions_to_check) do
if landmines[core.hash_node_position(pos2)] then
table.insert(landmine_positions, pos2)
end
end
-- explode them!
for _idx2, pos2 in ipairs(landmine_positions) do
if not is_self_landmine(obj, pos2) then
landmine_explode(pos2)
end
end
end
core.debug(
string.format(
"[CTF Landmine] Used %f of server time for %d landmines and %d players",
core.get_gametime() - start_time,
landmines_n,
players_n
)
)
end)

ctf_api.register_on_match_end(function()
clear_landmines()
end)
2 changes: 2 additions & 0 deletions mods/ctf/ctf_landmine/mod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name = ctf_landmine
depends = ctf_teams, grenades, default, ctf_api
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions mods/ctf/ctf_modebase/crafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ crafting.register_recipe({
items = { "default:cobble 6", "default:steel_ingot" },
always_known = false,
})

crafting.register_recipe({
output = "ctf_map:landmine",
items = { "default:steel_ingot 4", "grenades:frag" },
always_known = false,
})
1 change: 1 addition & 0 deletions mods/ctf/ctf_modebase/features.lua
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ local damage_group_textures = {
knockback_grenade = "ctf_mode_nade_fight_knockback_grenade.png",
black_hole_grenade = "ctf_mode_nade_fight_black_hole_grenade.png",
damage_cobble = "ctf_map_damage_cobble.png",
landmine = "ctf_landmine_landmine.png",
}

local function get_weapon_image(hitter, tool_capabilities)
Expand Down
3 changes: 2 additions & 1 deletion mods/ctf/ctf_modes/ctf_mode_classes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ctf_modebase.register_mode("classes", {
["ctf_map:spike" ] = {min_count = 1, max_count = 5, max_stacks = 2, rarity = 0.2},
["ctf_map:damage_cobble" ] = {min_count = 5, max_count = 20, max_stacks = 2, rarity = 0.2},
["ctf_map:reinforced_cobble"] = {min_count = 5, max_count = 25, max_stacks = 2, rarity = 0.2},
["ctf_map:landmine" ] = {min_count = 1, max_count = 5, max_stacks = 1, rarity = 0.2},

["ctf_ranged:ammo" ] = {min_count = 3, max_count = 10, rarity = 0.3 , max_stacks = 2},
["ctf_healing:medkit" ] = { rarity = 0.08 , max_stacks = 2},
Expand All @@ -67,7 +68,7 @@ ctf_modebase.register_mode("classes", {
},
crafts = {
"ctf_ranged:ammo", "default:axe_mese", "default:axe_diamond", "default:shovel_mese", "default:shovel_diamond",
"ctf_map:damage_cobble", "ctf_map:spike", "ctf_map:reinforced_cobble 2",
"ctf_map:damage_cobble", "ctf_map:spike", "ctf_map:reinforced_cobble 2", "ctf_map:landmine",
},
physics = {sneak_glitch = true, new_move = true},
blacklisted_nodes = {"default:apple"},
Expand Down
2 changes: 2 additions & 0 deletions mods/ctf/ctf_modes/ctf_mode_nade_fight/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ctf_modebase.register_mode("nade_fight", {
["ctf_map:spike" ] = {min_count = 1, max_count = 5, max_stacks = 3, rarity = 0.2},
["ctf_map:damage_cobble" ] = {min_count = 5, max_count = 20, max_stacks = 2, rarity = 0.2},
["ctf_map:reinforced_cobble"] = {min_count = 5, max_count = 25, max_stacks = 2, rarity = 0.2},
["ctf_map:landmine" ] = {min_count = 1, max_count = 3, max_stacks = 1, rarity = 0.2},

["ctf_ranged:ammo" ] = {min_count = 3, max_count = 10, rarity = 0.3 , max_stacks = 2},
["ctf_healing:medkit" ] = { rarity = 0.1 , max_stacks = 2},
Expand All @@ -51,6 +52,7 @@ ctf_modebase.register_mode("nade_fight", {
"ctf_map:damage_cobble",
"ctf_map:spike",
"ctf_map:reinforced_cobble 2",
"ctf_map:landmine",
},
physics = {sneak_glitch = true, new_move = true},
blacklisted_nodes = {"default:apple"},
Expand Down
Loading