DigRiver() public method

public DigRiver ( River, river, int size ) : void
river River,
size int
return void
    // 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++;
        }
    }
Beispiel #2
0
    // Dig river based off parent tributary
    private void DigRiver(River river, River parent)
    {
        int intersectionID   = 0;
        int intersectionSize = 0;

        // Find intersection point
        for (int i = 0; i < river.tiles.Count; i++)
        {
            Tile t1 = river.tiles [i];
            for (int j = 0; j < parent.tiles.Count; j++)
            {
                Tile t2 = parent.tiles [j];

                if (t1 == t2)
                {
                    intersectionID   = i;
                    intersectionSize = t2.riverSize;
                }
            }
        }

        int counter           = 0;
        int intersectionCount = river.tiles.Count - intersectionID;
        int size = Random.Range(intersectionSize, 5);

        river.length = river.tiles.Count;

        // Randomise 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;

        // Randomise length of each size
        int count1 = Random.Range(fiveMin, five);

        if (size < 4)
        {
            count1 = 0;
        }

        int count2 = count1 + Random.Range(fourMin, four);

        if (size < 3)
        {
            count1 = 0;
            count2 = 0;
        }

        int count3 = count2 + Random.Range(threeMin, three);

        if (size < 2)
        {
            count1 = 0;
            count2 = 0;
            count3 = 0;
        }

        int count4 = count3 + Random.Range(twoMin, two);

        // Ensure we don't dig 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--;
                }
            }
        }

        // Adjust size of river at intersection point
        if (intersectionSize == 1)
        {
            count4 = intersectionCount;
            count1 = 0;
            count2 = 0;
            count3 = 0;
        }
        else if (intersectionSize == 2)
        {
            count3 = intersectionCount;
            count1 = 0;
            count2 = 0;
        }
        else if (intersectionSize == 3)
        {
            count2 = intersectionCount;
            count1 = 0;
        }
        else if (intersectionCount == 4)
        {
            count1 = intersectionCount;
        }
        else
        {
            count1 = 0;
            count2 = 0;
            count3 = 0;
            count4 = 0;
        }

        // Dig the river
        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++;
        }
    }
    // Dig river based on a parent river vein
    private void DigRiver(River river, River parent)
    {
        int intersectionID   = 0;
        int intersectionSize = 0;

        // determine point of intersection
        for (int i = 0; i < river.Tiles.Count; i++)
        {
            Tile t1 = river.Tiles[i];
            for (int j = 0; j < parent.Tiles.Count; j++)
            {
                Tile t2 = parent.Tiles[j];
                if (t1 == t2)
                {
                    intersectionID   = i;
                    intersectionSize = t2.RiverSize;
                }
            }
        }

        int counter           = 0;
        int intersectionCount = river.Tiles.Count - intersectionID;
        int size = UnityEngine.Random.Range(intersectionSize, 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 length 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--;
                }
            }
        }

        // adjust size of river at intersection point
        if (intersectionSize == 1)
        {
            count4 = intersectionCount;
            count1 = 0;
            count2 = 0;
            count3 = 0;
        }
        else if (intersectionSize == 2)
        {
            count3 = intersectionCount;
            count1 = 0;
            count2 = 0;
        }
        else if (intersectionSize == 3)
        {
            count2 = intersectionCount;
            count1 = 0;
        }
        else if (intersectionSize == 4)
        {
            count1 = intersectionCount;
        }
        else
        {
            count1 = 0;
            count2 = 0;
            count3 = 0;
            count4 = 0;
        }

        // dig out the river
        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++;
        }
    }
Beispiel #4
0
    private void DigRiver(River river)
    {
        int counter = 0;

        // How wide is the river
        int size = Random.Range(1, 5);

        river.length = river.tiles.Count;

        // Randomised 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;

        // Randomise length of each size
        int count1 = Random.Range(fiveMin, five);

        if (size < 4)
        {
            count1 = 0;
        }

        int count2 = count1 + Random.Range(fourMin, four);

        if (size < 3)
        {
            count1 = 0;
            count2 = 0;
        }

        int count3 = count2 + Random.Range(threeMin, three);

        if (size < 2)
        {
            count1 = 0;
            count2 = 0;
            count3 = 0;
        }

        int count4 = count3 + Random.Range(twoMin, two);

        // Ensure we don't dig 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
        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++;
        }
    }