Beispiel #1
0
 /// <summary>
 /// Destroys the scene partitioner entry for this collider.
 /// </summary>
 private void DestroyPartitioner()
 {
     if (partitionerEntry.IsValid())
     {
         GameScenePartitioner.Instance.Free(ref partitionerEntry);
     }
 }
 protected void UpdateAnimEventSequenceTime()
 {
     if (eventManagerHandle.IsValid() && aem != null)
     {
         aem.SetElapsedTime(eventManagerHandle, elapsedTime);
     }
 }
 public void StartAbsorbing()
 {
     if (!absorberHandle.IsValid() && base.def.consumedElements != null && base.def.consumedElements.Length != 0)
     {
         GameObject gameObject = base.smi.gameObject;
         absorberHandle = Game.Instance.plantElementAbsorbers.Add(storage, base.def.consumedElements);
     }
 }
Beispiel #4
0
 public override void OnCleanUp()
 {
     if (partitionerEntry.IsValid())
     {
         GameScenePartitioner.Instance.Free(ref partitionerEntry);
     }
     base.OnCleanUp();
 }
Beispiel #5
0
 private void OnSerializing()
 {
     _Temperature = Temperature;
     SanitizeMassAndTemperature();
     diseaseID.HashValue = 0;
     diseaseCount        = 0;
     if (useSimDiseaseInfo)
     {
         int i = Grid.PosToCell(base.transform.GetPosition());
         if (Grid.DiseaseIdx[i] != 255)
         {
             diseaseID    = Db.Get().Diseases[Grid.DiseaseIdx[i]].id;
             diseaseCount = Grid.DiseaseCount[i];
         }
     }
     else if (diseaseHandle.IsValid())
     {
         DiseaseHeader header = GameComps.DiseaseContainers.GetHeader(diseaseHandle);
         if (header.diseaseIdx != 255)
         {
             diseaseID    = Db.Get().Diseases[header.diseaseIdx].id;
             diseaseCount = header.diseaseCount;
         }
     }
 }
    public void Update()
    {
        float num = 0f;

        if (temperatureAmount != null)
        {
            num = temperatureAmount.value;
        }
        else if (structureTemperature.IsValid())
        {
            num = GameComps.StructureTemperatures.GetPayload(structureTemperature).Temperature;
        }
        else if ((Object)primaryElement != (Object)null)
        {
            num = primaryElement.Temperature;
        }
        else if ((Object)temperatureVulnerable != (Object)null)
        {
            num = temperatureVulnerable.InternalTemperature;
        }
        if (!(num < 0f))
        {
            Color32 c = SimDebugView.Instance.NormalizedTemperature(num);
            controller.OverlayColour = c;
        }
    }
    public void Close()
    {
        openCount = Mathf.Max(0, openCount - 1);
        if (openCount == 0 && DisplacesGas(doorType))
        {
            StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures;
            HandleVector <int> .Handle     handle = structureTemperatures.GetHandle(base.gameObject);
            PrimaryElement component = GetComponent <PrimaryElement>();
            if (handle.IsValid() && !structureTemperatures.IsBypassed(handle))
            {
                float num = component.Temperature = structureTemperatures.GetPayload(handle).Temperature;
            }
        }
        switch (controlState)
        {
        case ControlState.Locked:
            controller.sm.isOpen.Set(false, controller);
            break;

        case ControlState.Auto:
            if (openCount == 0)
            {
                controller.sm.isOpen.Set(false, controller);
                Game.Instance.userMenu.Refresh(base.gameObject);
            }
            break;
        }
    }
 public override void OnPlay(AnimEventManager.EventPlayerData behaviour)
 {
     if (!string.IsNullOrEmpty(base.sound) && SoundEvent.ShouldPlaySound(behaviour.controller, base.sound, base.looping, isDynamic))
     {
         int        num        = -1;
         GameObject gameObject = behaviour.controller.gameObject;
         if (counterModulus >= -1)
         {
             HandleVector <int> .Handle h = GameComps.WhiteBoards.GetHandle(gameObject);
             if (!h.IsValid())
             {
                 h = GameComps.WhiteBoards.Add(gameObject);
             }
             num = (GameComps.WhiteBoards.HasValue(h, base.soundHash) ? ((int)GameComps.WhiteBoards.GetValue(h, base.soundHash)) : 0);
             int num2 = (counterModulus != -1) ? ((num + 1) % counterModulus) : 0;
             GameComps.WhiteBoards.SetValue(h, base.soundHash, num2);
         }
         Vector3       position = behaviour.GetComponent <Transform>().GetPosition();
         EventInstance instance = SoundEvent.BeginOneShot(base.sound, position);
         if (instance.isValid())
         {
             if (num >= 0)
             {
                 instance.setParameterValue("eventCount", (float)num);
             }
             SoundEvent.EndOneShot(instance);
         }
     }
 }
 public void CancelClearing()
 {
     if (isMarkedForClear)
     {
         isMarkedForClear = false;
         GetComponent <KPrefabID>().RemoveTag(GameTags.Garbage);
         Prioritizable.RemoveRef(base.gameObject);
         if (clearHandle.IsValid())
         {
             GlobalChoreProvider.Instance.UnregisterClearable(clearHandle);
             clearHandle.Clear();
         }
         RefreshClearableStatus();
         SimAndRenderScheduler.instance.Remove(this);
     }
 }
 public void UpdatePosition(HandleVector <int> .Handle handle, int x, int y)
 {
     if (handle.IsValid())
     {
         ScenePartitionerEntry data = scenePartitionerEntries.GetData(handle);
         data.UpdatePosition(x, y);
     }
 }
