示例#1
0
 /// <summary>
 /// TODO: Remove THis
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 public void SetPopulationDensity(int x, int y, int density)
 {
     PopulationDensityMap.Set(x, y, (byte)density);
 }
        /// <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;
        }