Exemplo n.º 1
0
        void digRiverGroups()
        {
            for (int i = 0; i < myRiverGroups.Count; i++)
            {
                RiverGroup group   = myRiverGroups[i];
                River      longest = null;

                //Find longest river in this group
                for (int j = 0; j < group.Rivers.Count; j++)
                {
                    River river = group.Rivers[j];
                    if (longest == null)
                    {
                        longest = river;
                    }
                    else if (longest.myTiles.Count < river.myTiles.Count)
                    {
                        longest = river;
                    }
                }

                if (longest != null)
                {
                    //Dig out longest path first
                    digRiver(longest);

                    for (int j = 0; j < group.Rivers.Count; j++)
                    {
                        River river = group.Rivers[j];
                        if (river != longest)
                        {
                            digRiver(river, longest);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        void buildRiverGroups()
        {
            //loop each tile, checking if it belongs to multiple rivers
            for (var x = 0; x < WorldParameters.theRegionSize; x++)
            {
                for (var y = 0; y < WorldParameters.theRegionSize; y++)
                {
                    Tile t = myTiles[x, y];

                    if (t.Rivers.Count > 1)
                    {
                        // multiple rivers == intersection
                        RiverGroup group = null;

                        // Does a rivergroup already exist for this group?
                        for (int n = 0; n < t.Rivers.Count; n++)
                        {
                            River tileriver = t.Rivers[n];
                            for (int i = 0; i < myRiverGroups.Count; i++)
                            {
                                for (int j = 0; j < myRiverGroups[i].Rivers.Count; j++)
                                {
                                    River river = myRiverGroups[i].Rivers[j];
                                    if (river.myId == tileriver.myId)
                                    {
                                        group = myRiverGroups[i];
                                    }
                                    if (group != null)
                                    {
                                        break;
                                    }
                                }
                                if (group != null)
                                {
                                    break;
                                }
                            }
                            if (group != null)
                            {
                                break;
                            }
                        }

                        // existing group found -- add to it
                        if (group != null)
                        {
                            for (int n = 0; n < t.Rivers.Count; n++)
                            {
                                if (!group.Rivers.Contains(t.Rivers[n]))
                                {
                                    group.Rivers.Add(t.Rivers[n]);
                                }
                            }
                        }
                        else //No existing group found - create a new one
                        {
                            group = new RiverGroup();
                            for (int n = 0; n < t.Rivers.Count; n++)
                            {
                                group.Rivers.Add(t.Rivers[n]);
                            }
                            myRiverGroups.Add(group);
                        }
                    }
                }
            }
        }