Esempio n. 1
0
    public static void SetUpFarmPlotTags(GameObject go)
    {
        KPrefabID component = go.GetComponent <KPrefabID>();

        component.prefabSpawnFn += delegate(GameObject inst)
        {
            Rotatable     component2 = inst.GetComponent <Rotatable>();
            PlantablePlot component3 = inst.GetComponent <PlantablePlot>();
            switch (component2.GetOrientation())
            {
            case Orientation.NumRotations:
                break;

            case Orientation.Neutral:
            case Orientation.FlipH:
                component3.SetReceptacleDirection(SingleEntityReceptacle.ReceptacleDirection.Top);
                break;

            case Orientation.R180:
            case Orientation.FlipV:
                component3.SetReceptacleDirection(SingleEntityReceptacle.ReceptacleDirection.Bottom);
                break;

            case Orientation.R90:
            case Orientation.R270:
                component3.SetReceptacleDirection(SingleEntityReceptacle.ReceptacleDirection.Side);
                break;
            }
        };
    }
        private void OnRotateClicked()
        {
            Rotatable rotatable = this.gameObject.GetComponent <Rotatable>();

            if (rotatable != null)
            {
                rotatable.Rotate();

                // Buildings with even width values jump one tile when rotating and must be moved back
                Building building = this.gameObject.GetComponent <Building>();
                if (building != null && building.Def != null && building.Def.WidthInCells % 2 == 0)
                {
                    this.transform.position += rotatable.GetOrientation() != Orientation.Neutral ? new UnityEngine.Vector3(1, 0, 0)
                                                                                                : new UnityEngine.Vector3(-1, 0, 0);
                }
            }
        }
Esempio n. 3
0
        private void OnRotateClicked()
        {
            Rotatable rotatable = this.gameObject.GetComponent <Rotatable>();

            if (rotatable != null)
            {
                rotatable.Rotate();
            }

            BuildingDef def = this.gameObject.GetComponent <Building>()?.Def;

            if (def != null && def.WidthInCells % 2 == 0)
            {
                this.transform.position += rotatable.GetOrientation() != Orientation.Neutral ? new UnityEngine.Vector3(1, 0, 0) : new UnityEngine.Vector3(-1, 0, 0);
            }

            artable.SetStage(artable.CurrentStage, false);
        }
Esempio n. 4
0
    private void CreateVisualizers()
    {
        int  num  = Grid.PosToCell(base.transform.GetPosition());
        bool flag = num != cell;

        cell = num;
        if (!flag)
        {
            Rotatable component = GetComponent <Rotatable>();
            if ((UnityEngine.Object)component != (UnityEngine.Object)null)
            {
                Orientation orientation = component.GetOrientation();
                flag             = (orientation != this.orientation);
                this.orientation = orientation;
            }
        }
        if (flag)
        {
            DestroyVisualizers();
            if (outputPortInfo != null)
            {
                outputPorts = new List <ILogicUIElement>();
                for (int i = 0; i < outputPortInfo.Length; i++)
                {
                    Port port = outputPortInfo[i];
                    LogicPortVisualizer logicPortVisualizer = new LogicPortVisualizer(GetActualCell(port.cellOffset), port.spriteType);
                    outputPorts.Add(logicPortVisualizer);
                    Game.Instance.logicCircuitManager.AddVisElem(logicPortVisualizer);
                }
            }
            if (inputPortInfo != null)
            {
                inputPorts = new List <ILogicUIElement>();
                for (int j = 0; j < inputPortInfo.Length; j++)
                {
                    Port port2 = inputPortInfo[j];
                    LogicPortVisualizer logicPortVisualizer2 = new LogicPortVisualizer(GetActualCell(port2.cellOffset), port2.spriteType);
                    inputPorts.Add(logicPortVisualizer2);
                    Game.Instance.logicCircuitManager.AddVisElem(logicPortVisualizer2);
                }
            }
        }
    }
