private GridCell FindLandingCell(GridCell startingCell)
    {
        int          slicesTried = 1;
        int          moveToLayer = startingCell.parentGrid.GetGridSize().layers - 2;
        GridCell     landingCell = startingCell;
        CircularGrid grid        = landingCell.parentGrid;

        while (landingCell.Selectable != null)
        {
            GridCell possiblePlus  = grid.GetGridCell(moveToLayer, startingCell.slice + slicesTried);
            GridCell possibleMinus = grid.GetGridCell(moveToLayer, startingCell.slice - slicesTried);
            if (possiblePlus.Selectable == null)
            {
                landingCell = possiblePlus;
            }
            else
            {
                landingCell = possibleMinus;
            }
            slicesTried++;
            if (slicesTried >= (startingCell.parentGrid.GetGridSize().slices - 1))
            {
                moveToLayer--;
                slicesTried = 0;
            }
            if (moveToLayer == -1)
            {
                throw new System.Exception("Ran out of spaces - what do we do?");
            }
        }
        return(landingCell);
    }
    private (GridCell north, GridCell south, GridCell east, GridCell west) GetLandingGridCells(CircularGrid grid)
    {
        (int tempLay, int tempSlice) = grid.GetGridSize();
        int      slices     = tempSlice - 1;
        int      outerLayer = tempLay - 2;
        GridCell eastCell   = grid.GetGridCell(outerLayer, 0);
        GridCell northCell  = grid.GetGridCell(outerLayer, Mathf.CeilToInt(slices / 4) * 1);
        GridCell westCell   = grid.GetGridCell(outerLayer, Mathf.CeilToInt(slices / 4) * 2);
        GridCell southCell  = grid.GetGridCell(outerLayer, Mathf.CeilToInt(slices / 4) * 3);

        return(northCell, southCell, eastCell, westCell);
    }
Beispiel #3
0
    private bool PlaceResource(CircularGrid grid, int layer, int slice, int prefabNumber)
    {
        GridCell parentCell = grid.GetGridCell(layer, slice);

        if (parentCell.Selectable == null && parentCell.ResourceDeposit == null)
        {
            ResourceDeposit deposit = Instantiate <ResourceDeposit>(this.resourceDepositPrefabs[prefabNumber]);
            deposit.transform.SetParent(resourceDepositHolder.transform);
            GridManager.Instance.AddResourceDeposit(deposit);
            deposit.SetParentCell(parentCell);
            return(true);
        }
        return(false);
    }