/// <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(); }
public string TempMap(Temp temp) { string s = TempMap1.TempMap(temp); if (s != null) { return(s); } return(TempMap2.TempMap(temp)); }
/// <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; }