public void RemoveProducer(IMyPowerProducer producer)
        {
            Debug.Assert(producer != null);
            Debug.Assert(GetProducers(producer.Group).Contains(producer));

            GetProducers(producer.Group).Remove(producer);
            --m_producerCount;
            m_needsRecompute                      = true;
            m_remainingFuelTimeDirty              = true;
            producer.MaxPowerOutputChanged       -= producer_MaxPowerOutputChanged;
            producer.HasCapacityRemainingChanged -= producer_HasRemainingCapacityChanged;
            if (m_producerCount == 0)
            {
                m_producersEnabled = MyMultipleEnabledEnum.NoObjects;
            }
            else if (m_producerCount == 1)
            {
                ChangeProducersState((GetFirstProducer().Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled, MySession.LocalPlayerId);
            }
            else if (ProducersEnabled == MyMultipleEnabledEnum.Mixed)
            {
                // We were in mixed state and need to check whether we still are.
                m_producersEnabledDirty = true;
            }
        }
 public MyGridReflectorLightSystem(MyCubeGrid grid)
 {
     m_reflectors = new HashSet<MyReflectorLight>();
     m_reflectorsEnabled = MyMultipleEnabledEnum.NoObjects;
     m_grid = grid;
     m_grid.SyncObject.ReflectorStateChanged += SyncObject_ReflectorStateChanged;
 }
        private void RefreshProducersEnabled()
        {
            ProfilerShort.Begin("MyPowerDistributor.RefreshProducersEnabled");
            m_producersEnabledDirty = false;
            // Simplest method for now. If it takes too long at some point, we can change it.

            if (m_producerCount == 0)
            {
                m_producersEnabled = MyMultipleEnabledEnum.NoObjects;
                ProfilerShort.End();
                return;
            }

            bool allOn  = true;
            bool allOff = true;

            foreach (var group in m_producersByPriority)
            {
                foreach (var producer in group)
                {
                    allOn  = allOn && producer.Enabled;
                    allOff = allOff && !producer.Enabled;
                    if (!allOn && !allOff)
                    {
                        m_producersEnabled = MyMultipleEnabledEnum.Mixed;
                        ProfilerShort.End();
                        return;
                    }
                }
            }
            m_producersEnabled = (allOn) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
            ProfilerShort.End();
        }
        public void AddProducer(IMyPowerProducer producer)
        {
            Debug.Assert(producer != null);
            Debug.Assert(!GetProducers(producer.Group).Contains(producer));
            Debug.Assert(MatchesInfiniteCapacity(GetProducers(producer.Group), producer),
                         "All producers in the same group must have same 'infinite capacity' state.");
            if (GetProducers(producer.Group).Contains(producer))
            {
                return;
            }

            GetProducers(producer.Group).Add(producer);
            ++m_producerCount;
            m_needsRecompute                      = true;
            m_remainingFuelTimeDirty              = true;
            producer.HasCapacityRemainingChanged += producer_HasRemainingCapacityChanged;
            producer.MaxPowerOutputChanged       += producer_MaxPowerOutputChanged;
            if (m_producerCount == 1)
            {
                // This is the only producer we have, so the state of all is the same as of this one.
                m_producersEnabled = (producer.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
            }
            else if ((ProducersEnabled == MyMultipleEnabledEnum.AllEnabled && !producer.Enabled) ||
                     (ProducersEnabled == MyMultipleEnabledEnum.AllDisabled && producer.Enabled))
            {
                m_producersEnabled = MyMultipleEnabledEnum.Mixed;
            }
        }
        public void ChangeProducersState(MyMultipleEnabledEnum state, long playerId)
        {
            MyDebug.AssertDebug(state != MyMultipleEnabledEnum.Mixed, "You must NOT use this property to set mixed state.");
            MyDebug.AssertDebug(state != MyMultipleEnabledEnum.NoObjects, "You must NOT use this property to set state without any objects.");
            // You cannot change the state when there are no objects.
            if (ProducersEnabled != state && ProducersEnabled != MyMultipleEnabledEnum.NoObjects)
            {
                m_producersEnabled = state;
                bool enabled = (state == MyMultipleEnabledEnum.AllEnabled);
                foreach (var group in m_producersByPriority)
                {
                    foreach (var producer in group)
                    {
                        if (producer.HasPlayerAccess(playerId))
                        {
                            producer.MaxPowerOutputChanged -= producer_MaxPowerOutputChanged;
                            producer.Enabled = enabled;
                            producer.MaxPowerOutputChanged += producer_MaxPowerOutputChanged;
                        }
                    }
                }

                // recomputing power distribution here caused problems with
                // connecting to ship connector. The bug caused immediate disconnect
                // in only special cases.

                //RecomputePowerDistribution();
                m_producersEnabledDirty = false;
                m_needsRecompute        = true;
            }
        }
 public MyGridReflectorLightSystem(MyCubeGrid grid)
 {
     m_reflectors        = new HashSet <MyReflectorLight>();
     m_reflectorsEnabled = MyMultipleEnabledEnum.NoObjects;
     m_grid = grid;
     m_grid.SyncObject.ReflectorStateChanged += SyncObject_ReflectorStateChanged;
 }
 public void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState, long playerId)
 {
     // Include the batteries for total power shutdown
     foreach (var block in CubeGrid.GetBlocks())
     {
         if (block.FatBlock is MyBatteryBlock)
         {
             ((MyBatteryBlock)block.FatBlock).Enabled = enabledState == MyMultipleEnabledEnum.AllEnabled ? true : false;
         }
     }
     ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
 }
        public void ReflectorStateChanged(MyMultipleEnabledEnum enabledState)
        {
            m_reflectorsEnabled = enabledState;
            bool enabled = (enabledState == MyMultipleEnabledEnum.AllEnabled);
            foreach (var reflector in m_reflectors)
            {
                reflector.EnabledChanged -= reflector_EnabledChanged;
                reflector.Enabled = enabled;
                reflector.EnabledChanged += reflector_EnabledChanged;
            }

            m_reflectorsEnabledNeedsRefresh = false;
        }
        private void SyncObject_ReflectorStateChanged(MyMultipleEnabledEnum enabledState)
        {
            m_reflectorsEnabled = enabledState;
            bool enabled = (enabledState == MyMultipleEnabledEnum.AllEnabled);

            foreach (var reflector in m_reflectors)
            {
                reflector.EnabledChanged -= reflector_EnabledChanged;
                reflector.Enabled         = enabled;
                reflector.EnabledChanged += reflector_EnabledChanged;
            }

            m_reflectorsEnabledNeedsRefresh = false;
        }
 public void Register(MyReflectorLight reflector)
 {
     Debug.Assert(!m_reflectors.Contains(reflector), "Reflector is already registered in the grid.");
     m_reflectors.Add(reflector);
     reflector.EnabledChanged += reflector_EnabledChanged;
     if (m_reflectors.Count == 1)
     {
         m_reflectorsEnabled = (reflector.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
     }
     else if ((ReflectorsEnabled == MyMultipleEnabledEnum.AllEnabled && !reflector.Enabled) ||
              (ReflectorsEnabled == MyMultipleEnabledEnum.AllDisabled && reflector.Enabled))
     {
         m_reflectorsEnabled = MyMultipleEnabledEnum.Mixed;
     }
 }
 public void Register(MyReflectorLight reflector)
 {
     Debug.Assert(!m_reflectors.Contains(reflector), "Reflector is already registered in the grid.");
     m_reflectors.Add(reflector);
     reflector.EnabledChanged += reflector_EnabledChanged;
     if (m_reflectors.Count == 1)
     {
         m_reflectorsEnabled = (reflector.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
     }
     else if ((ReflectorsEnabled == MyMultipleEnabledEnum.AllEnabled && !reflector.Enabled) ||
              (ReflectorsEnabled == MyMultipleEnabledEnum.AllDisabled && reflector.Enabled))
     {
         m_reflectorsEnabled = MyMultipleEnabledEnum.Mixed;
     }
 }
 public void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState, long playerId)
 {
     // Include the batteries for total power shutdown
     foreach (var block in CubeGrid.GetBlocks())
     {
         //GR: Do the same for solar panels too. Issue: solar panels are in SpaceEngineers assembly not Sanbox so cannot access them from here. Workaround is to get DisplayName.
         //Best solution would be to move GridSystem to SpaceEngineers. Also for this to work MySolarPanel is now a MyFunctionalBlock (can be toggled on /off).
         if (block != null && block.FatBlock != null && (block.FatBlock is MyBatteryBlock || block.FatBlock.DefinitionDisplayNameText.Equals("Solar Panel")))
         {
             ((MyFunctionalBlock)block.FatBlock).Enabled = enabledState == MyMultipleEnabledEnum.AllEnabled ? true : false;
         }
     }
     if (ResourceDistributor != null)
     {
         ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
     }
 }
 public void Unregister(MyReflectorLight reflector)
 {
     Debug.Assert(m_reflectors.Contains(reflector), "Removing reflector which was not registered.");
     m_reflectors.Remove(reflector);
     reflector.EnabledChanged -= reflector_EnabledChanged;
     if (m_reflectors.Count == 0)
     {
         m_reflectorsEnabled = MyMultipleEnabledEnum.NoObjects;
     }
     else if (m_reflectors.Count == 1)
     {
         ReflectorsEnabled = (m_reflectors.First().Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
     }
     else if (ReflectorsEnabled == MyMultipleEnabledEnum.Mixed)
     {
         // We were in mixed state and need to check whether we still are.
         m_reflectorsEnabledNeedsRefresh = true;
     }
 }
示例#14
0
 public void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState, long playerId)
 {
     if (Sync.IsServer)
     {
         foreach (MyCubeBlock block in this.CubeGrid.GetFatBlocks())
         {
             IMyPowerProducer producer = block as IMyPowerProducer;
             if ((producer != null) && (((playerId >= 0L) && ((MyFunctionalBlock)block).HasPlayerAccess(playerId)) || (playerId == -1L)))
             {
                 producer.Enabled = enabledState == MyMultipleEnabledEnum.AllEnabled;
             }
         }
     }
     if (this.ResourceDistributor != null)
     {
         this.ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
     }
     this.CubeGrid.ActivatePhysics();
 }
        public MyPowerDistributor()
        {
            m_consumerDataByPriority = new ConsumerGroupData[typeof(MyConsumerGroupEnum).GetEnumValues().Length];
            m_producerDataByPriority = new ProducerGroupData[typeof(MyProducerGroupEnum).GetEnumValues().Length];
            m_consumersByPriority    = new HashSet <IMyPowerConsumer> [m_consumerDataByPriority.Length];
            for (int i = 0; i < m_consumersByPriority.Length; ++i)
            {
                m_consumersByPriority[i] = new HashSet <IMyPowerConsumer>();
            }

            m_producersByPriority = new HashSet <IMyPowerProducer> [m_producerDataByPriority.Length];
            for (int i = 0; i < m_producerDataByPriority.Length; ++i)
            {
                m_producersByPriority[i] = new HashSet <IMyPowerProducer>();
            }

            m_needsRecompute         = true;
            m_remainingFuelTimeDirty = true;
            m_producersEnabled       = MyMultipleEnabledEnum.NoObjects;
        }
        private void RefreshReflectorsEnabled()
        {
            ProfilerShort.Begin("MyGridReflectorLightSystem.RefreshReflectorsEnabled");
            m_reflectorsEnabledNeedsRefresh = false;
            // Simplest method for now. If it takes too long at some point, we can change it.

            bool allOn  = true;
            bool allOff = true;

            foreach (var tmp in m_reflectors)
            {
                allOn  = allOn && tmp.Enabled;
                allOff = allOff && !tmp.Enabled;
                if (!allOn && !allOff)
                {
                    m_reflectorsEnabled = MyMultipleEnabledEnum.Mixed;
                    ProfilerShort.End();
                    return;
                }
            }
            ReflectorsEnabled = (allOn) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
            ProfilerShort.End();
        }
示例#17
0
 private void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState, long playerId)
 {
     ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
 }
示例#18
0
        public MyPowerDistributor()
        {
            m_consumerDataByPriority = new ConsumerGroupData[typeof(MyConsumerGroupEnum).GetEnumValues().Length];
            m_producerDataByPriority = new ProducerGroupData[typeof(MyProducerGroupEnum).GetEnumValues().Length];
            m_consumersByPriority = new HashSet<IMyPowerConsumer>[m_consumerDataByPriority.Length];
            for (int i = 0; i < m_consumersByPriority.Length; ++i)
                m_consumersByPriority[i] = new HashSet<IMyPowerConsumer>();

            m_producersByPriority = new HashSet<IMyPowerProducer>[m_producerDataByPriority.Length];
            for (int i = 0; i < m_producerDataByPriority.Length; ++i)
                m_producersByPriority[i] = new HashSet<IMyPowerProducer>();

            m_needsRecompute = true;
            m_remainingFuelTimeDirty = true;
            m_producersEnabled = MyMultipleEnabledEnum.NoObjects;
        }
        private void RefreshReflectorsEnabled()
        {
            ProfilerShort.Begin("MyGridReflectorLightSystem.RefreshReflectorsEnabled");
            m_reflectorsEnabledNeedsRefresh = false;
            // Simplest method for now. If it takes too long at some point, we can change it.

            bool allOn = true;
            bool allOff = true;
            foreach (var tmp in m_reflectors)
            {
                allOn = allOn && tmp.Enabled;
                allOff = allOff && !tmp.Enabled;
                if (!allOn && !allOff)
                {
                    m_reflectorsEnabled = MyMultipleEnabledEnum.Mixed;
                    ProfilerShort.End();
                    return;
                }
            }
            ReflectorsEnabled = (allOn) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
            ProfilerShort.End();
        }
 public MyGridReflectorLightSystem(MyCubeGrid grid)
 {
     m_reflectors = new HashSet<MyReflectorLight>();
     m_reflectorsEnabled = MyMultipleEnabledEnum.NoObjects;
     m_grid = grid;
 }
 private void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState, long playerId)
 {
     PowerDistributor.ChangeProducersState(enabledState, playerId);
 }
 private void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState,long playerId)
 {
     PowerDistributor.ChangeProducersState(enabledState, playerId);
 }
