/// <summary> /// Creates an inert output port that does not automatically handle Conduit Update behavior. The building must define its own behavior for the output port. /// </summary> /// <param name="conduitType">The type of conduit this port should attach to.</param> /// <param name="offset">The offset (left-right, down-up) of where this port is located. Offsets begin bottom-left.</param> /// <returns></returns> public OutputPort AddOutputPortInert(ConduitType conduitType, CellOffset offset) { OutputPort port = AddOutputPort(conduitType, offset); port.UseConduitUpdater = false; return(port); }
protected override void OnSpawn() { base.OnSpawn(); _spawned = true; Debug.Log($"[MultiIO] ConduitIO.OnSpawn() -> ConduitType: {ConduitType.ToString()} CellOffset: {CellOffset.x + "," + CellOffset.y}"); portCell = GetPortCell(); MultiIOExtensions.RegisterPort(portCell, this); //Register an event listener for any changes to the grid at the location of this port. ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(int)GetConduitObjectLayer()]; partitionerEntry = GameScenePartitioner.Instance.Add("ConduitIO.OnSpawn", _parent, portCell, layer, delegate { UpdateConduitExistsStatus(); }); //Register this conduit to the relevant network. Allows the network to determine flow direction. IUtilityNetworkMgr networkManager = GetNetworkManager(); _networkItem = new FlowUtilityNetwork.NetworkItem(ConduitType, EndpointType, portCell, _parent); networkManager.AddToNetworks(portCell, _networkItem, EndpointType != Endpoint.Conduit); if (UseConduitUpdater) { GetConduitManager().AddConduitUpdater(ConduitTick, FlowPriority); } UpdateConduitExistsStatus(true); }
protected override void OnSpawn() { base.OnSpawn(); ScenePartitionerLayer scenePartitionerLayer = null; Building component = GetComponent <Building>(); utilityCell = component.GetUtilityOutputCell(); conduitType = component.Def.OutputConduitType; switch (component.Def.OutputConduitType) { case ConduitType.Gas: scenePartitionerLayer = GameScenePartitioner.Instance.gasConduitsLayer; break; case ConduitType.Liquid: scenePartitionerLayer = GameScenePartitioner.Instance.liquidConduitsLayer; break; case ConduitType.Solid: scenePartitionerLayer = GameScenePartitioner.Instance.solidConduitsLayer; break; } UpdateConnectionState(true); UpdatePipeRoomState(true); if (scenePartitionerLayer != null) { partitionerEntry = GameScenePartitioner.Instance.Add("RequireOutputs", base.gameObject, utilityCell, scenePartitionerLayer, delegate { UpdateConnectionState(false); }); } GetConduitFlow().AddConduitUpdater(UpdatePipeState, ConduitFlowPriority.First); }
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()); } }
public static void Postfix(BuildingCellVisualizer __instance, HashedString mode) { var instance = Traverse.Create(__instance); var building = instance.Field("building").GetValue <Building>(); var secondaryOutput = building.Def.BuildingComplete.GetComponent <ISecondaryOutput>(); if (secondaryOutput == null) { return; } ConduitType secondaryConduitType = secondaryOutput.GetSecondaryConduitType(); if (secondaryConduitType != ConduitType.Solid) { return; } var resources = instance.Field("resources").GetValue <BuildingCellVisualizerResources>(); var iconsField = instance.Field("icons"); var icons = iconsField.GetValue <Dictionary <GameObject, UnityEngine.UI.Image> >(); var visualizerField = instance.Field("secondaryOutputVisualizer"); if (icons == null) { return; } var visualizer = visualizerField.GetValue <GameObject>(); if (visualizer == null) { visualizer = Util.KInstantiate(Assets.UIPrefabs.ResourceVisualizer, GameScreenManager.Instance.worldSpaceCanvas); visualizer.transform.SetAsFirstSibling(); icons.Add(visualizer, visualizer.transform.GetChild(0).GetComponent <UnityEngine.UI.Image>()); visualizerField.SetValue(visualizer); return; } if (mode != OverlayModes.SolidConveyor.ID || !building || !resources) { return; } var offset = secondaryOutput.GetSecondaryConduitOffset(); DrawUtilityIcon(ref icons, GetVisualizerCell(building, offset), resources.liquidOutputIcon, ref visualizer, BuildingCellVisualizer.secondOutputColour); visualizerField.SetValue(visualizer); iconsField.SetValue(icons); }
protected BuildingDef CreateBuildingDef(ConduitType conduitType, string anim, string ID) { int width = 1; int height = 2; int hitpoints = 100; float construction_time = 120f; float[] tIER = BUILDINGS.CONSTRUCTION_MASS_KG.TIER4; string[] rAW_METALS = MATERIALS.ALL_METALS; float melting_point = 1600f; BuildLocationRule build_location_rule = BuildLocationRule.Anywhere; EffectorValues decor = BUILDINGS.DECOR.PENALTY.TIER1; EffectorValues noise = NOISE_POLLUTION.NOISY.TIER1; BuildingDef buildingDef = BuildingTemplates.CreateBuildingDef(ID, width, height, anim, hitpoints, construction_time, tIER, rAW_METALS, melting_point, build_location_rule, decor, noise, 0.2f); buildingDef.InputConduitType = conduitType; buildingDef.OutputConduitType = conduitType; buildingDef.Floodable = false; buildingDef.ViewMode = conduitType == ConduitType.Liquid ? OverlayModes.LiquidConduits.ID : OverlayModes.GasConduits.ID; buildingDef.AudioCategory = "HollowMetal"; buildingDef.PowerInputOffset = new CellOffset(0, 1); buildingDef.UtilityInputOffset = new CellOffset(0, 0); buildingDef.UtilityOutputOffset = new CellOffset(0, 1); buildingDef.EnergyConsumptionWhenActive = 10f; buildingDef.RequiresPowerInput = true; buildingDef.PermittedRotations = PermittedRotations.R360; return(buildingDef); }
/// <summary> /// Creates an inert input port that does not automatically handle Conduit Update behavior. The building must define its own behavior for the input port. /// </summary> /// <param name="conduitType">The type of conduit this port should attach to.</param> /// <param name="offset">The offset (left-right, down-up) of where this port is located. Offsets begin bottom-left.</param> /// <param name="iconColor">The color the port icon will appear as.</param> /// <returns></returns> public InputPort AddInputPortInert(ConduitType conduitType, CellOffset offset, Color iconColor) { InputPort port = AddInputPort(conduitType, offset, GameTags.Any, iconColor); port.UseConduitUpdater = false; return(port); }
public static void DoPostConfigureComplete(GameObject go, float suckRate, ConduitType conduitType, float overPressureThreshold) { go.AddOrGetDef <OperationalController.Def>(); go.AddOrGet <EnergyConsumer>(); FanRotatablePassiveElementConsumer elementConsumer1 = go.AddComponent <FanRotatablePassiveElementConsumer>(); switch (conduitType) { case ConduitType.Gas: elementConsumer1.configuration = ElementConsumer.Configuration.AllGas; break; case ConduitType.Liquid: elementConsumer1.configuration = ElementConsumer.Configuration.AllLiquid; break; } elementConsumer1.consumptionRate = suckRate; elementConsumer1.storeOnConsume = true; elementConsumer1.showInStatusPanel = false; elementConsumer1.consumptionRadius = 1; elementConsumer1.rotatableCellOffset = new Vector3(0f, -1f); elementConsumer1.showDescriptor = false; Storage storage = go.AddOrGet <Storage>(); storage.capacityKg = 2 * suckRate; storage.showInUI = true; Fan fan = go.AddOrGet <Fan>(); fan.conduitType = conduitType; fan.overpressureMass = overPressureThreshold; GeneratedBuildings.RemoveLoopingSounds(go); go.GetComponent <KPrefabID>().AddTag(GameTags.FloorTiles, false); }
private static void UpdateConduitsOfWarpGates(float dt, ConduitType warpGateType) { try { if (warpGateType == ConduitType.Liquid) { var requesters = _liquidRequesters.Values.Where(x => x.Channel != 10000).ToList(); var providers = _liquidProviders.Values.Where(x => x.Channel != 10000).ToList(); if (requesters.Count == 0 || providers.Count == 0) { return; } PushFluid(requesters, providers); } else { var requesters = _gasRequesters.Values.Where(x => x.Channel != 10000).ToList(); var providers = _gasProviders.Values.Where(x => x.Channel != 10000).ToList(); if (requesters.Count == 0 || providers.Count == 0) { return; } PushFluid(requesters, providers); } } catch (Exception ex) { Logger.LogFormat("Exception in WarpSpaceManager.UpdateConduitsOfWarpGates: {0}\n{1}", ex.Message, ex.StackTrace); } }
public DiseaseContainer(GameObject go, byte elemIdx) { this.elemIdx = elemIdx; isContainer = (go.GetComponent <IUserControlledCapacity>() != null); Conduit component = go.GetComponent <Conduit>(); if ((Object)component != (Object)null) { conduitType = component.type; } else { conduitType = ConduitType.None; } controller = go.GetComponent <KBatchedAnimController>(); overpopulationCount = 1; instanceGrowthRate = 1f; accumulatedError = 0f; visualDiseaseProvider = null; autoDisinfectable = go.GetComponent <AutoDisinfectable>(); if ((Object)autoDisinfectable != (Object)null) { AutoDisinfectableManager.Instance.AddAutoDisinfectable(autoDisinfectable); } }
public HandleVector <int> .Handle Allocate(ConduitType conduit_type, int conduit_idx, HandleVector <int> .Handle conduit_structure_temperature_handle, ref ConduitFlow.ConduitContents contents) { StructureTemperaturePayload payload = GameComps.StructureTemperatures.GetPayload(conduit_structure_temperature_handle); Element element = payload.primaryElement.Element; BuildingDef def = payload.building.Def; float conduit_heat_capacity = def.MassForTemperatureModification * element.specificHeatCapacity; float conduit_thermal_conductivity = element.thermalConductivity * def.ThermalConductivity; int num = ConduitTemperatureManager_Add(contents.temperature, contents.mass, (int)contents.element, payload.simHandleCopy, conduit_heat_capacity, conduit_thermal_conductivity, def.ThermalConductivity < 1f); HandleVector <int> .Handle result = default(HandleVector <int> .Handle); result.index = num; int handleIndex = Sim.GetHandleIndex(num); if (handleIndex + 1 > temperatures.Length) { Array.Resize(ref temperatures, (handleIndex + 1) * 2); Array.Resize(ref conduitInfo, (handleIndex + 1) * 2); } temperatures[handleIndex] = contents.temperature; conduitInfo[handleIndex] = new ConduitInfo { type = conduit_type, idx = conduit_idx }; return(result); }
public NetworkItem(ConduitType conduit_type, Endpoint endpoint_type, int cell, GameObject parent) { conduitType = conduit_type; endpointType = endpoint_type; this.cell = cell; this.parent = parent; }
CellOffset ISecondaryInput.GetSecondaryConduitOffset(ConduitType type) { if (type == fuelPortInfo.conduitType) { return(fuelPortInfo.offset); } return(CellOffset.none); }
public static ConduitType GetConduitType(ValveSideScreen __instance) { FieldInfo fi1 = AccessTools.Field(typeof(ValveSideScreen), "targetValve"); FieldInfo fi2 = AccessTools.Field(typeof(Valve), "valveBase"); ConduitType type = ((ValveBase)fi2.GetValue(fi1.GetValue(__instance))).conduitType; return(type); }
internal void AssignPort(DisplayConduitPortInfo port) { this.type = port.type; this.offset = port.offset; this.offsetFlipped = port.offsetFlipped; this.input = port.input; this.color = port.color; this.sprite = GetSprite(); }
private static void Postfix(SimpleInfoScreen __instance, GameObject ___storagePanel, GameObject ___selectedTarget, ref Dictionary <string, GameObject> ___storageLabels) { if (___selectedTarget.GetComponent <TeleStorage>() == null) { return; } ConduitType type = ___selectedTarget.GetComponent <TeleStorage>().Type; ___storagePanel.gameObject.SetActive(true); ___storagePanel.GetComponent <CollapsibleDetailContentPanel>().HeaderLabel.text = (!(___selectedTarget.GetComponent <MinionIdentity>() != null) ? STRINGS.UI.DETAILTABS.DETAILS.GROUPNAME_CONTENTS : STRINGS.UI.DETAILTABS.DETAILS.GROUPNAME_MINION_CONTENTS); if (___storageLabels == null) { ___storageLabels = new Dictionary <string, GameObject>(); } foreach (KeyValuePair <string, GameObject> storageLabel in ___storageLabels) { storageLabel.Value.SetActive(false); } int num = 0; foreach (SimHashes element in TeleStorageData.Instance.storedElementsMap.Keys) { StoredItem item = TeleStorageData.Instance.storedElementsMap[element]; if (item.mass > 0.0f) { Element elementObj = ElementLoader.FindElementByHash(element); if (elementObj.IsLiquid && !type.Equals(ConduitType.Liquid)) { continue; } if (elementObj.IsGas && !type.Equals(ConduitType.Gas)) { continue; } GameObject storageLabel = Traverse.Create(__instance).Method("AddOrGetStorageLabel", new Type[] { typeof(Dictionary <string, GameObject>), typeof(GameObject), typeof(string) }).GetValue <GameObject>(new object[] { ___storageLabels, ___storagePanel, "storage_" + num.ToString() }); ++num; storageLabel.GetComponentInChildren <ToolTip>().ClearMultiStringTooltip(); string formattedName = elementObj.name; string str1 = string.Format(STRINGS.UI.DETAILTABS.DETAILS.CONTENTS_MASS, formattedName, GameUtil.GetFormattedMass(item.mass, GameUtil.TimeSlice.None, GameUtil.MetricMassFormat.UseThreshold, true, "{0:0.#}")); string str2 = string.Format(STRINGS.UI.DETAILTABS.DETAILS.CONTENTS_TEMPERATURE, str1, GameUtil.GetFormattedTemperature(item.temperature, GameUtil.TimeSlice.None, GameUtil.TemperatureInterpretation.Absolute, true, false)); if (item.diseaseIdx != byte.MaxValue) { str2 += string.Format(STRINGS.UI.DETAILTABS.DETAILS.CONTENTS_DISEASED, GameUtil.GetFormattedDisease(item.diseaseIdx, item.diseaseCount, false)); string formattedDisease = GameUtil.GetFormattedDisease(item.diseaseIdx, item.diseaseCount, true); storageLabel.GetComponentInChildren <ToolTip>().AddMultiStringTooltip(formattedDisease, PluginAssets.Instance.defaultTextStyleSetting); } storageLabel.GetComponentInChildren <LocText>().text = str2; } } if (num == 0) { Traverse.Create(__instance).Method("AddOrGetStorageLabel", new Type[] { typeof(Dictionary <string, GameObject>), typeof(GameObject), typeof(string) }).GetValue <GameObject>(___storageLabels, ___storagePanel, "empty").GetComponentInChildren <LocText>().text = STRINGS.UI.DETAILTABS.DETAILS.STORAGE_EMPTY; } Traverse.Create(___storagePanel.GetComponent <CollapsibleDetailContentPanel>().scalerMask).Method("Update").GetValue(); }
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))); }
private static float IntegratePressurized(float standardMax, ConduitType conduitType, int cell) { Pressurized pressure = GetPressurizedAt(cell, conduitType); if (!Pressurized.IsDefault(pressure)) { return(pressure.Info.Capacity); } return(standardMax); }
public static Pressurized GetPressurizedAt(int cell, ConduitType type, bool isBridge = false) { if (type != ConduitType.Gas && type != ConduitType.Liquid) { return(null); } int layer = isBridge ? connectionLayers[(int)type] : layers[(int)type]; return(Grid.Objects[cell, layer]?.GetComponent <Pressurized>()); }
public static GameObject GetConduitObjectAt(int cell, ConduitType type, bool isBridge = false) { if (type != ConduitType.Gas && type != ConduitType.Liquid) { return(null); } int layer = isBridge ? connectionLayers[(int)type] : layers[(int)type]; return(Grid.Objects[cell, layer]); }
CellOffset ISecondaryOutput.GetSecondaryConduitOffset(ConduitType type) { if (type == liquidWastePortInfo.conduitType) { return(liquidWastePortInfo.offset); } if (type == gasWastePortInfo.conduitType) { return(gasWastePortInfo.offset); } return(CellOffset.none); }
public static void Postfix(BuildingDef __instance, int cell, Orientation orientation, ObjectLayer layer, GameObject go) { foreach (PortDisplay2 portDisplay in __instance.BuildingComplete.GetComponents <PortDisplay2>()) { ConduitType secondaryConduitType2 = portDisplay.type; ObjectLayer objectLayerForConduitType4 = Grid.GetObjectLayerForConduitType(secondaryConduitType2); CellOffset rotatedCellOffset8 = Rotatable.GetRotatedCellOffset(portDisplay.offset, orientation); int cell11 = Grid.OffsetCell(cell, rotatedCellOffset8); __instance.MarkOverlappingPorts(Grid.Objects[cell11, (int)objectLayerForConduitType4], go); Grid.Objects[cell11, (int)objectLayerForConduitType4] = go; } }
// Get the index of the layer with the connectors (ports) for the conduit type in question internal static int GetPortObjectLayer(this ConduitType conduitType) { switch (conduitType) { case ConduitType.Gas: return((int)ObjectLayer.GasConduitConnection); case ConduitType.Liquid: return((int)ObjectLayer.LiquidConduitConnection); case ConduitType.Solid: return((int)ObjectLayer.SolidConduitConnection); } return(0); }
private static void Postfix(ValveSideScreen __instance) { Logger.LogFormat(" === FluidWarpMod_ValveSideScreen_SetTarget Postfix === "); ConduitType type = FluidWarpMod_Utils.GetConduitType(__instance); if (type == LiquidWarpConfig.CONDUIT_TYPE || type == GasWarpConfig.CONDUIT_TYPE) { ((LocText)minFlowLabelFI.GetValue(__instance)).text = "-Channel"; ((LocText)maxFlowLabelFI.GetValue(__instance)).text = "+Channel"; } }
private static void Postfix(ValveSideScreen __instance) { Debug.Log(" === FluidWarpMod_ValveSideScreen_OnSpawn Postfix === "); FieldInfo fi0 = AccessTools.Field(typeof(ValveSideScreen), "unitsLabel"); ConduitType type = FluidWarpMod_Utils.GetConduitType(__instance); if (type == (ConduitType)100 || type == (ConduitType)101) { ((LocText)fi0.GetValue(__instance)).text = "Ch."; } }
/// <summary> /// For DoPostConfigurePreview and DoPostUnderConstruction, adds a port specification that can appear during building previews. Implements no port functionality and acts as a visual placeholder until the building has been created. /// </summary> /// <param name="conduitType">The type of conduit this port should attach to.</param> /// <param name="offset">The offset (left-right, down-up) of where this port is located. Offsets begin bottom-left.</param> /// <param name="iconColor">The color the port icon will appear as.</param> /// <returns>A reference to the PreviewOutput port. Not typically needed.</returns> public PreviewOutput AddPreviewOutputPort(ConduitType conduitType, CellOffset offset, Color iconColor) { iconColor.a = 1f; GameObject obj = new GameObject(); PreviewOutput port = obj.AddComponent <PreviewOutput>(); port.ConduitType = conduitType; port.CellOffset = offset; port.IconColor = iconColor; base.AddIOPort(port); count++; return(port); }
protected T AddIOPort(ConduitType type, CellOffset offset, Color iconColor) { GameObject obj = new GameObject(); T comp = obj.AddComponent <T>(); comp.ConduitType = type; comp.CellOffset = offset; comp.IconColor = iconColor; //Allows the port component to be retrievable by searching Components in children. Better practice than having the multiples of the component attached to one GameObject comp.transform.parent = this.transform; _dirtyPortList = true; return(comp); }
/// <summary> /// Adds an OutputPort as a child Component to whatever building MultiOutput is attached to. This function can be used any number of times as long the ports remain valid. Returns a reference to the OutputPort object. /// </summary> /// <param name="conduitType">The type of conduit this port should attach to.</param> /// <param name="offset">The offset (left-right, down-up) of where this port is located. Offsets begin bottom-left.</param> /// <param name="iconColor">The color the port icon will appear as.</param> /// <param name="alwaysDispense">Whether or not this port should output from storage even if the machine is not operating.</param> /// <param name="elementFilter">If defined, will filter which elements to put through this port.</param> /// <param name="invertElementFilter">If the ElementFilter is defined, true will make the filter act as a blacklist, false will make the filter act as a whitelist.</param> /// <returns>A reference to the OutputPort that has already been attached as a child component.</returns> public OutputPort AddOutputPort(ConduitType conduitType, CellOffset offset, Color iconColor, bool alwaysDispense = false, SimHashes[] elementFilter = null, bool invertElementFilter = false) { //Debug.Log($"[MultiIO] Adding output port to building template"); iconColor.a = 1f; OutputPort port = base.AddIOPort(conduitType, offset, iconColor); port.AlwaysDispense = alwaysDispense; port.ElementFilter = elementFilter; port.InvertElementFilter = invertElementFilter; count++; return(port); //Debug.Log($"[MultiIO] Number of output ports now: {count}"); }
private bool SetContents(int cell, ConduitType conduitType, Element element, float mass, float temperature, byte diseaseIdx, int diseaseCount) { if (conduitType == ConduitType.Solid) { var conduitFlow = Game.Instance.solidConduitFlow; if (!conduitFlow.HasConduit(cell)) { return(false); } mass = Mathf.Clamp(mass, 0, MAX_SOLID_MASS); var res = element.substance.SpawnResource(Vector3.zero, mass, temperature, diseaseIdx, diseaseCount); var pc = res.GetComponent <Pickupable>(); var p = conduitFlow.RemovePickupable(cell); if (p != null) { DestroyPickupable(p); } conduitFlow.SetContents(cell, pc); updateSolidFlowVisualization = true; } else { ConduitFlow conduitFlow = conduitType == ConduitType.Liqud ? Game.Instance.liquidConduitFlow : Game.Instance.gasConduitFlow; if (!conduitFlow.HasConduit(cell)) { return(false); } var maxMass = conduitType == ConduitType.Liqud ? MAX_LIQUID_MASS : MAX_GAS_MASS; mass = Mathf.Clamp(mass, 0, maxMass); var contents = new ConduitFlow.ConduitContents(element.id, mass, temperature, diseaseIdx, diseaseCount); conduitFlow.SetContents(cell, contents); if (conduitType == ConduitType.Liqud) { updateLiquidFlowVisualization = true; } else { updateGasFlowVisualization = true; } } return(true); }
internal ConduitFlow GetConduitManager() { ConduitType conduitType = this.conduitType; if (conduitType == ConduitType.Gas) { return(Game.Instance.gasConduitFlow); } if (conduitType != ConduitType.Liquid) { return(null); } return(Game.Instance.liquidConduitFlow); }