Exemplo n.º 1
0
    public List <IntrinsicElectronicData> GetElectricalConnections(Vector3Int position)
    {
        var list = ElectricalPool.GetFPCList();

        if (ServerObjects != null)
        {
            var collection = ServerObjects.Get(position);
            for (int i = collection.Count - 1; i >= 0; i--)
            {
                if (i < collection.Count && collection[i] != null &&
                    collection[i].ElectricalData != null &&
                    collection[i].ElectricalData.InData != null)
                {
                    list.Add(collection[i].ElectricalData.InData);
                }
            }
        }
        if (metaDataLayer.Get(position)?.ElectricalData != null)
        {
            foreach (var electricalMetaData in metaDataLayer.Get(position).ElectricalData)
            {
                list.Add(electricalMetaData.InData);
            }
        }
        return(list);
    }
Exemplo n.º 2
0
    private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos)
    {
        forceDir.z = 0;
        Vector3      bulletHitTarget = hitPos + (forceDir * 0.2f);
        Vector3Int   cellPos         = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget));
        MetaDataNode data            = metaDataLayer.Get(cellPos);

        if (Layer.LayerType == LayerType.Windows)
        {
            LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows);
            if (getTile != null)
            {
                //TODO damage amt based off type of bullet
                AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget);
                return;
            }
        }

        if (Layer.LayerType == LayerType.Grills)
        {
            //Make sure a window is not protecting it first:
            if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true))
            {
                if (metaTileMap.HasTile(cellPos, LayerType.Grills, true))
                {
                    //TODO damage amt based off type of bullet
                    AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget);
                }
            }
        }
    }
Exemplo n.º 3
0
    public void ExposeHotspot(Vector3Int localPosition, float temperature, float volume)
    {
        if (hotspots.ContainsKey(localPosition) && hotspots[localPosition].Hotspot != null)
        {
            // TODO soh?
            hotspots[localPosition].Hotspot.UpdateValues(volume * 25, temperature);
        }
        else
        {
            MetaDataNode node   = metaDataLayer.Get(localPosition);
            GasMix       gasMix = node.GasMix;

            if (gasMix.GetMoles(Gas.Plasma) > 0.5 && gasMix.GetMoles(Gas.Oxygen) > 0.5 && temperature > Reactions.PLASMA_MINIMUM_BURN_TEMPERATURE)
            {
                // igniting
                Hotspot hotspot = new Hotspot(node, temperature, volume * 25);
                node.Hotspot            = hotspot;
                hotspots[localPosition] = node;
            }
        }

        if (hotspots.ContainsKey(localPosition) && hotspots[localPosition].Hotspot != null)
        {
            //expose everything on this tile
            Expose(localPosition, localPosition);

            //expose impassable things on the adjacent tile
            Expose(localPosition, localPosition + Vector3Int.right);
            Expose(localPosition, localPosition + Vector3Int.left);
            Expose(localPosition, localPosition + Vector3Int.up);
            Expose(localPosition, localPosition + Vector3Int.down);
        }
    }
Exemplo n.º 4
0
        private void InitializeRooms()
        {
            BoundsInt bounds = metaTileMap.GetBounds();

            int roomCounter = 1;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            foreach (Vector3Int position in bounds.allPositionsWithin)
            {
                MetaDataNode node = metaDataLayer.Get(position, false);

                if ((node == null || node.Room == 0) && !metaTileMap.IsSpaceAt(position) && metaTileMap.IsAtmosPassableAt(position))
                {
                    if (FindRoom(position, roomCounter))
                    {
                        roomCounter++;
                    }
                }
            }

            sw.Stop();

            Debug.Log("Room init: " + sw.ElapsedMilliseconds + " ms");
        }
