Beispiel #1
0
 public GroundGrid(int size_, float maxdist_, float margin_, float km_per_unit_, GameObject regioncentre, Transform earth_transform)
 {
     size        = size_;
     maxdist     = maxdist_;
     margin      = margin_;
     km_per_unit = km_per_unit_;
     // 111 km per degree. size is in degrees.  0.7 is half of diagonal of a square (worst case)
     squaremargin = 0.7f * 111f * size;
     numregions   = 360 / size;
     regions      = new GroundRegion[numregions / 2, numregions];  // only 180 degrees n to s
     for (int lat = 0; lat < numregions / 2; lat++)
     {
         for (int lng = 0; lng < numregions; lng++)
         {
             int reallat = lat * size;
             if (lat * size > 90)
             {
                 reallat = lat * size - 180;
             }
             int reallng = lng * size;
             if (lng * size > 180)
             {
                 reallng = lng * size - 360;
             }
             regions[lat, lng] = new GroundRegion(reallat, reallng, size, regioncentre, earth_transform);
         }
     }
     in_range = new List <List <City> > ();
 }
    public static GroundRegion[] GetClearNoiseRegions(float[,] noise, int divisions, int[,] mapMask)
    {
        float divisionPrice = 1f / divisions;
        float current       = 0f;

        GroundRegion[] regions = new GroundRegion[divisions];
        for (int i = 0; i < divisions; i++)
        {
            regions[i].tiles = new List <Vector2Int>();
            for (int x = 0; x < noise.GetLength(0); x++)
            {
                for (int y = 0; y < noise.GetLength(1); y++)
                {
                    if (noise[x, y] >= current && noise[x, y] <= current + divisionPrice)
                    {
                        if (mapMask[x, y] == 0)
                        {
                            regions[i].tiles.Add(new Vector2Int(x, y));
                            regions[i].groundLayerIndex = i;
                        }
                    }
                }
            }
            current += divisionPrice;
        }
        return(regions);
    }