Beispiel #1
0
        // Dig river
        private void DigRiver(River river)
        {
            int counter = 0;

            // How wide are we digging this river?
            int size = rng.Next(1, 5);

            //DEF: Try this
            //int size = 1;
            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 = rng.Next(fivemin, five);

            if (size < 4)
            {
                count1 = 0;
            }
            int count2 = count1 + rng.Next(fourmin, four);

            if (size < 3)
            {
                count2 = 0;
                count1 = 0;
            }
            int count3 = count2 + rng.Next(threemin, three);

            if (size < 2)
            {
                count3 = 0;
                count2 = 0;
                count1 = 0;
            }
            int count4 = count3 + rng.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--)
            {
                WorldTile t = river.Tiles[i];

                if (counter < count1 && MaxRiverSize > 3)
                {
                    t.DigRiver(river, 4);
                }
                else if (counter < count2 && MaxRiverSize > 2)
                {
                    t.DigRiver(river, 3);
                }
                else if (counter < count3 && MaxRiverSize > 1)
                {
                    t.DigRiver(river, 2);
                }
                else if (counter < count4 && MaxRiverSize > 0)
                {
                    t.DigRiver(river, 1);
                }
                else
                {
                    t.DigRiver(river, 0);
                }
                counter++;
            }
        }
Beispiel #2
0
        // 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++)
            {
                WorldTile t1 = river.Tiles[i];
                for (int j = 0; j < parent.Tiles.Count; j++)
                {
                    WorldTile t2 = parent.Tiles[j];
                    if (t1 == t2)
                    {
                        intersectionID   = i;
                        intersectionSize = t2.TerrainData.RiverSize;
                    }
                }
            }

            int counter           = 0;
            int intersectionCount = river.Tiles.Count - intersectionID;
            int size = rng.Next(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 = rng.Next(fivemin, five);

            if (size < 4)
            {
                count1 = 0;
            }
            int count2 = count1 + rng.Next(fourmin, four);

            if (size < 3)
            {
                count2 = 0;
                count1 = 0;
            }
            int count3 = count2 + rng.Next(threemin, three);

            if (size < 2)
            {
                count3 = 0;
                count2 = 0;
                count1 = 0;
            }
            int count4 = count3 + rng.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--;
                    }
                }
            }

            // 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--)
            {
                WorldTile t = river.Tiles[i];

                if (counter < count1 && MaxRiverSize > 3)
                {
                    t.DigRiver(river, 4);
                }
                else if (counter < count2 && MaxRiverSize > 2)
                {
                    t.DigRiver(river, 3);
                }
                else if (counter < count3 && MaxRiverSize > 1)
                {
                    t.DigRiver(river, 2);
                }
                else if (counter < count4 && MaxRiverSize > 0)
                {
                    t.DigRiver(river, 1);
                }
                else
                {
                    t.DigRiver(river, 0);
                }
                counter++;
            }
        }