Exemplo n.º 5
0
    private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir)
    {
        forceDir.z = 0;
        var bulletHitTarget = bullet.transform.position + (forceDir * 0.2f);
        var cellPos         = tileChangeManager.baseTileMap.WorldToCell(bulletHitTarget);
        var data            = metaDataLayer.Get(cellPos);

        if (Layer.LayerType == LayerType.Windows)
        {
            var getTile = tileChangeManager.windowTileMap.GetTile(cellPos);
            if (getTile != null)
            {
                //TODO damage amt based off type of bullet
                AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget);
                return;
            }
        }
        if (Layer.LayerType == LayerType.Grills)
        {
            var getWindowTile = tileChangeManager.windowTileMap.GetTile(cellPos);

            //Make sure a window is not protecting it first:
            if (!getWindowTile)
            {
                var getGrillTile = tileChangeManager.grillTileMap.GetTile(cellPos);
                if (getGrillTile != null)
                {
                    //TODO damage amt based off type of bullet
                    AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget);
                }
            }
        }
    }
Exemplo n.º 6
0
	public void OnExposed(FireExposure exposure)
	{
		if (Layer.LayerType == LayerType.Floors ||
		    Layer.LayerType == LayerType.Base ||
		    Layer.LayerType == LayerType.Walls ) return;

		var basicTile = metaTileMap.GetTile(exposure.ExposedLocalPosition, Layer.LayerType) as BasicTile;

		if (basicTile == null) return;

		MetaDataNode data = metaDataLayer.Get(exposure.ExposedLocalPosition);
		AddDamage(exposure.StandardDamage(), AttackType.Fire, data, basicTile, exposure.ExposedWorldPosition);
	}
Exemplo n.º 7
0
    public void ExposeHotspot(Vector3Int position, float temperature, float volume)
    {
        if (hotspots.ContainsKey(position) && hotspots[position].Hotspot != null)
        {
            // TODO soh?
            hotspots[position].Hotspot.UpdateValues(volume * 25, temperature);
        }
        else
        {
            MetaDataNode node   = metaDataLayer.Get(position);
            GasMix       gasMix = node.GasMix;

            if (gasMix.GetMoles(Gas.Plasma) > 0.5 && gasMix.GetMoles(Gas.Oxygen) > 0.5 && temperature > Reactions.PLASMA_MINIMUM_BURN_TEMPERATURE)
            {
                // igniting
                Hotspot hotspot = new Hotspot(node, temperature, volume * 25);
                node.Hotspot       = hotspot;
                hotspots[position] = node;
            }
        }

        if (hotspots.ContainsKey(position) && hotspots[position].Hotspot != null)
        {
            List <LivingHealthBehaviour> healths = matrix.Get <LivingHealthBehaviour>(position);

            foreach (LivingHealthBehaviour health in healths)
            {
                health.ApplyDamage(null, 1, DamageType.Burn);
            }
        }
    }
Exemplo n.º 8
0
        private void CheckRelease()
        {
            if (Opened)
            {
                MetaDataLayer metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position), true)
                                              .MetaDataLayer;

                Vector3Int   position = transform.localPosition.RoundToInt();
                MetaDataNode node     = metaDataLayer.Get(position, false);

                float deltaPressure = Mathf.Min(GasMix.Pressure, ReleasePressure) - node.GasMix.Pressure;

                if (deltaPressure > 0)
                {
                    float ratio = deltaPressure / GasMix.Pressure * Time.deltaTime;

                    node.GasMix += GasMix * ratio;

                    GasMix *= (1 - ratio);

                    metaDataLayer.UpdateSystemsAt(position);

                    Volume      = GasMix.Volume;
                    Temperature = GasMix.Temperature;

                    foreach (Gas gas in Gas.All)
                    {
                        Gases[gas] = GasMix.Gases[gas];
                    }
                }
            }
        }
