Exemplo n.º 1
0
        public List <Area> GetNeighborAreas(Area targetArea)
        {
            List <Area>    neighbors = new List <Area>();
            ClipperUtility utility   = new ClipperUtility();

            foreach (Area area in areas.Values)
            {
                if (utility.AreSurfacesNear(area, targetArea))
                {
                    neighbors.Add(area);
                }
            }
            return(neighbors);
        }
Exemplo n.º 2
0
        void CreateAreas()
        {
            List <Area>    europeAreas = new List <Area>();
            List <Area>    otherAreas  = new List <Area>();
            List <Area>    testAreas   = new List <Area>();
            ClipperUtility utility     = new ClipperUtility();
            Area           targetArea  = areas["Kharkiv"];

            foreach (Area area in areas.Values)
            {
                if (area.counterpart == "SLAV EMPIRE")
                {
                    europeAreas.Add(area);
                }
                else
                {
                    otherAreas.Add(area);
                }
                if (utility.AreSurfacesNear(area, targetArea))
                {
                    testAreas.Add(area);
                }
            }
            List <Terrain> lands = terrainLayouter.CreateLandscapesForAreas(ref testAreas);

            foreach (Terrain terrain in lands)
            {
                CreateAreaSurface(terrain, terrainLayouter.MaterialForSurface(terrain), terrainsObject);
            }
            List <Terrain> objs = terrainLayouter.CreateLayoutForAreas(ref testAreas);

            foreach (Terrain terrain in objs)
            {
                CreateAreaSurface(terrain, terrainLayouter.MaterialForSurface(terrain), terrainsObject);
            }

            foreach (Area area in europeAreas)
            {
                CreateAreaSurface(area, terrainLayouter.MaterialForSurface(area), areaBackgroundObject);
                CreateAreaTerrainsSurfaces(area);
                CreateAreaBorder(area, areaBorderMaterial);
                area.lockedOverlay = CreateAreaSurface(area, areaLockedMaterial, mapOverlayObject);
            }
            foreach (Area area in otherAreas)
            {
                CreateAreaSurface(area, areaBackgroundMaterial, areaBackgroundObject);
                CreateAreaBorder(area, areaBorderMaterial);
            }
        }
Exemplo n.º 3
0
        public float getResidualNoise(Vector2 point, List <Terrain> terrains)
        {
            float          height  = getNoise(point);
            ClipperUtility utility = new ClipperUtility();
            int            levels  = 0;

            foreach (Terrain terrain in terrains)
            {
                if (utility.IsPointInsideSurface(point, terrain))
                {
                    levels++;
                }
            }
            height -= noiseLevels[Mathf.Min(noiseLevels.Count - 1, levels)];
            return(height);
        }
Exemplo n.º 4
0
        public List <Terrain> CreateLayoutForAreas(ref List <Area> areas)
        {
            List <Terrain> terrains = new List <Terrain>();

            if (areas.Count == 0)
            {
                return(terrains);
            }
            Vector2        minBound     = areas[0].borderRect.min;
            Vector2        maxBound     = areas[0].borderRect.max;
            List <Vector2> chunkCenters = new List <Vector2>();

            foreach (Area area in areas)
            {
                minBound.x = Mathf.Min(minBound.x, area.borderRect.min.x);
                minBound.y = Mathf.Min(minBound.y, area.borderRect.min.y);
                maxBound.x = Mathf.Max(maxBound.x, area.borderRect.max.x);
                maxBound.y = Mathf.Max(maxBound.y, area.borderRect.max.y);
            }
            int            counter = 0;
            ClipperUtility utility = new ClipperUtility();

            while (counter < 10)
            {
                counter++;
                Vector2 newCenter = new Vector2(Random.Range(minBound.x, maxBound.x), Random.Range(minBound.y, maxBound.y));
                bool    isInside  = false;
                int     areaIndex = 0;
                foreach (Area area in areas)
                {
                    if (utility.IsPointInsideSurface(newCenter, area))
                    {
                        isInside = true;
                        break;
                    }
                    areaIndex++;
                }
                if (!isInside)
                {
                    continue;
                }
                bool isTooClose = false;
                foreach (Vector2 center in chunkCenters)
                {
                    if ((newCenter - center).magnitude < 2 * chunkSize)
                    {
                        isTooClose = true;
                    }
                }
                if (isTooClose)
                {
                    continue;
                }
                chunkCenters.Add(newCenter);
                terrains.AddRange(CreateAgrarianChunk(newCenter));
                counter = 0;
            }
            List <int> indeces = new List <int>();

            foreach (Terrain terrain in terrains)
            {
                bool found = false;
                for (int i = 0; i < areas.Count; i++)
                {
                    if (utility.IsPointInsideSurface(terrain.center, areas[i]))
                    {
                        indeces.Add(i);
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    indeces.Add(-1);
                }
            }
            return(terrains);

            /*for (int i1 = 0; i1 < terrains.Count; i1++) {
             *  if (indeces[i1] >= 0) {
             *      for (int i2 = 0; i2 < areas.Count; i2++) {
             *          if (i2 == indeces[i1]) {
             *              areas[i2].AddTerrain(terrains[i1]);
             *          } else if (utility.AreSurfacesNear(areas[i2], terrains[i1])) {
             *              areas[i2].ClipTerrain(terrains[i1]);
             *          }
             *      }
             *  }
             * }*/
        }