Esempio n. 1
0
 private void AddRemovalToSolution(MyDefinitionId removedComponentId, int removeCount)
 {
     for (int i = 0; i < this.m_solution.Count; i++)
     {
         MyComponentChange change = this.m_solution[i];
         if ((change.IsChange() || change.IsAddition()) && (change.ToAdd == removedComponentId))
         {
             int num2   = change.Amount - removeCount;
             int amount = Math.Min(removeCount, change.Amount);
             removeCount -= change.Amount;
             if (num2 <= 0)
             {
                 this.m_solution.RemoveAtFast <MyComponentChange>(i);
             }
             else
             {
                 change.Amount      = num2;
                 this.m_solution[i] = change;
             }
             if (change.IsChange())
             {
                 this.m_solution.Add(MyComponentChange.CreateRemoval(change.ToRemove, amount));
             }
             if (removeCount <= 0)
             {
                 break;
             }
         }
     }
     if (removeCount > 0)
     {
         this.m_solution.Add(MyComponentChange.CreateRemoval(removedComponentId, removeCount));
     }
 }
        private void AddRemovalToSolution(MyDefinitionId removedComponentId, int removeCount)
        {
            // First search through the changes, whether some of them didn't add the given component. If so, change the change to removal
            for (int i = 0; i < m_solution.Count; ++i)
            {
                MyComponentChange change = m_solution[i];
                if ((change.IsChange() || change.IsAddition()) && change.ToAdd == removedComponentId)
                {
                    int difference = change.Amount - removeCount;
                    int toRemove   = Math.Min(removeCount, change.Amount);
                    removeCount -= change.Amount;
                    if (difference > 0)
                    {
                        change.Amount = difference;
                        m_solution[i] = change;
                    }
                    else
                    {
                        m_solution.RemoveAtFast(i);
                    }

                    if (change.IsChange())
                    {
                        m_solution.Add(MyComponentChange.CreateRemoval(change.ToRemove, toRemove));
                    }

                    if (removeCount <= 0)
                    {
                        break;
                    }
                }
            }

            if (removeCount > 0)
            {
                m_solution.Add(MyComponentChange.CreateRemoval(removedComponentId, removeCount));
            }
        }