Exemplo n.º 9
0
        private static void DrawGizmo2(MetaDataLayer scr, GizmoType gizmoType)
        {
            if (!DrawGizmos || !rooms)
            {
                return;
            }

            Vector3Int start = Vector3Int.RoundToInt(Camera.current.ScreenToWorldPoint(Vector3.one * -32) - scr.transform.position);             // bottom left
            Vector3Int end   =
                Vector3Int.RoundToInt(Camera.current.ScreenToWorldPoint(new Vector3(Camera.current.pixelWidth + 32, Camera.current.pixelHeight + 32)) -
                                      scr.transform.position);

            start.z = 0;
            end.z   = 1;

            if (end.y - start.y > 100)
            {
                // avoid being zoomed out too much (creates too many objects)
                return;
            }

            Gizmos.matrix = scr.transform.localToWorldMatrix;

            Color blue = Color.blue;

            blue.a = 0.5f;

            Color red = Color.red;

            red.a = 0.5f;

            Color green = Color.green;

            green.a = 0.5f;

            foreach (Vector3Int position in new BoundsInt(start, end - start).allPositionsWithin)
            {
                MetaDataNode node = scr.Get(position, false);
                if (node != null)
                {
                    if (node.Room == 0)
                    {
                        Gizmos.color = green;
                    }

                    if (node.Room > 0)
                    {
                        Gizmos.color = blue;
                    }

                    if (node.Room < 0)
                    {
                        Gizmos.color = red;
                    }

                    Gizmos.DrawCube(position + new Vector3(0.5f, 0.5f, 0), Vector3.one);
                }
            }
        }
Exemplo n.º 10
0
        private void ReleaseContentsInstantly()
        {
            MetaDataLayer metaDataLayer = MatrixManager.AtPoint(WorldPosition, true).MetaDataLayer;
            MetaDataNode  node          = metaDataLayer.Get(LocalPosition, false);

            GasMix.TransferGas(node.GasMix, GasMix, GasMix.Moles);
            metaDataLayer.UpdateSystemsAt(LocalPosition, SystemType.AtmosSystem);
        }
Exemplo n.º 11
0
        public override void OnSpawnServer(SpawnInfo info)
        {
            metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
            metaNode      = metaDataLayer.Get(registerTile.LocalPositionServer, false);
            pipeMix       = pipeData.GetMixAndVolume.GetGasMix();

            UpdateState();
            base.OnSpawnServer(info);
        }
Exemplo n.º 12
0
 public override void OnSpawnServer(SpawnInfo info)
 {
     metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
     metaNode      = metaDataLayer.Get(registerTile.LocalPositionServer, false);
     if (SelfSufficient)
     {
         selfSufficientGas = GasMix.NewGasMix(GasMixes.Air);
     }
     base.OnSpawnServer(info);
 }
Exemplo n.º 13
0
        public void OnSpawnServer(SpawnInfo info)
        {
            var integrity = GetComponent <Integrity>();

            integrity.OnExposedEvent.AddListener(TriggerAlarm);
            RegisterTile  registerTile  = GetComponent <RegisterTile>();
            MetaDataLayer metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;

            metaNode = metaDataLayer.Get(registerTile.LocalPositionServer, false);
            Controller.Open();
        }
Exemplo n.º 14
0
        private void CheckPressure()
        {
            MetaDataLayer metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position)).MetaDataLayer;

            GasMix atmos = metaDataLayer.Get(transform.localPosition.RoundToInt(), false).Atmos;

            if (atmos.Pressure < AtmosConstants.HAZARD_LOW_PRESSURE || atmos.Pressure > AtmosConstants.HAZARD_HIGH_PRESSURE)
            {
                Logger.Log("URGENT TODO: Perform atmos damage to player ", Category.Health);
                //	health.ApplyDamage(null, (int)pressureDamage * Time.deltaTime, DamageType.Brute);
            }
        }
