Exemplo n.º 1
0
        public static IDGrid Build( IDMap idmap )
        {
            IDGrid result = new IDGrid();
            for ( int y=0; y<result.height; ++y ) {
                for ( int x=0; x<result.width; ++x ) {
                    result.BuildRegion( x, y, idmap );
                }
            }

            return result;
        }
Exemplo n.º 2
0
        public static bool CheckAreaForOverflow( IDMap idmap, Rectangle area, out Rectangle errorArea )
        {
            int l, r, t, b;

            l = (int)Math.Floor((double)(area.Left / RegionWidth));
            t = (int)Math.Floor((double)(area.Top / RegionWidth));
            r = (int)Math.Ceiling((double)(area.Right / RegionWidth));
            b = (int)Math.Ceiling((double)(area.Bottom / RegionWidth));
            IDGrid result = new IDGrid();
            try {
                for ( int y=t; y<b; ++y ) {
                    for ( int x=l; x<r; ++x ) {
                        result.BuildRegion( x, y, idmap );
                    }
                }
                errorArea = Rectangle.Empty;
                return true;
            }
            catch ( RegionSizeOverflowException e ) {
                errorArea = e.Region;
                return false;
            }
        }
Exemplo n.º 3
0
        public static IncognitaGrid Build( IDMap idmap, ProvinceList provinces, IDGrid idgrid )
        {
            IncognitaGrid result = new IncognitaGrid();

            double scansize = (double)(Lightmap.BlockSize << 1);
            double scanfactor = 256.0 / Math.Sqrt( (scansize/2.0) * (scansize/2.0) );

            Random rnd = new Random();
            int halfscan = (int)(scansize/2);
            for( int y=0; y<Lightmap.BaseHeight; y+=Lightmap.BlockSize ) {
                for( int x=0; x<Lightmap.BaseWidth; x+=Lightmap.BlockSize ) {
                    ushort[] list = idmap.GetIDs( x-halfscan, y-halfscan, (int)scansize, (int)scansize, GetIDOptions.SkipTI | GetIDOptions.SkipRivers, provinces );

                    if ( list.Length > 1 ) {
                        double[] distances;
                        ushort[] idlist;
                        int weight;

                        idmap.FindNearest( x, y, (int)scansize, 4, provinces, out idlist, out distances );
                        for ( int i=0; i<4; ++i ) {
                            if ( idlist[i] > Province.MaxID ) idlist[i] = Province.TerraIncognitaID;
                            weight = (int)(distances[i]*scanfactor);
                            weight = weight - 15 + (rnd.Next(0x7fff) & 31);
                            if ( weight < 0 ) weight = 0;
                            else if ( weight > 255 ) weight = 255;

                            result.grid[x >> Lightmap.BlockFactor,y >> Lightmap.BlockFactor].data[i].id = idgrid.MapID( x, y, idlist[i] );
                            result.grid[x >> Lightmap.BlockFactor,y >> Lightmap.BlockFactor].data[i].weight = (byte)weight;
                        }
                    }
                    else {
                        ushort id =  Province.TerraIncognitaID;
                        if ( list.Length > 0 ) {
                            id = list[0];
                            if ( id > Province.MaxID ) id = Province.TerraIncognitaID;
                        }

                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[0].id = idgrid.MapID( x, y, id );
                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[0].weight = 0;

                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[1].id = 0;
                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[1].weight = 255;

                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[2].id = 0;
                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[2].weight = 255;

                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[3].id = 0;
                        result.grid[x >> Lightmap.BlockFactor, y >> Lightmap.BlockFactor].data[3].weight = 255;
                    }
                }
            }

            return result;
        }