示例#23
0
        public void RemoveProducer(IMyPowerProducer producer)
        {
            Debug.Assert(producer != null);
            Debug.Assert(GetProducers(producer.Group).Contains(producer));

            GetProducers(producer.Group).Remove(producer);
            --m_producerCount;
            m_needsRecompute = true;
            m_remainingFuelTimeDirty = true;
            producer.MaxPowerOutputChanged -= producer_MaxPowerOutputChanged;
            producer.HasCapacityRemainingChanged -= producer_HasRemainingCapacityChanged;
            if (m_producerCount == 0)
            {
                m_producersEnabled = MyMultipleEnabledEnum.NoObjects;
            }
            else if (m_producerCount == 1)
            {
                ChangeProducersState((GetFirstProducer().Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled,MySession.LocalPlayerId);
            }
            else if (ProducersEnabled == MyMultipleEnabledEnum.Mixed)
            {
                // We were in mixed state and need to check whether we still are.
                m_producersEnabledDirty = true;
            }
        }
示例#24
0
        private void RefreshProducersEnabled()
        {
            ProfilerShort.Begin("MyPowerDistributor.RefreshProducersEnabled");
            m_producersEnabledDirty = false;
            // Simplest method for now. If it takes too long at some point, we can change it.

            if (m_producerCount == 0)
            {
                m_producersEnabled = MyMultipleEnabledEnum.NoObjects;
                ProfilerShort.End();
                return;
            }

            bool allOn = true;
            bool allOff = true;
            foreach (var group in m_producersByPriority)
            foreach (var producer in group)
            {
                allOn = allOn && producer.Enabled;
                allOff = allOff && !producer.Enabled;
                if (!allOn && !allOff)
                {
                    m_producersEnabled = MyMultipleEnabledEnum.Mixed;
                    ProfilerShort.End();
                    return;
                }
            }
            m_producersEnabled = (allOn) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
            ProfilerShort.End();
        }
 public void Unregister(MyReflectorLight reflector)
 {
     Debug.Assert(m_reflectors.Contains(reflector), "Removing reflector which was not registered.");
     m_reflectors.Remove(reflector);
     reflector.EnabledChanged -= reflector_EnabledChanged;
     if (m_reflectors.Count == 0)
     {
         m_reflectorsEnabled = MyMultipleEnabledEnum.NoObjects;
     }
     else if (m_reflectors.Count == 1)
     {
         ReflectorsEnabled = (m_reflectors.First().Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
     }
     else if (ReflectorsEnabled == MyMultipleEnabledEnum.Mixed)
     {
         // We were in mixed state and need to check whether we still are.
         m_reflectorsEnabledNeedsRefresh = true;
     }
 }
示例#26
0
 private void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState,long playerId)
 {
     ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
 }
示例#27
0
        public void ChangeProducersState(MyMultipleEnabledEnum state,long playerId)
        {
            MyDebug.AssertDebug(state != MyMultipleEnabledEnum.Mixed, "You must NOT use this property to set mixed state.");
            MyDebug.AssertDebug(state != MyMultipleEnabledEnum.NoObjects, "You must NOT use this property to set state without any objects.");
            // You cannot change the state when there are no objects.
            if (ProducersEnabled != state && ProducersEnabled != MyMultipleEnabledEnum.NoObjects)
            {
                m_producersEnabled = state;
                bool enabled = (state == MyMultipleEnabledEnum.AllEnabled);
                foreach (var group in m_producersByPriority)
                {
                    foreach (var producer in group)
                    {
                        if (producer.HasPlayerAccess(playerId))
                        {
                            producer.MaxPowerOutputChanged -= producer_MaxPowerOutputChanged;
                            producer.Enabled = enabled;
                            producer.MaxPowerOutputChanged += producer_MaxPowerOutputChanged;
                        }
                    }
                }

                // recomputing power distribution here caused problems with 
                // connecting to ship connector. The bug caused immediate disconnect
                // in only special cases.
                
                //RecomputePowerDistribution();
                m_producersEnabledDirty = false;
                m_needsRecompute = true;
				m_allEnabledCounter = 0;
            }
        }
示例#28
0
        public void SendPowerDistributorState(MyMultipleEnabledEnum enabledState, long playerId)
        {
            var msg = new PowerProducerStateMsg();
            msg.GridEntityId = Entity.EntityId;
            msg.Enabled = enabledState;
            msg.PlayerId = playerId;

            Sync.Layer.SendMessageToServer(ref msg);
        }
示例#29
0
        public void SendReflectorState(MyMultipleEnabledEnum enabledState)
        {
            var msg = new ReflectorsStateMsg();
            msg.GridEntityId = Entity.EntityId;
            msg.Enabled = enabledState;

            Sync.Layer.SendMessageToServer(ref msg);
        }
示例#30
0
 public MyGridReflectorLightSystem(MyCubeGrid grid)
 {
     m_reflectors        = new HashSet <MyReflectorLight>();
     m_reflectorsEnabled = MyMultipleEnabledEnum.NoObjects;
     m_grid = grid;
 }
		public void ChangeSourcesState(MyDefinitionId resourceTypeId, MyMultipleEnabledEnum state, long playerId)
		{
			MyDebug.AssertDebug(state != MyMultipleEnabledEnum.Mixed, "You must NOT use this property to set mixed state.");
			MyDebug.AssertDebug(state != MyMultipleEnabledEnum.NoObjects, "You must NOT use this property to set state without any objects.");
            int typeIndex;
            if (TryGetTypeIndex(resourceTypeId, out typeIndex) == false)
            {
                return;
            }
			// You cannot change the state when there are no objects.
			if (m_dataPerType[typeIndex].SourcesEnabled == state || m_dataPerType[typeIndex] .SourcesEnabled == MyMultipleEnabledEnum.NoObjects)
				return;

			m_dataPerType[typeIndex].SourcesEnabled = state;
			bool enabled = (state == MyMultipleEnabledEnum.AllEnabled);
			foreach (var group in m_dataPerType[typeIndex].SourcesByPriority)
			{
				foreach (var source in group)
				{
					source.MaxOutputChanged -= source_MaxOutputChanged;
				    source.ProductionEnabledChanged -= source_ProductionEnabledChanged;
					source.Enabled = enabled;
				    source.ProductionEnabledChanged += source_ProductionEnabledChanged;
					source.MaxOutputChanged += source_MaxOutputChanged;
				}
			}

			// recomputing power distribution here caused problems with 
			// connecting to ship connector. The bug caused immediate disconnect
			// in only special cases.

			//RecomputeResourceDistribution();
			m_dataPerType[typeIndex].SourcesEnabledDirty = false;
			m_dataPerType[typeIndex].NeedsRecompute = true;
			m_allEnabledCounter = 0;
		}
		public void ChangeSourcesState(MyDefinitionId resourceTypeId, MyMultipleEnabledEnum state, long playerId)
		{
			MyDebug.AssertDebug(state != MyMultipleEnabledEnum.Mixed, "You must NOT use this property to set mixed state.");
			MyDebug.AssertDebug(state != MyMultipleEnabledEnum.NoObjects, "You must NOT use this property to set state without any objects.");
            int typeIndex;
            if (TryGetTypeIndex(resourceTypeId, out typeIndex) == false)
            {
                return;
            }
			// You cannot change the state when there are no objects.
			if (m_dataPerType[typeIndex].SourcesEnabled == state || m_dataPerType[typeIndex] .SourcesEnabled == MyMultipleEnabledEnum.NoObjects)
				return;

			m_dataPerType[typeIndex].SourcesEnabled = state;
			bool enabled = (state == MyMultipleEnabledEnum.AllEnabled);
            IMyFaction faction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId);
			foreach (var group in m_dataPerType[typeIndex].SourcesByPriority)
			{
				foreach (var source in group)
				{
                    if (source.Entity != null)
                    {
                        MyFunctionalBlock fb = source.Entity as MyFunctionalBlock;
                        if (fb != null && fb.OwnerId != 0)
                        {
                            IMyFaction faction2 = MySession.Static.Factions.TryGetPlayerFaction(fb.OwnerId);
                            if (faction2 != null && MySession.Static.Factions.GetRelationBetweenFactions(faction1 != null ? faction1.FactionId : 0, faction2.FactionId) == MyRelationsBetweenFactions.Enemies)
                                continue;
                        }
                    }
					source.MaxOutputChanged -= source_MaxOutputChanged;
				    source.ProductionEnabledChanged -= source_ProductionEnabledChanged;
					source.Enabled = enabled;
				    source.ProductionEnabledChanged += source_ProductionEnabledChanged;
					source.MaxOutputChanged += source_MaxOutputChanged;
				}
			}

			// recomputing power distribution here caused problems with 
			// connecting to ship connector. The bug caused immediate disconnect
			// in only special cases.

			//RecomputeResourceDistribution();
			m_dataPerType[typeIndex].SourcesEnabledDirty = false;
			m_dataPerType[typeIndex].NeedsRecompute = true;
			m_allEnabledCounter = 0;
		}