Exemplo n.º 15
0
        public override void OnSpawnServer(SpawnInfo info)
        {
            metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
            metaNode      = metaDataLayer.Get(registerTile.LocalPositionServer, false);
            pipeMix       = selfSufficient ? GasMix.NewGasMix(GasMixes.BaseEmptyMix) : pipeData.GetMixAndVolume.GetGasMix();

            if (TryGetComponent <AcuDevice>(out var device) && device.Controller != null)
            {
                SetOperatingMode(device.Controller.DesiredMode);
            }

            base.OnSpawnServer(info);
        }
Exemplo n.º 16
0
    public List <IntrinsicElectronicData> GetElectricalConnections(Vector3Int position)
    {
        var list = ElectricalPool.GetFPCList();

        if (ServerObjects != null)
        {
            foreach (var Object in ServerObjects.Get(position))
            {
                if (Object?.ElectricalData?.InData != null)
                {
                    list.Add(Object?.ElectricalData?.InData);
                }
            }
        }
        if (metaDataLayer.Get(position)?.ElectricalData != null)
        {
            foreach (var electricalMetaData in metaDataLayer.Get(position).ElectricalData)
            {
                list.Add(electricalMetaData.InData);
            }
        }
        return(list);
    }
Exemplo n.º 17
0
    public void OnSpawnServer(SpawnInfo info)
    {
        var integrity = GetComponent <Integrity>();

        integrity.OnExposedEvent.AddListener(SendCloseAlerts);
        AtmosManager.Instance.inGameFireAlarms.Add(this);
        RegisterTile  registerTile  = GetComponent <RegisterTile>();
        MetaDataLayer metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;

        metaNode = metaDataLayer.Get(registerTile.LocalPositionServer, false);
        foreach (var firelock in FireLockList)
        {
            firelock.fireAlarm = this;
        }
    }
Exemplo n.º 18
0
        private void OperateAirPump()
        {
            MetaDataLayer metadata = registerObject.Matrix.MetaDataLayer;
            GasMix        tileMix  = metadata.Get(registerObject.LocalPositionServer, false).GasMix;

            // TODO: add voltage multiplier when bins are powered
            var molesToTransfer = (tileMix.Moles - (tileMix.Moles * (CHARGED_PRESSURE / gasContainer.GasMix.Pressure))) * -1;

            molesToTransfer *= 0.5f;

            GasMix.TransferGas(gasContainer.GasMix, tileMix, molesToTransfer.Clamp(0, 8));
            metadata.UpdateSystemsAt(registerObject.LocalPositionServer, SystemType.AtmosSystem);

            chargePressure = gasContainer.GasMix.Pressure;
        }
Exemplo n.º 19
0
        public override void TickUpdate()
        {
            if (metaDataLayer == null)
            {
                metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
            }

            if (metaNode == null)
            {
                metaNode = metaDataLayer.Get(registerTile.LocalPositionServer, false);
            }


            base.TickUpdate();
            pipeData.mixAndVolume.EqualiseWithOutputs(pipeData.Outputs);
            CheckAtmos();
        }
Exemplo n.º 20
0
    private void DoBulletDamage(BulletBehaviour bullet, Vector3 forceDir, Vector3 hitPos)
    {
        forceDir.z = 0;
        Vector3      bulletHitTarget = hitPos + (forceDir * 0.2f);
        Vector3Int   cellPos         = metaTileMap.WorldToCell(Vector3Int.RoundToInt(bulletHitTarget));
        MetaDataNode data            = metaDataLayer.Get(cellPos);

        if (Layer.LayerType == LayerType.Windows)
        {
            LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Windows);
            if (getTile != null)
            {
                //TODO damage amt based off type of bullet
                AddWindowDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet);
                return;
            }
        }

        if (Layer.LayerType == LayerType.Grills)
        {
            //Make sure a window is not protecting it first:
            if (!metaTileMap.HasTile(cellPos, LayerType.Windows, true))
            {
                if (metaTileMap.HasTile(cellPos, LayerType.Grills, true))
                {
                    //TODO damage amt based off type of bullet
                    AddGrillDamage(bullet.damage, data, cellPos, bulletHitTarget, AttackType.Bullet);
                }
            }
        }
        if (bullet.isMiningBullet)
        {
            if (Layer.LayerType == LayerType.Walls)
            {
                LayerTile getTile = metaTileMap.GetTile(cellPos, LayerType.Walls);
                if (getTile != null)
                {
                    if (Validations.IsMineableAt(bulletHitTarget, metaTileMap))
                    {
                        SoundManager.PlayNetworkedAtPos("BreakStone", bulletHitTarget);
                        var tile = getTile as BasicTile;
                        Spawn.ServerPrefab(tile.SpawnOnDeconstruct, bulletHitTarget, count: tile.SpawnAmountOnDeconstruct);
                        tileChangeManager.RemoveTile(cellPos, LayerType.Walls);
                    }
                }
            }
        }
    }
