Ejemplo n.º 1
0
        new void OnDestroy()
        {
            def.Build(cell, orientation, resource_storage, selected_elements, temp, playSound, timeBuilt);

            Grid.diseaseIdx[cell]   = diseaseID;
            Grid.diseaseCount[cell] = diseaseCount;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// A wrapper method used on BuildingDef.Build to use the right material for some
 /// POI buildings.
 /// </summary>
 private static GameObject BuildFixedMaterials(BuildingDef def, int cell,
                                               Orientation orient, Storage storage, IList <Tag> elements, float temperature,
                                               bool sound, float timeBuilt)
 {
     if (def != null && def.PrefabID == MassiveHeatSinkConfig.ID && elements != null)
     {
         // Special case the AETN to iron (it uses niobium otherwise)
         elements.Clear();
         elements.Add(ElementLoader.FindElementByHash(SimHashes.Iron).tag);
     }
     return(def.Build(cell, orient, storage, elements, temperature, sound, timeBuilt));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// A wrapper method used on BuildingDef.Build to avoid melting buildings built at cold
 /// temperatures.
 /// </summary>
 private static GameObject BuildAtTemp(BuildingDef def, int cell, Orientation orient,
                                       Storage storage, IList <Tag> elements, float temperature, bool sound,
                                       float timeBuilt)
 {
     if (elements != null && elements.Count > 0)
     {
         // Lower temperature to at least the element's melt point - 1 K
         var pe = ElementLoader.GetElement(elements[0]);
         if (pe != null)
         {
             temperature = Math.Min(temperature, Math.Max(1.0f, pe.highTemp - 1.0f));
         }
     }
     return(def.Build(cell, orient, storage, elements, temperature, sound, timeBuilt));
 }
Ejemplo n.º 4
0
    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();
    }
 private void Place(int cell)
 {
     if (Grid.IsValidBuildingCell(cell))
     {
         if (SandboxToolParameterMenu.instance.settings.Entity.PrefabID() == (Tag)MinionConfig.ID)
         {
             SpawnMinion();
         }
         else if ((Object)SandboxToolParameterMenu.instance.settings.Entity.GetComponent <Building>() != (Object)null)
         {
             BuildingDef def = SandboxToolParameterMenu.instance.settings.Entity.GetComponent <Building>().Def;
             def.Build(cell, Orientation.Neutral, null, def.DefaultElements(), 298.15f, true, -1f);
         }
         else
         {
             GameObject gameObject = GameUtil.KInstantiate(Assets.GetPrefab(SandboxToolParameterMenu.instance.settings.Entity.PrefabTag), Grid.CellToPosCBC(currentCell, Grid.SceneLayer.Creatures), Grid.SceneLayer.Creatures, null, 0);
             gameObject.SetActive(true);
         }
         UISounds.PlaySound(UISounds.Sound.ClickObject);
     }
 }
Ejemplo n.º 6
0
    public static GameObject PlaceBuilding(int root_cell, int x, int y, string prefab_id, SimHashes element = SimHashes.Cuprite)
    {
        int         cell        = Grid.OffsetCell(root_cell, x, y);
        BuildingDef buildingDef = Assets.GetBuildingDef(prefab_id);

        if ((UnityEngine.Object)buildingDef == (UnityEngine.Object)null || buildingDef.PlacementOffsets == null)
        {
            DebugUtil.LogErrorArgs("Missing def for", prefab_id);
        }
        Element element2 = ElementLoader.FindElementByHash(element);

        Debug.Assert(element2 != null, "Missing primary element.");
        GameObject gameObject = buildingDef.Build(buildingDef.GetBuildingCell(cell), Orientation.Neutral, null, new Tag[2]
        {
            element2.tag,
            ElementLoader.FindElementByHash(SimHashes.SedimentaryRock).tag
        }, 293.15f, false, -1f);
        PrimaryElement component = gameObject.GetComponent <PrimaryElement>();

        component.InternalTemperature = 300f;
        component.Temperature         = 300f;
        return(gameObject);
    }
 private void TryBuild(int cell)
 {
     if (!((Object)visualizer == (Object)null) && (cell != lastDragCell || buildingOrientation != lastDragOrientation))
     {
         int num = Grid.PosToCell(visualizer);
         if (num == cell || (!(bool)def.BuildingComplete.GetComponent <LogicPorts>() && !(bool)def.BuildingComplete.GetComponent <LogicGateBase>()))
         {
             lastDragCell        = cell;
             lastDragOrientation = buildingOrientation;
             ClearTilePreview();
             Vector3    vector     = Grid.CellToPosCBC(cell, Grid.SceneLayer.Building);
             GameObject gameObject = null;
             if (DebugHandler.InstantBuildMode || (Game.Instance.SandboxModeActive && SandboxToolParameterMenu.instance.settings.InstantBuild))
             {
                 if (def.IsValidBuildLocation(visualizer, vector, buildingOrientation) && def.IsValidPlaceLocation(visualizer, vector, buildingOrientation, out string _))
                 {
                     gameObject = def.Build(cell, buildingOrientation, null, selectedElements, 293.15f, false, GameClock.Instance.GetTime());
                     if ((Object)source != (Object)null)
                     {
                         source.DeleteObject();
                     }
                 }
             }
             else
             {
                 gameObject = def.TryPlace(visualizer, vector, buildingOrientation, selectedElements, 0);
                 if ((Object)gameObject == (Object)null && def.ReplacementLayer != ObjectLayer.NumLayers)
                 {
                     GameObject replacementCandidate = def.GetReplacementCandidate(cell);
                     if ((Object)replacementCandidate != (Object)null && !def.IsReplacementLayerOccupied(cell))
                     {
                         BuildingComplete component = replacementCandidate.GetComponent <BuildingComplete>();
                         if ((Object)component != (Object)null && component.Def.Replaceable && def.CanReplace(replacementCandidate) && ((Object)component.Def != (Object)def || selectedElements[0] != replacementCandidate.GetComponent <PrimaryElement>().Element.tag))
                         {
                             gameObject = def.TryReplaceTile(visualizer, vector, buildingOrientation, selectedElements, 0);
                             Grid.Objects[cell, (int)def.ReplacementLayer] = gameObject;
                         }
                     }
                 }
                 if ((Object)gameObject != (Object)null)
                 {
                     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());
                         }
                     }
                     if ((Object)source != (Object)null)
                     {
                         source.Trigger(2121280625, gameObject);
                     }
                 }
             }
             if ((Object)gameObject != (Object)null)
             {
                 if (def.MaterialsAvailable(selectedElements) || DebugHandler.InstantBuildMode)
                 {
                     placeSound = GlobalAssets.GetSound("Place_Building_" + def.AudioSize, false);
                     if (placeSound != null)
                     {
                         buildingCount = buildingCount % 14 + 1;
                         EventInstance instance = SoundEvent.BeginOneShot(placeSound, vector);
                         if (def.AudioSize == "small")
                         {
                             instance.setParameterValue("tileCount", (float)buildingCount);
                         }
                         SoundEvent.EndOneShot(instance);
                     }
                 }
                 else
                 {
                     PopFXManager.Instance.SpawnFX(PopFXManager.Instance.sprite_Resource, UI.TOOLTIPS.NOMATERIAL, null, vector, 1.5f, false, false);
                 }
                 Rotatable component3 = gameObject.GetComponent <Rotatable>();
                 if ((Object)component3 != (Object)null)
                 {
                     component3.SetOrientation(buildingOrientation);
                 }
             }
         }
     }
 }
    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);
    }