示例#33
0
        public void AddProducer(IMyPowerProducer producer)
        {
            Debug.Assert(producer != null);
            Debug.Assert(!GetProducers(producer.Group).Contains(producer));
            Debug.Assert(MatchesInfiniteCapacity(GetProducers(producer.Group), producer),
                         "All producers in the same group must have same 'infinite capacity' state.");
            if (GetProducers(producer.Group).Contains(producer))
                return;

            GetProducers(producer.Group).Add(producer);
            ++m_producerCount;
            m_needsRecompute = true;
            m_remainingFuelTimeDirty = true;
            producer.HasCapacityRemainingChanged += producer_HasRemainingCapacityChanged;
            producer.MaxPowerOutputChanged += producer_MaxPowerOutputChanged;
            if (m_producerCount == 1)
            {
                // This is the only producer we have, so the state of all is the same as of this one.
                m_producersEnabled = (producer.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
            }
            else if ((ProducersEnabled == MyMultipleEnabledEnum.AllEnabled && !producer.Enabled) ||
                     (ProducersEnabled == MyMultipleEnabledEnum.AllDisabled && producer.Enabled))
            {
                m_producersEnabled = MyMultipleEnabledEnum.Mixed;
            }
        }
示例#34
0
 public void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState,long playerId)
 {
     // Include the batteries for total power shutdown
     foreach (var block in CubeGrid.GetBlocks())
     {
         if (block != null && block.FatBlock is MyBatteryBlock)
         {
             ((MyBatteryBlock)block.FatBlock).Enabled = enabledState == MyMultipleEnabledEnum.AllEnabled ? true : false;
         }
     }
     if (ResourceDistributor != null)
     {
         ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
     }
 }
 public void SyncObject_PowerProducerStateChanged(MyMultipleEnabledEnum enabledState,long playerId)
 {
     // Include the batteries for total power shutdown
     foreach (var block in CubeGrid.GetBlocks())
     {
         //GR: Do the same for solar panels too. Issue: solar panels are in SpaceEngineers assembly not Sanbox so cannot access them from here. Workaround is to get DisplayName.
         //Best solution would be to move GridSystem to SpaceEngineers. Also for this to work MySolarPanel is now a MyFunctionalBlock (can be toggled on /off).
         if (block != null && block.FatBlock != null && (block.FatBlock is MyBatteryBlock || block.FatBlock.DefinitionDisplayNameText.Equals("Solar Panel")))
         {
             ((MyFunctionalBlock)block.FatBlock).Enabled = enabledState == MyMultipleEnabledEnum.AllEnabled ? true : false;
         }
     }
     if (ResourceDistributor != null)
     {
         ResourceDistributor.ChangeSourcesState(MyResourceDistributorComponent.ElectricityId, enabledState, playerId);
     }
 }