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 AddChangeToSolution(MyDefinitionId removedComponentId, MyDefinitionId addedComponentId, int numChanged) { 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 - numChanged; int toChange = Math.Min(numChanged, change.Amount); numChanged -= change.Amount; if (difference > 0) { change.Amount = difference; m_solution[i] = change; } else { m_solution.RemoveAtFast(i); } if (change.IsChange()) { m_solution.Add(MyComponentChange.CreateChange(change.ToRemove, addedComponentId, toChange)); } else // change.IsAddition() { m_solution.Add(MyComponentChange.CreateAddition(addedComponentId, toChange)); } if (numChanged <= 0) { break; } } } if (numChanged > 0) { m_solution.Add(MyComponentChange.CreateChange(removedComponentId, addedComponentId, numChanged)); } }
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)); } }
private void AddChangeToSolution(MyDefinitionId removedComponentId, MyDefinitionId addedComponentId, int numChanged) { 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 - numChanged; int amount = Math.Min(numChanged, change.Amount); numChanged -= 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.CreateChange(change.ToRemove, addedComponentId, amount)); } else { this.m_solution.Add(MyComponentChange.CreateAddition(addedComponentId, amount)); } if (numChanged <= 0) { break; } } } if (numChanged > 0) { this.m_solution.Add(MyComponentChange.CreateChange(removedComponentId, addedComponentId, numChanged)); } }