Advertisement
Guest User

checkspace_function_5th_inventory

a guest
Apr 6th, 2015
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. bool CExchange::CheckSpace()
  2. {
  3.     static CGrid s_grid1(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 1   9 Rows a 5 Columns
  4.     static CGrid s_grid2(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 2   9 Rows a 5 Columns
  5.     static CGrid s_grid3(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 3   9 Rows a 5 Columns
  6.     static CGrid s_grid4(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 4   9 Rows a 5 Columns
  7.     static CGrid s_grid5(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 5   9 Rows a 5 Columns
  8.  
  9.     s_grid1.Clear();
  10.     s_grid2.Clear();
  11.     s_grid3.Clear();
  12.     s_grid4.Clear();
  13.     s_grid5.Clear();
  14.  
  15.     LPCHARACTER victim = GetCompany()->GetOwner();
  16.     LPITEM item;
  17.  
  18.     int i;
  19.  
  20.     const int perPageSlotCount = INVENTORY_MAX_NUM / 5;
  21.  
  22.     for (i = 0; i < INVENTORY_MAX_NUM; ++i) {
  23.         if (!(item = victim->GetInventoryItem(i)))
  24.             continue;
  25.  
  26.         BYTE itemSize = item->GetSize();
  27.  
  28.         if (i < perPageSlotCount) // Notice: This is adjusted for 4 Pages only!
  29.             s_grid1.Put(i, 1, itemSize);
  30.         else if (i < perPageSlotCount * 2)
  31.             s_grid2.Put(i - perPageSlotCount, 1, itemSize);
  32.         else if (i < perPageSlotCount * 3)
  33.             s_grid3.Put(i - perPageSlotCount * 2, 1, itemSize);
  34.         else if (i < perPageSlotCount * 4)
  35.             s_grid4.Put(i - perPageSlotCount * 3, 1, itemSize);
  36.         else
  37.             s_grid5.Put(i - perPageSlotCount * 4, 1,itemSize);
  38.     }
  39.  
  40.     static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);
  41.  
  42.     bool bDSInitialized = false;
  43.  
  44.     for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
  45.     {
  46.         if (!(item = m_apItems[i]))
  47.             continue;
  48.  
  49.         BYTE itemSize = item->GetSize();
  50.  
  51.         if (item->IsDragonSoul())
  52.         {
  53.             if (!victim->DragonSoul_IsQualified())
  54.                 return false;
  55.  
  56.             if (!bDSInitialized) {
  57.                 bDSInitialized = true;
  58.                 victim->CopyDragonSoulItemGrid(s_vDSGrid);
  59.             }
  60.  
  61.             bool bExistEmptySpace = false;
  62.             WORD wBasePos = DSManager::instance().GetBasePosition(item);
  63.             if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
  64.                 return false;
  65.  
  66.             for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
  67.             {
  68.                 WORD wPos = wBasePos + i;
  69.                 if (0 == s_vDSGrid[wBasePos])
  70.                 {
  71.                     bool bEmpty = true;
  72.                     for (int j = 1; j < item->GetSize(); j++)
  73.                     {
  74.                         if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
  75.                         {
  76.                             bEmpty = false;
  77.                             break;
  78.                         }
  79.                     }
  80.                     if (bEmpty)
  81.                     {
  82.                         for (int j = 0; j < item->GetSize(); j++)
  83.                         {
  84.                             s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] = wPos + 1;
  85.                         }
  86.                         bExistEmptySpace = true;
  87.                         break;
  88.                     }
  89.                 }
  90.                 if (bExistEmptySpace)
  91.                     break;
  92.             }
  93.             if (!bExistEmptySpace)
  94.                 return false;
  95.         }
  96.         else
  97.         {
  98.             int iPos = s_grid1.FindBlank(1, itemSize);
  99.             if (iPos >= 0) {
  100.                 s_grid1.Put(iPos, 1, itemSize);
  101.                 continue;
  102.             }
  103.  
  104.             iPos = s_grid2.FindBlank(1, itemSize);
  105.             if (iPos >= 0) {
  106.                 s_grid2.Put(iPos, 1, itemSize);
  107.                 continue;
  108.             }
  109.  
  110.             iPos = s_grid3.FindBlank(1, itemSize);
  111.             if (iPos >= 0) {
  112.                 s_grid3.Put(iPos, 1, itemSize);
  113.                 continue;
  114.             }
  115.  
  116.             iPos = s_grid4.FindBlank(1, itemSize);
  117.             if (iPos >= 0) {
  118.                 s_grid4.Put(iPos, 1, itemSize);
  119.                 continue;            
  120.             }
  121.  
  122.             iPos = s_grid5.FindBlank(1, itemSize);
  123.             if (iPos >= 0) {
  124.                 s_grid5.Put(iPos, 1, itemSize);
  125.                 continue;
  126.             }
  127.  
  128.             return false;  // No space left in inventory
  129.         }
  130.     }
  131.  
  132.     return true;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement