本文整理汇总了C++中CInventory::GetNumCategories方法的典型用法代码示例。如果您正苦于以下问题:C++ CInventory::GetNumCategories方法的具体用法?C++ CInventory::GetNumCategories怎么用?C++ CInventory::GetNumCategories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CInventory
的用法示例。
在下文中一共展示了CInventory::GetNumCategories方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CopyPersistentItemsFrom
void CInventory::CopyPersistentItemsFrom(const CInventory& sourceInventory, idEntity* newOwner)
{
// Obtain the weapon category for this inventory
CInventoryCategoryPtr weaponCategory = GetCategory(TDM_PLAYER_WEAPON_CATEGORY);
// Cycle through all categories to add them
for ( int c = 0 ; c < sourceInventory.GetNumCategories() ; ++c )
{
const CInventoryCategoryPtr& category = sourceInventory.GetCategory(c);
for ( int itemIdx = 0 ; itemIdx < category->GetNumItems() ; ++itemIdx )
{
const CInventoryItemPtr& item = category->GetItem(itemIdx);
if (item->GetPersistentCount() <= 0)
{
DM_LOG(LC_INVENTORY, LT_DEBUG)LOGSTRING(
"Item %s is not marked as persistent, won't add to player inventory.\r",
common->Translate(item->GetName().c_str()));
continue; // not marked as persistent
}
// Check if the shop handled that item already
const idDict* itemDict = item->GetSavedItemEntityDict();
if (itemDict != NULL)
{
CShopItemPtr shopItem = gameLocal.m_Shop->FindShopItemDefByClassName(itemDict->GetString("classname"));
if ( (shopItem != NULL) && (CShop::GetQuantityForItem(item) > 0) )
{
// grayman #3723 - if there's no shop in this mission,
// then we can't rely on it to process this inventory item.
if ( gameLocal.m_Shop->ShopExists() )
{
DM_LOG(LC_INVENTORY, LT_DEBUG)LOGSTRING(
"Item %s would be handled by the shop, won't add that to player inventory.\r",
common->Translate(item->GetName().c_str()));
continue;
}
}
}
// Is set to true if we should add this item.
// For weapon items with ammo this will be set to false to prevent double-additions
bool addItem = true;
// Handle weapons separately, otherwise we might end up with duplicate weapon items
CInventoryWeaponItemPtr weaponItem = boost::dynamic_pointer_cast<CInventoryWeaponItem>(item);
if (weaponItem && weaponCategory)
{
// Weapon items need special consideration. For arrow-based weapons try to merge the ammo.
for ( int w = 0 ; w < weaponCategory->GetNumItems() ; ++w )
{
CInventoryWeaponItemPtr thisWeapon = boost::dynamic_pointer_cast<CInventoryWeaponItem>(weaponCategory->GetItem(w));
if (!thisWeapon)
{
continue;
}
if (thisWeapon->GetWeaponName() == weaponItem->GetWeaponName())
{
// Prevent adding this item, we already have one
addItem = false;
// Found a matching weapon, does it use ammo?
if (thisWeapon->NeedsAmmo())
{
DM_LOG(LC_INVENTORY, LT_DEBUG)LOGSTRING(
"Adding persistent ammo %d to player weapon %s.\r",
weaponItem->GetAmmo(), thisWeapon->GetWeaponName().c_str());
// Add the persistent ammo count to this item
thisWeapon->SetAmmo(thisWeapon->GetAmmo() + weaponItem->GetAmmo());
}
else
{
// Doesn't need ammo, check enabled state
if (weaponItem->IsEnabled() && !thisWeapon->IsEnabled())
{
DM_LOG(LC_INVENTORY, LT_DEBUG)LOGSTRING(
"Enabling weapon item %s as the persistent inventory contains an enabled one.\r",
thisWeapon->GetWeaponName().c_str());
thisWeapon->SetEnabled(true);
}
}
break;
}
}
}
if (addItem)
{
DM_LOG(LC_INVENTORY, LT_DEBUG)LOGSTRING(
//.........这里部分代码省略.........