Esempio n. 5
0
        protected override void OnSpawn()
        {
            base.OnSpawn();
            base.GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, Db.Get().BuildingStatusItems.Normal, null);
            base.Subscribe <Stair>(493375141, Stair.OnRefreshUserMenuDelegate);
            base.Subscribe <Stair>(-111137758, Stair.OnRefreshUserMenuDelegate);
            Rotatable rotatable = this.GetComponent <Rotatable>();
            int       cell      = Grid.PosToCell(this);

            MyGrid.Masks[cell] |= MyGrid.Flags.HasStair;
            MyGrid.Masks[cell] |= MyGrid.Flags.Walkable;
            if (rotatable.GetOrientation() == Orientation.FlipH)
            {
                MyGrid.Masks[cell] |= MyGrid.Flags.RightSet;
            }
            Pathfinding.Instance.AddDirtyNavGridCell(cell);
            if (this.blocked)
            {
                OnBlock();
            }
        }
Esempio n. 6
0
 [HarmonyPriority(-10000)] // Extremely low priority. We want this to happen last, since this will only overwrite RotatableElementConsumer variable
 public static void Prefix(ElementConsumer __instance)
 {
     if (__instance is RotatableElementConsumer)
     {
         Vector3   rotatableCellOffset = ((RotatableElementConsumer)__instance).rotatableCellOffset;
         Rotatable rotatable           = __instance.GetComponent <Rotatable>();
         if (rotatable != null)
         {
             __instance.sampleCellOffset = Rotatable.GetRotatedOffset(rotatableCellOffset, rotatable.GetOrientation());
         }
         //Debug.Log("GetSampleCell call " + rotatableCellOffset + ", " + __instance.sampleCellOffset);
     }
 }
