/// <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); }
public void Update() { if (!UnitPlacement.unitsAreFrozen()) { highlightUnit(); } }
public static void sell() { if (cursorObjID.isPresent()) { UnitPlacement.destroyUnit(cursorObjID.get()); } UnitPlacement.freezeUnits(false); }
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; } }
// 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); } }
/// <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); }
public void removeFromGrid() { UnitPlacement.removeUnit(bleftx, blefty, myXfloorSize, myYfloorSize); }
public void addToGrid() { UnitPlacement.addUnit(bleftx, blefty, myID, myXfloorSize, myYfloorSize, forward, myType); }
public void OnMouseOver() { UnitPlacement.freezeUnits(true); }
public void OnMouseExit() { UnitPlacement.freezeUnits(false); }
// Use this for initialization void Start() { unitPlacement = unitPlacer.GetComponent <UnitPlacement>(); }
private bool checkFree(int x, int y) { return(TileGrid.indexInGrid(x, y) && !UnitPlacement.occupied(x, y, -1)); }
public void destroyCurrentUnit() { UnitPlacement.freezeUnits(true); BuildController.sell(); }