/// <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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// comefrom: pollutionTerrainLandValueScan
        /// </summary>
        public void SmoothTerrain()
        {
            if ((DonDither & 1).IsTrue())
            {
                int x, y = 0, dir = 1;
                int z = 0;

                for (x = 0; x < TerrainDensityMap.width; x++)
                {
                    for (; y != TerrainDensityMap.height && y != -1; y += dir)
                    {
                        z +=
                            TempMap3.Get((x == 0) ? x : (x - 1), y) +
                            TempMap3.Get((x == (TerrainDensityMap.width - 1)) ? x : (x + 1), y) +
                            TempMap3.Get(x, (y == 0) ? (0) : (y - 1)) +
                            TempMap3.Get(x, (y == (TerrainDensityMap.height - 1)) ? y : (y + 1)) +
                            (TempMap3.Get(x, y) << 2);
                        Byte val = (Byte)(z / 8);
                        TerrainDensityMap.Set(x, y, val);
                        z &= 0x7;
                    }
                    dir = -dir;
                    y  += dir;
                }
            }
            else
            {
                short x, y;

                for (x = 0; x < TerrainDensityMap.width; x++)
                {
                    for (y = 0; y < TerrainDensityMap.height; y++)
                    {
                        int z = 0;
                        if (x > 0)
                        {
                            z += TempMap3.Get(x - 1, y);
                        }
                        if (x < (TerrainDensityMap.width - 1))
                        {
                            z += TempMap3.Get(x + 1, y);
                        }
                        if (y > 0)
                        {
                            z += TempMap3.Get(x, y - 1);
                        }
                        if (y < (TerrainDensityMap.height - 1))
                        {
                            z += TempMap3.Get(x, y + 1);
                        }
                        Byte val = (Byte)((z / 4 + TempMap3.Get(x, y)) / 2);
                        TerrainDensityMap.Set(x, y, val);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <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;
        }