forked from lizzie/lc_liberties
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
2.7 KiB
115 lines
2.7 KiB
-- 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 relative_neighbors = { |
|
vector.new(1, 0, 0), |
|
vector.new(0, 0, 1), |
|
vector.new(-1, 0, 0), |
|
vector.new(0, 0, -1) |
|
} |
|
|
|
local solid_drawtypes = { |
|
normal = true, |
|
glasslike_framed = true, |
|
} |
|
|
|
--[[ |
|
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) |
|
print(ret) -- todo: remove this |
|
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 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] then |
|
return "W" |
|
else |
|
return "E" |
|
end |
|
end |
|
|
|
function check_captures(pos) |
|
minetest.chat_send_all(tostring(pos)) |
|
nodecore.node_sound(pos, "dug") |
|
|
|
check_position(pos + vector.new(0, -1, 0)) |
|
|
|
local neighbors = {} |
|
|
|
for i,v in ipairs(relative_neighbors) do |
|
neighbors[i] = pos + v |
|
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 |