/// <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> /// 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; }
/// <summary> /// Reset many game state variables /// </summary> public void InitWillStuff() { RandomlySeedRandom(); InitGraphMax(); DestroyAllSprites(); RoadEffect = Constants.MaxRoadEffect; PoliceEffect = Constants.MaxPoliceStationEffect; FireEffect = Constants.MaxFireStationEffect; CityScore = 500; CityPopulation = -1; CityTimeLast = -1; CityYearLast = -1; CityMonthLast = -1; TotalFundsLast = -1; ResLast = ComLast = IndLast = -999999; RoadFund = 0; PoliceFund = 0; FireFund = 0; ValveFlag = true; DisasterEvent = Scenario.None; TaxFlag = false; PopulationDensityMap.Clear(); TrafficDensityMap.Clear(); PollutionDensityMap.Clear(); LandValueMap.Clear(); CrimeRateMap.Clear(); TerrainDensityMap.Clear(); RateOfGrowthMap.Clear(); ComRateMap.Clear(); PoliceStationMap.Clear(); PoliceStationEffectMap.Clear(); FireStationMap.Clear(); FireStationEffectMap.Clear(); DoNewGame(); DoUpdateHeads(); }
/// <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); } }
/// <summary> /// Initialize simulator variables to a sane default. /// </summary> private void init() { // short roadTotal; RoadTotal = 0; // short railTotal; RailTotal = 0; // short firePop; FirePop = 0; // short resPop; ResPop = 0; // short comPop; ComPop = 0; // short indPop; IndPop = 0; // short totalPop; TotalPop = 0; // short totalPopLast; TotalPopLast = 0; // short resZonePop; ResZonePop = 0; // short comZonePop; ComZonePop = 0; // short indZonePop; IndZonePop = 0; // short totalZonePop; TotalZonePop = 0; // short hospitalPop; HospitalPop = 0; // short churchPop; ChurchPop = 0; // short faith; Faith = 0; // short stadiumPop; StadiumPop = 0; // short policeStationPop; PoliceStationPop = 0; // short fireStationPop; FireStationPop = 0; // short coalPowerPop; CoalPowerPop = 0; // short nuclearPowerPop; NuclearPowerPop = 0; // short seaportPop; SeaportPop = 0; // short airportPop; AirportPop = 0; // short needHospital; NeedHospital = 0; // short needChurch; NeedChurch = 0; // short crimeAverage; CrimeAverage = 0; // short pollutionAverage; PollutionAverage = 0; // short landValueAverage; LandValueAverage = 0; // Quad cityTime; CityTime = 0; // Quad cityMonth; CityMonth = 0; // Quad cityYear; CityYear = 0; // short startingYear; StartingYear = 0; Map = new ushort[Constants.WorldWidth, Constants.WorldHeight]; // short resHist10Max; ResHist10Max = 0; // short resHist120Max; ResHist120Max = 0; // short comHist10Max; ComHist10Max = 0; // short comHist120Max; ComHist120Max = 0; // short indHist10Max; IndHist10Max = 0; // short indHist120Max; IndHist120Max = 0; CensusChanged = false; // Quad roadSpend; RoadSpend = 0; // Quad policeSpend; PoliceSpend = 0; // Quad fireSpend; FireSpend = 0; // Quad roadFund; RoadFund = 0; // Quad policeFund; PoliceFund = 0; // Quad fireFund; FireFund = 0; RoadEffect = 0; PoliceEffect = 0; FireEffect = 0; // Quad taxFund; TaxFund = 0; // short cityTax; CityTax = 0; // bool taxFlag; TaxFlag = false; PopulationDensityMap.Clear(); TrafficDensityMap.Clear(); PollutionDensityMap.Clear(); LandValueMap.Clear(); CrimeRateMap.Clear(); PowerGridMap.Clear(); TerrainDensityMap.Clear(); RateOfGrowthMap.Clear(); FireStationMap.Clear(); FireStationEffectMap.Clear(); PoliceStationMap.Clear(); PoliceStationEffectMap.Clear(); ComRateMap.Clear(); // short *resHist; ResHist = new short[Constants.HistoryLength]; // short *comHist; ComHist = new short[Constants.HistoryLength]; // short *indHist; IndHist = new short[Constants.HistoryLength]; // short *moneyHist; MoneyHist = new short[Constants.HistoryLength]; // short *pollutionHist; PollutionHist = new short[Constants.HistoryLength]; // short *crimeHist; CrimeHist = new short[Constants.HistoryLength]; // short *miscHist; MiscHist = new short[Constants.HistoryLength]; // float roadPercent; RoadPercentage = (float)0.0; // float policePercent; PolicePercentage = (float)0.0; // float firePercent; FirePercentage = (float)0.0; // Quad roadValue; RoadValue = 0; // Quad policeValue; PoliceValue = 0; // Quad fireValue; FireValue = 0; // int mustDrawBudget; MustDrawBudget = 0; // short floodCount; FloodCount = 0; // short cityYes; CityYes = 0; // short problemVotes[PROBNUM]; /* these are the votes for each */ ProblemVotes = new int[(int)CityVotingProblems.NumberOfProblems]; ProblemOrder = new int[(int)CityVotingProblems.CountOfProblemsToComplainAbout]; // Quad cityPop; CityPopulation = 0; // Quad cityPopDelta; CityPopDelta = 0; // Quad cityAssessedValue; CityAssessedValue = 0; CityClassification = CityClassification.Village; // short cityScore; CityScore = 0; // short cityScoreDelta; CityScoreDelta = 0; // short trafficAverage; TrafficAverage = 0; // int TreeLevel; /* level for tree creation */ TerrainTreeLevel = -1; // int LakeLevel; /* level for lake creation */ TerrainLakeLevel = -1; // int CurveLevel; /* level for river curviness */ TerrainCurveLevel = -1; // int CreateIsland; /* -1 => 10%, 0 => never, 1 => always */ TerrainCreateIsland = -1; Graph10Max = 0; Graph120Max = 0; // int simLoops; SimLoops = 0; // int simPasses; SimPasses = 0; // int simPass; SimPass = 0; SimPaused = false; // Simulation is running // int simPausedSpeed; SimPausedSpeed = 3; // int heatSteps; HeatSteps = 0; // int heatFlow; HeatFlow = -7; // std::string cityFileName; CityFileName = ""; // std::string cityName; CityName = ""; // bool tilesAnimated; TilesAnimated = false; // bool doAnimaton; DoAnimation = true; // bool doMessages; DoMessages = true; // bool doNotices; DoNotices = true; // Quad cityPopLast; CityPopulationLast = 0; // short categoryLast; CategoryLast = 0; AutoGoTo = false; powerStackPointer = 0; // Position powerStackXY[POWER_STACK_SIZE]; for (int i = 0; i < Constants.PowerStackSize; i++) { powerStackXY[i] = new Position(); } // UQuad nextRandom; nextRandom = 1; // char *HomeDir; homeDir = ""; // char *ResourceDir; resourceDir = ""; // Resource *resources; Resources = null; // StringTable *stringTables; StringTables = null; //////////////////////////////////////////////////////////////////////// // scan.cpp // short newMap; NewMap = 0; // short newMapFlags[MAP_TYPE_COUNT]; NewMapFlags = new short[(int)MapType.Count]; // short cityCenterX; CityCenterX = 0; // short cityCenterY; CityCenterY = 0; // short pollutionMaxX; PollutionMaxX = 0; // short pollutionMaxY; PollutionMaxY = 0; // short crimeMaxX; CrimeMaxX = 0; // short crimeMaxY; CrimeMaxY = 0; // Quad donDither; DonDither = 0; ValveFlag = false; // short crimeRamp; CrimeRamp = 0; // short pollutionRamp; PollutionRamp = 0; ResCap = false; // Do not block residential growth ComCap = false; // Do not block commercial growth IndCap = false; // Do not block industrial growth // short cashFlow; CashFlow = 0; // float externalMarket; ExternalMarket = (float)4.0; DisasterEvent = Scenario.None; // short disasterWait; DisasterWait = 0; ScoreType = Scenario.None; // short scoreWait; scoreWait = 0; // short poweredZoneCount; PoweredZoneCount = 0; // short unpoweredZoneCount; UnpoweredZoneCount = 0; NewPower = false; // short cityTaxAverage; CityTaxAverage = 0; // short simCycle; SimCycle = 0; // short phaseCycle; PhaseCycle = 0; // short speedCycle; SpeedCycle = 0; // bool doInitialEval DoInitialEval = false; // int mapSerial; MapSerial = 1; // short resValve; ResValve = 0; // short comValve; ComValve = 0; // short indValve; IndValve = 0; //SimSprite *spriteList; SpriteList = null; // SimSprite *freeSprites; freeSprites = null; // SimSprite *globalSprites[SPRITE_COUNT]; globalSprites = new SimSprite[(int)SpriteType.Count]; // int absDist; absDist = 0; // short spriteCycle; spriteCycle = 0; // Quad totalFunds; TotalFunds = 0; AutoBulldoze = true; AutoBudget = true; GameLevel = Levels.Easy; // short initSimLoad; InitSimLoad = 0; Scenario = Scenario.None; // short simSpeed; SimSpeed = 0; // short simSpeedMeta; SimSpeedMeta = 0; EnableSound = false; EnableDisasters = true; EvalChanged = false; // short blinkFlag; BlinkFlag = 0; // short curMapStackPointer; curMapStackPointer = 0; // Position curMapStackXY[MAX_TRAFFIC_DISTANCE+1]; for (int i = 0; i < Constants.MaxTrafficDistance + 1; i++) { curMapStackXY[i] = new Position(); } // short trafMaxX, trafMaxY; trafMaxX = 0; trafMaxY = 0; MustUpdateFunds = false; MustUpdateOptions = false; // Quad cityTimeLast; CityTimeLast = 0; // Quad cityYearLast; CityYearLast = 0; // Quad cityMonthLast; CityMonthLast = 0; // Quad totalFundsLast; TotalFundsLast = 0; // Quad resLast; ResLast = 0; // Quad comLast; ComLast = 0; // Quad indLast; IndLast = 0; SimInit(); }
/// <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> /// TODO: Remove THis /// </summary> /// <param name="x"></param> /// <param name="y"></param> public int GetPopulationDensity(int x, int y) { return(PopulationDensityMap.Get(x, y)); }
/// <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; }