Esempio n. 1
0
/// Utility function for activating/deactivating all associated entities
void CFlowNode_FeatureTest::ActivateAllEntities(bool activate)
{
// 	IEntityPoolManager *pEntityPoolManager = gEnv->pEntitySystem->GetIEntityPoolManager();
// 	CRY_ASSERT(pEntityPoolManager);

	// Activate/deactivate any associated entities
	for(int i = 0; i < SEQ_ENTITY_COUNT; ++i)
	{
		// If entity is pooled, this will prepare it when requesting to activate only.
		IEntity *pEnt = NULL;
		GetEntityAtIndex(i, pEnt, activate);

		if(pEnt)
		{
			// Deactivate means return pooled entities
			if(!activate && pEnt->IsFromPool())
			{
				//pEntityPoolManager->ReturnToPool(pEnt->GetId(), false);
			}
			else
			{
				pEnt->Hide(!activate);
				pEnt->Activate(activate);
			}
		}
	}
}
void CCheckpointSystem::LoadExternalEntities(XmlNodeRef parentNode)
{
	XmlNodeRef data = parentNode->findChild(EXTERNAL_ENTITIES_SECTION);
	if(!data)
		return;

	int numEntities = data->getChildCount();
	for(int i = 0; i < numEntities; ++i)
	{
		XmlNodeRef nextEntity = data->getChild(i);
		if(nextEntity)
		{
			EntityId id = 0;
			nextEntity->getAttr("id", id);
			const char *name = nextEntity->getAttr("name");
			
			//fix entityId if broken
			if(RepairEntityId(id, name))
			{
				IEntity *pEntity = gEnv->pEntitySystem->GetEntity(id);
				//setup entity
				bool bActive = false;
				bool bHidden = false;
				nextEntity->getAttr("active", bActive);
				nextEntity->getAttr("hidden", bHidden);
				pEntity->Activate(bActive);
				pEntity->Hide(bHidden);
				//load matrix
				SerializeWorldTM(pEntity, nextEntity, false);
			}
		}
	}
}
Esempio n. 3
0
/// Attempts to start the next test. Returns true if successful.
bool CFlowNode_FeatureTest::StartNextTestRun()
{
	// Ensure this is not marked as running
	CRY_ASSERT(!m_running);

	CODECHECKPOINT(FeatureTest_StartNextTestRun_Start);

	const int entityCount = GetTestEntityCount();

	// Is this a sequential test?
	const bool sequential = (entityCount > 0) && GetPortBool(&m_actInfo, eInputPorts_Sequential);

	if(sequential)
	{
		// Ensure sequence index is within a valid range (-1 indicates first run)
		CRY_ASSERT(m_entitySeqIndex >= -1 && m_entitySeqIndex < SEQ_ENTITY_COUNT);

		// If first run
		if(!TestHasRun())
		{
			CryLogAlways("Running sequential test \"%s\" for %d entities...", Name(), entityCount);
		}

		bool bHasEntry = false;
		IEntity *pSeqEntity = NULL;

		for(int i = m_entitySeqIndex + 1; i < SEQ_ENTITY_COUNT; ++i)
		{
			// Prepare the entity from pool if needed
			bHasEntry = GetEntityAtIndex(i, pSeqEntity, true);

			// If there's a valid entity at this index, use it
			if(pSeqEntity)
			{
				m_entitySeqIndex = i;
				break;
			}
			else if(bHasEntry)
			{
				// Fail this test and continue on to the next one
				m_entitySeqIndex = i;
				m_running = true;
				OnTestResult(false, "Test failed: Entity could not be found. Check Entity Pools or the Flowgraph setup.");
				break;
			}
		}

		// Prepare entity ready for test run
		if(pSeqEntity)
		{
			pSeqEntity->Hide(false);
			pSeqEntity->Activate(true);

			m_running = true;
			m_timeRunning = 0.0f;
			m_hasBeenStarted = true;

			CryLogAlways("Starting test: \"%s[%s]\". Max time: %fs.",
						 Name(),
						 pSeqEntity->GetEntityTextDescription(),
						 GetPortFloat(&m_actInfo, eInputPorts_MaxTime));

			// Output entity ID and trigger start
			ActivateOutput(&m_actInfo, eOutputPorts_SequenceEntity, pSeqEntity->GetId());
			ActivateOutput(&m_actInfo, eOutputPorts_Start, true);
		}
		else if(!bHasEntry)
		{
			// Indicate end of sequence
			m_entitySeqIndex = -1;
			CryLogAlways("Finished running sequential test \"%s\" for %d entities.", Name(), entityCount);
		}
	}
	else if(!TestHasRun())	// If test has not yet been run
	{
		// Not using sequence
		m_entitySeqIndex = -1;

		// Activate any associated entities
		ActivateAllEntities(true);

		m_running = true;
		m_timeRunning = 0.0f;
		m_hasBeenStarted = true;

		CryLogAlways("Starting test: \"%s\". Max time: %fs.",
					 Name(),
					 GetPortFloat(&m_actInfo, eInputPorts_MaxTime));

		// Start test
		ActivateOutput(&m_actInfo, eOutputPorts_Start, true);
	}

	// Additional workaround to ensure eyePosition (and therefore AI) doesn't track camera position.
	// See CPlayerMovementController::UpdateMovementState() for details.
	CPlayer *pPlayerActor = static_cast<CPlayer *>(gEnv->pGame->GetIGameFramework()->GetClientActor());

	if(pPlayerActor)
		pPlayerActor->SetThirdPerson(m_running);

	return m_running;
}
//////////////////////////////////////////////////////////////////////////
//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();
		}
	}
}
Esempio n. 5
0
void CFlashLight::EnableFogVolume(CWeapon* pWeapon, int slot, bool enable)
{
	if (!g_pGameCVars->i_flashlight_has_fog_volume)
	{
		return;
	}

	if (!m_sharedparams->pFlashLightParams)
	{
		return;
	}

	IEntity* pFogVolume = 0;

	if (m_fogVolume == 0)
	{
		const Vec3 size = Vec3(
		                    m_sharedparams->pFlashLightParams->fogVolumeRadius,
		                    m_sharedparams->pFlashLightParams->fogVolumeSize,
		                    m_sharedparams->pFlashLightParams->fogVolumeRadius);

		SEntitySpawnParams fogVolumeParams;
		fogVolumeParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("FogVolume");
		fogVolumeParams.nFlags = ENTITY_FLAG_NO_SAVE;
		fogVolumeParams.vPosition = Vec3(ZERO);

		pFogVolume = gEnv->pEntitySystem->SpawnEntity(fogVolumeParams);

		if (!pFogVolume)
		{
			return;
		}

		m_fogVolume = pFogVolume->GetId();

		SmartScriptTable pProperties;
		pFogVolume->GetScriptTable()->GetValue("Properties", pProperties);

		if (pProperties)
		{
			pProperties->SetValue("color_Color", m_sharedparams->pFlashLightParams->fogVolumeColor);
			pProperties->SetValue("GlobalDensity", m_sharedparams->pFlashLightParams->fogVolumeDensity);
			pProperties->SetValue("Size", size);
			pProperties->SetValue("FallOffScale", 0.0f);
		}

		EntityScripts::CallScriptFunction(pFogVolume, pFogVolume->GetScriptTable(), "OnPropertyChange");

		pFogVolume->Activate(true);
	}
	else
	{
		pFogVolume = gEnv->pEntitySystem->GetEntity(m_fogVolume);
	}

	if (!pFogVolume)
	{
		return;
	}

	const char* attachHelper = "lightFog_term";
	const float distance = m_sharedparams->pFlashLightParams->fogVolumeSize * 0.5f;
	ICharacterInstance* pCharacter = pWeapon->GetEntity()->GetCharacter(slot);

	if (enable && pCharacter)
	{
		IAttachmentManager* pAttachmentManager = pCharacter->GetIAttachmentManager();
		IAttachment* pAttachment = pAttachmentManager->GetInterfaceByName(attachHelper);

		if (pAttachment)
		{
			CEntityAttachment* pEntityAttachment = new CEntityAttachment();
			pEntityAttachment->SetEntityId(m_fogVolume);
			pAttachment->AddBinding(pEntityAttachment);
			QuatT relative(IDENTITY);
			relative.t.y = distance;
			pAttachment->SetAttRelativeDefault(relative);
		}
	}

	pFogVolume->Hide(!enable);
}