Example #1
0
        private unsafe void AddToItemList(List <MyBlueprintDefinitionBase.Item> items, MyBlueprintDefinitionBase.Item toAdd)
        {
            int num = 0;

            MyBlueprintDefinitionBase.Item item = new MyBlueprintDefinitionBase.Item();
            num = 0;
            while (true)
            {
                if (num < items.Count)
                {
                    item = items[num];
                    if (item.Id != toAdd.Id)
                    {
                        num++;
                        continue;
                    }
                }
                if (num >= items.Count)
                {
                    items.Add(toAdd);
                    return;
                }
                MyFixedPoint *pointPtr1 = (MyFixedPoint *)ref item.Amount;
                pointPtr1[0] += toAdd.Amount;
                items[num]    = item;
                return;
            }
        }
Example #2
0
 private unsafe void PostprocessAddSubblueprint(MyBlueprintDefinitionBase blueprint, MyFixedPoint blueprintAmount)
 {
     for (int i = 0; i < blueprint.Prerequisites.Length; i++)
     {
         MyBlueprintDefinitionBase.Item toAdd = blueprint.Prerequisites[i];
         MyFixedPoint *pointPtr1 = (MyFixedPoint *)ref toAdd.Amount;
         pointPtr1[0] *= blueprintAmount;
         this.AddToItemList(m_tmpPrerequisiteList, toAdd);
     }
     for (int j = 0; j < blueprint.Results.Length; j++)
     {
         MyBlueprintDefinitionBase.Item toAdd = blueprint.Results[j];
         MyFixedPoint *pointPtr2 = (MyFixedPoint *)ref toAdd.Amount;
         pointPtr2[0] *= blueprintAmount;
         this.AddToItemList(m_tmpResultList, toAdd);
     }
 }
Example #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(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 && MyFakes.ENABLE_ASSEMBLER_COOPERATION && !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);
                    }
                }
            }
        }