Beispiel #11
0
 public void SetData(HandleVector <int> .Handle handle, ref ConduitFlow.ConduitContents contents)
 {
     if (handle.IsValid())
     {
         temperatures[Sim.GetHandleIndex(handle.index)] = contents.temperature;
         ConduitTemperatureManager_Set(handle.index, contents.temperature, contents.mass, (int)contents.element);
     }
 }
 public void Free(ref HandleVector <int> .Handle handle)
 {
     if (handle.IsValid())
     {
         ScenePartitionerEntry data = scenePartitionerEntries.GetData(handle);
         data.Release();
         scenePartitionerEntries.Free(handle);
         handle.Clear();
     }
 }
    private CavityInfo GetCavityInfo(HandleVector <int> .Handle id)
    {
        CavityInfo result = null;

        if (id.IsValid())
        {
            result = cavityInfos.GetData(id);
        }
        return(result);
    }
Beispiel #14
0
	public void RegisterListeners()
	{
		if (!cleaningUp && !solidPartitionerEntry.IsValid())
		{
			int num = Grid.PosToCell(this);
			objectLayerListItem = new ObjectLayerListItem(base.gameObject, ObjectLayer.Pickupables, num);
			solidPartitionerEntry = GameScenePartitioner.Instance.Add("Pickupable.RegisterSolidListener", base.gameObject, num, GameScenePartitioner.Instance.solidChangedLayer, OnSolidChanged);
			partitionerEntry = GameScenePartitioner.Instance.Add("Pickupable.RegisterPickupable", this, num, GameScenePartitioner.Instance.pickupablesLayer, null);
			Singleton<CellChangeMonitor>.Instance.RegisterCellChangedHandler(base.transform, OnCellChange, "Pickupable.OnCellChange");
			Singleton<CellChangeMonitor>.Instance.MarkDirty(base.transform);
		}
	}
