示例#1
0
 private static void Postfix(Door __instance)
 {
     foreach (int cell in __instance.building.PlacementCells)
     {
         SimMessages.ClearCellProperties(cell, 3);
     }
 }
示例#2
0
        private void Dig(int cell)
        {
            var flags = Sim.Cell.Properties.GasImpermeable;

            if (!AllowLiquidThrough)
            {
                flags |= Sim.Cell.Properties.LiquidImpermeable;
            }
            SimMessages.ClearCellProperties(cell, (byte)flags);
            //SimMessages.Dig(cell, cb.index, true);
        }
示例#3
0
            private static bool Prefix(Door __instance, bool is_door_open, IList <int> cells)
            {
                PrimaryElement component = __instance.GetComponent <PrimaryElement>();
                float          mass      = component.Mass / (float)cells.Count;

                for (int i = 0; i < cells.Count; i++)
                {
                    int           offsetCell = cells[i];
                    Door.DoorType doorType   = __instance.doorType;
                    if (doorType <= Door.DoorType.ManualPressure || doorType == Door.DoorType.Sealed)
                    {
                        World.Instance.groundRenderer.MarkDirty(offsetCell);
                        if (is_door_open)
                        {
                            MethodInfo    method_opened = AccessTools.Method(typeof(Door), "OnSimDoorOpened");
                            System.Action cb_opened     = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_opened);
                            HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_opened));

                            SimMessages.Dig(offsetCell, handle.index, true);

                            SimMessages.ClearCellProperties(offsetCell, 1);
                            SimMessages.ClearCellProperties(offsetCell, 2);
                            SimMessages.ClearCellProperties(offsetCell, 4);

                            SimMessages.SetCellProperties(offsetCell, (byte)(__instance.CurrentState == Door.ControlState.Auto ? 7 : 4));

                            if (__instance.ShouldBlockFallingSand)
                            {
                                SimMessages.ClearCellProperties(offsetCell, 4);
                            }
                        }
                        else
                        {
                            MethodInfo    method_closed = AccessTools.Method(typeof(Door), "OnSimDoorClosed");
                            System.Action cb_closed     = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_closed);
                            HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_closed));

                            float temperature = component.Temperature;
                            if (temperature <= 0f)
                            {
                                temperature = component.Temperature;
                            }

                            SimMessages.ReplaceAndDisplaceElement(offsetCell, component.ElementID, CellEventLogger.Instance.DoorClose, mass, temperature, byte.MaxValue, 0, handle.index);

                            SimMessages.ClearCellProperties(offsetCell, 1);
                            SimMessages.ClearCellProperties(offsetCell, 2);
                            SimMessages.SetCellProperties(offsetCell, 4);
                        }
                    }
                }

                return(false);
            }
示例#4
0
        protected override void OnSpawn()
        {
            var building = GetComponent <Building>();

            if (building != null)
            {
                foreach (var cell in building.PlacementCells)
                {
                    SimMessages.ClearCellProperties(cell, (int)Sim.Cell.Properties.SolidImpermeable);
                }
            }
        }
示例#5
0
 public void DestroySelf(System.Action onComplete)
 {
     callDestroy = false;
     for (int i = 0; i < building.PlacementCells.Length; i++)
     {
         int num = building.PlacementCells[i];
         Game.Instance.RemoveSolidChangedFilter(num);
         Sim.Cell.Properties simCellProperties = GetSimCellProperties();
         SimMessages.ClearCellProperties(num, (byte)simCellProperties);
         if (doReplaceElement && Grid.Element[num].id == primaryElement.ElementID)
         {
             HandleVector <int> .Handle handle = GameComps.DiseaseContainers.GetHandle(base.gameObject);
             if (handle.IsValid())
             {
                 DiseaseHeader header = GameComps.DiseaseContainers.GetHeader(handle);
                 header.diseaseIdx   = Grid.DiseaseIdx[num];
                 header.diseaseCount = Grid.DiseaseCount[num];
                 GameComps.DiseaseContainers.SetHeader(handle, header);
             }
             if (onComplete != null)
             {
                 HandleVector <Game.CallbackInfo> .Handle handle2 = Game.Instance.callbackManager.Add(new Game.CallbackInfo(onComplete, false));
                 int              gameCell    = num;
                 SimHashes        new_element = SimHashes.Vacuum;
                 CellElementEvent simCellOccupierDestroySelf = CellEventLogger.Instance.SimCellOccupierDestroySelf;
                 float            mass        = 0f;
                 float            temperature = -1f;
                 int              index       = handle2.index;
                 SimMessages.ReplaceElement(gameCell, new_element, simCellOccupierDestroySelf, mass, temperature, byte.MaxValue, 0, index);
             }
             else
             {
                 SimMessages.ReplaceElement(num, SimHashes.Vacuum, CellEventLogger.Instance.SimCellOccupierDestroySelf, 0f, -1f, byte.MaxValue, 0, -1);
             }
             SimMessages.SetStrength(num, 1, 1f);
         }
         else
         {
             Grid.SetSolid(num, false, CellEventLogger.Instance.SimCellOccupierDestroy);
             onComplete.Signal();
             World.Instance.OnSolidChanged(num);
             GameScenePartitioner.Instance.TriggerEvent(num, GameScenePartitioner.Instance.solidChangedLayer, null);
         }
     }
 }
