protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_InventoryComponentDefinition;
            Volume = ob.Volume;
            if (ob.Size != null) 
            {
                Vector3 size = ob.Size.Value;
                Volume = size.Volume;
            }
            Mass = ob.Mass;
            RemoveEntityOnEmpty = ob.RemoveEntityOnEmpty;
            MultiplierEnabled = ob.MultiplierEnabled;
            MaxItemCount = ob.MaxItemCount;

            if (ob.InputConstraint != null)
            {
                InputConstraint = new MyInventoryConstraint("Input", whitelist: ob.InputConstraint.IsWhitelist);

                foreach (var constraint in ob.InputConstraint.Entries)
                {
                    if (string.IsNullOrEmpty(constraint.SubtypeName))
                        InputConstraint.AddObjectBuilderType(constraint.TypeId);
                    else
                        InputConstraint.Add(constraint);
                }
            }
        }
예제 #2
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_InventoryComponentDefinition;

            Volume = ob.Volume;
            if (ob.Size != null)
            {
                Vector3 size = ob.Size.Value;
                Volume = size.Volume;
            }
            Mass = ob.Mass;
            RemoveEntityOnEmpty = ob.RemoveEntityOnEmpty;
            MultiplierEnabled   = ob.MultiplierEnabled;
            MaxItemCount        = ob.MaxItemCount;

            if (ob.InputConstraint != null)
            {
                InputConstraint = new MyInventoryConstraint("Input", whitelist: ob.InputConstraint.IsWhitelist);

                foreach (var constraint in ob.InputConstraint.Entries)
                {
                    if (string.IsNullOrEmpty(constraint.SubtypeName))
                    {
                        InputConstraint.AddObjectBuilderType(constraint.TypeId);
                    }
                    else
                    {
                        InputConstraint.Add(constraint);
                    }
                }
            }
        }
예제 #3
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_ReactorDefinition definition = builder as MyObjectBuilder_ReactorDefinition;

            this.InventorySize      = definition.InventorySize;
            this.InventoryMaxVolume = (this.InventorySize.X * this.InventorySize.Y) * this.InventorySize.Z;
            List <MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo> fuelInfos = definition.FuelInfos;

            if (definition.FuelId != null)
            {
                MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo item = new MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo();
                item.Ratio = 1f;
                item.Id    = definition.FuelId.Value;
                List <MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo> list1 = new List <MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo>(fuelInfos);
                list1.Add(item);
                fuelInfos = list1;
            }
            this.FuelInfos           = new FuelInfo[fuelInfos.Count];
            this.InventoryConstraint = new MyInventoryConstraint(string.Format(MyTexts.GetString(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockInput), this.DisplayNameText), null, true);
            for (int i = 0; i < fuelInfos.Count; i++)
            {
                MyObjectBuilder_FueledPowerProducerDefinition.FuelInfo fuelInfo = fuelInfos[i];
                this.InventoryConstraint.Add(fuelInfo.Id);
                this.FuelInfos[i] = new FuelInfo(fuelInfo, this);
            }
        }
예제 #4
0
        private void MyEntities_OnEntityCreate(MyEntity obj)
        {
            var cubeblock = obj as MyCubeBlock;

            if (cubeblock == null || cubeblock.InventoryCount == 0)
            {
                return;
            }

            bool isDataBlock     = cubeblock.BlockDefinition.Id == _dataStorage;
            bool isResearchBlock = cubeblock.BlockDefinition.Id == _researchLab;
            bool allowed         = isDataBlock || isResearchBlock;

            try
            {
                if (isResearchBlock)
                {
                    var asm = cubeblock as Sandbox.ModAPI.IMyAssembler;
                    asm.Mode = MyAssemblerMode.Assembly;
                    asm.CurrentModeChanged += Assembler_OnModeChanged;
                    asm.OnClosing          += Assembler_OnClosing;
                }
            }
            catch (Exception ex)
            {
                _logger.Log();
                _logger.Log($"Exception with Assembler: {ex.Message}\n{ex.StackTrace}");
            }

            for (int i = 0; i < cubeblock.InventoryCount; i++)
            {
                var inv = cubeblock.GetInventory(i);
                MyInventoryConstraint constraint = inv.Constraint;
                if (constraint == null)
                {
                    constraint     = new MyInventoryConstraint("AQDConstraint", whitelist: isDataBlock);
                    inv.Constraint = constraint;
                }

                if (constraint.IsWhitelist)
                {
                    if (allowed)
                    {
                        foreach (var group in _researchSettings.ResearchGroupList)
                        {
                            constraint.Add(group.ComponentId.DefinitionId);
                        }
                    }
                }
                else if (!allowed)
                {
                    foreach (var group in _researchSettings.ResearchGroupList)
                    {
                        constraint.Add(group.ComponentId.DefinitionId);
                    }
                }
            }
        }
