private bool RemoveItemsInternal(int index, int count)
        {
            if (index >= m_items.Count())
            {
                return(false);
            }

            if (m_items[index].Amount == count)
            {
                MyStockpileItem syncItem = m_items[index];
                syncItem.Amount = -syncItem.Amount;

                AddSyncItem(syncItem);
                m_items.RemoveAt(index);
                return(true);
            }
            else if (count < m_items[index].Amount)
            {
                MyStockpileItem item = new MyStockpileItem();
                item.Amount    = m_items[index].Amount - count;
                item.Content   = m_items[index].Content;
                m_items[index] = item;

                MyStockpileItem syncItem = new MyStockpileItem();
                syncItem.Content = item.Content;
                syncItem.Amount  = -count;
                AddSyncItem(syncItem);
                return(true);
            }
            Debug.Assert(count < m_items[index].Amount, "Removing more items from the construction stockpile than how many are contained in it");
            return(false);
        }
Example #2
0
        private void AddSyncItem(MyStockpileItem diffItem)
        {
            int num = 0;

            using (List <MyStockpileItem> .Enumerator enumerator = m_syncItems.GetEnumerator())
            {
                while (true)
                {
                    if (!enumerator.MoveNext())
                    {
                        break;
                    }
                    MyStockpileItem current = enumerator.Current;
                    if (!current.Content.CanStack(diffItem.Content))
                    {
                        num++;
                        continue;
                    }
                    MyStockpileItem item2 = new MyStockpileItem {
                        Amount  = current.Amount + diffItem.Amount,
                        Content = current.Content
                    };
                    m_syncItems[num] = item2;
                    return;
                }
            }
            m_syncItems.Add(diffItem);
        }
Example #3
0
        private unsafe bool RemoveItemsInternal(int index, int count)
        {
            if (index >= this.m_items.Count)
            {
                return(false);
            }
            if (this.m_items[index].Amount == count)
            {
                MyStockpileItem  item     = this.m_items[index];
                MyStockpileItem *itemPtr1 = (MyStockpileItem *)ref item;
                itemPtr1->Amount = -item.Amount;
                this.AddSyncItem(item);
                this.m_items.RemoveAt(index);
                return(true);
            }
            if (count >= this.m_items[index].Amount)
            {
                return(false);
            }
            MyStockpileItem item2 = new MyStockpileItem {
                Amount  = this.m_items[index].Amount - count,
                Content = this.m_items[index].Content
            };

            this.m_items[index] = item2;
            MyStockpileItem diffItem = new MyStockpileItem {
                Content = item2.Content,
                Amount  = -count
            };

            this.AddSyncItem(diffItem);
            return(true);
        }
        public bool AddItems(int count, MyObjectBuilder_PhysicalObject physicalObject)
        {
            int index = 0;

            foreach (var item in m_items)
            {
                if (item.Content.CanStack(physicalObject))
                {
                    break;
                }
                index++;
            }
            if (index == m_items.Count())
            {
                Debug.Assert(count < int.MaxValue, "Trying to add more items into construction stockpile than int.MaxValue");
                if (count >= int.MaxValue)
                {
                    return(false);
                }

                MyStockpileItem item = new MyStockpileItem();
                item.Amount  = (int)count;
                item.Content = physicalObject;
                m_items.Add(item);
                AddSyncItem(item);
                return(true);
            }
            else
            {
                Debug.Assert((long)m_items[index].Amount + count < int.MaxValue, "Trying to add more items into construction stockpile than int.MaxValue");
                if ((long)m_items[index].Amount + count >= int.MaxValue)
                {
                    return(false);
                }

                MyStockpileItem item = new MyStockpileItem();
                item.Amount    = (int)(m_items[index].Amount + count);
                item.Content   = m_items[index].Content;
                m_items[index] = item;

                MyStockpileItem syncItem = new MyStockpileItem();
                syncItem.Content = m_items[index].Content;
                syncItem.Amount  = (int)count;
                AddSyncItem(syncItem);
                return(true);
            }

            return(false);
        }
Example #5
0
        public MyObjectBuilder_ConstructionStockpile GetObjectBuilder()
        {
            MyObjectBuilder_ConstructionStockpile stockpile = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ConstructionStockpile>();

            stockpile.Items = new MyObjectBuilder_StockpileItem[this.m_items.Count];
            for (int i = 0; i < this.m_items.Count; i++)
            {
                MyStockpileItem item = this.m_items[i];
                MyObjectBuilder_StockpileItem item2 = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_StockpileItem>();
                item2.Amount          = item.Amount;
                item2.PhysicalContent = item.Content;
                stockpile.Items[i]    = item2;
            }
            return(stockpile);
        }
