int CAIAwarenessToPlayerHelper::GetAlertnessAffectedByVisibility(const IAIActor& aiActor, const IAIObject& playerAiObject, const bool playerIsCloaked) const { int alertness = aiActor.GetProxy()->GetAlertnessState(); // Clamp the alertness to orange (1) if the player is cloaked or // if he's not currently seen by this ai actor. if (playerIsCloaked || !aiActor.CanSee(playerAiObject.GetVisionID())) { alertness = std::min(alertness, 1); } return alertness; }
CAIAwarenessToPlayerHelper::VisorIconColor CAIAwarenessToPlayerHelper::GetMarkerColorForAgent(const EntityId entityId) const { CAIAwarenessToPlayerHelper::VisorIconColor defaultColor = Green; IEntity* entity = gEnv->pEntitySystem->GetEntity(entityId); const IAIObject* ai = entity ? entity->GetAI() : NULL; const IAIActor* aiActor = ai ? ai->CastToIAIActor() : NULL; IAIObject* playerAiObject = NULL; CActor* playerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor()); if (playerActor) { if (IEntity* playerEntity = playerActor->GetEntity()) { playerAiObject = playerEntity->GetAI(); } } if (!playerActor || !playerAiObject) return defaultColor; const bool playerIsCloaked = playerActor->IsCloaked(); if (aiActor) { const int alertness = GetAlertnessAffectedByVisibility(*aiActor, *playerAiObject, playerIsCloaked); if (alertness == 0) return Green; else if (alertness == 1) return Orange; else return Red; } else { // Turrets are not AI actors so they are treated a bit differently // TODO: extend this to generic IAwarenessEntity. for now in C3 is fine as we dont want Towers to be show here. if (CTurret* turret = TurretHelpers::FindTurret(entityId)) { if (IEntity* turretEntity = turret->GetEntity()) { if (IAIObject* turretAI = turretEntity->GetAI()) { const bool turretIsDeployed = (turret->GetStateId() == eTurretBehaviorState_Deployed); if (!playerIsCloaked && turretIsDeployed && turretAI->IsHostile(playerAiObject) && turret->IsVisionIdInVisionRange(playerAiObject->GetVisionID())) return Red; else return Green; } } } } return defaultColor; }