/// <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> /// Scan the map for powered tiles, and copy them to the Micropolis::powerGridMap array. /// /// Also warns the user about using too much power ('buy another power plant'). /// </summary> public void DoPowerScan() { Direction anyDir, dir; int conNum; // Clear power map. PowerGridMap.Clear(); // Power that the combined coal and nuclear power plants can deliver. long maxPower = CoalPowerPop * Constants.CoalPowerStrength + NuclearPowerPop * Constants.NuclearPowerStrength; long numPower = 0; // Amount of power used. while (powerStackPointer > 0) { Position pos = PullPowerStack(); anyDir = Direction.Invalid; do { numPower++; if (numPower > maxPower) { SendMessage(GeneralMessages.MESSAGE_NOT_ENOUGH_POWER, Constants.NoWhere, Constants.NoWhere, false, false); return; } if (anyDir != Direction.Invalid) { pos.Move(anyDir); } PowerGridMap.WorldSet(pos.X, pos.Y, 1); conNum = 0; dir = Direction.Begin; while (dir < Direction.End && conNum < 2) { if (TestForConductive(pos, dir)) { conNum++; anyDir = dir; } dir = dir.Increment90(); } if (conNum > 1) { PushPowerStack(pos); } } while (conNum.IsTrue()); } }
/// <summary> /// Check at position \a pos for a power-less conducting tile in the direction \a testDir. /// /// TODO: Re-use something like Micropolis::getFromMap(), and fold this function into its caller. /// </summary> /// <param name="pos">Position to start from.</param> /// <param name="testDir">Direction to investigate.</param> /// <returns>Unpowered tile has been found in the indicated direction.</returns> public bool TestForConductive(Position pos, Direction testDir) { Position movedPos = new Position(pos); if (movedPos.Move(testDir)) { if ((Map[movedPos.X, movedPos.Y] & (ushort)MapTileBits.Conductivity) == (ushort)MapTileBits.Conductivity) { if (PowerGridMap.WorldGet(movedPos.X, movedPos.Y).IsFalse()) { return(true); } } } return(false); }
/// <summary> /// Copy the value of #powerGridMap at position \a pos to the map. /// </summary> /// <param name="pos">Position to copy.</param> /// <returns>Does the tile have power?</returns> public bool SetZonePower(Position pos) { ushort mapValue = Map[pos.X, pos.Y]; ushort tile = (ushort)(mapValue & (ushort)MapTileBits.LowMask); if (tile == (ushort)MapTileCharacters.NUCLEAR || tile == (ushort)MapTileCharacters.POWERPLANT) { Map[pos.X, pos.Y] = (ushort)(mapValue | (ushort)MapTileBits.Power); return(true); } if (PowerGridMap.WorldGet(pos.X, pos.Y) > 0) { Map[pos.X, pos.Y] = (ushort)(mapValue | (ushort)MapTileBits.Power); return(true); } else { Map[pos.X, pos.Y] = (ushort)(mapValue & (~(ushort)MapTileBits.Power)); return(false); } }
/// <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 SetPowerGrid(int x, int y, int power) { PowerGridMap.WorldSet(x, y, (byte)power); }
/// <summary> /// TODO: Remove THis /// </summary> /// <param name="x"></param> /// <param name="y"></param> public int GetPowerGrid(int x, int y) { return(PowerGridMap.WorldGet(x, y)); }