//Looks if any near tile is a suitable end node and returns all possible paths private List <RiverPath> SearchNewPaths(RiverPath localPath, ICollection <Location> map) { var coordX = localPath.LastX(); var coordY = localPath.LastY(); List <RiverPath> newPaths = new List <RiverPath>(); currentRiverAltitude = map.First(l => l.XCoord == coordX && l.YCoord == coordY).Altitude; if (localPath.MoveCheck(1 + coordX, coordY, currentRiverAltitude, map)) { newPaths.Add(AddPath(1 + coordX, coordY, localPath, map)); } if (localPath.MoveCheck(coordX - 1, coordY, currentRiverAltitude, map)) { newPaths.Add(AddPath(coordX - 1, coordY, localPath, map)); } if (localPath.MoveCheck(coordX, 1 + coordY, currentRiverAltitude, map)) { newPaths.Add(AddPath(coordX, 1 + coordY, localPath, map)); } if (localPath.MoveCheck(coordX, coordY - 1, currentRiverAltitude, map)) { newPaths.Add(AddPath(coordX, coordY - 1, localPath, map)); } return(newPaths); }
private RiverPath SelectRandomPath(List <RiverPath> PossibleRiverPaths) { altitudeChanged = false; int randomInt = (PossibleRiverPaths.Count == 0) ? 0:RngThreadSafe.Next(0, (PossibleRiverPaths.Count)); RiverPath chosenRiverPath = PossibleRiverPaths[randomInt]; return(chosenRiverPath); }
//checks if a riverpath is looping by checking a coördinate is dublicate inside of the array of coördinates private bool CheckCoördinateDuplicacy(RiverPath riverPath) { foreach (coordinate coördinate in riverPath.riverCoördinates) { if (riverPath.riverCoördinates.Where(r => r.X == coördinate.X && r.Y == coördinate.Y).Count() > 1) // checks if searching for the object from the start and from the back returns the same position { return(true); } } return(false); }
private List <RiverPath> Setup(int coördinateX, int coördinateY, ICollection <Location> map) { RiverPath startingPath = new RiverPath(); // the first route creation coordinate startingPosition = new coordinate(coördinateX, coördinateY); // the first coördinate of the first route startingPath.riverCoördinates.Add(startingPosition); currentRiverAltitude = map.First(l => l.XCoord == coördinateX && l.YCoord == coördinateY).Altitude; List <RiverPath> startingList = new List <RiverPath>(); startingList.Add(startingPath); return(startingList); }
public River(Lake parent, Lake child, List <River> generatedRivers, System.Random rnd) { parentLake = parent; childLake = child; rivers = generatedRivers; angleBetweenLakes = CalculateAngle(parent, child); childStartPoint = GenerateRiverFlowPoint(child, angleBetweenLakes); parentEndPoint = GenerateRiverFlowPoint(parent, angleBetweenLakes - Mathf.PI); FindAnchorPoints(parent, child, rnd); path = new RiverPath(anchorPoints); CreateRiverPoints(); SetRiverPointHeight(); }
// removes the riverPath from the PossiblePaths if it is a old, higheraltitude or looping path private bool CheckIfOldHighgroundOrInverting(List <RiverPath> riverPaths, RiverPath riverPath, ICollection <Location> map) { if (riverPath.riverCoördinates.Count < currentRiverLength) // checks the old { return(false); } else if (map.First(l => l.XCoord == riverPath.LastX() && l.YCoord == riverPath.LastY()).Altitude > currentRiverAltitude) // pakt de lokatie van de map zoals aangegeven in de coördinaten { return(false); } // removes all riverPaths that don't go downward else if (CheckCoördinateDuplicacy(riverPath)) //checks for dublicate positions in the path { return(false); } else { return(true); } }
// returns a set of coördinates on which the river runs private RiverPath FindRiverPath(int coördinateX, int coördinateY, ICollection <Location> map) { //Sets up the system List <RiverPath> possibleRiverWays = Setup(coördinateX, coördinateY, map); //Starts searching for a way to a river, ocean or lake possibleRiverWays = RecursiveRiverCreator(possibleRiverWays, map); List <RiverPath> newRiverWays = new List <RiverPath>(); foreach (RiverPath RiverPath in possibleRiverWays) { if (RiverPath.EndCheck(RiverPath.LastX(), RiverPath.LastY(), map)) { newRiverWays.Add(RiverPath); } } //SelectRandomPath(newRiverWays); return(newRiverWays[0]); }
private RiverPath AddPath(int coördinateX, int coördinateY, RiverPath oldPath, ICollection <Location> map) { bool endNodeFoundChecker = false; coordinate newCoördinate = new coordinate(coördinateX, coördinateY); RiverPath newRiverPath = new RiverPath(oldPath, newCoördinate); if (oldPath.EndCheck(coördinateX, coördinateY, map)) { endNodeFound = true; endNodeFoundChecker = true; } if (map.First(l => l.XCoord == coördinateX && l.YCoord == coördinateY).Altitude < currentRiverAltitude) { altitudeChanged = true; } if (endNodeFoundChecker) { newRiverPath.hasAnEndNode = true; } return(newRiverPath); }
//sets all the coördinates it gets from the FindRiver method to river tiles public ICollection <Location> CreateRiver(int coördinateX, int coördinateY, ICollection <Location> map) { RiverPath FinalRiverPath = FindRiverPath(coördinateX, coördinateY, map); FinalRiverPath.riverCoördinates.RemoveAt(FinalRiverPath.riverCoördinates.Count - 1); foreach (coordinate coördinate in FinalRiverPath.riverCoördinates) { var tempLocation = map.Single(l => l.XCoord == coördinate.X && l.YCoord == coördinate.Y); map.Remove(tempLocation); var newRiverTile = new River(coördinate.X, coördinate.Y); map.Add(newRiverTile); } if (madeALake) { map = MakeALake(lakeCoördinate, map); } CleanUp(); return(map); }
private void CreateRiverSprites(World world) { List <Line> paths = new List <Line>(); for (int i = 0; i < m_generation.riverPath.Count; i++) { // The last point goes nowhere and in included in Count - 2 if (i == m_generation.riverPath.Count - 1) { break; } RiverPath start = m_generation.riverPath[i]; Point cs = world.layout.HexCornerOffset(start.corner); Point hs = world.layout.HexToPixel(start.from.hex); Point ptStart = new Point(cs.x + hs.x, cs.y + hs.y); RiverPath end = m_generation.riverPath[i + 1]; Point ce = world.layout.HexCornerOffset(end.corner); Point he = world.layout.HexToPixel(end.from.hex); Point ptEnd = new Point(ce.x + he.x, ce.y + he.y); Line line = new Line(ptStart, ptEnd); paths.Add(line); // Sets sides of TileObject that contain rivers end.from.SetRiver(end.corner, true); } for (int i = 0; i < paths.Count; i++) { // Increases river's width m_river.riverWidth++; Line path = paths[i]; //RiverPath riverPart = m_generation.riverPath[i]; Vector3 posStart = new Vector3((float)path.pt0.x, (float)path.pt0.y); Vector3 posEnd = new Vector3((float)path.pt1.x, (float)path.pt1.y); posStart.z = posEnd.z; // ensure there is no 3D rotation by aligning Z position // vector from this object towards the target location Vector3 vectorToTarget = posStart - posEnd; // rotate that vector by 90 degrees around the Z axis Vector3 rotatedVectorToTarget = Quaternion.Euler(0, 0, 90) * vectorToTarget; // get the rotation that points the Z axis forward, and the Y axis 90 degrees away from the target // (resulting in the X axis facing the target) Quaternion targetRotation = Quaternion.LookRotation(forward: Vector3.forward, upwards: rotatedVectorToTarget); GameObject part = Instantiate(m_riverPartPrefab, posStart, targetRotation, this.transform); SpriteRenderer renderer = part.GetComponent <SpriteRenderer>(); m_parts.Add(renderer); if (i == 0) // Is start { HandleRiverStart(part, renderer); } else if (i == paths.Count - 1) // Is end { HandleRiverEnd(part, renderer); } else { HandleRiverPath(part, renderer); } } }