Exemplo n.º 21
0
        private void OnWillDestroyServer(DestructionInfo info)
        {
            var tileWorldPosition = gameObject.TileWorldPosition().To3Int();
            //release all of our gases at once when destroyed
            MetaDataLayer metaDataLayer  = MatrixManager.AtPoint(tileWorldPosition, true).MetaDataLayer;
            Vector3Int    position       = transform.localPosition.RoundToInt();
            MetaDataNode  node           = metaDataLayer.Get(position, false);
            var           shakeIntensity = (byte)Mathf.Lerp(byte.MinValue, byte.MaxValue / 2, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);
            var           shakeDistance  = Mathf.Lerp(1, 64, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);

            node.GasMix += GasMix;
            metaDataLayer.UpdateSystemsAt(position);
            Chat.AddLocalMsgToChat($"{name} exploded!", gameObject.TileWorldPosition());

            ObjectFactory.SpawnMetal(2, tileWorldPosition.To2Int(), parent: transform.parent);

            ExplosionUtils.PlaySoundAndShake(tileWorldPosition, shakeIntensity, (int)shakeDistance);
        }
Exemplo n.º 22
0
        private void OnWillDestroyServer(DestructionInfo info)
        {
            var tileWorldPosition = gameObject.TileWorldPosition().To3Int();
            //release all of our gases at once when destroyed
            MetaDataLayer metaDataLayer  = MatrixManager.AtPoint(tileWorldPosition, true).MetaDataLayer;
            Vector3Int    position       = transform.localPosition.RoundToInt();
            MetaDataNode  node           = metaDataLayer.Get(position, false);
            var           shakeIntensity = (byte)Mathf.Lerp(byte.MinValue, byte.MaxValue / 2, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);
            var           shakeDistance  = Mathf.Lerp(1, 64, GasMix.Pressure / MAX_EXPLOSION_EFFECT_PRESSURE);

            node.GasMix += GasMix;
            metaDataLayer.UpdateSystemsAt(position);
            Chat.AddLocalDestroyMsgToChat(gameObject.ExpensiveName(), " exploded!", gameObject.TileWorldPosition());

            Spawn.ServerPrefab("Metal", gameObject.TileWorldPosition().To3Int(), transform.parent, count: 2,
                               scatterRadius: Spawn.DefaultScatterRadius, cancelIfImpassable: true);

            ExplosionUtils.PlaySoundAndShake(tileWorldPosition, shakeIntensity, (int)shakeDistance);
        }
Exemplo n.º 23
0
    public void ExposeHotspot(Vector3Int position, float temperature, float volume)
    {
        if (hotspots.ContainsKey(position) && hotspots[position].Hotspot != null)
        {
            // TODO soh?
            hotspots[position].Hotspot.UpdateValues(volume * 25, temperature);
        }
        else
        {
            MetaDataNode node   = metaDataLayer.Get(position);
            GasMix       gasMix = node.Atmos;

            if (gasMix.GetMoles(Gas.Plasma) > 0.5 && gasMix.GetMoles(Gas.Oxygen) > 0.5 && temperature > Reactions.PLASMA_MINIMUM_BURN_TEMPERATURE)
            {
                // igniting
                Hotspot hotspot = new Hotspot(node, temperature, volume * 25);
                node.Hotspot       = hotspot;
                hotspots[position] = node;
            }
        }
    }
