/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="i"></param> /// <param name="j"></param> /// <returns></returns> public float SamplePerlinLerp(int x, int y, int i, int j) { //wat da hell why can't i find a better way if (x < 0 || y < 0 || x >= sizeX || y >= sizeY || isLand[x][y] == 0) { return(0); } float factor = 1; LandNode node = landNodes[x][y]; //Split into quadrants if (i < 16 && j < 16) { //bottom left factor = 0.5f * (j / 15.0f) * Mathf.Lerp(node.left, node.center, i / 15.0f) + //Lerp from left to center 0.5f * (1 - (j / 15.0f)) * Mathf.Lerp(node.bottomLeft, node.bottom, i / 15.0f) + //Lerp from bottomLeft to bottom 0.5f * (i / 15.0f) * Mathf.Lerp(node.bottom, node.center, j / 15.0f) + //Lerp from bottom to center 0.5f * (1 - (i / 15.0f)) * Mathf.Lerp(node.bottomLeft, node.left, j / 15.0f); //Lerp from bottomLeft to left } else if (i >= 16 && j < 16) { //Bottom right factor = 0.5f * (j / 15.0f) * Mathf.Lerp(node.center, node.right, (i - 16.0f) / 15.0f) + //lerp from center to right 0.5f * (1 - (j / 15.0f)) * Mathf.Lerp(node.bottom, node.bottomRight, (i - 16.0f) / 15.0f) + //Lerp from bottom to right 0.5f * ((i - 16.0f) / 15.0f) * Mathf.Lerp(node.bottomRight, node.right, j / 15.0f) + //Lerp from bottom to center 0.5f * (1 - ((i - 16.0f) / 15.0f)) * Mathf.Lerp(node.bottom, node.center, j / 15.0f); //Lerp from bottomLeft to left } else if (i < 16 && j >= 16) { //Top left factor = 0.5f * ((j - 16.0f) / 15.0f) * Mathf.Lerp(node.topLeft, node.top, i / 15.0f) + //Lerp from topLeft to top 0.5f * (1 - ((j - 16.0f) / 15.0f)) * Mathf.Lerp(node.left, node.center, i / 15.0f) + //Lerp from left to center 0.5f * (i / 15.0f) * Mathf.Lerp(node.center, node.top, (j - 16.0f) / 15.0f) + //Lerp from center to top 0.5f * (1 - (i / 15.0f)) * Mathf.Lerp(node.left, node.topLeft, (j - 16.0f) / 15.0f); //Lerp from left to topleft } else { //Top right factor = 0.5f * ((j - 16.0f) / 15.0f) * Mathf.Lerp(node.top, node.topRight, (i - 16.0f) / 15.0f) + //Lerp from top to topRight 0.5f * (1 - ((j - 16.0f) / 15.0f)) * Mathf.Lerp(node.center, node.right, (i - 16.0f) / 15.0f) + //Lerp from center to right 0.5f * ((i - 16.0f) / 15.0f) * Mathf.Lerp(node.right, node.topRight, (j - 16.0f) / 15.0f) + //Lerp from right to topRight 0.5f * (1 - ((i - 16.0f) / 15.0f)) * Mathf.Lerp(node.center, node.top, (j - 16.0f) / 15.0f); //Lerp from center to top } float perlin = Mathf.Clamp(0.33f * Mathf.PerlinNoise(((x * 32 + i) / 2.0f) + seed, ((y * 32 + j) / 2.0f) + seed) + 0.67f * Mathf.PerlinNoise(((x * 32 + i) / 4.0f) + seed, ((y * 32 + j) / 4.0f) + seed), 0, 0.99f); perlin = Mathf.Pow(perlin, 0.55f); return(Mathf.Clamp01(factor) * maps.Length * perlin); }
private void move() { //First get orientation and tiles around me string direction = flanAttributes.direction; GameObject northTile = terrainGeneration.landMap[flanAttributes.x, flanAttributes.y + 1]; GameObject westTile = terrainGeneration.landMap[flanAttributes.x - 1, flanAttributes.y]; GameObject southTile = terrainGeneration.landMap[flanAttributes.x, flanAttributes.y - 1]; GameObject eastTile = terrainGeneration.landMap[flanAttributes.x + 1, flanAttributes.y]; LandNode northLN = northTile.GetComponent <LandNode>(); LandNode westLN = westTile.GetComponent <LandNode>(); LandNode southLN = southTile.GetComponent <LandNode>(); LandNode eastLN = eastTile.GetComponent <LandNode>(); GameObject curTile = terrainGeneration.landMap[flanAttributes.x, flanAttributes.y]; curTile.GetComponent <LandNode>().hasFlan = false; curTile.GetComponent <LandNode>().flanOn = null; //Facing North if (direction == "N") { // Go Forward if (northLN.getBuildingID() == 1) { if (northLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (northLN.flanOn.GetComponent <FlanAI>().willMove(1)) { northLN.hasFlan = true; northLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y + 1); return; } } else { northLN.hasFlan = true; northLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y + 1); return; } } // Go Right if (eastLN.getBuildingID() == 1) { if (eastLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (eastLN.flanOn.GetComponent <FlanAI>().willMove(1)) { eastLN.hasFlan = true; eastLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x + 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 90, transform.eulerAngles.z); return; } } else { eastLN.hasFlan = true; eastLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x + 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 90, transform.eulerAngles.z); return; } } // Go Left if (westLN.getBuildingID() == 1) { if (westLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (westLN.flanOn.GetComponent <FlanAI>().willMove(1)) { westLN.hasFlan = true; westLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x - 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, -90, transform.eulerAngles.z); return; } } else { westLN.hasFlan = true; westLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x - 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, -90, transform.eulerAngles.z); return; } } } //Facing East -90 if (direction == "E") { // Go Forward if (eastLN.getBuildingID() == 1) { if (eastLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (eastLN.flanOn.GetComponent <FlanAI>().willMove(1)) { eastLN.hasFlan = true; eastLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x + 1, 1, flanAttributes.y); return; } } else { eastLN.hasFlan = true; eastLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x + 1, 1, flanAttributes.y); return; } } // Go Right if (southLN.getBuildingID() == 1) { if (southLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (southLN.flanOn.GetComponent <FlanAI>().willMove(1)) { southLN.hasFlan = true; southLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y - 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 180, transform.eulerAngles.z); return; } } else { southLN.hasFlan = true; southLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y - 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 180, transform.eulerAngles.z); return; } } // Go Left if (northLN.getBuildingID() == 1) { if (northLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (northLN.flanOn.GetComponent <FlanAI>().willMove(1)) { northLN.hasFlan = true; northLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y + 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z); return; } } else { northLN.hasFlan = true; northLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y + 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z); return; } } } //Facing South if (direction == "S") { // Go Forward if (southLN.getBuildingID() == 1) { if (southLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (southLN.flanOn.GetComponent <FlanAI>().willMove(1)) { southLN.hasFlan = true; southLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y - 1); return; } } else { southLN.hasFlan = true; southLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y - 1); return; } } // Go Right if (westLN.getBuildingID() == 1) { if (westLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (westLN.flanOn.GetComponent <FlanAI>().willMove(1)) { westLN.hasFlan = true; westLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x - 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, -90, transform.eulerAngles.z); return; } } else { westLN.hasFlan = true; westLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x - 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, -90, transform.eulerAngles.z); return; } } // Go Left if (eastLN.getBuildingID() == 1) { if (eastLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (eastLN.flanOn.GetComponent <FlanAI>().willMove(1)) { eastLN.hasFlan = true; eastLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x + 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 90, transform.eulerAngles.z); return; } } else { eastLN.hasFlan = true; eastLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x + 1, 1, flanAttributes.y); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 90, transform.eulerAngles.z); return; } } } //Facing West if (direction == "W") { // Go Forward if (westLN.getBuildingID() == 1) { if (westLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (westLN.flanOn.GetComponent <FlanAI>().willMove(1)) { westLN.hasFlan = true; westLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x - 1, 1, flanAttributes.y); return; } } else { westLN.hasFlan = true; westLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x - 1, 1, flanAttributes.y); return; } } // Go Right if (northLN.getBuildingID() == 1) { if (northLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (northLN.flanOn.GetComponent <FlanAI>().willMove(1)) { northLN.hasFlan = true; northLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y + 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z); return; } } else { northLN.hasFlan = true; northLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y + 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 0, transform.eulerAngles.z); return; } } // Go Left if (southLN.getBuildingID() == 1) { if (southLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (southLN.flanOn.GetComponent <FlanAI>().willMove(1)) { southLN.hasFlan = true; southLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y - 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 180, transform.eulerAngles.z); return; } } else { southLN.hasFlan = true; southLN.flanOn = this.gameObject; wayPoint = new Vector3(flanAttributes.x, 1, flanAttributes.y - 1); transform.eulerAngles = new Vector3(transform.eulerAngles.x, 180, transform.eulerAngles.z); return; } } } //Can't move? Reset this curTile.GetComponent <LandNode>().hasFlan = true; curTile.GetComponent <LandNode>().flanOn = this.gameObject; }
public bool willMove(int depth) { if (depth > 10) { return(false); } //First get orientation and tiles around me string direction = flanAttributes.direction; GameObject northTile = terrainGeneration.landMap[flanAttributes.x, flanAttributes.y + 1]; GameObject westTile = terrainGeneration.landMap[flanAttributes.x - 1, flanAttributes.y]; GameObject southTile = terrainGeneration.landMap[flanAttributes.x, flanAttributes.y - 1]; GameObject eastTile = terrainGeneration.landMap[flanAttributes.x + 1, flanAttributes.y]; LandNode northLN = northTile.GetComponent <LandNode>(); LandNode westLN = westTile.GetComponent <LandNode>(); LandNode southLN = southTile.GetComponent <LandNode>(); LandNode eastLN = eastTile.GetComponent <LandNode>(); //Facing North if (direction == "N") { // Go Forward if (northLN.getBuildingID() == 1) { if (northLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (northLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Right if (eastLN.getBuildingID() == 1) { if (eastLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (eastLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Left if (westLN.getBuildingID() == 1) { if (westLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (westLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } } //Facing East -90 if (direction == "E") { // Go Forward if (eastLN.getBuildingID() == 1) { if (eastLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (eastLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Right if (southLN.getBuildingID() == 1) { if (southLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (southLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Left if (northLN.getBuildingID() == 1) { if (northLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (northLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } } //Facing South if (direction == "S") { // Go Forward if (southLN.getBuildingID() == 1) { if (southLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (southLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Right if (westLN.getBuildingID() == 1) { if (westLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (westLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Left if (eastLN.getBuildingID() == 1) { if (eastLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (eastLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } } //Facing West if (direction == "W") { // Go Forward if (westLN.getBuildingID() == 1) { if (westLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (westLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Right if (northLN.getBuildingID() == 1) { if (northLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (northLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } // Go Left if (southLN.getBuildingID() == 1) { if (southLN.hasFlan) { //Get Flan on Tile and check if it will move next turn if (southLN.flanOn.GetComponent <FlanAI>().willMove(depth + 1)) { return(true); } } else { return(true); } } } //Cannot move return(false); }
public void GenerateIslandShape(int solveIterations) { //Intialize Array isLand = new int[sizeX][]; for (int i = 0; i < sizeX; i++) { isLand[i] = new int[sizeY]; } //Seed array for (int i = 1; i < sizeX - 1; i++) { for (int j = 1; j < sizeY - 1; j++) { if (Random.value > 0.425f) { isLand[i][j] = 1; } else { isLand[i][j] = 0; } } } for (int solve = 0; solve < solveIterations; solve++) { for (int i = 1; i < sizeX - 1; i++) { for (int j = 1; j < sizeY - 1; j++) { if (isLand[i][j] == 0) { if (isLand[i - 1][j - 1] + isLand[i - 1][j] + isLand[i - 1][j + 1] + isLand[i + 1][j - 1] + isLand[i + 1][j] + isLand[i + 1][j + 1] + isLand[i][j - 1] + isLand[i][j + 1] >= 5) { isLand[i][j] = 1; } } else { if (isLand[i - 1][j - 1] + isLand[i - 1][j] + isLand[i - 1][j + 1] + isLand[i + 1][j - 1] + isLand[i + 1][j] + isLand[i + 1][j + 1] + isLand[i][j - 1] + isLand[i][j + 1] <= 3) { isLand[i][j] = 0; } } } } } landNodes = new LandNode[sizeX][]; for (int i = 0; i < sizeX; i++) { landNodes[i] = new LandNode[sizeY]; for (int j = 0; j < sizeY; j++) { if (i != 0 && j != 0 && isLand[i][j] != 0) { landNodes[i][j] = new LandNode(isLand[i - 1][j + 1], isLand[i][j + 1], isLand[i + 1][j + 1], isLand[i - 1][j], isLand[i + 1][j], isLand[i - 1][j - 1], isLand[i][j - 1], isLand[i + 1][j - 1]); } else { landNodes[i][j] = new LandNode(0, 0, 0, 0, 0, 0, 0, 0); } } } }