// Dig river
private void DigRiver(River river)
{
int counter = 0;
// How wide are we digging this river?
int size = Random.Next(1, 5);
river.Length = river.Tiles.Count;
// randomize size change
int two = river.Length / 2;
int three = two / 2;
int four = three / 2;
int five = four / 2;
int twomin = two / 3;
int threemin = three / 3;
int fourmin = four / 3;
int fivemin = five / 3;
// randomize lenght of each size
int count1 = Random.Next(fivemin, five);
if (size < 4)
{
count1 = 0;
}
int count2 = count1 + Random.Next(fourmin, four);
if (size < 3)
{
count2 = 0;
count1 = 0;
}
int count3 = count2 + Random.Next(threemin, three);
if (size < 2)
{
count3 = 0;
count2 = 0;
count1 = 0;
}
int count4 = count3 + Random.Next(twomin, two);
// Make sure we are not digging past the river path
if (count4 > river.Length)
{
int extra = count4 - river.Length;
while (extra > 0)
{
if (count1 > 0)
{
count1--; count2--; count3--; count4--; extra--;
}
else if (count2 > 0)
{
count2--; count3--; count4--; extra--;
}
else if (count3 > 0)
{
count3--; count4--; extra--;
}
else if (count4 > 0)
{
count4--; extra--;
}
}
}
// Dig it out
for (int i = river.Tiles.Count - 1; i >= 0; i--)
{
Tile t = river.Tiles[i];
if (counter < count1)
{
t.DigRiver(river, 4);
}
else if (counter < count2)
{
t.DigRiver(river, 3);
}
else if (counter < count3)
{
t.DigRiver(river, 2);
}
else if (counter < count4)
{
t.DigRiver(river, 1);
}
else
{
t.DigRiver(river, 0);
}
counter++;
}
}