Jump to content

[C++] Sexier way to configure your CheckSpace


Guest Ezrekith

Recommended Posts

Guest Ezrekith

Yolo!

ServerSource / game / exchange.cpp

 

Search for

bool CExchange::CheckSpace()

Replace with this and don't forget to edit it for yourself!

bool CExchange::CheckSpace()
{
  	int INVENTORY_PAGE_COUNT = 9; //your max inventory page
	int INVENTORY_PAGE_SIZE = 63; //your max inventory size (In my case its 9*7 check your inventorywindow.py slot func and make some math with it)
	CGrid* pGrids[INVENTORY_PAGE_COUNT];
	for (int i = 0; i < INVENTORY_PAGE_COUNT; ++i)
	{
		pGrids[i] = new CGrid(9, INVENTORY_PAGE_SIZE / 9); //Setup with your inventory page
		pGrids[i]->Clear();
	}

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

	for (int iPage = 0; iPage < INVENTORY_PAGE_COUNT; ++iPage)
	{
		int iAdd = iPage * INVENTORY_PAGE_SIZE;

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

			pGrids[iPage]->Put(i, 1, item->GetSize());
		}
	}

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

		bool bFree = false;
		for (int iPage = 0; iPage < INVENTORY_PAGE_COUNT; ++iPage)
		{
			int iPos = pGrids[iPage]->FindBlank(1, item->GetSize());

			if (iPos >= 0)
			{
				pGrids[iPage]->Put(iPos, 1, item->GetSize());
				bFree = true;
				break;
			}
		}

		if (!bFree)
		{
			for (int i = 0; i < INVENTORY_PAGE_COUNT; ++i)
				M2_DELETE(pGrids[i]);
			return false;
		}
	}

	for (int i = 0; i < INVENTORY_PAGE_COUNT; ++i)
		M2_DELETE(pGrids[i]);

	return true;
}

 

Edited by Ezrekith
Link to post
Share on other sites
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...