void SpawnObstacle() { Tile targetTile = target as Tile; Obstacle obstacle = Instantiate(obstaclePrefab, targetTile.transform.position, obstaclePrefab.transform.rotation).GetComponent <Obstacle>(); obstacle.OnSpawn(MultiTile.Create(targetTile, obstacle.currentPosition.size)); }
public static void SetNewPosition(int index, int endPosX, int endPosZ) { Vector3 newPos = Global.instance.currentMap.board[endPosX, endPosZ].transform.position; Unit unit = UnitFactory.GetUnitByIndex(index); Tile tile = Global.instance.currentMap.board[endPosX, endPosZ]; unit.TryToSetMyPositionAndMoveTo(MultiTile.Create(tile, unit.currentPosition.size)); unit.FaceMiddleOfMap(); }
void RPCDoMovement(int startX, int startZ, int endX, int endZ) { Tile bottomLeftCorner = Global.instance.currentMap.board[startX, startZ]; Unit unit = bottomLeftCorner.GetMyObject <Unit>(); if (unit == null) { Debug.LogError("NoUnit!"); LogConsole.instance.SpawnLog("NO UNIT TO MOVE!"); return; } MultiTile destination = MultiTile.Create(Global.instance.currentMap.board[endX, endZ], unit.currentPosition.size); unit.Move(destination); }
MultiTile CalibrateToFitInBoard(MultiTile position) { int posX = position.bottomLeftCorner.position.x; int posZ = position.bottomLeftCorner.position.z; if (posX + position.size.width > Global.instance.currentMap.mapWidth) { posX = Global.instance.currentMap.mapWidth - position.size.width; } if (posZ + position.size.height > Global.instance.currentMap.mapHeight) { posZ = Global.instance.currentMap.mapHeight - position.size.height; } return(MultiTile.Create(Global.instance.currentMap.board[posX, posZ], position.size)); }
public MultiTile PositionRelatedToMouse(Size size, Vector3 exactClickPosition) { // this variable is equal to 1 if width or height are even, otherwise 0 int widthEven = size.width % 2; int heightEven = size.height % 2; // check which part of tile player clicked int xGt = Convert.ToInt32(exactClickPosition.x > this.transform.position.x); int zGt = Convert.ToInt32(exactClickPosition.z > this.transform.position.z); // find new bottom left corner of Multitile int widthOffset = (size.width - widthEven) / 2 - xGt * Convert.ToInt32(widthEven == 0); int heightOffset = (size.height - heightEven) / 2 - zGt * Convert.ToInt32(heightEven == 0); return(MultiTile.Create(ToTile(this.Offset(-widthOffset, -heightOffset).CalibrateTo(size.width, size.height)), size)); }
//This function gives the list of possible tiles a Unit could get to. public List <MultiTile> GetAllLegalPositionsFor(Unit unitToMove) { List <MultiTile> returnList = new List <MultiTile>(); BFS(unitToMove); for (int i = 0; i < Global.instance.currentMap.mapWidth - unitToMove.currentPosition.size.width + 1; i++) { for (int j = 0; j < Global.instance.currentMap.mapHeight - unitToMove.currentPosition.size.height + 1; j++) { MultiTile newPosition = MultiTile.Create(Global.instance.currentMap.board[i, j], unitToMove.currentPosition.size); if (unitToMove.CanMoveTo(newPosition)) { returnList.Add(newPosition); } } } return(returnList); }
MultiTile GetRandomMultiTile(Size size, MapVisualsSpecification spec) { int terminator = 0; Tile tile = Global.instance.currentMap.board[Random.Range(spec.minDistanceToShortSide, Global.instance.currentMap.mapWidth - spec.minDistanceToShortSide), Random.Range(spec.minDistanceToLongSide, Global.instance.currentMap.mapHeight - spec.minDistanceToLongSide)]; MultiTile position = MultiTile.Create(tile, size); while (IsMultiTileLegal(position, spec) == false) { terminator++; tile = Global.instance.currentMap.board[Random.Range(spec.minDistanceToShortSide, Global.instance.currentMap.mapWidth - spec.minDistanceToShortSide), Random.Range(spec.minDistanceToLongSide, Global.instance.currentMap.mapHeight - spec.minDistanceToLongSide)]; position = MultiTile.Create(tile, size); if (terminator == 100) { return(null); } } return(position); }
MultiTile ChooseThePosition(Size size) { List <MultiTile> possibleTiles = new List <MultiTile>(); foreach (Tile tile in Global.instance.currentMap.board) { MultiTile position = MultiTile.Create(tile, size); if (position != null && position.IsWalkable() && (position.IsDropzoneOfTeam(GameRound.instance.currentPlayer.team.index))) { possibleTiles.Add(position); } } MultiTile chosenTile = Tools.GetRandomElementFromList <MultiTile>(possibleTiles); if (chosenTile == null) { Debug.LogError("Too many units, couldn't put them on battlefield"); return(null); } return(chosenTile); }