예제 #5
0
 public void FixInputOutputInventories(MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
 {
     if (this.m_inventoryAggregate.InventoryCount != 2)
     {
         MyInventoryAggregate component = MyInventoryAggregate.FixInputOutputInventories(this.m_inventoryAggregate, inputInventoryConstraint, outputInventoryConstraint);
         base.Components.Remove <MyInventoryBase>();
         this.m_outputInventory = null;
         this.m_inputInventory  = null;
         base.Components.Add <MyInventoryBase>(component);
     }
 }
        private void InitBlock()
        {
            var         owner          = Entity as MyCubeBlock;
            MyInventory blockInventory = null;

            owner.Components.ComponentAdded -= OnNewComponentAdded;

            if (owner != null)
            {
                if (owner.InventoryCount == 0)
                {
                    // Inventory wasn't created yet, let's wait for it to be added..
                    owner.Components.ComponentAdded += OnNewComponentAdded;
                    return;
                }
                else
                {
                    blockInventory = owner.GetInventory();
                }
                System.Diagnostics.Debug.Assert(blockInventory != null, "Block inventory was not initialized!");

                blockInventory.SetFlags(MyInventoryFlags.CanReceive | MyInventoryFlags.CanSend);

                System.Diagnostics.Debug.Assert(blockInventory.MaxVolume > 0, "Max volume of the inventory is not positive, items won't be added!");
                System.Diagnostics.Debug.Assert(blockInventory.MaxMass > 0, "Max volume of the inventory is not positive, items won't be added!");

                var inventoryConstraint = new MyInventoryConstraint("Crafting constraints");

                foreach (var blueprintClass in m_blueprintClasses)
                {
                    foreach (var blueprint in blueprintClass)
                    {
                        foreach (var item in blueprint.Results)
                        {
                            inventoryConstraint.Add(item.Id);
                        }
                        foreach (var item in blueprint.Prerequisites)
                        {
                            inventoryConstraint.Add(item.Id);
                        }
                    }
                }

                blockInventory.Constraint = inventoryConstraint;
            }
            else
            {
                System.Diagnostics.Debug.Fail("InitBlockInventory can be called only when Entity owning this component is not null and is MyEntity type ");
            }

            UpdateBlock();
        }
예제 #7
0
        private MyInventoryConstraint PrepareConstraint(MyStringId descriptionId, IEnumerable <MyBlueprintClassDefinition> classes, bool input)
        {
            string icon = null;

            foreach (MyBlueprintClassDefinition definition in classes)
            {
                string str2 = input ? definition.InputConstraintIcon : definition.OutputConstraintIcon;
                if (str2 != null)
                {
                    if (icon == null)
                    {
                        icon = str2;
                        continue;
                    }
                    if (icon != str2)
                    {
                        icon = null;
                        break;
                    }
                }
            }
            MyInventoryConstraint constraint = new MyInventoryConstraint(string.Format(MyTexts.GetString(descriptionId), this.DisplayNameText), icon, true);

            using (IEnumerator <MyBlueprintClassDefinition> enumerator = classes.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    IEnumerator <MyBlueprintDefinitionBase> enumerator2 = enumerator.Current.GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            MyBlueprintDefinitionBase current = enumerator2.Current;
                            foreach (MyBlueprintDefinitionBase.Item item in input ? current.Prerequisites : current.Results)
                            {
                                constraint.Add(item.Id);
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator2 == null)
                        {
                            continue;
                        }
                        enumerator2.Dispose();
                    }
                }
            }
            return(constraint);
        }
예제 #8
0
        public MyInventoryConstraint CreateAmmoInventoryConstraints(String displayName)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(MyTexts.GetString(MySpaceTexts.ToolTipItemFilter_AmmoMagazineInput), displayName);
            MyInventoryConstraint output = new MyInventoryConstraint(sb.ToString());

            foreach (MyDefinitionId ammoMagazineId in m_weaponProperties.WeaponDefinition.AmmoMagazinesId)
            {
                output.Add(ammoMagazineId);
            }

            return(output);
        }
        public void FixInputOutputInventories(MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            if (m_inventoryAggregate.InventoryCount == 2)
            {
                return;
            }

            var fixedAggregate = MyInventoryAggregate.FixInputOutputInventories(m_inventoryAggregate, inputInventoryConstraint, outputInventoryConstraint);

            Components.Remove <MyInventoryBase>();
            m_outputInventory = null;
            m_inputInventory  = null;
            Components.Add <MyInventoryBase>(fixedAggregate);
        }
예제 #10
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem = generatorBuilder.UseConveyorSystem;

            NeedsUpdate = Common.MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_inventory = new MyInventory(
                BlockDefinition.InventoryMaxVolume,
                BlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this);
            m_inventory.Constraint = BlockDefinition.InputInventoryConstraint;
            m_oreConstraint        = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist);
            foreach (var id in m_inventory.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_OxygenContainerObject))
                {
                    m_oreConstraint.Add(id);
                }
            }

            m_inventory.Init(generatorBuilder.Inventory);

            m_inventory.ContentsChanged += m_inventory_ContentsChanged;

            m_autoRefill = generatorBuilder.AutoRefill;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
예제 #11
0
        public void LoadPostProcess()
        {
            int index = 0;

            while (index < this.BlueprintClasses.Count)
            {
                if (!this.BlueprintClassCanBeUsed(this.BlueprintClasses[index]))
                {
                    this.BlueprintClasses.RemoveAt(index);
                    continue;
                }
                index++;
            }
            this.InputInventoryConstraint  = this.PrepareConstraint(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockInput, this.GetInputClasses(), true);
            this.OutputInventoryConstraint = this.PrepareConstraint(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockOutput, this.GetOutputClasses(), false);
        }
