private void ConduitUpdate(float dt) { if (Type == ConduitType.Solid) { var sFlow = SolidConduit.GetFlowManager(); if (sFlow == null || !sFlow.HasConduit(inputCell) || !IsOperational) { operational.SetActive(false, false);; return; } if (sFlow.IsConduitEmpty(inputCell)) { operational.SetActive(false, false); return; } operational.SetActive(true, false); var pickupable = sFlow.RemovePickupable(inputCell); pickupable.DeleteObject(); } else { var flowManager = Conduit.GetFlowManager(Type); if (flowManager == null || !flowManager.HasConduit(inputCell) || !IsOperational || flowManager.IsConduitEmpty(inputCell)) { operational.SetActive(false, false); return; } operational.SetActive(true, false); var contents = flowManager.GetContents(inputCell); flowManager.RemoveElement(inputCell, contents.mass); Game.Instance.accumulators.Accumulate(accumulator, contents.mass); } }
private void ConduitUpdate(float dt) { ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType); if (flowManager.HasConduit(inputCell)) { ConduitFlow.ConduitContents contents = flowManager.GetContents(inputCell); if (!(contents.mass <= 0f)) { int cell = outputCell; ConduitFlow.ConduitContents contents2 = flowManager.GetContents(cell); if (contents2.mass > 0f) { cell = secondaryOutput.Cell; contents2 = flowManager.GetContents(cell); } if (contents2.mass <= 0f) { float num = flowManager.AddElement(cell, contents.element, contents.mass, contents.temperature, contents.diseaseIdx, contents.diseaseCount); if (num > 0f) { flowManager.RemoveElement(inputCell, num); } } } } }
public static float GetMaxCapacityWithObject(int cell, ConduitType type, out GameObject obj, bool isBridge = false) { if (type != ConduitType.Gas && type != ConduitType.Liquid) { throw new System.ArgumentException($"[Pressurized] Invalid Conduit Type given to IntegrationHelper.GetMaxCapacityAt(): {type.ToString()} Type must be ConduitType.Gas or ConduitType.Liquid.", "type"); } ConduitFlow manager = Conduit.GetFlowManager(type); Pressurized pressurized = GetPressurizedAt(cell, type, isBridge); if (pressurized == null) { obj = null; } else { obj = pressurized.gameObject; } if (Pressurized.IsDefault(pressurized)) { return(manager.MaxMass()); } else { return(pressurized.Info.IncreaseMultiplier * manager.MaxMass()); } }
protected override void UpdateVisualState(bool force = false) { if (wasOn != switchedOn || force) { wasOn = switchedOn; if (switchedOn) { animController.Play(ConduitSensor.ON_ANIMS, KAnim.PlayMode.Loop); int cell = Grid.PosToCell(this); ConduitFlow flowManager = Conduit.GetFlowManager(conduitType); ConduitFlow.ConduitContents contents = flowManager.GetContents(cell); Color32 c = Color.white; if (contents.diseaseIdx != 255) { Disease disease = Db.Get().Diseases[contents.diseaseIdx]; c = disease.overlayColour; } animController.SetSymbolTint(TINT_SYMBOL, c); } else { animController.Play(ConduitSensor.OFF_ANIMS, KAnim.PlayMode.Once); } } }
public unsafe void Sim200ms(float dt) { IntPtr value = ConduitTemperatureManager_Update(dt, (IntPtr)(void *)Game.Instance.simData.buildingTemperatures); ConduitTemperatureUpdateData *ptr = (ConduitTemperatureUpdateData *)(void *)value; int numEntries = ptr->numEntries; if (numEntries > 0) { Marshal.Copy((IntPtr)(void *)ptr->temperatures, temperatures, 0, numEntries); } for (int i = 0; i < ptr->numFrozenHandles; i++) { int h = ptr->frozenHandles[i]; int handleIndex = Sim.GetHandleIndex(h); ConduitInfo conduitInfo = this.conduitInfo[handleIndex]; ConduitFlow flowManager = Conduit.GetFlowManager(conduitInfo.type); flowManager.FreezeConduitContents(conduitInfo.idx); } for (int j = 0; j < ptr->numMeltedHandles; j++) { int h2 = ptr->meltedHandles[j]; int handleIndex2 = Sim.GetHandleIndex(h2); ConduitInfo conduitInfo2 = this.conduitInfo[handleIndex2]; ConduitFlow flowManager2 = Conduit.GetFlowManager(conduitInfo2.type); flowManager2.MeltConduitContents(conduitInfo2.idx); } }
private void ConduitUpdate(float dt) { operational.SetActive(operational.IsOperational, false); if (Type == ConduitType.Solid) { var sFlow = SolidConduit.GetFlowManager(); if (sFlow == null || !sFlow.HasConduit(outputCell) || !IsOperational) { return; } storage.AddOre(FilteredElement, Flow / InfiniteSourceFlowControl.GramsPerKilogram, Temp, 0, 0, false, false); sFlow.GetContents(outputCell); return; } else { var flowManager = Conduit.GetFlowManager(Type); if (flowManager == null || !flowManager.HasConduit(outputCell) || !IsOperational) { return; } var delta = flowManager.AddElement(outputCell, FilteredElement, Flow / InfiniteSourceFlowControl.GramsPerKilogram, Temp, 0, 0); Game.Instance.accumulators.Accumulate(accumulator, delta); } }
public bool CanConvertAtAll() { float filterAmt = 0; float liquidAmt = 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; } else if (elem.Element.IsLiquid /*&& elem.DiseaseIdx != Byte.MaxValue*/) { liquidAmt += elem.Mass; } } if (filterAmt <= 0.1f || liquidAmt <= 0.1f) { return(false); // non-zero to prevent constant activity } ConduitFlow flowManager = Conduit.GetFlowManager(ConduitType.Liquid); return(flowManager.HasConduit(outCell)); }
protected override void OnCleanUp() { Conduit.GetNetworkManager(Type).RemoveFromNetworks(_secondaryOutputCell, _secondOutputItem, true); Conduit.GetFlowManager(Type).RemoveConduitUpdater(ConduitUpdate); Game.Instance.accumulators.Remove(_accumulator); base.OnCleanUp(); }
public static bool Prefix(float dt, ValveBase __instance, float ___currentFlow, int ___outputCell, int ___inputCell, HandleVector <int> .Handle ___flowAccumulator) { ConduitFlow flowManager = Conduit.GetFlowManager(__instance.conduitType); if (!flowManager.HasConduit(___inputCell) || !flowManager.HasConduit(___outputCell)) { __instance.UpdateAnim(); } else { ConduitFlow.ConduitContents input_content = flowManager.GetConduit(___inputCell).GetContents(flowManager); ConduitFlow.ConduitContents output_content = flowManager.GetConduit(___outputCell).GetContents(flowManager); float mass_input = Mathf.Min(input_content.mass, ___currentFlow * dt); float mass_output = output_content.mass; float mass_limit = Mathf.Max(___currentFlow - mass_output, 0); // mass on output cannot exceed flow setting mass_input = Mathf.Min(mass_input, mass_limit); // set new input mass if (mass_input > 0f) { float disease_percent = mass_input / input_content.mass; int disease_count = (int)(disease_percent * input_content.diseaseCount); float mass_moved = flowManager.AddElement(___outputCell, input_content.element, mass_input, input_content.temperature, input_content.diseaseIdx, disease_count); Game.Instance.accumulators.Accumulate(___flowAccumulator, mass_moved); if (mass_moved > 0f) { flowManager.RemoveElement(___inputCell, mass_moved); } } __instance.UpdateAnim(); } return(false); }
protected override void OnCleanUp() { this.Unsubscribe((int)GameHashes.RefreshUserMenu); Game.Instance.accumulators.Remove(this.flowAccumulator); Conduit.GetFlowManager(this.conduitType).RemoveConduitUpdater(new Action <float>(this.ConduitUpdate)); //# //base.OnCleanUp(); }
private float GetContainedMass() { int cell = Grid.PosToCell(this); ConduitFlow flowManager = Conduit.GetFlowManager(conduitType); return(flowManager.GetContents(cell).mass); }
protected override void ConduitUpdate(float dt) { this.currentValue = 0; // spawn code should never toggle as it crashes on load if (dt < 0) { return; } int cell = Grid.PosToCell(this); ConduitFlow flowManager = Conduit.GetFlowManager(this.conduitType); if (flowManager.HasConduit(cell)) { if (flowManager != null) { var conduit = flowManager.GetConduit(cell); var lastFlow = conduit.GetLastFlowInfo(flowManager); if (lastFlow.direction != ConduitFlow.FlowDirections.None) { this.currentValue = (lastFlow.contents.mass) * 1000; } } } if (this.activateAboveThreshold) { // Empty is always false if (this.currentValue <= 0f) { if (base.IsSwitchedOn) { this.Toggle(); } return; } // Full is always true if (this.currentValue >= this.max) { if (!base.IsSwitchedOn) { this.Toggle(); } return; } if ((this.currentValue > this.threshold && !base.IsSwitchedOn) || (this.currentValue <= this.threshold && base.IsSwitchedOn)) { this.Toggle(); } } else if ((this.currentValue > this.threshold && base.IsSwitchedOn) || (this.currentValue <= this.threshold && !base.IsSwitchedOn)) { this.Toggle(); } }
protected override void OnCleanUp() { IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType); networkManager.RemoveFromNetworks(secondaryInput.Cell, secondaryInput, true); Conduit.GetFlowManager(portInfo.conduitType).RemoveConduitUpdater(ConduitUpdate); base.OnCleanUp(); }
public static void RegisterConduitUpdater() { if (!isUpdaterRegistered) { Conduit.GetFlowManager(ConduitType.Gas).AddConduitUpdater(new Action <float>(WarpSpaceManager.GasConduitUpdate), ConduitFlowPriority.Default); Conduit.GetFlowManager(ConduitType.Liquid).AddConduitUpdater(new Action <float>(WarpSpaceManager.LiquidConduitUpdate), ConduitFlowPriority.Default); isUpdaterRegistered = true; } }
protected override void OnSpawn() { base.OnSpawn(); Building component = GetComponent <Building>(); inputCell = component.GetUtilityInputCell(); outputCell = component.GetUtilityOutputCell(); Conduit.GetFlowManager(type).AddConduitUpdater(ConduitUpdate, ConduitFlowPriority.Default); }
public static void UnregisterConduitUpdate() { if (isUpdaterRegistered) { Conduit.GetFlowManager(ConduitType.Gas).RemoveConduitUpdater(new Action <float>(WarpSpaceManager.GasConduitUpdate)); Conduit.GetFlowManager(ConduitType.Liquid).RemoveConduitUpdater(new Action <float>(WarpSpaceManager.LiquidConduitUpdate)); isUpdaterRegistered = false; } }
protected override void OnSpawn() { base.OnSpawn(); animController = GetComponent <KBatchedAnimController>(); base.OnToggle += OnSwitchToggled; UpdateLogicCircuit(); UpdateVisualState(true); wasOn = switchedOn; Conduit.GetFlowManager(conduitType).AddConduitUpdater(ConduitUpdate, ConduitFlowPriority.Default); }
protected override void OnSpawn() { base.OnSpawn(); var building = GetComponent <Building>(); inputCell = building.GetUtilityInputCell(); Conduit.GetFlowManager(Type).AddConduitUpdater(ConduitUpdate); }
private void GetConduitData(out float temperature, out float mass, out int germs, out Element element) { int cell = Grid.PosToCell(this); var content = Conduit.GetFlowManager(conduitType).GetContents(cell); temperature = content.temperature; mass = content.mass; germs = content.diseaseCount; element = ElementLoader.FindElementByHash(content.element); }
protected override void OnSpawn() { base.OnSpawn(); operational.SetActive(operational.IsOperational, false); var building = GetComponent <Building>(); inputCell = building.GetUtilityInputCell(); Conduit.GetFlowManager(Type).AddConduitUpdater(ConduitUpdate); }
protected override void OnSpawn() { base.OnSpawn(); RefreshStatusItem(); //Remove the ValveBase's default ConduitUpdate and replace it with our own custom handler, so we can implement the buffer mode behavior. Conduit.GetFlowManager(valveBase.conduitType).RemoveConduitUpdater(GetBaseConduitUpdate()); Conduit.GetFlowManager(valveBase.conduitType).AddConduitUpdater(ConduitUpdate); Subscribe((int)GameHashes.RefreshUserMenu, OnRefreshUserMenuDelegate); Subscribe((int)GameHashes.StatusChange, OnRefreshUserMenuDelegate); }
protected override void OnCleanUp() { IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.portInfo.conduitType); networkManager.RemoveFromNetworks(this.sInputCell, this.itemSInput, true); ConduitFlow flowManager = Conduit.GetFlowManager(this.portInfo.conduitType); flowManager.RemoveConduitUpdater(this.OnConduitTick); base.OnCleanUp(); }
public static float GetMaxCapacityAt(int cell, ConduitType type, bool isBridge = false) { if (type != ConduitType.Gas && type != ConduitType.Liquid) { throw new System.ArgumentException($"[Pressurized] Invalid Conduit Type given to IntegrationHelper.GetMaxCapacityAt(): {type.ToString()} Type must be ConduitType.Gas or ConduitType.Liquid.", "type"); } ConduitFlow manager = Conduit.GetFlowManager(type); return(Pressurized.GetMaxCapacity(GetPressurizedAt(cell, type, isBridge))); }
protected override void OnSpawn() { //base.OnSpawn(); Building component = base.GetComponent <Building>(); this.inputCell = component.GetUtilityInputCell(); this.outputCell = component.GetUtilityOutputCell(); Conduit.GetFlowManager(this.conduitType).AddConduitUpdater(new Action <float>(this.ConduitUpdate), ConduitFlowPriority.Default); //# this.UpdateAnim(); this.OnCmpEnable(); }
private void UpdateConduitBlockedStatus() { ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType); bool flag = flowManager.IsConduitEmpty(filteredCell); StatusItem conduitBlockedMultiples = Db.Get().BuildingStatusItems.ConduitBlockedMultiples; bool flag2 = conduitBlockedStatusItemGuid != Guid.Empty; if (flag == flag2) { conduitBlockedStatusItemGuid = selectable.ToggleStatusItem(conduitBlockedMultiples, conduitBlockedStatusItemGuid, !flag, null); } }
public static float GetMaxCapacity(Pressurized pressure) { ConduitFlow manager = Conduit.GetFlowManager(pressure.ConduitType); if (IsDefault(pressure)) { return(manager.MaxMass()); } else { return(pressure.Info.IncreaseMultiplier * manager.MaxMass()); } }
protected override void OnSpawn() { base.OnSpawn(); outputCell = building.GetUtilityOutputCell(); Conduit.GetFlowManager(conduitType).AddConduitUpdater(ConduitUpdate); filterable.onFilterChanged += new Action <Tag>(OnFilterChanged); OnFilterChanged(filterable.SelectedTag); selectable.SetStatusItem(Db.Get().StatusItemCategories.Main, filterStatusItem, this); }
private void ForceRebuild() { //Rebuild the conduit flow network, so that conduit contents transfer no heat. ConduitFlow manager = conduit.GetFlowManager(); if (manager == null) { Debug.LogError($"[Pressurized] Could not retrieve the conduit flow manager for conduit type: {ConduitType}"); return; } //Without forcing the rebuild, the conduit system will not know that this conduit is now made out of insulation. Rebuilds normally occur when conduits are built/destroyed manager.ForceRebuildNetworks(); }
private void ConduitUpdate(float dt) { var flowManager = Conduit.GetFlowManager(Type); if (flowManager == null || !flowManager.HasConduit(outputCell) || !GetComponent <Operational>().IsOperational) { return; } var delta = flowManager.AddElement(outputCell, FilteredElement, Flow / InfiniteSourceFlowControl.GramsPerKilogram, Temp, 0, 0); Game.Instance.accumulators.Accumulate(accumulator, delta); }
protected override void OnSpawn() { base.OnSpawn(); var building = GetComponent <Building>(); outputCell = building.GetUtilityOutputCell(); Conduit.GetFlowManager(Type).AddConduitUpdater(ConduitUpdate); OnFilterChanged(ElementLoader.FindElementByHash(FilteredElement).tag); filterable.onFilterChanged += new Action <Tag>(OnFilterChanged); GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, filterStatusItem, this); }