private void RunRiver(TWorld world, CellAddress springLocation) { var rnd = new Random(world.Seed + "rivers".GetHashCode()); var current = springLocation; var river = new River(); var previousSegment = (RiverSegment)null; while (!IsOcean(current.X, current.Y, world)) { var currentCell = world.GetCell(current.X, current.Y); if (currentCell.RiverSegmentHere != null) { // Now a tributary if (river.Segments.Count >= RIVER_MIN_LENGTH) { currentCell.RiverSegmentHere.PreviousSegments.Add(previousSegment); previousSegment.NextSegment = currentCell.RiverSegmentHere; river.TributaryOf = currentCell.RiverSegmentHere.ParentRiver; //world.AddRiver(river); AddFlow(currentCell.RiverSegmentHere, 1); return; } //Too short, abort return; } previousSegment = river.AddSegment(current, previousSegment); current = PickNextLocation(world, current, river, rnd); if (current == null) { //Dead end, abort return; } } //Add the current location to the end of the river. river.AddSegment(current, previousSegment); if (river.Segments.Count < RIVER_MIN_LENGTH) { //Too short, abort return; } //Add river to world //world.AddRiver(river); }