Example #6
0
 public void Init(MyObjectBuilder_Inventory objectBuilder)
 {
     this.m_items.Clear();
     if (objectBuilder != null)
     {
         foreach (MyObjectBuilder_InventoryItem item in objectBuilder.Items)
         {
             if (item.Amount > 0)
             {
                 MyStockpileItem item2 = new MyStockpileItem {
                     Amount  = (int)item.Amount,
                     Content = item.PhysicalContent
                 };
                 this.m_items.Add(item2);
             }
         }
     }
 }
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            m_items.Clear();

            if (objectBuilder == null)
                return;

            foreach (var item in objectBuilder.Items)
            {
                if (item.Amount > 0)
                {
                    MyStockpileItem newItem = new MyStockpileItem();
                    newItem.Amount = (int)(item.Amount);
                    newItem.Content = item.PhysicalContent;
                    m_items.Add(newItem);
                }
            }
        }
Example #8
0
 public int GetItemAmount(MyDefinitionId contentId, MyItemFlags flags = 0)
 {
     using (List <MyStockpileItem> .Enumerator enumerator = this.m_items.GetEnumerator())
     {
         while (true)
         {
             if (!enumerator.MoveNext())
             {
                 break;
             }
             MyStockpileItem current = enumerator.Current;
             if (current.Content.CanStack(contentId.TypeId, contentId.SubtypeId, flags))
             {
                 return(current.Amount);
             }
         }
     }
     return(0);
 }
        private void AddSyncItem(MyStockpileItem diffItem)
        {
            int index = 0;

            foreach (var item in m_syncItems)
            {
                if (item.Content.CanStack(diffItem.Content))
                {
                    var tmpItem = new MyStockpileItem();
                    tmpItem.Amount     = item.Amount + diffItem.Amount;
                    tmpItem.Content    = item.Content;
                    m_syncItems[index] = tmpItem;
                    return;
                }
                index++;
            }

            m_syncItems.Add(diffItem);
        }
Example #10
0
        public bool AddItems(int count, MyObjectBuilder_PhysicalObject physicalObject)
        {
            int num = 0;

            using (List <MyStockpileItem> .Enumerator enumerator = this.m_items.GetEnumerator())
            {
                while (enumerator.MoveNext() && !enumerator.Current.Content.CanStack(physicalObject))
                {
                    num++;
                }
            }
            if (num == this.m_items.Count)
            {
                if (count >= 0x7fffffff)
                {
                    return(false);
                }
                MyStockpileItem item = new MyStockpileItem {
                    Amount  = count,
                    Content = physicalObject
                };
                this.m_items.Add(item);
                this.AddSyncItem(item);
                return(true);
            }
            if ((this.m_items[num].Amount + count) >= 0x7fffffffL)
            {
                return(false);
            }
            MyStockpileItem item2 = new MyStockpileItem {
                Amount  = this.m_items[num].Amount + count,
                Content = this.m_items[num].Content
            };

            this.m_items[num] = item2;
            MyStockpileItem diffItem = new MyStockpileItem {
                Content = this.m_items[num].Content,
                Amount  = count
            };

            this.AddSyncItem(diffItem);
            return(true);
        }
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            m_items.Clear();

            if (objectBuilder == null)
            {
                return;
            }

            foreach (var item in objectBuilder.Items)
            {
                if (item.Amount > 0)
                {
                    MyStockpileItem newItem = new MyStockpileItem();
                    newItem.Amount  = (int)(item.Amount);
                    newItem.Content = item.PhysicalContent;
                    m_items.Add(newItem);
                }
            }
        }
