Ejemplo n.º 1
0
    /// <summary>
    /// Finds a shelf near to the location passed in.
    /// </summary>
    /// <param name="startX"></param>
    /// <param name="startY"></param>
    /// <returns></returns>
    public List <int[]> FindShelf(int startX, int startY)
    {
        PriorityQueue <Tile> tilesToSearch = new PriorityQueue <Tile>(TileGrid.getGridSize() * 4);

        visitedTiles = new HashSet <string>();
        tilesToSearch.add(new Tile(Optional <Tile> .empty(), startX, startY), 0);


        while (tilesToSearch.hasElements())
        {
            int  currentDist = tilesToSearch.TopPriority();
            Tile currentTile = tilesToSearch.take();

            visitedTiles.Add(TileGrid.getKey(currentTile.x, currentTile.y));

            if (UnitPlacement.canAccessShelf(currentTile.x, currentTile.y) && UnityEngine.Random.Range(0, 5) == 0)
            {
                return(traceBackRoute(currentTile));
            }

            foreach (int[] tile in getAdjIndexes(currentTile.x, currentTile.y))
            {
                if (checkFree(tile[0], tile[1]) && !visitedTiles.Contains(TileGrid.getKey(tile[0], tile[1])))
                {
                    tilesToSearch.add(new Tile(Optional <Tile> .of(currentTile), tile[0], tile[1]), currentDist - 1);
                }
            }
        }

        return(null);
    }
Ejemplo n.º 2
0
 public void Update()
 {
     if (!UnitPlacement.unitsAreFrozen())
     {
         highlightUnit();
     }
 }
Ejemplo n.º 3
0
 public static void sell()
 {
     if (cursorObjID.isPresent())
     {
         UnitPlacement.destroyUnit(cursorObjID.get());
     }
     UnitPlacement.freezeUnits(false);
 }
Ejemplo n.º 4
0
    public void PlacementMode(bool state)
    {
        UnitPlacement up = this.gameObject.GetComponent <UnitPlacement>();

        if (up == null)
        {
            Debug.Log("There is no UnitPlacement on this object!");
        }
        else
        {
            up.enabled = state;
        }
    }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        //this is a bit hacky, fix maybe
        if (initial)
        {
            if (!forward)
            {
                rotate(true);
            }
            initial = false;
            spriteRenderer.sortingOrder = TileGrid.getSortingNum(blefty);
        }

        if (!UnitPlacement.unitsAreFrozen())
        {
            snapToMousePosition();
            grabOrDropObject();
            rotate(false);
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// True if the current position clashes with the differet unit
    /// </summary>
    /// <returns></returns>
    public bool thereIsClash()
    {
        //gets the tile coordinates of the bottom left of the unit
        int blX = Tile.getTile(mousePosition[0]);
        int blY = Tile.getTile(mousePosition[1]);

        //checks for clashes
        for (int x = 0; x < myXfloorSize; x++)
        {
            for (int y = 0; y < myYfloorSize; y++)
            {
                //Debug.Log("check");
                if (UnitPlacement.occupied(blX + x, blY + y, myID))
                {
                    //Debug.Log("Occupied");
                    return(true);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 7
0
 public void removeFromGrid()
 {
     UnitPlacement.removeUnit(bleftx, blefty, myXfloorSize, myYfloorSize);
 }
Ejemplo n.º 8
0
 public void addToGrid()
 {
     UnitPlacement.addUnit(bleftx, blefty, myID, myXfloorSize, myYfloorSize, forward, myType);
 }
Ejemplo n.º 9
0
 public void OnMouseOver()
 {
     UnitPlacement.freezeUnits(true);
 }
Ejemplo n.º 10
0
 public void OnMouseExit()
 {
     UnitPlacement.freezeUnits(false);
 }
Ejemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     unitPlacement = unitPlacer.GetComponent <UnitPlacement>();
 }
Ejemplo n.º 12
0
 private bool checkFree(int x, int y)
 {
     return(TileGrid.indexInGrid(x, y) &&
            !UnitPlacement.occupied(x, y, -1));
 }
Ejemplo n.º 13
0
 public void destroyCurrentUnit()
 {
     UnitPlacement.freezeUnits(true);
     BuildController.sell();
 }