예제 #12
0
        private void MyEntities_OnEntityCreate(MyEntity obj)
        {
            var cubeblock = obj as MyCubeBlock;

            if (cubeblock == null || cubeblock.InventoryCount == 0)
            {
                return;
            }

            bool isDataBlock = cubeblock.BlockDefinition.Id == _dataStorage;
            bool allowed     = isDataBlock || cubeblock.BlockDefinition.Id == _researchLab;

            for (int i = 0; i < cubeblock.InventoryCount; i++)
            {
                var inv = cubeblock.GetInventory(i);
                MyInventoryConstraint constraint = inv.Constraint;
                if (constraint == null)
                {
                    constraint     = new MyInventoryConstraint("AQDConstraint", whitelist: isDataBlock);
                    inv.Constraint = constraint;
                }

                if (constraint.IsWhitelist)
                {
                    if (allowed)
                    {
                        foreach (var group in _researchSettings.ResearchGroupList)
                        {
                            constraint.Add(group.ComponentId.DefinitionId);
                        }
                    }
                }
                else if (!allowed)
                {
                    foreach (var group in _researchSettings.ResearchGroupList)
                    {
                        constraint.Add(group.ComponentId.DefinitionId);
                    }
                }
            }
        }
예제 #13
0
        public override void UpdateOnceBeforeFrame()
        {
            MyInventory inv = (MyInventory)Entity.GetInventory(0);

            if (inv == null)
            {
                return;
            }

            if (inv.Constraint == null)
            {
                MyInventoryConstraint constraint = new MyInventoryConstraint("Inventory: Diesel Not Allowed", null, false);
                constraint.Add(new MyDefinitionId(PhysicalFuelObject.TypeId, PhysicalFuelObject.SubtypeId));

                inv.Constraint = constraint;
            }
            else if (inv.Constraint.IsWhitelist == false)
            {
                inv.Constraint.Add(new MyDefinitionId(PhysicalFuelObject.TypeId, PhysicalFuelObject.SubtypeId));
            }

            NeedsUpdate = MyEntityUpdateEnum.NONE;
        }
예제 #14
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var generatorBuilder = builder as MyObjectBuilder_ReactorDefinition;

            MyDebug.AssertDebug(generatorBuilder != null, "Initializing thrust definition using wrong object builder.");
            InventorySize      = generatorBuilder.InventorySize;
            InventoryMaxVolume = InventorySize.X * InventorySize.Y * InventorySize.Z;

            FuelId         = generatorBuilder.FuelId;
            FuelDefinition = MyDefinitionManager.Static.GetPhysicalItemDefinition(FuelId);
            MyDebug.AssertDebug(FuelDefinition != null);

            FuelItem = MyObjectBuilderSerializer.CreateNewObject(generatorBuilder.FuelId) as MyObjectBuilder_PhysicalObject;
            MyDebug.AssertDebug(FuelItem != null);

            //StringBuilder constraintTooltip = new StringBuilder();
            //constraintTooltip.Append(FuelDefinition.DisplayNameText);
            //InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId);
            String constraintTooltip = FuelDefinition.DisplayNameText;

            InventoryConstraint = new MyInventoryConstraint(constraintTooltip).Add(FuelId);
        }
예제 #15
0
 public void Set(MyInventoryConstraint inventoryConstraint)
 {
     Clear();
     m_constraint = inventoryConstraint;
 }
예제 #16
0
 public void Clear()
 {
     m_all = false;
     m_obType = null;
     m_constraint = null;
 }
예제 #17
0
 public static void PullAllRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyInventoryConstraint requestedTypeIds)
 {
     SetTraversalPlayerId(playerId);
     m_tmpRequestedItemSet.Set(requestedTypeIds);
     ItemPullAll(start, destinationInventory);
     m_tmpRequestedItemSet.Clear();
 }
        private void InitBlock()
        {
            var owner = Entity as MyCubeBlock;
            MyInventory blockInventory = null;

            owner.Components.ComponentAdded -= OnNewComponentAdded;

            if (owner != null)
            {
                if (owner.InventoryCount == 0)
                {
                    // Inventory wasn't created yet, let's wait for it to be added..
                    owner.Components.ComponentAdded += OnNewComponentAdded;
                    return;
                }
                else
                {
                    blockInventory = owner.GetInventory();
                }
                System.Diagnostics.Debug.Assert(blockInventory != null, "Block inventory was not initialized!");

                blockInventory.SetFlags(MyInventoryFlags.CanReceive | MyInventoryFlags.CanSend);

                System.Diagnostics.Debug.Assert(blockInventory.MaxVolume > 0, "Max volume of the inventory is not positive, items won't be added!");
                System.Diagnostics.Debug.Assert(blockInventory.MaxMass > 0, "Max volume of the inventory is not positive, items won't be added!");

                var inventoryConstraint = new MyInventoryConstraint("Crafting constraints");

                foreach (var blueprintClass in m_blueprintClasses)
                {
                    foreach (var blueprint in blueprintClass)
                    {
                        foreach (var item in blueprint.Results)
                        {
                            inventoryConstraint.Add(item.Id);
                        }
                        foreach (var item in blueprint.Prerequisites)
                        {
                            inventoryConstraint.Add(item.Id);
                        }
                    }
                }

                blockInventory.Constraint = inventoryConstraint;
            }
            else
            {
                System.Diagnostics.Debug.Fail("InitBlockInventory can be called only when Entity owning this component is not null and is MyEntity type ");
            }
            
            UpdateBlock();
        }
