示例#1
0
 public ContinentPoint WorldPointContinentToContinentPoint(WorldPointContinent wp, Continent plate)
 {
     if (!plate.Points.ContainsKey(wp.Pos - plate.WorldPointCenter.Pos))
     {
         return(null);
     }
     return(plate.Points[wp.Pos - plate.WorldPointCenter.Pos]);
 }
示例#2
0
 public Vector2 WorldPointContinentToContinentPointVector2(WorldPointContinent wp, Continent plate)
 {
     return(wp.Pos - plate.WorldPointCenter.Pos);
 }
示例#3
0
        public void Move(Continent continent)
        {
            Vector2 direction              = Vector2.zero;
            int     offWorldPoints         = 0;
            int     offWorldPointDirection = 0;

            foreach (ContinentPoint point in continent.Points.Values)
            {
                WorldPointContinent wpc = continent.ContinentPointToWorldPoint(point, this);
                if (wpc == null)
                {
                    offWorldPoints++;
                    offWorldPointDirection += (point.Pos + continent.WorldPointCenter.Pos).y > 0 ? -1 : 1;
                    continue;
                }
                wpc.contPoint = null;
            }

            if (offWorldPoints > 10)
            {
                continent.driftDuration  = Random.Range(5, 15);
                continent.driftDirection = new Vector2(Random.Range(-1, 2), offWorldPointDirection > 0 ? 1 : -1);
            }
            if (continent.driftDuration == 0)
            {
                float val = 0;
                continent.driftDuration = Random.Range(5, 15);
                val = Random.Range(0f, 100f) / 100f;
                if (val < 0.12f)
                {
                    direction = new Vector2(-1, 0);
                }
                else if (val < 0.25f)
                {
                    direction = new Vector2(-1, -1);
                }
                else if (val < 0.37f)
                {
                    direction = new Vector2(0, -1);
                }
                else if (val < 0.5f)
                {
                    direction = new Vector2(1, -1);
                }
                else if (val < 0.62f)
                {
                    direction = new Vector2(1, 0);
                }
                else if (val < 0.75f)
                {
                    direction = new Vector2(1, 1);
                }
                else if (val < 0.87f)
                {
                    direction = new Vector2(0, 1);
                }
                else
                {
                    direction = new Vector2(-1, 1);
                }
                continent.driftDirection = direction;
            }
            else
            {
                continent.driftDuration--;
                direction = continent.driftDirection;
            }
            //float val = MantleData.GetData(age, octaves, lac, pers, multi)[continent.WorldPointCenter.Pos];


            Vector2 newPoint = continent.WorldPointCenter.Pos + direction;

            if (newPoint.x > 99)
            {
                newPoint += new Vector2(-Width, 0);
            }
            if (newPoint.x < 0)
            {
                newPoint += new Vector2(Width, 0);
            }
            if (newPoint.y < 0 || newPoint.y > 99)
            {
                return;//continue;
            }
            continent.WorldPointCenter = WorldPointContinents[newPoint];
        }
示例#4
0
 public void AdditionalSubduction(WorldPointContinent origSubductionPoint, Continent subductingContinent, Continent growingContinent)
 {
     //if (Random.Range(0, 2) == 0)
     {
         if (WorldPointContinents.ContainsKey(origSubductionPoint.Pos + subductingContinent.driftDirection))
         {
             WorldPointContinent AddedHeightPoint = WorldPointContinents[origSubductionPoint.Pos + subductingContinent.driftDirection];
             ContinentPoint      cp = WorldPointContinentToContinentPoint(AddedHeightPoint, growingContinent);
             if (cp != null)
             {
                 cp.height++;
             }
         }
     }
 }
