static int ObserverShroudedEdges(Map map, CPos p, bool useExtendedIndex) { var u = 0; if (!map.Contains(p + new CVec(0, -1))) u |= 0x13; if (!map.Contains(p + new CVec(1, 0))) u |= 0x26; if (!map.Contains(p + new CVec(0, 1))) u |= 0x4C; if (!map.Contains(p + new CVec(-1, 0))) u |= 0x89; var uside = u & 0x0F; if (!map.Contains(p + new CVec(-1, -1))) u |= 0x01; if (!map.Contains(p + new CVec(1, -1))) u |= 0x02; if (!map.Contains(p + new CVec(1, 1))) u |= 0x04; if (!map.Contains(p + new CVec(-1, 1))) u |= 0x08; return useExtendedIndex ? u ^ uside : u & 0x0F; }