Beispiel #15
0
    public override void OnPlay(AnimEventManager.EventPlayerData behaviour)
    {
        if (!string.IsNullOrEmpty(base.sound) && SoundEvent.ShouldPlaySound(behaviour.controller, base.sound, base.looping, isDynamic))
        {
            int        num        = -1;
            GameObject gameObject = behaviour.controller.gameObject;
            if (counterModulus >= -1)
            {
                HandleVector <int> .Handle h = GameComps.WhiteBoards.GetHandle(gameObject);
                if (!h.IsValid())
                {
                    h = GameComps.WhiteBoards.Add(gameObject);
                }
                num = (GameComps.WhiteBoards.HasValue(h, base.soundHash) ? ((int)GameComps.WhiteBoards.GetValue(h, base.soundHash)) : 0);
                int num2 = (counterModulus != -1) ? ((num + 1) % counterModulus) : 0;
                GameComps.WhiteBoards.SetValue(h, base.soundHash, num2);
            }
            Vector3 position  = behaviour.GetComponent <Transform>().GetPosition();
            string  sound     = GlobalAssets.GetSound("Hammer_sculpture", false);
            Worker  component = behaviour.GetComponent <Worker>();
            if ((UnityEngine.Object)component != (UnityEngine.Object)null)
            {
                Workable workable = component.workable;
                if ((UnityEngine.Object)workable != (UnityEngine.Object)null)
                {
                    Building component2 = workable.GetComponent <Building>();
                    if ((UnityEngine.Object)component2 != (UnityEngine.Object)null)
                    {
                        BuildingDef def = component2.Def;
                        switch (def.name)
                        {
                        case "MetalSculpture":
                            sound = GlobalAssets.GetSound("Hammer_sculpture_metal", false);
                            break;

                        case "MarbleSculpture":
                            sound = GlobalAssets.GetSound("Hammer_sculpture_marble", false);
                            break;
                        }
                    }
                }
            }
            EventInstance instance = SoundEvent.BeginOneShot(sound, position);
            if (instance.isValid())
            {
                if (num >= 0)
                {
                    instance.setParameterValue("eventCount", (float)num);
                }
                SoundEvent.EndOneShot(instance);
            }
        }
    }
Beispiel #16
0
 protected override void OnSpawn()
 {
     base.OnSpawn();
     InitializeModifiers();
     HandleVector <int> .Handle handle = GameComps.StructureTemperatures.GetHandle(base.gameObject);
     if (handle.IsValid() && GameComps.StructureTemperatures.IsEnabled(handle))
     {
         GameComps.StructureTemperatures.Disable(handle);
         GameComps.StructureTemperatures.Enable(handle);
     }
     base.smi.StartSM();
 }
 public void Sim200ms(float dt)
 {
     if (!((Object)this == (Object)null))
     {
         if (doorOpenLiquidRefreshHack)
         {
             doorOpenLiquidRefreshTime -= dt;
             if (doorOpenLiquidRefreshTime <= 0f)
             {
                 doorOpenLiquidRefreshHack = false;
                 int[] placementCells = building.PlacementCells;
                 foreach (int cell in placementCells)
                 {
                     Pathfinding.Instance.AddDirtyNavGridCell(cell);
                 }
             }
         }
         if (applyLogicChange)
         {
             applyLogicChange = false;
             ApplyRequestedControlState(false);
         }
         if (do_melt_check)
         {
             StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures;
             HandleVector <int> .Handle     handle = structureTemperatures.GetHandle(base.gameObject);
             if (handle.IsValid())
             {
                 StructureTemperaturePayload payload = structureTemperatures.GetPayload(handle);
                 if (!payload.enabled)
                 {
                     int[] placementCells2 = building.PlacementCells;
                     int   num             = 0;
                     while (true)
                     {
                         if (num >= placementCells2.Length)
                         {
                             return;
                         }
                         int i2 = placementCells2[num];
                         if (!Grid.Solid[i2])
                         {
                             break;
                         }
                         num++;
                     }
                     PrimaryElement component = GetComponent <PrimaryElement>();
                     StructureTemperatureComponents.DoMelt(component);
                 }
             }
         }
     }
 }
