Example #1
0
        private void floodfillStep(List <MERegion> a, MERegion me)
        {
            // remove current region from the array
            for (int i = 0; i < a.Count; i++)
            {
                if (a[i].Id == me.Id)
                {
                    a.RemoveAt(i);
                    break;
                }
            }

            if (a.Count == 0)
            {
                return;
            }

            bool[] nb = me.getNeighbours();
            // iterate over neighb - they are saved as keys so "i"=ID
            for (int i = 0; i < 255; i++)
            {
                //if (this.checkC_cnt == 0) break;
                if (nb[i] == false)
                {
                    continue;
                }

                for (int r = a.Count - 1; r >= 0; r--)
                {
                    if (r >= a.Count)
                    {
                        continue;
                    }
                    floodfillStep(a, a[r]);
                }
            }
        }
Example #2
0
 // copy constructor
 public MERegion(MERegion source)
 {
     map   = source.map;
     Id    = source.Id;
     tiles = source.tiles;
 }
Example #3
0
        public MapResult checkMap()
        {
            // check for region count and empty spaces
            int maxRegionValue = hasDeluxe ? 250 : 40;

            foreach (byte tile in tiles)
            {
                if (tile == 255)
                {
                    return(MapResult.MAP_NOT_FULL);
                }

                if (tile > maxRegionValue)
                {
                    return(MapResult.TOO_MANY_REGIONS);
                }
            }

            List <MERegion> regions = new List <MERegion>();

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    byte tile = tiles[width * y + x];
                    if (tile != 0)
                    {
                        // check if region with this Id already exists
                        MERegion found = null;
                        foreach (MERegion region in regions)
                        {
                            if (region.Id == tile)
                            {
                                found = region;
                                break;
                            }
                        }

                        if (found == null)
                        {
                            found = new MERegion(this, tile);
                            regions.Add(found);
                        }

                        found.addTile(x, y);
                    }
                }
            }

            bool regionsOk = true;

            foreach (MERegion region in regions)
            {
                regionsOk &= region.checkConnectivity();
                if (!regionsOk)
                {
                    return(MapResult.MAP_NOT_CONTINUOS);
                }
            }

            regionsOk = true;
            foreach (MERegion region in regions)
            {
                regionsOk &= region.checkRegionSize();
                if (!regionsOk)
                {
                    return(MapResult.REGIONS_TOO_SMALL);
                }
            }

            // check map connectivity using regions
            List <MERegion> a = new List <MERegion>(regions.Count);

            regions.ForEach((item) =>
            {
                a.Add(new MERegion(item));
            });

            /*bool[] checkArr = new bool[255];
             * for (int i = 0; i < 255; i++) {
             *      checkArr[i] = true;
             * }*/

            floodfillStep(a, a[0]);

            if (a.Count != 0)
            {
                return(MapResult.MAP_NOT_CONTINUOS);
            }

            return(MapResult.MAP_OK);
        }