/// <summary> /// Evaluate residential zone. /// </summary> /// <param name="pos"></param> /// <param name="traf"></param> /// <returns></returns> public short EvalRes(Position pos, int traf) { short value; if (traf < 0) { return(-3000); } value = LandValueMap.WorldGet(pos.X, pos.Y); value -= PollutionDensityMap.WorldGet(pos.X, pos.Y); if (value < 0) { value = 0; /* Cap at 0 */ } else { value = (short)Math.Min(value * 32, 6000); /* Cap at 6000 */ } value = (short)(value - 3000); return(value); }
/// <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> /// Handle immigration of commercial zone. /// </summary> /// <param name="pos"></param> /// <param name="pop"></param> /// <param name="value"></param> public void DoComIn(Position pos, int pop, int value) { int z; z = LandValueMap.WorldGet(pos.X, pos.Y); z = z >> 5; if (pop > z) { return; } if (pop < 5) { ComPlop(pos, pop, value); IncRateOfGrowth(pos, 8); } }
/// <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> /// Compute average traffic in the city. /// </summary> /// <returns>Value representing how large the traffic problem is</returns> private short GetTrafficAverage() { long trafficTotal; int x, y, count; trafficTotal = 0; count = 1; for (x = 0; x < Constants.WorldWidth; x += LandValueMap.BlockSize) { for (y = 0; y < Constants.WorldHeight; y += LandValueMap.BlockSize) { if (LandValueMap.WorldGet(x, y) > 0) { trafficTotal += TrafficDensityMap.WorldGet(x, y); count++; } } } TrafficAverage = (short)((trafficTotal / count) * 2.4); return(TrafficAverage); }
/// <summary> /// Compute land value at \a pos, taking pollution into account. /// </summary> /// <param name="pos"></param> /// <returns>Indication of land-value adjusted for pollution (\c 0 => low value, \c 3 => high value)</returns> public short GetLandPollutionValue(Position pos) { short landVal; landVal = LandValueMap.WorldGet(pos.X, pos.Y); landVal -= PollutionDensityMap.WorldGet(pos.X, pos.Y); if (landVal < 30) { return(0); } if (landVal < 80) { return(1); } if (landVal < 150) { return(2); } return(3); }
/// <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 SetLandValue(int x, int y, int value) { LandValueMap.Set(x, y, (byte)value); }
/// <summary> /// TODO: Remove THis /// </summary> /// <param name="x"></param> /// <param name="y"></param> public int GetLandValue(int x, int y) { return(LandValueMap.Get(x, y)); }
/// <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; }