virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
		case eFE_Activate:
			{
				IActorSystem *pActorSystem = gEnv->pGame->GetIGameFramework()->GetIActorSystem();
				IActorIteratorPtr actorIt = pActorSystem->CreateActorIterator();
				int iNumPlayers = 0;
				IActor *pActor = actorIt->Next();
				while(iNumPlayers < 4 && pActor)
				{
					if(pActor->GetChannelId())
					{
						ActivateOutput(pActInfo, iNumPlayers, pActor->GetEntityId());
						++iNumPlayers;
					}

					pActor = actorIt->Next();
				}
			}
			break;
		}
	}
Exemple #2
0
//--------------------------------------------------------------
void CWeaponSystem::OnGameTokenEvent( EGameTokenEvent event,IGameToken *pGameToken )
{
	assert(pGameToken);

	if(EGAMETOKEN_EVENT_CHANGE == event)
	{
		bool handled = false;
		if(!strcmp("weapon.effects.ice",pGameToken->GetName()))
		{
			pGameToken->GetValueAs(m_frozenEnvironment);
			handled = true;
		}
		else if(!strcmp("weapon.effects.wet",pGameToken->GetName()))
		{
			pGameToken->GetValueAs(m_wetEnvironment);
			handled = true;
		}

		if (handled)
		{
			IGameFramework* pGF = gEnv->pGame->GetIGameFramework();
			IActorSystem* pAS = pGF->GetIActorSystem();

			int count = pAS->GetActorCount();
			if (count)
			{
				IActorIteratorPtr it = pAS->CreateActorIterator();
				while (CActor* pActor = (CActor*)it->Next())
				{
					CPlayer *pPlayer = (pActor->GetActorClass() == CPlayer::GetActorClassType()) ? static_cast<CPlayer*>(pActor) : 0;
					if (pPlayer && pPlayer->GetNanoSuit())
					{
						// go through all players and turn their ice effects on/off
						IEntityRenderProxy* pRenderProxy = (IEntityRenderProxy*)pPlayer->GetEntity()->GetProxy(ENTITY_PROXY_RENDER);
						if (pRenderProxy)
						{
							uint8 mask = pRenderProxy->GetMaterialLayersMask();
							uint32 blend = pRenderProxy->GetMaterialLayersBlend();
							mask = IsFrozenEnvironment() ? mask|MTL_LAYER_DYNAMICFROZEN : mask&~MTL_LAYER_DYNAMICFROZEN;
							mask = IsWetEnvironment() ? mask|MTL_LAYER_WET : mask&~MTL_LAYER_WET;
							pRenderProxy->SetMaterialLayersMask(mask);
							pRenderProxy->SetMaterialLayersBlend(blend);
							if (CItem* pItem = static_cast<CItem*>(pPlayer->GetCurrentItem(true)))
							{
								pItem->FrostSync(true);
								pItem->WetSync(true);
							}
							if (COffHand* pOffHand = static_cast<COffHand*>(pPlayer->GetItemByClass(CItem::sOffHandClass)))
							{
								pOffHand->FrostSync(pOffHand->GetOffHandState() != eOHS_INIT_STATE);
								pOffHand->WetSync(pOffHand->GetOffHandState() != eOHS_INIT_STATE);
							}
						}
					}
				}
			}
		}
	}
}
Exemple #3
0
void CUIMultiPlayer::RequestPlayers( const SUIEvent& event )
{
	IActorIteratorPtr actors = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();
	while (IActor* pActor = actors->Next())
	{
		if (pActor->IsPlayer())
			PlayerJoined(pActor->GetEntityId(), pActor->GetEntity()->GetName());
	}
}
Exemple #4
0
void CUIMultiPlayer::RequestPlayers()
{
	IActorIteratorPtr actors = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();
	while (IActor* pActor = actors->Next())
	{
		if (pActor->IsPlayer() && m_Players.find(pActor->GetEntityId()) == m_Players.end())
		{
			PlayerJoined(pActor->GetEntityId(), pActor->GetEntity()->GetName());
		}
	}
}
Exemple #5
0
IActor* CStatHelpers::GetProfileActor( int profileId )
{
	IActorIteratorPtr aIt = g_pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();
	while( IActor* pActor = aIt->Next() )
	{
		if ( pActor->IsPlayer() )
			if ( profileId == GetProfileId(pActor->GetChannelId()) )
				return pActor;
	}

	return 0;
}
// Description:
//
// Arguments:
//
// Return:
//
bool CPersonalRangeSignaling::Update( float fElapsedTime, uint32 uDebugOrder )
{
  CRY_ASSERT( m_bInit == true );

  bool  bRet = false;

  if(m_bEnabled)
  {
    if( uDebugOrder > 0 )
    {
      DebugDraw( uDebugOrder );
    }

    // Iterate all actors and check range to them
    IActorIteratorPtr pActorIt = CCryAction::GetCryAction()->GetIActorSystem()->CreateActorIterator();
    while( IActor * pActor = pActorIt->Next() )
    {
      EntityId entityId = pActor->GetEntityId();
      if( entityId != GetEntityId() )
      {
        // Skip over if not enabled
        IAIObject const* pAIObject = GetEntityAI(entityId);
        if (!pAIObject || pAIObject->IsEnabled())
        {
          CheckActorRanges( pActor );
          CheckActorAngles( pActor );

		  // Do check on target ranges
		  MapTargetRanges::iterator itTargetRanges = m_mapTargetRanges.find(entityId);
		  if (itTargetRanges != m_mapTargetRanges.end())
		  {
		    CheckActorTargetRanges( pActor );
		  }
        }
      }
    }

    bRet = true;
  }

  return( bRet );
}
Exemple #7
0
bool SkillKill::IsGotYourBackKill(CPlayer* pShooterPlayer, CPlayer* pTargetPlayer)
{
    //To use the new actor manager stuff when merged back to postalpha
    const float maxDistSq = sqr(g_pGameCVars->g_gotYourBackKill_targetDistFromFriendly);
    const float fovRange = cry_cosf(DEG2RAD(g_pGameCVars->g_gotYourBackKill_FOVRange));

    IActorIteratorPtr pActorIterator = g_pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();

    Vec3 targetLocation = pTargetPlayer->GetEntity()->GetWorldPos();
    SMovementState targetMovementState;
    pTargetPlayer->GetMovementController()->GetMovementState(targetMovementState);

    Vec3 targetAimDirection = targetMovementState.aimDirection;

    while(CActor* pActor = static_cast<CActor*>(pActorIterator->Next()))
        {
            if(pActor != pShooterPlayer && !pActor->IsDead() && pShooterPlayer->IsFriendlyEntity(pActor->GetEntityId()))
                {
                    Vec3 actorLocation = pActor->GetEntity()->GetWorldPos();
                    Vec3 distance = actorLocation - targetLocation;

                    if(distance.GetLengthSquared() < maxDistSq)
                        {
                            distance.Normalize();
                            if(distance.Dot(targetAimDirection) > fovRange)
                                {
                                    SMovementState actorMovementState;
                                    pActor->GetMovementController()->GetMovementState(actorMovementState);
                                    Vec3 actorAimDirection = actorMovementState.aimDirection;

                                    if(actorAimDirection.Dot(-distance) < fovRange)
                                        {
                                            return true;
                                        }
                                }
                        }
                }
        }

    return false;
}
Exemple #8
0
bool SkillKill::IsGuardianKill(CPlayer* pShooterPlayer, CPlayer* pTargetPlayer)
{
    EntityId targetId = pTargetPlayer->GetEntityId();

    float currentTime = gEnv->pTimer->GetFrameStartTime().GetSeconds();

    IActorIteratorPtr pActorIterator = g_pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();

    while(CActor* pActor = static_cast<CActor*>(pActorIterator->Next()))
        {
            if(pActor != pShooterPlayer && !pActor->IsDead() && pActor->IsPlayer() && pShooterPlayer->IsFriendlyEntity(pActor->GetEntityId()))
                {
                    CPlayer* pPlayer = static_cast<CPlayer*>(pActor);

                    if((pPlayer->GetLastAttacker() == targetId) && (currentTime - pPlayer->GetLastDamageSeconds() < g_pGameCVars->g_guardian_maxTimeSinceLastDamage))
                        {
                            return true;
                        }
                }
        }

    return false;
}
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);
}
void CAICounter_Alertness::UpdateCounters()
{
	if (!gEnv->pGame)
		return;
	const IActor*     pLocalPlayer    = gEnv->pGame->GetIGameFramework()->GetClientActor();
	const IAIObject*  pAILocalPlayer  = pLocalPlayer ? pLocalPlayer->GetEntity()->GetAI() : NULL;
	if (!pAILocalPlayer)
		return;

	m_bJustUpdated = true;

	if (!m_bFactionVectorsAreValid)
	{
		m_alertnessFaction.clear();
		m_alertnessFaction.resize( gEnv->pAISystem->GetFactionMap().GetFactionCount(), 0 );
		m_tempAlertnessFaction.resize( gEnv->pAISystem->GetFactionMap().GetFactionCount(), 0 );
		m_bFactionVectorsAreValid = true;
	}

	for (std::vector<int>::iterator iter = m_tempAlertnessFaction.begin(); iter!=m_tempAlertnessFaction.end(); ++iter)
		(*iter)=0;
	int alertnessGlobal = 0;
	int alertnessFriends = 0;
	int alertnessEnemies = 0;


	IActorIteratorPtr actorIt = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();
	while (IActor *pActor=actorIt->Next())
	{
		if (pActor && pActor!=pLocalPlayer)
		{
			const IAIObject* pAIObject = pActor->GetEntity()->GetAI();
			if (pAIObject)
			{
				const IAIActor* pAIActor = pAIObject->CastToIAIActor();
				CRY_ASSERT(pAIActor);
				if (pAIActor && pAIActor->IsActive())
				{
					int alertness = pAIActor->GetProxy()->GetAlertnessState();
					alertnessGlobal = max( alertnessGlobal, alertness );

					uint32 faction = pAIObject->GetFactionID();
					m_tempAlertnessFaction[ faction ] = max( m_tempAlertnessFaction[ faction ], alertness );
					bool enemy = pAIObject->IsHostile( pAILocalPlayer );
					if (enemy)
						alertnessEnemies = max( alertnessEnemies, alertness );
					else
						alertnessFriends = max( alertnessFriends, alertness );
				}
			}
		}
	}

	bool hasChanged = false;
	if (m_alertnessGlobal!=alertnessGlobal || m_alertnessEnemies!=alertnessEnemies || m_alertnessFriends!=alertnessFriends)
	{
		hasChanged = true;
	}
	else
	{
		std::vector<int>::iterator iterTemp = m_tempAlertnessFaction.begin();
		std::vector<int>::iterator iter = m_alertnessFaction.begin();
		for (; iterTemp!=m_tempAlertnessFaction.end(); ++iterTemp, ++iter)
		{
			int valTemp = *iterTemp;
			int val = *iter;
			if (valTemp!=val)
			{
				hasChanged = true;
				break;
			}
		}
	}

	if (hasChanged || m_bNewListeners)
	{
		m_alertnessGlobal = alertnessGlobal;
		m_alertnessEnemies = alertnessEnemies;
		m_alertnessFriends = alertnessFriends;
		m_alertnessFaction.swap( m_tempAlertnessFaction );
		NotifyListeners();
		m_bNewListeners = false;
	}
}
//------------------------------------------------------------------------
void CGameRulesMPDamageHandling::SvOnCollision(const IEntity *pVictimEntity, const CGameRules::SCollisionHitInfo& collisionHitInfo)
{
	FUNCTION_PROFILER(gEnv->pSystem, PROFILE_GAME);
	CRY_ASSERT(gEnv->bMultiplayer);

#if !defined(_RELEASE)
	if (g_pGameCVars->g_DisableCollisionDamage)
		return;
#endif

	IGameFramework* gameFramwork = g_pGame->GetIGameFramework();

	EntityId victimID = pVictimEntity->GetId();
	EntityId offenderID = collisionHitInfo.targetId;

	const IEntity* pOffenderEntity = gEnv->pEntitySystem->GetEntity(offenderID);

	float currentTime = gEnv->pTimer->GetCurrTime();

	CActor* victimActor = static_cast<CActor*>(gameFramwork->GetIActorSystem()->GetActor(victimID));
	IVehicle* offenderVehicle = gameFramwork->GetIVehicleSystem()->GetVehicle(offenderID);
	IVehicle* victimVehicle = gameFramwork->GetIVehicleSystem()->GetVehicle(victimID);
	IActor* offenderActor = gameFramwork->GetIActorSystem()->GetActor(offenderID);

	if(pOffenderEntity && !offenderVehicle && !offenderActor)
	{
		if( IEntity* pParent = pOffenderEntity->GetParent() )
		{
			 offenderVehicle = gameFramwork->GetIVehicleSystem()->GetVehicle(pParent->GetId());
		}
	}

	// Vehicles being flipped do no damage, for now
	if (offenderVehicle != NULL && offenderVehicle->GetStatus().beingFlipped)
		return;

	// Players can't damage vehicles
	if (victimVehicle && offenderActor)
		return;

	// Filter frequent collisions
	if (pOffenderEntity)
	{
		FRAME_PROFILER("Filter out recent collisions", gEnv->pSystem, PROFILE_GAME);

		EntityCollisionRecords::const_iterator collisionRecordIter = m_entityCollisionRecords.find(victimID);
		if (collisionRecordIter != m_entityCollisionRecords.end())
		{
			const EntityCollisionRecord& record = collisionRecordIter->second;
			if (record.entityID == offenderID &&
			    record.time + EntityCollisionIgnoreTimeBetweenCollisions > currentTime)
			{
				return;
			}
		}
	}

	float offenderMass = collisionHitInfo.target_mass;

	enum
	{
		CollisionWithEntity,
		CollisionWithStaticWorld
	}
	collisionType = (pOffenderEntity || offenderMass > 0.0f) ? CollisionWithEntity : CollisionWithStaticWorld;

	const Vec3& victimVelocity = collisionHitInfo.velocity;
	const Vec3& offenderVelocity = collisionHitInfo.target_velocity;

	float relativeSpeedSq = 0.0f;
	float minSpeedToCareAboutCollisionSq = 0.0f;
	float contactMass = 0.0f;

	bool offenderIsBig = offenderMass > 1000.f;

	switch (collisionType)
	{
	case CollisionWithEntity:
		{
			Vec3 relativeVelocity = victimVelocity - offenderVelocity;
			relativeSpeedSq = relativeVelocity.GetLengthSquared();

			minSpeedToCareAboutCollisionSq = sqr(10.0f);

			if (victimActor && offenderIsBig)
			{
				minSpeedToCareAboutCollisionSq = sqr(1.0f);
			}

			if (victimActor && offenderVehicle)
			{
				//Players won't be hurt by vehicles with a negative kill player speed
				if(offenderVehicle->GetDamageParams().aiKillPlayerSpeed < 0.f)
				{
					return;
				}

				minSpeedToCareAboutCollisionSq = sqr(2.0f);
			}

			const float offenderSpeedSq = offenderVelocity.GetLengthSquared();
			if (offenderSpeedSq == 0.0f) // -- if collision target it not moving
			{
				minSpeedToCareAboutCollisionSq *= sqr(2.0f);
			}

			//////////////////////////////////////////////////////////////////////////

			contactMass = offenderMass;
			break;
		}

	case CollisionWithStaticWorld:
		{
			// Actors don't take damage from running into walls!
			if (victimActor)
			{
				return;
			}

			relativeSpeedSq = victimVelocity.GetLengthSquared();
			minSpeedToCareAboutCollisionSq = sqr(7.5f);
			contactMass = collisionHitInfo.mass;

			break;
		}
	}

	const bool contactMassIsTooLowToCare = contactMass < 0.01f;
	if (contactMassIsTooLowToCare)
		return;

			
	//////////////////////////////////////////////////////////////////////////
	// Calculate the collision damage
	if (relativeSpeedSq >= minSpeedToCareAboutCollisionSq)
	{
		bool useDefaultCalculation = true;
		float fEnergy = 0.f;
		float damage = 0.f;
		EntityId kickerId = 0;

		// Calculate damage
		if (offenderVehicle && victimActor)
		{
			useDefaultCalculation = false;
			damage = ProcessActorVehicleCollision(victimActor, victimID, offenderVehicle, offenderID, damage, collisionHitInfo, kickerId);
		}
		else if (offenderIsBig && victimActor) // i.e. a kickable car
		{
			// Try to find the kicker
			CTimeValue time = gEnv->pTimer->GetAsyncTime();
			IActorSystem* pActorSystem = gEnv->pGame->GetIGameFramework()->GetIActorSystem();
			IActorIteratorPtr pActorIterator = pActorSystem->CreateActorIterator();
			IActor* pActor = pActorIterator->Next();
			float lowestTime = 5.f;
			while (pActor != NULL)
			{
				CPlayer* pPlayer = static_cast<CPlayer*>(pActor);
				EntityId kicked = pPlayer->GetLargeObjectInteraction().GetLastObjectId();
				if (kicked==offenderID)
				{
					float timeSinceKick = (time - pPlayer->GetLargeObjectInteraction().GetLastObjectTime()).GetSeconds();
					if (timeSinceKick < lowestTime)
					{
						// We found the kicker and the kicked
						kickerId = pActor->GetEntityId();
						lowestTime = timeSinceKick;
					}
				}
				pActor = pActorIterator->Next();
			}
			damage = ProcessActorKickedVehicle(victimActor, victimID, kickerId, offenderID, damage, collisionHitInfo);
			useDefaultCalculation = false;
		}

		if (useDefaultCalculation)
		{
			fEnergy = GetCollisionEnergy(pVictimEntity, collisionHitInfo);
			if (victimVehicle || offenderIsBig)
			{
				damage = 0.0005f * fEnergy;
			}
			else
			{
				damage = 0.0025f * fEnergy;
			}

			// Apply damage multipliers
			damage *= GetCollisionDamageMult(pVictimEntity, pOffenderEntity, collisionHitInfo);

			if (victimActor)
			{
				const bool victimIsPlayer = victimActor->IsPlayer();

				if (victimIsPlayer)
				{
					damage = AdjustPlayerCollisionDamage(pVictimEntity, pOffenderEntity, collisionHitInfo, damage);
				}
			}
		}

		if (damage >= DAMAGE_THRESHOLD_COLLISIONS)
		{
			HitInfo hit;
			hit.damage = damage;
			hit.pos = collisionHitInfo.pos;
			if (collisionHitInfo.target_velocity.GetLengthSquared() > 1e-6)
				hit.dir = collisionHitInfo.target_velocity.GetNormalized();
			hit.radius = 0.0f;
			hit.partId = collisionHitInfo.partId;
			hit.targetId = victimID;
			hit.weaponId = offenderID;
			hit.shooterId = kickerId != 0 ? kickerId : offenderID;
			hit.material = 0;
			hit.type = CGameRules::EHitType::Collision;
			hit.explosion = false;

			CGameRules *pGameRules = g_pGame->GetGameRules();
			if (pGameRules->GetTeamCount() > 1)
			{
				int shooterTeamId = pGameRules->GetTeam(hit.shooterId);
				int targetTeamId = pGameRules->GetTeam(hit.targetId);

				if (shooterTeamId && (shooterTeamId == targetTeamId))
				{
					damage = GetFriendlyFireDamage(damage, hit, victimActor);
				}
			}

			if (damage >= DAMAGE_THRESHOLD_COLLISIONS)
			{
				IScriptTable* pVictimScript = pVictimEntity ? pVictimEntity->GetScriptTable() : NULL;
				IScriptTable* pOffenderScript = pOffenderEntity ? pOffenderEntity->GetScriptTable() : NULL;

				if (!pOffenderEntity && pVictimEntity)
				{
					pOffenderEntity = pVictimEntity;
					offenderID = victimID;
				}

				m_entityCollisionRecords[victimID] = EntityCollisionRecord(offenderID, currentTime);

				if(victimVehicle)
				{
					victimVehicle->OnHit(hit);
				}	
				else if (pVictimScript)
				{
					FRAME_PROFILER("Call to OnHit", gEnv->pSystem, PROFILE_GAME);

					if (!IsDead(victimActor, pVictimScript))
					{
						if (IActor* offenderDriver = offenderVehicle ? offenderVehicle->GetDriver() : NULL)
							hit.shooterId = offenderDriver->GetEntityId();

						DelegateServerHit(pVictimScript, hit, victimActor);
					}
				}
			}
		}
	}
}
//////////////////////////////////////////////////////////////////////////
//this respawns the active AI at their spawn locations
void CCheckpointSystem::RespawnAI(XmlNodeRef data)
{
	if(!data)
		return;

	XmlNodeRef actorData = data->findChild(ACTOR_FLAGS_SECTION);
	if(!actorData)
	{
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed reading actor data from checkpoint, actors won't be respawned");
		return;
	}

	IActorSystem *pActorSystem = CCryAction::GetCryAction()->GetIActorSystem();

	//first run through all actors and hide/deactivate them
	IActorIteratorPtr it = pActorSystem->CreateActorIterator();
	while (IActor *pActor = it->Next())
	{
		IEntity *pEntity = pActor->GetEntity();
		//deactivate all actors
		pEntity->Hide(true);
		pEntity->Activate(false);
	}

	//load actorflags for active actors
	XmlNodeRef activatedActors = actorData->findChild(ACTIVATED_ACTORS_SECTION);
	if(activatedActors)
	{
		int actorFlags = activatedActors->getNumAttributes();
		const char *key;
		const char *value;
		for(int i = 0; i < actorFlags; ++i)
		{
			activatedActors->getAttributeByIndex(i, &key, &value);
			//format is "idXXX"
			CRY_ASSERT(strlen(key)>2);
			EntityId id = (EntityId)(atoi(&key[2]));
			bool foundEntity = RepairEntityId(id, value);
			if(foundEntity)
			{
				IActor* pActor = pActorSystem->GetActor(id);
				if(pActor)
				{
					pActor->GetEntity()->Hide(false);
					pActor->GetEntity()->Activate(true);
				}
				else
					CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed finding actor %i from checkpoint.", (int)id);
			}
			else
				CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Failed finding actor %s from checkpoint, actor is not setup correctly.", value);
		}
	}
	else
		CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "Deactivated actors section was missing in checkpoint.");

	it = pActorSystem->CreateActorIterator();
	//iterate all actors and respawn if active
	while (IActor *pActor = it->Next())
	{
		IEntity *pEntity = pActor->GetEntity();
		if(pEntity->GetId() == LOCAL_PLAYER_ENTITY_ID) //don't respawn player
			continue;

		//we don't respawn deactivated actors
		if(!pEntity->IsHidden() && pEntity->IsActive())
		{
			pActor->SetHealth(0);
			pActor->Respawn();
		}
		else //but we still reset their position
		{
			pActor->ResetToSpawnLocation();
		}
	}
}
//------------------------------------------------------------------------
bool CGameRules::OnPromoteToServer(SHostMigrationInfo& hostMigrationInfo, uint32& state)
{
	if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session))
	{
		return true;
	}

	CryLogAlways("[Host Migration]: CGameRules::OnPromoteToServer() started");

	// Server time will change after we migrate (change from old server time to new server time)
	m_gameStartedTime.SetValue(m_gameStartedTime.GetValue() - m_cachedServerTime.GetValue());
	m_gameStartTime.SetValue(m_gameStartTime.GetValue() - m_cachedServerTime.GetValue());

	// If this migration has reset (we're not the original anticipated host, remove any entities from the first attempt
	if (!m_hostMigrationCachedEntities.empty())
	{
		HostMigrationRemoveDuplicateDynamicEntities();
	}

	// Now we know we're the server, remove the actors for anyone we know isn't going to migrate
	CGameLobby *pGameLobby = g_pGame->GetGameLobby();
	CRY_ASSERT(pGameLobby);
	if (pGameLobby)
	{
		TPlayers playersToRemove;

		IActorSystem *pActorSystem = g_pGame->GetIGameFramework()->GetIActorSystem();

		playersToRemove.reserve(pActorSystem->GetActorCount());

		IActorIteratorPtr actorIt = pActorSystem->CreateActorIterator();
		IActor *pActor;
		while (pActor = actorIt->Next())
		{
			if (pActor->IsPlayer())
			{
				CRY_ASSERT(pActor->GetChannelId());
				SCryMatchMakingConnectionUID conId = pGameLobby->GetConnectionUIDFromChannelID((int) pActor->GetChannelId());
				if (pGameLobby->GetSessionNames().Find(conId) == SSessionNames::k_unableToFind)
				{
					CryLog("  player '%s' has not got a corresponding CGameLobby entry, removing actor", pActor->GetEntity()->GetName());
					playersToRemove.push_back(pActor->GetEntityId());
				}
			}
		}

		const int numPlayersToRemove = playersToRemove.size();
		for (int i = 0; i < numPlayersToRemove; ++ i)
		{
			FakeDisconnectPlayer(playersToRemove[i]);
		}
	}

	for (uint32 i = 0; i < MAX_PLAYERS; ++ i)
	{
		m_migratedPlayerChannels[i] = 0;
	}

	IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();

	IEntityItPtr it = gEnv->pEntitySystem->GetEntityIterator();
	it->MoveFirst();

	for (uint32 i = 0; i < m_hostMigrationItemMaxCount; ++ i)
	{
		m_pHostMigrationItemInfo[i].Reset();
	}
	uint32 itemIndex = 0;

	IEntity *pEntity = NULL;
	while (pEntity = it->Next())
	{
		IItem *pItem = pItemSystem->GetItem(pEntity->GetId());
		if (pItem)
		{
			if (pItem->GetOwnerId())
			{
				IEntity *pOwner = gEnv->pEntitySystem->GetEntity(pItem->GetOwnerId());
				if (pOwner)
				{
					EntityId currentItemId = 0;

					IActor *pOwnerActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pOwner->GetId());
					if (pOwnerActor)
					{
						IItem *pCurrentItem = pOwnerActor->GetCurrentItem();
						currentItemId = pCurrentItem ? pCurrentItem->GetEntityId() : 0;
					}

					CryLog("[CG] Item '%s' is owned by '%s'", pEntity->GetName(), pOwner->GetName());
					//m_pHostMigrationItemInfo[itemIndex].Set(pEntity->GetId(), pOwner->GetId(), pItem->IsUsed(), (pItem->GetEntityId() == currentItemId));
					itemIndex ++;
					if (itemIndex >= m_hostMigrationItemMaxCount)
					{
						CRY_ASSERT(itemIndex < m_hostMigrationItemMaxCount);
						break;
					}
				}
			}
		}
		// Tell entities that we're host migrating
		// - Currently only used by ForbiddenArea but may well be needed for other entities later
		// - Currently only called on the new server, add to OnDemoteToClient if we need to use this on a client
		IScriptTable *pScript = pEntity->GetScriptTable();
		if (pScript != NULL && pScript->GetValueType("OnHostMigration") == svtFunction)
		{
			m_pScriptSystem->BeginCall(pScript, "OnHostMigration");
			m_pScriptSystem->PushFuncParam(pScript);
			m_pScriptSystem->PushFuncParam(true);
			m_pScriptSystem->EndCall();
		}
	}

	// This needs initialising on the new server otherwise the respawn timer will be counting down
	// from uninitialised data.  Likewise for the pre-round timer.
	ResetReviveCycleTime();

	const int numRespawnParams = m_respawndata.size();
	for (int i = 0; i < numRespawnParams; ++ i)
	{
		SEntityRespawnData *pData = &m_respawndata[i];
		pEntity = gEnv->pEntitySystem->GetEntity(pData->m_currentEntityId);
		if (pEntity == NULL)
		{
			CryLog("  detected respawn entity (id=%u) is not present, scheduling for respawn", pData->m_currentEntityId);
			ScheduleEntityRespawn(pData->m_currentEntityId, false, g_pGameCVars->g_defaultItemRespawnTimer);
		}
	}

	CryLog("[Host Migration]: CGameRules::OnPromoteToServer() finished");

	CCCPOINT(HostMigration_OnPromoteToServer);
	return true;
}
void CAIAwarenessToPlayerHelper::RecalculateAwareness()
{
	int highestAlertnessInGameRightNow = 0;

	float distanceToTheClosestHostileAgentSq = FLT_MAX;
	Vec3 playerPosition(ZERO);

	const IFactionMap& factionMap = gEnv->pAISystem->GetFactionMap();
	uint8 playerFactionID = factionMap.GetFactionID("Players");

	IAIObject* playerAiObject = NULL;
	CActor* playerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor());

	if (playerActor)
	{
		if (IEntity* playerEntity = playerActor->GetEntity())
		{
			playerPosition = playerEntity->GetWorldPos();
			playerAiObject = playerEntity->GetAI();
		}
	}

	IF_UNLIKELY ((playerActor == NULL) || (playerAiObject == NULL))
		return;

	const bool playerIsCloaked = playerActor ? playerActor->IsCloaked() : true;

	const bool applyProximityToHostileAgentIncrement = m_actualAwareness < kAIAwarenessToPlayerAware && !playerPosition.IsZero();

	// Go through actors
	IActorIteratorPtr actorIt = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->CreateActorIterator();
	if (actorIt)
	{
		while (IActor* actor = actorIt->Next())
		{
			const IAIObject* ai = actor->GetEntity()->GetAI();
			const IAIActor* aiActor = ai ? ai->CastToIAIActor() : NULL;
			if (aiActor && aiActor->IsActive())
			{
				const int alertness = GetAlertnessAffectedByVisibility(*aiActor, *playerAiObject, playerIsCloaked);

				highestAlertnessInGameRightNow = std::max(alertness, highestAlertnessInGameRightNow);

				if (applyProximityToHostileAgentIncrement && 
					factionMap.GetReaction(playerFactionID, ai->GetFactionID()) == IFactionMap::Hostile)
				{
					float distanceSq = playerPosition.GetSquaredDistance(ai->GetPos());
					if (distanceToTheClosestHostileAgentSq > distanceSq)
					{
						distanceToTheClosestHostileAgentSq = distanceSq;
					}
				}
			}
		}
	}

	// Go through non Actors
	{
		SAwarenessEntitiesVector::iterator it = m_awarenessEntities.begin();
		SAwarenessEntitiesVector::iterator end = m_awarenessEntities.end();

		for (; it != end; ++it)
		{
			const IAwarenessEntity* pAwarenessEntity = *it;
			const int awareness = pAwarenessEntity->GetAwarenessToActor( playerAiObject, playerActor );
			highestAlertnessInGameRightNow = std::max(awareness, highestAlertnessInGameRightNow);
		}
	}


	///
	assert(highestAlertnessInGameRightNow >= 0 && highestAlertnessInGameRightNow <= 2);

	switch (highestAlertnessInGameRightNow)
	{
	default: 
		{
			const float thresholdDistanceSq = square(g_pGameCVars->ai_ProximityToHostileAlertnessIncrementThresholdDistance);
			if (applyProximityToHostileAgentIncrement && distanceToTheClosestHostileAgentSq < thresholdDistanceSq)
			{
				m_actualAwareness = kAIAwarenessToPlayerAware * (1 - (distanceToTheClosestHostileAgentSq / thresholdDistanceSq));
			}
			else
			{
				m_actualAwareness = 0.0f;
			}
		}
		break;
	case 1:  m_actualAwareness = kAIAwarenessToPlayerAware;  break;
	case 2:  m_actualAwareness = kAIAwarenessToPlayerAlerted; break;
	}
}