예제 #19
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem = generatorBuilder.UseConveyorSystem;

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

	        m_inventory = new MyInventory(
		        BlockDefinition.InventoryMaxVolume,
			        BlockDefinition.InventorySize,
			        MyInventoryFlags.CanReceive,
			        this)
	        {
		        Constraint = BlockDefinition.InputInventoryConstraint
	        };
	        m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist);
            foreach (var id in m_inventory.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                    m_oreConstraint.Add(id);
            }

            m_inventory.Init(generatorBuilder.Inventory);

            m_inventory.ContentsChanged += Inventory_ContentsChanged;

            AutoRefill = generatorBuilder.AutoRefill;

	        var sourceDataList = new List<MyResourceSourceInfo>();

	        foreach (var producedInfo in BlockDefinition.ProducedGases)
				sourceDataList.Add(new MyResourceSourceInfo
				{
				    ResourceTypeId = producedInfo.Id,
                    DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio,
                    ProductionToCapacityMultiplier = 1
				});

			SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList);
            if (Sync.IsServer)
                SourceComp.OutputChanged += Source_OutputChanged;
            float iceAmount = IceAmount();
            foreach (var gasId in SourceComp.ResourceTypes)
                m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(gasId, iceAmount));

            m_updateCounter = 0;
            m_lastSourceUpdate = m_updateCounter;

	        ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo
				{
				    ResourceTypeId = MyResourceDistributorComponent.ElectricityId,
                    MaxRequiredInput = BlockDefinition.OperationalPowerConsumption,
                    RequiredInputFunc = ComputeRequiredPower
				});
			ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
			ResourceSink.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyGasGenerator_IsWorkingChanged;
        }
예제 #20
0
        public MyInventoryConstraint CreateAmmoInventoryConstraints(String displayName)
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat(MyTexts.GetString(MySpaceTexts.ToolTipItemFilter_AmmoMagazineInput), displayName);
            MyInventoryConstraint output = new MyInventoryConstraint(sb.ToString());

            foreach (MyDefinitionId ammoMagazineId in m_weaponProperties.WeaponDefinition.AmmoMagazinesId)
                output.Add(ammoMagazineId);

            return output;
        }
예제 #21
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sourceDataList = new List <MyResourceSourceInfo>();

            foreach (var producedInfo in BlockDefinition.ProducedGases)
            {
                sourceDataList.Add(new MyResourceSourceInfo
                {
                    ResourceTypeId = producedInfo.Id,
                    DefinedOutput  = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio * (MySession.Static.CreativeMode ? 10f : 1f),
                    ProductionToCapacityMultiplier = 1
                });
            }

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList);

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (this.GetInventory() == null) // can be already initialized as deserialized component
            {
                MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive);
                inventory.Constraint = BlockDefinition.InputInventoryConstraint;
                Components.Add <MyInventoryBase>(inventory);
            }
            else
            {
                this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint;
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            m_oreConstraint = new MyInventoryConstraint(this.GetInventory().Constraint.Description, this.GetInventory().Constraint.Icon, this.GetInventory().Constraint.IsWhitelist);
            foreach (var id in this.GetInventory().Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                {
                    m_oreConstraint.Add(id);
                }
            }

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            if (this.GetInventory() != null)
            {
                this.GetInventory().Init(generatorBuilder.Inventory);
            }
            else
            {
                Debug.Fail("Trying to init inventory, but it's null!");
            }

            AutoRefill = generatorBuilder.AutoRefill;



            SourceComp.Enabled = Enabled;
            if (Sync.IsServer)
            {
                SourceComp.OutputChanged += Source_OutputChanged;
            }
            float iceAmount = IceAmount();

            foreach (var gasId in SourceComp.ResourceTypes)
            {
                var tmpGasId = gasId;
                m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(ref tmpGasId, iceAmount));
            }

            m_lastSourceUpdate = MySession.Static.GameplayFrameCounter;

            ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo
            {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = ComputeRequiredPower
            });
            ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyGasGenerator_IsWorkingChanged;
        }
