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


C++ CInventory::GetAccessory方法代码示例

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


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

示例1: if

/*template <class EventHandlerFunc> */void CGameStateRecorder::CheckInventory(CActor* pActor, IItem *pItem)//, EventHandlerFunc eventHandler)
{

    if(pActor)
    {
        TGameStates::iterator itGS;
        if(pActor->IsPlayer())
            itGS = m_itSingleActorGameState;
        else if(pActor->GetEntity())
            itGS = m_GameStates.find(pActor->GetEntity()->GetId());
        else
            return;

        if(itGS != m_GameStates.end())
        {
            SActorGameState& gstate = itGS->second;

            // items

            CInventory *pInventory = (CInventory*)(pActor->GetInventory());
            if(pInventory)
            {
                bool bSingleItem = (pItem!=0);
                int nInvItems = (bSingleItem ? 1 : pInventory->GetCount());
                TItemContainer& Items = gstate.Items;
                
                for(int i=0; i< nInvItems; i++)
                {
                    if(!bSingleItem) 
                        pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pInventory->GetItem(i));

                    if(pItem)
                    {
                        TItemName szItemName = GetItemName(pItem->GetEntityId());

                        TItemContainer::iterator it = Items.find(szItemName);
                        if(it==Items.end())
                        {
                            it = (Items.insert(std::make_pair(szItemName,SItemProperties()))).first;

                            GameplayEvent event;
                            event.event = eGE_ItemPickedUp;
                            event.description = szItemName;
                            //eventHandler(pActor,event);
                            SendGamePlayEvent(pActor->GetEntity(),event);

                            SItemProperties& recItem = it->second;
                            CWeapon *pWeapon = (CWeapon*)(pItem->GetIWeapon());
                            if(pWeapon)
                            {
                                // ammo
                                for(SWeaponAmmo weaponAmmo = pWeapon->GetFirstAmmo(); weaponAmmo.pAmmoClass ; weaponAmmo = pWeapon->GetNextAmmo())
                                {
                                    int ammoCount = weaponAmmo.count;
                                    string ammoClass;
                                    if(weaponAmmo.pAmmoClass && (ammoClass = weaponAmmo.pAmmoClass->GetName()))
                                    {
                                        TAmmoContainer& recAmmo = recItem.Ammo;

                                        if(recAmmo.find(ammoClass) == recAmmo.end())
                                            recAmmo.insert(std::make_pair(ammoClass,0));
                                        int recAmmoCount = recAmmo[ammoClass];
                                        if(ammoCount!=recAmmoCount)
                                        {
                                            GameplayEvent event;
                                            event.event = eGE_AmmoCount;
                                            event.value = (float)ammoCount;
                                            event.extra = (void*)(ammoClass.c_str());
                                            event.description = (const char*)szItemName;
                                            //eventHandler(pActor,event);
                                            SendGamePlayEvent(pActor->GetEntity(),event);

                                        }
                                    }
                                }
                                // current fire mode
                                int curFireModeIdx = pWeapon->GetCurrentFireMode();
                                int recFireModeIdx = recItem.fireMode;
                                if(curFireModeIdx!= recFireModeIdx)
                                {
                                    GameplayEvent event;
                                    event.event = eGE_WeaponFireModeChanged;
                                    event.value = (float)curFireModeIdx;
                                    event.description = (const char*)szItemName;
                                    //eventHandler(pActor,event);
                                    SendGamePlayEvent(pActor->GetEntity(),event);
                                }
                            }
                        }
                    }
                }

                /// Accessories

                int nInvAccessories = pInventory->GetAccessoryCount();

                TAccessoryContainer& Accessories = gstate.Accessories;
                int nRecAccessories = Accessories.size();

                for(int j=0 ; j< nInvAccessories; j++)
//.........这里部分代码省略.........
开发者ID:kitnet,项目名称:project-o,代码行数:101,代码来源:GameStateRecorder.cpp

示例2: DumpWholeGameState

void CGameStateRecorder::DumpWholeGameState(const CActor* pActor)
{
    GameplayEvent event;
    IEntity* pEntity = pActor->GetEntity();
    
    // health
    float health = (float)pActor->GetHealth();
    event.event = eGE_HealthChanged;
    event.value = health;
    SendGamePlayEvent(pEntity,event);
    
    // Inventory
    CInventory *pInventory = (CInventory*)(pActor->GetInventory());
    if(!pInventory)
        return;

    int count = pInventory->GetCount();
    for(int i=0; i<count; ++i)
    {
        EntityId itemId = pInventory->GetItem(i);
        
        CItem* pItem=NULL;
        TItemName itemName = GetItemName(itemId,&pItem);
        if(pItem && itemName)	
        {
            event.event = eGE_ItemPickedUp;
            event.description = itemName;
            SendGamePlayEvent(pEntity,event);

            if(pActor->GetCurrentItem() == pItem)
            {
                event.event = eGE_ItemSelected;
                event.description = itemName;
                event.value = 1; // for initialization
                SendGamePlayEvent(pEntity,event);
            }
            
            CWeapon* pWeapon = (CWeapon*)(pItem->GetIWeapon());
            if(pWeapon)
            {
                IEntityClass* pItemClass = pWeapon->GetEntity()->GetClass();
                if(pItemClass && !strcmpi(pItemClass->GetName(),"binoculars"))
                    continue; // no fire mode or ammo recorded for binocular (which is a weapon)

                // fire mode
                int fireModeIdx = pWeapon->GetCurrentFireMode();

                event.event = eGE_WeaponFireModeChanged;
                event.value = (float)fireModeIdx;
                event.description = itemName;
                SendGamePlayEvent(pEntity,event);
                // count ammo
                for(SWeaponAmmo weaponAmmo = pWeapon->GetFirstAmmo(); weaponAmmo.pAmmoClass ; weaponAmmo = pWeapon->GetNextAmmo())
                {
                    const char* ammoClass;
                    if(weaponAmmo.pAmmoClass && (ammoClass = weaponAmmo.pAmmoClass->GetName()))
                    {
                        event.event = eGE_AmmoCount;
                        event.value = (float)weaponAmmo.count;
                        event.extra = (void*)ammoClass;
                        event.description = (const char*)itemName;
                        SendGamePlayEvent(pEntity,event);
                    }
                }
            }
        }
    }

    count = pInventory->GetAccessoryCount();

    for(int i=0; i< count; i++)
    {
        const char* accessory = pInventory->GetAccessory(i);
        if(accessory && strlen(accessory))	
        {
            IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(accessory);
            if(pClass)
            {
                TItemName classItem = pClass->GetName();
                event.event = eGE_AccessoryPickedUp;
                //event.value = classIdx;
                event.description = classItem;
                SendGamePlayEvent(pEntity,event);
            }
        }
    }

    int nInvAmmo = pInventory->GetAmmoPackCount();
    pInventory->AmmoIteratorFirst();
    for(int j=0 ; !pInventory->AmmoIteratorEnd(); j++, pInventory->AmmoIteratorNext())
    {
        const IEntityClass* pAmmoClass = pInventory->AmmoIteratorGetClass();
        if(pAmmoClass)
        {
            const char* ammoClassName = pAmmoClass->GetName();
            int ammoCount = pInventory->AmmoIteratorGetCount();
            GameplayEvent event;
            event.event = eGE_AmmoPickedUp;
            event.description = ammoClassName;
            event.value = (float)ammoCount;
//.........这里部分代码省略.........
开发者ID:kitnet,项目名称:project-o,代码行数:101,代码来源:GameStateRecorder.cpp

示例3: RenderInfo


//.........这里部分代码省略.........
                                                bool bError2 = ammoCount!=recAmmoCount;
                                                pRenderer->Draw2dLabel( xp+xa,y+retY, 1.3f, bError2? fColorWarning : fColor, false,"Am%d:%d",idx,ammoCount);
                                                pRenderer->Draw2dLabel( xri+xa,y+retY, 1.3f, bError2? fColorWarning : fColor, false,"Am%d:%d",idx,recAmmoCount);
                                                xa += 50;
                                                ++idx;
                                                if(idx%5 ==0)
                                                {
                                                    xa=0;
                                                    retY+=15;
                                                }
                                            }
                                        }
                                    }

                                    // current fire mode
                                    int curFireModeIdx = pWeapon->GetCurrentFireMode();
                                    int recFireModeIdx = recItem.fireMode;
                                    bool bError3 = curFireModeIdx!= recFireModeIdx;
                                    pRenderer->Draw2dLabel( xp+xa,y+retY, 1.3f, bError3? fColorWarning : fColor, false,"FMode:%d",curFireModeIdx);
                                    pRenderer->Draw2dLabel( xri+xa,y+retY, 1.3f, bError3? fColorWarning : fColor, false,"FMode:%d",recFireModeIdx);
                                }
                                else
                                {
                                    pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor, false, "Ok");
                                }
                            }

                        }
                        retY +=15;
                    }

                    /// Accessories

                    int nInvAccessories = pInventory->GetAccessoryCount();

                    TAccessoryContainer& Accessories = gstate.Accessories;
                    int nRecAccessories = Accessories.size();
                    if(nRecAccessories)
                    {
                        pRenderer->Draw2dLabel( 1,y+retY, 1.3f, bError? fColorWarning : fColor, false," Accessories");
                        retY +=15;
                    }

                    for(int j=0 ; j< nInvAccessories; j++,i++)
                    {
                        const char* accessory = pInventory->GetAccessory(j);
                        if(accessory && strlen(accessory))	
                        {

                            IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(accessory);
                            if(pClass)
                            {
                                TItemName szItemName = pClass->GetName();
                                TAccessoryContainer::iterator it = Accessories.find(szItemName);
                                bError = it==Accessories.end();
                                pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," %2d)",i+1);

                                char itemName[32];
                                int length = strlen(accessory);
                                length = min(length,31);
                                strncpy(itemName,accessory,length);
                                itemName[length]=0;
                                pRenderer->Draw2dLabel( 1,y+retY, 1.3f, bError? fColorWarning : fColor, false,"     %s",itemName);

                                if(bError)
                                    pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColorWarning, false, "Missing");
开发者ID:kitnet,项目名称:project-o,代码行数:67,代码来源:GameStateRecorder.cpp


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