private void RegisterAllComponentsOf(ThingWithComps parentThing) { CompPipeTrader comp = parentThing.GetComp <CompPipeTrader>(); if (comp != null) { if (this.powerComps.Contains(comp)) { Log.Error("PowerNet adding powerComp " + comp + " which it already has.", false); } else { this.powerComps.Add(comp); } } CompPipeTank comp2 = parentThing.GetComp <CompPipeTank>(); if (comp2 != null) { if (this.batteryComps.Contains(comp2)) { Log.Error("PowerNet adding batteryComp " + comp2 + " which it already has.", false); } else { this.batteryComps.Add(comp2); } } }
private bool IsActivePowerSource(CompPipe cp) { CompPipeTank compPowerBattery = cp as CompPipeTank; if (compPowerBattery != null && compPowerBattery.StoredEnergy > 0f) { return(true); } CompPipeTrader compPowerTrader = cp as CompPipeTrader; return(compPowerTrader != null && compPowerTrader.PowerOutput > 0f); }
private void DeregisterAllComponentsOf(ThingWithComps parentThing) { CompPipeTrader comp = parentThing.GetComp <CompPipeTrader>(); if (comp != null) { this.powerComps.Remove(comp); } CompPipeTank comp2 = parentThing.GetComp <CompPipeTank>(); if (comp2 != null) { this.batteryComps.Remove(comp2); } }
public static void DisconnectAllFromTransmitterAndSetWantConnect(CompPipe deadPc, Map map) { if (deadPc.connectChildren == null) { return; } for (int i = 0; i < deadPc.connectChildren.Count; i++) { CompPipe compPipe = deadPc.connectChildren[i]; compPipe.connectParent = null; CompPipeTrader compPipeTrader = compPipe as CompPipeTrader; if (compPipeTrader != null) { compPipeTrader.PowerOn = false; } map.GetComponent <PipeMapComponent>().Notify_ConnectorWantsConnect(compPipe); } }
public void PowerNetTick() { float num = this.CurrentEnergyGainRate(); float num2 = this.CurrentStoredEnergy(); if (num2 + num >= -1E-07f) { float num3; if (this.batteryComps.Count > 0 && num2 >= 0.1f) { num3 = num2 - 5f; } else { num3 = num2; } if (num3 + num >= 0f) { 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()) { partsWantingPowerOn.Add(this.powerComps[i]); } } if (partsWantingPowerOn.Count > 0) { int num4 = 200 / partsWantingPowerOn.Count; if (num4 < 30) { num4 = 30; } if (Find.TickManager.TicksGame % num4 == 0) { int num5 = Mathf.Max(1, Mathf.RoundToInt((float)partsWantingPowerOn.Count * 0.05f)); for (int j = 0; j < num5; j++) { CompPipeTrader compPowerTrader = partsWantingPowerOn.RandomElement <CompPipeTrader>(); if (!compPowerTrader.PowerOn) { if (num + num2 >= -(compPowerTrader.EnergyOutputPerTick + 1E-07f)) { compPowerTrader.PowerOn = true; num += compPowerTrader.EnergyOutputPerTick; } } } } } } this.ChangeStoredEnergy(num); } else if (Find.TickManager.TicksGame % 20 == 0) { potentialShutdownParts.Clear(); for (int k = 0; k < this.powerComps.Count; k++) { if (this.powerComps[k].PowerOn && this.powerComps[k].EnergyOutputPerTick < 0f) { potentialShutdownParts.Add(this.powerComps[k]); } } if (potentialShutdownParts.Count > 0) { int num6 = Mathf.Max(1, Mathf.RoundToInt((float)potentialShutdownParts.Count * 0.05f)); for (int l = 0; l < num6; l++) { potentialShutdownParts.RandomElement <CompPipeTrader>().PowerOn = false; } } } }