public override void PostDraw() { base.PostDraw(); if (!this.parent.IsBrokenDown()) { if (this.flickableComp != null && !this.flickableComp.SwitchIsOn) { this.parent.Map.overlayDrawer.DrawOverlay(this.parent, OverlayTypes.PowerOff); } else if (FlickUtility.WantsToBeOn(this.parent)) { if (!this.PowerOn) { this.parent.Map.overlayDrawer.DrawOverlay(this.parent, OverlayTypes.NeedsPower); } } } }
public override string GetInspectString() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(base.GetInspectString()); if (stringBuilder.Length != 0) { stringBuilder.AppendLine(); } stringBuilder.Append("PowerSwitch_Power".Translate() + ": "); if (FlickUtility.WantsToBeOn(this)) { stringBuilder.Append("On".Translate().ToLower()); } else { stringBuilder.Append("Off".Translate().ToLower()); } return(stringBuilder.ToString()); }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { foreach (Gizmo item in base.CompGetGizmosExtra()) { yield return(item); } if (parent.Faction == Faction.OfPlayer) { Command_Toggle command_Toggle = new Command_Toggle(); command_Toggle.hotKey = KeyBindingDefOf.Command_TogglePower; command_Toggle.icon = CommandTex; command_Toggle.defaultLabel = Props.commandLabelKey.Translate(); command_Toggle.defaultDesc = Props.commandDescKey.Translate(); command_Toggle.isActive = () => wantSwitchOn; command_Toggle.toggleAction = delegate { wantSwitchOn = !wantSwitchOn; FlickUtility.UpdateFlickDesignation(parent); }; yield return(command_Toggle); } }
public override IEnumerable <Gizmo> CompGetGizmosExtra() { foreach (Gizmo c in base.CompGetGizmosExtra()) { yield return(c); } if (this.parent.Faction == Faction.OfPlayer) { yield return(new Command_Toggle { hotKey = KeyBindingDefOf.CommandTogglePower, icon = this.CommandTex, defaultLabel = this.Props.commandLabelKey.Translate(), defaultDesc = this.Props.commandDescKey.Translate(), isActive = (() => this.$this.wantSwitchOn), toggleAction = delegate { this.$this.wantSwitchOn = !this.$this.wantSwitchOn; FlickUtility.UpdateFlickDesignation(this.$this.parent); } }); } }
public void PowerNetTick() { float num = this.CurrentEnergyGainRate(); float num2 = this.CurrentStoredEnergy(); if (num2 + num >= -1E-07f && !this.Map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare)) { Profiler.BeginSample("PowerNetTick Excess Energy"); 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) { PowerNet.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()) { PowerNet.partsWantingPowerOn.Add(this.powerComps[i]); } } if (PowerNet.partsWantingPowerOn.Count > 0) { int num4 = 200 / PowerNet.partsWantingPowerOn.Count; if (num4 < 30) { num4 = 30; } if (Find.TickManager.TicksGame % num4 == 0) { int num5 = Mathf.Max(1, Mathf.RoundToInt((float)PowerNet.partsWantingPowerOn.Count * 0.05f)); for (int j = 0; j < num5; j++) { CompPowerTrader compPowerTrader = PowerNet.partsWantingPowerOn.RandomElement <CompPowerTrader>(); if (!compPowerTrader.PowerOn) { if (num + num2 >= -(compPowerTrader.EnergyOutputPerTick + 1E-07f)) { compPowerTrader.PowerOn = true; num += compPowerTrader.EnergyOutputPerTick; } } } } } } this.ChangeStoredEnergy(num); Profiler.EndSample(); } else { Profiler.BeginSample("PowerNetTick Shutdown"); if (Find.TickManager.TicksGame % 20 == 0) { PowerNet.potentialShutdownParts.Clear(); for (int k = 0; k < this.powerComps.Count; k++) { if (this.powerComps[k].PowerOn && this.powerComps[k].EnergyOutputPerTick < 0f) { PowerNet.potentialShutdownParts.Add(this.powerComps[k]); } } if (PowerNet.potentialShutdownParts.Count > 0) { int num6 = Mathf.Max(1, Mathf.RoundToInt((float)PowerNet.potentialShutdownParts.Count * 0.05f)); for (int l = 0; l < num6; l++) { PowerNet.potentialShutdownParts.RandomElement <CompPowerTrader>().PowerOn = false; } } } Profiler.EndSample(); } }
public void PowerNetTick() { float num = CurrentEnergyGainRate(); float num2 = CurrentStoredEnergy(); if (num2 + num >= -1E-07f && !Map.gameConditionManager.ElectricityDisabled) { float num3 = ((batteryComps.Count <= 0 || !(num2 >= 0.1f)) ? num2 : (num2 - 5f)); if (num3 + num >= 0f) { partsWantingPowerOn.Clear(); for (int i = 0; i < powerComps.Count; i++) { if (!powerComps[i].PowerOn && FlickUtility.WantsToBeOn(powerComps[i].parent) && !powerComps[i].parent.IsBrokenDown()) { partsWantingPowerOn.Add(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++) { CompPowerTrader compPowerTrader = partsWantingPowerOn.RandomElement(); if (!compPowerTrader.PowerOn && num + num2 >= 0f - (compPowerTrader.EnergyOutputPerTick + 1E-07f)) { compPowerTrader.PowerOn = true; num += compPowerTrader.EnergyOutputPerTick; } } } } } ChangeStoredEnergy(num); } else { if (Find.TickManager.TicksGame % 20 != 0) { return; } potentialShutdownParts.Clear(); for (int k = 0; k < powerComps.Count; k++) { if (powerComps[k].PowerOn && powerComps[k].EnergyOutputPerTick < 0f) { potentialShutdownParts.Add(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().PowerOn = false; } } } }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; bool flag = false; switch (num) { case 0u: enumerator = base.< CompGetGizmosExtra > __BaseCallProxy0().GetEnumerator(); num = 4294967293u; break; case 1u: break; case 2u: goto IL_193; default: return(false); } try { switch (num) { } if (enumerator.MoveNext()) { c = enumerator.Current; this.$current = c; if (!this.$disposing) { this.$PC = 1; } flag = true; return(true); } } finally { if (!flag) { if (enumerator != null) { enumerator.Dispose(); } } } if (this.parent.Faction != Faction.OfPlayer) { goto IL_193; } Command_Toggle com = new Command_Toggle(); com.hotKey = KeyBindingDefOf.Command_TogglePower; com.icon = base.CommandTex; com.defaultLabel = base.Props.commandLabelKey.Translate(); com.defaultDesc = base.Props.commandDescKey.Translate(); com.isActive = (() => this.wantSwitchOn); com.toggleAction = delegate() { this.wantSwitchOn = !this.wantSwitchOn; FlickUtility.UpdateFlickDesignation(this.parent); }; this.$current = com; if (!this.$disposing) { this.$PC = 2; } return(true); IL_193: this.$PC = -1; return(false); }
public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); this.refuelableComp = this.parent.GetComp <CompRefuelable>(); this.breakdownableComp = this.parent.GetComp <CompBreakdownable>(); if (base.Props.basePowerConsumption < 0f && !this.parent.IsBrokenDown() && FlickUtility.WantsToBeOn(this.parent)) { base.PowerOn = true; } }
public void PowerNetTick() { float num = this.CurrentEnergyGainRate(); float num2 = this.CurrentStoredEnergy(); if (num2 + num >= -1.0000000116860974E-07 && !this.Map.gameConditionManager.ConditionIsActive(GameConditionDefOf.SolarFlare)) { float num3 = (float)((this.batteryComps.Count <= 0 || !(num2 >= 0.10000000149011612)) ? num2 : (num2 - 5.0)); if (UnityData.isDebugBuild) { this.debugLastApparentStoredEnergy = num3; this.debugLastCreatedEnergy = num; this.debugLastRawStoredEnergy = num2; } if (num3 + num >= 0.0) { PowerNet.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()) { PowerNet.partsWantingPowerOn.Add(this.powerComps[i]); } } if (PowerNet.partsWantingPowerOn.Count > 0) { int num4 = 200 / PowerNet.partsWantingPowerOn.Count; if (num4 < 30) { num4 = 30; } if (Find.TickManager.TicksGame % num4 == 0) { int num5 = Mathf.Max(1, Mathf.RoundToInt((float)((float)PowerNet.partsWantingPowerOn.Count * 0.05000000074505806))); for (int j = 0; j < num5; j++) { CompPowerTrader compPowerTrader = PowerNet.partsWantingPowerOn.RandomElement(); if (!compPowerTrader.PowerOn && num + num2 >= 0.0 - (compPowerTrader.EnergyOutputPerTick + 1.0000000116860974E-07)) { compPowerTrader.PowerOn = true; num += compPowerTrader.EnergyOutputPerTick; } } } } } this.ChangeStoredEnergy(num); } else if (Find.TickManager.TicksGame % 20 == 0) { PowerNet.potentialShutdownParts.Clear(); for (int k = 0; k < this.powerComps.Count; k++) { if (this.powerComps[k].PowerOn && this.powerComps[k].EnergyOutputPerTick < 0.0) { PowerNet.potentialShutdownParts.Add(this.powerComps[k]); } } if (PowerNet.potentialShutdownParts.Count > 0) { int num6 = Mathf.Max(1, Mathf.RoundToInt((float)((float)PowerNet.potentialShutdownParts.Count * 0.05000000074505806))); for (int l = 0; l < num6; l++) { PowerNet.potentialShutdownParts.RandomElement().PowerOn = false; } } } }