Exemplo n.º 24
0
        private IEnumerator Breathe()
        {
            while (!health.IsDead)
            {
                MetaDataLayer metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position)).MetaDataLayer;

                GasMix atmos           = metaDataLayer.Get(transform.localPosition.RoundToInt(), false).Atmos;
                float  partialPressure = atmos.GetPressure(Gas.Oxygen);

                if (partialPressure < AtmosConstants.MINIMUM_OXYGEN_PRESSURE)
                {
                    float ratio = 1 - partialPressure / AtmosConstants.MINIMUM_OXYGEN_PRESSURE;
                    Logger.Log("URGENT TODO: Move this to LivingHealthBehaviour Respiratory system ", Category.Health);
                    //health.ApplyDamage(null, Mathf.Min(5 * ratio, 3), DamageType.Oxy);
                }
                else
                {
                    // TODO implement breathing (remove oxygen, add co2, etc.)
                }

                yield return(new WaitForSeconds(breathTime));
            }
        }
Exemplo n.º 25
0
        public void OnSpawnServer(SpawnInfo info)
        {
            var integrity = GetComponent <Integrity>();

            integrity.OnExposedEvent.AddListener(SendCloseAlerts);
            AtmosManager.Instance.inGameFireAlarms.Add(this);
            RegisterTile  registerTile  = GetComponent <RegisterTile>();
            MetaDataLayer metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
            var           wallMount     = GetComponent <WallmountBehavior>();
            var           direction     = wallMount.CalculateFacing().CutToInt();

            metaNode = metaDataLayer.Get(registerTile.LocalPositionServer + direction, false);
            foreach (var firelock in FireLockList)
            {
                firelock.fireAlarm = this;
            }
            if (!info.SpawnItems)
            {
                hasCables = false;
                coverOpen = true;
                stateSync = FireAlarmState.OpenEmptySprite;
            }
        }
Exemplo n.º 26
0
        private void CheckRelease()
        {
            if (Opened)
            {
                MetaDataLayer metaDataLayer = MatrixManager.AtPoint(Vector3Int.RoundToInt(transform.position)).MetaDataLayer;

                Vector3Int   position = transform.localPosition.RoundToInt();
                MetaDataNode node     = metaDataLayer.Get(position, false);

                float deltaPressure = Mathf.Min(GasMix.Pressure, ReleasePressure) - node.Atmos.Pressure;

                if (deltaPressure > 0)
                {
                    float ratio = deltaPressure / GasMix.Pressure * Time.deltaTime;

                    node.Atmos += GasMix * ratio;

                    GasMix *= (1 - ratio);

                    metaDataLayer.UpdateSystemsAt(position);
                }
            }
        }
Exemplo n.º 27
0
        private void Start()
        {
            MetaDataLayer metaDataLayer = GetComponentInParent <MetaDataLayer>();

            metaNode = metaDataLayer.Get(transform.localPosition.RoundToInt());
        }
Exemplo n.º 28
0
 private void LoadTurf()
 {
     metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
     metaNode      = metaDataLayer.Get(registerTile.WorldPositionServer, false);
 }
Exemplo n.º 29
0
 public void OnSpawnServer(SpawnInfo info)
 {
     metaDataLayer = MatrixManager.AtPoint(registerTile.WorldPositionServer, true).MetaDataLayer;
     metaNode      = metaDataLayer.Get(registerTile.LocalPositionServer, false);
 }
Exemplo n.º 30
0
 public bool IsSpaceAt(Vector3Int position)
 {
     return(metaDataLayer.Get(position).IsSpace());
 }