Beispiel #1
0
    public void RemoveAllOverlays(Vector3Int cellPosition, LayerType layerType, bool onlyIfCleanable = false)
    {
        cellPosition.z = 0;

        var overlayPos = metaTileMap.GetAllOverlayPos(cellPosition, layerType);

        if (overlayPos == null || overlayPos.Count == 0)
        {
            return;
        }

        foreach (var overlay in overlayPos)
        {
            cellPosition = overlay;

            if (onlyIfCleanable)
            {
                //only remove it if it's a cleanable tile
                var tile = metaTileMap.GetTile(cellPosition, layerType) as OverlayTile;
                //it's not an overlay tile or it's not cleanable so don't remove it
                if (tile == null || !tile.IsCleanable)
                {
                    continue;
                }
            }

            InternalRemoveTile(cellPosition, layerType);

            SpawnSafeThread.RemoveTileMessageSend(networkMatrix.MatrixSync.netId, cellPosition, layerType);

            AddToChangeList(cellPosition, layerType);
        }
    }
Beispiel #2
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            if (gasMix.Temperature > AtmosDefines.WATER_VAPOR_FREEZE)
            {
                return;
            }

            if (gasMix.GetMoles(Gas.WaterVapor) < 2f)
            {
                //Not enough moles to freeze
                return;
            }

            var numberOfIceToSpawn = (int)Mathf.Floor(gasMix.GetMoles(Gas.WaterVapor) / 2f);

            //Stack size of ice is 50
            if (numberOfIceToSpawn > 50)
            {
                numberOfIceToSpawn = 50;
            }

            if (numberOfIceToSpawn < 1)
            {
                return;
            }

            SpawnSafeThread.SpawnPrefab(tilePos, AtmosManager.Instance.iceShard, amountIfStackable: numberOfIceToSpawn);

            gasMix.RemoveGas(Gas.WaterVapor, numberOfIceToSpawn * 2f);
        }
Beispiel #3
0
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            var energyReleased = 0f;
            var oldHeatCap     = gasMix.WholeHeatCapacity;

            var temperatureScale = 1f;

            if (gasMix.Temperature < AtmosDefines.FREON_LOWER_TEMPERATURE)
            {
                temperatureScale = 0;
            }
            else
            {
                temperatureScale = (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - gasMix.Temperature) / (AtmosDefines.FREON_MAXIMUM_BURN_TEMPERATURE - AtmosDefines.FREON_LOWER_TEMPERATURE);
            }

            if (temperatureScale >= 0)
            {
                var oxygenBurnRate = AtmosDefines.OXYGEN_BURN_RATE_BASE - temperatureScale;

                var freonBurnRate = 0f;

                if (gasMix.GetMoles(Gas.Oxygen) > gasMix.GetMoles(Gas.Freon) * AtmosDefines.FREON_OXYGEN_FULLBURN)
                {
                    freonBurnRate = gasMix.GetMoles(Gas.Freon) * temperatureScale /
                                    AtmosDefines.FREON_BURN_RATE_DELTA;
                }
                else
                {
                    freonBurnRate = (temperatureScale * (gasMix.GetMoles(Gas.Oxygen) / AtmosDefines.FREON_OXYGEN_FULLBURN) / AtmosDefines.FREON_BURN_RATE_DELTA);
                }

                if (freonBurnRate > 0.0001f)
                {
                    freonBurnRate = Mathf.Min(freonBurnRate, gasMix.GetMoles(Gas.Freon), gasMix.GetMoles(Gas.Oxygen));

                    gasMix.RemoveGas(Gas.Freon, freonBurnRate);
                    gasMix.RemoveGas(Gas.Oxygen, freonBurnRate * oxygenBurnRate);

                    gasMix.AddGas(Gas.CarbonDioxide, freonBurnRate);

                    if (gasMix.Temperature < 160 && gasMix.Temperature > 120 && rnd.Next(0, 2) == 0)
                    {
                        SpawnSafeThread.SpawnPrefab(tilePos, AtmosManager.Instance.hotIce);
                    }

                    energyReleased += AtmosDefines.FIRE_FREON_ENERGY_RELEASED * freonBurnRate;
                }
            }

            if (energyReleased < 0)
            {
                var newHeatCap = gasMix.WholeHeatCapacity;
                if (newHeatCap > 0.0003f)
                {
                    gasMix.SetTemperature((gasMix.Temperature * oldHeatCap + energyReleased) / newHeatCap);
                }
            }
        }
