Example #1
0
mono::object CScriptbind_Entity::GetEntitiesByClass(mono::string _class)
{
	IEntityClass *pDesiredClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString(_class));

	std::vector<EntityId> classEntities;

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

	while(!pIt->IsEnd())
	{
		if(IEntity *pEntity = pIt->Next())
		{
			if(pEntity->GetClass() == pDesiredClass)
				classEntities.push_back(pEntity->GetId());
		}
	}

	if(classEntities.size()<1)
		return nullptr;

	IMonoClass *pEntityIdClass = g_pScriptSystem->GetCryBraryAssembly()->GetClass("EntityId");

	IMonoArray *pArray = CreateMonoArray(classEntities.size());

	for(auto it = classEntities.begin(); it != classEntities.end(); ++it)
		pArray->Insert(pEntityIdClass->BoxObject(&mono::entityId(*it)));

	return pArray->GetManagedObject();
}
Example #2
0
	virtual void OnIterStart(SActivationInfo *pActInfo)
	{
		const int type = GetPortInt(pActInfo, EIP_Type);

		IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
		if (pEntitySystem)
		{
			IEntityItPtr iter = pEntitySystem->GetEntityIterator();
			if (iter)
			{
				iter->MoveFirst();
				IEntity *pEntity = NULL;
				while (!iter->IsEnd())
				{
					pEntity = iter->Next();
					if (pEntity)
					{
						const EntityId id = pEntity->GetId();
						const EEntityType entityType = GetEntityType(id);
						if (IsValidType(type, entityType))
						{
							AddEntity(id);
						}
					}
				}
			}
		}
	}
void CCheckpointSystem::DeleteDynamicEntities()
{
	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	IEntityItPtr pIt = pEntitySystem->GetEntityIterator();
	//////////////////////////////////////////////////////////////////////////
	pIt->MoveFirst();
	while (!pIt->IsEnd())
	{
		IEntity * pEntity = pIt->Next();
		uint32 nEntityFlags = pEntity->GetFlags();

		// Local player must not be deleted.
		if (nEntityFlags & ENTITY_FLAG_LOCAL_PLAYER)
			continue;

		if (nEntityFlags & ENTITY_FLAG_SPAWNED)
			pEntitySystem->RemoveEntity( pEntity->GetId() );
	}
	// Force deletion of removed entities.
	pEntitySystem->DeletePendingEntities();
	//////////////////////////////////////////////////////////////////////////

	// Reset entity pools
	pEntitySystem->GetIEntityPoolManager()->ResetPools(false);
}
Example #4
0
	EContextEstablishTaskResult OnStep( SContextEstablishState& state )
	{
		CScopedRemoveObjectUnlock unlockRemovals(CCryAction::GetCryAction()->GetGameContext());
		if (m_skipGameRules || m_skipPlayers)
		{
			IEntityItPtr i = gEnv->pEntitySystem->GetEntityIterator();

			while(!i->IsEnd())
			{
				IEntity* pEnt = i->Next();

				// skip gamerules
				if (m_skipGameRules)
					if (pEnt->GetId() == CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRulesEntity()->GetId())
						continue;

				// skip players
				if (m_skipPlayers)
				{
					IActor* pActor = CCryAction::GetCryAction()->GetIActorSystem()->GetActor(pEnt->GetId());
					if (pActor && pActor->IsPlayer())
						continue;
				}

				pEnt->ClearFlags(ENTITY_FLAG_UNREMOVABLE);

				// force remove all other entities
				gEnv->pEntitySystem->RemoveEntity(pEnt->GetId(), true);
			}

			if (!m_skipGameRules)
				gEnv->pEntitySystem->ReserveEntityId(1);
		}
		else
		{
			if(!gEnv->pSystem->IsSerializingFile())
				gEnv->pEntitySystem->Reset();
			gEnv->pEntitySystem->ReserveEntityId(1);
		}
		gEnv->pEntitySystem->ReserveEntityId( LOCAL_PLAYER_ENTITY_ID );
		
		CActionGame::Get()->OnEntitySystemReset();

		return eCETR_Ok;
	}
