protected void InitializeInventoryCounts(bool inputInventory = true)
 {
     m_tmpInventoryCounts.Clear();
     foreach (var item in inputInventory ? InputInventory.GetItems() : OutputInventory.GetItems())
     {
         MyFixedPoint   count  = 0;
         MyDefinitionId itemId = new MyDefinitionId(item.Content.TypeId, item.Content.SubtypeId);
         m_tmpInventoryCounts.TryGetValue(itemId, out count);
         m_tmpInventoryCounts[itemId] = count + item.Amount;
     }
 }
Пример #2
0
 public override void UpdateBeforeSimulation100()
 {
     base.UpdateBeforeSimulation100();
     if (Sync.IsServer && IsWorking && m_useConveyorSystem)
     {
         if (InputInventory.VolumeFillFactor < 0.6f)
         {
             MyGridConveyorSystem.PullAllRequest(this, InputInventory, OwnerId, InputInventory.Constraint);
         }
         if (OutputInventory.VolumeFillFactor > 0.75f)
         {
             Debug.Assert(OutputInventory.GetItems().Count > 0);
             MyGridConveyorSystem.PushAnyRequest(this, OutputInventory, OwnerId);
         }
     }
 }
Пример #3
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();

            if (m_inventoryOwnersDirty)
            {
                GetCoveyorInventoryOwners();
            }

            if (Sync.IsServer && IsWorking && m_useConveyorSystem)
            {
                if (DisassembleEnabled) // Dissasembling
                {
                    if (OutputInventory.VolumeFillFactor < 0.99f)
                    {
                        //MyGridConveyorSystem.PullAllRequest(this, OutputInventory, OwnerId, OutputInventory.Constraint);
                        var item = TryGetFirstQueueItem();
                        if (item != null)
                        {
                            if (!OutputInventory.ContainItems(null, item.Value.Blueprint.Results[0].Id))
                            {
                                MyGridConveyorSystem.ItemPullRequest(this, OutputInventory, OwnerId, item.Value.Blueprint.Results[0].Id, item.Value.Amount);
                            }
                        }
                    }
                    if (InputInventory.VolumeFillFactor > 0.75f)
                    {
                        Debug.Assert(InputInventory.GetItems().Count > 0);
                        MyGridConveyorSystem.PushAnyRequest(this, InputInventory, OwnerId);
                    }
                }
                else // Assembling
                {
                    if (IsSlave && m_queue.Count < 1 && MyFakes.ENABLE_ASSEMBLER_COOPERATION && !RepeatEnabled)
                    {
                        GetItemFromOtherAssemblers();
                    }
                    if (InputInventory.VolumeFillFactor < 0.99f)
                    {
                        var next = false;
                        int i    = 0;
                        var time = 0f;
                        do
                        {
                            var item = TryGetQueueItem(i);
                            if (item.HasValue)
                            {
                                var factor        = MySession.Static.AssemblerSpeedMultiplier / MySession.Static.AssemblerEfficiencyMultiplier;
                                var itemAmount    = 1;
                                var remainingTime = TIME_IN_ADVANCE - time;
                                if (item.Value.Blueprint.BaseProductionTimeInSeconds < remainingTime)
                                {
                                    itemAmount = Math.Min((int)item.Value.Amount, Convert.ToInt32(Math.Floor(remainingTime / (item.Value.Blueprint.BaseProductionTimeInSeconds / factor))));
                                    time      += itemAmount * item.Value.Blueprint.BaseProductionTimeInSeconds / MySession.Static.AssemblerSpeedMultiplier;
                                    if (time < TIME_IN_ADVANCE)

                                    {
                                        next = true;
                                    }
                                }
                                foreach (var component in item.Value.Blueprint.Prerequisites)
                                {
                                    var availableAmount = InputInventory.GetItemAmount(component.Id);
                                    if (i > 0)
                                    {
                                        availableAmount = 0;
                                    }
                                    var neededAmount = component.Amount * itemAmount - availableAmount;
                                    if (neededAmount <= 0)
                                    {
                                        continue;
                                    }

                                    MyGridConveyorSystem.ItemPullRequest(this, InputInventory, OwnerId, component.Id, neededAmount);
                                }
                            }
                            if (i > 0)
                            {
                                next = false;
                            }
                            i++;
                        } while (next);
                    }
                    if (OutputInventory.VolumeFillFactor > 0.75f)
                    {
                        Debug.Assert(OutputInventory.GetItems().Count > 0);
                        MyGridConveyorSystem.PushAnyRequest(this, OutputInventory, OwnerId);
                    }
                }
            }
        }