示例#5
0
        public void RecalculateWorldPointContinents(Continent Cont)
        {
            //foreach (Continent plate in Plates)
            {
                Dictionary <ContinentPoint, ContinentPoint> Collisions = new Dictionary <ContinentPoint, ContinentPoint>();
                foreach (ContinentPoint point in Cont.Points.Values)
                {
                    WorldPointContinent wp = Cont.ContinentPointToWorldPoint(point, this);
                    if (wp != null)
                    {
                        if (wp.contPoint != null)
                        {
                            Collisions.Add(wp.contPoint, point);
                        }
                        else
                        {
                            wp.contPoint = point;
                        }
                    }
                }
                foreach (Continent collCont in Collisions.Select(p => p.Key.cont).Distinct())
                {
                    Dictionary <ContinentPoint, ContinentPoint> ContinentCollisionPoints = Collisions.Where(p => p.Key.cont == collCont).ToDictionary(p => p.Key, p => p.Value);


                    if (ContinentCollisionPoints.Count < 10)
                    //if ((float)ContinentCollisionPoints.Count / (float)collCont.Points.Count < 0.025f)
                    {
                        foreach (var pair in ContinentCollisionPoints)
                        {
                            //not big enough to be collision, smaller one subducts
                            WorldPointContinent wp         = collCont.ContinentPointToWorldPoint(pair.Key, this);
                            ContinentPoint      theirPoint = pair.Key;
                            ContinentPoint      ourPoint   = pair.Value;
                            if (Cont.GetNeighbors(ourPoint).Count < 3)
                            {
                                //island or something, we give it to them
                                theirPoint.height += 2;
                                Cont.Points.Remove(ourPoint.Pos);

                                /*Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos;
                                 * ContinentPoint theirNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont);
                                 * theirNewPoint.height = theirPoint.height;
                                 * if (!collCont.Points.ContainsKey(theirNewPoint.Pos))
                                 * {
                                 *  collCont.Points.Add(theirNewPoint.Pos, theirNewPoint);
                                 *  WorldPointContinent wp2 = collCont.ContinentPointToWorldPoint(theirNewPoint, this);
                                 *  if (wp2 != null)
                                 *      wp2.contPoint = theirNewPoint;
                                 * }*/
                                // if(Random.Range(0,2) == 0)
                                AdditionalSubduction(wp, Cont, collCont);
                            }
                            else if (collCont.GetNeighbors(theirPoint).Count < 3)
                            {
                                //we are colliding with an island
                                ourPoint.height += 2;
                                wp.contPoint     = ourPoint;
                                collCont.Points.Remove(theirPoint.Pos);

                                /* Vector2 worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos;
                                 * ContinentPoint ourNewPoint = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont);
                                 * ourNewPoint.height = theirPoint.height;
                                 * if (!Cont.Points.ContainsKey(ourNewPoint.Pos))
                                 * {
                                 *   Cont.Points.Add(ourNewPoint.Pos, ourNewPoint);
                                 *   WorldPointContinent wp2 = Cont.ContinentPointToWorldPoint(ourNewPoint, this);
                                 *   if (wp2 != null)
                                 *       wp2.contPoint = ourNewPoint;
                                 * }*/
                                AdditionalSubduction(wp, collCont, Cont);
                            }
                            else if (ourPoint.height > theirPoint.height) //cont already there subducts
                            {
                                ourPoint.height += 2;
                                wp.contPoint     = ourPoint;
                                collCont.Points.Remove(theirPoint.Pos);
                                // if (Random.Range(0, 2) == 0)
                                AdditionalSubduction(wp, collCont, Cont);
                            }
                            else //our cont subducts
                            {
                                theirPoint.height += 2;
                                Cont.Points.Remove(ourPoint.Pos);
                                //if (Random.Range(0, 2) == 0)
                                AdditionalSubduction(wp, Cont, collCont);
                            }
                        }
                    }
                    else
                    {
                        //big enough, the continents become one
                        //first fix collision points
                        foreach (var pair in ContinentCollisionPoints)
                        {
                            WorldPointContinent wp         = collCont.ContinentPointToWorldPoint(pair.Key, this);
                            ContinentPoint      theirPoint = pair.Key;
                            ContinentPoint      ourPoint   = pair.Value;
                            wp.contPoint = ourPoint;
                            ourPoint.height++;
                            collCont.Points.Remove(theirPoint.Pos);
                            AdditionalSubduction(wp, collCont, Cont);
                        }
                        //then move their cont points to our continent
                        foreach (ContinentPoint theirPoint in collCont.Points.Values)
                        {
                            Vector2        worldPosition = collCont.WorldPointCenter.Pos + theirPoint.Pos;
                            ContinentPoint ourNewPoint   = new ContinentPoint(worldPosition - Cont.WorldPointCenter.Pos, Cont);
                            ourNewPoint.height = theirPoint.height;
                            if (!Cont.Points.ContainsKey(ourNewPoint.Pos))
                            {
                                Cont.Points.Add(ourNewPoint.Pos, ourNewPoint);
                                WorldPointContinent wp = Cont.ContinentPointToWorldPoint(ourNewPoint, this);
                                if (wp != null)
                                {
                                    wp.contPoint = ourNewPoint;
                                }
                            }
                        }
                        DeletedContinents.Add(collCont);
                    }
                }
            }
        }
