EntityId CAICorpse::CloneAttachedItem( const CAICorpse::AttachedItem& attachedItem, IAttachment* pAttachment ) { stack_string clonedItemName; clonedItemName.Format("%s_%s", GetEntity()->GetName(), attachedItem.pClass->GetName() ); SEntitySpawnParams params; params.sName = clonedItemName.c_str(); params.pClass = attachedItem.pClass; // Flag as 'No Save' they will be recreated during serialization if needed params.nFlags |= (ENTITY_FLAG_NO_SAVE); IEntity *pClonedItemEntity = gEnv->pEntitySystem->SpawnEntity(params); assert (pClonedItemEntity != NULL); IItem* pClonedItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pClonedItemEntity->GetId()); assert(pClonedItem != NULL); pClonedItem->Physicalize(false, false); pClonedItem->SetOwnerId( GetEntityId() ); // Set properties table to null, since they'll not be used IScriptTable* pClonedItemEntityScript = pClonedItemEntity->GetScriptTable(); if (pClonedItemEntityScript != NULL) { pClonedItemEntity->GetScriptTable()->SetToNull("Properties"); } // Swap attachments CEntityAttachment* pEntityAttachement = new CEntityAttachment(); pEntityAttachement->SetEntityId( pClonedItemEntity->GetId() ); pAttachment->AddBinding( pEntityAttachement ); return pClonedItemEntity->GetId(); }
//------------------------------------------------------------------------ void CFlowVehicleBase::ProcessEvent(EFlowEvent flowEvent, SActivationInfo* pActivationInfo) { if (flowEvent == eFE_SetEntityId) { IEntity* pEntity = pActivationInfo->pEntity; if (pEntity) { IVehicleSystem* pVehicleSystem = CCryAction::GetCryAction()->GetIVehicleSystem(); CRY_ASSERT(pVehicleSystem); if (pEntity->GetId() != m_vehicleId) { if (IVehicle* pVehicle = GetVehicle()) pVehicle->UnregisterVehicleEventListener(this); m_vehicleId = 0; } if (IVehicle* pVehicle = pVehicleSystem->GetVehicle(pEntity->GetId())) { pVehicle->RegisterVehicleEventListener(this, "FlowVehicleBase"); m_vehicleId = pEntity->GetId(); } } else { if (IVehicle* pVehicle = GetVehicle()) pVehicle->UnregisterVehicleEventListener(this); } } }
//------------------------------------------------------------------------ void CVehicleDamageBehaviorBurn::Update(const float deltaTime) { m_timeCounter -= deltaTime; if(m_timeCounter <= 0.0f) { CGameRules *pGameRules = g_pGame->GetGameRules(); if(pGameRules && gEnv->bServer) { Vec3 worldPos; if(m_pHelper) worldPos = m_pHelper->GetWorldSpaceTranslation(); else worldPos = m_pVehicle->GetEntity()->GetWorldTM().GetTranslation(); SEntityProximityQuery query; query.box = AABB(worldPos-Vec3(m_radius), worldPos+Vec3(m_radius)); gEnv->pEntitySystem->QueryProximity(query); IEntity *pEntity = 0; for(int i = 0; i < query.nCount; ++i) { if((pEntity = query.pEntities[i]) && pEntity->GetPhysics()) { float damage = (pEntity->GetId() == m_pVehicle->GetEntityId()) ? m_selfDamage : m_damage; // SNH: need to check vertical distance here as the QueryProximity() call seems to work in 2d only Vec3 pos = pEntity->GetWorldPos(); if(abs(pos.z - worldPos.z) < m_radius) { if(damage > 0.f) { HitInfo hitInfo; hitInfo.damage = damage; hitInfo.pos = worldPos; hitInfo.radius = m_radius; hitInfo.targetId = pEntity->GetId(); hitInfo.shooterId = m_shooterId; hitInfo.weaponId = m_pVehicle->GetEntityId(); hitInfo.type = pGameRules->GetHitTypeId("fire"); pGameRules->ServerHit(hitInfo); } } } } if(gEnv->pAISystem) gEnv->pAISystem->RegisterDamageRegion(this, Sphere(worldPos, m_radius)); } m_timeCounter = m_interval; } m_pVehicle->NeedsUpdate(); }
void CClaymore::ProcessEvent(SEntityEvent &event) { if (m_frozen) return; switch(event.event) { case ENTITY_EVENT_ENTERAREA: { IEntity * pEntity = gEnv->pEntitySystem->GetEntity(event.nParam[0]); IVehicle* pVehicle = NULL; IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(event.nParam[0]); // only detonate for actors... if(!pActor) pVehicle = g_pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(event.nParam[0]); // ...or vehicles // ignore actors in vehicles (we detect the vehicle instead) if(pActor && pActor->GetLinkedVehicle()) pActor = NULL; // ignore spectators if(pActor && static_cast<CActor*>(pActor)->GetSpectatorMode() != CActor::eASM_None) pActor = NULL; if(pEntity && (pActor || pVehicle)) { if(g_pGameCVars->g_debugMines != 0) CryLog("Claymore detected entity: %d, type %s", pEntity->GetId(), pActor == NULL ? "Vehicle" : "Actor"); m_targetList.push_back(pEntity->GetId()); } break; } case ENTITY_EVENT_LEAVEAREA: { IEntity * pEntity = gEnv->pEntitySystem->GetEntity(event.nParam[0]); if(pEntity) { std::list<EntityId>::iterator it = std::find(m_targetList.begin(), m_targetList.end(), pEntity->GetId()); if(it != m_targetList.end()) m_targetList.erase(it); } break; } default: break; } return CProjectile::ProcessEvent(event); }
bool CCheckpointSystem::SaveExternalEntity(EntityId id) { //this function allows external logic (flowgraph) to save specific entities if(!CHECKPOINT_SAVE_XML_NODE) { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Tried writing external entity %i while savegame was not open.", (int)id); return false; } //find entity and access external section IEntity *pEntity = gEnv->pEntitySystem->GetEntity(id); if(pEntity) { XmlNodeRef externalEntities = CHECKPOINT_SAVE_XML_NODE->findChild(EXTERNAL_ENTITIES_SECTION); if(!externalEntities) { externalEntities = GetISystem()->CreateXmlNode(EXTERNAL_ENTITIES_SECTION); CHECKPOINT_SAVE_XML_NODE->addChild(externalEntities); } IActor *pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(pEntity->GetId()); if(pActor) { CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "The actor %s is additionally saved as external entity.", pEntity->GetName()); } //create entity data char entityId[16]; _snprintf(entityId, sizeof(entityId), "%s%i", "id", id); XmlNodeRef nextEntity = GetISystem()->CreateXmlNode(entityId); if(nextEntity) { nextEntity->setAttr("id", pEntity->GetId()); nextEntity->setAttr("name", pEntity->GetName()); //save active / hidden nextEntity->setAttr("active", pEntity->IsActive()); nextEntity->setAttr("hidden", pEntity->IsHidden()); //save translation and rotation (complete tm matrix for simplicity) SerializeWorldTM(pEntity, nextEntity, true); //add new entity to checkpoint externalEntities->addChild(nextEntity); return true; } return false; } return false; }
//------------------------------------------------------------------------ void CRock::HandleEvent(const SGameObjectEvent &event) { CProjectile::HandleEvent(event); if (event.event == eGFE_OnCollision) { if (m_destroying) return; EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr); if (!pCollision) return; IEntity *pTarget = pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[1]:0; if (!pTarget || pTarget->GetId()==m_ownerId || pTarget->GetId()==GetEntityId()) return; Vec3 dir(0, 0, 0); if (pCollision->vloc[0].GetLengthSquared() > 1e-6f) dir = pCollision->vloc[0].GetNormalized(); CGameRules *pGameRules = g_pGame->GetGameRules(); HitInfo hitInfo(m_ownerId, pTarget?pTarget->GetId():0, m_weaponId, m_fmId, 0.0f, pGameRules->GetHitMaterialIdFromSurfaceId(pCollision->idmat[1]), pCollision->partid[1], pGameRules->GetHitTypeId("melee"), pCollision->pt, dir, pCollision->n); hitInfo.remote = IsRemote(); hitInfo.projectileId = GetEntityId(); if (!hitInfo.remote) hitInfo.seq=m_seq; hitInfo.damage = m_damage; if (m_weaponId) { CWeapon *pWeapon=GetWeapon(); if (pWeapon && pWeapon->GetForcedHitMaterial() != -1) hitInfo.material=pGameRules->GetHitMaterialIdFromSurfaceId(pWeapon->GetForcedHitMaterial()); } pGameRules->ClientHit(hitInfo); if(m_damage>10) m_damage =(int)(m_damage*0.5f); } }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { ICustomAction* pCustomAction = pActInfo->pGraph->GetCustomAction(); switch ( event ) { case eFE_Update: pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, false ); if ( pCustomAction && !bAborted ) { // Abort only once bAborted = true; IEntity* pTarget = pCustomAction->GetObjectEntity(); ActivateOutput( pActInfo, 0, pTarget ? pTarget->GetId() : 0 ); } break; case eFE_Initialize: bAborted = false; pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, false ); break; case eFE_Activate: if ( !bAborted && pCustomAction && IsPortActive(pActInfo, 0) ) { pCustomAction->AbortAction(); } break; } }
//------------------------------------------------------------------------ void CCannonBall::ProcessHit(CGameRules& gameRules, const EventPhysCollision& collision, IEntity& target, float damage, int hitMatId, const Vec3& hitDir) { if(damage > 0.f) { EntityId targetId = target.GetId(); bool alreadyHit = CheckForPreviousHit(targetId, damage); if(!alreadyHit) { HitInfo hitInfo(m_ownerId ? m_ownerId : m_hostId, targetId, m_weaponId, damage, 0.0f, hitMatId, collision.partid[1], m_hitTypeId, collision.pt, hitDir, collision.n); hitInfo.remote = IsRemote(); hitInfo.projectileId = GetEntityId(); hitInfo.bulletType = m_pAmmoParams->bulletType; hitInfo.knocksDown = CheckAnyProjectileFlags(ePFlag_knocksTarget) && ( damage > m_minDamageForKnockDown ); hitInfo.knocksDownLeg = m_chanceToKnockDownLeg>0 && damage>m_minDamageForKnockDownLeg && m_chanceToKnockDownLeg>(int)Random(100); hitInfo.penetrationCount = m_penetrationCount; hitInfo.hitViaProxy = CheckAnyProjectileFlags(ePFlag_firedViaProxy); hitInfo.aimed = CheckAnyProjectileFlags(ePFlag_aimedShot); IPhysicalEntity* pPhysicalEntity = collision.pEntity[1]; if (pPhysicalEntity && pPhysicalEntity->GetType() == PE_ROPE) { hitInfo.partId = GetRopeBoneId(collision, target, pPhysicalEntity); } gameRules.ClientHit(hitInfo); ReportHit(targetId); } } }
void CTacAlienBullet::HandleEvent(const SGameObjectEvent &event) { if (m_destroying) return; CProjectile::HandleEvent(event); if (event.event == eGFE_OnCollision) { EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr); if (!pCollision) return; IEntity *pTarget = pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[1]:0; if (pTarget) { EntityId targetId = pTarget->GetId(); CActor* pActor = static_cast<CActor*>(g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTarget->GetId())); if(pActor && pActor->CanSleep()) { SimpleHitInfo info(m_ownerId, targetId, m_weaponId, 1); // 0=tag,1=tac info.remote=IsRemote(); g_pGame->GetGameRules()->ClientSimpleHit(info); } } Destroy(); } }
int CScriptBind_Boids::CanPickup(IFunctionHandler *pH, SmartScriptTable flockEntity, SmartScriptTable boidEntity) { CFlock* flock = GetFlock(flockEntity); IEntity* pBoidEntity = GetEntity(boidEntity); if (flock != NULL && pBoidEntity != NULL) { CBoidObject* pBoidObject = NULL; for (int i = 0; i < flock->GetBoidsCount(); ++i) { if (flock->GetBoid(i)->GetId() == pBoidEntity->GetId()) { pBoidObject = flock->GetBoid(i); break; } } if (pBoidObject != NULL) { SBoidContext bc; flock->GetBoidSettings(bc); return pH->EndFunction((pBoidObject->IsDead() && bc.bPickableWhenDead) || (!pBoidObject->IsDead() && bc.bPickableWhenAlive)); } } return pH->EndFunction(0); }
int CScriptBind_Boids::OnPickup(IFunctionHandler *pH, SmartScriptTable flockEntity, SmartScriptTable boidEntity, bool bPickup, float fThrowSpeed) { CFlock* flock = GetFlock(flockEntity); IEntity* pBoidEntity = GetEntity(boidEntity); if (flock != NULL && pBoidEntity != NULL) { CBoidObject* pBoidObject = NULL; for (int i = 0; i < flock->GetBoidsCount(); ++i) { if (flock->GetBoid(i)->GetId() == pBoidEntity->GetId()) { pBoidObject = flock->GetBoid(i); break; } } if (pBoidObject != NULL) { pBoidObject->OnPickup(bPickup, fThrowSpeed); } } return pH->EndFunction(); }
bool CStickyProjectile::AttachToCharacter(CProjectile* pProjectile, IEntity& pEntity, ICharacterInstance& pCharacter, const char* boneName) { IEntity* pProjectileEntity = pProjectile->GetEntity(); char attachName[16] = ""; sprintf(attachName, "StickyProj_%d", s_attachNameID++); IAttachment* pCharacterAttachment = pCharacter.GetIAttachmentManager()->CreateAttachment(attachName, CA_BONE, boneName, false); if(!pCharacterAttachment) { CryLogAlways("Could not create attachment for StickyProjectile[%s]. AttachmentName[%s] BoneName[%s]", pProjectileEntity->GetName(), attachName, boneName ); CRY_ASSERT_MESSAGE(pCharacterAttachment, "Could not create attachment for StickyProjectile. This must be fixed."); return false; } m_characterAttachmentCrC = pCharacterAttachment->GetNameCRC(); SetProjectilePhysics(pProjectile, ePT_None); pCharacterAttachment->SetAttRelativeDefault(QuatT(m_stuckRot, m_stuckPos)); CEntityAttachment *pEntityAttachment = new CEntityAttachment(); pEntityAttachment->SetEntityId(pProjectileEntity->GetId()); pCharacterAttachment->AddBinding(pEntityAttachment); return true; }
IEntity* CLaserBeam::CreateLaserEntity() { IEntity* pLaserEntity = gEnv->pEntitySystem->GetEntity(m_laserEntityId); if (pLaserEntity) return pLaserEntity; IEntity* pOwnerEntity = gEnv->pEntitySystem->GetEntity(m_ownerEntityId); if (!pOwnerEntity) return 0; SEntitySpawnParams spawnParams; spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->GetDefaultClass(); spawnParams.sName = "LaserBeam"; spawnParams.nFlags = (pOwnerEntity->GetFlags() | ENTITY_FLAG_NO_SAVE) & ~ENTITY_FLAG_CASTSHADOW; IEntity* pNewEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams); if(pNewEntity) { m_laserEntityId = pNewEntity->GetId(); IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)pNewEntity->GetProxy(ENTITY_PROXY_RENDER); IRenderNode * pRenderNode = pRenderProxy?pRenderProxy->GetRenderNode():NULL; if(pRenderNode) pRenderNode->SetRndFlags(ERF_RENDER_ALWAYS,true); SetLaserEntitySlots(false); } return pNewEntity; }
virtual void OnIterStart(SActivationInfo *pActInfo) { const int type = GetPortInt(pActInfo, EIP_Type); IEntitySystem *pEntitySystem = gEnv->pEntitySystem; if (pEntitySystem) { IEntityItPtr iter = pEntitySystem->GetEntityIterator(); if (iter) { iter->MoveFirst(); IEntity *pEntity = NULL; while (!iter->IsEnd()) { pEntity = iter->Next(); if (pEntity) { const EntityId id = pEntity->GetId(); const EEntityType entityType = GetEntityType(id); if (IsValidType(type, entityType)) { AddEntity(id); } } } } } }
void CTagBullet::HandleEvent(const SGameObjectEvent &event) { if (m_destroying) { return; } CProjectile::HandleEvent(event); if (event.event == eGFE_OnCollision) { EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr); if (!pCollision) { return; } IEntity *pTarget = pCollision->iForeignData[1] == PHYS_FOREIGN_ID_ENTITY ? (IEntity *)pCollision->pForeignData[1] : 0; if (pTarget) { EntityId targetId = pTarget->GetId(); SimpleHitInfo info(m_ownerId, targetId, m_weaponId, 0); // 0=tag,1=tac info.remote = IsRemote(); g_pGame->GetGameRules()->ClientSimpleHit(info); } Destroy(); } }
//------------------------------------------------------------------------ void CVehicleActionEntityAttachment::SpawnEntity() { IEntitySystem* pEntitySystem = gEnv->pEntitySystem; assert(pEntitySystem); IEntityClassRegistry* pClassRegistry = pEntitySystem->GetClassRegistry(); assert(pClassRegistry); IEntityClass* pEntityClass = pClassRegistry->FindClass(m_entityClassName.c_str()); if (!pEntityClass) return; char pEntityName[256]; _snprintf(pEntityName, 256, "%s_%s", m_pVehicle->GetEntity()->GetName(), m_entityClassName.c_str()); pEntityName[sizeof(pEntityName)-1] = '\0'; SEntitySpawnParams params; params.sName = pEntityName; params.nFlags = ENTITY_FLAG_CLIENT_ONLY; params.pClass = pEntityClass; IEntity* pEntity = pEntitySystem->SpawnEntity(params, true); if (!pEntity) { m_entityId = 0; return; } m_entityId = pEntity->GetId(); m_pVehicle->GetEntity()->AttachChild(pEntity); pEntity->SetLocalTM(m_pHelper->GetVehicleTM()); m_isAttached = true; }
bool CCheckpointSystem::RepairEntityId(EntityId &id, const char *pEntityName) { //EntityId's may change on level export -> fix id if(pEntityName) { //test the original entity id IEntity *pOriginalEntity = gEnv->pEntitySystem->GetEntity(id); if(pOriginalEntity && !stricmp(pOriginalEntity->GetName(), pEntityName)) return true; //seems correct IEntity *pNewEntity = gEnv->pEntitySystem->FindEntityByName(pEntityName); if(!pNewEntity) CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "Entity %s in loaded checkpoint could not be found. This means the checkpoint file is not compatible with this level version.", pEntityName); else if(!stricmp(pNewEntity->GetName(), pEntityName)) { //if the level was re-exported, the entity id might differ CHECKPOINT_RESAVE_NECESSARY = true; //this is a weakness of our entity system/editor and might be fixed in future id = pNewEntity->GetId(); return true; } return false; } return false; }
void CCheckpointSystem::DeleteDynamicEntities() { IEntitySystem *pEntitySystem = gEnv->pEntitySystem; IEntityItPtr pIt = pEntitySystem->GetEntityIterator(); ////////////////////////////////////////////////////////////////////////// pIt->MoveFirst(); while (!pIt->IsEnd()) { IEntity * pEntity = pIt->Next(); uint32 nEntityFlags = pEntity->GetFlags(); // Local player must not be deleted. if (nEntityFlags & ENTITY_FLAG_LOCAL_PLAYER) continue; if (nEntityFlags & ENTITY_FLAG_SPAWNED) pEntitySystem->RemoveEntity( pEntity->GetId() ); } // Force deletion of removed entities. pEntitySystem->DeletePendingEntities(); ////////////////////////////////////////////////////////////////////////// // Reset entity pools pEntitySystem->GetIEntityPoolManager()->ResetPools(false); }
void CTagBullet::HandleEvent(const SGameObjectEvent &event) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); CProjectile::HandleEvent(event); if (event.event == eGFE_OnCollision) { if (m_destroying) return; EventPhysCollision *pCollision = reinterpret_cast<EventPhysCollision *>(event.ptr); if (!pCollision) return; IEntity *pTarget = pCollision->iForeignData[1]==PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[1]:0; if (pTarget) { EntityId targetId = pTarget->GetId(); CHUD *pHUD = g_pGame->GetHUD(); pHUD->AddToRadar(targetId); SimpleHitInfo info(m_ownerId, targetId, m_weaponId, 0); // 0=tag,1=tac info.remote=IsRemote(); g_pGame->GetGameRules()->ClientSimpleHit(info); } Destroy(); } }
virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo) { switch (event) { case eFE_Activate: { IEntity* pEntity = pActInfo->pEntity; if(!pEntity) return; m_delayResult = GetPortBool(pActInfo, EIP_DelayResult); if(IsPortActive(pActInfo, EIP_Enable)) { m_actInfo = *pActInfo; m_entityId = pEntity->GetId(); SetEnabled(true); } else if(IsPortActive(pActInfo, EIP_Disable)) { SetEnabled(false); } break; } } }
//------------------------------------------------------------------------ CProjectile *CWeaponSystem::DoSpawnAmmo(IEntityClass *pAmmoType, bool isRemote, const SAmmoParams *pAmmoParams) { bool isServer=gEnv->bServer; bool isClient=gEnv->IsClient(); if(pAmmoParams->serverSpawn && (!isServer || IsDemoPlayback())) { if(!pAmmoParams->predictSpawn || isRemote) return 0; } SEntitySpawnParams spawnParams; spawnParams.pClass = pAmmoType; spawnParams.sName = "ammo"; spawnParams.nFlags = pAmmoParams->flags | ENTITY_FLAG_NO_PROXIMITY; // No proximity for this entity. IEntity *pEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams); if(!pEntity) { GameWarning("Failed to spawn ammo '%s'! Entity creation failed...", pAmmoType->GetName()); return 0; } CProjectile *pProjectile = GetProjectile(pEntity->GetId()); if(pProjectile && !isServer && !isRemote && pAmmoParams->predictSpawn) pProjectile->GetGameObject()->RegisterAsPredicted(); return pProjectile; }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Activate: const int nDrawPlayer = GetPortInt(pActInfo, EIP_DrawPlayer); if (IsPortActive(pActInfo, EIP_Link)) { IEntity* pEntity = gEnv->pEntitySystem->GetEntity(GetPortEntityId(pActInfo, EIP_Target)); if (pEntity) { CActor *pPlayerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor()); if (pPlayerActor) { SActorStats* pActorStats = pPlayerActor->GetActorStats(); if (pActorStats) { if (nDrawPlayer == -1) pActorStats->isHidden = true; else if (nDrawPlayer == 1) pActorStats->isHidden = false; } m_Position = pEntity->GetWorldPos(); m_Rotation = pEntity->GetWorldRotation(); pPlayerActor->LinkToEntity(pEntity->GetId()); ActivateOutput(pActInfo, EOP_Linked, true); } } } if (IsPortActive(pActInfo, EIP_Unlink)) { CActor *pPlayerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor()); if (pPlayerActor) { SActorStats* pActorStats = pPlayerActor->GetActorStats(); if (pActorStats) { if (nDrawPlayer == -1) pActorStats->isHidden = true; else if (nDrawPlayer == 1) pActorStats->isHidden = false; } bool keepTransform = GetPortBool(pActInfo, EIP_KeepTransform); pPlayerActor->LinkToEntity(0, keepTransform); if(!keepTransform) { pPlayerActor->GetEntity()->SetPos(m_Position); pPlayerActor->GetEntity()->SetRotation(m_Rotation); } ActivateOutput(pActInfo, EOP_Unlinked, true); } } break; } }
void CMelee::ApplyMeleeDamageHit( const SCollisionTestParams& collisionParams, const ray_hit& hitResult ) { IEntity* pCollidedEntity = gEnv->pEntitySystem->GetEntityFromPhysics(hitResult.pCollider); EntityId collidedEntityId = pCollidedEntity ? pCollidedEntity->GetId() : 0; ApplyMeleeDamage(hitResult.pt, collisionParams.m_dir, hitResult.n, hitResult.pCollider, collidedEntityId, hitResult.partid, hitResult.ipart, hitResult.surface_idx, collisionParams.m_remote, hitResult.iPrim); }
//------------------------------------------------------------------------ void CGameRules::StoreMigratingPlayer(IActor* pActor) { if (pActor == NULL) { GameWarning("Invalid data for migrating player"); return; } IEntity* pEntity = pActor->GetEntity(); EntityId id = pEntity->GetId(); bool registered = false; uint16 channelId = pActor->GetChannelId(); CRY_ASSERT(channelId); bool bShouldAdd = true; CGameLobby *pGameLobby = g_pGame->GetGameLobby(); CRY_ASSERT(pGameLobby); if (pGameLobby) { SCryMatchMakingConnectionUID conId = pGameLobby->GetConnectionUIDFromChannelID((int) channelId); if (pGameLobby->GetSessionNames().Find(conId) == SSessionNames::k_unableToFind) { CryLog("CGameRules::StoreMigratingPlayer() player %s (channelId=%u) has already left the game, not storing", pEntity->GetName(), channelId); bShouldAdd = false; } } if (bShouldAdd && (!m_hostMigrationCachedEntities.empty())) { if (!stl::find(m_hostMigrationCachedEntities, pActor->GetEntityId())) { bShouldAdd = false; } } if (bShouldAdd) { for (uint32 index = 0; index < m_migratingPlayerMaxCount; ++index) { if (!m_pMigratingPlayerInfo[index].InUse()) { m_pMigratingPlayerInfo[index].SetData(pEntity->GetName(), id, GetTeam(id), pEntity->GetWorldPos(), pEntity->GetWorldAngles(), pActor->GetHealth()); m_pMigratingPlayerInfo[index].SetChannelID(channelId); registered = true; break; } } } pEntity->Hide(true); // Hide the player, they will be unhidden when they rejoin if (!registered && bShouldAdd) { GameWarning("Too many migrating players!"); } }
//------------------------------------------------------------------------ void CDebugGun::Shoot(bool bPrimary) { CWeapon::StartFire(); // console cmd string cmd; cmd = (bPrimary) ? g_pGameCVars->i_debuggun_1->GetString() : g_pGameCVars->i_debuggun_2->GetString(); cmd += " "; unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any; if (m_fireModes[m_fireMode].first == "pierceability") { flags = (unsigned int)m_fireModes[m_fireMode].second & rwi_pierceability_mask; } IPhysicalWorld* pWorld = gEnv->pPhysicalWorld; IPhysicalEntity *pSkip = GetOwnerActor()->GetEntity()->GetPhysics(); ray_hit rayhit; CCamera& cam = GetISystem()->GetViewCamera(); Vec3 pos = cam.GetPosition()+cam.GetViewdir(); Vec3 dir = cam.GetViewdir() * HIT_RANGE; IEntity* pEntity = 0; if (pWorld->RayWorldIntersection(pos, dir, ent_all, flags, &rayhit, 1, &pSkip, 1)) { pEntity = (IEntity*)rayhit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY); } cmd.append(pEntity ? pEntity->GetName() : "0"); // if we execute an AI command take care of ai_debugdraw if (cmd.substr(0, 3) == "ai_") { if (pEntity && m_pAIDebugDraw->GetIVal() == 0) m_pAIDebugDraw->Set(1); else if(!pEntity && m_aiDebugDrawPrev == 0 && m_pAIDebugDraw->GetIVal() == 1) m_pAIDebugDraw->Set(0); } gEnv->pConsole->ExecuteString(cmd.c_str()); // if 2nd button hits a vehicle, enable movement profiling if (!bPrimary) { static IVehicleSystem* pVehicleSystem = g_pGame->GetIGameFramework()->GetIVehicleSystem(); string vehicleCmd = "v_debugVehicle "; vehicleCmd.append((pEntity && pVehicleSystem->GetVehicle(pEntity->GetId())) ? pEntity->GetName() : "0"); gEnv->pConsole->ExecuteString(vehicleCmd.c_str()); } OnShoot(GetOwnerId(), 0, 0, pos, dir, Vec3(ZERO)); }
EntityId CAICorpseManager::SpawnAICorpseFromEntity( IEntity& sourceEntity, const SCorpseParameters& corpseParams ) { assert(gEnv->IsEditor() == false); assert(gEnv->bMultiplayer == false); if(g_pGameCVars->g_aiCorpses_Enable == 0) return 0; if(m_corpsesArray.size() == m_maxCorpses) { RemoveSomeCorpses(); assert((uint32)m_corpsesArray.size() < m_maxCorpses); } MEMSTAT_CONTEXT(EMemStatContextTypes::MSC_Other, EMemStatContextFlags::MSF_None, "AICorpseManager::SpawnCorpse"); EntityId corpseId = 0; IPhysicalEntity* pSourcePhysics = sourceEntity.GetPhysics(); if ((pSourcePhysics != NULL) && (pSourcePhysics->GetType() == PE_ARTICULATED)) { ICharacterInstance *pSourceCharacterInstance = sourceEntity.GetCharacter(0); if (pSourceCharacterInstance != NULL) { IEntityClass *pCorpseClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AICorpse"); assert(pCorpseClass); stack_string corpseName; corpseName.Format("%s_Corpse", sourceEntity.GetName()); SEntitySpawnParams params; params.pClass = pCorpseClass; params.sName = corpseName.c_str(); #if !AI_CORPSES_ENABLE_SERIALIZE params.nFlags |= ENTITY_FLAG_NO_SAVE; #endif params.vPosition = sourceEntity.GetWorldPos(); params.qRotation = sourceEntity.GetWorldRotation(); IEntity *pCorpseEntity = gEnv->pEntitySystem->SpawnEntity(params, true); if(pCorpseEntity != NULL) { corpseId = pCorpseEntity->GetId(); CorpseInfo* pCorpseInfo = FindCorpseInfo( corpseId ); assert(pCorpseInfo != NULL); CAICorpse* pCorpse = pCorpseInfo->GetCorpse(); assert(pCorpse != NULL); pCorpse->SetupFromSource( sourceEntity, *pSourceCharacterInstance, (uint32)corpseParams.priority); } } } return corpseId; }
EContextEstablishTaskResult OnStep( SContextEstablishState& state ) { CScopedRemoveObjectUnlock unlockRemovals(CCryAction::GetCryAction()->GetGameContext()); if (m_skipGameRules || m_skipPlayers) { IEntityItPtr i = gEnv->pEntitySystem->GetEntityIterator(); while(!i->IsEnd()) { IEntity* pEnt = i->Next(); // skip gamerules if (m_skipGameRules) if (pEnt->GetId() == CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRulesEntity()->GetId()) continue; // skip players if (m_skipPlayers) { IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(pEnt->GetId()); if (pActor && pActor->IsPlayer()) continue; } pEnt->ClearFlags(ENTITY_FLAG_UNREMOVABLE); // force remove all other entities gEnv->pEntitySystem->RemoveEntity(pEnt->GetId(), true); } if (!m_skipGameRules) gEnv->pEntitySystem->ReserveEntityId(1); } else { if(!gEnv->pSystem->IsSerializingFile()) gEnv->pEntitySystem->Reset(); gEnv->pEntitySystem->ReserveEntityId(1); } gEnv->pEntitySystem->ReserveEntityId( LOCAL_PLAYER_ENTITY_ID ); CActionGame::Get()->OnEntitySystemReset(); return eCETR_Ok; }
void CLipSync_TransitionQueue::InjectLipSyncProvider() { IEntity* pEntity = GetEntity(); IEntityAudioProxy* pSoundProxy = static_cast<IEntityAudioProxy*>(pEntity->CreateProxy(ENTITY_PROXY_AUDIO).get()); CRY_ASSERT(pSoundProxy); m_pLipSyncProvider.reset(new CLipSyncProvider_TransitionQueue(pEntity->GetId())); REINST(add SetLipSyncProvider to interface) //pSoundProxy->SetLipSyncProvider(m_pLipSyncProvider); }
void CStickyProjectile::NetSetStuck(CProjectile* pProjectile, bool stuck) { if(stuck && ((m_flags&eSF_IsStuck)==0)) { IEntity* pTargetEntity = gEnv->pEntitySystem->GetEntity(m_parentId); if(pTargetEntity) { if(ICharacterInstance* pTargetCharacter = pTargetEntity->GetCharacter(0)) { const char* boneName = pTargetCharacter->GetICharacterModel()->GetICharacterModelSkeleton()->GetJointNameByID(m_stuckJoint); if(AttachToCharacter(pProjectile, *pTargetEntity, *pTargetCharacter, boneName)) { IActor* pActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pTargetEntity->GetId()); m_flags |= eSF_IsStuck; m_flags |= pActor ? pActor->IsPlayer() ? eSF_StuckToPlayer : eSF_StuckToAI : 0; m_childId = pProjectile->GetEntityId(); } } } if((m_flags&eSF_IsStuck)==0) { IEntity* pProjectileEntity = pProjectile->GetEntity(); AttachTo(pProjectile, pTargetEntity); m_childId = pProjectileEntity->GetId(); if(pTargetEntity) //If we have a parent then the stuck position/rotation are local to the parent { pProjectileEntity->SetPos(m_stuckPos); pProjectileEntity->SetRotation(m_stuckRot); } else if(m_flags&eSF_OrientateToCollNormal) { Matrix34 mat; mat.SetTranslation(m_stuckPos); mat.SetRotation33(Matrix33(m_stuckRot)); pProjectileEntity->SetWorldTM(mat); } else { pProjectileEntity->SetPos(m_stuckPos); } m_flags |= eSF_IsStuck; } } }
void CCameraFlight::DetectCollisions() { primitives::sphere sph; sph.r = 0.15f; sph.center = m_vTargetFadePos + m_vLookingDirection * RAY_SCAN_DISTANCE; CCameraRayScan *pRayScan = g_pGame->GetCameraManager()->GetCamView()->GetCamRayScan(); if (m_RayId == INVALID_RAY_ID) { m_RayId = pRayScan->ShootRay(sph.center, -m_vLookingDirection * RAY_SCAN_DISTANCE, ent_all & ~(ent_living | ent_independent | ent_rigid), geom_colltype0); } const RayCastResult* pRayRes = pRayScan->GetExternalHit(m_RayId); const ray_hit *pHit = pRayRes->hitCount > 0 ? &pRayRes->hits[0] : NULL; static int iNumHits = 0; if(pHit && pHit->dist > 0.0f) { iNumHits++; if(iNumHits > 2) { bool bIgnore = false; IPhysicalEntity *pPhysEntity = pHit->pCollider; if(pPhysEntity) { int iForeignData = pPhysEntity->GetiForeignData(); if (iForeignData == PHYS_FOREIGN_ID_STATIC) { //check whether the hit rendernode is "vegetation" void *pForeignData = pPhysEntity->GetForeignData(PHYS_FOREIGN_ID_STATIC); IRenderNode * pRN = (IRenderNode*)pForeignData; if(pRN && pRN->GetRenderNodeType() == eERType_Vegetation) bIgnore = true; } else if(iForeignData == PHYS_FOREIGN_ID_ENTITY) { IEntity *pEntity = gEnv->pEntitySystem->GetEntityFromPhysics(pPhysEntity); if(pEntity && (pEntity == m_pRefEnt || pEntity->GetId() == LOCAL_PLAYER_ENTITY_ID)) bIgnore = true; } else if(iForeignData == -1) bIgnore = true; } if(!bIgnore) m_vTargetFadePos = m_vTargetFadePos + m_vLookingDirection * max(0.0f, (RAY_SCAN_DISTANCE - pHit->dist)); else iNumHits = 0; } } else iNumHits = 0; if (pRayRes) { pRayScan->RemoveExternalHit(m_RayId); m_RayId = INVALID_RAY_ID; } }