Exemplo n.º 1
0
        /// <summary>
        /// Generate a desert
        /// </summary>
        /// <param name="pg">LandMass desert belongs to.</param>
        /// <param name="points">Points in desert.</param>
        /// <param name="dist">distance between desert points</param>
        /// <returns>Desert PointGroup</returns>
        public PointGroup GenerateDesert(PointGroup pg, int points, int dist = 5)
        {
            MapPoint            mp  = pg.GetPointFromBounds();
            PointGroupGenerator pgg = new PointGroupGenerator();

            return(pgg.GenerateCluster(mp.X, mp.Y, points, MapTerrain.Desert, dist));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Generate a swamp
        /// </summary>
        /// <param name="pg">LandMass swamp belongs to.</param>
        /// <param name="size">Size of swamp</param>
        /// <param name="dist">distance between swamp points</param>
        /// <returns>Swamp PointGroup</returns>
        public PointGroup GenerateSwamp(PointGroup pg, int size, int dist = 5)
        {
            MapPoint            mp  = pg.GetPointFromBounds();
            PointGroupGenerator pgg = new PointGroupGenerator();

            return(pgg.GenerateCluster(mp.X, mp.Y, size, MapTerrain.Swamp, dist));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Generate a PointGroup with points adjacent to another PointGroup.
        /// </summary>
        /// <param name="size"></param>
        /// <param name="distance"></param>
        /// <param name="angle"></param>
        /// <param name="startbox"></param>
        /// <returns>Adjacent point collection.</returns>
        public PointGroup GenerateAdjacentBox(int size, int distance, int angle, PointGroup startbox, MapTerrain mt)
        {
            PointGenerator pg       = new PointGenerator();
            double         radangle = angle * Math.PI / 180;
            MapPoint       mp       = pg.GenerateAdjacentPoint(startbox.GetAverage(), distance, angle, mt);

            return(GenerateBox(mp.X - size / 2, mp.Y - size / 2, mp.X + size / 2, mp.Y + size / 2, startbox.Count, mt));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Add a range of MapPoints but exclude points of a certain terrain.
 /// </summary>
 /// <param name="pg">PointGroup to add</param>
 /// <param name="mt">MapTerrain to ignore.</param>
 public void AddRangeAlpha(PointGroup pg, MapTerrain mt)
 {
     foreach (MapPoint mp in pg)
     {
         if (mp.Terrain != mt)
         {
             this.Add(mp);
         }
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Generate random points within a box
        /// </summary>
        /// <param name="minx">Minimum X Bound</param>
        /// <param name="miny">Minimum Y Bound</param>
        /// <param name="maxx">Maximum X Bound</param>
        /// <param name="maxy">Maximum Y Bound</param>
        /// <param name="points">Number of points to draw.</param>
        /// <returns>generated MapPointGroup</returns>
        public PointGroup GenerateBox(int minx, int miny, int maxx, int maxy, int points, MapTerrain mt)
        {
            PointGenerator pg  = new PointGenerator();
            PointGroup     mpc = new PointGroup();

            for (int i = 0; i < points; i++)
            {
                mpc.Add(pg.GeneratePoint(minx, miny, maxx, maxy, mt));
            }
            return(mpc);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Generates a chain that deviates slightly by a supplied angle
        /// </summary>
        /// <param name="x1">X Start</param>
        /// <param name="y1">Y Start</param>
        /// <param name="points">Number of points to draw.</param>
        /// <param name="dist">Maximum distance of point.</param>
        /// <param name="startangle">Angle to start in</param>
        /// <param name="anglebound">+- angle to deviate from.</param>
        /// <returns>generated PointGroup</returns>
        public PointGroup GenerateChain(int x1, int y1, int points, int dist, int startangle, int anglebound, MapTerrain mt)
        {
            PointGenerator pg  = new PointGenerator();
            PointGroup     mtc = new PointGroup();

            mtc.Add(new MapPoint(x1, y1, mt));
            for (int i = 1; i < points; i++)
            {
                mtc.Add(pg.GenerateAdjacentPoint((MapPoint)mtc[mtc.Count - 1], rand.Next(1, dist), rand.Next(-anglebound, anglebound), mt));
            }
            return(mtc);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Generate a continent
        /// </summary>
        /// <param name="x">X start</param>
        /// <param name="y">Y start</param>
        /// <param name="clusters">Number of clusters</param>
        /// <param name="clustersize">distance between cluster center nodes</param>
        /// <param name="clusterpoints">Number of points in each cluster.</param>
        /// <returns>Continent</returns>
        public PointGroup GenerateContinent(int x, int y, int clusters, int clustersize, int clusterpoints)
        {
            PointGroupGenerator pgg          = new PointGroupGenerator();
            PointGroup          clusternodes = pgg.GenerateCluster(x, y, clusters, MapTerrain.Plains, clustersize);
            PointGroup          landmass     = new PointGroup();

            foreach (MapPoint mp in clusternodes)
            {
                landmass.AddRange(pgg.GenerateCluster(mp.X, mp.Y, clusterpoints, MapTerrain.Plains, 5));
            }
            return(landmass);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Return a colored GameMap object.
        /// </summary>
        /// <param name="pg">PointGroup to generate map from</param>
        /// <param name="x">Size of map</param>
        /// <param name="y">Size of map</param>
        /// <returns>new GameMap</returns>
        private GameMap ColorMap(PointGroup pg, int x, int y)
        {
            GameMap gamemap = new GameMap(x, y);

            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    MapPoint closest = pg.GetClosest(new MapPoint(i, j, MapTerrain.NONE));
                    gamemap[i, j] = new MapPoint(i, j, closest.Terrain);
                }
            }
            return(gamemap);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Wrap MapPoints around world.
 /// </summary>
 /// <param name="pg">PointGroup to wrap.</param>
 /// <param name="sizex">XSize of map</param>
 /// <returns>Wrapped PointGroup</returns>
 private PointGroup MapWrap(PointGroup pg, int sizex)
 {
     foreach (MapPoint mp in pg)
     {
         if (mp.X < 0)
         {
             mp.X = mp.X + sizex;
         }
         if (mp.X > sizex)
         {
             mp.X = mp.X - sizex;
         }
     }
     return(pg);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Generate a cluster of points that are adjacent to one another.
        /// </summary>
        /// <param name="x">Start X</param>
        /// <param name="y">Start Y</param>
        /// <param name="points">Number of points in cluster</param>
        /// <param name="mt">MapTerrain to color point.</param>
        /// <returns>new PointGroup</returns>
        public PointGroup GenerateCluster(int x, int y, int points, MapTerrain mt, int dist)
        {
            PointGroup     newpg = new PointGroup();
            PointGenerator pg    = new PointGenerator();

            for (int i = 0; i < points; i++)
            {
                if (i == 0)
                {
                    newpg.Add(new MapPoint(x, y, mt));
                }
                else
                {
                    newpg.Add(pg.GenerateAdjacentPoint(newpg[rand.Next(newpg.Count - 1)], dist, rand.Next(360), mt));
                }
            }
            return(newpg);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Generate a TestTerrain
        /// </summary>
        /// <param name="x">Size X</param>
        /// <param name="y">Size Y</param>
        /// <returns>Completed GameMap</returns>
        public GameMap GenerateTestTerran(int x, int y)
        {
            LandMassGenerator lmg      = new LandMassGenerator();
            PointGroup        ocean    = lmg.GenerateOcean(x, y);
            PointGroup        LandMass = new PointGroup();
            PointGroup        IceCaps  = new PointGroup();
            PointGroup        Deserts  = new PointGroup();
            PointGroup        Swamp    = new PointGroup();
            MapConsolidator   mc       = new MapConsolidator();

            //***LandMass***
            //right side of planet
            LandMass.AddRange(lmg.GenerateContinent(x / 4, y / 4, 10, 20, 20));        //Canada region
            LandMass.AddRange(lmg.GenerateContinent(x / 2, y / 4, 4, 10, 10));         //Greenland Region
            LandMass.AddRange(lmg.GenerateContinent(x / 4, y / 3, 7, 20, 30));         //North America region
            LandMass.AddRange(lmg.GenerateContinent(x / 4, y / 2, 4, 10, 10));         //Centeral America Region
            LandMass.AddRange(lmg.GenerateContinent(x / 4, y * 3 / 4, 7, 20, 20));     //South America region
            //left side of planet
            LandMass.AddRange(lmg.GenerateContinent(x * 3 / 4, y / 4, 10, 20, 30));    //Siberia Region
            LandMass.AddRange(lmg.GenerateContinent(x * 2 / 3, y / 3, 4, 10, 10));     //Europe Region
            LandMass.AddRange(lmg.GenerateContinent(x * 2 / 3, y * 2 / 3, 7, 20, 20)); //Africa Region
            LandMass.AddRange(lmg.GenerateContinent(x * 3 / 4, y * 3 / 4, 3, 10, 10)); //Australia Region
            LandMass.AddRange(lmg.GenerateContinent(x * 7 / 8, y / 2, 7, 10, 10));     //Asian Region
            //South Pole
            LandMass.AddRange(lmg.GenerateContinent(x / 2, y, 3, 10, 10));             //South pole land
            IceCaps.AddRange(lmg.GenerateIceCaps(x, y));                               //Ice Caps
            //***LandMass SubRegions***
            //Deserts
            Deserts.AddRange(lmg.GenerateDesert(LandMass, 20, 10));
            Deserts.AddRange(lmg.GenerateDesert(LandMass, 20, 10));
            //Swamps
            Swamp.AddRange(lmg.GenerateSwamp(LandMass, 20, 10));
            Swamp.AddRange(lmg.GenerateSwamp(LandMass, 20, 10));

            LandMass = MapWrap(LandMass, x);
            LandMass = mc.ConsolidateGroupPoints(new List <PointGroup> {
                ocean, LandMass, Deserts, Swamp
            });

            LandMass.AddRange(IceCaps);
            return(ColorMap(LandMass, x, y));
            //return LandMass;
        }
Exemplo n.º 12
0
        /// <summary>
        /// Generate the IceCaps
        /// </summary>
        /// <param name="sizex"></param>
        /// <param name="sizey"></param>
        /// <returns></returns>
        public PointGroup GenerateIceCaps(int sizex, int sizey)
        {
            int miny = sizey / 8;
            int maxy = sizey * 7 / 8;
            PointGroupGenerator pgg = new PointGroupGenerator();

            PointGroup caps = new PointGroup();

            caps.AddRange(pgg.GenerateBox(0, 0, sizex, miny, (sizex + sizey) * 2, MapTerrain.Ice));
            caps.AddRange(pgg.GenerateBox(0, maxy, sizex, sizey, (sizex + sizey) * 2, MapTerrain.Ice));

            foreach (MapPoint mp in caps)
            {
                mp.Terrain = IceOrOcean(mp.Y, sizey);
            }
            PointGroup newpointgroup = new PointGroup();

            newpointgroup.AddRangeAlpha(caps, MapTerrain.Ocean);
            return(newpointgroup);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Consolidate MapPoints, destroyes overlap.
        /// </summary>
        /// <param name="lpg">List of PointGroups to consolidate.</param>
        /// <returns>Consolidated MapPoints.</returns>
        public PointGroup ConsolidateGroupPoints(List <PointGroup> lpg)
        {
            PointGroup ConsolidatedPoints = new PointGroup();
            PointGroup removegroup        = new PointGroup();

            foreach (PointGroup pg in lpg)
            {
                for (int i = 0; i < ConsolidatedPoints.Count; i++)
                {
                    if (pg.InBounds(ConsolidatedPoints[i], 5))
                    {
                        removegroup.Add(ConsolidatedPoints[i]);
                    }
                }
                foreach (MapPoint mp in removegroup)
                {
                    ConsolidatedPoints.Remove(mp);
                }
                removegroup.Clear();
                ConsolidatedPoints.AddRange(pg);
            }
            return(ConsolidatedPoints);
        }
Exemplo n.º 14
0
        public GameMap GenerateTerran()
        {
            PointGroup Land   = new PointGroup();
            PointGroup Desert = new PointGroup();
            PointGroup Swamp  = new PointGroup();
            PointGroup Ocean  = new PointGroup();

            LandMassGenerator lmg = new LandMassGenerator();
            MapConsolidator   mc  = new MapConsolidator();

            //Left Side of Planet
            DrawLandMassStartEvent?.Invoke(this, "Continents");
            Land.AddRange(lmg.GenerateContinent(SizeX / 4, SizeY / 4, MediumContinentPoints, MediumContinentSize, MediumContinentClusterPoints));         //North America
            Land.AddRange(lmg.GenerateContinent(SizeX / 4, SizeY / 2, SmallContinentPoints, SmallContinentSize, SmallContinentClusterPoints));            //Central America
            Land.AddRange(lmg.GenerateContinent(SizeX / 4, SizeY * 3 / 4, MediumContinentPoints, MediumContinentSize, MediumContinentClusterPoints));     //South America
            //Right Side of Planet
            Land.AddRange(lmg.GenerateContinent(SizeX * 7 / 8, SizeY / 4, HugeContinentPoints, HugeContinentSize, HugeContinentClusterPoints));           //Asia
            Land.AddRange(lmg.GenerateContinent(SizeX * 2 / 3, SizeY / 2, SmallContinentPoints, SmallContinentSize, SmallContinentClusterPoints));        //Europe
            Land.AddRange(lmg.GenerateContinent(SizeX * 2 / 3, SizeY * 3 / 4, MediumContinentPoints, MediumContinentSize, MediumContinentClusterPoints)); //Africa
            Land.AddRange(lmg.GenerateContinent(SizeX * 3 / 4, SizeY * 3 / 4, SmallContinentPoints, SmallContinentSize, SmallContinentClusterPoints));    //Oceania
            DrawLandMassFinishEvent?.Invoke(this, "Continents");
            //Deserts
            DrawLandMassStartEvent?.Invoke(this, "Desert");
            Desert.AddRange(lmg.GenerateDesert(Land, IslandPoints));
            Desert.AddRange(lmg.GenerateDesert(Land, IslandPoints));
            Desert.AddRange(lmg.GenerateDesert(Land, IslandPoints));
            DrawLandMassFinishEvent?.Invoke(this, "Desert");
            //Swamp
            DrawLandMassStartEvent?.Invoke(this, "Swamp");
            Swamp.AddRange(lmg.GenerateSwamp(Land, IslandPoints));
            Swamp.AddRange(lmg.GenerateSwamp(Land, IslandPoints));
            Swamp.AddRange(lmg.GenerateSwamp(Land, IslandPoints));
            DrawLandMassFinishEvent?.Invoke(this, "Swamp");
            //Ocean
            DrawLandMassStartEvent?.Invoke(this, "Ocean");
            Ocean.AddRange(lmg.GenerateOcean(SizeX, SizeY));
            DrawLandMassFinishEvent?.Invoke(this, "Ocean");
            //SouthPole
            DrawLandMassStartEvent?.Invoke(this, "Polar caps");
            Land.AddRange(lmg.GenerateContinent(SizeX / 2, SizeY, SmallContinentPoints, SmallContinentSize, SmallContinentClusterPoints)); //Antartica Land
            Land.AddRange(lmg.GenerateIceCaps(SizeX, SizeY));
            DrawLandMassFinishEvent?.Invoke(this, "Polar caps");

            DrawLandMassStartEvent?.Invoke(this, "Consildated Map");
            Land = mc.ConsolidateGroupPoints(new List <PointGroup>()
            {
                Ocean, Land, Desert, Swamp
            });
            DrawLandMassFinishEvent?.Invoke(this, "Consildated Map");

            DrawLandMassStartEvent?.Invoke(this, "Wrap Map");
            Land = MapWrap(Land, SizeX);
            DrawLandMassFinishEvent?.Invoke(this, "Wrap Map");

            DrawLandMassStartEvent?.Invoke(this, "Color map");
            GameMap gamemap = ColorMap(Land, SizeX, SizeY);

            DrawLandMassFinishEvent?.Invoke(this, "Color map");

            return(gamemap);
        }