public DigRiver ( River, river, int size ) : void | ||
river | River, | |
size | int | |
return | void |
public void DigRiver(River river, int size)
{
SetRiverTile (river);
RiverSize = size;
if (size == 1) {
if (Bottom != null)
{
Bottom.SetRiverTile (river);
if (Bottom.Right != null) Bottom.Right.SetRiverTile (river);
}
if (Right != null) Right.SetRiverTile (river);
}
if (size == 2) {
if (Bottom != null) {
Bottom.SetRiverTile (river);
if (Bottom.Right != null) Bottom.Right.SetRiverTile (river);
}
if (Right != null) {
Right.SetRiverTile (river);
}
if (Top != null) {
Top.SetRiverTile (river);
if (Top.Left != null) Top.Left.SetRiverTile (river);
if (Top.Right != null)Top.Right.SetRiverTile (river);
}
if (Left != null) {
Left.SetRiverTile (river);
if (Left.Bottom != null) Left.Bottom.SetRiverTile (river);
}
}
if (size == 3) {
if (Bottom != null) {
Bottom.SetRiverTile (river);
if (Bottom.Right != null) Bottom.Right.SetRiverTile (river);
if (Bottom.Bottom != null)
{
Bottom.Bottom.SetRiverTile (river);
if (Bottom.Bottom.Right != null) Bottom.Bottom.Right.SetRiverTile (river);
}
}
if (Right != null) {
Right.SetRiverTile (river);
if (Right.Right != null)
{
Right.Right.SetRiverTile (river);
if (Right.Right.Bottom != null) Right.Right.Bottom.SetRiverTile (river);
}
}
if (Top != null) {
Top.SetRiverTile (river);
if (Top.Left != null) Top.Left.SetRiverTile (river);
if (Top.Right != null)Top.Right.SetRiverTile (river);
}
if (Left != null) {
Left.SetRiverTile (river);
if (Left.Bottom != null) Left.Bottom.SetRiverTile (river);
}
}
if (size == 4) {
if (Bottom != null) {
Bottom.SetRiverTile (river);
if (Bottom.Right != null) Bottom.Right.SetRiverTile (river);
if (Bottom.Bottom != null)
{
Bottom.Bottom.SetRiverTile (river);
if (Bottom.Bottom.Right != null) Bottom.Bottom.Right.SetRiverTile (river);
}
}
if (Right != null) {
Right.SetRiverTile (river);
if (Right.Right != null)
{
Right.Right.SetRiverTile (river);
if (Right.Right.Bottom != null) Right.Right.Bottom.SetRiverTile (river);
}
}
if (Top != null) {
Top.SetRiverTile (river);
if (Top.Right != null) {
Top.Right.SetRiverTile (river);
if (Top.Right.Right != null) Top.Right.Right.SetRiverTile (river);
}
if (Top.Top != null)
{
Top.Top.SetRiverTile (river);
if (Top.Top.Right != null) Top.Top.Right.SetRiverTile (river);
}
}
if (Left != null) {
Left.SetRiverTile (river);
if (Left.Bottom != null) {
Left.Bottom.SetRiverTile (river);
if (Left.Bottom.Bottom != null) Left.Bottom.Bottom.SetRiverTile (river);
}
if (Left.Left != null) {
Left.Left.SetRiverTile (river);
if (Left.Left.Bottom != null) Left.Left.Bottom.SetRiverTile (river);
if (Left.Left.Top != null) Left.Left.Top.SetRiverTile (river);
}
if (Left.Top != null)
{
Left.Top.SetRiverTile (river);
if (Left.Top.Top != null) Left.Top.Top.SetRiverTile (river);
}
}
}
}
// Dig river private void DigRiver(River river) { int counter = 0; // How wide are we digging this river? int size = UnityEngine.Random.Range(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 = UnityEngine.Random.Range(fivemin, five); if (size < 4) { count1 = 0; } int count2 = count1 + UnityEngine.Random.Range(fourmin, four); if (size < 3) { count2 = 0; count1 = 0; } int count3 = count2 + UnityEngine.Random.Range(threemin, three); if (size < 2) { count3 = 0; count2 = 0; count1 = 0; } int count4 = count3 + UnityEngine.Random.Range(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++; } }