本文整理汇总了C++中CInventory::GetItem方法的典型用法代码示例。如果您正苦于以下问题:C++ CInventory::GetItem方法的具体用法?C++ CInventory::GetItem怎么用?C++ CInventory::GetItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CInventory
的用法示例。
在下文中一共展示了CInventory::GetItem方法的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++)
//.........这里部分代码省略.........
示例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;
//.........这里部分代码省略.........
示例3: RenderInfo
float CGameStateRecorder::RenderInfo(float y, bool bRecording)
{
float retY = 0;
IRenderer *pRenderer = gEnv->pRenderer;
if (bRecording)
{
float fColor[4] = {1,0,0,1};
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Recording game state");
retY +=15;
}
else
{
const float xp = 300;
const float xr = 400;
const float xri = 600;
float fColor[4] = {0,1,0,1};
float fColorWarning[4] = {1,1,0,1};
const char* actorName = m_demo_actorInfo->GetString();
CActor *pActor = GetActorOfName(actorName);
if(pActor)
{
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Game state - Actor: %s --------------------------------------------------",pActor->GetEntity()? pActor->GetEntity()->GetName(): "(no entity)");
retY +=15;
if(m_itSingleActorGameState != m_GameStates.end() && pActor->GetEntity() && m_itSingleActorGameState->first == pActor->GetEntity()->GetId())
{
ICVar *pVar = gEnv->pConsole->GetCVar( "demo_force_game_state" );
if(pVar)
{
int demo_forceGameState = pVar->GetIVal();
if(demo_forceGameState)
{
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false,demo_forceGameState==1 ?
" Override mode = (health, suit energy)" : " Override mode = (all)");
retY +=15;
}
}
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor,false,"Current");
pRenderer->Draw2dLabel( xr,y+retY, 1.3f, fColor,false,"Recorded");
retY +=15;
SActorGameState& gstate = m_itSingleActorGameState->second;
float recordedHealth = (float)gstate.health;
float health = (float)pActor->GetHealth();
bool bError = CHECK_MISMATCH(health, recordedHealth,10);
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Health:");
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",(int)health);
pRenderer->Draw2dLabel( xr,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",(int)recordedHealth);
retY +=15;
// items
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," Inventory ---------------------------------------------------------------------------------------");
retY +=15;
pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor,false,"Current");
pRenderer->Draw2dLabel( xri,y+retY, 1.3f, fColor,false,"Recorded");
retY +=15;
CInventory *pInventory = (CInventory*)(pActor->GetInventory());
if(pInventory)
{
int nInvItems = pInventory->GetCount();
TItemContainer& Items = gstate.Items;
int nRecItems = Items.size();
int maxItems = max(nRecItems,nInvItems);
int i=0;
EntityId curSelectedId = pActor->GetCurrentItemId();
TItemName curSelClass = GetItemName(curSelectedId);
bool bSelectedError = !equal_strings(gstate.itemSelected,curSelClass);
for(; i< nInvItems; i++)
{
IItem *pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pInventory->GetItem(i));
if(pItem)
{
TItemName szItemName = GetItemName(pItem->GetEntityId());
TItemContainer::iterator it = Items.find(szItemName);
bError = it==Items.end();
pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false," %2d)",i+1);
EntityId curId = pItem->GetEntityId();
TItemName curClass = GetItemName(curId);
if(equal_strings(curClass,curSelClass) )
pRenderer->Draw2dLabel( xp-16,y+retY, 1.3f,bSelectedError ? fColorWarning:fColor, false, "[]");
if(equal_strings(szItemName, gstate.itemSelected))
pRenderer->Draw2dLabel( xri-16,y+retY, 1.3f,bSelectedError ? fColorWarning:fColor, false, "[]");
char itemName[32];
const char* originalItemName = pItem->GetEntity() ? pItem->GetEntity()->GetName():"(null)";
int length = strlen(originalItemName);
length = min(length,31);
//.........这里部分代码省略.........