Example #12
0
        internal unsafe void Change(List <MyStockpileItem> items)
        {
            int count = this.m_items.Count;

            foreach (MyStockpileItem item in items)
            {
                int num2 = 0;
                while (true)
                {
                    if (num2 < count)
                    {
                        if (!this.m_items[num2].Content.CanStack(item.Content))
                        {
                            num2++;
                            continue;
                        }
                        MyStockpileItem item2   = this.m_items[num2];
                        int *           numPtr1 = (int *)ref item2.Amount;
                        numPtr1[0]        += item.Amount;
                        this.m_items[num2] = item2;
                    }
                    if (num2 == count)
                    {
                        MyStockpileItem item3 = new MyStockpileItem {
                            Amount  = item.Amount,
                            Content = item.Content
                        };
                        this.m_items.Add(item3);
                    }
                    break;
                }
            }
            for (int i = this.m_items.Count - 1; i >= 0; i--)
            {
                if (this.m_items[i].Amount == 0)
                {
                    this.m_items.RemoveAtFast <MyStockpileItem>(i);
                }
            }
        }
        internal void Change(List <MyStockpileItem> items)
        {
            // We don't have to iterate over the newly added items, as they should not be stackable (server would have sent them together)
            int originalCount = m_items.Count();

            foreach (var diffItem in items)
            {
                int i;
                for (i = 0; i < originalCount; ++i)
                {
                    if (m_items[i].Content.CanStack(diffItem.Content))
                    {
                        MyStockpileItem changedItem = m_items[i];
                        changedItem.Amount += diffItem.Amount;
                        m_items[i]          = changedItem;
                        break;
                    }
                }
                if (i == originalCount)
                {
                    MyStockpileItem changedItem = new MyStockpileItem();
                    changedItem.Amount  = diffItem.Amount;
                    changedItem.Content = diffItem.Content;
                    m_items.Add(changedItem);
                }
            }

            // Remove items with zero count
            for (int i = m_items.Count() - 1; i >= 0; --i)
            {
                if (m_items[i].Amount == 0)
                {
                    m_items.RemoveAtFast(i);
                }
            }
        }
        private bool RemoveItemsInternal(int index, int count)
        {
            if (index >= m_items.Count()) return false;

            if (m_items[index].Amount == count)
            {
                MyStockpileItem syncItem = m_items[index];
                syncItem.Amount = -syncItem.Amount;

                AddSyncItem(syncItem);
                m_items.RemoveAt(index);
                return true;
            }
            else if (count < m_items[index].Amount)
            {
                MyStockpileItem item = new MyStockpileItem();
                item.Amount = m_items[index].Amount - count;
                item.Content = m_items[index].Content;
                m_items[index] = item;

                MyStockpileItem syncItem = new MyStockpileItem();
                syncItem.Content = item.Content;
                syncItem.Amount = -count;
                AddSyncItem(syncItem);
                return true;
            }
            Debug.Assert(count < m_items[index].Amount, "Removing more items from the construction stockpile than how many are contained in it");
            return false;
        }
        public bool AddItems(int count, MyObjectBuilder_PhysicalObject physicalObject)
        {
            int index = 0;
            foreach (var item in m_items)
            {
                if (item.Content.CanStack(physicalObject))
                    break;
                index++;
            }
            if (index == m_items.Count())
            {
                Debug.Assert(count < int.MaxValue, "Trying to add more items into construction stockpile than int.MaxValue");
                if (count >= int.MaxValue) return false;

                MyStockpileItem item = new MyStockpileItem();
                item.Amount = (int)count;
                item.Content = physicalObject;
                m_items.Add(item);
                AddSyncItem(item);
                return true;
            }
            else
            {
                Debug.Assert((long)m_items[index].Amount + count < int.MaxValue, "Trying to add more items into construction stockpile than int.MaxValue");
                if ((long)m_items[index].Amount + count >= int.MaxValue) return false;

                MyStockpileItem item = new MyStockpileItem();
                item.Amount = (int)(m_items[index].Amount + count);
                item.Content = m_items[index].Content;
                m_items[index] = item;

                MyStockpileItem syncItem = new MyStockpileItem();
                syncItem.Content = m_items[index].Content;
                syncItem.Amount = (int)count;
                AddSyncItem(syncItem);
                return true;
            }

            return false;
        }
        private void AddSyncItem(MyStockpileItem diffItem)
        {
            int index = 0;
            foreach (var item in m_syncItems)
            {
                if (item.Content.CanStack(diffItem.Content))
                {
                    var tmpItem = new MyStockpileItem();
                    tmpItem.Amount = item.Amount + diffItem.Amount;
                    tmpItem.Content = item.Content;
                    m_syncItems[index] = tmpItem;
                    return;
                }
                index++;
            }

            m_syncItems.Add(diffItem);
        }
        internal void Change(List<MyStockpileItem> items)
        {
            // We don't have to iterate over the newly added items, as they should not be stackable (server would have sent them together)
            int originalCount = m_items.Count();

            foreach (var diffItem in items)
            {
                int i;
                for (i = 0; i < originalCount; ++i)
                {
                    if (m_items[i].Content.CanStack(diffItem.Content))
                    {
                        MyStockpileItem changedItem = m_items[i];
                        changedItem.Amount += diffItem.Amount;
                        m_items[i] = changedItem;
                        break;
                    }
                }
                if (i == originalCount)
                {
                    MyStockpileItem changedItem = new MyStockpileItem();
                    changedItem.Amount = diffItem.Amount;
                    changedItem.Content = diffItem.Content;
                    m_items.Add(changedItem);
                }
            }

            // Remove items with zero count
            for (int i = m_items.Count() - 1; i >= 0; --i)
            {
                if (m_items[i].Amount == 0)
                {
                    m_items.RemoveAtFast(i);
                }
            }
        }