partial/prototype capture behavior, and improved handling of caching when touching a group from multiple sides

pull/1/head
capitalthree 1 year ago
parent 423c213f2b
commit f9ac9acb48
  1. 59
      rules.lua

@ -41,24 +41,47 @@ function handle_placement(pos)
end
our_stone = our_stone:sub(2, -1)
local captureses = {}
local captured = false
for i,v in pairs(neighbor_dirs(pos)) do
local node = check_position(pos + directions[v])
if node:byte(1) == S then
if not (node:sub(2, -1) == our_stone) then
local captures = check_captures(pos + directions[v])
if not (#captures == 0) then
minetest.chat_send_all("You gotcher self a capture right there! size: "..#captures)
captured = true
end
local new_pos = pos + directions[v]
local hash = minetest.hash_node_position(new_pos)
local checked = false
for i2,v2 in pairs(captureses) do
if v2.stones[hash] then
checked = true
end
end
if not checked then
local node = check_position(new_pos)
if (node:byte(1) == S) and (not (node:sub(2, -1) == our_stone)) then
local captures = check_captures(new_pos)
captured = captured or captures.capture
captureses[#captureses+1] = captures
end
end
end
if not captured then
if captured then
for i,v in pairs(captureses) do
if v.capture then
local proximal = {}
for i2, v2 in pairs(v.stones) do
nodecore.set_loud(v2, {name = "nc_fire:fire"})
end
-- todo: spawn itemstack of captured stones somehow
end
end
else
local captures = check_captures(pos)
if not (#captures == 0) then
minetest.chat_send_all("You gotcher self a suicide move right there! size: "..#captures)
if captures.capture then
minetest.chat_send_all("You gotcher self a suicide move right there! size: "..#(captures.stones))
-- todo: replace with itemstack of one stone
end
end
end
@ -155,7 +178,8 @@ no captures.
--]]
function check_captures(pos)
local group = {pos}
local checked = {[minetest.hash_node_position(pos)] = true}
local stones = {[minetest.hash_node_position(pos)] = pos}
local checked = {}
local team = check_position(pos):sub(2,-1)
local probe = 0
@ -167,22 +191,23 @@ function check_captures(pos)
local newpos = pos + directions[v]
local newhash = minetest.hash_node_position(newpos)
if not checked[newhash] then
checked[newhash] = true
if (not stones[newhash]) and (not checked[newhash]) then
local newnode = check_position(newpos)
if newnode:byte(1) == E then
return {}
return {capture = false, stones = stones}
elseif newnode:byte(1) == S and
newnode:sub(2, -1) == team then
stones[newhash] = newpos
group[#group+1] = newpos
else
checked[newhash] = true
end
end
end
end
return group
return {capture = true, stones = stones}
end

Loading…
Cancel
Save