Esempio n. 1
0
        private unsafe QueueItem DeserializeQueueItem(MyObjectBuilder_ProductionBlock.QueueItem itemOb)
        {
            QueueItem *itemPtr1;
            QueueItem  item = new QueueItem {
                Amount    = itemOb.Amount,
                Blueprint = !MyDefinitionManager.Static.HasBlueprint(itemOb.Id) ? MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(itemOb.Id) : MyDefinitionManager.Static.GetBlueprintDefinition(itemOb.Id)
            };

            itemPtr1->ItemId = (itemOb.ItemId != null) ? itemOb.ItemId.Value : this.NextItemId;
            itemPtr1         = (QueueItem *)ref item;
            return(item);
        }
        private QueueItem DeserializeQueueItem(MyObjectBuilder_ProductionBlock.QueueItem itemOb)
        {
            QueueItem item = new QueueItem();

            item.Amount = itemOb.Amount;
            // Try to get the blueprint by its definition ID
            if (MyDefinitionManager.Static.HasBlueprint(itemOb.Id))
            {
                item.Blueprint = MyDefinitionManager.Static.GetBlueprintDefinition(itemOb.Id);
            }
            // Otherwise, we're dealing with an old save, so we get the blueprint by the result's definition ID
            else
            {
                item.Blueprint = MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(itemOb.Id);
            }
            item.ItemId = itemOb.ItemId.HasValue ? itemOb.ItemId.Value : NextItemId;
            return(item);
        }
Esempio n. 3
0
 public ProductionQueueItem(MyObjectBuilder_ProductionBlock.QueueItem q)
 {
     Amount = (decimal)q.Amount;
     Id     = q.Id;
     ItemId = q.ItemId.GetValueOrDefault(0);
 }
Esempio n. 4
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.SyncFlag = true;
            MyResourceSinkComponent component = new MyResourceSinkComponent(1);

            component.Init(this.ProductionBlockDefinition.ResourceSinkGroup, this.ProductionBlockDefinition.OperationalPowerConsumption, new Func <float>(this.ComputeRequiredPower));
            component.IsPoweredChanged += new Action(this.Receiver_IsPoweredChanged);
            base.ResourceSink           = component;
            base.Init(objectBuilder, cubeGrid);
            MyObjectBuilder_ProductionBlock block = (MyObjectBuilder_ProductionBlock)objectBuilder;

            if (this.InventoryAggregate == null)
            {
                this.InventoryAggregate = new MyInventoryAggregate();
            }
            if (this.InputInventory == null)
            {
                this.InputInventory = new MyInventory(this.ProductionBlockDefinition.InventoryMaxVolume, this.ProductionBlockDefinition.InventorySize, MyInventoryFlags.CanReceive);
                if (block.InputInventory != null)
                {
                    this.InputInventory.Init(block.InputInventory);
                }
            }
            if (this.OutputInventory == null)
            {
                this.OutputInventory = new MyInventory(this.ProductionBlockDefinition.InventoryMaxVolume, this.ProductionBlockDefinition.InventorySize, MyInventoryFlags.CanSend);
                if (block.OutputInventory != null)
                {
                    this.OutputInventory.Init(block.OutputInventory);
                }
            }
            this.m_nextItemId = block.NextItemId;
            uint nextItemId = this.m_nextItemId;

            base.IsWorkingChanged += new Action <MyCubeBlock>(this.CubeBlock_IsWorkingChanged);
            base.ResourceSink.Update();
            base.SlimBlock.ComponentStack.IsFunctionalChanged += new Action(this.ComponentStack_IsFunctionalChanged);
            if (block.Queue != null)
            {
                this.m_queue.Clear();
                if (this.m_queue.Capacity < block.Queue.Length)
                {
                    this.m_queue.Capacity = block.Queue.Length;
                }
                int index = 0;
                while (true)
                {
                    if (index >= block.Queue.Length)
                    {
                        this.UpdatePower();
                        break;
                    }
                    MyObjectBuilder_ProductionBlock.QueueItem itemOb = block.Queue[index];
                    QueueItem item = this.DeserializeQueueItem(itemOb);
                    if (item.Blueprint != null)
                    {
                        this.m_queue.Add(item);
                    }
                    else
                    {
                        MySandboxGame.Log.WriteLine($"Could not add item into production block's queue: Blueprint {itemOb.Id} was not found.");
                    }
                    index++;
                }
            }
            this.m_useConveyorSystem.SetLocalValue(block.UseConveyorSystem);
            this.m_lastUpdateTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
        }