public float BuildingHeight(Vector3 pos, float diameter) { List <GridTile> gridtiles = GridTile.FindGridTilesAround(pos, diameter); int count = 0; float curHeight = -1; foreach (GridTile tile in gridtiles) { for (int i = 0; i < tile.gridNodes.Count; i++) { if (tile.gridNodes[i].heighIsSet) { count++; if (count > 1 && Mathf.Abs(tile.gridNodes[i].position.y - curHeight) > 0.5f) { return(-1); } curHeight = tile.gridNodes[i].position.y; } } } if (count == 0) { return(pos.y); } else { return(curHeight); } }
// Use this for initialization void Start() { foreach (GridTile tile in GridTile.FindGridTilesAround(transform.position, windRadius)) { tile.canSeeWind = true; } }
void RemoveFromGridTiles(Vector3 point, float circleRadius) { List <GridTile> gridtiles = GridTile.FindGridTilesAround(point, circleRadius); foreach (GridTile tile in gridtiles) { tile.occupants.Clear(); //tile.type = GridTileOccupant.OccupantType.Empty; } }
// Function that adds on object to all gridtiles in a certian circle radius around a tile with position point. void AddToGridTiles(GameObject something, Vector3 point, float circleRadius, GridTileOccupant.OccupantType type) { List <GridTile> gridtiles = GridTile.FindGridTilesAround(point, circleRadius + 2 * TerrainController.thisTerrainController.tileSize); foreach (GridTile tile in gridtiles) { TerrainController.thisTerrainController.RemoveTerrainTileOccupant(tile); tile.occupants.Add(new GridTileOccupant(something, type)); } //tile.type = type; }
public bool BuildingNearby(Vector3 pos, float diameter) { List <GridTile> gridtiles = GridTile.FindGridTilesAround(pos, diameter); foreach (GridTile tile in gridtiles) { for (int i = 0; i < tile.gridNodes.Count; i++) { if (tile.gridNodes[i].heighIsSet) { return(true); } } } return(false); }
// Set the terrain height around a position to the tile closest to the entered position void EqualTerrain(Vector3 pos, float circleRadius, bool isTemp) { GridTile middleTile = GridTile.FindClosestGridTile(pos); List <GridTile> gridtiles = GridTile.FindGridTilesAround(pos, circleRadius); List <Chunk> updateChunks = new List <Chunk>(); foreach (GridTile tile in gridtiles) { for (int i = 0; i < tile.gridNodes.Count; i++) { if (tile.gridNodes[i].heighIsSet) { continue; } Vector3 newPos = Vector3.zero; Vector3 vertex = tile.gridNodes[i].position; Chunk[] chunks = Chunk.FindChunksWithVertex(vertex); foreach (Chunk chunk in chunks) { int[] index = Chunk.FindClosestVertices(vertex, chunk); float diffx = chunk.gameObject.transform.position.x + chunk.map[index[0], index[1]].x - middleTile.position.x; float diffz = chunk.gameObject.transform.position.z + chunk.map[index[0], index[1]].z - middleTile.position.z; newPos = new Vector3(chunk.map[index[0], index[1]].x, pos.y, chunk.map[index[0], index[1]].z); if (!isTemp) { chunk.map[index[0], index[1]] = newPos; } else { chunk.tempMap[index[0], index[1]] = newPos; } //chunk.AddVertsAndUVAndNorm(chunk.map.GetLength(0), true); if (!updateChunks.Contains(chunk)) { updateChunks.Add(chunk); } } if (!isTemp) { tile.gridNodes[i].position = new Vector3(tile.gridNodes[i].position.x, pos.y, tile.gridNodes[i].position.z); tile.gridNodes[i].heighIsSet = true; } } if (!isTemp) { tile.position = tile.gridNodes[0].position; } } foreach (Chunk chunk in updateChunks) { chunk.GenerateTerrainMesh(true, isTemp); tempChunks.Add(chunk); } }
// Function that determines if a tile has an object on it and return true if there is no objects on all the tiles in a circle with size as diameter. public bool CanBuild(Vector3 pos, float size, GameObject buildObj, float scale, Quaternion rotation, bool neglectTerrainObjects) { List <GridTile> gridtiles = GridTile.FindGridTilesAround(pos, size + 60); GridTile thisTile = GridTile.FindClosestGridTile(pos); Collider[] colliders = Physics.OverlapBox(buildObj.GetComponent <BoxCollider>().center *scale + pos, buildObj.GetComponent <BoxCollider>().size / 2 * scale, rotation, notTerrain); if (colliders.Length > 1) { return(false); } else if (colliders.Length == 1 && colliders[0].gameObject.GetInstanceID() != buildObj.gameObject.GetInstanceID()) { return(false); } if (pos.y <= TerrainController.thisTerrainController.waterLevel) { return(false); } float lowPoint = pos.y; float highPoint = pos.y; bool heighSet = false; foreach (GridTile tile in gridtiles) { if (tile.isOutsideBorder) { return(false); } for (int i = 0; i < tile.gridNodes.Count; i++) { if (tile.gridNodes[i].position.y > highPoint) { highPoint = tile.position.y; } else if (tile.gridNodes[i].position.y < lowPoint) { lowPoint = tile.position.y; } if (tile.gridNodes[i].heighIsSet) { heighSet = true; } } } if ((highPoint - lowPoint > 40 || lowPoint < TerrainController.thisTerrainController.waterLevel) && heighSet) { return(false); } if (BuildingHeight(pos, size * scale) == -1) { return(false); } return(true); }