Example #5
0
mono::object CScriptbind_Entity::GetEntitiesByClasses(mono::object classes)
{
	IMonoArray *pClassArray = *classes;

	int numClasses = pClassArray->GetSize();
	IEntityClass **pClasses = new IEntityClass *[numClasses];
	for(int i = 0; i < numClasses; i++)
		pClasses[i] = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString((mono::string)pClassArray->GetManagedObject()));

	IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();

	IMonoClass *pEntityIdClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("EntityId");
	IMonoArray *pEntities = CreateDynamicMonoArray();
	
	pIt->MoveFirst();
	while(!pIt->IsEnd())
	{
		if(IEntity *pEntity = pIt->Next())
		{
			IEntityClass *pEntityClass = pEntity->GetClass();
			for(int i = 0; i < numClasses; i++)
			{
				if(pEntityClass == pClasses[i])
				{
					pEntities->InsertMonoObject(pEntityIdClass->BoxObject(&mono::entityId(pEntity->GetId())));
					break;
				}
			}
		}
	}

	auto result = pEntities->GetManagedObject();
	pEntities->Release();

	return result;
}
Example #6
0
mono::object CScriptbind_Entity::GetEntitiesByClass(mono::string _class)
{
	IEntityClass *pDesiredClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ToCryString(_class));

	IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();

	IMonoClass *pEntityIdClass = GetMonoScriptSystem()->GetCryBraryAssembly()->GetClass("EntityId");
	IMonoArray *pEntities = CreateDynamicMonoArray();

	pIt->MoveFirst();
	while(!pIt->IsEnd())
	{
		if(IEntity *pEntity = pIt->Next())
		{
			if(pEntity->GetClass() == pDesiredClass)
				pEntities->InsertMonoObject(pEntityIdClass->BoxObject(&mono::entityId(pEntity->GetId())));
		}
	}

	auto result = pEntities->GetManagedObject();
	pEntities->Release();

	return result;
}
Example #7
0
void CMPTutorial::Update()
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!m_enabled && g_pGameCVars->g_PSTutorial_Enabled)
		EnableTutorialMode(true);
	else if(m_enabled && !g_pGameCVars->g_PSTutorial_Enabled)
		EnableTutorialMode(false);

	m_currentEvent.m_msgDisplayTime -= gEnv->pTimer->GetFrameTime();
	if(!m_enabled)
	{	
		if(m_currentEvent.m_msgDisplayTime < 0.0f && m_currentEvent.m_msgRemovalCondition != eMRC_None)
		{
			m_currentEvent.m_msgRemovalCondition = eMRC_None;
			SAFE_HUD_FUNC(ShowTutorialText(NULL,1));
		}
	}

	// update the text... must be done even if not enabled, to ensure the 'you may reenable...' 
	//	message is shown correctly.
	if(m_currentEvent.m_numChunks > 0)
	{
		// calculate how far through the current sound we are
		CTimeValue now = gEnv->pTimer->GetFrameStartTime();
		float soundTimer = now.GetMilliSeconds() - m_currentEvent.m_soundStartTime;
		assert(soundTimer >= 0);
		float soundPercent = 1.0f;
		if(m_currentEvent.m_soundLength == 0.0f && m_currentEvent.m_pCurrentSound.get())
		{
			m_currentEvent.m_soundLength = m_currentEvent.m_pCurrentSound->GetLengthMs();
		}
		if(m_currentEvent.m_soundLength > 0.0f)
		{
			soundPercent = soundTimer / m_currentEvent.m_soundLength;
		}
		for(int i=m_currentEvent.m_numChunks-1; i > m_currentEvent.m_currentChunk; --i)
		{
			if(m_currentEvent.m_chunks[i].m_startPercent <= soundPercent)
			{
				m_currentEvent.m_currentChunk = i;

				int pos = 2; // 2=bottom, 1=middle
				IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();	
				if(pClientActor && pClientActor->GetLinkedVehicle())
				{
					pos = 1;
				}

				SAFE_HUD_FUNC(ShowTutorialText(m_currentEvent.m_chunks[i].m_text, pos));
				break;
			}
		}
	}

	if(!m_enabled)
		return;

	CPlayer* pPlayer = static_cast<CPlayer*>(g_pGame->GetIGameFramework()->GetClientActor());
	if(!pPlayer)
		return;

	// don't start until game begins
	if(pPlayer->GetSpectatorMode() != 0 || g_pGame->GetGameRules()->GetCurrentStateId() != 3)
		return;

	if(!m_initialised)
	{
		m_initialised = true;

		if(g_pGame->GetHUD())
		{
			// register as a HUD listener
			g_pGame->GetHUD()->RegisterListener(this);
		}

		// go through entity list and pull out the factories.
		IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();
		while (!pIt->IsEnd())
		{
			if (IEntity * pEnt = pIt->Next())
			{
				if(pEnt->GetClass() == m_pHQClass)
				{
					m_baseList.push_back(pEnt->GetId());
					//CryLog("Adding HQ %d to list: %d", pEnt->GetId(), m_baseList.size());
				}
				else if(pEnt->GetClass() == m_pAlienEnergyPointClass)
				{
					m_alienEnergyPointList.push_back(pEnt->GetId());
					//CryLog("Adding AEP %d to list: %d", pEnt->GetId(), m_alienEnergyPointList.size());
				}
				else if(pEnt->GetClass() == m_pSpawnGroupClass)
				{
					m_spawnGroupList.push_back(pEnt->GetId());
					//CryLog("Adding spawngroup %d to list: %d", pEnt->GetId(), m_spawnGroupList.size());
				}
				else if(pEnt->GetClass() == m_pFactoryClass)
				{
					m_factoryList.push_back(pEnt->GetId());
					//CryLog("Adding Factory %d to list: %d", pEnt->GetId(), m_factoryList.size());
				}
			}
		}
	}

	// first the briefing events. These are shown in order.
	bool showPrompt = CheckBriefingEvents(pPlayer);

	// player has been killed
	if(pPlayer->GetHealth() <= 0)
	{
		showPrompt = TriggerEvent(eTE_Killed);
	}
	else if(!showPrompt)
	{
		// check each event type here. Which might take a while.

		// entering a neutral factory
		// enter prototype factory
		// enter hostile factory
		// find alien crash
		m_entityCheckTimer -= gEnv->pTimer->GetFrameTime();
		if(m_entityCheckTimer < 0.0f)
		{
			CheckNearbyEntities(pPlayer);
			m_entityCheckTimer = ENTITY_CHECK_TIME;
		}

		// board vehicle and vehicle tutorials
		CheckVehicles(pPlayer);

		// player has been wounded
		if(pPlayer->GetHealth() < pPlayer->GetMaxHealth())
			TriggerEvent(eTE_Wounded);

		// bases
		m_baseCheckTimer -= gEnv->pTimer->GetFrameTime();
		if(m_baseCheckTimer < 0.0f)
		{
			CheckBases(pPlayer);
			m_baseCheckTimer = ENTITY_CHECK_TIME;
		}
	}

	bool promptShown = false;
	for(int i=0; i<eTE_NumEvents; ++i)
	{
		if(m_events[i].m_status == eMS_Waiting)
		{
			if(m_currentEvent.m_msgDisplayTime < -MESSAGE_GAP_TIME)
			{
				ShowMessage(m_events[i]);
			}
			promptShown = true;
			break;
		}
	}

	if(!promptShown	&& (m_currentEvent.m_msgRemovalCondition == eMRC_Time) && (m_currentEvent.m_msgDisplayTime < 0.0f))
	{
		HideMessage();
	}
}
	virtual void OnPostUpdate(float fDeltaTime)
	{
		// Get it once, then unregister to prevent unnescessary updates
		if(!m_get)
		{
			gEnv->pGame->GetIGameFramework()->UnregisterListener(this);
			return;
		}
		m_get = false;

		// Grab the container, and make sure its valid (user has to create it for us and pass the valid ID)
		IFlowSystemContainerPtr pContainer = gEnv->pFlowSystem->GetContainer(GetPortInt(&m_actInfo, EIP_ContainerId));
		
		if(!pContainer)
			return;
		
		IEntityItPtr pIt = gEnv->pEntitySystem->GetEntityIterator();

		while (!pIt->IsEnd())
		{
			if (IEntity *pEntity = pIt->Next())
			{
				//skip Local player
				if (IPhysicalEntity *physEnt = pEntity->GetPhysics())
				{
					IActor *pClientActor = gEnv->pGame->GetIGameFramework()->GetClientActor();

					if (!pClientActor)
						return;

					//skip the client actor entity
					if (physEnt == pClientActor->GetEntity()->GetPhysics())
						continue;

					AABB worldBounds;
					pEntity->GetWorldBounds(worldBounds);

					//skip further calculations if the entity is not visible at all...
					if (gEnv->pSystem->GetViewCamera().IsAABBVisible_F(worldBounds) == CULL_EXCLUSION)
						continue;

					Vec3 wpos = pEntity->GetWorldPos();
					Quat rot = pEntity->GetWorldRotation();
					AABB localBounds;

					pEntity->GetLocalBounds(localBounds);

					//get min and max values of the entity bounding box (local positions)
					Vec3 points[2];
					points[0] = wpos + rot * localBounds.min;
					points[1] = wpos + rot * localBounds.max;

					Vec3 pointsProjected[2];

					//project the bounding box min max values to screen positions
					for (int i=0; i<2; ++i)
					{
						gEnv->pRenderer->ProjectToScreen(points[i].x, points[i].y, points[i].z, &pointsProjected[i].x, &pointsProjected[i].y, &pointsProjected[i].z); 
						const float fWidth = (float)gEnv->pRenderer->GetWidth();
						const float fHeight = (float)gEnv->pRenderer->GetHeight();

						//scale projected values to the actual screen resolution
						pointsProjected[i].x *= 0.01f * fWidth;
						pointsProjected[i].y *= 0.01f * fHeight;
					}	

					//check if the projected bounding box min max values are fully or partly inside the screen selection 
					if ((m_screenX <= pointsProjected[0].x && pointsProjected[0].x <= m_screenX2) || 
						(m_screenX >= pointsProjected[0].x && m_screenX2 <= pointsProjected[1].x) || 
						(m_screenX <= pointsProjected[1].x && m_screenX2 >= pointsProjected[1].x) ||
						(m_screenX <= pointsProjected[0].x && m_screenX2 >= pointsProjected[1].x))
					{
						if ((m_screenY <= pointsProjected[0].y && m_screenY2 >= pointsProjected[0].y) ||
							(m_screenY <= pointsProjected[1].y && m_screenY2 >= pointsProjected[0].y) ||
							(m_screenY <= pointsProjected[1].y && m_screenY2 >= pointsProjected[1].y))
						{
							// Add entity to container
							pContainer->AddItem(TFlowInputData(pEntity->GetId()));
						}
					}
				}

			}
		}
	}
