Jump to content

Proper 4th Inventory CExchange::CheckSpace function


Recommended Posts

I read the version of CBaran (The old one which he now edited away and corrected after i posted) and it didnt really make a lot of sense to me so well here is mine:

 

If someone is able to test this great i did not because we dont need 4 inventories at WoM :D

 

bool CExchange::CheckSpace()
{
	static CGrid s_grid1(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 1   9 Rows a 5 Columns
	static CGrid s_grid2(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 2   9 Rows a 5 Columns
	static CGrid s_grid3(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 3   9 Rows a 5 Columns
	static CGrid s_grid4(5, INVENTORY_MAX_NUM / 5 / 4); // inven page 4   9 Rows a 5 Columns

	s_grid1.Clear();
	s_grid2.Clear();
	s_grid3.Clear();
	s_grid4.Clear();

	LPCHARACTER	victim = GetCompany()->GetOwner();
	LPITEM item;

	int i;

	const int perPageSlotCount = INVENTORY_MAX_NUM / 4;

	for (i = 0; i < INVENTORY_MAX_NUM; ++i) {
		if (!(item = victim->GetInventoryItem(i)))
			continue;

		BYTE itemSize = item->GetSize();

		if (i < perPageSlotCount) // Notice: This is adjusted for 4 Pages only!
			s_grid1.Put(i, 1, itemSize);
		else if (i < perPageSlotCount * 2)
			s_grid2.Put(i - perPageSlotCount, 1, itemSize);
		else if (i < perPageSlotCount * 3)
			s_grid3.Put(i - perPageSlotCount * 2, 1, itemSize);
		else
			s_grid4.Put(i - perPageSlotCount * 3, 1, itemSize);
	}

	static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);

	bool bDSInitialized = false;

	for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
	{
		if (!(item = m_apItems[i]))
			continue;

		BYTE itemSize = item->GetSize();

		if (item->IsDragonSoul())
		{
			if (!victim->DragonSoul_IsQualified())
				return false;

			if (!bDSInitialized) {
				bDSInitialized = true;
				victim->CopyDragonSoulItemGrid(s_vDSGrid);
			}

			bool bExistEmptySpace = false;
			WORD wBasePos = DSManager::instance().GetBasePosition(item);
			if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
				return false;

			for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
			{
				WORD wPos = wBasePos + i;
				if (0 == s_vDSGrid[wBasePos])
				{
					bool bEmpty = true;
					for (int j = 1; j < item->GetSize(); j++)
					{
						if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
						{
							bEmpty = false;
							break;
						}
					}
					if (bEmpty)
					{
						for (int j = 0; j < item->GetSize(); j++)
						{
							s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] = wPos + 1;
						}
						bExistEmptySpace = true;
						break;
					}
				}
				if (bExistEmptySpace)
					break;
			}
			if (!bExistEmptySpace)
				return false;
		}
		else
		{
			int iPos = s_grid1.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid1.Put(iPos, 1, itemSize);
				continue;
			}

			iPos = s_grid2.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid2.Put(iPos, 1, itemSize);
				continue;
			}

			iPos = s_grid3.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid3.Put(iPos, 1, itemSize);
				continue;
			}

			iPos = s_grid4.FindBlank(1, itemSize);
			if (iPos >= 0) {
				s_grid4.Put(iPos, 1, itemSize);
				continue;
			}

			return false;  // No space left in inventory
		}
	}

	return true;
}

PS: If there are any errors please report them asap because i have no way to test this.

 

Kind regards

MartPwnS