示例#6
0
        public void SplitContinent(Continent c)
        {
            //first split
            Dictionary <Vector2, List <Vector2> > voronoiCenters = new Dictionary <Vector2, List <Vector2> >();
            int worldXMin = (int)c.Points.Min(p => p.Key.x) + (int)c.WorldPointCenter.Pos.x;
            int worldXMax = (int)c.Points.Max(p => p.Key.x) + (int)c.WorldPointCenter.Pos.x;
            int worldYMin = (int)c.Points.Min(p => p.Key.y) + (int)c.WorldPointCenter.Pos.y;
            int worldYMax = (int)c.Points.Max(p => p.Key.y) + (int)c.WorldPointCenter.Pos.y;

            //now split the continent
            Vector2 cont1 = new Vector2(Random.Range(worldXMin, worldXMax), Random.Range(worldYMin, worldYMax));
            Vector2 cont2 = new Vector2(Random.Range(worldXMin, worldXMax), Random.Range(worldYMin, worldYMax));

            if (!WorldPointContinents.ContainsKey(cont1) || !WorldPointContinents.ContainsKey(cont2))
            {
                return;
            }

            Continent newCont1 = new Continent(c.WorldPointCenter);
            Continent newCont2 = new Continent(c.WorldPointCenter);

            for (int i = 0; i < 20; i++)
            {
                Vector2 voronoi = new Vector2(Random.Range(worldXMin, worldXMax), Random.Range(worldYMin, worldYMax));
                voronoiCenters.Add(voronoi, new List <Vector2>());
            }
            foreach (ContinentPoint cp in c.Points.Values)
            {
                Vector2 cpWorldPos   = cp.Pos + c.WorldPointCenter.Pos;
                float   shortestDist = 9999;
                Vector2 voronoi      = Vector2.zero;
                foreach (var pair in voronoiCenters)
                {
                    float dist = Vector2.Distance(cpWorldPos, pair.Key);
                    if (dist < shortestDist)
                    {
                        shortestDist = dist;
                        voronoi      = pair.Key;
                    }
                }
                voronoiCenters[voronoi].Add(cp.Pos);
            }

            List <ContinentPoint> con1Points = new List <ContinentPoint>();
            List <ContinentPoint> con2Points = new List <ContinentPoint>();

            foreach (var pair in voronoiCenters)
            {
                float dist1 = Vector2.Distance(cont1, pair.Key);
                float dist2 = Vector2.Distance(cont2, pair.Key);
                if (dist1 < dist2)
                {
                    foreach (Vector2 v in pair.Value)
                    {
                        ContinentPoint newCP = new ContinentPoint(v - cont1, newCont1);
                        newCP.height = c.Points[v].height;
                        con1Points.Add(newCP);
                    }
                }
                else
                {
                    foreach (Vector2 v in pair.Value)
                    {
                        ContinentPoint newCP = new ContinentPoint(v - cont2, newCont2);
                        newCP.height = c.Points[v].height;
                        con2Points.Add(newCP);
                    }
                }
            }
            newCont1.driftDirection = (cont1 - cont2).normalized;
            newCont1.driftDirection = new Vector2((int)newCont1.driftDirection.x + 1, (int)newCont1.driftDirection.y + 1);
            newCont2.driftDirection = (cont2 - cont1).normalized;
            newCont2.driftDirection = new Vector2((int)newCont2.driftDirection.x + 1, (int)newCont2.driftDirection.y + 1);
            newCont1.driftDuration  = 15;
            newCont2.driftDuration  = 15;
            Continents.Add(newCont1);
            Continents.Add(newCont2);
            Continents.Remove(c);
            lastContBreak = age;
        }
 public ContinentPoint(Vector2 pos, Continent cont_)
 {
     Pos  = pos;
     cont = cont_;
 }