Пример #4
0
        private void DisassembleAllInOutput()
        {
            ClearQueue(sendEvent: false);

            var  items = OutputInventory.GetItems();
            var  toAdd = new List <Tuple <MyBlueprintDefinitionBase, MyFixedPoint> >();
            bool add   = true;

            foreach (var item in items)
            {
                var blueprint = MyDefinitionManager.Static.TryGetBlueprintDefinitionByResultId(item.Content.GetId());
                if (blueprint != null)
                {
                    var tuple = Tuple.Create(blueprint, item.Amount);
                    toAdd.Add(tuple);
                }
                else
                {
                    add = false;
                    toAdd.Clear();
                    break;
                }
            }
            if (add)
            {
                foreach (var bp in toAdd)
                {
                    InsertQueueItemRequest(-1, bp.Item1, bp.Item2);
                }
                return;
            }

            InitializeInventoryCounts(inputInventory: false);

            MyFixedPoint disassembleAmount, remainingAmount;

            for (int i = 0; i < m_assemblerDef.BlueprintClasses.Count; ++i)
            {
                foreach (var blueprint in m_assemblerDef.BlueprintClasses[i])
                {
                    disassembleAmount = MyFixedPoint.MaxValue;
                    foreach (var result in blueprint.Results)
                    {
                        remainingAmount = 0;
                        m_tmpInventoryCounts.TryGetValue(result.Id, out remainingAmount);
                        if (remainingAmount == 0)
                        {
                            disassembleAmount = 0;
                            break;
                        }
                        disassembleAmount = MyFixedPoint.Min((MyFixedPoint)((double)remainingAmount / (double)result.Amount), disassembleAmount);
                    }

                    if (blueprint.Atomic)
                    {
                        disassembleAmount = MyFixedPoint.Floor(disassembleAmount);
                    }

                    if (disassembleAmount > 0)
                    {
                        InsertQueueItemRequest(-1, blueprint, disassembleAmount);
                        foreach (var result in blueprint.Results)
                        {
                            m_tmpInventoryCounts.TryGetValue(result.Id, out remainingAmount);
                            remainingAmount -= result.Amount * disassembleAmount;
                            Debug.Assert(remainingAmount >= 0);
                            if (remainingAmount == 0)
                            {
                                m_tmpInventoryCounts.Remove(result.Id);
                            }
                            else
                            {
                                m_tmpInventoryCounts[result.Id] = remainingAmount;
                            }
                        }
                    }
                }
            }

            m_tmpInventoryCounts.Clear();
        }