示例#6
0
            internal static void Postfix(SolarPanel __instance)
            {
                var def = __instance.GetComponent <BuildingComplete>().Def;
                int baseCell = Grid.PosToCell(__instance), n = def.WidthInCells;
                var solidChanged = GameScenePartitioner.Instance.solidChangedLayer;

                for (int i = 0; i < n; i++)
                {
                    int cell = Grid.OffsetCell(baseCell, new CellOffset(i - (n - 1) / 2, 0));
                    SimMessages.ClearCellProperties(cell, LI_GI);
                    Grid.Foundation[cell] = false;
                    Grid.SetSolid(cell, false, CellEventLogger.Instance.
                                  SimCellOccupierForceSolid);
                    World.Instance.OnSolidChanged(cell);
                    GameScenePartitioner.Instance.TriggerEvent(cell, solidChanged, null);
                    Grid.RenderedByWorld[cell] = true;
                }
            }
    protected override void OnCleanUp()
    {
        int placementCell = Grid.PosToCell((KMonoBehaviour)this);

        SimMessages.ClearCellProperties(placementCell, (byte)12);
        Grid.RenderedByWorld[placementCell] = true; // Grid.Element[placementCell].substance.renderedByWorld;
        Grid.FakeFloor[placementCell]       = false;
        Pathfinding.Instance.AddDirtyNavGridCell(placementCell);
        Grid.HasDoor[placementCell] = false;
        Game.Instance.SetForceField(placementCell, false, Grid.Solid[placementCell]);
        base.OnCleanUp();

        /*if (this.isPole)
         *  Grid.HasPole[Grid.PosToCell((KMonoBehaviour) this)] = false;
         * else
         *  Grid.HasLadder[Grid.PosToCell((KMonoBehaviour) this)] = false;
         * Components.Ladders.Remove(this);*/
    }
    private void SetSimState(bool is_door_open, IList <int> cells)
    {
        PrimaryElement component = GetComponent <PrimaryElement>();
        float          num       = component.Mass / (float)cells.Count;

        for (int i = 0; i < cells.Count; i++)
        {
            int      num2     = cells[i];
            DoorType doorType = this.doorType;
            if (doorType == DoorType.Pressure || doorType == DoorType.Sealed || doorType == DoorType.ManualPressure)
            {
                World.Instance.groundRenderer.MarkDirty(num2);
                if (is_door_open)
                {
                    SimMessages.Dig(num2, Game.Instance.callbackManager.Add(new Game.CallbackInfo(OnSimDoorOpened, false)).index);
                    if (ShouldBlockFallingSand)
                    {
                        SimMessages.ClearCellProperties(num2, 4);
                    }
                    else
                    {
                        SimMessages.SetCellProperties(num2, 4);
                    }
                }
                else
                {
                    HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(OnSimDoorClosed, false));
                    float temperature = component.Temperature;
                    if (temperature <= 0f)
                    {
                        temperature = component.Temperature;
                    }
                    int              gameCell     = num2;
                    SimHashes        elementID    = component.ElementID;
                    CellElementEvent doorClose    = CellEventLogger.Instance.DoorClose;
                    float            mass         = num;
                    float            temperature2 = temperature;
                    int              index        = handle.index;
                    SimMessages.ReplaceAndDisplaceElement(gameCell, elementID, doorClose, mass, temperature2, byte.MaxValue, 0, index);
                    SimMessages.SetCellProperties(num2, 4);
                }
            }
        }
    }
示例#9
0
    protected override void OnCleanUp()
    {
        smi.StopSM("cleanup");
        BuildingDef def  = GetComponent <BuildingComplete>().Def;
        int         cell = Grid.PosToCell(this);

        for (int i = 0; i < def.WidthInCells; i++)
        {
            int x   = i - (def.WidthInCells - 1) / 2;
            int num = Grid.OffsetCell(cell, new CellOffset(x, 0));
            SimMessages.ClearCellProperties(num, 39);
            Grid.Foundation[num] = false;
            Grid.SetSolid(num, false, CellEventLogger.Instance.SimCellOccupierForceSolid);
            World.Instance.OnSolidChanged(num);
            GameScenePartitioner.Instance.TriggerEvent(num, GameScenePartitioner.Instance.solidChangedLayer, null);
            Grid.RenderedByWorld[num] = true;
        }
        Game.Instance.accumulators.Remove(accumulator);
        base.OnCleanUp();
    }
    protected override void OnCleanUp()
    {
        UpdateDoorState(true);
        List <int> list = new List <int>();

        int[] placementCells = building.PlacementCells;
        foreach (int num in placementCells)
        {
            SimMessages.ClearCellProperties(num, 12);
            Grid.RenderedByWorld[num] = Grid.Element[num].substance.renderedByWorld;
            Grid.FakeFloor[num]       = false;
            if (Grid.Element[num].IsSolid)
            {
                SimMessages.ReplaceAndDisplaceElement(num, SimHashes.Vacuum, CellEventLogger.Instance.DoorOpen, 0f, -1f, byte.MaxValue, 0, -1);
            }
            Pathfinding.Instance.AddDirtyNavGridCell(num);
            if (rotatable.IsRotated)
            {
                list.Add(Grid.CellAbove(num));
                list.Add(Grid.CellBelow(num));
            }
            else
            {
                list.Add(Grid.CellLeft(num));
                list.Add(Grid.CellRight(num));
            }
        }
        int[] placementCells2 = building.PlacementCells;
        foreach (int num2 in placementCells2)
        {
            Grid.HasDoor[num2]       = false;
            Grid.HasAccessDoor[num2] = false;
            Game.Instance.SetDupePassableSolid(num2, false, Grid.Solid[num2]);
            Grid.CritterImpassable[num2] = false;
            Grid.DupeImpassable[num2]    = false;
            Pathfinding.Instance.AddDirtyNavGridCell(num2);
        }
        base.OnCleanUp();
    }
