private int GetBitMask4(Vec2i tileId) { TileNeighbour bitMask = TileNeighbour.None; if (CheckUp(tileId)) { bitMask |= TileNeighbour.Up; } if (CheckLeft(tileId)) { bitMask |= TileNeighbour.Left; } if (CheckDown(tileId)) { bitMask |= TileNeighbour.Down; } if (CheckRight(tileId)) { bitMask |= TileNeighbour.Right; } return((int)bitMask); }
private bool NoNeighbour(TileNeighbour neighbour, Tile[] myNeighbours) { return(myNeighbours[(int)neighbour] == null || !myNeighbours[(int)neighbour].IsOccupied || (myNeighbours[(int)neighbour].IsOccupied && myNeighbours[(int)neighbour].Occupier.Type != tileType)); }
private bool SameNeighbour(TileNeighbour neighbour, Tile[] myNeighbours) { return(myNeighbours[(int)neighbour] != null && myNeighbours[(int)neighbour].IsOccupied && myNeighbours[(int)neighbour].Occupier.Type == tileType); }
private int GetBitMask8(Vec2i tileId) { TileNeighbour bitMask = TileNeighbour.None; int edgeCount = 0; bool hasEdgeUp = false; bool hasEdgeLeft = false; bool hasEdgeDown = false; bool hasEdgeRight = false; if (CheckUp(tileId)) { bitMask |= TileNeighbour.Up; hasEdgeUp = true; edgeCount++; } if (CheckLeft(tileId)) { bitMask |= TileNeighbour.Left; hasEdgeLeft = true; edgeCount++; } if (CheckDown(tileId)) { bitMask |= TileNeighbour.Down; hasEdgeDown = true; edgeCount++; } if (CheckRight(tileId)) { bitMask |= TileNeighbour.Right; hasEdgeRight = true; edgeCount++; } //no adjacent edges, ignore corners OR if one edge is set, ignre corners if (edgeCount == 0 || edgeCount == 1) { return((int)bitMask); } //if two edges are opposite, the corner doesnt matter if (edgeCount == 2) { if (hasEdgeUp && hasEdgeLeft && CheckUpLeft(tileId)) { bitMask |= TileNeighbour.UpLeft; } if (hasEdgeLeft && hasEdgeDown && CheckLeftDown(tileId)) { bitMask |= TileNeighbour.Leftdown; } if (hasEdgeDown && hasEdgeRight && CheckDownRight(tileId)) { bitMask |= TileNeighbour.DownRight; } if (hasEdgeRight && hasEdgeUp && CheckRightUp(tileId)) { bitMask |= TileNeighbour.RightUp; } return((int)bitMask); } if (edgeCount == 3) { if (!hasEdgeDown) { if (CheckUpLeft(tileId)) { bitMask |= TileNeighbour.UpLeft; } if (CheckRightUp(tileId)) { bitMask |= TileNeighbour.RightUp; } } else if (!hasEdgeRight) { if (CheckUpLeft(tileId)) { bitMask |= TileNeighbour.UpLeft; } if (CheckLeftDown(tileId)) { bitMask |= TileNeighbour.Leftdown; } } else if (!hasEdgeUp) { if (CheckDownRight(tileId)) { bitMask |= TileNeighbour.DownRight; } if (CheckLeftDown(tileId)) { bitMask |= TileNeighbour.Leftdown; } } else if (!hasEdgeLeft) { if (CheckDownRight(tileId)) { bitMask |= TileNeighbour.DownRight; } if (CheckRightUp(tileId)) { bitMask |= TileNeighbour.RightUp; } } return((int)bitMask); } //all edges are set: all corners can be relevant: if (edgeCount == 4) { if (CheckUpLeft(tileId)) { bitMask |= TileNeighbour.UpLeft; } if (CheckLeftDown(tileId)) { bitMask |= TileNeighbour.Leftdown; } if (CheckDownRight(tileId)) { bitMask |= TileNeighbour.DownRight; } if (CheckRightUp(tileId)) { bitMask |= TileNeighbour.RightUp; } return((int)bitMask); } Debug.Log("Case didnt met the cases: " + bitMask); Debug.Assert(false); return((int)bitMask); }