Skip to content

Commit

Permalink
Misc landmine mod improvements/fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWolfHT committed Dec 2, 2024
1 parent 6e933c6 commit 052be16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 35 deletions.
39 changes: 9 additions & 30 deletions mods/ctf/ctf_landmine/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ 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
Expand All @@ -42,7 +39,7 @@ local function is_self_landmine(object_ref, pos)
end

local function landmine_explode(pos)
local near_objs = core.get_objects_inside_radius(pos, 3)
local near_objs = ctf_core.get_players_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)
Expand Down Expand Up @@ -145,21 +142,15 @@ core.register_node("ctf_landmine:landmine", {
end
})




core.register_globalstep(function(dtime)
if number_of_landmines == 0 then return end

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),
Expand All @@ -174,27 +165,15 @@ core.register_globalstep(function(dtime)
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)
if not is_self_landmine(obj, pos2) then
landmine_explode(pos2)
end
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()
Expand Down
2 changes: 1 addition & 1 deletion mods/ctf/ctf_modebase/crafting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ crafting.register_recipe({
})

crafting.register_recipe({
output = "ctf_map:landmine",
output = "ctf_landmine:landmine",
items = { "default:steel_ingot 4", "grenades:frag" },
always_known = false,
})
4 changes: 2 additions & 2 deletions mods/ctf/ctf_modes/ctf_mode_classes/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +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_landmine: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 @@ -68,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:landmine",
"ctf_map:damage_cobble", "ctf_map:spike", "ctf_map:reinforced_cobble 2", "ctf_landmine:landmine",
},
physics = {sneak_glitch = true, new_move = true},
blacklisted_nodes = {"default:apple"},
Expand Down
4 changes: 2 additions & 2 deletions mods/ctf/ctf_modes/ctf_mode_nade_fight/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +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_landmine: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 @@ -52,7 +52,7 @@ ctf_modebase.register_mode("nade_fight", {
"ctf_map:damage_cobble",
"ctf_map:spike",
"ctf_map:reinforced_cobble 2",
"ctf_map:landmine",
"ctf_landmine:landmine",
},
physics = {sneak_glitch = true, new_move = true},
blacklisted_nodes = {"default:apple"},
Expand Down

0 comments on commit 052be16

Please sign in to comment.