示例#11
0
        private void CleanSim(int cell)
        {
            if (!Grid.IsValidCell(cell))
            {
                return;
            }

            Grid.Foundation[cell] = false;
            Grid.HasDoor[cell]    = false;
            Game.Instance.SetDupePassableSolid(cell, false, Grid.Solid[cell]);
            Grid.CritterImpassable[cell] = false;
            Grid.DupeImpassable[cell]    = false;

            var flags = Sim.Cell.Properties.GasImpermeable | Sim.Cell.Properties.Unbreakable | Sim.Cell.Properties.Transparent;

            if (!AllowLiquidThrough)
            {
                flags |= Sim.Cell.Properties.LiquidImpermeable;
            }
            SimMessages.ClearCellProperties(cell, (byte)flags);
            SimMessages.ReplaceAndDisplaceElement(cell, SimHashes.Vacuum, CellEventLogger.Instance.DoorOpen, 0);

            Pathfinding.Instance.AddDirtyNavGridCell(cell);
        }
示例#12
0
        private static bool Prefix(Door __instance, bool is_door_open, IList <int> cells)
        {
            Door.ControlState controlState = Traverse.Create(__instance).Field("controlState").GetValue <Door.ControlState>();
            PrimaryElement    component    = __instance.GetComponent <PrimaryElement>();
            float             num          = component.Mass / (float)cells.Count;

            MethodInfo method_closed = AccessTools.Method(typeof(Door), "OnSimDoorClosed", null, null);

            System.Action cb_closed = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_closed);

            MethodInfo method_opened = AccessTools.Method(typeof(Door), "OnSimDoorOpened", null, null);

            System.Action cb_opened = (System.Action)Delegate.CreateDelegate(typeof(System.Action), __instance, method_opened);

            for (int i = 0; i < cells.Count; i++)
            {
                int           num2     = cells[i];
                Door.DoorType doorType = __instance.doorType;
                if (doorType == Door.DoorType.Pressure || doorType == Door.DoorType.Sealed || doorType == Door.DoorType.ManualPressure)
                {
                    World.Instance.groundRenderer.MarkDirty(num2);

                    if (is_door_open)
                    {
                        SimMessages.Dig(num2, Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_opened, false)).index);

                        if (controlState == Door.ControlState.Auto)
                        {
                            HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_opened, false));
                            float temperature = component.Temperature;
                            if (temperature <= 0f)
                            {
                                temperature = component.Temperature;
                            }
                            int              gameCell     = num2;
                            SimHashes        elementID    = component.ElementID;
                            CellElementEvent doorOpen     = CellEventLogger.Instance.DoorOpen;
                            float            mass         = num;
                            float            temperature2 = temperature;
                            int              index        = handle.index;
                            SimMessages.ReplaceAndDisplaceElement(gameCell, elementID, doorOpen, mass, temperature2, byte.MaxValue, 0, index);
                            SimMessages.SetCellProperties(num2, 4);
                        }

                        else if (__instance.ShouldBlockFallingSand)
                        {
                            SimMessages.ClearCellProperties(num2, 4);
                        }

                        else
                        {
                            SimMessages.SetCellProperties(num2, 4);
                        }
                    }
                    else
                    {
                        HandleVector <Game.CallbackInfo> .Handle handle = Game.Instance.callbackManager.Add(new Game.CallbackInfo(cb_closed, false));
                        float temperature = component.Temperature;
                        if (temperature <= 0f)
                        {
                            temperature = component.Temperature;
                        }
                        int              gameCell     = num2;
                        SimHashes        elementID    = component.ElementID;
                        CellElementEvent doorClose    = CellEventLogger.Instance.DoorClose;
                        float            mass         = num;
                        float            temperature2 = temperature;
                        int              index        = handle.index;
                        SimMessages.ReplaceAndDisplaceElement(gameCell, elementID, doorClose, mass, temperature2, byte.MaxValue, 0, index);
                        SimMessages.SetCellProperties(num2, 4);
                    }
                }
            }

            return(false);
        }