예제 #22
0
        public static bool PullAllRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyInventoryConstraint requestedTypeIds)
        {
            MyCubeBlock startingBlock = start as MyCubeBlock;
            if (startingBlock == null) return false;

            m_tmpRequestedItemSet.Set(requestedTypeIds);

            // Try and get the block from the cache
            MyGridConveyorSystem conveyorSystem = startingBlock.CubeGrid.GridSystems.ConveyorSystem;
            MyGridConveyorSystem.ConveyorEndpointMapping endpoints = conveyorSystem.GetConveyorEndpointMapping(start);
            if (endpoints.pullElements != null)
            {
                bool didTransfer = false;

                // Iterate to the other elements, see if we can collect some amount of items to pull
                for (int i = 0; i < endpoints.pullElements.Count; i++)
                {
                    MyCubeBlock sourceBlock = endpoints.pullElements[i] as MyCubeBlock;
                    if (sourceBlock == null) continue;

                    int inventoryCount = sourceBlock.InventoryCount;
                    for (int inventoryIndex = 0; inventoryIndex < inventoryCount; inventoryIndex++)
                    {
                        MyInventory inventory = sourceBlock.GetInventory(inventoryIndex);
                        if ((inventory.GetFlags() & MyInventoryFlags.CanSend) == 0)
                            continue;

                        if (inventory == destinationInventory)
                            continue;

                        m_tmpInventoryItems.Clear();
                        foreach (var item in inventory.GetItems())
                        {
                            m_tmpInventoryItems.Add(item);
                        }

                        foreach (var item in m_tmpInventoryItems)
                        {
                            if (destinationInventory.VolumeFillFactor >= 1.0f)
                            {
                                m_tmpInventoryItems.Clear();
                                return true;
                            }

                            var itemId = item.Content.GetId();

                            if (requestedTypeIds != null && !m_tmpRequestedItemSet.Contains(itemId))
                                continue;

                            // Verify that this item can, in fact, make it past sorters, etc
                            if (!CanTransfer(start, endpoints.pullElements[i], itemId, false))
                                continue;

                            var transferedAmount = item.Amount;

                            var oxygenBottle = item.Content as Sandbox.Common.ObjectBuilders.Definitions.MyObjectBuilder_GasContainerObject;
                            if (oxygenBottle != null && oxygenBottle.GasLevel >= 1f)
                                continue;

                            if (!MySession.Static.CreativeMode)
                            {
                                var fittingAmount = destinationInventory.ComputeAmountThatFits(item.Content.GetId());
                                if (item.Content.TypeId != typeof(MyObjectBuilder_Ore) &&
                                    item.Content.TypeId != typeof(MyObjectBuilder_Ingot))
                                {
                                    fittingAmount = MyFixedPoint.Floor(fittingAmount);
                                }
                                transferedAmount = MyFixedPoint.Min(fittingAmount, transferedAmount);
                            }
                            if (transferedAmount == 0)
                                continue;

                            didTransfer = true;
                            MyInventory.Transfer(inventory, destinationInventory, item.Content.GetId(), MyItemFlags.None, transferedAmount);

                            if (destinationInventory.CargoPercentage >= 0.99f)
                                break;
                        }

                        if (destinationInventory.CargoPercentage >= 0.99f)
                            break;
                    }

                    if (destinationInventory.CargoPercentage >= 0.99f)
                        break;
                }

                return didTransfer;
            }

            else
            {
                // Cache may need to be recomputed
                if (!conveyorSystem.m_isRecomputingGraph)
                    conveyorSystem.RecomputeConveyorEndpoints();
            }

            return false;
        }
