public MySolarPanel()
	    {
            SourceComp = new MyResourceSourceComponent();

            m_soundEmitter = new MyEntity3DSoundEmitter(this, true);
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;
	    }
Esempio n. 2
0
	    public MyGasTank()
	    {
            CreateTerminalControls();

			SourceComp = new MyResourceSourceComponent();
			ResourceSink = new MyResourceSinkComponent(2);
	    }
Esempio n. 3
0
        public MyBattery(MyCharacter owner)
        {
            m_owner = owner;
            SyncObject = new MySyncBattery(this);
			ResourceSink = new MyResourceSinkComponent();
			ResourceSource = new MyResourceSourceComponent();
        }
Esempio n. 4
0
        public MyReactor()
        {
            CreateTerminalControls();

			SourceComp = new MyResourceSourceComponent();
            m_remainingPowerCapacity.ValueChanged += (x) => RemainingCapacityChanged();
            m_remainingPowerCapacity.ValidateNever();
        }
 public MyGasGenerator()
 {
     #if XB1 // XB1_SYNC_NOREFLECTION
     m_useConveyorSystem = SyncType.CreateAndAddProp<bool>();
     #endif // XB1
     CreateTerminalControls();
     SourceComp = new MyResourceSourceComponent(2);
     ResourceSink = new MyResourceSinkComponent();
 }
            public MyPhysicalDistributionGroup(MyDefinitionId typeId, MyResourceSourceComponent tempConnectedSource)
            {
                SinksByPriority = null; SourcesByPriority = null; SinkSourcePairs = null; FirstEndpoint = null;
                SinkDataByPriority = null; SourceDataByPriority = null; StockpilingStorage = null; OtherStorage = null;
                InputOutputData = new MyTuple<MySinkGroupData, MySourceGroupData>();
                MaxAvailableResources = 0f; ResourceState = MyResourceStateEnum.NoPower;
                AllocateData();

                InitFromTempConnected(typeId, tempConnectedSource);
            }
        public MyAirVent()
        {
            #if XB1 // XB1_SYNC_NOREFLECTION
            m_isDepressurizing = SyncType.CreateAndAddProp<bool>();
            #endif // XB1
            CreateTerminalControls();

            ResourceSink = new MyResourceSinkComponent(2);
            SourceComp = new MyResourceSourceComponent();
            m_isDepressurizing.ValueChanged += (x) => SetDepressurizing();
        }