Beispiel #18
0
            public static void Prefix(ICollection <int> visited_cells, KCompactedVector <CavityInfo> ___cavityInfos, HandleVector <int> .Handle[] ___CellCavityID)
            {
                int maxRoomSize = TuningData <RoomProber.Tuning> .Get().maxRoomSize;

                foreach (int current in visited_cells)
                {
                    HandleVector <int> .Handle handle = ___CellCavityID [current];
                    if (handle.IsValid())
                    {
                        CavityInfo data = ___cavityInfos.GetData(handle);
                        if (0 < data.numCells && data.numCells <= maxRoomSize)
                        {
                            GameObject gameObject = Grid.Objects [current, (int)ObjectLayer.Plants];
                            if (gameObject != null)
                            {
                                KPrefabID component = gameObject.GetComponent <KPrefabID> ();
                                bool      flag2     = false;
                                foreach (KPrefabID current2 in data.buildings)
                                {
                                    if (component.InstanceID == current2.InstanceID)
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                                foreach (KPrefabID current3 in data.plants)
                                {
                                    if (component.InstanceID == current3.InstanceID)
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                                if (!flag2)
                                {
                                    if (component.GetComponent <Deconstructable> ())
                                    {
                                        data.AddBuilding(component);
                                    }
                                    else
                                    {
                                        if (component.HasTag(GameTags.Plant) && !component.HasTag("ForestTreeBranch".ToTag()))
                                        {
                                            data.AddPlants(component);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
Beispiel #19
0
 public void Release()
 {
     if (handle.IsValid())
     {
         Game.CallbackInfo item = Game.Instance.callbackManager.GetItem(handle);
         System.Action     cb   = item.cb;
         if (!item.manuallyRelease)
         {
             Game.Instance.callbackManager.Release(handle);
         }
         cb();
     }
 }
 private void OnMove()
 {
     if (partitionerEntry.IsValid())
     {
         Extents extents = occupyArea.GetExtents();
         GameScenePartitioner.Instance.UpdatePosition(partitionerEntry, extents.x, extents.y);
     }
     else
     {
         partitionerEntry = GameScenePartitioner.Instance.Add("DrowningMonitor.OnSpawn", base.gameObject, occupyArea.GetExtents(), GameScenePartitioner.Instance.liquidChangedLayer, OnLiquidChanged);
     }
     CheckDrowning(null);
 }
Beispiel #21
0
    protected override void OnCleanUp()
    {
        IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType);

        networkManager.RemoveFromNetworks(filteredCell, itemFilter, true);
        ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType);

        flowManager.RemoveConduitUpdater(OnConduitTick);
        if (partitionerEntry.IsValid() && (UnityEngine.Object)GameScenePartitioner.Instance != (UnityEngine.Object)null)
        {
            GameScenePartitioner.Instance.Free(ref partitionerEntry);
        }
        base.OnCleanUp();
    }
Beispiel #22
0
 public void Free(HandleVector <int> .Handle handle)
 {
     if (handle.IsValid())
     {
         int handleIndex = Sim.GetHandleIndex(handle.index);
         temperatures[handleIndex] = -1f;
         conduitInfo[handleIndex]  = new ConduitInfo
         {
             type = ConduitType.None,
             idx  = -1
         };
         ConduitTemperatureManager_Remove(handle.index);
     }
 }
    private void RebuildDirtyCavities(ICollection <int> visited_cells)
    {
        int maxRoomSize = TuningData <Tuning> .Get().maxRoomSize;

        foreach (int visited_cell in visited_cells)
        {
            HandleVector <int> .Handle handle = CellCavityID[visited_cell];
            if (handle.IsValid())
            {
                CavityInfo data = cavityInfos.GetData(handle);
                if (0 < data.numCells && data.numCells <= maxRoomSize)
                {
                    GameObject gameObject = Grid.Objects[visited_cell, 1];
                    if ((UnityEngine.Object)gameObject != (UnityEngine.Object)null)
                    {
                        KPrefabID component = gameObject.GetComponent <KPrefabID>();
                        bool      flag      = false;
                        foreach (KPrefabID building in data.buildings)
                        {
                            if (component.InstanceID == building.InstanceID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        foreach (KPrefabID plant in data.plants)
                        {
                            if (component.InstanceID == plant.InstanceID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            if ((bool)component.GetComponent <Deconstructable>())
                            {
                                data.AddBuilding(component);
                            }
                            else if (component.HasTag(GameTags.Plant) && !component.HasTag("ForestTreeBranch".ToTag()))
                            {
                                data.AddPlants(component);
                            }
                        }
                    }
                }
            }
        }
        visited_cells.Clear();
    }
Beispiel #24
0
	private void OnOreSizeChanged(object data)
	{
		Vector3 v = Vector3.zero;
		HandleVector<int>.Handle handle = GameComps.Gravities.GetHandle(base.gameObject);
		if (handle.IsValid())
		{
			GravityComponent data2 = GameComps.Gravities.GetData(handle);
			v = data2.velocity;
		}
		RemoveFaller();
		if (!KPrefabID.HasTag(GameTags.Stored))
		{
			AddFaller(v);
		}
	}
Beispiel #25
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);
         }
     }
 }
Beispiel #26
0
    public void MarkDirty(bool force = false)
    {
        bool flag = force || partitionerEntry.IsValid();

        if (flag)
        {
            Extents extents = GetExtents();
            if (force || cachedExtents.x != extents.x || cachedExtents.y != extents.y || cachedExtents.width != extents.width || cachedExtents.height != extents.height)
            {
                cachedExtents = extents;
                GameScenePartitioner.Instance.Free(ref partitionerEntry);
                if (flag)
                {
                    partitionerEntry = GameScenePartitioner.Instance.Add(base.name, this, cachedExtents, GameScenePartitioner.Instance.collisionLayer, null);
                }
            }
        }
    }
    public float Open()
    {
        if (openCount == 0 && DisplacesGas(doorType))
        {
            StructureTemperatureComponents structureTemperatures = GameComps.StructureTemperatures;
            HandleVector <int> .Handle     handle = structureTemperatures.GetHandle(base.gameObject);
            if (handle.IsValid() && structureTemperatures.IsBypassed(handle))
            {
                int[] placementCells = building.PlacementCells;
                float num            = 0f;
                int   num2           = 0;
                foreach (int i2 in placementCells)
                {
                    if (Grid.Mass[i2] > 0f)
                    {
                        num2++;
                        num += Grid.Temperature[i2];
                    }
                }
                if (num2 > 0)
                {
                    num /= (float)placementCells.Length;
                    PrimaryElement component = GetComponent <PrimaryElement>();
                    KCrashReporter.Assert(num > 0f, "Door has calculated an invalid temperature");
                    component.Temperature = num;
                }
            }
        }
        openCount++;
        float result = 1f;

        if ((Object)consumer != (Object)null)
        {
            result = ((!consumer.IsPowered) ? 0.5f : 1f);
        }
        switch (controlState)
        {
        case ControlState.Auto:
        case ControlState.Opened:
            controller.sm.isOpen.Set(true, controller);
            break;
        }
        return(result);
    }
        public void UpdateAbsorbing(bool allow)
        {
            bool flag = allow && !base.smi.gameObject.HasTag(GameTags.Wilting);

            if (flag != absorberHandle.IsValid())
            {
                if (flag)
                {
                    if (base.def.consumedElements != null && base.def.consumedElements.Length != 0)
                    {
                        absorberHandle = Game.Instance.plantElementAbsorbers.Add(storage, base.def.consumedElements);
                    }
                }
                else
                {
                    absorberHandle = Game.Instance.plantElementAbsorbers.Remove(absorberHandle);
                }
            }
        }
Beispiel #29
0
 protected bool Free(HandleVector <int> .Handle handle, int last_idx, out int free_component_idx)
 {
     free_component_idx = -1;
     if (!handle.IsValid())
     {
         return(false);
     }
     free_component_idx = handles.Release(handle);
     if (free_component_idx < last_idx)
     {
         int num = dataHandleIndices[last_idx];
         if (handles.Items[num] != last_idx)
         {
             DebugUtil.LogErrorArgs("KCompactedVector: Bad state after attempting to free handle", handle.index);
         }
         handles.Items[num] = free_component_idx;
         dataHandleIndices[free_component_idx] = num;
     }
     dataHandleIndices.RemoveAt(last_idx);
     return(true);
 }
Beispiel #30
0
 protected override void UpdateCell(int previous_cell, int current_cell)
 {
     if (previous_cell != current_cell)
     {
         base.UpdateCell(previous_cell, current_cell);
         if (!solidPartitionerEntry.IsValid())
         {
             Extents extents = new Extents(current_cell, table);
             extents.height += 2;
             extents.y--;
             solidPartitionerEntry = GameScenePartitioner.Instance.Add("OffsetTableTracker.UpdateCell", cmp.gameObject, extents, GameScenePartitioner.Instance.solidChangedLayer, OnCellChanged);
             validNavCellChangedPartitionerEntry = GameScenePartitioner.Instance.Add("OffsetTableTracker.UpdateCell", cmp.gameObject, extents, GameScenePartitioner.Instance.validNavCellChangedLayer, OnCellChanged);
         }
         else
         {
             GameScenePartitioner.Instance.UpdatePosition(solidPartitionerEntry, current_cell);
             GameScenePartitioner.Instance.UpdatePosition(validNavCellChangedPartitionerEntry, current_cell);
         }
         offsets = null;
     }
 }