예제 #23
0
        public static MyInventoryAggregate FixInputOutputInventories(MyInventoryAggregate inventoryAggregate, MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            MyInventory objA      = null;
            MyInventory component = null;

            foreach (MyInventory inventory3 in inventoryAggregate.ChildList.Reader)
            {
                if (inventory3 == null)
                {
                    continue;
                }
                if (inventory3.GetItemsCount() > 0)
                {
                    if (objA == null)
                    {
                        bool flag = true;
                        if (inputInventoryConstraint != null)
                        {
                            foreach (MyPhysicalInventoryItem item in inventory3.GetItems())
                            {
                                flag &= inputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (flag)
                        {
                            objA = inventory3;
                        }
                    }
                    if ((component == null) && !ReferenceEquals(objA, inventory3))
                    {
                        bool flag2 = true;
                        if (outputInventoryConstraint != null)
                        {
                            foreach (MyPhysicalInventoryItem item2 in inventory3.GetItems())
                            {
                                flag2 &= outputInventoryConstraint.Check(item2.GetDefinitionId());
                            }
                        }
                        if (flag2)
                        {
                            component = inventory3;
                        }
                    }
                }
            }
            if ((objA == null) || (component == null))
            {
                foreach (MyInventory inventory4 in inventoryAggregate.ChildList.Reader)
                {
                    if (inventory4 != null)
                    {
                        if (objA == null)
                        {
                            objA = inventory4;
                            continue;
                        }
                        if (component != null)
                        {
                            break;
                        }
                        component = inventory4;
                    }
                }
            }
            inventoryAggregate.RemoveComponent(objA);
            inventoryAggregate.RemoveComponent(component);
            MyInventoryAggregate aggregate = new MyInventoryAggregate();

            aggregate.AddComponent(objA);
            aggregate.AddComponent(component);
            return(aggregate);
        }
        /// <summary>
        /// Naive looking for inventories with some items..
        /// </summary>
        static public MyInventoryAggregate FixInputOutputInventories(MyInventoryAggregate inventoryAggregate, MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            MyInventory inputInventory = null;
            MyInventory outputInventory = null;

            foreach (var inventory in inventoryAggregate.ChildList.Reader)
            {
                var myInventory = inventory as MyInventory;

                if (myInventory == null)
                    continue;

                if (myInventory.GetItemsCount() > 0)
                {
                    if (inputInventory == null)
                    {
                        bool check = true;
                        if (inputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= inputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            inputInventory = myInventory;
                        }
                    }
                    if (outputInventory == null && inputInventory != myInventory)
                    {
                        bool check = true;
                        if (outputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= outputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            outputInventory = myInventory;
                        }
                    }
                }
            }

            if (inputInventory == null || outputInventory == null)
            {
                foreach (var inventory in inventoryAggregate.ChildList.Reader)
                {
                    var myInventory = inventory as MyInventory;
                    if (myInventory == null)
                        continue;
                    if (inputInventory == null)
                    {
                        inputInventory = myInventory;
                    }
                    else if (outputInventory == null)
                    {
                        outputInventory = myInventory;
                    }
                    else
                    {
                        break;
                    }
                }
            }


            inventoryAggregate.RemoveComponent(inputInventory);
            inventoryAggregate.RemoveComponent(outputInventory);
            var fixedAggregate = new MyInventoryAggregate();
            fixedAggregate.AddComponent(inputInventory);
            fixedAggregate.AddComponent(outputInventory);
            return fixedAggregate;
        }
예제 #25
0
        private void InitBlock()
        {
            MyCubeBlock entity    = base.Entity as MyCubeBlock;
            MyInventory inventory = null;

            entity.Components.ComponentAdded -= new Action <System.Type, MyEntityComponentBase>(this.OnNewComponentAdded);
            if (entity != null)
            {
                if (entity.InventoryCount == 0)
                {
                    entity.Components.ComponentAdded += new Action <System.Type, MyEntityComponentBase>(this.OnNewComponentAdded);
                    return;
                }
                inventory = entity.GetInventory(0);
                inventory.SetFlags(MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive);
                MyInventoryConstraint constraint = new MyInventoryConstraint("Crafting constraints", null, true);
                using (List <MyBlueprintClassDefinition> .Enumerator enumerator = base.m_blueprintClasses.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IEnumerator <MyBlueprintDefinitionBase> enumerator2 = enumerator.Current.GetEnumerator();
                        try
                        {
                            while (enumerator2.MoveNext())
                            {
                                MyBlueprintDefinitionBase        current = enumerator2.Current;
                                MyBlueprintDefinitionBase.Item[] results = current.Results;
                                int index = 0;
                                while (true)
                                {
                                    if (index >= results.Length)
                                    {
                                        results = current.Prerequisites;
                                        index   = 0;
                                        while (index < results.Length)
                                        {
                                            MyBlueprintDefinitionBase.Item item2 = results[index];
                                            constraint.Add(item2.Id);
                                            index++;
                                        }
                                        break;
                                    }
                                    MyBlueprintDefinitionBase.Item item = results[index];
                                    constraint.Add(item.Id);
                                    index++;
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator2 == null)
                            {
                                continue;
                            }
                            enumerator2.Dispose();
                        }
                    }
                }
                inventory.Constraint = constraint;
            }
            this.UpdateBlock();
        }
예제 #26
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem = generatorBuilder.UseConveyorSystem;

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_inventory = new MyInventory(
                BlockDefinition.InventoryMaxVolume,
                BlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this)
            {
                Constraint = BlockDefinition.InputInventoryConstraint
            };
            m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist);
            foreach (var id in m_inventory.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                {
                    m_oreConstraint.Add(id);
                }
            }

            m_inventory.Init(generatorBuilder.Inventory);

            m_inventory.ContentsChanged += Inventory_ContentsChanged;

            AutoRefill = generatorBuilder.AutoRefill;

            var sourceDataList = new List <MyResourceSourceInfo>();

            foreach (var producedInfo in BlockDefinition.ProducedGases)
            {
                sourceDataList.Add(new MyResourceSourceInfo
                {
                    ResourceTypeId = producedInfo.Id,
                    DefinedOutput  = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio,
                    ProductionToCapacityMultiplier = 1
                });
            }

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList);
            if (Sync.IsServer)
            {
                SourceComp.OutputChanged += Source_OutputChanged;
            }
            float iceAmount = IceAmount();

            foreach (var gasId in SourceComp.ResourceTypes)
            {
                m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(gasId, iceAmount));
            }

            m_updateCounter    = 0;
            m_lastSourceUpdate = m_updateCounter;

            ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo
            {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = ComputeRequiredPower
            });
            ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyGasGenerator_IsWorkingChanged;
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem = generatorBuilder.UseConveyorSystem;

            NeedsUpdate = Common.MyEntityUpdateEnum.EACH_100TH_FRAME;

            m_inventory = new MyInventory(
                BlockDefinition.InventoryMaxVolume,
                BlockDefinition.InventorySize,
                MyInventoryFlags.CanReceive,
                this);
            m_inventory.Constraint = BlockDefinition.InputInventoryConstraint;
            m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist);
            foreach (var id in m_inventory.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_OxygenContainerObject))
                {
                    m_oreConstraint.Add(id);
                }
            }

            m_inventory.Init(generatorBuilder.Inventory);

            m_inventory.ContentsChanged += m_inventory_ContentsChanged;

            m_autoRefill = generatorBuilder.AutoRefill;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
