/// <summary>
        /// Free / Clear all Map Arrays
        /// </summary>
        private void destoryMapArrays()
        {
            InitMapArrays();

            for (int x = 0; x < Constants.WorldWidth; ++x)
            {
                for (int y = 0; y < Constants.WorldHeight; ++y)
                {
                    Map[x, y] = (ushort)MapTileCharacters.DIRT;
                }
            }

            PopulationDensityMap.Clear();
            TrafficDensityMap.Clear();
            PollutionDensityMap.Clear();
            LandValueMap.Clear();
            CrimeRateMap.Clear();
            TerrainDensityMap.Clear();
            RateOfGrowthMap.Clear();
            PowerGridMap.Clear();
            FireStationMap.Clear();
            FireStationEffectMap.Clear();
            PoliceStationMap.Clear();
            PoliceStationEffectMap.Clear();
            ComRateMap.Clear();

            TempMap1.Clear();
            TempMap2.Clear();
            TempMap3.Clear();
        }
        /// <summary>
        /// comefrom: simulate SpecialInit
        /// </summary>
        public void PollutionTerrainLandValueScan()
        { /* Does pollution, terrain, land value */
            long ptot, LVtot;
            int  x, y, z, dis;
            int  pollutionLevel, loc, worldX, worldY, Mx, My, pnum, LVnum, pmax;

            // tempMap3 is a map of development density, smoothed into terrainMap.
            TempMap3.Clear();

            LVtot = 0;
            LVnum = 0;

            for (x = 0; x < LandValueMap.width; x++)
            {
                for (y = 0; y < LandValueMap.height; y++)
                {
                    pollutionLevel = 0;
                    bool landValueFlag = false;
                    worldX = x * 2;
                    worldY = y * 2;

                    for (Mx = worldX; Mx <= worldX + 1; Mx++)
                    {
                        for (My = worldY; My <= worldY + 1; My++)
                        {
                            loc = (Map[Mx, My] & (ushort)MapTileBits.LowMask);
                            if (loc.IsTrue())
                            {
                                if (loc < (ushort)MapTileCharacters.RUBBLE)
                                {
                                    // Increment terrain memory.
                                    byte value = TempMap3.Get(x >> 1, y >> 1);
                                    TempMap3.Set(x >> 1, y >> 1, (byte)(value + 15));
                                    continue;
                                }
                                pollutionLevel += GetPollutionValue(loc);
                                if (loc >= (ushort)MapTileCharacters.ROADBASE)
                                {
                                    landValueFlag = true;
                                }
                            }
                        }
                    }

                    /* XXX ??? This might have to do with the radiation tile returning -40.
                     *          if (pollutionLevel < 0) {
                     *              pollutionLevel = 250;
                     *          }
                     */

                    pollutionLevel = Math.Min(pollutionLevel, 255);
                    TempMap1.Set(x, y, (byte)pollutionLevel);

                    if (landValueFlag)
                    {              /* LandValue Equation */
                        dis  = 34 - GetCityCenterDistance(worldX, worldY) / 2;
                        dis  = dis << 2;
                        dis += TerrainDensityMap.Get(x >> 1, y >> 1);
                        dis -= PollutionDensityMap.Get(x, y);
                        if (CrimeRateMap.Get(x, y) > 190)
                        {
                            dis -= 20;
                        }
                        dis = Utilities.Restrict(dis, 1, 250);
                        LandValueMap.Set(x, y, (byte)dis);
                        LVtot += dis;
                        LVnum++;
                    }
                    else
                    {
                        LandValueMap.Set(x, y, 0);
                    }
                }
            }

            if (LVnum > 0)
            {
                LandValueAverage = (short)(LVtot / LVnum);
            }
            else
            {
                LandValueAverage = 0;
            }

            DoSmooth1(); // tempMap1 -> tempMap2
            DoSmooth2(); // tempMap2 -> tempMap1

            pmax = 0;
            pnum = 0;
            ptot = 0;

            for (x = 0; x < Constants.WorldWidth; x += PollutionDensityMap.BlockSize)
            {
                for (y = 0; y < Constants.WorldHeight; y += PollutionDensityMap.BlockSize)
                {
                    z = TempMap1.WorldGet(x, y);
                    PollutionDensityMap.WorldSet(x, y, (byte)z);

                    if (z.IsTrue())
                    { /*  get pollute average  */
                        pnum++;
                        ptot += z;
                        /* find max pol for monster  */
                        if (z > pmax || (z == pmax && (GetRandom16() & 3) == 0))
                        {
                            pmax          = z;
                            PollutionMaxX = (short)x;
                            PollutionMaxY = (short)y;
                        }
                    }
                }
            }
            if (pnum.IsTrue())
            {
                PollutionAverage = (short)(ptot / pnum);
            }
            else
            {
                PollutionAverage = 0;
            }

            SmoothTerrain();

            NewMapFlags[(int)MapType.Pollution] = 1;
            NewMapFlags[(int)MapType.LandValue] = 1;
            NewMapFlags[(int)MapType.Dynamic]   = 1;
        }
        /// <summary>
        /// The tempMap1 has MAP_BLOCKSIZE > 1, so we may be able to optimize the first x, y loop.
        /// </summary>
        public void PopulationDensityScan()
        {
            /*  sets: populationDensityMap, , , comRateMap  */
            TempMap1.Clear();
            long Xtot = 0;
            long Ytot = 0;
            long Ztot = 0;

            for (int x = 0; x < Constants.WorldWidth; x++)
            {
                for (int y = 0; y < Constants.WorldHeight; y++)
                {
                    ushort mapValue = Map[x, y];
                    if ((mapValue & (ushort)MapTileBits.CenterOfZone).IsTrue())
                    {
                        ushort mapTile = (ushort)(mapValue & (ushort)MapTileBits.LowMask);
                        int    pop     = GetPopulationDensity(new Position(x, y), mapTile) * 8;
                        pop = Math.Min(pop, 254);

                        TempMap1.WorldSet(x, y, (Byte)pop);
                        Xtot += x;
                        Ytot += y;
                        Ztot++;
                    }
                }
            }

            DoSmooth1(); // tempMap1 -> tempMap2
            DoSmooth2(); // tempMap2 -> tempMap1
            DoSmooth1(); // tempMap1 -> tempMap2

            Debug.Assert(PopulationDensityMap.width == TempMap2.width);
            Debug.Assert(PopulationDensityMap.height == TempMap2.height);

            // Copy tempMap2 to populationDensityMap, multiplying by 2
            for (int x = 0; x < PopulationDensityMap.width; x++)
            {
                for (int y = 0; y < PopulationDensityMap.height; y++)
                {
                    PopulationDensityMap.Set(x, y, TempMap2.Get(x, y));
                }
            }

            ComputeComRateMap();          /* Compute the comRateMap */


            // Compute new city center
            if (Ztot > 0)
            {               /* Find Center of Mass for City */
                CityCenterX = (short)(Xtot / Ztot);
                CityCenterY = (short)(Ytot / Ztot);
            }
            else
            {
                CityCenterX = Constants.WorldWidth / 2;  /* if pop==0 center of map is city center */
                CityCenterY = Constants.WorldHeight / 2;
            }

            // Set flags for updated maps
            NewMapFlags[(int)MapType.PopulationDensity] = 1;
            NewMapFlags[(int)MapType.RateOfGrowth]      = 1;
            NewMapFlags[(int)MapType.Dynamic]           = 1;
        }