private bool IsConvertible(float dt) { bool flag = true; EnergyGenerator.InputItem[] inputs = this.formula.inputs; for (int i = 0; i < inputs.Length; i++) { EnergyGenerator.InputItem inputItem = inputs[i]; GameObject gameObject = this.storage.FindFirst(inputItem.tag); if (gameObject != null) { PrimaryElement component = gameObject.GetComponent <PrimaryElement>(); float num = inputItem.consumptionRate * dt; flag = (flag && component.Mass >= num); } else { flag = false; } if (!flag) { break; } } return(flag); }
public override void EnergySim200ms(float dt) { base.EnergySim200ms(dt); if (this.hasMeter) { EnergyGenerator.InputItem inputItem = this.formula.inputs[0]; float positionPercent = 0f; GameObject gameObject = this.storage.FindFirst(inputItem.tag); if (gameObject != null) { PrimaryElement component = gameObject.GetComponent <PrimaryElement>(); positionPercent = component.Mass / inputItem.maxStoredMass; } this.meter.SetPositionPercent(positionPercent); } ushort circuitID = base.CircuitID; this.operational.SetFlag(Generator.wireConnectedFlag, circuitID != 65535); bool value = false; if (this.operational.IsOperational) { if (this.formula.inputs != null) { bool flag2 = this.IsConvertible(dt); this.selectable.ToggleStatusItem(Db.Get().BuildingStatusItems.NeedResourceMass, !flag2, this.formula); if (flag2) { EnergyGenerator.InputItem[] inputs = this.formula.inputs; for (int i = 0; i < inputs.Length; i++) { EnergyGenerator.InputItem inputItem2 = inputs[i]; float amount = inputItem2.consumptionRate * dt; this.storage.ConsumeIgnoringDisease(inputItem2.tag, amount); } PrimaryElement component2 = base.GetComponent <PrimaryElement>(); EnergyGenerator.OutputItem[] outputs = this.formula.outputs; for (int j = 0; j < outputs.Length; j++) { EnergyGenerator.OutputItem output = outputs[j]; this.Emit(output, dt, component2); } base.GenerateJoules(base.WattageRating * dt, false); this.selectable.SetStatusItem(Db.Get().StatusItemCategories.Power, Db.Get().BuildingStatusItems.Wattage, this); value = true; } } } this.operational.SetActive(value, false); }
public List <Descriptor> RequirementDescriptors(BuildingDef def) { List <Descriptor> list = new List <Descriptor>(); List <Descriptor> result; if (this.formula.inputs == null || this.formula.inputs.Length == 0) { result = list; } else { for (int i = 0; i < this.formula.inputs.Length; i++) { EnergyGenerator.InputItem inputItem = this.formula.inputs[i]; string arg = inputItem.tag.ProperName(); Descriptor item = default(Descriptor); item.SetupDescriptor(string.Format(UI.BUILDINGEFFECTS.ELEMENTCONSUMED, arg, GameUtil.GetFormattedMass(inputItem.consumptionRate, GameUtil.TimeSlice.PerSecond, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.##}")), string.Format(UI.BUILDINGEFFECTS.TOOLTIPS.ELEMENTCONSUMED, arg, GameUtil.GetFormattedMass(inputItem.consumptionRate, GameUtil.TimeSlice.PerSecond, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.##}")), Descriptor.DescriptorType.Requirement); list.Add(item); } result = list; } return(result); }