void CCinematicInput::UpdateWeapons() { CWeapon* pPrimaryWeapon = GetWeapon(eWeapon_Primary); CWeapon* pSecondaryWeapon = GetWeapon(eWeapon_Secondary); const bool doUpdate = (pPrimaryWeapon != NULL) || (pSecondaryWeapon != NULL); if (doUpdate) { const CCamera& camera = gEnv->pSystem->GetViewCamera(); const Vec3 viewPosition = camera.GetPosition(); const Vec3 viewDirection = camera.GetViewdir(); // Update raycast if (m_aimingRayID == 0) { IEntity *pIgnoredEntity = gEnv->pEntitySystem->GetEntity(m_weapons[eWeapon_Primary].m_parentId); IEntity *pIgnoredEntity2 = gEnv->pEntitySystem->GetEntity(m_weapons[eWeapon_Secondary].m_parentId); int ignoreCount = 0; IPhysicalEntity *pIgnoredEntityPhysics[2] = { NULL, NULL }; if (pIgnoredEntity) { pIgnoredEntityPhysics[ignoreCount] = pIgnoredEntity->GetPhysics(); ignoreCount += pIgnoredEntityPhysics[ignoreCount] ? 1 : 0; } if (pIgnoredEntity2 && (pIgnoredEntity2 != pIgnoredEntity)) { pIgnoredEntityPhysics[ignoreCount] = pIgnoredEntity2->GetPhysics(); ignoreCount += pIgnoredEntityPhysics[ignoreCount] ? 1 : 0; } m_aimingRayID = g_pGame->GetRayCaster().Queue( RayCastRequest::HighestPriority, RayCastRequest(viewPosition, viewDirection * CINEMATIC_INPUT_MAX_AIM_DISTANCE, ent_all|ent_water, rwi_stop_at_pierceable|rwi_ignore_back_faces, pIgnoredEntityPhysics, ignoreCount), functor(*this, &CCinematicInput::OnRayCastDataReceived)); } // Update weapon orientation const Vec3 aimTargetPosition = viewPosition + (viewDirection * m_aimingDistance); if (pPrimaryWeapon != NULL) { UpdateWeaponOrientation( pPrimaryWeapon->GetEntity(), aimTargetPosition ); } if (pSecondaryWeapon != NULL) { UpdateWeaponOrientation( pSecondaryWeapon->GetEntity(), aimTargetPosition ); } } }
// IWeaponEventListener //--------------------------------------- void CMiscAnnouncer::OnShoot(IWeapon *pWeapon, EntityId shooterId, EntityId ammoId, IEntityClass* pAmmoType, const Vec3 &pos, const Vec3 &dir, const Vec3 &vel) { if(!ma_enabled || !AnnouncerRequired()) return; CWeapon *pWeaponImpl = static_cast<CWeapon*>(pWeapon); IEntityClass *pWeaponEntityClass = pWeaponImpl->GetEntity()->GetClass(); g_pGame->GetWeaponSystem()->GetWeaponAlias().UpdateClass(&pWeaponEntityClass); DbgLog("CMiscAnnouncer::OnShoot() pWeaponImpl=%s; shooter=%d; pAmmoType=%s", pWeaponImpl->GetEntity()->GetName(), g_pGame->GetGameRules()->GetEntityName(shooterId), pAmmoType->GetName()); TWeaponFiredMap::iterator it = m_weaponFiredMap.find(pWeaponEntityClass); if(it != m_weaponFiredMap.end()) { SOnWeaponFired &onWeaponFired = it->second; DbgLog("CMiscAnnouncer::OnShoot() has found the firing weaponClass in our weaponFiredMap. With announcement=%s", onWeaponFired.m_announcementName.c_str()); // we only want to play the announcement once each game/round IActor *pClientActor = gEnv->pGame->GetIGameFramework()->GetClientActor(); CGameRules *pGameRules = g_pGame->GetGameRules(); int clientTeam = pGameRules->GetTeam(pClientActor->GetEntityId()); int shooterTeam = pGameRules->GetTeam(shooterId); if (clientTeam == shooterTeam) { if (!onWeaponFired.m_havePlayedFriendly) { DbgLog("CMiscAnnouncer::OnShoot() we've not played this friendly annoucement already. Let's do it"); CAnnouncer::GetInstance()->Announce(shooterId, onWeaponFired.m_announcementID, CAnnouncer::eAC_inGame); } else { DbgLog("CMiscAnnouncer::OnShoot() we've already played this friendly announcement. Not playing again"); } onWeaponFired.m_havePlayedFriendly = true; } else { if (!onWeaponFired.m_havePlayedEnemy) { DbgLog("CMiscAnnouncer::OnShoot() we've not played this enemy announcement already. Let's do it"); CAnnouncer::GetInstance()->Announce(shooterId, onWeaponFired.m_announcementID, CAnnouncer::eAC_inGame); } else { DbgLog("CMiscAnnouncer::OnShoot() we've already played this enemy announcement. Not playing again."); } onWeaponFired.m_havePlayedEnemy = true; } } }
//------------------------------------------------------------------------ void CFireModePlugin_Reject::OnShoot() { const SEffectParams& rejectEffect = m_pParams->rejectEffect; CWeapon* pWeapon = m_pOwnerFiremode->GetWeapon(); const int slot = pWeapon->GetStats().fp ? 0 : 1; const bool doRejectEffect = (g_pGameCVars->i_rejecteffects != 0) && (!rejectEffect.effect[slot].empty()); if (doRejectEffect) { //First check if we can skip/cull the effect (not for the local player) if (!pWeapon->IsOwnerClient()) { const CCamera& camera = gEnv->p3DEngine->GetRenderingCamera(); const Vec3 cameraPos = camera.GetPosition(); const Vec3 effectPosition = pWeapon->GetWorldPos(); const float fDist2 = (cameraPos-effectPosition).len2(); // Too far, skip if (fDist2 > g_pGameCVars->g_rejectEffectCullDistance) { return; } // Not in the view ? if(g_pGameCVars->g_rejectEffectVisibilityCull) { Sphere emitterSphere(effectPosition, 2.0f); if(camera.IsSphereVisible_F(emitterSphere) == false) { return; } } } IParticleEffect* pParticleEffect = gEnv->pParticleManager->FindEffect(rejectEffect.effect[slot].c_str()); if (m_shellFXSpeed == 0.0f) { if (pParticleEffect) { const ParticleParams& particleParams = pParticleEffect->GetParticleParams(); m_shellFXSpeed = particleParams.fSpeed.GetMaxValue(); } } const Vec3 shellDirection = pWeapon->GetSlotHelperRotation(slot, rejectEffect.helper[slot].c_str(), true).GetColumn1(); const Vec3 shellVelocity = m_shellHelperVelocity + (shellDirection * m_shellFXSpeed); EntityEffects::SEffectSpawnParams spawnParams(ZERO, shellVelocity.GetNormalized(), rejectEffect.scale[slot], shellVelocity.GetLength(), false); EntityEffects::SpawnParticleWithEntity(pWeapon->GetEntity(), slot, pParticleEffect, rejectEffect.helper[slot].c_str(), spawnParams); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if(eFE_Activate == event && IsPortActive(pActInfo,0)) { IActor* pActor = GetActor(pActInfo); if (pActor == 0) return; CWeapon* pWeapon = static_cast<CWeapon*> (GetWeapon(pActor)); bool bZoomed = false; if (pWeapon != 0) { const string& weaponClass = GetPortString(pActInfo, 1); if (weaponClass.empty() == true || weaponClass == pWeapon->GetEntity()->GetClass()->GetName()) { bZoomed = pWeapon->IsZoomed(); } } ActivateOutput(pActInfo, bZoomed ? 1 : 0, true); } }
//------------------------------------------- void CLaser::Update(SEntityUpdateContext& ctx, int slot) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); if((slot == eIUS_General) && m_laserBeam.IsLaserActivated()) { RequireUpdate(eIUS_General); CWeapon* pParentWeapon = GetWeapon(); if (pParentWeapon) { CActor* pOwnerActor = pParentWeapon->GetOwnerActor(); Vec3 laserPos, laserDir; GetLaserPositionAndDirection(pParentWeapon, laserPos, laserDir); CLaserBeam::SLaserUpdateDesc laserUpdateDesc(laserPos, laserDir, ctx.fFrameTime, pParentWeapon->GetEntity()->IsHidden()); laserUpdateDesc.m_weaponZoomed = pParentWeapon->IsZoomed() || pParentWeapon->IsZoomingInOrOut(); m_laserBeam.UpdateLaser(laserUpdateDesc); } } }
void CGameStateRecorder::OnGameplayEvent(IEntity *pEntity, const GameplayEvent &event) { EntityId id; if(!pEntity || !(id = pEntity->GetId())) { GameWarning("TimeDemo:GameState::OnGamePlayEvent: Entity not found"); return; } CActor *pActor = (CActor*)(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(id)); if(!pActor) { GameWarning("TimeDemo:GameState::OnGamePlayEvent: Entity %s has no actor", pEntity->GetName()); return; } GameplayEvent event2 = event; event2.extra = 0;// event2 is the forwarded event, extra either will be not used by the listener or re-set as a string uint8 eType = event.event; bool bPlayer = (pActor->IsPlayer() && m_mode); if(bPlayer || m_mode==GPM_AllActors) { //items switch(eType) { case eGE_ItemPickedUp: { CheckInventory(pActor,0);//,*m_pRecordGameEventFtor); } break; case eGE_ItemDropped: { TItemName itemName = GetItemName(EntityId(event.extra)); if(!itemName ) //if(itemIdx < 0) break; event2.description = itemName; SendGamePlayEvent(pEntity,event2); IEntity* pItemEntity = gEnv->pEntitySystem->FindEntityByName(itemName); if(!pItemEntity) break; IItem* pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pItemEntity->GetId()); if(!pItem) break; IEntityClass* pItemClass = pItem->GetEntity()->GetClass(); if(pItemClass && !strcmpi(pItemClass->GetName(),"SOCOM")) { IItem* pCurrentItem = pActor->GetCurrentItem(); if(pCurrentItem) { IEntityClass* pCurrentItemClass = pCurrentItem->GetEntity()->GetClass(); if(pCurrentItemClass && !strcmpi(pCurrentItemClass->GetName(),"SOCOM")) { GameplayEvent event3; event3.event = eGE_ItemSelected; TItemName itemName = GetItemName(pCurrentItem->GetEntity()->GetId()); if(!itemName) break; event3.value = 0; event3.description = (const char*)itemName; SendGamePlayEvent(pEntity,event3); } } } } break; case eGE_WeaponFireModeChanged: { TItemName itemIdx = GetItemName(EntityId(event.extra)); if(!itemIdx)//if(itemIdx < 0) break; event2.description = (const char*)itemIdx; SendGamePlayEvent(pEntity,event2); } break; case eGE_ItemSelected: { EntityId itemId = EntityId(event.extra); TItemName itemIdx = GetItemName(itemId); if(itemId && !itemIdx) break; event2.value = 0; event2.description = (const char*)itemIdx; SendGamePlayEvent(pEntity,event2); } break; case eGE_AttachedAccessory: { if(!IsGrenade(event.description)) // NOT OffHandGrenade SendGamePlayEvent(pEntity,event2); } break; case eGE_AmmoCount: { const char* itemIdx = event.description; if(!itemIdx) break; TGameStates::iterator itGS; /*if(pActor->IsPlayer()) itGS = m_itSingleActorGameState; else */if(pActor->GetEntity()) itGS = m_GameStates.find(pActor->GetEntity()->GetId()); else break; if(itGS == m_GameStates.end()) break; SActorGameState& gstate = itGS->second; IEntity* pItemEntity = gEnv->pEntitySystem->FindEntityByName(itemIdx); if(!pItemEntity) break; IItem* pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pItemEntity->GetId()); if(!pItem) break; CWeapon* pWeapon = (CWeapon*)(pItem->GetIWeapon()); if(pWeapon && pWeapon->GetEntity()) { TItemContainer::iterator it = gstate.Items.find(itemIdx); if(it==gstate.Items.end()) break; SItemProperties& recItem = it->second; SWeaponAmmo weaponAmmo = pWeapon->GetFirstAmmo(); bool bGrenade = false; if(!weaponAmmo.pAmmoClass) { // special case for grenades if(IsAmmoGrenade((const char*)(event.extra))) { weaponAmmo.pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass((const char*)event.extra); weaponAmmo.count = (int)event.value; bGrenade = true; } } for(; weaponAmmo.pAmmoClass ; weaponAmmo = pWeapon->GetNextAmmo()) { int ammoCount = weaponAmmo.count; const char* ammoClass; if(weaponAmmo.pAmmoClass && (ammoClass = weaponAmmo.pAmmoClass->GetName())) { TAmmoContainer& recAmmo = bGrenade? gstate.AmmoMags : recItem.Ammo; if(recAmmo.find(ammoClass) == recAmmo.end()) recAmmo.insert(std::make_pair(ammoClass,0)); if(ammoCount != recAmmo[ammoClass]) { event2.event = eGE_AmmoCount; event2.value = (float)ammoCount; if(event2.value < 0) event2.value = 0; event2.extra = (void*)ammoClass; event2.description = (const char*)itemIdx; SendGamePlayEvent(pEntity,event2); } } } } } break; case eGE_EntityGrabbed: { EntityId entityId = EntityId(event.extra); IEntity * pGrabbedEntity = gEnv->pEntitySystem->GetEntity(entityId); if(pGrabbedEntity) { event2.description = pGrabbedEntity->GetName(); SendGamePlayEvent(pEntity,event2); } } break; case eGE_WeaponReload: case eGE_ZoomedIn: case eGE_ZoomedOut: case eGE_HealthChanged: case eGE_ItemExchanged: SendGamePlayEvent(pEntity,event2); break; default: break; } } }
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; SendGamePlayEvent(pEntity,event); } } }
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 CHUDCrosshair::UpdateCrosshair() { IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); if(!pClientActor) return; int iNewFriendly = 0; if(pClientActor->GetLinkedVehicle()) { // JanM/MichaelR: // Get status from the VehicleWeapon, which raycasts considering the necessary SkipEntities (in contrast to WorldQuery) // Julien: this is now done in MP as well iNewFriendly = g_pHUD->GetVehicleInterface()->GetFriendlyFire(); } else { if(!gEnv->bMultiplayer) { CWeapon *pWeapon = g_pHUD->GetCurrentWeapon(); if(pWeapon) { iNewFriendly = pWeapon->IsWeaponLowered() && pWeapon->IsPendingFireRequest(); if(iNewFriendly && pWeapon->GetEntity()->GetClass() == CItem::sTACGunFleetClass) iNewFriendly = 0; } else{ //Two handed pickups need the red X as well CPlayer *pPlayer= static_cast<CPlayer*>(pClientActor); if(CWeapon *pOffHand = static_cast<CWeapon*>(pPlayer->GetItemByClass(CItem::sOffHandClass))) iNewFriendly = pOffHand->IsWeaponLowered(); } } else { EntityId uiCenterId = pClientActor->GetGameObject()->GetWorldQuery()->GetLookAtEntityId(); if(uiCenterId) { iNewFriendly = IsFriendlyEntity(gEnv->pEntitySystem->GetEntity(uiCenterId)); } } } // SNH: if player is carrying a claymore or mine, ask the weapon whether it is possible to place it currently // (takes into account player speed / stance / aim direction). // So 'friendly' is a bit of a misnomer here, but we want the "don't/can't fire" crosshair... if(iNewFriendly != 1 && g_pHUD) { CWeapon *pWeapon = g_pHUD->GetCurrentWeapon(); if(pWeapon) { static IEntityClass* pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Claymore"); static IEntityClass* pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AVMine"); IEntityClass* pClass = pWeapon->GetEntity()->GetClass(); if(pClass == pClaymoreClass || pClass == pAVMineClass) { if(IFireMode* pfm = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode())) { if(!pfm->IsFiring()) iNewFriendly = pWeapon->CanFire() ? 0 : 1; } } } } if(iNewFriendly != m_iFriendlyTarget) { m_iFriendlyTarget = iNewFriendly; //m_animCrossHair.Invoke("setFriendly", m_iFriendlyTarget); if(iNewFriendly) m_animFriendCross.SetVisible(true); else m_animFriendCross.SetVisible(false); } if(m_animInterActiveIcons.GetVisible()) { m_bHideUseIconTemp = false; CItem *pItem = static_cast<CItem*>(pClientActor->GetCurrentItem()); if(pItem) { IWeapon *pWeapon = pItem->GetIWeapon(); if(pWeapon) { CItem::SStats stats = pItem->GetStats(); if(stats.mounted && stats.used) m_bHideUseIconTemp = true; } } if(!m_bHideUseIconTemp) { EntityId offHandId = pClientActor->GetInventory()->GetItemByClass(CItem::sOffHandClass); IItem *pOffHandItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(offHandId); if(pOffHandItem) { COffHand *pOffHand = static_cast<COffHand*>(pOffHandItem); uint32 offHandState = pOffHand->GetOffHandState(); if(offHandState == eOHS_HOLDING_OBJECT || offHandState == eOHS_THROWING_OBJECT || offHandState == eOHS_HOLDING_NPC || offHandState == eOHS_THROWING_NPC) m_bHideUseIconTemp = true; } } } }