public static CellOffset ConnectionsToOffset(UtilityConnections utilityConnections) { return(utilityConnections switch { UtilityConnections.Left => new CellOffset(-1, 0), UtilityConnections.Right => new CellOffset(1, 0), UtilityConnections.Up => new CellOffset(0, 1), _ => new CellOffset(0, -1) });
public void UpdateConnections(UtilityConnections new_connections) { _connections = new_connections; if (connectionManager != null) { int cell = Grid.PosToCell(base.transform.GetPosition()); connectionManager.SetConnections(new_connections, cell, isPhysicalBuilding); } }
public static UtilityConnections OppositeDirection(UtilityConnections utilityConnections) { switch (utilityConnections) { case UtilityConnections.Left: return(UtilityConnections.Right); case UtilityConnections.Right: return(UtilityConnections.Left); case UtilityConnections.Up: return(UtilityConnections.Down); default: return(UtilityConnections.Up); } }
public static CellOffset ConnectionsToOffset(UtilityConnections utilityConnections) { switch (utilityConnections) { case UtilityConnections.Left: return(new CellOffset(-1, 0)); case UtilityConnections.Right: return(new CellOffset(1, 0)); case UtilityConnections.Up: return(new CellOffset(0, 1)); default: return(new CellOffset(0, -1)); } }
private void FinishConstruction(UtilityConnections connections) { Rotatable component = GetComponent <Rotatable>(); Orientation orientation = ((UnityEngine.Object)component != (UnityEngine.Object)null) ? component.GetOrientation() : Orientation.Neutral; int num = Grid.PosToCell(base.transform.GetLocalPosition()); UnmarkArea(); BuildingDef def = building.Def; int cell = num; Orientation orientation2 = orientation; Storage resource_storage = storage; Tag[] selected_elements = selectedElementsTags; float temperature = initialTemperature; float time = GameClock.Instance.GetTime(); GameObject gameObject = def.Build(cell, orientation2, resource_storage, selected_elements, temperature, true, time); gameObject.transform.rotation = base.transform.rotation; Rotatable component2 = gameObject.GetComponent <Rotatable>(); if ((UnityEngine.Object)component2 != (UnityEngine.Object)null) { component2.SetOrientation(orientation); } KAnimGraphTileVisualizer component3 = GetComponent <KAnimGraphTileVisualizer>(); if ((UnityEngine.Object)component3 != (UnityEngine.Object)null) { KAnimGraphTileVisualizer component4 = gameObject.GetComponent <KAnimGraphTileVisualizer>(); component4.Connections = connections; component3.skipCleanup = true; } KSelectable component5 = GetComponent <KSelectable>(); if ((UnityEngine.Object)component5 != (UnityEngine.Object)null && component5.IsSelected && (UnityEngine.Object)gameObject.GetComponent <KSelectable>() != (UnityEngine.Object)null) { component5.Unselect(); if (PlayerController.Instance.ActiveTool.name == "SelectTool") { ((SelectTool)PlayerController.Instance.ActiveTool).SelectNextFrame(gameObject.GetComponent <KSelectable>(), false); } } storage.ConsumeAllIgnoringDisease(); finished = true; this.DeleteObject(); }
public string GetWireConnectionsString() { UtilityConnections wireConnections = GetWireConnections(); return(Game.Instance.logicCircuitSystem.GetVisualizerString(wireConnections)); }
private void BuildPath() { ApplyPathToConduitSystem(); int num = 0; for (int i = 0; i < path.Count; i++) { PathNode pathNode = path[i]; Vector3 vector = Grid.CellToPosCBC(pathNode.cell, Grid.SceneLayer.Building); UtilityConnections utilityConnections = (UtilityConnections)0; GameObject gameObject = Grid.Objects[pathNode.cell, (int)def.TileLayer]; if ((Object)gameObject == (Object)null) { utilityConnections = conduitMgr.GetConnections(pathNode.cell, false); if ((DebugHandler.InstantBuildMode || (Game.Instance.SandboxModeActive && SandboxToolParameterMenu.instance.settings.InstantBuild)) && def.IsValidBuildLocation(visualizer, vector, Orientation.Neutral) && def.IsValidPlaceLocation(visualizer, vector, Orientation.Neutral, out string _)) { BuildingDef buildingDef = def; int cell = pathNode.cell; Orientation orientation = Orientation.Neutral; Storage resource_storage = null; IList <Tag> selected_elements = selectedElements; float temperature = 293.15f; float time = GameClock.Instance.GetTime(); gameObject = buildingDef.Build(cell, orientation, resource_storage, selected_elements, temperature, true, time); } else { gameObject = def.TryPlace(null, vector, Orientation.Neutral, selectedElements, 0); if ((Object)gameObject != (Object)null) { if (!def.MaterialsAvailable(selectedElements) && !DebugHandler.InstantBuildMode) { PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, UI.TOOLTIPS.NOMATERIAL, null, vector, 1.5f, false, false); } Constructable component = gameObject.GetComponent <Constructable>(); if (component.IconConnectionAnimation(0.1f * (float)num, num, "Wire", "OutletConnected_release") || component.IconConnectionAnimation(0.1f * (float)num, num, "Pipe", "OutletConnected_release")) { num++; } Prioritizable component2 = gameObject.GetComponent <Prioritizable>(); if ((Object)component2 != (Object)null) { if ((Object)BuildMenu.Instance != (Object)null) { component2.SetMasterPriority(BuildMenu.Instance.GetBuildingPriority()); } if ((Object)PlanScreen.Instance != (Object)null) { component2.SetMasterPriority(PlanScreen.Instance.GetBuildingPriority()); } } } } } else { IUtilityItem component3 = gameObject.GetComponent <KAnimGraphTileVisualizer>(); if (component3 != null) { utilityConnections = component3.Connections; } utilityConnections |= conduitMgr.GetConnections(pathNode.cell, false); if ((Object)gameObject.GetComponent <BuildingComplete>() != (Object)null) { component3.UpdateConnections(utilityConnections); } } if (def.ReplacementLayer != ObjectLayer.NumLayers && !DebugHandler.InstantBuildMode && (!Game.Instance.SandboxModeActive || !SandboxToolParameterMenu.instance.settings.InstantBuild) && def.IsValidBuildLocation(null, vector, Orientation.Neutral)) { GameObject gameObject2 = Grid.Objects[pathNode.cell, (int)def.TileLayer]; GameObject x = Grid.Objects[pathNode.cell, (int)def.ReplacementLayer]; if ((Object)gameObject2 != (Object)null && (Object)x == (Object)null) { BuildingComplete component4 = gameObject2.GetComponent <BuildingComplete>(); if ((Object)component4 != (Object)null && (Object)component4.Def != (Object)def) { Constructable component5 = def.BuildingUnderConstruction.GetComponent <Constructable>(); component5.IsReplacementTile = true; gameObject = def.Instantiate(vector, Orientation.Neutral, selectedElements, 0); component5.IsReplacementTile = false; if (!def.MaterialsAvailable(selectedElements) && !DebugHandler.InstantBuildMode) { PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, UI.TOOLTIPS.NOMATERIAL, null, vector, 1.5f, false, false); } Grid.Objects[pathNode.cell, (int)def.ReplacementLayer] = gameObject; IUtilityItem component6 = gameObject.GetComponent <KAnimGraphTileVisualizer>(); if (component6 != null) { utilityConnections = component6.Connections; } utilityConnections |= conduitMgr.GetConnections(pathNode.cell, false); if ((Object)gameObject.GetComponent <BuildingComplete>() != (Object)null) { component6.UpdateConnections(utilityConnections); } string visualizerString = conduitMgr.GetVisualizerString(utilityConnections); string text = visualizerString; if (gameObject.GetComponent <KBatchedAnimController>().HasAnimation(visualizerString + "_place")) { text += "_place"; } Play(gameObject, text); } } } if ((Object)gameObject != (Object)null) { IUtilityItem component7 = gameObject.GetComponent <KAnimGraphTileVisualizer>(); if (component7 != null) { component7.Connections = utilityConnections; } } TileVisualizer.RefreshCell(pathNode.cell, def.TileLayer, def.ReplacementLayer); } ResourceRemainingDisplayScreen.instance.SetNumberOfPendingConstructions(0); }
protected override void OnDragComplete(Vector3 cursorDown, Vector3 cursorUp) { base.OnDragComplete(cursorDown, cursorUp); if (hasFocus) { Grid.PosToXY(cursorDown, out int x0, out int y0); Grid.PosToXY(cursorUp, out int x1, out int y1); if (x0 > x1) { Util.Swap(ref x0, ref x1); } if (y0 > y1) { Util.Swap(ref y0, ref y1); } for (int x = x0; x <= x1; ++x) { for (int y = y0; y <= y1; ++y) { int cell = Grid.XYToCell(x, y); if (Grid.IsVisible(cell)) { for (int layer = 0; layer < Grid.ObjectLayers.Length; ++layer) { GameObject gameObject = Grid.Objects[cell, layer]; Building building; if (gameObject != null && (building = gameObject.GetComponent <Building>()) != null && IsActiveLayer(GetFilterLayerFromGameObject(gameObject))) { IHaveUtilityNetworkMgr utilityNetworkManager; if ((utilityNetworkManager = building.Def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>()) != null) { UtilityConnections connectionsToRemove = 0; UtilityConnections buildingConnections = utilityNetworkManager.GetNetworkManager().GetConnections(cell, false); foreach (UtilityConnections utilityConnection in connections) { if ((buildingConnections & utilityConnection) != utilityConnection) { continue; } int offsetCell = Grid.OffsetCell(cell, Utilities.ConnectionsToOffset(utilityConnection)); if (Grid.IsValidBuildingCell(offsetCell)) { Grid.CellToXY(offsetCell, out int x2, out int y2); if (x2 >= x0 && x2 <= x1 && y2 >= y0 && y2 <= y1) { GameObject otherGameObject = Grid.Objects[offsetCell, layer]; Building otherBuilding; if (otherGameObject != null && (otherBuilding = otherGameObject.GetComponent <Building>()) != null && otherBuilding.Def.BuildingComplete.GetComponent <IHaveUtilityNetworkMgr>() != null && IsActiveLayer(GetFilterLayerFromGameObject(gameObject))) { connectionsToRemove |= utilityConnection; } } } } if (connectionsToRemove != 0) { if (building.GetComponent <KAnimGraphTileVisualizer>() != null) { building.GetComponent <KAnimGraphTileVisualizer>().UpdateConnections(buildingConnections & ~connectionsToRemove); building.GetComponent <KAnimGraphTileVisualizer>().Refresh(); } TileVisualizer.RefreshCell(cell, building.Def.TileLayer, building.Def.ReplacementLayer); utilityNetworkManager.GetNetworkManager()?.ForceRebuildNetworks(); } } } } } } } } }
protected override void OnCompleteWork(Worker worker) { float num = 0f; float num2 = 0f; bool flag = true; foreach (GameObject item in storage.items) { if (!((UnityEngine.Object)item == (UnityEngine.Object)null)) { PrimaryElement component = item.GetComponent <PrimaryElement>(); if (!((UnityEngine.Object)component == (UnityEngine.Object)null)) { num += component.Mass; num2 += component.Temperature * component.Mass; flag = (flag && component.HasTag(GameTags.Liquifiable)); } } } if (num <= 0f) { DebugUtil.LogWarningArgs(base.gameObject, "uhhh this constructable is about to generate a nan", "Item Count: ", storage.items.Count); } else { if (flag) { initialTemperature = Mathf.Min(num2 / num, 318.15f); } else { initialTemperature = Mathf.Clamp(num2 / num, 288.15f, 318.15f); } KAnimGraphTileVisualizer component2 = GetComponent <KAnimGraphTileVisualizer>(); UtilityConnections connections = (!((UnityEngine.Object)component2 == (UnityEngine.Object)null)) ? component2.Connections : ((UtilityConnections)0); if (IsReplacementTile) { int cell = Grid.PosToCell(base.transform.GetLocalPosition()); GameObject replacementCandidate = building.Def.GetReplacementCandidate(cell); if ((UnityEngine.Object)replacementCandidate != (UnityEngine.Object)null) { SimCellOccupier component3 = replacementCandidate.GetComponent <SimCellOccupier>(); if ((UnityEngine.Object)component3 != (UnityEngine.Object)null) { component3.DestroySelf(delegate { if ((UnityEngine.Object) this != (UnityEngine.Object)null && (UnityEngine.Object)base.gameObject != (UnityEngine.Object)null) { FinishConstruction(connections); } }); } else { Conduit component4 = replacementCandidate.GetComponent <Conduit>(); if ((UnityEngine.Object)component4 != (UnityEngine.Object)null) { ConduitFlow flowManager = component4.GetFlowManager(); flowManager.MarkForReplacement(cell); } BuildingComplete component5 = replacementCandidate.GetComponent <BuildingComplete>(); if ((UnityEngine.Object)component5 != (UnityEngine.Object)null) { component5.Subscribe(-21016276, delegate { FinishConstruction(connections); }); } else { Debug.LogWarning("Why am I trying to replace a: " + replacementCandidate.name); FinishConstruction(connections); } } KAnimGraphTileVisualizer component6 = replacementCandidate.GetComponent <KAnimGraphTileVisualizer>(); if ((UnityEngine.Object)component6 != (UnityEngine.Object)null) { component6.skipCleanup = true; } PrimaryElement component7 = replacementCandidate.GetComponent <PrimaryElement>(); float mass = component7.Mass; float temperature = component7.Temperature; byte diseaseIdx = component7.DiseaseIdx; int diseaseCount = component7.DiseaseCount; Debug.Assert(component7.Element != null && component7.Element.tag != (Tag)null); Deconstructable.SpawnItem(component7.transform.GetPosition(), component7.GetComponent <Building>().Def, component7.Element.tag, mass, temperature, diseaseIdx, diseaseCount); replacementCandidate.Trigger(1606648047, building.Def.TileLayer); replacementCandidate.DeleteObject(); } } else { FinishConstruction(connections); } PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Building, GetComponent <KSelectable>().GetName(), base.transform, 1.5f, false); } }
public int IsValid(int cell, NavTable nav_table) { if (!Grid.IsCellOffsetValid(cell, x, y)) { return(Grid.InvalidCell); } int num = Grid.OffsetCell(cell, x, y); if (!nav_table.IsValid(num, end)) { return(Grid.InvalidCell); } Grid.BuildFlags buildFlags = Grid.BuildFlags.Solid | Grid.BuildFlags.DupeImpassable; if (isCritter) { buildFlags |= Grid.BuildFlags.CritterImpassable; } CellOffset[] array = voidOffsets; for (int i = 0; i < array.Length; i++) { CellOffset cellOffset = array[i]; int num2 = Grid.OffsetCell(cell, cellOffset.x, cellOffset.y); if (Grid.IsValidCell(num2) && (Grid.BuildMasks[num2] & buildFlags) != 0) { if (isCritter) { return(Grid.InvalidCell); } if ((Grid.BuildMasks[num2] & Grid.BuildFlags.DupePassable) == (Grid.BuildFlags) 0) { return(Grid.InvalidCell); } } } CellOffset[] array2 = solidOffsets; for (int j = 0; j < array2.Length; j++) { CellOffset cellOffset2 = array2[j]; int num3 = Grid.OffsetCell(cell, cellOffset2.x, cellOffset2.y); if (Grid.IsValidCell(num3) && !Grid.Solid[num3]) { return(Grid.InvalidCell); } } NavOffset[] array3 = validNavOffsets; for (int k = 0; k < array3.Length; k++) { NavOffset navOffset = array3[k]; int cell2 = Grid.OffsetCell(cell, navOffset.offset.x, navOffset.offset.y); if (!nav_table.IsValid(cell2, navOffset.navType)) { return(Grid.InvalidCell); } } NavOffset[] array4 = invalidNavOffsets; for (int l = 0; l < array4.Length; l++) { NavOffset navOffset2 = array4[l]; int cell3 = Grid.OffsetCell(cell, navOffset2.offset.x, navOffset2.offset.y); if (nav_table.IsValid(cell3, navOffset2.navType)) { return(Grid.InvalidCell); } } if (start == NavType.Tube) { if (end == NavType.Tube) { GameObject gameObject = Grid.Objects[cell, 9]; GameObject gameObject2 = Grid.Objects[num, 9]; TravelTubeUtilityNetworkLink travelTubeUtilityNetworkLink = (!(bool)gameObject) ? null : gameObject.GetComponent <TravelTubeUtilityNetworkLink>(); TravelTubeUtilityNetworkLink travelTubeUtilityNetworkLink2 = (!(bool)gameObject2) ? null : gameObject2.GetComponent <TravelTubeUtilityNetworkLink>(); if ((bool)travelTubeUtilityNetworkLink) { travelTubeUtilityNetworkLink.GetCells(out int linked_cell, out int linked_cell2); if (num != linked_cell && num != linked_cell2) { return(Grid.InvalidCell); } UtilityConnections utilityConnections = UtilityConnectionsExtensions.DirectionFromToCell(cell, num); if (utilityConnections == (UtilityConnections)0) { return(Grid.InvalidCell); } UtilityConnections connections = Game.Instance.travelTubeSystem.GetConnections(num, false); if (connections != utilityConnections) { return(Grid.InvalidCell); } } else if ((bool)travelTubeUtilityNetworkLink2) { travelTubeUtilityNetworkLink2.GetCells(out int linked_cell3, out int linked_cell4); if (cell != linked_cell3 && cell != linked_cell4) { return(Grid.InvalidCell); } UtilityConnections utilityConnections2 = UtilityConnectionsExtensions.DirectionFromToCell(num, cell); if (utilityConnections2 == (UtilityConnections)0) { return(Grid.InvalidCell); } UtilityConnections connections2 = Game.Instance.travelTubeSystem.GetConnections(cell, false); if (connections2 != utilityConnections2) { return(Grid.InvalidCell); } } else { bool flag = startAxis == NavAxis.X; int cell4 = cell; for (int m = 0; m < 2; m++) { if ((flag && m == 0) || (!flag && m == 1)) { int num4 = (x > 0) ? 1 : (-1); for (int n = 0; n < Mathf.Abs(x); n++) { UtilityConnections connections3 = Game.Instance.travelTubeSystem.GetConnections(cell4, false); if (num4 > 0 && (connections3 & UtilityConnections.Right) == (UtilityConnections)0) { return(Grid.InvalidCell); } if (num4 < 0 && (connections3 & UtilityConnections.Left) == (UtilityConnections)0) { return(Grid.InvalidCell); } cell4 = Grid.OffsetCell(cell4, num4, 0); } } else { int num5 = (y > 0) ? 1 : (-1); for (int num6 = 0; num6 < Mathf.Abs(y); num6++) { UtilityConnections connections4 = Game.Instance.travelTubeSystem.GetConnections(cell4, false); if (num5 > 0 && (connections4 & UtilityConnections.Up) == (UtilityConnections)0) { return(Grid.InvalidCell); } if (num5 < 0 && (connections4 & UtilityConnections.Down) == (UtilityConnections)0) { return(Grid.InvalidCell); } cell4 = Grid.OffsetCell(cell4, 0, num5); } } } } } else { UtilityConnections connections5 = Game.Instance.travelTubeSystem.GetConnections(cell, false); if (y > 0) { if (connections5 != UtilityConnections.Down) { return(Grid.InvalidCell); } } else if (x > 0) { if (connections5 != UtilityConnections.Left) { return(Grid.InvalidCell); } } else if (x < 0) { if (connections5 != UtilityConnections.Right) { return(Grid.InvalidCell); } } else { if (y >= 0) { return(Grid.InvalidCell); } if (connections5 != UtilityConnections.Up) { return(Grid.InvalidCell); } } } } else if (start == NavType.Floor && end == NavType.Tube) { int cell5 = Grid.OffsetCell(cell, x, y); UtilityConnections connections6 = Game.Instance.travelTubeSystem.GetConnections(cell5, false); if (connections6 != UtilityConnections.Up) { return(Grid.InvalidCell); } } return(num); }