|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
|
|
|
local include, nodecore, pairs, string, table
|
|
|
|
= include, nodecore, pairs, string, table
|
|
|
|
local string_lower
|
|
|
|
= string.lower
|
|
|
|
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
--nodecore.gametime
|
|
|
|
|
|
|
|
local cache = {}
|
|
|
|
|
|
|
|
local directions = { [0] =
|
|
|
|
vector.new(0, 0, -1),
|
|
|
|
vector.new(-1, 0, 0),
|
|
|
|
vector.new(0, 0, 1),
|
|
|
|
vector.new(1, 0, 0),
|
|
|
|
}
|
|
|
|
|
|
|
|
local down = vector.new(0, -1, 0)
|
|
|
|
|
|
|
|
local solid_drawtypes = {
|
|
|
|
normal = true,
|
|
|
|
glasslike_framed = true,
|
|
|
|
}
|
|
|
|
|
|
|
|
local S = ("S"):byte(1)
|
|
|
|
local W = ("W"):byte(1)
|
|
|
|
local E = ("E"):byte(1)
|
|
|
|
local C = ("C"):byte(1)
|
|
|
|
|
|
|
|
function handle_placement(pos)
|
|
|
|
cache = {}
|
|
|
|
--minetest.chat_send_all(tostring(pos))
|
|
|
|
--nodecore.node_sound(pos, "dug")
|
|
|
|
|
|
|
|
local our_stone = check_position(pos)
|
|
|
|
if not (our_stone:byte(1) == S) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
our_stone = our_stone:sub(2, -1)
|
|
|
|
|
|
|
|
-- print_r(neighbor_dirs(pos))
|
|
|
|
|
|
|
|
for i,v in pairs(neighbor_dirs(pos)) do
|
|
|
|
local node = check_position(pos +directions[v])
|
|
|
|
if node:byte(1) == S then
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--neighbors[i] = pos + v
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[
|
|
|
|
give valid neighbor directions from a position, excluding solid blocks
|
|
|
|
and also respecting borders indicated by goban concrete
|
|
|
|
--]]
|
|
|
|
function neighbor_dirs(pos)
|
|
|
|
local neighbors = {}
|
|
|
|
for i,v in pairs(directions) do
|
|
|
|
if not edge_check(pos, i) then
|
|
|
|
if not (check_position(pos + directions[i]):byte(1) == W) then
|
|
|
|
neighbors[#neighbors+1] = i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return neighbors
|
|
|
|
end
|
|
|
|
|
|
|
|
-- check for walls, physical or implied
|
|
|
|
function edge_check(pos, dir, terminate)
|
|
|
|
local under = check_position(pos + down)
|
|
|
|
|
|
|
|
if under:byte(1) == W and under:len() == 3 then
|
|
|
|
local corner = (under:byte(2) == C)
|
|
|
|
local edge_dir = tonumber(under:sub(3, 3))
|
|
|
|
|
|
|
|
if (dir == edge_dir) or (corner and (dir == (edge_dir+1)%4)) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not terminate then
|
|
|
|
if edge_check(pos+directions[dir], (dir+2)%4, true) then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--[[
|
|
|
|
E: empty
|
|
|
|
Stype: a go stone of some type
|
|
|
|
W: full block wall
|
|
|
|
WE0-WE3: edge concrete
|
|
|
|
WC0-WC3: corner concrete
|
|
|
|
--]]
|
|
|
|
function check_position(pos)
|
|
|
|
local hash = minetest.hash_node_position(pos)
|
|
|
|
if cache[hash] then
|
|
|
|
return cache[hash]
|
|
|
|
end
|
|
|
|
|
|
|
|
local ret = _check_position_uncached(pos)
|
|
|
|
cache[hash] = ret
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
function _check_position_uncached(pos)
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
local reg_item = minetest.registered_items[node.name]
|
|
|
|
|
|
|
|
if not reg_item then
|
|
|
|
return "W"
|
|
|
|
end
|
|
|
|
|
|
|
|
if reg_item.groups and reg_item.groups.go_stone then
|
|
|
|
return "S" .. reg_item.go_team
|
|
|
|
end
|
|
|
|
|
|
|
|
if reg_item.pattern_def then
|
|
|
|
if reg_item.pattern_def.name == "edgy" then
|
|
|
|
return "WE" .. node.param2
|
|
|
|
elseif reg_item.pattern_def.name == "corny" then
|
|
|
|
return "WC" .. node.param2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if solid_drawtypes[reg_item.drawtype] and not reg_item.groups.falling_node then
|
|
|
|
return "W"
|
|
|
|
else
|
|
|
|
return "E"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function surrounded_group(pos)
|
|
|
|
local group = {}
|
|
|
|
local queue = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function print_r ( t )
|
|
|
|
local print_r_cache={}
|
|
|
|
local function sub_print_r(t,indent)
|
|
|
|
if (print_r_cache[tostring(t)]) then
|
|
|
|
print(indent.."*"..tostring(t))
|
|
|
|
else
|
|
|
|
print_r_cache[tostring(t)]=true
|
|
|
|
if (type(t)=="table") then
|
|
|
|
for pos,val in pairs(t) do
|
|
|
|
if (type(val)=="table") then
|
|
|
|
print(indent.."["..pos.."] => "..tostring(t).." {")
|
|
|
|
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
|
|
|
|
print(indent..string.rep(" ",string.len(pos)+6).."}")
|
|
|
|
else
|
|
|
|
print(indent.."["..pos.."] => "..tostring(val))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print(indent..tostring(t))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
sub_print_r(t," ")
|
|
|
|
end
|