/// <summary> /// Returns a connectivity bitmask that contains all relevant bits for the specified /// subtile quadrant of an AutoTile. /// </summary> /// <param name="quadrant"></param> public TileConnection GetSubTileMask(TileQuadrant quadrant) { switch (quadrant) { case TileQuadrant.TopLeft: return(TileConnection.Top | TileConnection.TopLeft | TileConnection.Left); case TileQuadrant.TopRight: return(TileConnection.Top | TileConnection.TopRight | TileConnection.Right); case TileQuadrant.BottomRight: return(TileConnection.Bottom | TileConnection.BottomRight | TileConnection.Right); case TileQuadrant.BottomLeft: return(TileConnection.Bottom | TileConnection.BottomLeft | TileConnection.Left); default: return(TileConnection.None); } }
/// <summary> /// Finds an existing base tile where a certain sub-tile matches with the specified connectivity state. /// Returns <see cref="TileConnection.None"/> if no match was found in the existing set. /// </summary> /// <param name="quadrant"></param> /// <param name="targetConnectivity"></param> /// <param name="isStateAvailable"></param> private static TileConnection FindGeneratedAutoTileBase(TileQuadrant quadrant, TileConnection targetConnectivity, bool[] isStateAvailable) { TileConnection mask = AutoTileFallbackMap.GetSubTileMask(quadrant); TileConnection targetBits = targetConnectivity & mask; IReadOnlyList <TileConnection> baseTiles = AutoTileFallbackMap.BaseConnectivityTiles; TileConnection bestMatch = TileConnection.None; int bestMatchNeighbourCount = 0; for (int i = 0; i < baseTiles.Count; i++) { // Skip tiles that are not available in the tileset TileConnection connectivity = baseTiles[i]; if (!isStateAvailable[(int)connectivity]) { continue; } // Skip tiles that do not match in the required bits TileConnection bits = connectivity & mask; if (bits != targetBits) { continue; } // Special case: Skip the entirely unconnected tile, since this one is often // different from any partially connected tiles. Note if this should change: // It's also currently conflicting with the "no match found" return value. if (connectivity == TileConnection.None) { continue; } // Prefer the most connected match we can find, since less connected tiles // tend to be more specialized in their visual appearance. Only consider // connectivity that we also find in the target tile to avoid under-specializing. TileConnection sharedConnectivity = connectivity & targetConnectivity; int neighbourCount = GetConnectedNeighbours(sharedConnectivity); if (neighbourCount > bestMatchNeighbourCount) { bestMatchNeighbourCount = neighbourCount; bestMatch = connectivity; } } return(bestMatch); }
// // Input Handlers // /// <summary> /// Handles a click with the primary mouse button. /// </summary> /// <param name="position">The position that was returned by a raycast.</param> private void HandlePrimaryClick(Vector3 position) { TileCoordinates coords = TileCoordinates.FromPosition(position); // get the coordinates of the tile TileQuadrant quadrant = coords.QuadrantFromPosition(position); // get the quadrant that was clicked Tile tile = World.GetTileAt(coords); // get the tile at the given coordinates // handle moving a unit, if the conditions are met // and if the unit wasn't moved, then if (!HandleUnitMove(tile)) { // get the unit that was clicked on if (!HandleUnitClick(GetUnitInTile(coords, quadrant))) { // update the tile information in the gui HandleTileClick(tile); } } }
/// <summary> /// Gets the unit in the given tile coordinate and quadrant. /// </summary> /// <param name="coordinates">The tile that was clicked.</param> /// <param name="quadrant">The quadrant of the tile that was clicked.</param> /// <returns></returns> private Unit GetUnitInTile(TileCoordinates coordinates, TileQuadrant quadrant) { // ensure that the quadrant is in the east, where the units are if (quadrant.IsWest()) { return(null); } List <Unit>[] units = World.GetUnitsAt(coordinates); // if the user clicked in the north quadrant, check for military units of our faction (0) // otherwise check for civilian units of our faction (1) foreach (Unit u in units[quadrant.IsNorth() ? 0 : 1]) { if (u.faction == Faction.player) { return(u); } } return(null); }
public static bool IsWest(this TileQuadrant enumVal) { return((( int )enumVal & 1) != 0); }
public static bool IsSouth(this TileQuadrant enumVal) { return((( int )enumVal & 4) != 0); }
public static bool IsNorth(this TileQuadrant enumVal) { return((( int )enumVal & 8) != 0); }