Example #9
0
void CBaseManager::Validate(BuildingGUID nGUID)
{
	ControllerList ValidateList;
	ControllerList::iterator itBuilding = m_ControllerList.begin();
	if (GUID_INVALID != nGUID)
	{
		// Find it
		itBuilding = m_ControllerList.find(nGUID);

		// Check if it is ready to be validated
		if (true == itBuilding->second->BeforeValidate())
			ValidateList[itBuilding->first] = itBuilding->second;
	}
	else
	{
		// Check all of them
		for (itBuilding; itBuilding != m_ControllerList.end(); itBuilding++)
		{
			if (true == itBuilding->second->BeforeValidate())
				ValidateList.insert(ControllerList::value_type(itBuilding->first,itBuilding->second));
		}
	}
	if (true == ValidateList.empty()) return; // Must have something to continue with

	// Look for new interfaces and tell them they now represent me
	IEntity *pEntity = NULL;
	IEntitySystem *pES = gEnv->pEntitySystem;
	IEntityItPtr pIt = pES->GetEntityIterator();
	while (false == pIt->IsEnd())
	{
		if (NULL != (pEntity = pIt->Next()))
		{
			// Check if it has a CNCBuilding property table and that it is
			//	interfacing this particular one
			IScriptTable *pTable;
			if (NULL != pEntity && NULL != (pTable = pEntity->GetScriptTable()))
			{
				// Get property table
				SmartScriptTable props, cncbuilding;
				if (true == pTable->GetValue("Properties", props) &&
					true == props->GetValue("CNCBuilding", cncbuilding))
				{
					// Extract and build GUID
					char const* szTeam = 0;
					char const* szClass = 0;
					cncbuilding->GetValue("Team", szTeam);
					cncbuilding->GetValue("Class", szClass);
					BuildingGUID GUID = g_D6Core->pBaseManager->GenerateGUID(szTeam, szClass);
					itBuilding = ValidateList.find(GUID);
					if (itBuilding != ValidateList.end())
						itBuilding->second->AddInterface(pEntity);
				}
			}
		}
	}

	// And finally, validate them all
	for (itBuilding = ValidateList.begin(); itBuilding != ValidateList.end(); itBuilding++)
	{
		itBuilding->second->Validate();
	}
}