Beispiel #4
0
    private void AlertClients(Vector3Int position, TileType tileType, string tileName,
                              Matrix4x4?transformMatrix = null, Color?color = null)
    {
        if (color == null)
        {
            color = color.GetValueOrDefault(Color.white);
        }

        if (transformMatrix == null)
        {
            transformMatrix = transformMatrix.GetValueOrDefault(Matrix4x4.identity);
        }

        SpawnSafeThread.UpdateTileMessageSend(networkMatrix.MatrixSync.netId, position, tileType, tileName, (Matrix4x4)transformMatrix, (Color)color);
    }
        public void React(GasMix gasMix, Vector3 tilePos, Matrix matrix)
        {
            if (gasMix.Temperature <= AtmosDefines.WATER_VAPOR_FREEZE)
            {
                if (gasMix.GetMoles(Gas.WaterVapor) < 2f)
                {
                    //Not enough moles to freeze
                    return;
                }

                var numberOfIceToSpawn = Mathf.Floor(gasMix.GetMoles(Gas.WaterVapor) / 2f);

                for (var i = 0; i < numberOfIceToSpawn; i++)
                {
                    SpawnSafeThread.SpawnPrefab(tilePos, AtmosManager.Instance.iceShard);
                }

                gasMix.RemoveGas(Gas.WaterVapor, numberOfIceToSpawn * 2f);
            }
        }
Beispiel #6
0
        public void Update()
        {
            if (GamesStartInitialiseSystems.Count > 0)
            {
                var ToProcess = GamesStartInitialiseSystems[0];
                GamesStartInitialiseSystems.RemoveAt(0);
                var InInterface = ToProcess as IInitialise;
                if (InInterface == null)
                {
                    return;
                }
                InInterface.Initialise();
            }

            if (QueueInitialise.Count > 0)
            {
                //Logger.Log(QueueInitialise.Count.ToString() + " < in queue ");
                stopwatch.Reset();
                stopwatch.Start();
                Action QueueAction = null;
                while (stopwatch.ElapsedMilliseconds < TargetMSprefFrame)
                {
                    if (QueueInitialise.Count > 0)
                    {
                        QueueAction = QueueInitialise.Dequeue();
                        QueueAction.Invoke();
                    }
                    else
                    {
                        break;
                    }
                }

                stopwatch.Stop();
                //Logger.Log(stopwatch.ElapsedMilliseconds.ToString() + " < ElapsedMilliseconds ");
            }
            SpawnSafeThread.Process();
        }
Beispiel #7
0
    public LayerTile RemoveTile(Vector3Int cellPosition, LayerType layerType)
    {
        var layerTile = metaTileMap.GetTile(cellPosition, layerType);

        if (metaTileMap.HasTile(cellPosition, layerType))
        {
            InternalRemoveTile(cellPosition, layerType);

            SpawnSafeThread.RemoveTileMessageSend(networkMatrix.MatrixSync.netId, cellPosition, layerType);

            AddToChangeList(cellPosition, layerType);

            if (layerType == LayerType.Floors || layerType == LayerType.Base)
            {
                OnFloorOrPlatingRemoved.Invoke(cellPosition);
            }

            RemoveOverlaysOfType(cellPosition, LayerType.Effects, OverlayType.Damage);

            return(layerTile);
        }

        return(layerTile);
    }
Beispiel #8
0
        public void Update()
        {
            if (GamesStartInitialiseSystems.Count > 0)
            {
                var ToProcess = GamesStartInitialiseSystems[0];
                GamesStartInitialiseSystems.RemoveAt(0);
                var InInterface = ToProcess as IInitialise;
                if (InInterface == null)
                {
                    return;
                }
                try
                {
                    InInterface.Initialise();
                }
                catch (Exception e)
                {
                    Logger.LogError(e.ToString());
                }
            }

            if (DelayedActions.Count > 0)
            {
                //Logger.Log(QueueInitialise.Count.ToString() + " < in queue ");
                stopwatch.Start();

                int i = 0;
                while (stopwatch.ElapsedMilliseconds < TargetMSprefFramePreStep && DelayedActions.Count > i)
                {
                    if (DelayedActions.Count > 0)
                    {
                        DelayedAction delayedAction = DelayedActions[i];
                        delayedAction.Frames -= 1;
                        if (delayedAction.Frames <= 0)
                        {
                            try
                            {
                                ToClear.Add(delayedAction);
                                delayedAction.Action.Invoke();
                            }
                            catch (Exception e)
                            {
                                Logger.LogError(e.ToString());
                            }
                        }

                        i++;
                    }
                    else
                    {
                        break;
                    }
                }

                stopwatch.Stop();
                stopwatch.Reset();
                //Logger.Log(stopwatch.ElapsedMilliseconds.ToString() + " < ElapsedMilliseconds ");
            }

            if (QueueInitialise.Count > 0)
            {
                //Logger.Log(QueueInitialise.Count.ToString() + " < in queue ");
                stopwatch.Start();
                Action QueueAction = null;
                while (stopwatch.ElapsedMilliseconds < TargetMSprefFramePreStep)
                {
                    if (QueueInitialise.Count > 0)
                    {
                        QueueAction = QueueInitialise.Dequeue();
                        try
                        {
                            QueueAction.Invoke();
                        }
                        catch (Exception e)
                        {
                            Logger.LogError(e.ToString());
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                stopwatch.Stop();
                stopwatch.Reset();
                //Logger.Log(stopwatch.ElapsedMilliseconds.ToString() + " < ElapsedMilliseconds ");
            }

            foreach (var delayedAction in ToClear)
            {
                DelayedActions.Remove(delayedAction);
            }

            SpawnSafeThread.Process();
        }