예제 #28
0
        /// <summary>
        /// Naive looking for inventories with some items..
        /// </summary>
        static public MyInventoryAggregate FixInputOutputInventories(MyInventoryAggregate inventoryAggregate, MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            MyInventory inputInventory  = null;
            MyInventory outputInventory = null;

            foreach (var inventory in inventoryAggregate.ChildList.Reader)
            {
                var myInventory = inventory as MyInventory;

                if (myInventory == null)
                {
                    continue;
                }

                if (myInventory.GetItemsCount() > 0)
                {
                    if (inputInventory == null)
                    {
                        bool check = true;
                        if (inputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= inputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            inputInventory = myInventory;
                        }
                    }
                    if (outputInventory == null && inputInventory != myInventory)
                    {
                        bool check = true;
                        if (outputInventoryConstraint != null)
                        {
                            foreach (var item in myInventory.GetItems())
                            {
                                check &= outputInventoryConstraint.Check(item.GetDefinitionId());
                            }
                        }
                        if (check)
                        {
                            outputInventory = myInventory;
                        }
                    }
                }
            }

            if (inputInventory == null || outputInventory == null)
            {
                foreach (var inventory in inventoryAggregate.ChildList.Reader)
                {
                    var myInventory = inventory as MyInventory;
                    if (myInventory == null)
                    {
                        continue;
                    }
                    if (inputInventory == null)
                    {
                        inputInventory = myInventory;
                    }
                    else if (outputInventory == null)
                    {
                        outputInventory = myInventory;
                    }
                    else
                    {
                        break;
                    }
                }
            }


            inventoryAggregate.RemoveComponent(inputInventory);
            inventoryAggregate.RemoveComponent(outputInventory);
            var fixedAggregate = new MyInventoryAggregate();

            fixedAggregate.AddComponent(inputInventory);
            fixedAggregate.AddComponent(outputInventory);
            return(fixedAggregate);
        }
예제 #29
0
        public void FixInputOutputInventories(MyInventoryConstraint inputInventoryConstraint, MyInventoryConstraint outputInventoryConstraint)
        {
            if (m_inventoryAggregate.InventoryCount == 2)
            {
                return;
            }

            var fixedAggregate = MyInventoryAggregate.FixInputOutputInventories(m_inventoryAggregate, inputInventoryConstraint, outputInventoryConstraint);
            Components.Remove<MyInventoryBase>();
            m_outputInventory = null;
            m_inputInventory = null;
            Components.Add<MyInventoryBase>(fixedAggregate);
        }
 public void Clear()
 {
     m_all        = false;
     m_obType     = null;
     m_constraint = null;
 }
 public void Set(MyInventoryConstraint inventoryConstraint)
 {
     Clear();
     m_constraint = inventoryConstraint;
 }
        public void LoadPostProcess()
        {
            // Remove invalid blueprint classes
            for (int i = 0; i < BlueprintClasses.Count;)
            {
                if (!BlueprintClassCanBeUsed(BlueprintClasses[i]))
                {
                    BlueprintClasses.RemoveAt(i);
                }
                else
                {
                    ++i;
                }
            }

            // Set the constraint icons only if all the blueprint classes agree upon them
            string firstInputIcon  = null;
            string firstOutputIcon = null;

            if (BlueprintClasses.Count != 0)
            {
                firstInputIcon  = BlueprintClasses[0].InputConstraintIcon;
                firstOutputIcon = BlueprintClasses[0].OutputConstraintIcon;

                for (int i = 1; i < BlueprintClasses.Count; ++i)
                {
                    if (BlueprintClasses[i].InputConstraintIcon != firstInputIcon)
                    {
                        firstInputIcon = null;
                    }
                    if (BlueprintClasses[i].OutputConstraintIcon != firstOutputIcon)
                    {
                        firstOutputIcon = null;
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockInput, DisplayNameText);
            InputInventoryConstraint = new MyInventoryConstraint(sb.ToString(), firstInputIcon);

            sb = new StringBuilder();
            sb.AppendFormat(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockOutput, DisplayNameText);
            OutputInventoryConstraint = new MyInventoryConstraint(sb.ToString(), firstOutputIcon);

            for (int i = 0; i < BlueprintClasses.Count; ++i)
            {
                foreach (var blueprint in BlueprintClasses[i])
                {
                    foreach (var input in blueprint.Prerequisites)
                    {
                        InputInventoryConstraint.Add(input.Id);
                    }
                    foreach (var output in blueprint.Results)
                    {
                        OutputInventoryConstraint.Add(output.Id);
                    }
                }
            }
        }
        public static bool PullAllRequest(IMyConveyorEndpointBlock start, MyInventory destinationInventory, long playerId, MyInventoryConstraint requestedTypeIds)
        {
            SetTraversalPlayerId(playerId);
            m_tmpRequestedItemSet.Set(requestedTypeIds);
            bool ret = ItemPullAll(start, destinationInventory);

            m_tmpRequestedItemSet.Clear();
            return(ret);
        }
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sourceDataList = new List<MyResourceSourceInfo>();

            foreach (var producedInfo in BlockDefinition.ProducedGases)
                sourceDataList.Add(new MyResourceSourceInfo
                {
                    ResourceTypeId = producedInfo.Id,
                    DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio * (MySession.Static.CreativeMode ? 10f : 1f),
                    ProductionToCapacityMultiplier = 1
                });

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList);

            base.Init(objectBuilder, cubeGrid);

            var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator;

            InitializeConveyorEndpoint();
            m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            if (this.GetInventory() == null) // can be already initialized as deserialized component
            {
                MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive);
                inventory.Constraint = BlockDefinition.InputInventoryConstraint;
                Components.Add<MyInventoryBase>(inventory);
            }
            else
            {
                this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint;
            }
            Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!");

            m_oreConstraint = new MyInventoryConstraint(this.GetInventory().Constraint.Description, this.GetInventory().Constraint.Icon, this.GetInventory().Constraint.IsWhitelist);
            foreach (var id in this.GetInventory().Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                    m_oreConstraint.Add(id);
            }

            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                FixSingleInventory();
            }

            if (this.GetInventory() != null)
            {
                this.GetInventory().Init(generatorBuilder.Inventory);
            }
            else
            {
                Debug.Fail("Trying to init inventory, but it's null!");
            }

            AutoRefill = generatorBuilder.AutoRefill;

            SourceComp.Enabled = Enabled;
            if (Sync.IsServer)
                SourceComp.OutputChanged += Source_OutputChanged;
            float iceAmount = IceAmount();
            foreach (var gasId in SourceComp.ResourceTypes)
            {
                var tmpGasId = gasId;
                m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(ref tmpGasId, iceAmount));
            }

            m_lastSourceUpdate = MySession.Static.GameplayFrameCounter;

            ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo
                {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId,
                    MaxRequiredInput = BlockDefinition.OperationalPowerConsumption,
                    RequiredInputFunc = ComputeRequiredPower
                });
            ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            ResourceSink.Update();

            UpdateEmissivity();
            UpdateText();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyGasGenerator_IsWorkingChanged;
        }