Пример #5
0
        public override void UpdateBeforeSimulation100()
        {
            base.UpdateBeforeSimulation100();

            if (m_inventoryOwnersDirty)
            {
                GetCoveyorInventoryOwners();
            }

            if (Sync.IsServer && IsWorking && m_useConveyorSystem)
            {
                if (DisassembleEnabled) // Dissasembling
                {
                    if (OutputInventory.VolumeFillFactor < 0.99f)
                    {
                        //MyGridConveyorSystem.PullAllRequest(this, OutputInventory, OwnerId, OutputInventory.Constraint);
                        var item = TryGetFirstQueueItem();
                        if (item != null)
                        {
                            if (!OutputInventory.ContainItems(null, item.Value.Blueprint.Results[0].Id))
                            {
                                MyGridConveyorSystem.ItemPullRequest(this, OutputInventory, OwnerId, item.Value.Blueprint.Results[0].Id, item.Value.Amount);
                            }
                        }
                    }
                    if (InputInventory.VolumeFillFactor > 0.75f)
                    {
                        Debug.Assert(InputInventory.GetItems().Count > 0);
                        MyGridConveyorSystem.PushAnyRequest(this, InputInventory, OwnerId);
                    }
                }
                else // Assembling
                {
                    //if (IsSlave && m_queue.Count < 1 && MyFakes.ENABLE_ASSEMBLER_COOPERATION && !RepeatEnabled)
                    //{
                    //    GetItemFromOtherAssemblers(TIME_IN_ADVANCE);
                    //}
                    if (InputInventory.VolumeFillFactor < 0.99f)
                    {
                        m_requiredComponents.Clear();

                        var next = false;
                        int i    = 0;
                        var time = 0f;
                        do
                        {
                            var item          = TryGetQueueItem(i);
                            var remainingTime = TIME_IN_ADVANCE - time;
                            if (item.HasValue)
                            {
                                var productivity = (((MyAssemblerDefinition)BlockDefinition).AssemblySpeed + UpgradeValues["Productivity"]);
                                var factor       = MySession.Static.AssemblerSpeedMultiplier * productivity;
                                var itemAmount   = 1;
                                if (item.Value.Blueprint.BaseProductionTimeInSeconds / factor < remainingTime)
                                {
                                    itemAmount = Math.Min((int)item.Value.Amount, Convert.ToInt32(Math.Ceiling(remainingTime / (item.Value.Blueprint.BaseProductionTimeInSeconds / factor))));
                                }
                                time += itemAmount * item.Value.Blueprint.BaseProductionTimeInSeconds / factor;
                                if (time < TIME_IN_ADVANCE)
                                {
                                    next = true;
                                }
                                var amountMult = (MyFixedPoint)(1.0f / MySession.Static.AssemblerEfficiencyMultiplier);
                                foreach (var component in item.Value.Blueprint.Prerequisites)
                                {
                                    var requiredAmount = component.Amount * itemAmount * amountMult;

                                    bool found = false;
                                    for (int j = 0; j < m_requiredComponents.Count; j++)
                                    {
                                        if (m_requiredComponents[j].Id == component.Id)
                                        {
                                            m_requiredComponents[j] = new MyBlueprintDefinitionBase.Item
                                            {
                                                Amount = m_requiredComponents[j].Amount + requiredAmount,
                                                Id     = component.Id
                                            };
                                            found = true;
                                            break;
                                        }
                                    }
                                    if (!found)
                                    {
                                        m_requiredComponents.Add(new MyBlueprintDefinitionBase.Item
                                        {
                                            Amount = requiredAmount,
                                            Id     = component.Id
                                        });
                                    }
                                }
                            }

                            i++;
                            if (i >= m_queue.Count)
                            {
                                next = false;
                            }
                        } while (next);

                        foreach (var component in m_requiredComponents)
                        {
                            var availableAmount = InputInventory.GetItemAmount(component.Id);
                            var neededAmount    = component.Amount - availableAmount;
                            if (neededAmount <= 0)
                            {
                                continue;
                            }

                            MyGridConveyorSystem.ItemPullRequest(this, InputInventory, OwnerId, component.Id, neededAmount);
                        }

                        if (IsSlave && !RepeatEnabled)
                        {
                            var remainingTime = TIME_IN_ADVANCE - time;
                            if (remainingTime > 0)
                            {
                                GetItemFromOtherAssemblers(remainingTime);
                            }
                        }
                    }

                    if (OutputInventory.VolumeFillFactor > 0.75f)
                    {
                        Debug.Assert(OutputInventory.GetItems().Count > 0);
                        MyGridConveyorSystem.PushAnyRequest(this, OutputInventory, OwnerId);
                    }
                }
            }
        }