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 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)); }
void CCheckpointSystem::WriteMetaData(EntityId checkpointId, XmlNodeRef parentNode, SCheckpointData &outMetaData) { XmlNodeRef node = GetISystem()->CreateXmlNode(META_DATA_SECTION); const char *levelName = CCryAction::GetCryAction()->GetLevelName(); CRY_ASSERT(levelName); CryFixedStringT<32> curlevelName = levelName; RepairLevelName(curlevelName); node->setAttr("Version", CHECKPOINT_VERSION_NUMBER); node->setAttr("LevelName", curlevelName.c_str()); node->setAttr("CheckpointId", checkpointId); //write checkpoint name to be independent of entityId IEntity *pCheckpointEntity = gEnv->pEntitySystem->GetEntity(checkpointId); if(pCheckpointEntity) node->setAttr("CheckpointName", pCheckpointEntity->GetName()); else node->setAttr("CheckpointName", "none"); string timeString; GameUtils::timeToString(time(NULL), timeString); node->setAttr("Timestamp", timeString.c_str()); parentNode->addChild(node); //write back metadata for listeners outMetaData.m_checkPointId = checkpointId; outMetaData.m_levelName = levelName; outMetaData.m_saveTime = timeString.c_str(); }
void CGameAIRecorder::AddRecordComment(EntityId requesterId, const char* szComment) { assert(szComment && szComment[0]); assert(requesterId > 0); assert(gEnv->bServer); if (m_bIsRecording && szComment && szComment[0]) { if (!gEnv->bServer) { CryLogAlways("[AI] Recorder comment requested on Client. Only the Server can do this!"); return; } IEntity *pEntity = gEnv->pEntitySystem->GetEntity(requesterId); IAIObject *pAI = pEntity ? pEntity->GetAI() : NULL; if (!pAI) { CryLogAlways("[AI] Attempting to add recorder comment, but the requester does not have an AI!"); return; } // Output to log CryLogAlways("[AI] --- RECORDER COMMENT ADDED ---"); CryLogAlways("[AI] By: %s", pEntity->GetName()); CryLogAlways("[AI] Comment: %s", szComment); // Add comment to stream RecordLuaComment(pAI, "Comment: %s", szComment); } }
//------------------------------------------------------------------------ void CDetonate::StartFire() { if (CanFire(false)) { CActor *pOwner=m_pWeapon->GetOwnerActor(); CCCPOINT(DetonateFireMode_StartFireOK); m_pWeapon->RequireUpdate(eIUS_FireMode); m_detonationTimer = 0.1f; m_pWeapon->PlayAction(GetFragmentIds().fire); m_pWeapon->RequestDetonate(); } else { #if !defined(_RELEASE) IFireMode* pFM = m_pWeapon->GetFireMode(m_pWeapon->GetCurrentFireMode()); EntityId projectileId = pFM ? pFM->GetProjectileId() : 0; IEntity * projectile = gEnv->pEntitySystem->GetEntity(projectileId); CryLog ("[Detonate] Failure to detonate %s '%s' (timer = %.4f, can detonate = %s, fire mode = '%s') projectile = %u (%s '%s')", m_pWeapon->GetEntity()->GetClass()->GetName(), m_pWeapon->GetEntity()->GetName(), m_detonationTimer, m_canDetonate ? "TRUE" : "FALSE", pFM ? pFM->GetName() : "NONE", projectileId, projectile ? projectile->GetClass()->GetName() : "NONE", projectile ? projectile->GetName() : "N/A"); #endif CCCPOINT_IF(m_detonationTimer > 0.0f, DetonateFireMode_CannotFire_TimerNotReachedZero); CCCPOINT(DetonateFireMode_CannotFire); } }
//------------------------------------------------------------------------ IEntity* CVehicleDamageBehaviorDetachPart::SpawnDetachedEntity() { IEntity* pVehicleEntity = m_pVehicle->GetEntity(); CRY_ASSERT(pVehicleEntity); // spawn the detached entity char pPartName[128]; _snprintf(pPartName, 128, "%s_DetachedPart_%s", pVehicleEntity->GetName(), m_partName.c_str()); pPartName[sizeof(pPartName)-1] = '\0'; SEntitySpawnParams spawnParams; spawnParams.sName = pPartName; spawnParams.bCreatedThroughPool = true; spawnParams.nFlags = ENTITY_FLAG_CLIENT_ONLY; if(!m_pickableDebris) spawnParams.nFlags |= ENTITY_FLAG_NO_PROXIMITY; spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("VehiclePartDetached"); if (!spawnParams.pClass) { CRY_ASSERT(0); return NULL; } return gEnv->pEntitySystem->SpawnEntity(spawnParams, true); }
void CUIMultiPlayer::PlayerKilled(EntityId playerid, EntityId shooterid) { SUIArguments args; IEntity* pEntity = gEnv->pEntitySystem->GetEntity(playerid); assert(pEntity); IEntity* pShooterEntity = gEnv->pEntitySystem->GetEntity(shooterid); assert(pShooterEntity); args.AddArgument(playerid); args.AddArgument(pEntity ? string(pEntity->GetName()) : string(UNDEF_ENTITY_NAME)); args.AddArgument(shooterid); args.AddArgument(pShooterEntity ? string(pShooterEntity->GetName()) : string("undefined")); m_pUIFunctions->SendEvent(SUIEvent(m_EventMap[EUIE_PlayerKilled], args)); }
//--------------------------------------- void CAreaAnnouncer::Init() { Reset(); //Scan for areas IEntityClass* pTargetClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AreaBox"); CRY_ASSERT_MESSAGE(pTargetClass, "Unable to find Target class AreaBox"); if(pTargetClass) { IEntityIt* it = gEnv->pEntitySystem->GetEntityIterator(); while ( !it->IsEnd() ) { IEntity* pEntity = it->Next(); if(pEntity->GetClass() == pTargetClass) { //check entityName IEntityAreaProxy *pArea = (IEntityAreaProxy*)pEntity->GetProxy(ENTITY_PROXY_AREA); if (pArea) { LoadAnnouncementArea(pEntity, pEntity->GetName()); } } } it->Release(); } CGameRules *pGameRules = g_pGame->GetGameRules(); pGameRules->RegisterRevivedListener(this); }
void CLightningArc::TriggerSpark() { const char* targetName = "Target"; IEntity* pEntity = GetEntity(); if (pEntity->GetMaterial() == 0) { GameWarning("Lightning arc '%s' has no Material, no sparks will trigger", pEntity->GetName()); return; } IEntityLink* pLinks = pEntity->GetEntityLinks(); int numLinks = 0; for (IEntityLink* link = pLinks; link; link = link->next) { if (strcmp(link->name, targetName) == 0) ++numLinks; } if (numLinks == 0) { GameWarning("Lightning arc '%s' has no Targets, no sparks will trigger", pEntity->GetName()); return; } int nextSpark = Random(numLinks); IEntityLink* pNextSparkLink = pLinks; for (; nextSpark && pNextSparkLink; pNextSparkLink = pNextSparkLink->next) { if (strcmp(pNextSparkLink->name, targetName) == 0) --nextSpark; } CLightningGameEffect::TIndex id = g_pGame->GetLightningGameEffect()->TriggerSpark( m_lightningPreset, pEntity->GetMaterial(), CLightningGameEffect::STarget(GetEntityId()), CLightningGameEffect::STarget(pNextSparkLink->entityId)); float strikeTime = g_pGame->GetLightningGameEffect()->GetSparkRemainingTime(id); IScriptTable* pTargetScriptTable = 0; IEntity* pTarget = gEnv->pEntitySystem->GetEntity(pNextSparkLink->entityId); if (pTarget) pTargetScriptTable = pTarget->GetScriptTable(); EntityScripts::CallScriptFunction(pEntity, pEntity->GetScriptTable(), "OnStrike", strikeTime, pTargetScriptTable); }
//------------------------------------------------------------------------ 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!"); } }
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; }
static const char * GetEntityName() { IEntity * pEnt = gEnv->pEntitySystem->GetEntity(_netinputchain_debugentity); assert(pEnt); if (pEnt) return pEnt->GetName(); else return "<<unknown>>"; }
void CHUDMissionObjective::SetTrackedEntity(EntityId entityId) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(entityId); if (pEntity) { m_trackedEntity = pEntity->GetName(); m_trackedEntityId = entityId; } }
CDialogActorContext::~CDialogActorContext() { StopSound(); CancelCurrent(); IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_entityID); const char* debugName = pEntity ? pEntity->GetName() : "<no entity>"; DiaLOG::Log(DiaLOG::eAlways, "[DIALOG] CDialogActorContext::dtor: %s 0x%p actorID=%d entity=%s entityId=%d", m_pSession->GetDebugName(), this, m_actorID, debugName, m_entityID); }
void CPersistantDebug::AddEntityTag(const SEntityTagParams& params, const char *tagContext) { // Create tag SEntityTag tag; tag.params = params; tag.params.column = max(1, tag.params.column); tag.params.visibleTime = max(0.f, tag.params.visibleTime); tag.params.fadeTime = max(0.f, tag.params.fadeTime); if (tagContext != NULL && *tagContext != '\0') tag.params.tagContext = tagContext; tag.totalTime = tag.params.visibleTime + tag.params.fadeTime; tag.totalFadeTime = tag.params.fadeTime; tag.vScreenPos.zero(); SObj *obj = FindObj(params.entity); if (!obj) { // Create new object to push back SObj sobj; sobj.obj = eOT_EntityTag; sobj.entityId = params.entity; sobj.entityHeight = 0.f; sobj.timeRemaining = tag.totalTime; sobj.totalTime = tag.totalTime; sobj.columns.resize(params.column); AddToTagList(sobj.tags, tag); m_objects[entityTagsContext].push_back(sobj); } else { obj->timeRemaining = max(obj->timeRemaining, tag.totalTime); obj->totalTime = obj->timeRemaining; int size = max(int(obj->columns.size()), params.column); if (obj->columns.size() < size) obj->columns.resize(size); AddToTagList(obj->tags, tag); } if (m_pETLog->GetIVal() > 0) { IEntity *ent = gEnv->pEntitySystem->GetEntity(params.entity); if (ent) { CryLog("[Entity Tag] %s added tag: %s", ent->GetName(), params.text.c_str()); if (m_pETLog->GetIVal() > 1) { char text[256]; _snprintf(text, sizeof(text), "[Entity Tag] %s", params.text.c_str()); gEnv->pAISystem->Record(ent->GetAI(), IAIRecordable::E_NONE, text); } } } }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CGameRules, ClHostMigrationPlayerJoined) { const EntityId playerId = params.entityId; #if !defined(_RELEASE) IEntity *pPlayer = gEnv->pEntitySystem->GetEntity(playerId); CryLog("CGameRules::ClHostMigrationPlayerJoined() '%s'", pPlayer ? pPlayer->GetName() : "<NULL>"); #endif // todo: ui return true; }
string CUIMultiPlayer::GetPlayerNameById( EntityId playerid ) { TPlayers::const_iterator it = m_Players.find(playerid); if (it != m_Players.end() ) { return it->second.name; } IEntity* pEntity = gEnv->pEntitySystem->GetEntity(playerid); return pEntity ? pEntity->GetName() : "<UNDEFINED>"; }
void CVisibleObjectsHelper::RegisterVisibility(SVisibleObject &visibleObject, const ObservableParams &observableParams) const { IEntity *pObject = gEnv->pEntitySystem->GetEntity(visibleObject.entityId); if (pObject) { IVisionMap& visionMap = *gEnv->pAISystem->GetVisionMap(); visibleObject.visionId = visionMap.CreateVisionID(pObject->GetName()); visionMap.RegisterObservable(visibleObject.visionId, observableParams); } }
//------------------------------------------------------------------------ int CScriptBind_Actor::RenderScore(IFunctionHandler *pH, ScriptHandle player, int kills, int deaths, int ping) { IEntity* pEntity = gEnv->pEntitySystem->GetEntity((EntityId)player.n); if(pEntity) { string name = pEntity->GetName(); EntityId id = (EntityId)player.n; g_pGame->GetGameRules()->UpdateScoreBoardItem(id, name, kills, deaths); } return pH->EndFunction(); }
CDialogActorContext::CDialogActorContext(CDialogSession* pSession, CDialogScript::TActorID actorID) { m_pSession = pSession; m_actorID = actorID; m_entityID = pSession->GetActorEntityId(m_actorID); IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_entityID); const char* debugName = pEntity ? pEntity->GetName() : "<no entity>"; m_pIActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(m_entityID); m_bIsLocalPlayer = m_pIActor != 0 && CCryAction::GetCryAction()->GetClientActor() == m_pIActor; ResetState(); DiaLOG::Log(DiaLOG::eAlways, "[DIALOG] CDialogActorContext::ctor: %s 0x%p actorID=%d entity=%s entityId=%u", m_pSession->GetDebugName(), this, m_actorID, debugName, m_entityID); }
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 CIntersectionAssistanceUnit::DebugUpdate() const { if(g_pGameCVars->pl_pickAndThrow.intersectionAssistDebugEnabled) { IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_subjectEntityId); if(pEntity) { IPhysicalEntity *pPhysical = pEntity->GetPhysics(); if(pPhysical) { const float fFontSize = 1.2f; float drawColor[4] = {1.0f, 1.0f, 1.0f, 1.0f}; string sMsg(string().Format(" Entity ID: [%d]", m_subjectEntityId)); sMsg += string().Format("\n Entity Name: [%s]", pEntity->GetName()); sMsg += string().Format("\n EmbedTimer: [%.3f]", m_embedTimer); sMsg += string().Format("\n EmbedState: [%s]",(m_embedState == eES_None) ? "NONE" : (m_embedState == eES_Evaluating) ? "EVALUATING" : (m_embedState == eES_ReEvaluating) ? "REEVALUATING" : (m_embedState == eES_NotEmbedded) ? "NOT EMBEDDED" : (m_embedState == eES_Embedded) ? "EMBEDDED" : "UNKNOWN"); Vec3 vCurrTrans = m_entityStartingWPos - pEntity->GetWorldPos(); sMsg += string().Format("\n Translation: < %.3f, %.3f, %.3f >", vCurrTrans.x, vCurrTrans.y, vCurrTrans.z ); sMsg += string().Format("\n Trans magnitude: < %.3f >", vCurrTrans.GetLength() ); sMsg += string().Format("\n Trans per sec: < %.3f >", vCurrTrans.GetLength() / g_pGameCVars->pl_pickAndThrow.intersectionAssistTimePeriod ); sMsg += string().Format("\n Collision count: %u", m_collisionCount ); // RENDER Vec3 vDrawPos = pEntity->GetWorldPos() + Vec3(0.0f,0.0f,0.6f); gEnv->pRenderer->DrawLabelEx(vDrawPos, fFontSize, drawColor, true, true, sMsg.c_str()); // Box pe_params_bbox bbox; if(pPhysical->GetParams(&bbox)) { ColorB colDefault = ColorB( 127,127,127 ); ColorB embedded = ColorB(255, 0, 0); ColorB notEmbedded = ColorB(0, 255, 0); gEnv->pRenderer->GetIRenderAuxGeom()->DrawAABB( AABB(bbox.BBox[0],bbox.BBox[1]), Matrix34(IDENTITY), false, (m_embedState == eES_Embedded) ? embedded : (m_embedState == eES_NotEmbedded) ? notEmbedded : colDefault, eBBD_Faceted); } } } } }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: m_errorLogSent = false; break; case eFE_Activate: if (IsPortActive(pActInfo, 0)) { IEntitySystem* pESys = gEnv->pEntitySystem; EntityId id1 = GetPortEntityId(pActInfo, 1); EntityId id2 = GetPortEntityId(pActInfo, 2); IEntity* pEnt1 = pESys->GetEntity( id1 ); IEntity* pEnt2 = pESys->GetEntity( id2 ); IEntity* pGraphEntity = pESys->GetEntity( pActInfo->pGraph->GetGraphEntity( 0 ) ); if (pEnt1==NULL || pEnt2==NULL) { if (!m_errorLogSent) { GameWarning("[flow] Entity::EntitiesInRange - flowgraph entity: %d:'%s' - at least one of the input entities is invalid!. Entity1: %d:'%s' Entity2: %d:'%s'", pActInfo->pGraph->GetGraphEntity( 0 ), pGraphEntity ? pGraphEntity->GetName() : "<NULL>", id1, pEnt1 ? pEnt1->GetName() : "<NULL>", id2, pEnt2 ? pEnt2->GetName() : "<NULL>" ); m_errorLogSent = true; } } else { const float range = GetPortFloat(pActInfo, 3); const float distance = pEnt1->GetWorldPos().GetDistance(pEnt2->GetWorldPos()) ; const bool inRange = (distance <= range); ActivateOutput(pActInfo, 0, inRange); ActivateOutput(pActInfo, 1 + (inRange ? 1 : 0), true); ActivateOutput(pActInfo, 3, distance); const Vec3 distVector = pEnt2->GetPos() - pEnt1->GetPos(); ActivateOutput(pActInfo, 4, distVector); m_errorLogSent = false; } } break; } }
void CPlayerPlugin_CurrentlyTargetting::Update(float dt) { m_currentTargetTime += dt; //updated locally for all players (so doesn't have to be synced) assert (IsEntered()); if (m_ownerPlayer->IsClient()) { EntityId newTargetId = !m_ownerPlayer->IsDead() ? m_ownerPlayer->GetGameObject()->GetWorldQuery()->GetLookAtEntityId() : 0; if (newTargetId) { IActor * targettedActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(newTargetId); if (targettedActor == NULL || targettedActor->IsDead()) { newTargetId = 0; } } if (m_currentTarget != newTargetId) { m_currentTarget = newTargetId; CCCPOINT_IF(m_currentTarget, PlayerState_LocalPlayerNowTargettingSomebody); CCCPOINT_IF(!m_currentTarget, PlayerState_LocalPlayerNowTargettingNobody); m_currentTargetTime = 0.0f; CHANGED_NETWORK_STATE(m_ownerPlayer, CPlayer::ASPECT_CURRENTLYTARGETTING_CLIENT); } } #if PLAYER_PLUGIN_DEBUGGING IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_currentTarget); PlayerPluginWatch ("Target e%05d (%s %s) - %.2f", m_currentTarget, pEntity ? pEntity->GetName() : "NULL", pEntity ? pEntity->GetClass()->GetName() : "entity", m_currentTargetTime); #endif }
//------------------------------------------------------------------------ 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; 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!"); } }
CDialogActorContext::CDialogActorContext(CDialogSession* pSession, CDialogScript::TActorID actorID) : m_pCurLine(0) { static int uniqueID = 0; m_ContextID = ++uniqueID; m_pSession = pSession; m_actorID = actorID; m_entityID = pSession->GetActorEntityId(m_actorID); IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_entityID); const char* debugName = pEntity ? pEntity->GetName() : "<no entity>"; m_pIActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(m_entityID); m_bIsLocalPlayer = m_pIActor != 0 && CCryAction::GetCryAction()->GetClientActor() == m_pIActor; m_SpeechAuxProxy = INVALID_AUDIO_PROXY_ID; ResetState(); DiaLOG::Log(DiaLOG::eAlways, "[DIALOG] CDialogActorContext::ctor: %s 0x%p actorID=%d entity=%s entityId=%u", m_pSession->GetDebugName(), this, m_actorID, debugName, m_entityID); }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CGameRules, ClRenameEntity) { IEntity *pEntity = gEnv->pEntitySystem->GetEntity(params.entityId); if (pEntity) { string old = pEntity->GetName(); pEntity->SetName(params.name.c_str()); CryLogAlways("$8%s$o renamed to $8%s", old.c_str(), params.name.c_str()); // if this was a remote player, check we're not spectating them. // If we are, we need to trigger a spectator hud update for the new name EntityId clientId = g_pGame->GetIGameFramework()->GetClientActorId(); if(gEnv->bMultiplayer && params.entityId != clientId) { CActor *pClientActor = static_cast<CActor *>(g_pGame->GetIGameFramework()->GetClientActor()); } } return true; }
void CPlayerVisTable::UpdateIgnoreEntityDebug() { // Output array contents CryWatch("==== VISTABLE: Ignore Entities ===="); CryWatch(""); const int finalIndex = m_currentNumIgnoreEntities; for(int i = 0; i <= finalIndex; ++i) { const char* pEntName = "Unknown"; IEntity* pIgnoreEntity = gEnv->pEntitySystem->GetEntity(m_globalIgnoreEntities[i].id); if(pIgnoreEntity) { pEntName = pIgnoreEntity->GetName(); } CryWatch("Entity: Id < %d > , Name < %s >", m_globalIgnoreEntities[i].id, pEntName); CryWatch("RefCount %d", m_globalIgnoreEntities[i].refCount); if(m_globalIgnoreEntities[i].requesteeName.c_str()) { CryWatch("Caller %s", m_globalIgnoreEntities[i].requesteeName.c_str()); } CryWatch(""); } CryWatch("==== ==== ==== ==== ==== ==== ===="); // Test adding / removing specified ids if(g_pGameCVars->pl_debug_vistableAddEntityId) { AddGlobalIgnoreEntity(g_pGameCVars->pl_debug_vistableAddEntityId, "VisTable DEBUG"); g_pGameCVars->pl_debug_vistableAddEntityId = 0; } if(g_pGameCVars->pl_debug_vistableRemoveEntityId) { RemoveGlobalIgnoreEntity(g_pGameCVars->pl_debug_vistableRemoveEntityId); g_pGameCVars->pl_debug_vistableRemoveEntityId = 0; } }
void CCheckpointSystem::WriteActorData(XmlNodeRef parentNode) { XmlNodeRef node = GetISystem()->CreateXmlNode(ACTOR_FLAGS_SECTION); //write only data for non-active or hidden actors XmlNodeRef activatedActors = GetISystem()->CreateXmlNode(ACTIVATED_ACTORS_SECTION); char buffer[100]; IActorSystem *pActorSystem = CCryAction::GetCryAction()->GetIActorSystem(); IActorIteratorPtr it = pActorSystem->CreateActorIterator(); while (IActor *pActor = it->Next()) { IEntity *pEntity = pActor->GetEntity(); if(!pEntity->IsHidden() && pEntity->IsActive()) { EntityId id = pEntity->GetId(); const char *name = pEntity->GetName(); //we have to rely on names, since Id's change on level reexport _snprintf(buffer, sizeof(buffer), "%s%i", "id", id); activatedActors->setAttr(buffer, name); } } node->addChild(activatedActors); parentNode->addChild(node); }
CDialogActorContext::~CDialogActorContext() { if (m_SpeechAuxProxy != INVALID_AUDIO_PROXY_ID) { IEntity* pActorEntity = m_pSession->GetActorEntity(m_actorID); if (pActorEntity) { IEntityAudioProxy* pActorAudioProxy = m_pSession->GetEntityAudioProxy(pActorEntity); if (pActorAudioProxy) { pActorAudioProxy->RemoveAsListenerFromAuxAudioProxy(m_SpeechAuxProxy, &CDialogActorContext::OnAudioTriggerFinished); pActorAudioProxy->RemoveAuxAudioProxy(m_SpeechAuxProxy); } } } StopSound(); CancelCurrent(); IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_entityID); const char* debugName = pEntity ? pEntity->GetName() : "<no entity>"; DiaLOG::Log(DiaLOG::eAlways, "[DIALOG] CDialogActorContext::dtor: %s 0x%p actorID=%d entity=%s entityId=%d", m_pSession->GetDebugName(), this, m_actorID, debugName, m_entityID); }