bool CExchange::CheckSpace() // vagabond20 4 env.
{
	static CGrid s_grid1(5, INVENTORY_MAX_NUM/5 / 4); // inven page 1
	static CGrid s_grid2(5, INVENTORY_MAX_NUM/5 / 4); // inven page 2
	static CGrid s_grid3(5, INVENTORY_MAX_NUM/5 / 4); // inven page 3
	static CGrid s_grid4(5, INVENTORY_MAX_NUM/5 / 4); // inven page 4

	s_grid1.Clear();
	s_grid2.Clear();
	s_grid3.Clear();
	s_grid4.Clear();

	LPCHARACTER	victim = GetCompany()->GetOwner();
	LPITEM item;

	int i;

	for (i = 0; i < INVENTORY_MAX_NUM / 4; ++i)
	{
		if (!(item = victim->GetInventoryItem(i)))
			continue;

		s_grid1.Put(i, 1, item->GetSize());
	}
	for (i = INVENTORY_MAX_NUM / 4; i < INVENTORY_MAX_NUM / 2; ++i)
	{
		if (!(item = victim->GetInventoryItem(i)))
			continue;

		s_grid2.Put(i - INVENTORY_MAX_NUM / 4, 1, item->GetSize());
	}
	for (i = INVENTORY_MAX_NUM / 2; i < (INVENTORY_MAX_NUM / 4) * 3; ++i)
	{
		if (!(item = victim->GetInventoryItem(i)))
			continue;

		s_grid3.Put(i - INVENTORY_MAX_NUM / 2, 1, item->GetSize());
	}
	for (i = (INVENTORY_MAX_NUM / 4) * 3; i < INVENTORY_MAX_NUM; ++i)
	{
		if (!(item = victim->GetInventoryItem(i)))
			continue;

		s_grid4.Put(i - (INVENTORY_MAX_NUM / 4) * 3, 1, item->GetSize());
	}

	// ¾Æ... ¹º°¡ °³º´½Å °°Áö¸¸... ¿ëÈ¥¼® Àκ¥À» ³ë¸Ö Àκ¥ º¸°í µû¶ó ¸¸µç ³» À߸øÀÌ´Ù ¤Ğ¤Ğ
	static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);
	
	// ÀÏ´Ü ¿ëÈ¥¼®À» ±³È¯ÇÏÁö ¾ÊÀ» °¡´É¼ºÀÌ Å©¹Ç·Î, ¿ëÈ¥¼® Àκ¥ º¹»ç´Â ¿ëÈ¥¼®ÀÌ ÀÖÀ» ¶§ Çϵµ·Ï ÇÑ´Ù.
	bool bDSInitialized = false;
	
	for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
	{
		if (!(item = m_apItems[i]))
			continue;

		if (item->IsDragonSoul())
		{
			if (!victim->DragonSoul_IsQualified())
			{
				return false;
			}

			if (!bDSInitialized)
			{
				bDSInitialized = true;
				victim->CopyDragonSoulItemGrid(s_vDSGrid);
			}

			bool bExistEmptySpace = false;
			WORD wBasePos = DSManager::instance().GetBasePosition(item);
			if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
				return false;
			
			for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
			{
				WORD wPos = wBasePos + i;
				if (0 == s_vDSGrid[wBasePos])
				{
					bool bEmpty = true;
					for (int j = 1; j < item->GetSize(); j++)
					{
						if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
						{
							bEmpty = false;
							break;
						}
					}
					if (bEmpty)
					{
						for (int j = 0; j < item->GetSize(); j++)
						{
							s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] =  wPos + 1;
						}
						bExistEmptySpace = true;
						break;
					}
				}
				if (bExistEmptySpace)
					break;
			}
			if (!bExistEmptySpace)
				return false;
		}
		else
		{
			int iPos = s_grid1.FindBlank(1, item->GetSize());

			if (iPos >= 0)
			{
				s_grid1.Put(iPos, 1, item->GetSize());
			}
			else
			{
				iPos = s_grid2.FindBlank(1, item->GetSize());

				if (iPos >= 0)
				{
					s_grid2.Put(iPos, 1, item->GetSize());
				}
				else
				{
					iPos = s_grid3.FindBlank(1, item->GetSize());
 
					if (iPos >= 0)
					{
						s_grid3.Put(iPos, 1, item->GetSize());
					}
					else
					{
						iPos = s_grid4.FindBlank(1, item->GetSize());

						if (iPos >= 0)
						{
							s_grid4.Put(iPos, 1, item->GetSize());
						}
						else
						{
							return false;
						}
					}
				}
			}
		}
	}

	return true;
}

 :D

  • Love 1
Link to comment
Share on other sites

  • Premium

Please help me.


 
exchange.cpp:429: error: expected unqualified-id before 'for'
exchange.cpp:429: error: expected constructor, destructor, or type conversion before '<' token
exchange.cpp:429: error: expected unqualified-id before '++' token
 
429=  for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
Link to comment
Share on other sites

  • Premium

 

Please help me.

 
exchange.cpp:429: error: expected unqualified-id before 'for'
exchange.cpp:429: error: expected constructor, destructor, or type conversion before '<' token
exchange.cpp:429: error: expected unqualified-id before '++' token
 
429=  for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)

 

 

What is that "429="? Remove it o.O

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 1 month later...

code for 5 inventory? please post plis e iam noob c++ :P

