void CGameStateRecorder::StartSession() { m_GameStates.clear(); m_itSingleActorGameState = m_GameStates.end(); m_IgnoredEvents.clear(); const char* filterName = m_demo_actorFilter->GetString(); // send game events to record the initial game state /* if(m_mode) { CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor()); */ m_pSingleActor = GetActorOfName(filterName); if(m_pSingleActor)// && !pActor->GetSpectatorMode() && pActor->IsPlayer()) { m_mode = GPM_SingleActor; AddActorToStats(m_pSingleActor); m_itSingleActorGameState = m_GameStates.begin();// position of requested actor's id (player by default) } // } else if (!strcmpi(filterName,"all")) { IAIObjectManager* pAIObjMgr = gEnv->pAISystem->GetAIObjectManager(); m_mode = GPM_AllActors; { AutoAIObjectIter it(pAIObjMgr->GetFirstAIObject(OBJFILTER_TYPE, AIOBJECT_ACTOR)); for(; it->GetObject(); it->Next()) { IAIObject* pObject = it->GetObject(); if(pObject) { CActor* pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pObject->GetEntityID())); if(pActor) AddActorToStats(pActor); } } } { AutoAIObjectIter it(pAIObjMgr->GetFirstAIObject(OBJFILTER_TYPE, AIOBJECT_VEHICLE)); for(; it->GetObject(); it->Next()) { IAIObject* pObject = it->GetObject(); if(pObject) { CActor* pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pObject->GetEntityID())); if(pActor) AddActorToStats(pActor); } } } } }
IAIObject* CTacticalPointLanguageExtender::GetBattleFrontObject() const { IAIObjectManager* pAIObjMgr = gEnv->pAISystem->GetAIObjectManager(); IAIObject *pObj = pAIObjMgr->GetAIObject(m_battlefrontAIObject); if (!pObj) { // Not created or has been removed (by reset, etc), so create one ITacticalPointSystem& tacticalPointSystem = *gEnv->pAISystem->GetTacticalPointSystem(); pObj = tacticalPointSystem.CreateExtenderDummyObject("Game_BattleFront"); assert(pObj); m_battlefrontAIObject = pObj ? pObj->GetAIObjectID() : 0; } return pObj; }
void CVisibleObjectsHelper::Update() { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); const float fCurrTime = gEnv->pTimer->GetFrameStartTime().GetSeconds(); IVisionMap& visionMap = *gEnv->pAISystem->GetVisionMap(); IEntitySystem *pEntitySystem = gEnv->pEntitySystem; assert(pEntitySystem); TActiveVisibleObjects activeVisibleObjects; activeVisibleObjects.reserve(m_VisibleObjects.size()); TVisibleObjects::iterator itNext = m_VisibleObjects.begin(); while (itNext != m_VisibleObjects.end()) { TVisibleObjects::iterator itObject = itNext++; EntityId objectId = itObject->first; SVisibleObject &visibleObject = itObject->second; IEntity *pObject = pEntitySystem->GetEntity(objectId); if (pObject) { const bool bIsStillActive = (fCurrTime - visibleObject.fLastActiveTime <= 1.0f); const bool bPassesRule = (pObject && CheckVisibilityRule(pObject, visibleObject, fCurrTime)); if (bPassesRule) visibleObject.fLastActiveTime = fCurrTime; visibleObject.bIsObservable = (bPassesRule || bIsStillActive); if (visibleObject.bIsObservable) { ObservableParams observableParams; observableParams.observablePositionsCount = 1; observableParams.observablePositions[0] = pObject->GetWorldPos(); visionMap.ObservableChanged(visibleObject.visionId, observableParams, eChangedPosition); if (visibleObject.pFunc || eVOR_FlagNotifyOnSeen == (visibleObject.rule & eVOR_FlagNotifyOnSeen)) activeVisibleObjects.push_back(&visibleObject); } else if (eVOR_FlagDropOnceInvisible == (visibleObject.rule & eVOR_FlagDropOnceInvisible)) { // No longer visible, so kill it // TODO: Kevin, please take a look here and see if you're happy with how i unregister it /Jonas UnregisterVisibility(visibleObject); m_VisibleObjects.erase(itObject); } } else { // TODO: Kevin, please take a look here and see if you're happy with how i unregister it /Jonas UnregisterVisibility(visibleObject); m_VisibleObjects.erase(itObject); } } IAIObjectManager* pAIObjectManager = !activeVisibleObjects.empty() ? gEnv->pAISystem->GetAIObjectManager() : NULL; IAIObjectIter* pAIObjectIter = pAIObjectManager ? pAIObjectManager->GetFirstAIObject(OBJFILTER_TYPE, AIOBJECT_ACTOR) : NULL; if (pAIObjectIter) { while (IAIObject *pAIObject = pAIObjectIter->GetObject()) { Agent agent(pAIObject); if (agent.IsValid()) { CheckVisibilityToAI(activeVisibleObjects, agent); } pAIObjectIter->Next(); } pAIObjectIter->Release(); } }
bool CTacticalPointLanguageExtender::GeneratePoints(TGenerateParameters& parameters, SGenerateDetails& details, TObjectType object, const Vec3& objectPos, TObjectType auxObject, const Vec3& auxObjectPos) const { bool generationHandled = false; if (stricmp(parameters.query, "advantagePoints") == 0) { generationHandled = true; CRY_ASSERT_MESSAGE(gEnv->pAISystem != NULL, "Expected AI System to exist, but it didn't."); IAIObjectManager* pAIObjMgr = gEnv->pAISystem->GetAIObjectManager(); IAIObjectIter* advPointObjIter = pAIObjMgr->GetFirstAIObjectInRange(OBJFILTER_TYPE, AIANCHOR_ADVANTAGE_POINT, objectPos, details.fSearchDist, true); if (advPointObjIter != NULL) { while (IAIObject* advPointObj = advPointObjIter->GetObject()) { const Vec3& advPointPos = advPointObj->GetPos(); const Vec3& advPointDir = advPointObj->GetEntityDir(); if (!g_pGame->GetGameAISystem()->GetAdvantagePointOccupancyControl().IsAdvantagePointOccupied(advPointPos, parameters.pOwner.actorEntityId)) { Vec3 advPointToObjDir = (auxObjectPos - advPointPos).GetNormalizedSafe(); float dotProduct = advPointToObjDir.Dot(advPointDir); bool objIsVisibleFromAdvPoint = (dotProduct > 0.5f); if (objIsVisibleFromAdvPoint) { parameters.result->AddPoint(advPointPos); } } advPointObjIter->Next(); } advPointObjIter->Release(); } } else if (stricmp(parameters.query, "tagPoints") == 0) { generationHandled = true; if (IEntity* actorEntity = gEnv->pEntitySystem->GetEntity(parameters.pOwner.actorEntityId)) { unsigned int tagPointIndex = 0; string tagPointName; while (1) { tagPointName.Format("%s%s%d", actorEntity->GetName(), details.tagPointPostfix.c_str(), tagPointIndex++); if (IEntity* tagPoint = gEnv->pEntitySystem->FindEntityByName(tagPointName.c_str())) parameters.result->AddPoint(tagPoint->GetWorldPos()); else break; } } } return generationHandled; }