private void RegisterAllComponentsOf(ThingWithComps parentThing) { CompShieldTrader comp = parentThing.GetComp <CompShieldTrader>(); if (comp != null) { if (this.powerComps.Contains(comp)) { Log.Error("PowerNet adding powerComp " + comp + " which it already has."); } else { this.powerComps.Add(comp); } } CompShieldBattery comp2 = parentThing.GetComp <CompShieldBattery>(); if (comp2 != null) { if (this.batteryComps.Contains(comp2)) { Log.Error("PowerNet adding batteryComp " + comp2 + " which it already has."); } else { this.batteryComps.Add(comp2); } } }
private void DeregisterAllComponentsOf(ThingWithComps parentThing) { CompShieldTrader comp = parentThing.GetComp <CompShieldTrader>(); if (comp != null) { this.powerComps.Remove(comp); } CompShieldBattery comp2 = parentThing.GetComp <CompShieldBattery>(); if (comp2 != null) { this.batteryComps.Remove(comp2); } }
public void PowerNetTick() { float num = this.CurrentEnergyGainRate(); float num2 = this.CurrentStoredEnergy(); if (num2 + num >= -1E-07f && !this.shieldNetManager.map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare)) { float num3; if (this.batteryComps.Count > 0 && num2 >= 0.1f) { num3 = num2 - 5f; } else { num3 = num2; } if (UnityData.isDebugBuild) { this.debugLastApparentStoredEnergy = num3; this.debugLastCreatedEnergy = num; this.debugLastRawStoredEnergy = num2; } if (num3 + num >= 0f) { ShieldNet.partsWantingPowerOn.Clear(); for (int i = 0; i < this.powerComps.Count; i++) { if (!this.powerComps[i].PowerOn && FlickUtility.WantsToBeOn(this.powerComps[i].parent) && !this.powerComps[i].parent.IsBrokenDown()) { ShieldNet.partsWantingPowerOn.Add(this.powerComps[i]); } } if (ShieldNet.partsWantingPowerOn.Count > 0) { int num4 = 200 / ShieldNet.partsWantingPowerOn.Count; if (num4 < 30) { num4 = 30; } if (Find.TickManager.TicksGame % num4 == 0) { CompShieldTrader compPowerTrader = ShieldNet.partsWantingPowerOn.RandomElement <CompShieldTrader>(); if (num + num2 >= -(compPowerTrader.EnergyOutputPerTick + 1E-07f)) { compPowerTrader.PowerOn = true; num += compPowerTrader.EnergyOutputPerTick; } } } } this.ChangeStoredEnergy(num); } else if (Find.TickManager.TicksGame % 20 == 0) { ShieldNet.potentialShutdownParts.Clear(); for (int j = 0; j < this.powerComps.Count; j++) { if (this.powerComps[j].PowerOn && this.powerComps[j].EnergyOutputPerTick < 0f) { ShieldNet.potentialShutdownParts.Add(this.powerComps[j]); } } if (ShieldNet.potentialShutdownParts.Count > 0) { ShieldNet.potentialShutdownParts.RandomElement <CompShieldTrader>().PowerOn = false; } } }