当前位置: 首页>>代码示例>>C++>>正文


C++ cItem::GetMaxStackSize方法代码示例

本文整理汇总了C++中cItem::GetMaxStackSize方法的典型用法代码示例。如果您正苦于以下问题:C++ cItem::GetMaxStackSize方法的具体用法?C++ cItem::GetMaxStackSize怎么用?C++ cItem::GetMaxStackSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cItem的用法示例。


在下文中一共展示了cItem::GetMaxStackSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CollectItemsToHand

bool cSlotArea::CollectItemsToHand(cItem & a_Dragging, cPlayer & a_Player, bool a_CollectFullStacks)
{
	int NumSlots = GetNumSlots();
	for (int i = 0; i < NumSlots; i++)
	{
		const cItem & SlotItem = *GetSlot(i, a_Player);
		if (!SlotItem.IsEqual(a_Dragging))
		{
			continue;
		}
		int ToMove = a_Dragging.GetMaxStackSize() - a_Dragging.m_ItemCount;
		if (ToMove > SlotItem.m_ItemCount)
		{
			ToMove = SlotItem.m_ItemCount;
		}
		a_Dragging.m_ItemCount += ToMove;
		cItem NewSlot(SlotItem);
		NewSlot.m_ItemCount -= ToMove;
		SetSlot(i, a_Player, NewSlot);
		if (!NewSlot.IsEmpty())
		{
			// There are leftovers in the slot, so a_Dragging must be full
			return true;
		}
	}  // for i - Slots[]
	// a_Dragging may be full if there were exactly the number of items needed to fill it
	return a_Dragging.IsFullStack();
}
开发者ID:RedEnraged96,项目名称:MCServer-1,代码行数:28,代码来源:SlotArea.cpp

示例2: AddItem

int cItemGrid::AddItem(cItem & a_ItemStack, bool a_AllowNewStacks, int a_PrioritarySlot)
{
	int NumLeft = a_ItemStack.m_ItemCount;
	int MaxStack = a_ItemStack.GetMaxStackSize();

	// Try prioritarySlot first:
	if (
		(a_PrioritarySlot != -1) &&
		(
			m_Slots[a_PrioritarySlot].IsEmpty() ||
			m_Slots[a_PrioritarySlot].IsEqual(a_ItemStack)
		)
	)
	{
		NumLeft -= AddItemToSlot(a_ItemStack, a_PrioritarySlot, NumLeft, MaxStack);
	}

	// Scan existing stacks:
	for (int i = 0; i < m_NumSlots; i++)
	{
		if (m_Slots[i].IsEqual(a_ItemStack))
		{
			NumLeft -= AddItemToSlot(a_ItemStack, i, NumLeft, MaxStack);
		}
		if (NumLeft <= 0)
		{
			// All items fit
			return a_ItemStack.m_ItemCount;
		}
	}  // for i - m_Slots[]

	if (!a_AllowNewStacks)
	{
		return (a_ItemStack.m_ItemCount - NumLeft);
	}

	for (int i = 0; i < m_NumSlots; i++)
	{
		if (m_Slots[i].IsEmpty())
		{
			NumLeft -= AddItemToSlot(a_ItemStack, i, NumLeft, MaxStack);
		}
		if (NumLeft <= 0)
		{
			// All items fit
			return a_ItemStack.m_ItemCount;
		}
	}  // for i - m_Slots[]
	return (a_ItemStack.m_ItemCount - NumLeft);
}
开发者ID:1285done,项目名称:cuberite,代码行数:50,代码来源:ItemGrid.cpp


注:本文中的cItem::GetMaxStackSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。