/// <summary> /// Get the funding setting for each service. /// </summary> /// <returns>Dictionary of name => funding.</returns> /// <remarks>Funding is a percentage, and can be more than 100%. /// In-game range is 50% to 200%.</remarks> public Dictionary <String, int> GetBudgetRates() { Dictionary <String, int> budgetRates = new Dictionary <string, int>(); foreach (BudgetGroup group in budgetGroups) { budgetRates[$"{group.Name}_Day"] = economyManager.GetBudget(group.Service, group.SubService, false); budgetRates[$"{group.Name}_Night"] = economyManager.GetBudget(group.Service, group.SubService, true); } return(budgetRates); }
protected override void setAutobudget() { District d = Singleton <DistrictManager> .instance.m_districts.m_buffer[0]; int capacity1 = d.GetEducation1Capacity(); int capacity2 = d.GetEducation2Capacity(); // No education facilities if (capacity1 == 0 && capacity2 == 0) { return; } int need1 = d.GetEducation1Need(); int need2 = d.GetEducation2Need(); //Debug.Log(string.Format("Capacity: {0}, need: {1}", capacity1, need1)); EconomyManager em = Singleton <EconomyManager> .instance; SimulationManager sm = Singleton <SimulationManager> .instance; int currentBudget = em.GetBudget(ItemClass.Service.Education, ItemClass.SubService.None, sm.m_isNightTime); float currentProductionRate = Helper.GetProductionRateFromBudget(currentBudget); // Convert to the normal capacity capacity1 = (int)(capacity1 / currentProductionRate + 0.5f); capacity2 = (int)(capacity2 / currentProductionRate + 0.5f); //Debug.Log(string.Format("currentBudget: {0}, currentProductionRate: {1}, normal capacity", currentBudget, currentProductionRate, capacity1)); float targetProductionRate1 = 0.25f; if (capacity1 > 0 && need1 > 0) { targetProductionRate1 = need1 * (ElementaryEducationTargetRate * 0.01f) / capacity1; } float targetProductionRate2 = 0.25f; if (capacity2 > 0 && need2 > 0) { targetProductionRate2 = need2 * (HighEducationTargetRate * 0.01f) / capacity2; } float targetProductionRate = Math.Max(targetProductionRate1, targetProductionRate2); int newBudget = Helper.GetBudgetFromProductionRate(targetProductionRate); //Debug.Log(string.Format("targetProductionRate: {0}, newBudget: {1}", targetProductionRate, newBudget)); newBudget = Math.Min(newBudget, BudgetMaxValue); setBudget(newBudget); }
public void SetAutobudget() { if (!Enabled) { return; } if (!Singleton <DistrictManager> .exists || !Singleton <EconomyManager> .exists || !Singleton <SimulationManager> .exists) { return; } EconomyManager em = Singleton <EconomyManager> .instance; int budgetDay = em.GetBudget(GetService(), GetSubService(), false); int budgetNight = em.GetBudget(GetService(), GetSubService(), true); // If not the beginning if (prevBudgetDay != 0 && prevBudgetNight != 0) { // Probably somebody changed budget manually -> disable autobudget if (prevBudgetDay != budgetDay || budgetNight != prevBudgetNight) { Enabled = false; prevBudgetDay = 0; prevBudgetNight = 0; Mod.UpdateUI(); BudgetControlsManager.UpdateControls(); } } prevBudgetDay = budgetDay; prevBudgetNight = budgetNight; if (counter-- <= 0) { counter = refreshCount; setAutobudget(); prevBudgetDay = 0; prevBudgetNight = 0; } }
protected override void setAutobudget() { DistrictManager dm = Singleton <DistrictManager> .instance; int capacity = dm.m_districts.m_buffer[0].GetElectricityCapacity(); // No electricity if (capacity <= 0) { return; } int consumption = dm.m_districts.m_buffer[0].GetElectricityConsumption(); // No changes from the previous state if (capacity == capacity_prev && consumption == consumption_prev) { return; } capacity_prev = capacity; consumption_prev = consumption; int electricityFromGarbage = getGarbageElectricityProduction(); //Debug.Log(string.Format("capacity = {0}, consumption = {1}, getGarbageElectricityProduction = {2}", capacity, consumption, getGarbageElectricityProduction())); AutobudgetObjectsContainer o = Singleton <AutobudgetManager> .instance.container; EconomyManager em = Singleton <EconomyManager> .instance; SimulationManager sm = Singleton <SimulationManager> .instance; int budget = em.GetBudget(ItemClass.Service.Electricity, ItemClass.SubService.None, sm.m_isNightTime); int newBudget = calculateNewBudget(capacity - electricityFromGarbage, consumption - electricityFromGarbage, budget, getBufferCoefficient(AutobudgetBuffer)); newBudget = Math.Min(newBudget, BudgetMaxValue); if (newBudget == BudgetMaxValue && PauseWhenBudgetTooHigh && !isPausedRecently) { SetPause(); isPausedRecently = true; Singleton <InfoManager> .instance.SetCurrentMode(InfoManager.InfoMode.Electricity, InfoManager.SubInfoMode.Default); } if (newBudget < BudgetMaxValue) { isPausedRecently = false; } setBudget(newBudget); }
protected override void setAutobudget() { DistrictManager dm = Singleton <DistrictManager> .instance; // Water int waterCapacity = dm.m_districts.m_buffer[0].GetWaterCapacity(); int waterConsumption = dm.m_districts.m_buffer[0].GetWaterConsumption(); // Sewage int sewageCapacity = dm.m_districts.m_buffer[0].GetSewageCapacity(); int sewageAccumulation = dm.m_districts.m_buffer[0].GetSewageAccumulation(); // No water and no sewage if (waterCapacity <= 0 && sewageCapacity <= 0) { return; } int waterStorageCapacity = dm.m_districts.m_buffer[0].GetWaterStorageCapacity(); int waterStorageAmount = dm.m_districts.m_buffer[0].GetWaterStorageAmount(); int waterStorageRatio = waterStorageCapacity == 0 ? 0 : waterStorageAmount * 100 / waterStorageCapacity; AutobudgetObjectsContainer o = Singleton <AutobudgetManager> .instance.container; EconomyManager em = Singleton <EconomyManager> .instance; SimulationManager sm = Singleton <SimulationManager> .instance; int budget = em.GetBudget(ItemClass.Service.Water, ItemClass.SubService.None, sm.m_isNightTime); float buffer = getBufferCoefficient(AutobudgetBuffer); int newWaterBudget = waterStorageRatio > TargetWaterStorageRatio ? 50 : calculateNewBudget(waterCapacity, waterConsumption, budget, buffer); int newSewageBudget = calculateNewBudget(sewageCapacity, sewageAccumulation, budget, buffer); int newBudget = Math.Max(newWaterBudget, newSewageBudget); newBudget = Math.Min(newBudget, BudgetMaxValue); if (newBudget == BudgetMaxValue && PauseWhenBudgetTooHigh && !isPausedRecently) { SetPause(); isPausedRecently = true; Singleton <InfoManager> .instance.SetCurrentMode(InfoManager.InfoMode.Water, InfoManager.SubInfoMode.Default); } if (newBudget < BudgetMaxValue) { isPausedRecently = false; } // Heating autobudget if (UseHeatingAutobudget && newBudget < HeatingBudgetMaxValue) { if (heatingCounter-- <= 0) { heatingCounter = heatingRefreshCount; if (currentHeatingBudget < newBudget) { currentHeatingBudget = newBudget; } int heatingProblemCount = 0; int allBldCount = 0; BuildingManager bm = Singleton <BuildingManager> .instance; for (int n = 0; n <= (255 + 1) * 192 - 1; n++) { Building.Flags flags = bm.m_buildings.m_buffer[n].m_flags; if ((flags & Building.Flags.Created) != Building.Flags.None) { if (bm.m_buildings.m_buffer[n].m_heatingProblemTimer > 0) { heatingProblemCount++; } allBldCount++; } } if (allBldCount > 0) { if (heatingProblemCount > 0) { currentHeatingBudget += 1 + heatingProblemCount * 20 / allBldCount; } else { currentHeatingBudget -= 1; } } } if (currentHeatingBudget > HeatingBudgetMaxValue) { currentHeatingBudget = HeatingBudgetMaxValue; } if (currentHeatingBudget > newBudget) { newBudget = currentHeatingBudget; } } setBudget(newBudget); }