public bool removeMapPiece(mapPieceServer target) { bool removedPiece = false; int y = 0; // this will be a counting variable for the second list landCount--; mapPieceServer[] temp = new mapPieceServer[landCount]; for (int x = 0; x < ownedLand.Length; x++) // go through and add existing land besides the one we are removing { if (target != ownedLand[x]) { temp[y] = ownedLand[x]; // if it is not the piece we are removing, add it to the new list y++; } else { removedPiece = true; // otherwise simply dont } } if (removedPiece) // if we actually were able to remove the object, return true { ownedLand = temp; // only need to overwrite return(true); } return(false); }
public void addMapPiece(mapPieceServer data) { landCount++; mapPieceServer[] temp = new mapPieceServer[landCount]; for (int x = 0; x < ownedLand.Length; x++) // go through and add existing land { temp[x] = ownedLand[x]; } temp[landCount - 1] = data; // add the new piece ownedLand = temp; // overwrite old list }
private void CreateMap() { map = new mapPieceServer[mapWidth][]; for (int i = 0; i < map.Length; i++) { map[i] = new mapPieceServer[mapLength]; } // CreateFreeBallRiver(); // Near Random river of near random length at near random location. FEW RESITRCTIONS CreateCuttingRiver(); //River that stretches entire map left to right, cuts the map in half. // FILLS EMPTY SPOTS for (int i = 0; i < mapLength; i++) { for (int j = 0; j < mapWidth; j++) { if (map[i][j] == null) { map[i][j] = new mapPieceServer("Wasteland", 0, "None", "" + i.ToString() + "-" + j.ToString()); // Fill all empty zones with Wasteland /* map[i][j].rH=(int)Math.Round((double)UnityEngine.Random.Range(0, 2)); * map[i][j].tH = (int)Math.Round((double)UnityEngine.Random.Range(0, 2)); * map[i][j].lH = (int)Math.Round((double)UnityEngine.Random.Range(0, 2)); * map[i][j].bH = (int)Math.Round((double)UnityEngine.Random.Range(0, 2)); */ } } } // Save(); /*// Debug.Log("Server should make "+ (mapLength*mapWidth)+" many map pieces"); * int count = 0; * for(int i=0; i < mapLength; i++) * { * for(int j=0; j< mapWidth; j++) * { * int landTypeNum = (int)Math.Round((double)UnityEngine.Random.Range(0,4)); * string landType = "Wasteland"; * switch (landTypeNum) * { * case 0: landType = "Wasteland"; break; * case 1: landType = "Grassland"; break; * case 2: landType = "Water"; break; * case 3: landType = "Mountain"; break; * * } * map[i, j] = new mapPieceServer(landType,0,"None",""+i.ToString()+"-"+j.ToString()); // Creates a new map Piece from scratch * count++; * } * } * // Debug.Log("Server is making " + (count) + " many map pieces"); */ }
private void CreateCuttingRiver() { //Cutting Style int riverWidth = 0; if (UnityEngine.Random.Range(0, 1) < 1) // 100% chance to be width of 2 { riverWidth = 2; } else // otherwise can be 1 through 3 width { riverWidth = (int)Math.Round((double)UnityEngine.Random.Range(0, 3)) + 1; } int i = (int)Math.Round(UnityEngine.Random.Range(mapWidth * 0.3f, mapWidth * 0.7f)); float riverSwitch = 0; bool recentlyTurned = false; // Debug.Log("Should start at " + i + " - " + 0); // Debug.Log("River Width = " + riverWidth); for (int j = 0; j < mapLength; j++) // start at the left part of the map, and go through { // Debug.Log("Currently at " + i + " - " + j); // Debug.Log("if " + j + "<" + mapLength); { for (int x = i; x < i + riverWidth; x++) // goes down up to three times depending on riverWidth { // Debug.Log("if " + x + "<" + mapWidth); if (x < mapWidth) { map[x][j] = new mapPieceServer("Water", 0, "None", "" + x.ToString() + "-" + j.ToString()); // Creates a new map Piece from scratch // Debug.Log("Made water at " + x + " - " + j); } } } riverSwitch = UnityEngine.Random.Range(0, 10); // percent chance to either go down or go up by one block if (!recentlyTurned) { // Debug.Log("Turn number - "+riverSwitch); if (riverSwitch <= 2) { i++; } else if (riverSwitch >= 8.5) { i--; } recentlyTurned = true; } else { recentlyTurned = false; } /* if (i < 0) * i++; * if (i >= riverWidth) * i--; */// This code corrects out of bounds, possible bug tho } }
private void CreateFreeBallRiver() { //FreeBall Style //RIVER STARTS HERE int randomSpotLength = (int)Math.Round(UnityEngine.Random.Range(0, mapLength * 0.8f)); int randomSpotWidth = (int)Math.Round(UnityEngine.Random.Range(0, mapWidth * 0.8f)); int riverWidth = 0; if (UnityEngine.Random.Range(0, 1) < 1) // 100% chance to be width of 2 { riverWidth = 2; } else // otherwise can be 1 through 3 width { riverWidth = (int)Math.Round((double)UnityEngine.Random.Range(0, 3)) + 1; } int i = randomSpotWidth; int j = randomSpotLength; bool riverGoing = true; float chanceToStop = 0; float increaseStop = 0; float riverSwitch = 0; bool recentlyTurned = false; Debug.Log("Should start at " + i + " - " + j); Debug.Log("River Width = " + riverWidth); while (riverGoing) { Debug.Log("Currently at " + i + " - " + j); Debug.Log("while going - " + chanceToStop); Debug.Log("if " + j + "<" + mapLength); if (j < mapLength) { { for (int x = i; x < i + riverWidth; x++)// goes down up to three times depending on riverWidth { Debug.Log("if " + x + "<" + mapWidth); if (x < mapWidth) { map[x][j] = new mapPieceServer("Water", 0, "None", "" + x.ToString() + "-" + j.ToString()); // Creates a new map Piece from scratch Debug.Log("Made water at " + x + " - " + j); } } } riverSwitch = UnityEngine.Random.Range(0, 4); // 25 percent chance to either go down or go up by one block if (!recentlyTurned) { if (riverSwitch <= 1.0) { i++; } else if (riverSwitch >= 3.0) { i--; } recentlyTurned = true; } else { recentlyTurned = false; } /* if (i < 0) * i++; * if (i >= riverWidth) * i--; */// This code corrects out of bounds, possible bug tho if (chanceToStop > UnityEngine.Random.Range(0, 100)) { riverGoing = false; } increaseStop += 1.0f; // percent increase to stop goes up by 1 percent each time, in theory, chanceToStop goes from 0, to 1, to 3, to 6, to 10. chanceToStop += increaseStop; //Simple exponential growth. j++; } else { riverGoing = false; } } // RIVER STOPS HERE }