public List <Descriptor> EffectDescriptors(BuildingDef def) { List <Descriptor> list = new List <Descriptor>(); List <Descriptor> result; if (this.formula.outputs == null || this.formula.outputs.Length == 0) { result = list; } else { for (int i = 0; i < this.formula.outputs.Length; i++) { EnergyGenerator.OutputItem outputItem = this.formula.outputs[i]; Element element = ElementLoader.FindElementByHash(outputItem.element); string arg = element.tag.ProperName(); Descriptor item = default(Descriptor); if (outputItem.minTemperature > 0f) { item.SetupDescriptor(string.Format(UI.BUILDINGEFFECTS.ELEMENTEMITTED_MINORENTITYTEMP, arg, GameUtil.GetFormattedMass(outputItem.creationRate, GameUtil.TimeSlice.PerSecond, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}"), GameUtil.GetFormattedTemperature(outputItem.minTemperature, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)), string.Format(UI.BUILDINGEFFECTS.TOOLTIPS.ELEMENTEMITTED_MINORENTITYTEMP, arg, GameUtil.GetFormattedMass(outputItem.creationRate, GameUtil.TimeSlice.PerSecond, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}"), GameUtil.GetFormattedTemperature(outputItem.minTemperature, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)), Descriptor.DescriptorType.Effect); } else { item.SetupDescriptor(string.Format(UI.BUILDINGEFFECTS.ELEMENTEMITTED_ENTITYTEMP, arg, GameUtil.GetFormattedMass(outputItem.creationRate, GameUtil.TimeSlice.PerSecond, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}")), string.Format(UI.BUILDINGEFFECTS.TOOLTIPS.ELEMENTEMITTED_ENTITYTEMP, arg, GameUtil.GetFormattedMass(outputItem.creationRate, GameUtil.TimeSlice.PerSecond, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}")), Descriptor.DescriptorType.Effect); } list.Add(item); } result = list; } return(result); }
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); }
private void Emit(EnergyGenerator.OutputItem output, float dt, PrimaryElement root_pe) { Element element = ElementLoader.FindElementByHash(output.element); float num = output.creationRate * dt; if (output.store) { if (element.IsGas) { this.storage.AddGasChunk(output.element, num, root_pe.Temperature, 255, 0, true, true); } else if (element.IsLiquid) { this.storage.AddLiquid(output.element, num, root_pe.Temperature, 255, 0, true, true); } else { GameObject go = element.substance.SpawnResource(base.transform.GetPosition(), num, root_pe.Temperature, 255, 0, false, false, false); this.storage.Store(go, true, false, true, false); } } else { int cell = Grid.PosToCell(base.transform.GetPosition()); int num2 = Grid.OffsetCell(cell, output.emitOffset); float temperature = Mathf.Max(root_pe.Temperature, output.minTemperature); if (element.IsGas) { SimMessages.ModifyMass(num2, num, 255, 0, CellEventLogger.Instance.EnergyGeneratorModifyMass, temperature, output.element); } else if (element.IsLiquid) { int elementIndex = ElementLoader.GetElementIndex(output.element); FallingWater.instance.AddParticle(num2, (byte)elementIndex, num, temperature, 255, 0, true, false, false, false); } else { element.substance.SpawnResource(Grid.CellToPosCCC(num2, Grid.SceneLayer.Front), num, temperature, 255, 0, true, false, false); } } }
internal static PortDisplayOutput AddOutput(GameObject go, CellOffset offset, SimHashes elementHash) { Element element = ElementLoader.GetElement(elementHash.CreateTag()); ConduitType conduitType = element.IsGas ? ConduitType.Gas : element.IsLiquid ? ConduitType.Liquid : ConduitType.Solid; // port color Color32 color = element.substance.conduitColour; color.a = 255; // for some reason the alpha channel is set to invisible for some elements (hydrogen only?) if (color.r == 0 && color.g == 0 && color.b == 0) { // avoid completely black icons since the background is black color.r = 25; color.g = 25; color.b = 25; } PortDisplayOutput outputPort = new PortDisplayOutput(conduitType, offset, null, color); PortDisplayController controller = go.AddOrGet <PortDisplayController>(); controller.Init(go); controller.AssignPort(go, outputPort); ElementConverter converter = go.GetComponent <ElementConverter>(); if (converter != null) { for (int i = 0; i < converter.outputElements.Length; ++i) { ElementConverter.OutputElement item = converter.outputElements[i]; if (item.elementHash == elementHash) { converter.outputElements[i].storeOutput = true; PipedDispenser dispenser = go.AddComponent <PipedDispenser>(); dispenser.elementFilter = new SimHashes[] { elementHash }; dispenser.AssignPort(outputPort); dispenser.alwaysDispense = true; dispenser.SkipSetOperational = true; PipedOptionalExhaust exhaust = go.AddComponent <PipedOptionalExhaust>(); exhaust.dispenser = dispenser; exhaust.elementHash = elementHash; exhaust.elementTag = elementHash.CreateTag(); exhaust.capacity = item.massGenerationRate * converter.OutputMultiplier * 5; break; } } } else { EnergyGenerator energyGenerator = go.GetComponent <EnergyGenerator>(); if (energyGenerator != null) { for (int i = 0; i < energyGenerator.formula.outputs.Length; ++i) { EnergyGenerator.OutputItem item = energyGenerator.formula.outputs[i]; if (item.element == elementHash) { energyGenerator.formula.outputs[i].store = true; PipedDispenser dispenser = go.AddComponent <PipedDispenser>(); dispenser.elementFilter = new SimHashes[] { elementHash }; dispenser.AssignPort(outputPort); dispenser.alwaysDispense = true; dispenser.SkipSetOperational = true; PipedOptionalExhaust exhaust = go.AddComponent <PipedOptionalExhaust>(); exhaust.dispenser = dispenser; exhaust.elementHash = elementHash; exhaust.elementTag = elementHash.CreateTag(); exhaust.capacity = item.creationRate * 5; break; } } } } return(outputPort); }