Esempio n. 7
0
        private static void AddVisualizer(GameObject go, bool movable)
        {
            StationaryChoreRangeVisualizer stationaryChoreRangeVisualizer = go.AddOrGet <StationaryChoreRangeVisualizer>();
            Rotatable  rotatable = go.AddOrGet <Rotatable>();
            CellOffset offset    = Rotatable.GetRotatedCellOffset(new CellOffset(0, 1), rotatable.GetOrientation());

            stationaryChoreRangeVisualizer.x       = offset.x;
            stationaryChoreRangeVisualizer.y       = offset.y;
            stationaryChoreRangeVisualizer.width   = 1;
            stationaryChoreRangeVisualizer.height  = 1;
            stationaryChoreRangeVisualizer.movable = movable;
        }
    private TemplateContainer GetSelectionAsAsset()
    {
        List <Cell>          list  = new List <Cell>();
        List <Prefab>        list2 = new List <Prefab>();
        List <Prefab>        list3 = new List <Prefab>();
        List <Prefab>        _primaryElementOres = new List <Prefab>();
        List <Prefab>        _otherEntities      = new List <Prefab>();
        HashSet <GameObject> _excludeEntities    = new HashSet <GameObject>();
        float num  = 0f;
        float num2 = 0f;

        foreach (int selectedCell in SelectedCells)
        {
            float    num3     = num;
            Vector2I vector2I = Grid.CellToXY(selectedCell);
            num = num3 + (float)vector2I.x;
            float    num4      = num2;
            Vector2I vector2I2 = Grid.CellToXY(selectedCell);
            num2 = num4 + (float)vector2I2.y;
        }
        float x    = num / (float)SelectedCells.Count;
        float y    = num2 /= (float)SelectedCells.Count;
        int   cell = Grid.PosToCell(new Vector3(x, y, 0f));

        Grid.CellToXY(cell, out int x2, out int y2);
        for (int i = 0; i < SelectedCells.Count; i++)
        {
            int i2 = SelectedCells[i];
            Grid.CellToXY(SelectedCells[i], out int x3, out int y3);
            Element element     = ElementLoader.elements[Grid.ElementIdx[i2]];
            string  diseaseName = (Grid.DiseaseIdx[i2] == 255) ? null : Db.Get().Diseases[Grid.DiseaseIdx[i2]].Id;
            list.Add(new Cell(x3 - x2, y3 - y2, element.id, Grid.Temperature[i2], Grid.Mass[i2], diseaseName, Grid.DiseaseCount[i2], Grid.PreventFogOfWarReveal[SelectedCells[i]]));
        }
        for (int j = 0; j < Components.BuildingCompletes.Count; j++)
        {
            BuildingComplete buildingComplete = Components.BuildingCompletes[j];
            if (!_excludeEntities.Contains(buildingComplete.gameObject))
            {
                Grid.CellToXY(Grid.PosToCell(buildingComplete), out int x4, out int y4);
                if (SaveAllBuildings || SelectedCells.Contains(Grid.PosToCell(buildingComplete)))
                {
                    int[]  placementCells = buildingComplete.PlacementCells;
                    string diseaseName2;
                    foreach (int num5 in placementCells)
                    {
                        Grid.CellToXY(num5, out int x5, out int y5);
                        diseaseName2 = ((Grid.DiseaseIdx[num5] == 255) ? null : Db.Get().Diseases[Grid.DiseaseIdx[num5]].Id);
                        list.Add(new Cell(x5 - x2, y5 - y2, Grid.Element[num5].id, Grid.Temperature[num5], Grid.Mass[num5], diseaseName2, Grid.DiseaseCount[num5], false));
                    }
                    Orientation rotation  = Orientation.Neutral;
                    Rotatable   component = buildingComplete.gameObject.GetComponent <Rotatable>();
                    if ((UnityEngine.Object)component != (UnityEngine.Object)null)
                    {
                        rotation = component.GetOrientation();
                    }
                    SimHashes element2 = SimHashes.Void;
                    float     value    = 280f;
                    diseaseName2 = null;
                    int            disease_count = 0;
                    PrimaryElement component2    = buildingComplete.GetComponent <PrimaryElement>();
                    if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
                    {
                        element2      = component2.ElementID;
                        value         = component2.Temperature;
                        diseaseName2  = ((component2.DiseaseIdx == 255) ? null : Db.Get().Diseases[component2.DiseaseIdx].Id);
                        disease_count = component2.DiseaseCount;
                    }
                    List <Prefab.template_amount_value> list4 = new List <Prefab.template_amount_value>();
                    List <Prefab.template_amount_value> list5 = new List <Prefab.template_amount_value>();
                    foreach (AmountInstance amount in buildingComplete.gameObject.GetAmounts())
                    {
                        list4.Add(new Prefab.template_amount_value(amount.amount.Id, amount.value));
                    }
                    float   num6       = 0f;
                    Battery component3 = buildingComplete.GetComponent <Battery>();
                    if ((UnityEngine.Object)component3 != (UnityEngine.Object)null)
                    {
                        num6 = component3.JoulesAvailable;
                        list5.Add(new Prefab.template_amount_value("joulesAvailable", num6));
                    }
                    float      num7       = 0f;
                    Unsealable component4 = buildingComplete.GetComponent <Unsealable>();
                    if ((UnityEngine.Object)component4 != (UnityEngine.Object)null)
                    {
                        num7 = (float)(component4.facingRight ? 1 : 0);
                        list5.Add(new Prefab.template_amount_value("sealedDoorDirection", num7));
                    }
                    float       num8       = 0f;
                    LogicSwitch component5 = buildingComplete.GetComponent <LogicSwitch>();
                    if ((UnityEngine.Object)component5 != (UnityEngine.Object)null)
                    {
                        num8 = (float)(component5.IsSwitchedOn ? 1 : 0);
                        list5.Add(new Prefab.template_amount_value("switchSetting", num8));
                    }
                    x4   -= x2;
                    y4   -= y2;
                    value = Mathf.Clamp(value, 1f, 99999f);
                    Prefab  prefab     = new Prefab(buildingComplete.PrefabID().Name, Prefab.Type.Building, x4, y4, element2, value, 0f, diseaseName2, disease_count, rotation, list4.ToArray(), list5.ToArray(), 0);
                    Storage component6 = buildingComplete.gameObject.GetComponent <Storage>();
                    if ((UnityEngine.Object)component6 != (UnityEngine.Object)null)
                    {
                        foreach (GameObject item2 in component6.items)
                        {
                            float          units          = 0f;
                            SimHashes      element3       = SimHashes.Vacuum;
                            float          temp           = 280f;
                            string         disease        = null;
                            int            disease_count2 = 0;
                            bool           isOre          = false;
                            PrimaryElement component7     = item2.GetComponent <PrimaryElement>();
                            if ((UnityEngine.Object)component7 != (UnityEngine.Object)null)
                            {
                                units          = component7.Units;
                                element3       = component7.ElementID;
                                temp           = component7.Temperature;
                                disease        = ((component7.DiseaseIdx == 255) ? null : Db.Get().Diseases[component7.DiseaseIdx].Id);
                                disease_count2 = component7.DiseaseCount;
                            }
                            float             rotAmount = 0f;
                            Rottable.Instance sMI       = item2.gameObject.GetSMI <Rottable.Instance>();
                            if (sMI != null)
                            {
                                rotAmount = sMI.RotValue;
                            }
                            ElementChunk component8 = item2.GetComponent <ElementChunk>();
                            if ((UnityEngine.Object)component8 != (UnityEngine.Object)null)
                            {
                                isOre = true;
                            }
                            StorageItem storageItem = new StorageItem(item2.PrefabID().Name, units, temp, element3, disease, disease_count2, isOre);
                            if (sMI != null)
                            {
                                storageItem.rottable.rotAmount = rotAmount;
                            }
                            prefab.AssignStorage(storageItem);
                            _excludeEntities.Add(item2);
                        }
                    }
                    list2.Add(prefab);
                    _excludeEntities.Add(buildingComplete.gameObject);
                }
            }
        }
        for (int l = 0; l < list2.Count; l++)
        {
            Prefab prefab2 = list2[l];
            int    x6      = prefab2.location_x + x2;
            int    y6      = prefab2.location_y + y2;
            int    cell2   = Grid.XYToCell(x6, y6);
            switch (prefab2.id)
            {
            default:
                prefab2.connections = 0;
                break;

            case "Wire":
            case "InsulatedWire":
            case "HighWattageWire":
                prefab2.connections = (int)Game.Instance.electricalConduitSystem.GetConnections(cell2, true);
                break;

            case "GasConduit":
            case "InsulatedGasConduit":
                prefab2.connections = (int)Game.Instance.gasConduitSystem.GetConnections(cell2, true);
                break;

            case "LiquidConduit":
            case "InsulatedLiquidConduit":
                prefab2.connections = (int)Game.Instance.liquidConduitSystem.GetConnections(cell2, true);
                break;

            case "LogicWire":
                prefab2.connections = (int)Game.Instance.logicCircuitSystem.GetConnections(cell2, true);
                break;
            }
        }
        for (int m = 0; m < Components.Pickupables.Count; m++)
        {
            if (Components.Pickupables[m].gameObject.activeSelf)
            {
                Pickupable pickupable = Components.Pickupables[m];
                if (!_excludeEntities.Contains(pickupable.gameObject))
                {
                    int num9 = Grid.PosToCell(pickupable);
                    if ((SaveAllPickups || SelectedCells.Contains(num9)) && !(bool)Components.Pickupables[m].gameObject.GetComponent <MinionBrain>())
                    {
                        Grid.CellToXY(num9, out int x7, out int y7);
                        x7 -= x2;
                        y7 -= y2;
                        SimHashes         element4       = SimHashes.Void;
                        float             temperature    = 280f;
                        float             units2         = 1f;
                        string            disease2       = null;
                        int               disease_count3 = 0;
                        float             rotAmount2     = 0f;
                        Rottable.Instance sMI2           = pickupable.gameObject.GetSMI <Rottable.Instance>();
                        if (sMI2 != null)
                        {
                            rotAmount2 = sMI2.RotValue;
                        }
                        PrimaryElement component9 = pickupable.gameObject.GetComponent <PrimaryElement>();
                        if ((UnityEngine.Object)component9 != (UnityEngine.Object)null)
                        {
                            element4       = component9.ElementID;
                            units2         = component9.Units;
                            temperature    = component9.Temperature;
                            disease2       = ((component9.DiseaseIdx == 255) ? null : Db.Get().Diseases[component9.DiseaseIdx].Id);
                            disease_count3 = component9.DiseaseCount;
                        }
                        ElementChunk component10 = pickupable.gameObject.GetComponent <ElementChunk>();
                        if ((UnityEngine.Object)component10 != (UnityEngine.Object)null)
                        {
                            Prefab item = new Prefab(pickupable.PrefabID().Name, Prefab.Type.Ore, x7, y7, element4, temperature, units2, disease2, disease_count3, Orientation.Neutral, null, null, 0);
                            _primaryElementOres.Add(item);
                        }
                        else
                        {
                            Prefab item = new Prefab(pickupable.PrefabID().Name, Prefab.Type.Pickupable, x7, y7, element4, temperature, units2, disease2, disease_count3, Orientation.Neutral, null, null, 0);
                            item.rottable           = new TemplateClasses.Rottable();
                            item.rottable.rotAmount = rotAmount2;
                            list3.Add(item);
                        }
                        _excludeEntities.Add(pickupable.gameObject);
                    }
                }
            }
        }
        GetEntities(Components.Crops.Items, x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        GetEntities(Components.Health.Items, x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        GetEntities(Components.Harvestables.Items, x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        GetEntities(Components.Edibles.Items, x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        GetEntities <Geyser>(x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        GetEntities <OccupyArea>(x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        GetEntities <FogOfWarMask>(x2, y2, ref _primaryElementOres, ref _otherEntities, ref _excludeEntities);
        TemplateContainer templateContainer = new TemplateContainer();

        templateContainer.Init(list, list2, list3, _primaryElementOres, _otherEntities);
        return(templateContainer);
    }
Esempio n. 9
0
    private void RegisterInGrid(bool register)
    {
        Building component = GetComponent <Building>();

        if (!((Object)component == (Object)null))
        {
            if (register)
            {
                Rotatable component2 = GetComponent <Rotatable>();
                Grid.Restriction.Orientation orientation = (!((Object)component2 == (Object)null) && component2.GetOrientation() != 0) ? Grid.Restriction.Orientation.Horizontal : Grid.Restriction.Orientation.Vertical;
                int[] placementCells = component.PlacementCells;
                foreach (int cell in placementCells)
                {
                    Grid.RegisterRestriction(cell, orientation);
                }
            }
            else
            {
                int[] placementCells2 = component.PlacementCells;
                foreach (int cell2 in placementCells2)
                {
                    Grid.UnregisterRestriction(cell2);
                }
            }
        }
    }
    protected override void OnSpawn()
    {
        base.OnSpawn();
        KPrefabID component = GetComponent <KPrefabID>();

        if ((Object)component != (Object)null)
        {
            log = new LoggerFSS("Door", 35);
        }
        if (!allowAutoControl && controlState == ControlState.Auto)
        {
            controlState = ControlState.Locked;
        }
        StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures;

        HandleVector <int> .Handle handle = structureTemperatures.GetHandle(base.gameObject);
        if (DisplacesGas(doorType))
        {
            structureTemperatures.Bypass(handle);
        }
        controller = new Controller.Instance(this);
        controller.StartSM();
        if (doorType == DoorType.Sealed && !hasBeenUnsealed)
        {
            Seal();
        }
        UpdateDoorSpeed(operational.IsOperational);
        Subscribe(-592767678, OnOperationalChangedDelegate);
        Subscribe(824508782, OnOperationalChangedDelegate);
        Subscribe(-801688580, OnLogicValueChangedDelegate);
        requestedState = CurrentState;
        ApplyRequestedControlState(true);
        int num  = (rotatable.GetOrientation() == Orientation.Neutral) ? (building.Def.WidthInCells * (building.Def.HeightInCells - 1)) : 0;
        int num2 = (rotatable.GetOrientation() != 0) ? building.Def.HeightInCells : building.Def.WidthInCells;

        for (int i = 0; i != num2; i++)
        {
            int num3 = building.PlacementCells[num + i];
            Grid.FakeFloor[num3] = true;
            Pathfinding.Instance.AddDirtyNavGridCell(num3);
        }
        List <int> list = new List <int>();

        int[] placementCells = building.PlacementCells;
        foreach (int num4 in placementCells)
        {
            Grid.HasDoor[num4]       = true;
            Grid.HasAccessDoor[num4] = ((Object)GetComponent <AccessControl>() != (Object)null);
            if (rotatable.IsRotated)
            {
                list.Add(Grid.CellAbove(num4));
                list.Add(Grid.CellBelow(num4));
            }
            else
            {
                list.Add(Grid.CellLeft(num4));
                list.Add(Grid.CellRight(num4));
            }
            SimMessages.SetCellProperties(num4, 8);
            if (DisplacesGas(doorType))
            {
                Grid.RenderedByWorld[num4] = false;
            }
        }
    }
Esempio n. 11
0
        protected override void OnSpawn()
        {
            base.OnSpawn();

            Vector3   position            = transform.GetPosition();
            Rotatable rotatable           = GetComponent <Rotatable>();
            Vector3   rotatedInputOffset  = Rotatable.GetRotatedOffset(new Vector3(0, -1), rotatable.GetOrientation());
            Vector3   rotatedOutputOffset = Rotatable.GetRotatedOffset(new Vector3(0, 1), rotatable.GetOrientation());

            inputCell  = Grid.PosToCell(position + rotatedInputOffset);
            outputCell = Grid.PosToCell(position + rotatedOutputOffset);

            elapsedTime = 0.0f;
            pumpable    = UpdatePumpOperational();
            ventable    = UpdateVentOperational();
        }
Esempio n. 12
0
 [HarmonyPriority(-10000)] // Extremely low priority. We want this to happen last, since this will only overwrite RotatablePump results
 public static void Postfix(Pump __instance, ref bool __result, Element.State expected_state)
 {
     if (__instance is RotatablePump)
     {
         Rotatable rotatable = __instance.GetComponent <Rotatable>();
         RotatableElementConsumer consumer = __instance.GetComponent <RotatableElementConsumer>();
         //Debug.Log("IsPumpable call " + consumer.rotatableCellOffset + ", " + consumer.sampleCellOffset);
         // Basically a copy of vanilla Pump IsPumpable, but with different initial
         int num = Grid.PosToCell(__instance.transform.GetPosition() + Rotatable.GetRotatedOffset(consumer.rotatableCellOffset, rotatable.GetOrientation()));
         for (int i = 0; i < consumer.consumptionRadius; i++)
         {
             for (int j = 0; j < consumer.consumptionRadius; j++)
             {
                 int  num2 = num + j + Grid.WidthInCells * i;
                 bool flag = Grid.Element[num2].IsState(expected_state);
                 if (flag)
                 {
                     __result = true;
                     return;
                 }
             }
         }
         __result = false;
         return;
     }
 }
 private void CreateProgressBar()
 {
     if (!((UnityEngine.Object)progressBar != (UnityEngine.Object)null))
     {
         progressBar = Util.KInstantiateUI <ProgressBar>(ProgressBarsConfig.Instance.progressBarPrefab, null, false);
         progressBar.transform.SetParent(GameScreenManager.Instance.worldSpaceCanvas.transform);
         progressBar.name = base.smi.master.name + "." + base.smi.master.GetType().Name + " ProgressBar";
         progressBar.transform.Find("Bar").GetComponent <Image>().color = ProgressBarsConfig.Instance.GetBarColor("ProgressBar");
         progressBar.SetUpdateFunc(HealthPercent);
         progressBar.barColor = ProgressBarsConfig.Instance.GetBarColor("HealthBar");
         CanvasGroup component = progressBar.GetComponent <CanvasGroup>();
         component.interactable   = false;
         component.blocksRaycasts = false;
         progressBar.Update();
         float   d      = 0.15f;
         Vector3 vector = base.gameObject.transform.GetPosition() + Vector3.down * d;
         vector.z += 0.05f;
         Rotatable component2 = GetComponent <Rotatable>();
         vector = ((!((UnityEngine.Object)component2 == (UnityEngine.Object)null) && component2.GetOrientation() != 0 && base.smi.master.building.Def.WidthInCells >= 2 && base.smi.master.building.Def.HeightInCells >= 2) ? (vector + Vector3.left * (1f + 0.5f * (float)(base.smi.master.building.Def.WidthInCells % 2))) : (vector - Vector3.right * 0.5f * (float)(base.smi.master.building.Def.WidthInCells % 2)));
         progressBar.transform.SetPosition(vector);
         progressBar.gameObject.SetActive(true);
     }
 }
Esempio n. 14
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();
    }
Esempio n. 15
0
    private void OnSolidChanged(HandleVector <int> .Handle h)
    {
        Data            data      = GetData(h);
        SimCellOccupier component = data.go.GetComponent <SimCellOccupier>();

        if ((UnityEngine.Object)component == (UnityEngine.Object)null || component.IsReady())
        {
            Rotatable   component2  = data.go.GetComponent <Rotatable>();
            Orientation orientation = ((UnityEngine.Object)component2 != (UnityEngine.Object)null) ? component2.GetOrientation() : Orientation.Neutral;
            bool        is_solid    = BuildingDef.CheckFoundation(data.cell, orientation, data.buildRule, data.width, data.height);
            UpdateSolidState(is_solid, ref data);
            SetData(h, data);
        }
    }
Esempio n. 16
0
    public HandleVector <int> .Handle Add(GameObject go)
    {
        BuildingDef def  = go.GetComponent <Building>().Def;
        int         cell = Grid.PosToCell(go.transform.GetPosition());
        Data        data = default(Data);

        data.cell      = cell;
        data.width     = def.WidthInCells;
        data.height    = def.HeightInCells;
        data.buildRule = def.BuildLocationRule;
        data.solid     = true;
        data.go        = go;
        Data data2 = data;

        HandleVector <int> .Handle h = Add(go, data2);
        if (def.ContinuouslyCheckFoundation)
        {
            Action <object> event_callback = delegate
            {
                OnSolidChanged(h);
            };
            Rotatable   component   = data2.go.GetComponent <Rotatable>();
            Orientation orientation = ((UnityEngine.Object)component != (UnityEngine.Object)null) ? component.GetOrientation() : Orientation.Neutral;
            int         num         = -(def.WidthInCells - 1) / 2;
            int         num2        = def.WidthInCells / 2;
            List <int>  list        = new List <int>();
            for (int i = num; i <= num2; i++)
            {
                CellOffset offset = new CellOffset(i, -1);
                if (def.BuildLocationRule == BuildLocationRule.OnWall)
                {
                    offset = new CellOffset(i - 1, 0);
                }
                else if (def.BuildLocationRule == BuildLocationRule.OnCeiling || def.BuildLocationRule == BuildLocationRule.InCorner)
                {
                    offset = new CellOffset(i, def.HeightInCells);
                }
                CellOffset rotatedCellOffset = Rotatable.GetRotatedCellOffset(offset, orientation);
                int        item = Grid.OffsetCell(cell, rotatedCellOffset);
                list.Add(item);
            }
            Vector2I vector2I  = Grid.CellToXY(list[0]);
            Vector2I vector2I2 = Grid.CellToXY(list[list.Count - 1]);
            float    xmin      = (float)((vector2I.x <= vector2I2.x) ? vector2I.x : vector2I2.x);
            float    xmax      = (float)((vector2I.x >= vector2I2.x) ? vector2I.x : vector2I2.x);
            float    ymin      = (float)((vector2I.y <= vector2I2.y) ? vector2I.y : vector2I2.y);
            float    ymax      = (float)((vector2I.y >= vector2I2.y) ? vector2I.y : vector2I2.y);
            Rect     rect      = Rect.MinMaxRect(xmin, ymin, xmax, ymax);
            data2.solidPartitionerEntry    = GameScenePartitioner.Instance.Add("RequiresFoundation.Add", go, (int)rect.x, (int)rect.y, (int)rect.width + 1, (int)rect.height + 1, GameScenePartitioner.Instance.solidChangedLayer, event_callback);
            data2.buildingPartitionerEntry = GameScenePartitioner.Instance.Add("RequiresFoundation.Add", go, (int)rect.x, (int)rect.y, (int)rect.width + 1, (int)rect.height + 1, GameScenePartitioner.Instance.objectLayers[1], event_callback);
            SetData(h, data2);
            OnSolidChanged(h);
        }
        return(h);
    }
Esempio n. 17
0
 [HarmonyPriority(-10000)] // Extremely low priority. We want this to happen last, since this will only overwrite FanRotatablePassiveElementConsumer variable
 public static void Prefix(ElementConsumer __instance)
 {
     if (__instance is FanRotatablePassiveElementConsumer)
     {
         Vector3   rotatableCellOffset = ((FanRotatablePassiveElementConsumer)__instance).rotatableCellOffset;
         Rotatable rotatable           = __instance.GetComponent <Rotatable>();
         if (rotatable != null)
         {
             __instance.sampleCellOffset = Rotatable.GetRotatedOffset(rotatableCellOffset, rotatable.GetOrientation());
         }
     }
 }