//------------------------------------------------------------------------ bool CC4::CanSelect() const { bool canSelect = (CWeapon::CanSelect() && !OutOfAmmo(false)); //Check for remaining projectiles to detonate if(!canSelect) { CActor *pOwner = GetOwnerActor(); if(!pOwner) return false; EntityId detonatorId = pOwner->GetInventory()?pOwner->GetInventory()->GetItemByClass(CItem::sDetonatorClass):0; //Do not re-select detonator again if(detonatorId && (detonatorId==pOwner->GetCurrentItemId())) return false; IFireMode *pFM = GetFireMode(GetCurrentFireMode()); if(pFM) { //CC4::Select will select the detonator in this case EntityId projectileId = pFM->GetProjectileId(); if(projectileId && g_pGame->GetWeaponSystem()->GetProjectile(projectileId)) return true; } } return canSelect; };
//------------------------------------------------------------------------ void CC4::Drop(float impulseScale, bool selectNext, bool byDeath) { EntityId fistsId = 0; CActor *pOwner = GetOwnerActor(); if(pOwner) fistsId = pOwner->GetInventory()?pOwner->GetInventory()->GetItemByClass(CItem::sFistsClass):0; CItem::Drop(impulseScale,selectNext,byDeath); if (fistsId) pOwner->SelectItem(fistsId,true); }
void CJaw::PostSerialize() { BaseClass::PostSerialize(); if(m_auxSlotUsed) { SetViewMode(0); DrawSlot(eIGS_ThirdPersonAux,true); } else if (GetOwner() != 0 && !IsAttachedToBack() && !IsAttachedToHand()) { Hide(true); } else if (!IsOwnerFP()) { SetViewMode(eIVM_ThirdPerson); DrawSlot(eIGS_ThirdPerson, true); DrawSlot(eIGS_ThirdPersonAux,false); } if (m_smokeActive) { Pickalize(false, true); } if (GetOwner() != 0) { CActor* pOwner = GetOwnerActor(); IInventory* pInventory = pOwner ? pOwner->GetInventory() : 0; UnregisterUsedAmmoWithInventory(pInventory); RegisterUsedAmmoWithInventory(pInventory); } }
//------------------------------------------------------------------------ int CScriptBind_Actor::SetInventoryAmmo(IFunctionHandler *pH, const char *ammo, int amount) { CActor * pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); IInventory *pInventory=pActor->GetInventory(); if (!pInventory) return pH->EndFunction(); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammo); assert(pClass); int capacity = pInventory->GetAmmoCapacity(pClass); int current = pInventory->GetAmmoCount(pClass); if((!gEnv->IsEditor()) && (amount > capacity)) { //If still there's some place, full inventory to maximum... if(current<capacity) { pInventory->SetAmmoCount(pClass,capacity); if (gEnv->bServer) pActor->GetGameObject()->InvokeRMI(CActor::ClSetAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients); } } else { pInventory->SetAmmoCount(pClass, amount); if (gEnv->bServer) pActor->GetGameObject()->InvokeRMI(CActor::ClSetAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients); } return pH->EndFunction(); }
//------------------------------------------------------------------------ int CScriptBind_Actor::AddInventoryAmmo(IFunctionHandler *pH, const char *ammo, int amount) { CActor * pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); IInventory *pInventory=pActor->GetInventory(); if (!pInventory) return pH->EndFunction(); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammo); assert(pClass); int capacity = pInventory->GetAmmoCapacity(pClass); int current = pInventory->GetAmmoCount(pClass); if((!gEnv->pSystem->IsEditor()) && (amount > capacity)) { if(pActor->IsClient()) SAFE_HUD_FUNC(DisplayFlashMessage("@ammo_maxed_out", 2, ColorF(1.0f, 0,0), true, (string("@")+pClass->GetName()).c_str())); //If still there's some place, full inventory to maximum... if(current<capacity) { pInventory->SetAmmoCount(pClass,capacity); if(pActor->IsClient() && capacity - current > 0) { /*char buffer[5]; itoa(capacity - current, buffer, 10); SAFE_HUD_FUNC(DisplayFlashMessage("@grab_ammo", 3, Col_Wheat, true, (string("@")+pClass->GetName()).c_str(), buffer));*/ if(g_pGame->GetHUD()) g_pGame->GetHUD()->DisplayAmmoPickup(pClass->GetName(), capacity - current); } if (gEnv->bServer) pActor->GetGameObject()->InvokeRMI(CActor::ClAddAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients); } } else { pInventory->SetAmmoCount(pClass, amount); if(pActor->IsClient() && amount - current > 0) { /*char buffer[5]; itoa(amount - current, buffer, 10); SAFE_HUD_FUNC(DisplayFlashMessage("@grab_ammo", 3, Col_Wheat, true, (string("@")+pClass->GetName()).c_str(), buffer));*/ if(g_pGame->GetHUD()) g_pGame->GetHUD()->DisplayAmmoPickup(pClass->GetName(), amount - current); } if (gEnv->bServer) pActor->GetGameObject()->InvokeRMI(CActor::ClAddAmmo(), CActor::AmmoParams(ammo, amount), eRMI_ToRemoteClients); } return pH->EndFunction(); }
bool CJaw::OutOfAmmo(bool allFireModes) const { CActor* pOwner = GetOwnerActor(); IInventory* pOwnerInventory = pOwner ? pOwner->GetInventory() : 0; if (!pOwnerInventory) return true; IEntityClass* pJawClass = GetEntity()->GetClass(); IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); int jawUniqueId = pItemSystem->GetItemUniqueId(pJawClass->GetName()); int currentNumJaws = pOwnerInventory->GetCountOfUniqueId(jawUniqueId); return currentNumJaws == 0; }
//------------------------------------------------------------------------ int CScriptBind_Actor::GetInventoryAmmo(IFunctionHandler *pH, const char *ammo) { CActor * pActor = GetActor(pH); if (!pActor) return pH->EndFunction(); IInventory *pInventory=pActor->GetInventory(); if (!pInventory) return pH->EndFunction(); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammo); assert(pClass); return pH->EndFunction(pInventory->GetAmmoCount(pClass)); }
bool CMelee::SwitchToMeleeWeaponAndAttack() { // Checking for the equipped MeleeWeapon for each melee is hateful, but there's nowhere to check the inventory when a weapon is equipped. CActor* pOwner = m_pWeapon->GetOwnerActor(); if( pOwner && (pOwner->GetInventory()->GetItemByClass( CItem::sWeaponMeleeClass ) != 0) ) { m_pWeapon->SetPlaySelectAction( false ); pOwner->SelectItemByName( "WeaponMelee", true ); // trigger the attack - should be good without ptr checks, we validated that the weapon exists in the inventory. pOwner->GetCurrentItem()->GetIWeapon()->MeleeAttack(); return true; } return false; }
void CJaw::Drop(float impulseScale, bool selectNext, bool byDeath) { // No special handling needed when exiting editor game mode if (gEnv->IsEditor() && !gEnv->IsEditorGameMode()) return BaseClass::Drop(impulseScale, selectNext, byDeath); CActor* pOwner = GetOwnerActor(); //Don't let the player drop it if it has not been opened if(m_stats.first_selection && pOwner && pOwner->IsPlayer() && !pOwner->IsDead() && !byDeath) return; if(pOwner && !pOwner->IsPlayer()) { //In this case goes to the clip, no the inventory if(m_minDropAmmoAvailable && !m_weaponsharedparams->ammoParams.minDroppedAmmo.empty()) { TAmmoVector::const_iterator end = m_weaponsharedparams->ammoParams.minDroppedAmmo.end(); for(TAmmoVector::const_iterator it = m_weaponsharedparams->ammoParams.minDroppedAmmo.begin(); it != end; ++it) { SWeaponAmmoUtils::SetAmmo(m_ammo, it->pAmmoClass, it->count); } m_minDropAmmoAvailable = false; } } BaseClass::Drop(impulseScale,selectNext,byDeath); if (pOwner && !selectNext && !pOwner->IsHeadUnderWater()) { IInventory* pInventory = pOwner->GetInventory(); EntityId pNextJawItem = pInventory->GetItemByClass(GetEntity()->GetClass()); m_pItemSystem->SetActorItem(pOwner, pNextJawItem, true); } if (pOwner && pOwner->IsPlayer()) { if (m_fired) DropUsed(); else DropUnused(pOwner); } }
void CJaw::AddAmmoCapacity() { CActor* pOwner = GetOwnerActor(); if (!pOwner || !(gEnv->bServer || pOwner->IsClient())) return; IInventory* pOwnerInventory = pOwner->GetInventory(); if (!pOwnerInventory) return; if (pOwnerInventory->GetItemByClass(GetEntity()->GetClass()) != 0) return; const CWeaponSharedParams* pWeaponParams = GetWeaponSharedParams(); for (size_t i = 0; i < pWeaponParams->ammoParams.capacityAmmo.size(); ++i) { IEntityClass* pAmmoType = pWeaponParams->ammoParams.capacityAmmo[i].pAmmoClass; int capacity = pWeaponParams->ammoParams.capacityAmmo[i].count; pOwnerInventory->SetAmmoCapacity(pAmmoType, capacity); } }
//------------------------------------------------------------------------ void CItem::NetSetOwnerId(EntityId id) { if (id == m_ownerId) { return; } CryLogAlways("%s::NetSetOwnerId(%s)", GetEntity()->GetName(), GetActor(id) ? GetActor(id)->GetEntity()->GetName() : "null"); if (id) { PickUp(id, true); } else { Drop(); CActor *pActor = GetOwnerActor(); if (pActor) { pActor->GetInventory()->SetCurrentItem(0); } } }
void CJaw::DoAutoDrop() { if(!m_playedDropAction && m_fm) { m_firedRockets--; CActor* pOwner = GetOwnerActor(); // no need to auto-drop for AI if(pOwner && !pOwner->IsPlayer()) return; if((GetAmmoCount(m_fm->GetAmmoType())<=0)&&(m_firedRockets<=0)) { if( pOwner ) { uint8 uniqueId = m_pItemSystem->GetItemUniqueId(GetEntity()->GetClass()->GetName()); bool selectNext = pOwner->GetInventory()->GetCountOfUniqueId(uniqueId) <= 1; PlayAction(GetFragmentIds().drop); m_playedDropAction = true; } } } }
//---------------------------------------------------- void CAmmoPickup::OnIncendiaryAmmoPickedUp(IEntityClass *pClass,int count) { bool incendiary = (pClass == CItem::sIncendiaryAmmo); if(incendiary && !gEnv->bMultiplayer) { CActor* pPlayer = GetOwnerActor(); if(!pPlayer) return; if(IInventory *pInventory = pPlayer->GetInventory()) { if(pInventory->GetCountOfClass("FY71IncendiaryAmmo")==0) { const int clipSize = 30; m_pItemSystem->GiveItem(pPlayer,"FY71IncendiaryAmmo",false,false,false); int amount = count-clipSize; amount = MAX(0,amount); pInventory->SetAmmoCount(pClass,amount); } } } }
void CGameStateRecorder::OnRecordedGameplayEvent(IEntity *pEntity, const GameplayEvent &event, int currentFrame, bool bRecording) { EntityId id; m_currentFrame = currentFrame; int demo_forceGameState = 0; if(!bRecording) { ICVar *pVar = gEnv->pConsole->GetCVar( "demo_force_game_state" ); if(pVar) demo_forceGameState = pVar->GetIVal(); } if(!pEntity || !(id = pEntity->GetId())) return; if(m_IgnoredEvents.size()) if(event.event == m_IgnoredEvents[0]) { m_IgnoredEvents.erase(m_IgnoredEvents.begin()); return; } TGameStates::iterator itActor = m_GameStates.find(id); if(itActor == m_GameStates.end()) { m_GameStates.insert(std::make_pair(id,SActorGameState())); itActor = m_GameStates.find(id); } if(itActor == m_GameStates.end()) { GameWarning("TimeDemo:GameState: actor %s not found in records",pEntity->GetName()); return; } SActorGameState& gstate = itActor->second; switch(event.event) { case eGE_HealthChanged: { gstate.health = event.value; if(!m_bRecording) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { if(m_bLogWarning) { if(CHECK_MISMATCH(pActor->GetHealth(), gstate.health,10)) { if(!gstate.bHealthDifferent) { GameWarning("TimeDemo:GameState: Frame %d - Actor %s - HEALTH mismatch (%d, %d)",m_currentFrame,pEntity->GetName(), static_cast<int>(pActor->GetHealth()), static_cast<int>(gstate.health)); gstate.bHealthDifferent = true; } } else gstate.bHealthDifferent = false; } if( demo_forceGameState) pActor->SetHealth(gstate.health); } } } break; case eGE_WeaponFireModeChanged: { TItemName sel = (event.description); if(sel) { TItemContainer& Items = gstate.Items; TItemContainer::iterator iti = Items.find(sel); uint8 recFireModeIdx = uint8(event.value); if(iti != Items.end()) iti->second.fireMode = recFireModeIdx; CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor && pActor->GetInventory()) { IItem* pItem = pActor->GetInventory()->GetItemByName(sel); CWeapon* pWeapon; if(pItem && (pWeapon = (CWeapon*)(pItem->GetIWeapon()))) { int fireModeIdx = pWeapon->GetCurrentFireMode(); if(m_bLogWarning) { CheckDifference(recFireModeIdx,fireModeIdx,"TimeDemo:GameState: Frame %d - Actor %s - FIRE MODE mismatch for weapon %s (rec:%d, cur:%d)",pEntity,pItem->GetEntity() ? pItem->GetEntity()->GetName() : "(null)"); } if(demo_forceGameState==2 && fireModeIdx!= recFireModeIdx) pWeapon->SetCurrentFireMode(recFireModeIdx); } } } } break; case eGE_WeaponReload: { const char* ammoType = event.description; TAmmoContainer& ammoMags = gstate.AmmoMags; TAmmoContainer::iterator it = ammoMags.find(ammoType); if(it!=ammoMags.end()) { it->second -= (uint16)event.value; CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { { IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType); if(pAmmoClass) { if(m_bLogWarning) CheckDifference(it->second,pInventory->GetAmmoCount(pAmmoClass),"TimeDemo:GameState: Frame %d - Actor %s - WEAPON RELOAD, ammo count mismatch for ammo class %s (rec:%d, cur:%d)",pEntity,ammoType); if(demo_forceGameState == 2) pInventory->SetAmmoCount(pAmmoClass,it->second); } } } } } } break; case eGE_ItemSelected: { TItemName itemName = event.description; gstate.itemSelected = itemName; if(itemName) { if( !bRecording && (event.value > 0 || demo_forceGameState==2)) // EVENT.VALUE > 0 means initialization { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor && pActor->GetInventory()) { IItem* pItem = pActor->GetInventory()->GetItemByName(itemName); if(pItem) pActor->SelectItem(pItem->GetEntityId(),false); } } } if(m_bLogWarning) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { IItem* pItem = pActor->GetCurrentItem(); const char* curItemName= pItem && pItem->GetEntity() ? pItem->GetEntity()->GetName(): NULL; CheckDifferenceString(itemName,curItemName,"TimeDemo:GameState: Frame %d - Actor %s - SELECTED ITEM mismatch (rec:%s, cur:%s)",pEntity); } } break; } break; case eGE_ItemExchanged: { // prevent unwanted record/play mismatch error with current item during item exchanging // two unneeded game events are sent (selecting fists) m_IgnoredEvents.push_back(eGE_ItemSelected); m_IgnoredEvents.push_back(eGE_ItemSelected); } break; case eGE_ItemPickedUp: { TItemName sel = (TItemName)event.description; // gstate.itemSelected = sel; TItemContainer& Items = gstate.Items; TItemContainer::iterator it = Items.find(sel); if(it == Items.end()) { Items.insert(std::make_pair(sel,SItemProperties())); it = Items.find(sel); } if(it != Items.end()) { it->second.count++; CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor && !m_bRecording) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { // just check if the item is the inventory if(m_bLogWarning && !pInventory->GetItemByName(sel)) GameWarning("TimeDemo:GameState: Frame %d - Actor %s - Recorded PICKED UP ITEM class '%s' not found in current inventory",m_currentFrame,pEntity->GetName(),sel); if(demo_forceGameState == 2) { IEntity* pItemEntity = gEnv->pEntitySystem->FindEntityByName(sel); if(pItemEntity) pInventory->AddItem(pItemEntity->GetId()); else GameWarning("TimeDemo:GameState: Frame %d - Actor %s - PICKED UP ITEM entity %s not found in level",m_currentFrame,pEntity->GetName(),sel); } } } } else if(m_bLogWarning) { if(!sel) sel = "(null)"; GameWarning("TimeDemo:GameState: Frame %d - Actor %s - PICKED UP ITEM %s not found in recorded inventory",m_currentFrame,pEntity->GetName(),sel); } } break; case eGE_AmmoPickedUp: { uint16 ammoCount = (uint16)(event.value); TItemName sel = (TItemName)event.description; TAmmoContainer& Ammo = gstate.AmmoMags; TAmmoContainer::iterator it = Ammo.find(sel); if(it == Ammo.end()) Ammo.insert(std::make_pair(sel,ammoCount)); else it->second = ammoCount; if( !m_bRecording) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(sel); if(m_bLogWarning) CheckDifference(ammoCount,pInventory->GetAmmoCount(pClass),"TimeDemo:GameState: Frame %d - Actor %s - AMMO PICKEDUP: count mismatch for ammo class %s (rec:%d, cur:%d)", pEntity,sel); if(demo_forceGameState == 2) pInventory->SetAmmoCount(pClass,ammoCount); } } } } break; case eGE_AccessoryPickedUp: { TItemName sel = (TItemName)event.description; // gstate.itemSelected = sel; TAccessoryContainer& Accessories = gstate.Accessories; TAccessoryContainer::iterator it = Accessories.find(sel); if(it == Accessories.end()) { Accessories.insert(std::make_pair(sel,1)); } else it->second++; CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(sel); if(m_bLogWarning && !pInventory->HasAccessory(pClass)) GameWarning("TimeDemo:GameState: Frame %d - Actor %s - ACCESSORY PICKEDUP %s not found in current inventory", m_currentFrame, pEntity->GetName(),sel ? sel:"(null)"); if(demo_forceGameState == 2 && pClass) pInventory->AddAccessory(pClass);// doesn't actually add it if it's there already } } } break; case eGE_ItemDropped: { TItemName sel = (TItemName)event.description; //gstate.itemSelected = sel; TItemContainer& Items = gstate.Items; TItemContainer::iterator it = Items.find(sel); if(it != Items.end()) { it->second.count--; if(it->second.count<=0) Items.erase(it); if(demo_forceGameState == 2) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(sel); if(pClass) { EntityId itemId = pInventory->GetItemByClass(pClass); if(itemId) pInventory->RemoveItem(itemId); } } } } } else GameWarning("TimeDemo:GameState: Frame %d - Actor %s - ITEM DROPPED, wrong item selected (%s)",m_currentFrame,pEntity->GetName(),sel); } break; case eGE_AmmoCount: { TItemContainer& Items = gstate.Items; TItemName itemClassDesc = event.description; TItemContainer::iterator it = Items.find(itemClassDesc); if(it != Items.end()) { SItemProperties& item = it->second; const char* ammoClassDesc = (const char*)(event.extra); if(ammoClassDesc) { string szAmmoClassDesc(ammoClassDesc); bool bAmmoMag = IsAmmoGrenade(ammoClassDesc); TAmmoContainer& itemAmmo = bAmmoMag ? gstate.AmmoMags : item.Ammo; if(itemAmmo.find(szAmmoClassDesc)==itemAmmo.end()) itemAmmo.insert(std::make_pair(szAmmoClassDesc,int(event.value))); else itemAmmo[szAmmoClassDesc] = (uint16)event.value; if(!bRecording && (m_bLogWarning || demo_forceGameState==2)) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { IItem* pItem = pInventory->GetItemByName(itemClassDesc); if(pItem) { CWeapon* pWeapon = (CWeapon*)(pItem->GetIWeapon()); if(pWeapon) { IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoClassDesc); if(pAmmoClass) { if(m_bLogWarning) { int curAmmoCount = (bAmmoMag ? pInventory->GetAmmoCount(pAmmoClass) : pWeapon->GetAmmoCount(pAmmoClass)); CheckDifference( int(event.value),curAmmoCount,"TimeDemo:GameState: Frame %d - Actor %s - AMMO COUNT mismatch for ammo class %s (rec:%d, cur:%d)",pEntity,ammoClassDesc); } if(demo_forceGameState==2) pWeapon->SetAmmoCount(pAmmoClass,int(event.value)); } } } } } } } else GameWarning("TimeDemo:GameState: Frame %d - Actor %s - AMMO COUNT null ammoClass descriptor",m_currentFrame,pEntity->GetName()); } else GameWarning("TimeDemo:GameState: Frame %d - Actor %s - AMMO COUNT wrong item selected (%s)",m_currentFrame,pEntity->GetName(),itemClassDesc); } break; case eGE_AttachedAccessory: { // always force attachment of accessory to the current weapon // kind of a workaround, the HUD weapon modifier menu is spawned during timedemo playback // but it doesn't use recorded input events if(!bRecording) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { CInventory* pInventory = (CInventory*)(pActor->GetInventory()); if(pInventory) { const char* sel = event.description; IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(sel); if(!sel) sel = "(null)"; if(!pInventory->HasAccessory(pClass)) { if(m_bLogWarning) GameWarning("TimeDemo:GameState: Frame %d - Actor %s - ATTACHED ACCESSORY %s not found in current inventory", m_currentFrame,pEntity->GetName(),sel); } else { CItem* pCurrentItem = (CItem*)(pActor->GetCurrentItem()); if(pCurrentItem) pCurrentItem->SwitchAccessory(sel); } } } } } break; case eGE_EntityGrabbed: { if(demo_forceGameState==2) { TItemName itemName = event.description; if(itemName) { IEntity * pGrabbedEntity = gEnv->pEntitySystem->FindEntityByName(itemName); if(pGrabbedEntity) { CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(pActor) { IItem* pItem = GetItemOfName(pActor,itemName); if(!pItem) { // it's a pickable entity, won't end up in the inventory //(otherwise it would be managed by eGE_ItemPickedUp) COffHand* pOffHand = static_cast<COffHand*>(pActor->GetWeaponByClass(CItem::sOffHandClass)); if(pOffHand && !pOffHand->GetPreHeldEntityId()) pOffHand->ForcePickUp(pGrabbedEntity->GetId()); } } } } } } break; default: break; } }
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); strncpy(itemName,originalItemName,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"); else { SItemProperties& recItem = it->second; CWeapon *pWeapon = (CWeapon*)(pItem->GetIWeapon()); IEntityClass* pItemClass = pItem->GetEntity()->GetClass(); if(pItemClass && !strcmpi(pItemClass->GetName(),"binoculars")) pWeapon = NULL; // no fire mode or ammo recorded for binocular (which is a weapon) if(pWeapon) { int idx = 0; // ammo float xa = 0; for(SWeaponAmmo weaponAmmo = pWeapon->GetFirstAmmo(); weaponAmmo.pAmmoClass ; weaponAmmo = pWeapon->GetNextAmmo()) { int ammoCount = weaponAmmo.count; const char* ammoClass; if(weaponAmmo.pAmmoClass && (ammoClass = weaponAmmo.pAmmoClass->GetName())) { TAmmoContainer::iterator it = recItem.Ammo.find(ammoClass); if(it!=recItem.Ammo.end()) { int recAmmoCount = recItem.Ammo[ammoClass]; 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"); else pRenderer->Draw2dLabel( xp,y+retY, 1.3f, fColor, false, "Ok"); retY +=15; } } } /// Ammo Mags TAmmoContainer& Ammo = gstate.AmmoMags; int nRecAmmo = Ammo.size(); int nInvAmmo = pInventory->GetAmmoPackCount(); if(nInvAmmo) { pRenderer->Draw2dLabel( 1,y+retY, 1.3f, bError? fColorWarning : fColor, false," Ammo Packs"); retY +=15; } pInventory->AmmoIteratorFirst(); for(int j=0 ; !pInventory->AmmoIteratorEnd(); j++, pInventory->AmmoIteratorNext()) { TAmmoContainer& Mags = gstate.AmmoMags; const IEntityClass* pAmmoClass = pInventory->AmmoIteratorGetClass(); if(pAmmoClass) { int invAmmoCount = pInventory->AmmoIteratorGetCount(); const char* ammoClassName = pAmmoClass->GetName(); bool bNotFound = Mags.find(ammoClassName) == Mags.end(); int recAmmoCount = bNotFound ? 0 :Mags[ammoClassName]; bool bError = bNotFound || invAmmoCount!= recAmmoCount; pRenderer->Draw2dLabel( 1,y+retY, 1.3f, bError? fColorWarning : fColor, false," %s:",ammoClassName); pRenderer->Draw2dLabel( xp,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",invAmmoCount); if(bNotFound) pRenderer->Draw2dLabel( xr,y+retY, 1.3f, fColorWarning, false,"NotRecd"); else pRenderer->Draw2dLabel( xr,y+retY, 1.3f, bError? fColorWarning : fColor, false,"%d",recAmmoCount); retY +=15; } } } } else // m_itSingleActorGameState != m_GameStates.end() { pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false, "<<Not Recorded>>"); retY +=15; } } else // pActor { pRenderer->Draw2dLabel( 1,y+retY, 1.3f, fColor,false, "<<Actor %s not in the map>>",actorName ? actorName:"(no name)"); retY +=15; } } return retY; }
void CHandGrenades::UpdateStowedWeapons() { CActor *pOwnerActor = GetOwnerActor(); if (!pOwnerActor) return; ICharacterInstance *pOwnerCharacter = pOwnerActor->GetEntity()->GetCharacter(0); if (!pOwnerCharacter) return; IStatObj *pTPObj = GetEntity()->GetStatObj(eIGS_ThirdPerson); if (!pTPObj) return; int ammoCount = m_fm ? pOwnerActor->GetInventory()->GetAmmoCount(m_fm->GetAmmoType()) : 0; if (IsSelected() && (ammoCount > 0)) { ammoCount--; } if (!pOwnerActor->IsThirdPerson()) { ammoCount = 0; } int numGrenDiff = ammoCount - m_numStowedCopies; if(numGrenDiff != 0) { if (m_stowSlot < 0) { m_stowSlot = PickStowSlot(pOwnerCharacter->GetIAttachmentManager(), m_sharedparams->params.bone_attachment_01.c_str(), m_sharedparams->params.bone_attachment_02.c_str()); } if (m_stowSlot >= 0) { bool attach = numGrenDiff > 0; int tot = abs(numGrenDiff); IAttachmentManager *pAttachmentManager = pOwnerCharacter->GetIAttachmentManager(); IAttachment *pAttachment = NULL; for (int i=0; i<tot; i++) { //--- Generate the secondary slot from the first by adding one to the attachment name, is all we need at present... const char *attach1 = (m_stowSlot == 0) ? m_sharedparams->params.bone_attachment_01.c_str() : m_sharedparams->params.bone_attachment_02.c_str(); int lenAttachName = strlen(attach1); stack_string attach2(attach1, lenAttachName-1); attach2 += (attach1[lenAttachName-1]+1); if (attach) { pAttachment = pAttachmentManager->GetInterfaceByName(attach1); if(pAttachment && pAttachment->GetIAttachmentObject()) { pAttachment = pAttachmentManager->GetInterfaceByName(attach2); } if (pAttachment && !pAttachment->GetIAttachmentObject()) { CCGFAttachment *pCGFAttachment = new CCGFAttachment(); pCGFAttachment->pObj = pTPObj; pAttachment->AddBinding(pCGFAttachment); pAttachment->HideAttachment(0); pAttachment->HideInShadow(0); m_numStowedCopies++; } } else { pAttachment = pAttachmentManager->GetInterfaceByName(attach2); if(!pAttachment || !pAttachment->GetIAttachmentObject()) { pAttachment = pAttachmentManager->GetInterfaceByName(attach1); } if (pAttachment && pAttachment->GetIAttachmentObject()) { pAttachment->ClearBinding(); m_numStowedCopies--; } } } } } }
int CScriptBind_Weapon::AttachAccessoryPlaceHolder(IFunctionHandler *pH, SmartScriptTable accessory, bool attach) { CWeapon *pWeapon = GetWeapon(pH); if (!pWeapon) return pH->EndFunction(); const char *accessoryName; accessory->GetValue("class", accessoryName); ScriptHandle id; accessory->GetValue("id", id); EntityId entId = (EntityId)id.n; //CryLogAlways("id = %d", entId); IEntity *attachment = gEnv->pEntitySystem->GetEntity(entId); if (accessoryName) { //CryLogAlways("got name: %s", accessoryName); if (pWeapon->GetAccessoryPlaceHolder(accessoryName)) { //CryLogAlways("found accessory place holder"); pWeapon->AttachAccessoryPlaceHolder(accessoryName, attach); } else { //CryLogAlways("accessory place holder not found"); CActor *pActor = pWeapon->GetOwnerActor(); IEntity *wep = pWeapon->GetEntity(); //IGameObject *pGameObject = pWeapon->GetOwnerActor()->GetGameObject(); IInventory *pInventory = pActor->GetInventory(); if (pInventory) { //CryLogAlways("found inventory"); if (attachment) { if (pInventory->FindItem(entId) != -1) { //CryLogAlways("found attachment in inventory already..."); } else { //CryLogAlways("attachment not found in inventory, adding..."); } //CryLogAlways("found attachment"); //attachment->DetachThis(0); //attachment->SetParentId(0); //CItem *t = (CItem *)attachment; //t->SetParentId(0); //pWeapon->GetEntity()->AttachChild(attachment, false) pInventory->AddItem(attachment->GetId()); //for (int i = 0; i < wep->GetChildCount(); i++) //{ // IEntity *cur = wep->GetChild(i); // CryLogAlways("none of these should be %s", attachment->GetName()); // CryLogAlways(" %s", cur->GetName()); //} pWeapon->AttachAccessoryPlaceHolder(accessoryName, attach); pInventory->RemoveItem(attachment->GetId()); } else { //CryLogAlways("!attachment"); } } } } return pH->EndFunction(); }
void CHUDInventory::ShowInventory() { IUIElement* pElement = gEnv->pFlashUI->GetUIElement("Inventory"); if(pElement) { if(!Inv_loaded) { pElement->Reload(); pElement->GetFlashPlayer()->SetVisible(true); pElement->SetVisible(true); CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor()); IInventory *pInventory = pActor->GetInventory(); g_pGame->Actions().FilterNoMouse()->Enable(true); for (int i = 0; i < pInventory->GetCount(); i++) { EntityId ide = pInventory->GetItem(i); EntityId slotID = pActor->GetInventory()->FindItem(ide); CItem *curItem = static_cast<CItem*>(gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GetItem(ide)); IItem *pItem = static_cast<IItem*>(gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GetItem(ide)); CItem::SInventotyInfo info = curItem->GetInventoryInfo(); //int slotID; EntityId itemID = pItem->GetEntityId(); itemsSaved = false; for(int i = 0; i<inventoryItems.size(); i++) { if(inventoryItems[i].itemID == itemID) { //CryLog("Items finded in saved items"); slotID = inventoryItems[i].slotID; itemsSaved = true; break; } } if(!itemsSaved) slotID--; SFlashVarValue args[8] = {slotID, info.iconName.c_str(), itemID, info.itemName.c_str(), info.itemDescription.c_str(), 0, info.canStack, info.canQuick}; if(info.itemClass) { pElement->GetFlashPlayer()->Invoke("addInventoryItem", args, 8); if(!itemsSaved) { SInventoryItem inventoryItem; inventoryItem.itemName = info.itemName.c_str(); inventoryItem.itemID = itemID; inventoryItem.slotID = slotID++; inventoryItem.itemAmmount = 0; inventoryItem.canStack = info.canStack; inventoryItems.push_back(inventoryItem); } } } pElement->GetFlashPlayer()->SetFSCommandHandler(this); Inv_loaded = true; } else { g_pGame->Actions().FilterNoMouse()->Enable(false); pElement->SetVisible(false); pElement->GetFlashPlayer()->SetVisible(false); pElement->GetFlashPlayer()->SetFSCommandHandler(NULL); Inv_loaded = false; } } else CryLog("CHUDInventory::Error open inventory!"); }