Esempio n. 8
0
        public MyReactor()
        {
#if XB1 // XB1_SYNC_NOREFLECTION
            m_remainingPowerCapacity = SyncType.CreateAndAddProp<float>();
            m_useConveyorSystem = SyncType.CreateAndAddProp<bool>();
#endif // XB1
            CreateTerminalControls();

			SourceComp = new MyResourceSourceComponent();
            m_remainingPowerCapacity.ValueChanged += (x) => RemainingCapacityChanged();
            m_remainingPowerCapacity.ValidateNever();
        }
        private void RemoveSourceLazy(MyResourceSourceComponent source)
        {
            foreach (var resourceTypeId in source.ResourceTypes)
		    {
                MyDefinitionId typeId = resourceTypeId;
			    var sourcesOfType = GetSourcesOfType(ref typeId, source.Group);
                if (sourcesOfType == null)
                {
                    Debug.Fail("SourcesOfType is null on removal of " + typeId.ToString());
                    continue;
                }
			    var typeIndex = GetTypeIndex(ref typeId);

                if (!sourcesOfType.Remove(source))
                {
                    int foundIndex = -1;
                    for (int pairIndex = 0; pairIndex < m_dataPerType[typeIndex].InputOutputList.Count; ++pairIndex)
                    {
                        if (m_dataPerType[typeIndex].InputOutputList[pairIndex].Item2 != source)
                            continue;

                        foundIndex = pairIndex;
                        break;
                    }

                    if (foundIndex != -1)
                    {
                        var matchingSink = m_dataPerType[typeIndex].InputOutputList[foundIndex].Item1;
                        m_dataPerType[typeIndex].InputOutputList.RemoveAtFast(foundIndex);
                        m_dataPerType[typeIndex].SinksByPriority[GetPriority(matchingSink)].Add(matchingSink);
                    }
                }

			    m_dataPerType[typeIndex].NeedsRecompute = true;
                m_dataPerType[typeIndex].GroupsDirty = true;

			    --m_dataPerType[typeIndex].SourceCount;
				if (m_dataPerType[typeIndex].SourceCount == 0)
				{
					m_dataPerType[typeIndex].SourcesEnabled= MyMultipleEnabledEnum.NoObjects;
				}
				else if (m_dataPerType[typeIndex].SourceCount== 1)
				{
				    var firstSourceOfType = GetFirstSourceOfType(ref typeId);
                    if (firstSourceOfType != null)
                        ChangeSourcesState(typeId, (firstSourceOfType.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled, MySession.Static.LocalPlayerId);
                    else
                    {
                        // Bug Fix - When battery is on grid it somehow leaves Sources = 1 even tought that no sources are present
                        --m_dataPerType[typeIndex].SourceCount;
                        m_dataPerType[typeIndex].SourcesEnabled = MyMultipleEnabledEnum.NoObjects;
                    }
				}
				else if (m_dataPerType[typeIndex].SourcesEnabled == MyMultipleEnabledEnum.Mixed)
				{
					// We were in mixed state and need to check whether we still are.
					m_dataPerType[typeIndex].SourcesEnabledDirty = true;
				}
				m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
		    }
	        source.ProductionEnabledChanged -= source_ProductionEnabledChanged;
		    source.MaxOutputChanged -= source_MaxOutputChanged;
		    source.HasCapacityRemainingChanged -= source_HasRemainingCapacityChanged;
        }
        private void AddSourceLazy(MyResourceSourceComponent source)
        {
            foreach (var resourceType in source.ResourceTypes)
		    {
                var typeId = resourceType;
				if(!m_initializedTypes.Contains(typeId))
					InitializeNewType(ref typeId);

			    var sourcesOfType = GetSourcesOfType(ref typeId, source.Group);
                if (sourcesOfType == null)
                {
                    Debug.Fail("SourcesOfType is null on add of " + typeId.ToString());
                    continue;
                }
			    int typeIndex = GetTypeIndex(ref typeId);
				Debug.Assert(!sourcesOfType.Contains(source));
				Debug.Assert(MatchesInfiniteCapacity(sourcesOfType, source), "All producers in the same group must have same 'infinite capacity' state.");

                MyResourceSinkComponent matchingSink = null;
                if (source.Container != null)
                {
                    foreach (var sinks in m_dataPerType[typeIndex].SinksByPriority)
                    {
                        foreach (var sink in sinks)
                        {
                            if (sink.Container == null)
                                continue;

                            var sourceInContainer = sink.Container.Get<MyResourceSourceComponent>();
                            if (sourceInContainer == source)
                            {
                                m_dataPerType[typeIndex].InputOutputList.Add(MyTuple.Create(sink, source));
                                matchingSink = sink;
                                break;
                            }
                        }
                        if (matchingSink == null)
                            continue;

                        sinks.Remove(matchingSink);
                        break;
                    }
                }

                if (matchingSink == null)
				    sourcesOfType.Add(source);

			    m_dataPerType[typeIndex].NeedsRecompute = true;
                m_dataPerType[typeIndex].GroupsDirty = true;
			    ++m_dataPerType[typeIndex].SourceCount;

				if (m_dataPerType[typeIndex].SourceCount == 1)
				{
					// This is the only source we have, so the state of all is the same as of this one.
					m_dataPerType[typeIndex].SourcesEnabled = (source.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled;
				}
				else if ((m_dataPerType[typeIndex].SourcesEnabled == MyMultipleEnabledEnum.AllEnabled && !source.Enabled) || (m_dataPerType[typeIndex].SourcesEnabled == MyMultipleEnabledEnum.AllDisabled && source.Enabled))
				{
					m_dataPerType[typeIndex].SourcesEnabled = MyMultipleEnabledEnum.Mixed;
				}
			    m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
		    }
		    source.HasCapacityRemainingChanged += source_HasRemainingCapacityChanged;
		    source.MaxOutputChanged += source_MaxOutputChanged;
	        source.ProductionEnabledChanged += source_ProductionEnabledChanged;
        }
Esempio n. 11
0
        public MyReactor()
        {
            m_soundEmitter = new MyEntity3DSoundEmitter(this);
			SourceComp = new MyResourceSourceComponent();
        }
        private void source_ProductionEnabledChanged(MyDefinitionId changedResourceTypeId, MyResourceSourceComponent obj)
        {
            int typeIndex = GetTypeIndex(ref changedResourceTypeId);
            m_dataPerType[typeIndex].NeedsRecompute = true;
            m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
            m_dataPerType[typeIndex].SourcesEnabledDirty = true;

            if (m_dataPerType[typeIndex].SourceCount == 1)
                RecomputeResourceDistribution(ref changedResourceTypeId);
        }
	    public void RemoveSource(MyResourceSourceComponent source)
	    {
		    Debug.Assert(source != null);

            lock (m_sourcesToAdd)
            {
                if (m_sourcesToAdd.Contains(source))
                {
                    m_sourcesToAdd.Remove(source);
                    RemoveTypesFromChanges(source.ResourceTypes);
                    return;
                }
            }

            lock (m_sourcesToRemove)
            {
                m_sourcesToRemove.Add(source);
            }

            foreach (var resourceType in source.ResourceTypes)
            {
                int existingCount;
                if (!m_changedTypes.TryGetValue(resourceType, out existingCount))
                    m_changedTypes.Add(resourceType, 1);
                else
                    m_changedTypes[resourceType] = existingCount+1;
            }
	    }
		static internal int GetPriority(MyResourceSourceComponent source)
		{
			return m_sourceSubtypeToPriority[source.Group];
		}
	    private void source_HasRemainingCapacityChanged(MyDefinitionId changedResourceTypeId, MyResourceSourceComponent source)
	    {
		    int typeIndex = GetTypeIndex(ref changedResourceTypeId);
			m_dataPerType[typeIndex].NeedsRecompute = true;
			m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
	    }
Esempio n. 16
0
        public MyBatteryBlock()
        {
#if XB1 // XB1_SYNC_NOREFLECTION
            m_isFull = SyncType.CreateAndAddProp<bool>();
            m_onlyRecharge = SyncType.CreateAndAddProp<bool>();
            m_onlyDischarge = SyncType.CreateAndAddProp<bool>();
            m_semiautoEnabled = SyncType.CreateAndAddProp<bool>();
            m_producerEnabled = SyncType.CreateAndAddProp<bool>();
            m_storedPower = SyncType.CreateAndAddProp<float>();
#endif // XB1
            CreateTerminalControls();

            SourceComp = new MyResourceSourceComponent();
            ResourceSink = new MyResourceSinkComponent();
            m_semiautoEnabled.ValueChanged += (x) => UpdateMaxOutputAndEmissivity();
            m_onlyRecharge.ValueChanged += (x) => { if (m_onlyRecharge.Value) m_onlyDischarge.Value = false; UpdateMaxOutputAndEmissivity(); };
            m_onlyDischarge.ValueChanged += (x) => { if (m_onlyDischarge.Value) m_onlyRecharge.Value = false; UpdateMaxOutputAndEmissivity(); };

            m_producerEnabled.ValueChanged += (x) => ProducerEnadChanged();
            m_storedPower.ValueChanged += (x) => CapacityChanged();
	    }
	    private bool MatchesInfiniteCapacity(HashSet<MyResourceSourceComponent> group, MyResourceSourceComponent producer)
	    {
		    foreach (MyResourceSourceComponent source in group)
		    {
			    if (producer.IsInfiniteCapacity != source.IsInfiniteCapacity)
				    return false;
		    }
		    return true;
	    }
Esempio n. 18
0
        public MyAirVent()
        {
            CreateTerminalControls();

            ResourceSink = new MyResourceSinkComponent(2);
            SourceComp = new MyResourceSourceComponent();
            m_isDepressurizing.ValueChanged += (x) => SetDepressurizing();
        }
Esempio n. 19
0
        public MyBatteryBlock()
        {
            CreateTerminalControls();

            SourceComp = new MyResourceSourceComponent();
            ResourceSink = new MyResourceSinkComponent();
            m_semiautoEnabled.ValueChanged += (x) => UpdateMaxOutputAndEmissivity();
            m_onlyRecharge.ValueChanged += (x) => { if (m_onlyRecharge.Value) m_onlyDischarge.Value = false; UpdateMaxOutputAndEmissivity(); };
            m_onlyDischarge.ValueChanged += (x) => { if (m_onlyDischarge.Value) m_onlyRecharge.Value = false; UpdateMaxOutputAndEmissivity(); };

            m_producerEnabled.ValueChanged += (x) => ProducerEnadChanged();
            m_storedPower.ValueChanged += (x) => CapacityChanged();
	    }
        private void Source_CurrentOutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source)
        {
            int typeIndex;
            if (!TryGetTypeIndex(ref changedResourceId, out typeIndex))
                return;

            float timeSinceLastOutputSeconds = (MySession.Static.GameplayFrameCounter - m_storedGases[typeIndex].LastOutputTime) * VRage.Game.MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
            m_storedGases[typeIndex].LastOutputTime = MySession.Static.GameplayFrameCounter;
            float outputAmount = oldOutput*timeSinceLastOutputSeconds;

            m_storedGases[typeIndex].NextGasTransfer -= outputAmount;
        }
Esempio n. 21
0
		private void Source_OnOutputChanged(MyDefinitionId resourceTypeId, float oldOutput, MyResourceSourceComponent source)
	    {
			UpdateText();
            if ((SoundEmitter != null) && (SoundEmitter.Sound != null) && (SoundEmitter.Sound.IsPlaying))
			{
				if (SourceComp.MaxOutput != 0f)
				{
					float semitones = 4f * (SourceComp.CurrentOutput - 0.5f * SourceComp.MaxOutput) / SourceComp.MaxOutput;
					SoundEmitter.Sound.FrequencyRatio = MyAudio.Static.SemitonesToFrequencyRatio(semitones);
				}
				else
					SoundEmitter.Sound.FrequencyRatio = 1f;
			}
	    }
	    public void RemoveSource(MyResourceSourceComponent source)
	    {
		    Debug.Assert(source != null);

		    foreach (var typeId in source.ResourceTypes)
		    {
			    var sourcesOfType = GetSourcesOfType(typeId, source.Group);
			    var typeIndex = GetTypeIndex(typeId);

                if (!sourcesOfType.Remove(source))
                {
                    int foundIndex = -1;
                    for (int pairIndex = 0; pairIndex < m_dataPerType[typeIndex].InputOutputList.Count; ++pairIndex)
                    {
                        if (m_dataPerType[typeIndex].InputOutputList[pairIndex].Item2 != source)
                            continue;

                        foundIndex = pairIndex;
                        break;
                    }

                    if (foundIndex != -1)
                    {
                        var matchingSink = m_dataPerType[typeIndex].InputOutputList[foundIndex].Item1;
                        m_dataPerType[typeIndex].InputOutputList.RemoveAtFast(foundIndex);
                        m_dataPerType[typeIndex].SinksByPriority[GetPriority(matchingSink)].Add(matchingSink);
                    }
                }

			    m_dataPerType[typeIndex].NeedsRecompute = true;

			    --m_dataPerType[typeIndex].SourceCount;
				if (m_dataPerType[typeIndex].SourceCount == 0)
				{
					m_dataPerType[typeIndex].SourcesEnabled= MyMultipleEnabledEnum.NoObjects;
				}
				else if (m_dataPerType[typeIndex].SourceCount== 1)
				{
				    var firstSourceOfType = GetFirstSourceOfType(typeId);
                    if(firstSourceOfType != null)
					    ChangeSourcesState(typeId, (firstSourceOfType.Enabled) ? MyMultipleEnabledEnum.AllEnabled : MyMultipleEnabledEnum.AllDisabled, MySession.LocalPlayerId);
				}
				else if (m_dataPerType[typeIndex].SourcesEnabled == MyMultipleEnabledEnum.Mixed)
				{
					// We were in mixed state and need to check whether we still are.
					m_dataPerType[typeIndex].SourcesEnabledDirty = true;
				}
				m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
		    }
	        source.ProductionEnabledChanged -= source_ProductionEnabledChanged;
		    source.MaxOutputChanged -= source_MaxOutputChanged;
		    source.HasCapacityRemainingChanged -= source_HasRemainingCapacityChanged;
		    
	    }
	    private void source_MaxOutputChanged(MyDefinitionId changedResourceTypeId, float oldOutput, MyResourceSourceComponent obj)
	    {
			int typeIndex = GetTypeIndex(changedResourceTypeId);
		    m_dataPerType[typeIndex].NeedsRecompute = true;
		    m_dataPerType[typeIndex].RemainingFuelTimeDirty = true;
		    m_dataPerType[typeIndex].SourcesEnabledDirty = true;

		    // Don't wait for next update with few sources.
		    // Also ensures that when character enters cockpit, his battery is
		    // turned off right away without waiting for update.
		    if (m_dataPerType[typeIndex].SourceCount == 1)
			    RecomputeResourceDistribution(changedResourceTypeId);
	    }
Esempio n. 24
0
	    public MySolarPanel()
	    {
            SourceComp = new MyResourceSourceComponent();
	    }
        private void SetGasSource(MyResourceSourceComponent characterSourceComponent)
        {
            foreach (var gasInfo in m_storedGases)
            {
                gasInfo.LastOutputTime = MySession.Static.GameplayFrameCounter;
                if (m_characterGasSource != null)
                {
                    m_characterGasSource.SetRemainingCapacityByType(gasInfo.Id, 0);

                    if(Sync.IsServer)
                        m_characterGasSource.OutputChanged -= Source_CurrentOutputChanged;
                }

                if (characterSourceComponent != null)
                {
                    characterSourceComponent.SetRemainingCapacityByType(gasInfo.Id, gasInfo.FillLevel*gasInfo.MaxCapacity);
                    characterSourceComponent.SetProductionEnabledByType(gasInfo.Id, gasInfo.FillLevel > 0);
                    if(Sync.IsServer)
                        characterSourceComponent.OutputChanged += Source_CurrentOutputChanged;
                }
            }
            m_characterGasSource = characterSourceComponent;
        }
            public void InitFromTempConnected(MyDefinitionId typeId, MyResourceSourceComponent tempConnectedSource)
            {
                var conveyorEndPointBlock = tempConnectedSource.TemporaryConnectedEntity as IMyConveyorEndpointBlock;
                if (conveyorEndPointBlock != null)
                    FirstEndpoint = conveyorEndPointBlock.ConveyorEndpoint;

                ClearData();

                AddTempConnected(typeId, tempConnectedSource);
            }
Esempio n. 27
0
 private void Source_OutputChanged(MyDefinitionId changedResourceId, float oldOutput, MyResourceSourceComponent source)
 {
     float timeSinceLastUpdateSeconds = (MySession.Static.GameplayFrameCounter - m_lastOutputUpdateTime) / 1000f * VRage.Game.MyEngineConstants.UPDATE_STEPS_PER_SECOND;
     m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter;
     float outputAmount = oldOutput * timeSinceLastUpdateSeconds;
     m_nextGasTransfer -= outputAmount;
 }
        void SetEntityGroupForTempConnected(ref MyDefinitionId typeId, MyResourceSourceComponent source)
        {
            var block = source.TemporaryConnectedEntity as IMyConveyorEndpointBlock;

            int typeIndex = GetTypeIndex(ref typeId);
            bool found = false;
            for (int groupIndex = 0; groupIndex < m_dataPerType[typeIndex].DistributionGroupsInUse; ++groupIndex)
            {
                if (block == null || !MyGridConveyorSystem.Pathfinding.Reachable(m_dataPerType[typeIndex].DistributionGroups[groupIndex].FirstEndpoint, block.ConveyorEndpoint))
                {
                    bool addToGroup = false;
                    if (block == null)
                    {
                        foreach (var sinks in m_dataPerType[typeIndex].DistributionGroups[groupIndex].SinksByPriority)
                        {
                            foreach (var groupSink in sinks)
                            {
                                if (source.TemporaryConnectedEntity == groupSink.TemporaryConnectedEntity)
                                {
                                    addToGroup = true;
                                    break;
                                }
                            }
                            if (addToGroup)
                                break;
                        }
                    }
                    if (!addToGroup)
                        continue;
                }
                var group = m_dataPerType[typeIndex].DistributionGroups[groupIndex];
                group.AddTempConnected(typeId, source);
                m_dataPerType[typeIndex].DistributionGroups[groupIndex] = group;
                found = true;
                break;
            }

            if (!found)
            {
                if (++m_dataPerType[typeIndex].DistributionGroupsInUse > m_dataPerType[typeIndex].DistributionGroups.Count)
                    m_dataPerType[typeIndex].DistributionGroups.Add(new MyPhysicalDistributionGroup(typeId, source));
                else
                {
                    var group = m_dataPerType[typeIndex].DistributionGroups[m_dataPerType[typeIndex].DistributionGroupsInUse - 1];
                    group.InitFromTempConnected(typeId, source);
                    m_dataPerType[typeIndex].DistributionGroups[m_dataPerType[typeIndex].DistributionGroupsInUse - 1] = group;
                }
            }
        }
Esempio n. 29
0
 private void Source_ProductionEnabledChanged(MyDefinitionId changedResourceId, MyResourceSourceComponent source)
 {
     Enabled = source.Enabled;
     UpdateIsWorking();
 }
 public void AddTempConnected(MyDefinitionId typeId, MyResourceSourceComponent tempConnectedSource)
 {
     bool containsSource = tempConnectedSource != null && tempConnectedSource.ResourceTypes.Contains(typeId);
     Debug.Assert(containsSource);
     if (containsSource)
         SourcesByPriority[GetPriority(tempConnectedSource)].Add(tempConnectedSource);
 }