예제 #35
0
        public override unsafe void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.SyncFlag = true;
            List <MyResourceSourceInfo> sourceResourceData = new List <MyResourceSourceInfo>();

            foreach (MyOxygenGeneratorDefinition.MyGasGeneratorResourceInfo info in this.BlockDefinition.ProducedGases)
            {
                MyResourceSourceInfo *infoPtr1;
                MyResourceSourceInfo  item = new MyResourceSourceInfo {
                    ResourceTypeId = info.Id
                };
                infoPtr1->DefinedOutput = (this.BlockDefinition.IceConsumptionPerSecond * info.IceToGasRatio) * (MySession.Static.CreativeMode ? 10f : 1f);
                infoPtr1 = (MyResourceSourceInfo *)ref item;
                item.ProductionToCapacityMultiplier = 1f;
                sourceResourceData.Add(item);
            }
            this.SourceComp.Init(this.BlockDefinition.ResourceSourceGroup, sourceResourceData);
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_OxygenGenerator generator = objectBuilder as MyObjectBuilder_OxygenGenerator;

            this.InitializeConveyorEndpoint();
            this.m_useConveyorSystem.SetLocalValue(generator.UseConveyorSystem);
            base.NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME | MyEntityUpdateEnum.EACH_FRAME;
            MyInventory component = this.GetInventory(0);

            if (component != null)
            {
                component.Constraint = this.BlockDefinition.InputInventoryConstraint;
            }
            else
            {
                component = new MyInventory(this.BlockDefinition.InventoryMaxVolume, this.BlockDefinition.InventorySize, MyInventoryFlags.CanReceive)
                {
                    Constraint = this.BlockDefinition.InputInventoryConstraint
                };
                base.Components.Add <MyInventoryBase>(component);
            }
            this.m_oreConstraint = new MyInventoryConstraint(component.Constraint.Description, component.Constraint.Icon, component.Constraint.IsWhitelist);
            foreach (MyDefinitionId id in component.Constraint.ConstrainedIds)
            {
                if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject))
                {
                    this.m_oreConstraint.Add(id);
                }
            }
            if (MyFakes.ENABLE_INVENTORY_FIX)
            {
                base.FixSingleInventory();
            }
            if (component != null)
            {
                component.Init(generator.Inventory);
            }
            this.AutoRefill         = generator.AutoRefill;
            this.SourceComp.Enabled = base.Enabled;
            if (Sync.IsServer)
            {
                this.SourceComp.OutputChanged += new MyResourceOutputChangedDelegate(this.Source_OutputChanged);
            }
            float num = this.IceAmount();

            foreach (MyDefinitionId id2 in this.SourceComp.ResourceTypes)
            {
                MyDefinitionId gasId = id2;
                this.m_sourceComp.SetRemainingCapacityByType(id2, (float)this.IceToGas(ref gasId, (double)num));
            }
            MyResourceSinkInfo sinkData = new MyResourceSinkInfo {
                ResourceTypeId    = MyResourceDistributorComponent.ElectricityId,
                MaxRequiredInput  = this.BlockDefinition.OperationalPowerConsumption,
                RequiredInputFunc = new Func <float>(this.ComputeRequiredPower)
            };

            base.ResourceSink.Init(this.BlockDefinition.ResourceSinkGroup, sinkData);
            base.ResourceSink.IsPoweredChanged += new Action(this.PowerReceiver_IsPoweredChanged);
            base.ResourceSink.Update();
            this.UpdateText();
            base.AddDebugRenderComponent(new MyDebugRenderComponentDrawConveyorEndpoint(this.m_conveyorEndpoint));
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            base.IsWorkingChanged += new Action <MyCubeBlock>(this.MyGasGenerator_IsWorkingChanged);
        }