bool CExchange::CheckSpace()
{
    static CGrid s_grid1(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 1   9 Rows a 5 Columns
    static CGrid s_grid2(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 2   9 Rows a 5 Columns
    static CGrid s_grid3(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 3   9 Rows a 5 Columns
    static CGrid s_grid4(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 4   9 Rows a 5 Columns
    static CGrid s_grid5(5, INVENTORY_MAX_NUM / 5 / 5); // inven page 5   9 Rows a 5 Columns


    s_grid1.Clear();
    s_grid2.Clear();
    s_grid3.Clear();
    s_grid4.Clear();
    s_grid5.Clear();


    LPCHARACTER victim = GetCompany()->GetOwner();
    LPITEM item;


    int i;


    const int perPageSlotCount = INVENTORY_MAX_NUM / 5;


    for (i = 0; i < INVENTORY_MAX_NUM; ++i) {
        if (!(item = victim->GetInventoryItem(i)))
            continue;


        BYTE itemSize = item->GetSize();


        if (i < perPageSlotCount) // Notice: This is adjusted for 4 Pages only!
            s_grid1.Put(i, 1, itemSize);
        else if (i < perPageSlotCount * 2)
            s_grid2.Put(i - perPageSlotCount, 1, itemSize);
        else if (i < perPageSlotCount * 3)
            s_grid3.Put(i - perPageSlotCount * 2, 1, itemSize);
        else if (i < perPageSlotCount * 3)
            s_grid4.Put(i - perPageSlotCount * 3, 1, itemSize);
        else
            s_grid5.Put(i - perPageSlotCount * 4, 1, itemSize);
    }


    static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);


    bool bDSInitialized = false;


    for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
    {
        if (!(item = m_apItems[i]))
            continue;


        BYTE itemSize = item->GetSize();


        if (item->IsDragonSoul())
        {
            if (!victim->DragonSoul_IsQualified())
                return false;


            if (!bDSInitialized) {
                bDSInitialized = true;
                victim->CopyDragonSoulItemGrid(s_vDSGrid);
            }


            bool bExistEmptySpace = false;
            WORD wBasePos = DSManager::instance().GetBasePosition(item);
            if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
                return false;


            for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
            {
                WORD wPos = wBasePos + i;
                if (0 == s_vDSGrid[wBasePos])
                {
                    bool bEmpty = true;
                    for (int j = 1; j < item->GetSize(); j++)
                    {
                        if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
                        {
                            bEmpty = false;
                            break;
                        }
                    }
                    if (bEmpty)
                    {
                        for (int j = 0; j < item->GetSize(); j++)
                        {
                            s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] = wPos + 1;
                        }
                        bExistEmptySpace = true;
                        break;
                    }
                }
                if (bExistEmptySpace)
                    break;
            }
            if (!bExistEmptySpace)
                return false;
        }
        else
        {
            int iPos = s_grid1.FindBlank(1, itemSize);
            if (iPos >= 0) {
                s_grid1.Put(iPos, 1, itemSize);
                continue;
            }


            iPos = s_grid2.FindBlank(1, itemSize);
            if (iPos >= 0) {
                s_grid2.Put(iPos, 1, itemSize);
                continue;
            }


            iPos = s_grid3.FindBlank(1, itemSize);
            if (iPos >= 0) {
                s_grid3.Put(iPos, 1, itemSize);
                continue;
            }


            iPos = s_grid4.FindBlank(1, itemSize);
            if (iPos >= 0) {
                s_grid4.Put(iPos, 1, itemSize);
                continue;
            }


            iPos = s_grid5.FindBlank(1, itemSize);
            if (iPos >= 0) {
                s_grid5.Put(iPos, 1, itemSize);
                continue;
            }


            return false;  // No space left in inventory
        }
    }


    return true;
}
Link to comment
Share on other sites

  • 1 month later...
  • Premium

i have 5 inventory but now i don't can add itens on Belt_system any one can help me ? 

So, we have:

  • 5 inventory, each 45 slots
  • 32 equipment slots
  • 30 DS slots
  • 16 belt slots

And we are allowed to 255 maximum slots because the type of position is BYTE.

Let's calculate your total amount of slots: (5 x 45) + 32 + 30 + 16 = 303. 303 is way bigger than 255. And as I see, you can't even use DS slots because inventory + equipment slots = 257. Stop destroying your game. Think about it.

Link to comment
Share on other sites

  • Former Staff

i have 5 inventory but now i don't can add itens on Belt_system any one can help me ? 

So, we have:

  • 5 inventory, each 45 slots
  • 32 equipment slots
  • 30 DS slots
  • 16 belt slots

And we are allowed to 255 maximum slots because the type of position is BYTE.

Let's calculate your total amount of slots: (5 x 45) + 32 + 30 + 16 = 303. 303 is way bigger than 255. And as I see, you can't even use DS slots because inventory + equipment slots = 257. Stop destroying your game. Think about it.

And if I want to take ds slots?

Link to comment
Share on other sites

  • Premium

i have 5 inventory but now i don't can add itens on Belt_system any one can help me ? 

So, we have:

  • 5 inventory, each 45 slots
  • 32 equipment slots
  • 30 DS slots
  • 16 belt slots

And we are allowed to 255 maximum slots because the type of position is BYTE.

Let's calculate your total amount of slots: (5 x 45) + 32 + 30 + 16 = 303. 303 is way bigger than 255. And as I see, you can't even use DS slots because inventory + equipment slots = 257. Stop destroying your game. Think about it.

And if I want to take ds slots?

With the 5 inventory you can't even use whole equipment.

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.