protected override bool OnWorkTick(Worker worker, float dt) { base.OnWorkTick(worker, dt); HandSanitizer component = GetComponent <HandSanitizer>(); Storage component2 = GetComponent <Storage>(); float massAvailable = component2.GetMassAvailable(component.consumedElement); if (massAvailable == 0f) { return(true); } PrimaryElement component3 = worker.GetComponent <PrimaryElement>(); float a = component.massConsumedPerUse * dt / workTime; float num = Mathf.Min(a, massAvailable); int num2 = Math.Min((int)(dt / workTime * (float)component.diseaseRemovalCount), component3.DiseaseCount); diseaseRemoved += num2; SimUtil.DiseaseInfo invalid = SimUtil.DiseaseInfo.Invalid; invalid.idx = component3.DiseaseIdx; invalid.count = num2; component3.ModifyDiseaseCount(-num2, "HandSanitizer.OnWorkTick"); component.maxPossiblyRemoved += num2; SimUtil.DiseaseInfo disease_info = SimUtil.DiseaseInfo.Invalid; component2.ConsumeAndGetDisease(ElementLoader.FindElementByHash(component.consumedElement).tag, num, out disease_info, out float aggregate_temperature); if (component.outputElement != SimHashes.Vacuum) { disease_info = SimUtil.CalculateFinalDiseaseInfo(invalid, disease_info); component2.AddLiquid(component.outputElement, num, aggregate_temperature, disease_info.idx, disease_info.count, false, true); } return(diseaseRemoved > component.diseaseRemovalCount); }
private void Dispense(float dt) { if (!operational.IsOperational && !alwaysDispense) { return; } PrimaryElement primaryElement = FindSuitableElement(); if (primaryElement == null) { return; } primaryElement.KeepZeroMassObject = true; float dispensed = ConduitManager.AddElement(utilityCell, primaryElement.ElementID, primaryElement.Mass, primaryElement.Temperature, primaryElement.DiseaseIdx, primaryElement.DiseaseCount); if (dispensed > 0) { float dispensedFraction = dispensed / primaryElement.Mass; int dispensedGerms = (int)(dispensedFraction * (float)primaryElement.DiseaseCount); primaryElement.ModifyDiseaseCount(-dispensedGerms, "ConduitOutput.Dispense"); primaryElement.Mass -= dispensed; Trigger(-1697596308, primaryElement.gameObject); } else { blocked = true; } }
protected override void OnSpawn() { base.OnSpawn(); base.workable.requiredSkillPerk = Db.Get().SkillPerks.CanElectricGrill.Id; base.workable.WorkerStatusItem = Db.Get().DuplicantStatusItems.Cooking; base.workable.overrideAnims = new KAnimFile[1] { Assets.GetAnim("anim_interacts_cookstation_kanim") }; base.workable.AttributeConverter = Db.Get().AttributeConverters.CookingSpeed; base.workable.AttributeExperienceMultiplier = DUPLICANTSTATS.ATTRIBUTE_LEVELING.MOST_DAY_EXPERIENCE; base.workable.SkillExperienceSkillGroup = Db.Get().SkillGroups.Cooking.Id; base.workable.SkillExperienceMultiplier = SKILLS.MOST_DAY_EXPERIENCE; ComplexFabricatorWorkable workable = base.workable; workable.OnWorkTickActions = (Action <Worker, float>) Delegate.Combine(workable.OnWorkTickActions, (Action <Worker, float>) delegate(Worker worker, float dt) { Debug.Assert((UnityEngine.Object)worker != (UnityEngine.Object)null, "How did we get a null worker?"); if (diseaseCountKillRate > 0) { PrimaryElement component = GetComponent <PrimaryElement>(); int num = Math.Max(1, (int)((float)diseaseCountKillRate * dt)); component.ModifyDiseaseCount(-num, "CookingStation"); } }); }
protected virtual void ConduitUpdate(float dt) { if (!SkipSetOperational) { this.operational.SetFlag(PortConduitDispenserBase.outputConduitFlag, this.IsConnected); } if (this.operational.IsOperational || this.alwaysDispense) { PrimaryElement primaryElement = this.FindSuitableElement(); if (primaryElement != null) { primaryElement.KeepZeroMassObject = true; ConduitFlow conduitManager = this.GetConduitManager(); float num = conduitManager.AddElement(this.utilityCell, primaryElement.ElementID, primaryElement.Mass, primaryElement.Temperature, primaryElement.DiseaseIdx, primaryElement.DiseaseCount); if (num > 0f) { float num2 = num / primaryElement.Mass; int num3 = (int)(num2 * (float)primaryElement.DiseaseCount); primaryElement.ModifyDiseaseCount(-num3, "CustomConduitDispenser.ConduitUpdate"); primaryElement.Mass -= num; base.Trigger(-1697596308, primaryElement.gameObject); } } } }
protected override bool OnWorkTick(Worker worker, float dt) { base.OnWorkTick(worker, dt); OreScrubber component = GetComponent <OreScrubber>(); Storage component2 = GetComponent <Storage>(); PrimaryElement firstInfected = GetFirstInfected(worker.GetComponent <Storage>()); int num = 0; SimUtil.DiseaseInfo invalid = SimUtil.DiseaseInfo.Invalid; if ((UnityEngine.Object)firstInfected != (UnityEngine.Object)null) { num = Math.Min((int)(dt / workTime * (float)component.diseaseRemovalCount), firstInfected.DiseaseCount); diseaseRemoved += num; invalid.idx = firstInfected.DiseaseIdx; invalid.count = num; firstInfected.ModifyDiseaseCount(-num, "OreScrubber.OnWorkTick"); } component.maxPossiblyRemoved += num; float num2 = component.massConsumedPerUse * dt / workTime; SimUtil.DiseaseInfo disease_info = SimUtil.DiseaseInfo.Invalid; component2.ConsumeAndGetDisease(ElementLoader.FindElementByHash(component.consumedElement).tag, num2, out disease_info, out float aggregate_temperature); if (component.outputElement != SimHashes.Vacuum) { disease_info = SimUtil.CalculateFinalDiseaseInfo(invalid, disease_info); component2.AddLiquid(component.outputElement, num2, aggregate_temperature, disease_info.idx, disease_info.count, false, true); } return(diseaseRemoved > component.diseaseRemovalCount); }
private bool EmitCommon(int cell, PrimaryElement primary_element, EmitDelegate emit) { if (primary_element.Mass <= 0.0) { return(false); } int disease_to_item1; int disease_to_item2; CalculateDiseaseTransfer(exhaustPE, primary_element, 0.05f, out disease_to_item1, out disease_to_item2); primary_element.ModifyDiseaseCount(-disease_to_item1, "Exhaust transfer"); primary_element.AddDisease(exhaustPE.DiseaseIdx, disease_to_item2, "Exhaust transfer"); exhaustPE.ModifyDiseaseCount(-disease_to_item2, "Exhaust transfer"); exhaustPE.AddDisease(primary_element.DiseaseIdx, disease_to_item1, "Exhaust transfer"); emit(cell, primary_element); primary_element.KeepZeroMassObject = true; primary_element.Mass = 0.0f; primary_element.ModifyDiseaseCount(int.MinValue, "Exhaust.SimUpdate"); return(true); }
private void UpdateState(float dt) { bool value = consumer.IsSatisfied; envTemp = 0f; cellCount = 0; if ((UnityEngine.Object)occupyArea != (UnityEngine.Object)null && (UnityEngine.Object)base.gameObject != (UnityEngine.Object)null) { occupyArea.TestArea(Grid.PosToCell(base.gameObject), this, UpdateStateCb); envTemp /= (float)cellCount; } lastEnvTemp = envTemp; List <GameObject> items = storage.items; for (int i = 0; i < items.Count; i++) { PrimaryElement component = items[i].GetComponent <PrimaryElement>(); if (component.Mass > 0f && (!isLiquidConditioner || !component.Element.IsGas) && (isLiquidConditioner || !component.Element.IsLiquid)) { value = true; lastGasTemp = component.Temperature; float num = component.Temperature + temperatureDelta; if (num < 1f) { num = 1f; lowTempLag = Mathf.Min(lowTempLag + dt / 5f, 1f); } else { lowTempLag = Mathf.Min(lowTempLag - dt / 5f, 0f); } ConduitFlow conduitFlow = (!isLiquidConditioner) ? Game.Instance.gasConduitFlow : Game.Instance.liquidConduitFlow; float num2 = conduitFlow.AddElement(cooledAirOutputCell, component.ElementID, component.Mass, num, component.DiseaseIdx, component.DiseaseCount); component.KeepZeroMassObject = true; float num3 = num2 / component.Mass; int num4 = (int)((float)component.DiseaseCount * num3); component.Mass -= num2; component.ModifyDiseaseCount(-num4, "AirConditioner.UpdateState"); float num5 = num - component.Temperature; float num6 = num5 * component.Element.specificHeatCapacity * num2; float display_dt = (!(lastSampleTime > 0f)) ? 1f : (Time.time - lastSampleTime); lastSampleTime = Time.time; GameComps.StructureTemperatures.ProduceEnergy(structureTemperature, 0f - num6, BUILDING.STATUSITEMS.OPERATINGENERGY.PIPECONTENTS_TRANSFER, display_dt); break; } } if (Time.time - lastSampleTime > 2f) { GameComps.StructureTemperatures.ProduceEnergy(structureTemperature, 0f, BUILDING.STATUSITEMS.OPERATINGENERGY.PIPECONTENTS_TRANSFER, Time.time - lastSampleTime); lastSampleTime = Time.time; } operational.SetActive(value, false); UpdateStatus(); }
protected override List <GameObject> SpawnOrderProduct(ComplexRecipe recipe) { List <GameObject> list = base.SpawnOrderProduct(recipe); foreach (GameObject item in list) { PrimaryElement component = item.GetComponent <PrimaryElement>(); component.ModifyDiseaseCount(-component.DiseaseCount, "CookingStation.CompleteOrder"); } GetComponent <Operational>().SetActive(false, false); return(list); }
private bool EmitCommon(int cell, PrimaryElement primary_element, EmitDelegate emit) { if (primary_element.Mass <= 0f) { return(false); } CalculateDiseaseTransfer(exhaustPE, primary_element, 0.05f, out int disease_to_item, out int disease_to_item2); primary_element.ModifyDiseaseCount(-disease_to_item, "Exhaust transfer"); primary_element.AddDisease(exhaustPE.DiseaseIdx, disease_to_item2, "Exhaust transfer"); exhaustPE.ModifyDiseaseCount(-disease_to_item2, "Exhaust transfer"); exhaustPE.AddDisease(primary_element.DiseaseIdx, disease_to_item, "Exhaust transfer"); emit(cell, primary_element); if ((Object)vent != (Object)null) { vent.UpdateVentedMass(primary_element.ElementID, primary_element.Mass); } primary_element.KeepZeroMassObject = true; primary_element.Mass = 0f; primary_element.ModifyDiseaseCount(-2147483648, "Exhaust.SimUpdate"); recentlyExhausted = true; return(true); }
public override void EnergySim200ms(float dt) { base.EnergySim200ms(dt); ushort circuitID = base.CircuitID; this.operational.SetFlag(Generator.wireConnectedFlag, circuitID != 65535); if (!this.operational.IsOperational) { return; } float num = 0f; if (this.gasStorage != null && this.gasStorage.items.Count > 0) { GameObject gameObject = this.gasStorage.FindFirst(ElementLoader.FindElementByHash(this.srcElem).tag); if (gameObject != null) { PrimaryElement component = gameObject.GetComponent <PrimaryElement>(); float num2 = 0.1f; if (component.Mass > num2) { num2 = Mathf.Min(component.Mass, this.pumpKGRate * dt); float num3 = this.JoulesToGenerate(component); num = Mathf.Min(num3 * (num2 / this.pumpKGRate), this.maxWattage * dt); float num4 = this.HeatFromCoolingSteam(component); float num5 = num4 * (num2 / component.Mass); float num6 = num2 / component.Mass; int num7 = Mathf.RoundToInt((float)component.DiseaseCount * num6); component.Mass -= num2; component.ModifyDiseaseCount(-num7, "SteamTurbine.EnergySim200ms"); float display_dt = (this.lastSampleTime <= 0f) ? 1f : (Time.get_time() - this.lastSampleTime); this.lastSampleTime = Time.get_time(); GameComps.StructureTemperatures.ProduceEnergy(this.structureTemperature, num5 * this.wasteHeatToTurbinePercent, BUILDINGS.PREFABS.STEAMTURBINE2.HEAT_SOURCE, display_dt); this.liquidStorage.AddLiquid(this.destElem, num2, this.outputElementTemperature, component.DiseaseIdx, num7, false, true); } } } num = Mathf.Clamp(num, 0f, this.maxWattage); Game.Instance.accumulators.Accumulate(this.accumulator, num); if (num > 0f) { base.GenerateJoules(num, false); } this.meter.SetPositionPercent(Game.Instance.accumulators.GetAverageRate(this.accumulator) / this.maxWattage); this.meter.SetSymbolTint(SteamTurbine.TINT_SYMBOL, Color.Lerp(Color.get_red(), Color.get_green(), Game.Instance.accumulators.GetAverageRate(this.accumulator) / this.maxWattage)); }
private void ConduitUpdate(float dt) { operational.SetFlag(outputConduitFlag, IsConnected); if (operational.IsOperational || alwaysDispense) { PrimaryElement primaryElement = FindSuitableElement(); if ((Object)primaryElement != (Object)null) { primaryElement.KeepZeroMassObject = true; ConduitFlow conduitManager = GetConduitManager(); float num = conduitManager.AddElement(utilityCell, primaryElement.ElementID, primaryElement.Mass, primaryElement.Temperature, primaryElement.DiseaseIdx, primaryElement.DiseaseCount); if (num > 0f) { float num2 = num / primaryElement.Mass; int num3 = (int)(num2 * (float)primaryElement.DiseaseCount); primaryElement.ModifyDiseaseCount(-num3, "ConduitDispenser.ConduitUpdate"); primaryElement.Mass -= num; Trigger(-1697596308, primaryElement.gameObject); } } } }
public void ModifyDiseaseCount(int delta, string reason) { if ((bool)diseaseRedirectTarget) { diseaseRedirectTarget.ModifyDiseaseCount(delta, reason); } else if (useSimDiseaseInfo) { int gameCell = Grid.PosToCell(this); SimMessages.ModifyDiseaseOnCell(gameCell, byte.MaxValue, delta); } else if (delta != 0 && diseaseHandle.IsValid()) { int num = GameComps.DiseaseContainers.ModifyDiseaseCount(diseaseHandle, delta); if (num <= 0 && !forcePermanentDiseaseContainer) { Trigger(-1689370368, false); GameComps.DiseaseContainers.Remove(base.gameObject); diseaseHandle.Clear(); } } }
private void ConduitUpdate(float dt) { this.operational.SetFlag(ConduitDispenser2.outputConduitFlag, this.IsConnected); if (!this.operational.IsOperational && !this.alwaysDispense) { return; } PrimaryElement suitableElement = this.FindSuitableElement(); if ((UnityEngine.Object)suitableElement != (UnityEngine.Object)null) { suitableElement.KeepZeroMassObject = true; float num1 = this.GetConduitManager().AddElement(this.utilityCell, suitableElement.ElementID, suitableElement.Mass, suitableElement.Temperature, suitableElement.DiseaseIdx, suitableElement.DiseaseCount); if ((double)num1 > 0.0) { int num2 = (int)((double)(num1 / suitableElement.Mass) * (double)suitableElement.DiseaseCount); suitableElement.ModifyDiseaseCount(-num2, "ConduitDispenser.ConduitUpdate"); suitableElement.Mass -= num1; this.Trigger(-1697596308, (object)suitableElement.gameObject); } } }
protected override bool OnWorkTick(Worker worker, float dt) { PrimaryElement component = worker.GetComponent <PrimaryElement>(); if (component.DiseaseCount > 0) { SimUtil.DiseaseInfo diseaseInfo = default(SimUtil.DiseaseInfo); diseaseInfo.idx = component.DiseaseIdx; diseaseInfo.count = Mathf.CeilToInt((float)component.DiseaseCount * (1f - Mathf.Pow(fractionalDiseaseRemoval, dt)) - (float)absoluteDiseaseRemoval); SimUtil.DiseaseInfo b = diseaseInfo; component.ModifyDiseaseCount(-b.count, "Shower.RemoveDisease"); accumulatedDisease = SimUtil.CalculateFinalDiseaseInfo(accumulatedDisease, b); Storage component2 = GetComponent <Storage>(); PrimaryElement primaryElement = component2.FindPrimaryElement(outputTargetElement); if ((Object)primaryElement != (Object)null) { PrimaryElement component3 = primaryElement.GetComponent <PrimaryElement>(); component3.AddDisease(accumulatedDisease.idx, accumulatedDisease.count, "Shower.RemoveDisease"); accumulatedDisease = SimUtil.DiseaseInfo.Invalid; } } return(false); }
private void Dispense(float dt) { PrimaryElement suitableElement = this.FindSuitableElement(); if (!((UnityEngine.Object)suitableElement != (UnityEngine.Object)null)) { return; } suitableElement.KeepZeroMassObject = true; float num1 = this.GetConduitManager().AddElement(this.utilityCell, suitableElement.ElementID, suitableElement.Mass, suitableElement.Temperature, suitableElement.DiseaseIdx, suitableElement.DiseaseCount); if ((double)num1 > 0.0) { int num2 = (int)((double)num1 / (double)suitableElement.Mass * (double)suitableElement.DiseaseCount); suitableElement.ModifyDiseaseCount(-num2, "MatPacketRecver.ConduitUpdate"); suitableElement.Mass -= num1; this.Trigger(-1697596308, (object)suitableElement.gameObject); } else { this.blocked = true; } }
private void TryEmit(PrimaryElement primary_elem) { if (primary_elem.Mass >= emitMass) { plasticMeter.SetPositionPercent(0f); GameObject gameObject = storage.Drop(primary_elem.gameObject, true); Rotatable component = GetComponent <Rotatable>(); Vector3 vector = component.transform.GetPosition() + component.GetRotatedOffset(emitOffset); int i = Grid.PosToCell(vector); if (Grid.Solid[i]) { vector += component.GetRotatedOffset(Vector3.left); } gameObject.transform.SetPosition(vector); PrimaryElement primaryElement = storage.FindPrimaryElement(exhaustElement); if ((Object)primaryElement != (Object)null) { int gameCell = Grid.PosToCell(vector); SimMessages.AddRemoveSubstance(gameCell, primaryElement.ElementID, null, primaryElement.Mass, primaryElement.Temperature, primaryElement.DiseaseIdx, primaryElement.DiseaseCount, true, -1); primaryElement.Mass = 0f; primaryElement.ModifyDiseaseCount(-2147483648, "Polymerizer.Exhaust"); } } }
public override void EndTransition(Navigator navigator, Navigator.ActiveTransition transition) { base.EndTransition(navigator, transition); if (transition.end == NavType.Ladder) { int cell = Grid.PosToCell(navigator); GameObject gameObject = Grid.Objects[cell, 1]; if ((Object)gameObject != (Object)null) { PrimaryElement component = gameObject.GetComponent <PrimaryElement>(); if ((Object)component != (Object)null) { PrimaryElement component2 = navigator.GetComponent <PrimaryElement>(); if ((Object)component2 != (Object)null) { SimUtil.DiseaseInfo invalid = SimUtil.DiseaseInfo.Invalid; invalid.idx = component2.DiseaseIdx; invalid.count = (int)((float)component2.DiseaseCount * 0.005f); SimUtil.DiseaseInfo invalid2 = SimUtil.DiseaseInfo.Invalid; invalid2.idx = component.DiseaseIdx; invalid2.count = (int)((float)component.DiseaseCount * 0.005f); component2.ModifyDiseaseCount(-invalid.count, "Navigator.EndTransition"); component.ModifyDiseaseCount(-invalid2.count, "Navigator.EndTransition"); if (invalid.count > 0) { component.AddDisease(invalid.idx, invalid.count, "TransitionDriver.EndTransition"); } if (invalid2.count > 0) { component2.AddDisease(invalid2.idx, invalid2.count, "TransitionDriver.EndTransition"); } } } } } }
public void DoReplaceSubstance(int cell) { if (Grid.IsValidBuildingCell(cell)) { Element element = (!DebugPaintElementScreen.Instance.paintElement.isOn) ? ElementLoader.elements[Grid.ElementIdx[cell]] : ElementLoader.FindElementByHash(DebugPaintElementScreen.Instance.element); if (element == null) { element = ElementLoader.FindElementByHash(SimHashes.Vacuum); } byte b = (!DebugPaintElementScreen.Instance.paintDisease.isOn) ? Grid.DiseaseIdx[cell] : DebugPaintElementScreen.Instance.diseaseIdx; float num = (!DebugPaintElementScreen.Instance.paintTemperature.isOn) ? Grid.Temperature[cell] : DebugPaintElementScreen.Instance.temperature; float num2 = (!DebugPaintElementScreen.Instance.paintMass.isOn) ? Grid.Mass[cell] : DebugPaintElementScreen.Instance.mass; int num3 = (!DebugPaintElementScreen.Instance.paintDiseaseCount.isOn) ? Grid.DiseaseCount[cell] : DebugPaintElementScreen.Instance.diseaseCount; if (num == -1f) { num = element.defaultValues.temperature; } if (num2 == -1f) { num2 = element.defaultValues.mass; } if (DebugPaintElementScreen.Instance.affectCells.isOn) { SimMessages.ReplaceElement(cell, element.id, CellEventLogger.Instance.DebugTool, num2, num, b, num3, -1); if (DebugPaintElementScreen.Instance.set_prevent_fow_reveal) { Grid.Visible[cell] = 0; Grid.PreventFogOfWarReveal[cell] = true; } else if (DebugPaintElementScreen.Instance.set_allow_fow_reveal && Grid.PreventFogOfWarReveal[cell]) { Grid.PreventFogOfWarReveal[cell] = false; } } if (DebugPaintElementScreen.Instance.affectBuildings.isOn) { List <GameObject> list = new List <GameObject>(); list.Add(Grid.Objects[cell, 1]); list.Add(Grid.Objects[cell, 2]); list.Add(Grid.Objects[cell, 9]); list.Add(Grid.Objects[cell, 16]); list.Add(Grid.Objects[cell, 12]); list.Add(Grid.Objects[cell, 16]); list.Add(Grid.Objects[cell, 26]); foreach (GameObject item in list) { if ((Object)item != (Object)null) { PrimaryElement component = item.GetComponent <PrimaryElement>(); if (num > 0f) { component.Temperature = num; } if (num3 > 0 && b != 255) { component.ModifyDiseaseCount(-2147483648, "DebugTool.DoReplaceSubstance"); component.AddDisease(b, num3, "DebugTool.DoReplaceSubstance"); } } } } } }
private PrimaryElement FindSuitableElement() { PrimaryElement ret = null; // Maybe make it buffer an extra message, that might help? // better version: grab stuff from our ass, I mean network - BR int x, y; Grid.CellToXY(Grid.PosToCell(this), out x, out y); JObject message = Z.net.get_message_for("got_packet", x, y); if (outstanding && message != null) { outstanding = false; // We have a response from the server, finally ya lazy basterd if (message["packet"] != null && message["packet"].Type == JTokenType.Object) { JObject mat_packet = (JObject)message["packet"]; JObject germ_packet = null; if (mat_packet["germs"] != null && mat_packet["germs"].Type == JTokenType.Object) { germ_packet = (JObject)mat_packet["germs"]; } if (dave == null) { dave = GasSourceManager.Instance.CreateChunk( (SimHashes)(-1528777920), 0f, 456f, 255, 0, this.transform.GetPosition()); steve = dave.GetComponent <PrimaryElement>(); steve.KeepZeroMassObject = true; } steve.SetElement((SimHashes)((int)mat_packet["element"])); steve.SetMassTemperature((float)mat_packet["mass"], (float)mat_packet["temperature"]); string reason = conduitType == ConduitType.Liquid ? "Storage.AddLiquid" : "Storage.AddGasChunk"; steve.ModifyDiseaseCount(-steve.DiseaseCount, reason); if (germ_packet != null) { steve.AddDisease((byte)germ_packet["id"], (int)germ_packet["count"], reason); } message = null; ret = steve; } } // Only ask for goodies when we are enabled if (!outstanding && ztransporter.is_enabled()) { // Send a message to the server asking for goodies message = Network.make_message("recv_packet", x, y); message.Add("phase", this.conduitType == ConduitType.Liquid ? "Liquid" : "Gas"); Z.net.send_message(message); outstanding = true; } return(ret); }
private void ConvertMass() { float filterAmt = 0; List <GameObject> items = this.storage.items; PrimaryElement elem = null; foreach (GameObject item in items) { elem = item.GetComponent <PrimaryElement>(); if (elem.ElementID == SimHashes.BleachStone) { filterAmt += elem.Mass; } } if (filterAmt <= 0) { return; } float maxGerms = Mathf.Min(GERMS_PER_KG * MAX_KG_PER_SEC, (int)(filterAmt * GERMS_PER_KG)); float removedAmount = 0; ConduitFlow flowManager = Conduit.GetFlowManager(ConduitType.Liquid); if (!flowManager.HasConduit(inCell) || !flowManager.HasConduit(outCell)) { return; } foreach (GameObject item in items) { elem = item.GetComponent <PrimaryElement>(); if (elem.Element.IsLiquid) { float mass = Mathf.Min(10f, elem.Mass); float disease = elem.DiseaseCount / elem.Mass * mass; if (elem.DiseaseIdx == Byte.MaxValue) { disease = 0; } if (disease > maxGerms) { mass = mass * maxGerms / disease; disease = maxGerms; } float trueMass = flowManager.AddElement(outCell, elem.ElementID, mass, elem.Temperature, Byte.MaxValue, 0); if (trueMass < mass) { disease = disease * trueMass / mass; mass = trueMass; } elem.Mass -= mass; elem.ModifyDiseaseCount(-(int)disease, ""); removedAmount = disease; Game.Instance.accumulators.Accumulate(fluidProcessedLastTick, mass); if (mass > 0) { break; } } } if (removedAmount > 0) { float removal = (float)removedAmount / GERMS_PER_KG; storage.ConsumeIgnoringDisease(ElementLoader.FindElementByHash(filterIn).tag, removal); Game.Instance.accumulators.Accumulate(filterConsumedLastTick, removal); if (EMIT_CHLORINE) { float addition = (float)removedAmount / GERMS_PER_KG; Element elementByHash = ElementLoader.FindElementByHash(filterOut); Vector3 outVector3 = new Vector3(this.transform.GetPosition().x, this.transform.GetPosition().y, 0.0f); int outCell = Grid.PosToCell(outVector3); SimMessages.AddRemoveSubstance(outCell, filterOut, CellEventLogger.Instance.OxygenModifierSimUpdate, addition, 273.15f + 45f, Byte.MaxValue, 0); } } //TODO: find out what the nice name is this.storage.Trigger(-1697596308, (object)this.gameObject); }
private void ConvertMass() { SimUtil.DiseaseInfo diseaseInfo = SimUtil.DiseaseInfo.Invalid; diseaseInfo.idx = byte.MaxValue; diseaseInfo.count = 0; float speedMultiplier = GetSpeedMultiplier(); // Accumulators float oxygenMass = 0f; float hydrogenMass = 0f; float bleachStoneMass = 0f; float totalConsumedAmount = 0f; float waterConsumptionRate = Config.waterConsumptionRate * speedMultiplier; Tag dirtyWaterTag = SimHashes.DirtyWater.CreateTag(); Tag saltWaterTag = SimHashes.SaltWater.CreateTag(); Tag brineTag = SimHashes.Brine.CreateTag(); bool isDirty = false; for (int i = 0; i < storage.items.Count; i++) { GameObject storageItem = storage.items[i]; if (storageItem != null && storageItem.HasTag(GameTags.AnyWater)) { PrimaryElement element = storageItem.GetComponent <PrimaryElement>(); //element.KeepZeroMassObject = true; float consumedAmount = Mathf.Min(waterConsumptionRate, element.Mass); float consumedPercentage = consumedAmount / element.Mass; int diseaseCount = (int)(consumedPercentage * element.DiseaseCount); element.Mass -= consumedAmount; element.ModifyDiseaseCount(-diseaseCount, "IndustrialElectrolyzer.ConvertMass"); if (storageItem.HasTag(saltWaterTag)) { // 93% H2O oxygenMass += consumedAmount * Config.saltWater2WaterRatio * Config.water2OxygenRatio; hydrogenMass += consumedAmount * Config.saltWater2WaterRatio * Config.water2HydrogenRatio; // 7% NaCl bleachStoneMass += consumedAmount * Config.saltWater2SaltRatio * Config.salt2BleachStoneRatio; } else if (storageItem.HasTag(brineTag)) { // 70% H2O oxygenMass += consumedAmount * Config.brine2WaterRatio * Config.water2OxygenRatio; hydrogenMass += consumedAmount * Config.brine2WaterRatio * Config.water2HydrogenRatio; // 30% NaCl bleachStoneMass += consumedAmount * Config.brine2SaltRatio * Config.salt2BleachStoneRatio; } else { oxygenMass += consumedAmount * Config.water2OxygenRatio; hydrogenMass += consumedAmount * Config.water2HydrogenRatio; } totalConsumedAmount += consumedAmount; if (storageItem.HasTag(dirtyWaterTag) && consumedAmount > EPSILON) { isDirty = true; } diseaseInfo = SimUtil.CalculateFinalDiseaseInfo(diseaseInfo.idx, diseaseInfo.count, element.DiseaseIdx, element.DiseaseCount); waterConsumptionRate -= consumedAmount; if (waterConsumptionRate <= 0f) { Debug.Assert(waterConsumptionRate <= 0f); break; } } } float temperature = GetComponent <PrimaryElement>().Temperature; if (onConvertMass != null && totalConsumedAmount > EPSILON) { onConvertMass(totalConsumedAmount); } ConduitFlow gasFlowManager = Conduit.GetFlowManager(portInfo.conduitType); SimHashes oxygenHash = isDirty ? SimHashes.ContaminatedOxygen : SimHashes.Oxygen; float oxygenGenerated = gasFlowManager.AddElement(oxygenOutputCell, oxygenHash, oxygenMass * speedMultiplier, Mathf.Max(Config.oxygenTemperature, temperature), diseaseInfo.idx, diseaseInfo.count / 2); ReportManager.Instance.ReportValue(ReportManager.ReportType.OxygenCreated, oxygenGenerated, gameObject.GetProperName()); Game.Instance.accumulators.Accumulate(OxygenAccumulator, oxygenGenerated); float hydrogenGenerated = gasFlowManager.AddElement(hydrogenOutputCell, SimHashes.Hydrogen, hydrogenMass * speedMultiplier, Mathf.Max(Config.hydrogenTemperature, temperature), diseaseInfo.idx, diseaseInfo.count / 2); Game.Instance.accumulators.Accumulate(HydrogenAccumulator, hydrogenGenerated); if (bleachStoneMass > EPSILON) { Element bleachStone = ElementLoader.FindElementByHash(SimHashes.BleachStone); Vector3 position = building.GetRotatedOffset(new CellOffset(1, 0)).ToVector3() + new Vector3(.5f, .5f, .0f) + transform.position; UnityEngine.Debug.Log("[AE] transform is at " + transform.position); UnityEngine.Debug.Log("[AE] exit is at " + position); bleachStone.substance.SpawnResource(position, bleachStoneMass, temperature, diseaseInfo.idx, diseaseInfo.count); } storage.Trigger((int)GameHashes.OnStorageChange, gameObject); }
protected override void ConduitTick(float delta) { UpdateConduitBlockedStatus(); bool dispensed = false; if (!operational.IsOperational && !AlwaysDispense) { return; } foreach (GameObject item in storage.items) { if (item.GetComponent <PrimaryElement>()?.Element.id == SimHashes.Water) { item.AddOrGet <Pickupable>(); } } PrimaryElement element = FindSuitableElement(); if (element != null) { element.KeepZeroMassObject = true; IConduitFlow iConduitManager = GetConduitManager(); if (iConduitManager == null) { Debug.LogError($"[MultiIO] OutputPort.ConduitTick(): iConduitManager is null"); } //Solid Conduits do not use the same kind of flow manager, so the code must be separated if (ConduitType == ConduitType.Solid) { SolidConduitFlow solidManager = iConduitManager as SolidConduitFlow; if (solidManager == null) { Debug.LogError($"[MultiIO] OutputPort.ConduitTick(): solidManager is null"); } //Solid conveyor only needs to take elements with a Pikcupable component. The only difference between Water and Bottled Water is a Pikcupable component. Pickupable pickup = element.gameObject.GetComponent <Pickupable>(); if (pickup == null) { return; } if (pickup.PrimaryElement.Mass > SolidOutputMax) { pickup = pickup.Take(SolidOutputMax); } solidManager.AddPickupable(portCell, pickup); dispensed = true; } else if (ConduitType == ConduitType.Liquid || ConduitType == ConduitType.Gas) { ConduitFlow conduitManager = iConduitManager as ConduitFlow; if (conduitManager == null) { Debug.LogError($"[MutiIO] OutputPort.ConduitTick(): conduitManager is null"); return; } float amountMoved = conduitManager.AddElement(portCell, element.ElementID, element.Mass, element.Temperature, element.DiseaseIdx, element.DiseaseCount); if (amountMoved > 0f) { float movedRatio = amountMoved / element.Mass; int movedDisease = (int)(movedRatio * (float)element.DiseaseCount); element.ModifyDiseaseCount(-movedDisease, "ConduitDispenser.ConduitUpdate"); element.Mass -= amountMoved; _parent.Trigger((int)GameHashes.OnStorageChange, element.gameObject); dispensed = true; } } } isDispensing = dispensed; }
public void UpdateState(float dt) { bool isSatisfied = this.consumer.IsSatisfied; this.envTemp = 0f; this.cellCount = 0; if (this.occupyArea != null && base.gameObject != null) { this.occupyArea.TestArea(Grid.PosToCell(base.gameObject), this, AdvancedAirConditioner.UpdateStateCbDelegate); this.envTemp /= (float)this.cellCount; } _lastEnvTemp(this, this.envTemp); //this.lastEnvTemp = this.envTemp; List <GameObject> items = this.storage.items; for (int i = 0; i < items.Count; i++) { PrimaryElement element = items[i].GetComponent <PrimaryElement>(); if (element.Mass > 0f && (!isLiquidConditioner && element.Element.IsGas || isLiquidConditioner && element.Element.IsLiquid)) { isSatisfied = true; _lastGasTemp(this, element.Temperature); //this.lastGasTemp = storage.Temperature; float temperatureNew = element.Temperature + this.temperatureDelta; if (this.useTarget) { temperatureNew = this.targetTemperature; //# } if (temperatureNew < 1f) { temperatureNew = 1f; this.lowTempLag = Mathf.Min(this.lowTempLag + dt / 5f, 1f); } else { this.lowTempLag = Mathf.Min(this.lowTempLag - dt / 5f, 0f); } _lowTempLag(this, this.lowTempLag); ConduitFlow conduit = this.isLiquidConditioner ? Game.Instance.liquidConduitFlow : Game.Instance.gasConduitFlow; float mass_max = element.Mass; float temperatureCooled = temperatureNew - element.Temperature; if (this.useMassReduction) { // mass cannot be greater than the pipe size minus pipe content //mass_max = Math.Min(mass_max, this.consumer.consumptionRate - conduit.GetContents(this.cooledAirOutputCell).mass); // max of mass that could be moved with the DPUMax float mass_DPU = this.DPUMax / (temperatureCooled * element.Element.specificHeatCapacity); mass_max = Math.Min(mass_max, mass_DPU); } float mass_output = conduit.AddElement(this.cooledAirOutputCell, element.ElementID, mass_max, temperatureNew, element.DiseaseIdx, element.DiseaseCount); element.KeepZeroMassObject = true; float diseasePercent = mass_output / element.Mass; int diseaseCount = (int)((float)element.DiseaseCount * diseasePercent); element.Mass -= mass_output; element.ModifyDiseaseCount(-diseaseCount, "AirConditioner.UpdateState"); float DPU_removed = temperatureCooled * element.Element.specificHeatCapacity * mass_output; float display_dt = (this.lastSampleTime > 0f) ? (Time.time - this.lastSampleTime) : 1f; this.lastSampleTime = Time.time; GameComps.StructureTemperatures.ProduceEnergy(this.structureTemperature, -DPU_removed, STRINGS.BUILDING.STATUSITEMS.OPERATINGENERGY.PIPECONTENTS_TRANSFER, display_dt); break; } } if (Time.time - this.lastSampleTime > 2f) { GameComps.StructureTemperatures.ProduceEnergy(this.structureTemperature, 0f, STRINGS.BUILDING.STATUSITEMS.OPERATINGENERGY.PIPECONTENTS_TRANSFER, Time.time - this.lastSampleTime); this.lastSampleTime = Time.time; } this.operational.SetActive(isSatisfied, false); this.Trigger((int)GameHashes.ActiveChanged, this); //this.UpdateStatus(); }
private void ConvertMass() { float speedMultiplier = GetSpeedMultiplier(); float num = 1f * speedMultiplier; float num2 = 1f; for (int i = 0; i < consumedElements.Length; i++) { ConsumedElement consumedElement = consumedElements[i]; float num3 = consumedElement.massConsumptionRate * num * num2; if (num3 <= 0f) { num2 = 0f; break; } float num4 = 0f; for (int j = 0; j < storage.items.Count; j++) { GameObject gameObject = storage.items[j]; if (!((UnityEngine.Object)gameObject == (UnityEngine.Object)null) && gameObject.HasTag(consumedElement.tag)) { PrimaryElement component = gameObject.GetComponent <PrimaryElement>(); float num5 = Mathf.Min(num3, component.Mass); num4 += num5 / num3; } } num2 = Mathf.Min(num2, num4); } if (!(num2 <= 0f)) { SimUtil.DiseaseInfo diseaseInfo = SimUtil.DiseaseInfo.Invalid; diseaseInfo.idx = byte.MaxValue; diseaseInfo.count = 0; float num6 = 0f; float num7 = 0f; float num8 = 0f; for (int k = 0; k < consumedElements.Length; k++) { ConsumedElement consumedElement2 = consumedElements[k]; float num9 = consumedElement2.massConsumptionRate * num * num2; Game.Instance.accumulators.Accumulate(consumedElement2.accumulator, num9); for (int l = 0; l < storage.items.Count; l++) { GameObject gameObject2 = storage.items[l]; if (!((UnityEngine.Object)gameObject2 == (UnityEngine.Object)null)) { if (gameObject2.HasTag(consumedElement2.tag)) { PrimaryElement component2 = gameObject2.GetComponent <PrimaryElement>(); component2.KeepZeroMassObject = true; float num10 = Mathf.Min(num9, component2.Mass); float num11 = num10 / component2.Mass; int num12 = (int)(num11 * (float)component2.DiseaseCount); float num13 = num10 * component2.Element.specificHeatCapacity; num8 += num13; num7 += num13 * component2.Temperature; component2.Mass -= num10; component2.ModifyDiseaseCount(-num12, "ElementConverter.ConvertMass"); num6 += num10; diseaseInfo = SimUtil.CalculateFinalDiseaseInfo(diseaseInfo.idx, diseaseInfo.count, component2.DiseaseIdx, num12); num9 -= num10; if (num9 <= 0f) { break; } } if (num9 <= 0f) { Debug.Assert(num9 <= 0f); } } } } float num14 = (!(num8 > 0f)) ? 0f : (num7 / num8); if (onConvertMass != null && num6 > 0f) { onConvertMass(num6); } if (outputElements != null && outputElements.Length > 0) { for (int m = 0; m < outputElements.Length; m++) { OutputElement outputElement = outputElements[m]; SimUtil.DiseaseInfo a = diseaseInfo; if (totalDiseaseWeight <= 0f) { a.idx = byte.MaxValue; a.count = 0; } else { float num15 = outputElement.diseaseWeight / totalDiseaseWeight; a.count = (int)((float)a.count * num15); } if (outputElement.addedDiseaseIdx != 255) { a = SimUtil.CalculateFinalDiseaseInfo(a, new SimUtil.DiseaseInfo { idx = outputElement.addedDiseaseIdx, count = outputElement.addedDiseaseCount }); } float num16 = outputElement.massGenerationRate * OutputMultiplier * num * num2; Game.Instance.accumulators.Accumulate(outputElement.accumulator, num16); float num17 = 0f; num17 = ((!outputElement.useEntityTemperature && (num14 != 0f || outputElement.minOutputTemperature != 0f)) ? Mathf.Max(outputElement.minOutputTemperature, num14) : GetComponent <PrimaryElement>().Temperature); Element element = ElementLoader.FindElementByHash(outputElement.elementHash); if (outputElement.storeOutput) { PrimaryElement primaryElement = storage.AddToPrimaryElement(outputElement.elementHash, num16, num17); if ((UnityEngine.Object)primaryElement == (UnityEngine.Object)null) { if (element.IsGas) { storage.AddGasChunk(outputElement.elementHash, num16, num17, a.idx, a.count, true, true); } else if (element.IsLiquid) { storage.AddLiquid(outputElement.elementHash, num16, num17, a.idx, a.count, true, true); } else { GameObject go = element.substance.SpawnResource(base.transform.GetPosition(), num16, num17, a.idx, a.count, true, false, false); storage.Store(go, true, false, true, false); } } else { primaryElement.AddDisease(a.idx, a.count, "ElementConverter.ConvertMass"); } } else { Vector3 position = base.transform.GetPosition(); float x = position.x + outputElement.outputElementOffset.x; Vector3 position2 = base.transform.GetPosition(); Vector3 vector = new Vector3(x, position2.y + outputElement.outputElementOffset.y, 0f); int num18 = Grid.PosToCell(vector); if (element.IsLiquid) { int idx = element.idx; FallingWater.instance.AddParticle(num18, (byte)idx, num16, num17, a.idx, a.count, true, false, false, false); } else if (element.IsSolid) { element.substance.SpawnResource(vector, num16, num17, a.idx, a.count, false, false, false); } else { SimMessages.AddRemoveSubstance(num18, outputElement.elementHash, CellEventLogger.Instance.OxygenModifierSimUpdate, num16, num17, a.idx, a.count, true, -1); } } if (outputElement.elementHash == SimHashes.Oxygen) { ReportManager.Instance.ReportValue(ReportManager.ReportType.OxygenCreated, num16, base.gameObject.GetProperName(), null); } } } storage.Trigger(-1697596308, base.gameObject); } }