/// <summary>
        /// Smooth police station map and compute crime rate
        /// </summary>
        public void CrimeScan()
        {
            SmoothStationMap(PoliceStationMap);
            SmoothStationMap(PoliceStationMap);
            SmoothStationMap(PoliceStationMap);

            long totz = 0;
            int  numz = 0;
            int  cmax = 0;

            for (int x = 0; x < Constants.WorldWidth; x += CrimeRateMap.BlockSize)
            {
                for (int y = 0; y < Constants.WorldHeight; y += CrimeRateMap.BlockSize)
                {
                    int z = LandValueMap.WorldGet(x, y);
                    if (z > 0)
                    {
                        ++numz;
                        z  = 128 - z;
                        z += PopulationDensityMap.WorldGet(x, y);
                        z  = Math.Min(z, 300);
                        z -= PoliceStationMap.WorldGet(x, y);
                        z  = Utilities.Restrict(z, 0, 250);
                        CrimeRateMap.WorldSet(x, y, (Byte)z);
                        totz += z;

                        // Update new crime hot-spot
                        if (z > cmax || (z == cmax && (GetRandom16() & 3) == 0))
                        {
                            cmax      = z;
                            CrimeMaxX = (short)x;
                            CrimeMaxY = (short)y;
                        }
                    }
                    else
                    {
                        CrimeRateMap.WorldSet(x, y, 0);
                    }
                }
            }

            if (numz > 0)
            {
                CrimeAverage = (short)(totz / numz);
            }
            else
            {
                CrimeAverage = 0;
            }

            PoliceStationEffectMap = PoliceStationMap;

            NewMapFlags[(int)MapType.Crime]        = 1;
            NewMapFlags[(int)MapType.PoliceRadius] = 1;
            NewMapFlags[(int)MapType.Dynamic]      = 1;
        }
Exemple #2
0
        /// <summary>
        /// Perform residential immigration into the current residential tile.
        /// </summary>
        /// <param name="pos">Position of the tile.</param>
        /// <param name="pop">Population ?</param>
        /// <param name="value">Land value corrected for pollution.</param>
        public void DoResIn(Position pos, int pop, int value)
        {
            short pollution = PollutionDensityMap.WorldGet(pos.X, pos.Y);

            if (pollution > 128)
            {
                return;
            }

            ushort tile = (ushort)(Map[pos.X, pos.Y] & (ushort)MapTileBits.LowMask);

            if (tile == (ushort)MapTileCharacters.FREEZ)
            {
                if (pop < 8)
                {
                    BuildHouse(pos, value);
                    IncRateOfGrowth(pos, 1);
                    return;
                }

                if (PopulationDensityMap.WorldGet(pos.X, pos.Y) > 64)
                {
                    ResPlop(pos, 0, value);
                    IncRateOfGrowth(pos, 8);
                    return;
                }

                return;
            }

            if (pop < 40)
            {
                ResPlop(pos, (pop / 8) - 1, value);
                IncRateOfGrowth(pos, 8);
            }
        }