diff --git a/rules.lua b/rules.lua index 9550c46..61c1381 100644 --- a/rules.lua +++ b/rules.lua @@ -11,27 +11,61 @@ local modname = minetest.get_current_modname() local cache = {} -local relativeNeighbors = { +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 = minetest.get_node(pos) - print_r(ret) - print_r(minetest.registered_items[ret.name]) - print(pos) + 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") @@ -40,7 +74,7 @@ function check_captures(pos) local neighbors = {} - for i,v in ipairs(relativeNeighbors) do + for i,v in ipairs(relative_neighbors) do neighbors[i] = pos + v end diff --git a/stones.lua b/stones.lua index d0602a8..0a19ab5 100644 --- a/stones.lua +++ b/stones.lua @@ -54,12 +54,18 @@ local function reg(name, basename, basedef) }, paramtype = "light", + sunlight_propagates = true, + groups = { snappy = 1, falling_node = 1, falling_repose = 1, + go_stone = 1 }, + + go_team = name, + sounds = basedef.sounds, on_construct = check_captures @@ -72,7 +78,6 @@ local function reg(name, basename, basedef) nodes = { { match = "nc_concrete:" .. name .. "_starcrossy_ply", - --match = {groups = {goban = 1}}, replace = "air" } },