private IEnumerable <Building> GetWastingFuelGenerators() { prevAlertThings.Clear(); prevAlertThings.Concat(alertThings); alertThings.Clear(); prevBatteryLow.Clear(); prevBatteryLow.Concat(batteryLow); batteryLow.Clear(); Map map = Find.Maps.FirstOrDefault(m => m.IsPlayerHome); Vector2 longLat = Find.WorldGrid.LongLatOf(map.Tile); int gameTicks = Find.TickManager.TicksGame; int absTicks = Find.TickManager.TicksAbs; int dayOfYear = GenDate.DayOfYear((long)absTicks, longLat.x); if (dayOfYear != CurrentDayOfYear) { CurrentAverageGlow = GenCelestial.AverageGlow(longLat.y, dayOfYear); CurrentDayOfYear = dayOfYear; } float glow = CurrentAverageGlow; if (map.gameConditionManager.ConditionIsActive(GameConditionDefOf.Eclipse)) { glow = 0.0f; } if (map.gameConditionManager.ConditionIsActive(GameConditionDefOf.VolcanicWinter)) { glow *= 0.5f; } float averageWind = 0.55f; foreach (PowerNet powerNet in map.powerNetManager.AllNetsListForReading.Where(pn => (pn.batteryComps.Count() > 0 || pn.powerComps.Any(pc => pc != null && pc.PowerOn && pc.Props.basePowerConsumption > 0.0f)) && pn.powerComps.Any(pc => pc != null && pc.PowerOn && pc.parent.GetComp <CompRefuelable>() != null))) { if (powerNet.batteryComps.Count() > 0) { float batteryPercent = powerNet.batteryComps.Sum(bc => bc.StoredEnergy) / powerNet.batteryComps.Sum(bc => bc.Props.storedEnergyMax); if (prevBatteryLow.Contains(powerNet)) { if (batteryPercent < batteryLowToHighThreshold) { batteryLow.Add(powerNet); continue; } } else { if (batteryPercent < batteryHighToLowThreshold) { batteryLow.Add(powerNet); continue; } } } float deltaPower = powerNet.powerComps.OfType <CompPowerPlantSolar>().Where(pc => pc.PowerOn).Sum(pc => glow * 1700 - pc.PowerOutput) + powerNet.powerComps.OfType <CompPowerPlantWind>().Sum(pc => averageWind * -pc.Props.basePowerConsumption - pc.PowerOutput) - powerNet.powerComps.Select(pc => pc.parent.GetComp <CompSchedule>()).Where(cs => cs != null).Sum(cs => GetScheduledPowerDelta(cs)); float excess = powerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick + deltaPower; if (excess > 0) { foreach (CompPowerTrader cpt in powerNet.powerComps.Where(pc => pc != null && pc.PowerOn)) { CompRefuelable cr = cpt.parent.GetComp <CompRefuelable>(); if (cpt.Props.basePowerConsumption < 0.0f && cr != null) { if (prevAlertThings.Contains(cpt.parent as Building)) { if (excess < -cpt.Props.basePowerConsumption * powerCompAlertOnToOffThreshold) { continue; } } else { if (excess < -cpt.Props.basePowerConsumption * powerCompAlertOffToOnThreshold) { continue; } } alertThings.Add(cpt.parent as Building); } } } } return(alertThings); }