bool CVisibleObjectsHelper::CheckObjectViewDist(const Agent& agent, const SVisibleObject &visibleObject) const
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	assert(agent.IsValid());

	bool bInViewDist = true;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	IEntity *pAIEntity = pEntitySystem->GetEntity(agent.GetEntityID());
	IEntity *pObjectEntity = pEntitySystem->GetEntity(visibleObject.entityId);

	IComponentRender *pObjectRenderProxy = (pAIEntity != NULL && pObjectEntity ? static_cast<IComponentRender *>(pObjectEntity->GetComponent<IComponentRender>().get()) : NULL);
	if (pObjectRenderProxy != NULL)
	{
		IRenderNode *pObjectRenderNode = pObjectRenderProxy->GetRenderNode();
		if (pObjectRenderNode != NULL)
		{
			const float fDistanceSq = pAIEntity->GetWorldPos().GetSquaredDistance(pObjectEntity->GetWorldPos());
			const float fMaxViewDistSq = sqr(pObjectRenderNode->GetMaxViewDist());
			
			bInViewDist = (fDistanceSq <= fMaxViewDistSq);
		}
	}

	return bInViewDist;
}
Пример #2
0
int CScriptBind_Action::GetPlayerList( IFunctionHandler *pH )
{
	CGameServerNub * pNub = m_pCryAction->GetGameServerNub();
	if (!pNub)
	{
		GameWarning("No game server nub");
		return pH->EndFunction();
	}
	TServerChannelMap *playerMap = m_pCryAction->GetGameServerNub()->GetServerChannelMap();
	if (!playerMap)
		return pH->EndFunction();

	IEntitySystem *pES = gEnv->pEntitySystem;

	int	k=1;
	SmartScriptTable playerList(m_pSS);
	
	for (TServerChannelMap::iterator it = playerMap->begin(); it != playerMap->end(); it++)
	{
		EntityId playerId = it->second->GetPlayerId();
		
		if (!playerId)
			continue;

		IEntity *pPlayer = pES->GetEntity(playerId);
		if (!pPlayer)
			continue;
		if (pPlayer->GetScriptTable())
			playerList->SetAt(k++, pPlayer->GetScriptTable());
	}

	return pH->EndFunction(*playerList);
}
//------------------------------------------------------------------------
int CInventory::FindPrev(IEntityClass *pClass, const char *category, int firstSlot, bool wrap) const
{
	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	for (int i = (firstSlot > -1)?firstSlot+1:0; i < m_stats.slots.size(); i++)
	{
		IEntity *pEntity = pEntitySystem->GetEntity(m_stats.slots[firstSlot-i]);
		bool ok=true;
		if (pEntity->GetClass() != pClass)
			ok=false;
		if (ok && category && category[0] && strcmp(m_pGameFrameWork->GetIItemSystem()->GetItemCategory(pEntity->GetClass()->GetName()), category))
			ok=false;

		if (ok)
			return i;
	}

	if (wrap && firstSlot > 0)
	{
		int count = GetCount();
		for (int i = 0; i < firstSlot; i++)
		{
			IEntity *pEntity = pEntitySystem->GetEntity(m_stats.slots[count-i+firstSlot]);
			bool ok=true;
			if (pEntity->GetClass() != pClass)
				ok=false;
			if (ok && category && category[0] && strcmp(m_pGameFrameWork->GetIItemSystem()->GetItemCategory(pEntity->GetClass()->GetName()), category))
				ok=false;

			if (ok)
				return i;
		}
	}

	return -1;
}
Пример #4
0
void CDialogActorContext::BeginSession()
{
	DiaLOG::Log(DiaLOG::eAlways, "[DIALOG] CDialogActorContext::BeginSession: %s Now=%f 0x%p actorID=%d ",
		m_pSession->GetDebugName(), m_pSession->GetCurTime(), this, m_actorID);	

	ResetState();

	IEntitySystem* pES = gEnv->pEntitySystem;
	pES->AddEntityEventListener( m_entityID, ENTITY_EVENT_AI_DONE, this );
	pES->AddEntityEventListener( m_entityID, ENTITY_EVENT_DONE, this );
	pES->AddEntityEventListener( m_entityID, ENTITY_EVENT_RESET, this );

	switch (GetAIBehaviourMode())
	{
	case CDialogSession::eDIB_InterruptAlways:
		ExecuteAI( m_goalPipeID, "ACT_ANIM" );
		break;
	case CDialogSession::eDIB_InterruptMedium:
		ExecuteAI( m_goalPipeID, "ACT_DIALOG" );
		break;
	case CDialogSession::eDIB_InterruptNever:
		break;
	}
	m_bNeedsCancel = true;
}
Пример #5
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 CInventory::Destroy()
{
  //
  //CryLog("%s::CInventory::Destroy()",GetEntity()->GetName());
  //
	if(!GetISystem()->IsSerializingFile())
	{
		IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
		IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

		TInventoryVector deleteList = m_stats.slots;
		for (TInventoryIt it = deleteList.begin(); it != deleteList.end(); ++it)
		{
			EntityId entityId = *it;

			IItem *pItem = pItemSystem->GetItem(entityId);
			if (pItem)
			{
				RemoveItemFromCategorySlot(pItem->GetEntityId());
				pItem->RemoveOwnerAttachedAccessories();
				pItem->AttachToHand(false);
				pItem->AttachToBack(false);
				pItem->SetOwnerId(0);
			}

			pEntitySystem->RemoveEntity(entityId);
		}
	}

	Clear();
}
//------------------------------------------------------------------------
int CInventory::Validate()
{
	TInventoryVector copyOfSlots;
	copyOfSlots.reserve(m_stats.slots.size());
	std::swap(copyOfSlots, m_stats.slots);

	int count = 0;
	const int slotCount = copyOfSlots.size();

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	for (int i = 0; i < slotCount; ++i)
	{
		EntityId itemId = copyOfSlots[i];
		IEntity *pEntity = pEntitySystem->GetEntity(itemId);
		if (!pEntity)
		{
			++count;
		}
		else
		{
			m_stats.slots.push_back(itemId);
		}
	}

	return count;
}
//------------------------------------------------------------------------
int CInventory::GetCountOfClass(const char *className) const
{
	int count = 0;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	
	IEntityClass* pClass = (className != NULL) ? pEntitySystem->GetClassRegistry()->FindClass( className ) : NULL;
	if (pClass)
	{
		for (TInventoryCIt it = m_stats.slots.begin(); it != m_stats.slots.end(); ++it)
		{
			IEntity *pEntity = pEntitySystem->GetEntity(*it);
			if ((pEntity != NULL) && (pEntity->GetClass() == pClass))
			{
					++count;
			}
		}
		TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end();
		for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit)
		{
			if (*cit == pClass)
			{
				count++;
			}
		}
	}

	return count;
}
//------------------------------------------------------------------------
bool CVehicleActionEntityAttachment::DetachEntity()
{
	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	if(IEntity *pEntity = pEntitySystem->GetEntity(m_entityId))
	{
		IVehicleSystem *pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
		assert(pVehicleSystem);

		// FIXME: remove this workaround, replace by e.g. buddy constraint
		if(IVehicle *pVehicle = pVehicleSystem->GetVehicle(m_entityId))
		{
			int hitType = g_pGame->GetGameRules()->GetHitTypeId("disableCollisions");
			pVehicle->OnHit(m_pVehicle->GetEntityId(), m_pVehicle->GetEntityId(), 10.0f, Vec3(0.0f, 0.0f, 0.0f), 0.0f, hitType, false);
		}

		pEntity->DetachThis();
		m_isAttached = false;

		m_timer = g_parachuteTimeMax;
		m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_AlwaysUpdate);
		return true;
	}

	return false;
}
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);
}
//------------------------------------------------------------------------
void CVehicleDamageBehaviorDetachPart::Reset()
{
	if (m_detachedEntityId)
	{
		for(TDetachedStatObjs::iterator ite = m_detachedStatObjs.begin(), end = m_detachedStatObjs.end(); ite != end; ++ite)
		{
			CVehiclePartBase	*pPartBase = ite->first;

			if(IStatObj *pStatObj = ite->second)
			{
				if(pPartBase)
				{
					pPartBase->SetStatObj(pStatObj);
				}

				pStatObj->Release();
			}
		}

		m_detachedStatObjs.clear();

		if(GetISystem()->IsSerializingFile() != 1)
		{		
			IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
			pEntitySystem->RemoveEntity(m_detachedEntityId, true);
		}
		
		m_detachedEntityId = 0;
	}	
}
//------------------------------------------------------------------------
void CVehicleActionEntityAttachment::SpawnEntity()
{
	IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	IEntityClassRegistry* pClassRegistry = pEntitySystem->GetClassRegistry();
	assert(pClassRegistry);

	IEntityClass* pEntityClass = pClassRegistry->FindClass(m_entityClassName.c_str());
	if (!pEntityClass)
		return;

	char pEntityName[256];
	_snprintf(pEntityName, 256, "%s_%s", m_pVehicle->GetEntity()->GetName(), m_entityClassName.c_str());
	pEntityName[sizeof(pEntityName)-1] = '\0';

	SEntitySpawnParams params;
	params.sName = pEntityName;
	params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
	params.pClass = pEntityClass;

	IEntity* pEntity = pEntitySystem->SpawnEntity(params, true);
	if (!pEntity)
	{
		m_entityId = 0;
		return;
	}

	m_entityId = pEntity->GetId();

	m_pVehicle->GetEntity()->AttachChild(pEntity);
	pEntity->SetLocalTM(m_pHelper->GetVehicleTM());

	m_isAttached = true;
}
Пример #13
0
EEntityType GetEntityType(EntityId id)
{
	int type = eET_Unknown;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	if (pEntitySystem)
	{
		IEntity *pEntity = pEntitySystem->GetEntity(id);
		if (pEntity)
		{
			type = eET_Valid;

			IEntityClass *pClass = pEntity->GetClass();
			if (pClass)
			{
				const char* className = pClass->GetName();

				// Check AI
				if (pEntity->GetAI())
				{
					type |= eET_AI;
				}
				
				// Check actor
				IActorSystem *pActorSystem = gEnv->pGame->GetIGameFramework()->GetIActorSystem();
				if (pActorSystem)
				{
					IActor *pActor = pActorSystem->GetActor(id);
					if (pActor)
					{
						type |= eET_Actor;
					}
				}

				// Check vehicle
				IVehicleSystem *pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
				if (pVehicleSystem)
				{
					if (pVehicleSystem->IsVehicleClass(className))
					{
						type |= eET_Vehicle;
					}
				}

				// Check item
				IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
				if (pItemSystem)
				{
					if (pItemSystem->IsItemClass(className))
					{
						type |= eET_Item;
					}
				}
			}
		}
	}

	return (EEntityType)type;
}
Пример #14
0
//////////////////////////////////////////////////////////////////////////
//
// Allows the game code to write game-specific data into the minimap xml
// file on level export. Currently used to export data to StatsTool
//
//////////////////////////////////////////////////////////////////////////
bool CEditorGame::GetAdditionalMinimapData(XmlNodeRef output)
{
	string classes = g_pGameCVars->g_telemetryEntityClassesToExport;
	if(!classes.empty())
	{
		// additional data relating to StatsTool
		XmlNodeRef statsNode = output->findChild("StatsTool");
		if(!statsNode)
		{
			statsNode = GetISystem()->CreateXmlNode("StatsTool");
			output->addChild(statsNode);
		}
		else
		{
			statsNode->removeAllChilds();
		}

		// first build a list of entity classes from the cvar
		std::vector<IEntityClass*> interestingClasses;
		int curPos = 0;
		string currentClass = classes.Tokenize(",",curPos);
		IEntitySystem* pES = GetISystem()->GetIEntitySystem();
		if(IEntityClassRegistry* pClassReg = pES->GetClassRegistry())
		{
			while (!currentClass.empty())
			{
				if(IEntityClass* pClass = pClassReg->FindClass(currentClass.c_str()))
				{
					interestingClasses.push_back(pClass);
				}

				currentClass = classes.Tokenize(",",curPos);
			}
		}

		// now iterate through all entities and save the ones which match the classes
		if(interestingClasses.size() > 0)
		{
			IEntityItPtr it = pES->GetEntityIterator();
			while(IEntity* pEntity = it->Next())
			{
				if(stl::find(interestingClasses, pEntity->GetClass()))
				{
					XmlNodeRef entityNode = GetISystem()->CreateXmlNode("Entity");
					statsNode->addChild(entityNode);

					entityNode->setAttr("class", pEntity->GetClass()->GetName());
					Vec3 pos = pEntity->GetWorldPos();
					entityNode->setAttr("x", pos.x);
					entityNode->setAttr("y", pos.y);
					entityNode->setAttr("z", pos.z);
				}
			}
		}
	}

	return true;
}
Пример #15
0
	virtual void DestroyGameObject( const char* name )
	{
		IEntitySystem* pEntitySystem = PerModuleInterface::g_pSystemTable->pEntitySystem;
		IAUEntity* pEnt = pEntitySystem->Get(name);
		if (pEnt)
		{
			DestroyGameObject( pEnt->GetObject()->GetObjectId() );
		}
	}
Пример #16
0
	//CGameRules::IHitInfo
	virtual void OnHit(const HitInfo &hitInfo)
	{
		if(GetPortBool(&m_actInfo, EIP_Enable) == false)
			return;

		EntityId shooter = GetPortEntityId(&m_actInfo, EIP_ShooterId);

		if(shooter != 0 && shooter != hitInfo.shooterId)
			return;

		EntityId target = GetPortEntityId(&m_actInfo, EIP_TargetId);

		if(target != 0 && target != hitInfo.targetId)
			return;

		IEntitySystem *pEntitySys = gEnv->pEntitySystem;
		IEntity *pTempEntity;

		// check weapon match
		const string &weapon = GetPortString(&m_actInfo, EIP_Weapon);

		if(weapon.empty() == false)
		{
			pTempEntity = pEntitySys->GetEntity(hitInfo.weaponId);

			if(pTempEntity == 0 || weapon.compare(pTempEntity->GetClass()->GetName()) != 0)
				return;
		}

		// check ammo match
		const string &ammo = GetPortString(&m_actInfo, EIP_Ammo);

		if(ammo.empty() == false)
		{
			pTempEntity = pEntitySys->GetEntity(hitInfo.projectileId);

			if(pTempEntity == 0 || ammo.compare(pTempEntity->GetClass()->GetName()) != 0)
				return;
		}

		ActivateOutput(&m_actInfo, EOP_ShooterId, hitInfo.shooterId);
		ActivateOutput(&m_actInfo, EOP_TargetId, hitInfo.targetId);
		ActivateOutput(&m_actInfo, EOP_WeaponId, hitInfo.weaponId);
		ActivateOutput(&m_actInfo, EOP_ProjectileId, hitInfo.projectileId);
		ActivateOutput(&m_actInfo, EOP_HitPos, hitInfo.pos);
		ActivateOutput(&m_actInfo, EOP_HitDir, hitInfo.dir);
		ActivateOutput(&m_actInfo, EOP_HitNormal, hitInfo.normal);
		ActivateOutput(&m_actInfo, EOP_Damage, hitInfo.damage);
		ISurfaceType *pSurface = g_pGame->GetGameRules()->GetHitMaterial(hitInfo.material);
		ActivateOutput(&m_actInfo, EOP_Material, string(pSurface ? pSurface->GetName() : ""));
		const char *hitType = "";

		if(CGameRules *pGR = g_pGame->GetGameRules())
			hitType = pGR->GetHitType(hitInfo.type);

		ActivateOutput(&m_actInfo, EOP_HitType, string(hitType));
	}
//------------------------------------------------------------------------
CVehicleActionEntityAttachment::~CVehicleActionEntityAttachment()
{
	if(m_entityId)
	{
		IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
		assert(pEntitySystem);

		pEntitySystem->RemoveEntity(m_entityId);
	}
}
Пример #18
0
bool CDialogActorContext::ExecuteAI(int& goalPipeID, const char* signalText, IAISignalExtraData* pExtraData, bool bRegisterAsListener)
{
	IEntitySystem* pSystem = gEnv->pEntitySystem;
	IEntity* pEntity = pSystem->GetEntity(m_entityID);
	if (pEntity == 0)
		return false;

	IAIObject* pAI = pEntity->GetAI();
	if (pAI == 0)
		return false;

	unsigned short nType=pAI->GetAIType();
	if ( nType != AIOBJECT_ACTOR )
	{
		if ( nType == AIOBJECT_PLAYER )
		{
			goalPipeID = -1;

			// not needed for player 
			// pAI->SetSignal( 10, signalText, pEntity, NULL ); // 10 means this signal must be sent (but sent[!], not set)
			// even if the same signal is already present in the queue
			return true;
		}

		// invalid AIObject type
		return false;
	}

	IPipeUser* pPipeUser = pAI->CastToIPipeUser();
	if (pPipeUser)
	{
		if (goalPipeID > 0)
		{
			pPipeUser->RemoveSubPipe(goalPipeID, true);
			pPipeUser->UnRegisterGoalPipeListener( this, goalPipeID );
			goalPipeID = 0;
		}
	}

	goalPipeID = gEnv->pAISystem->AllocGoalPipeId();
	if (pExtraData == 0)
		pExtraData = gEnv->pAISystem->CreateSignalExtraData();
	pExtraData->iValue = goalPipeID;
	
	if (pPipeUser && bRegisterAsListener)
	{
		pPipeUser->RegisterGoalPipeListener( this, goalPipeID, "CDialogActorContext::ExecuteAI");
	}

	IAIActor* pAIActor = CastToIAIActorSafe(pAI);
	if(pAIActor)
		pAIActor->SetSignal( 10, signalText, pEntity, pExtraData ); // 10 means this signal must be sent (but sent[!], not set)
	// even if the same signal is already present in the queue
	return true;
}
Пример #19
0
	virtual void OnExplosion(const ExplosionInfo &explosionInfo)
	{
		if(GetPortBool(&m_actInfo, EIP_Enable) == false)
			return;

		EntityId shooter = GetPortEntityId(&m_actInfo, EIP_ShooterId);

		if(shooter != 0 && shooter != explosionInfo.shooterId)
			return;

		EntityId impactTarget = GetPortEntityId(&m_actInfo, EIP_ImpactTargetId);

		if(impactTarget != 0 && explosionInfo.impact && impactTarget != explosionInfo.impact_targetId)
			return;

		IEntitySystem *pEntitySys = gEnv->pEntitySystem;
		IEntity *pTempEntity = pEntitySys->GetEntity(explosionInfo.weaponId);

		// check ammo match
		const string &ammo = GetPortString(&m_actInfo, EIP_Ammo);

		if(ammo.empty() == false)
		{
			if(pTempEntity == 0 || ammo.compare(pTempEntity->GetClass()->GetName()) != 0)
				return;
		}

		string ammoClass = pTempEntity ? pTempEntity->GetClass()->GetName() : "";
		ActivateOutput(&m_actInfo, EOP_ShooterId, explosionInfo.shooterId);
		ActivateOutput(&m_actInfo, EOP_Ammo, ammoClass);
		ActivateOutput(&m_actInfo, EOP_Pos, explosionInfo.pos);
		ActivateOutput(&m_actInfo, EOP_Dir, explosionInfo.dir);
		ActivateOutput(&m_actInfo, EOP_Radius, explosionInfo.radius);
		ActivateOutput(&m_actInfo, EOP_Damage, explosionInfo.damage);
		ActivateOutput(&m_actInfo, EOP_Pressure, explosionInfo.pressure);
		ActivateOutput(&m_actInfo, EOP_HoleSize, explosionInfo.hole_size);
		const char *hitType = 0;

		if(CGameRules *pGR = g_pGame->GetGameRules())
			hitType = pGR->GetHitType(explosionInfo.type);

		hitType = hitType ? hitType : "";
		ActivateOutput(&m_actInfo, EOP_Type, string(hitType));

		if(explosionInfo.impact)
		{
			ActivateOutput(&m_actInfo, EOP_ImpactTargetId, explosionInfo.impact_targetId);
			ActivateOutput(&m_actInfo, EOP_ImpactNormal, explosionInfo.impact_normal);
			ActivateOutput(&m_actInfo, EOP_ImpactVelocity, explosionInfo.impact_velocity);
		}
	}
Пример #20
0
void CVTOLVehicleManager::Reset()
{
	//Drop all the registered Ids
	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	for (TVTOLList::const_iterator it = m_vtolList.begin(), end = m_vtolList.end(); it != end; ++ it)
	{
		const EntityId vtolId = it->second.entityId;
		pEntitySystem->RemoveEntityEventListener(vtolId, ENTITY_EVENT_RESET, this);
		pEntitySystem->RemoveEntityEventListener(vtolId, ENTITY_EVENT_DONE, this);
		pEntitySystem->RemoveEntityEventListener(vtolId, ENTITY_EVENT_HIDE, this);
		pEntitySystem->RemoveEntityEventListener(vtolId, ENTITY_EVENT_UNHIDE, this);
	}
	m_vtolList.clear();
}
//------------------------------------------------------------------------
IItem* CInventory::GetItemByName(const char* name) const
{
	if (!name)
		return 0;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;

	TInventoryCIt end = m_stats.slots.end();
	for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it)
	{
		if (IEntity *pEntity = pEntitySystem->GetEntity(*it))
			if (!strcmp(pEntity->GetName(),name))
				return gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pEntity->GetId());
	}

	return 0;
}
//------------------------------------------------------------------------
void CVehicleActionEntityAttachment::Reset()
{
	if(m_entityId)
	{
		IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
		assert(pEntitySystem);

		pEntitySystem->RemoveEntity(m_entityId);
	}

	SpawnEntity();

	if(m_timer > 0.0f)
		m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);

	m_timer = 0.0f;
}
//------------------------------------------------------------------------
EntityId CInventory::GetItemByClass(IEntityClass* pClass, IItem *pIgnoreItem) const
{
	if (!pClass)
		return 0;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;

	TInventoryCIt end = m_stats.slots.end();
	for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it)
	{
		if (IEntity *pEntity = pEntitySystem->GetEntity(*it))
			if (pEntity->GetClass() == pClass)
				if(!pIgnoreItem || pIgnoreItem->GetEntity() != pEntity)
					return *it;
	}

	return 0;
}
//------------------------------------------------------------------------
void CVehicleActionEntityAttachment::Update(const float deltaTime)
{
	if(m_isAttached)
		return;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	IEntity *pEntity = pEntitySystem->GetEntity(m_entityId);

	if(!pEntity)
		return;

	IPhysicalEntity *pPhysEntity = pEntity->GetPhysics();

	if(!pPhysEntity)
		return;

	pe_simulation_params paramsSim;
	float gravity;

	if(pPhysEntity->GetParams(&paramsSim))
		gravity = abs(paramsSim.gravity.z);
	else
		gravity = 9.82f;

	pe_status_dynamics dyn;

	if(pPhysEntity->GetStatus(&dyn))
	{
		pe_action_impulse impulse;
		impulse.impulse  = Matrix33(pEntity->GetWorldTM()) * Vec3(0.0f, 0.0f, 1.0f) * g_parachuteForce * gravity;
		impulse.impulse = impulse.impulse - dyn.v;
		impulse.impulse *= dyn.mass * deltaTime;
		impulse.iSource = 3;

		pPhysEntity->Action(&impulse);
	}

	m_timer -= deltaTime;

	if(m_timer <= 0.0f || dyn.v.z >= 0.0f)
		m_pVehicle->SetObjectUpdate(this, IVehicle::eVOU_NoUpdate);
}
	virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
			m_errorLogSent = false;
			break;

		case eFE_Activate:
			if (IsPortActive(pActInfo, 0)) 
			{
				IEntitySystem* pESys = gEnv->pEntitySystem;
				EntityId id1 = GetPortEntityId(pActInfo, 1);
				EntityId id2 = GetPortEntityId(pActInfo, 2);
				IEntity* pEnt1 = pESys->GetEntity( id1 );
				IEntity* pEnt2 = pESys->GetEntity( id2 );
				IEntity* pGraphEntity = pESys->GetEntity( pActInfo->pGraph->GetGraphEntity( 0 ) );
				if (pEnt1==NULL || pEnt2==NULL)
				{
					if (!m_errorLogSent)
					{
						GameWarning("[flow] Entity::EntitiesInRange - flowgraph entity: %d:'%s' - at least one of the input entities is invalid!. Entity1: %d:'%s'    Entity2:  %d:'%s'", 
							pActInfo->pGraph->GetGraphEntity( 0 ), pGraphEntity ? pGraphEntity->GetName() : "<NULL>",
							id1, pEnt1 ? pEnt1->GetName() : "<NULL>", id2, pEnt2 ? pEnt2->GetName() : "<NULL>" );
						m_errorLogSent = true;
					}
				}
				else
				{
					const float range = GetPortFloat(pActInfo, 3);
					const float distance = pEnt1->GetWorldPos().GetDistance(pEnt2->GetWorldPos()) ;
					const bool inRange = (distance <= range);
					ActivateOutput(pActInfo, 0, inRange);
					ActivateOutput(pActInfo, 1 + (inRange ? 1 : 0), true);
					ActivateOutput(pActInfo, 3, distance);

					const Vec3 distVector = pEnt2->GetPos() - pEnt1->GetPos();
					ActivateOutput(pActInfo, 4, distVector);
					m_errorLogSent = false;
				}
			}
			break;
		}
	}
Пример #26
0
/// Utility function for getting the entity at the index
/// outEntity contains the entity if one could be found at the given index, otherwise NULL
/// bPrepareFromPool is used to specify if the entity at the given index should be prepared from the pool if needed
/// NOTE: Index -1 is special case for camera entity.
/// Returns: True if there was an entityId specified at this index. Note you can still have a NULL outEntity even if true, indicating error.
bool CFlowNode_FeatureTest::GetEntityAtIndex(int index, IEntity *&outEntity, bool bPrepareFromPool)
{
	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	CRY_ASSERT(pEntitySystem);

	//IEntityPoolManager *pEntityPoolManager = pEntitySystem->GetIEntityPoolManager();
	//CRY_ASSERT(pEntityPoolManager);

	outEntity = NULL;
	bool bHasEntry = false;

	if(index >= -1 && index < SEQ_ENTITY_COUNT)
	{
		EntityId id = GetPortEntityId(&m_actInfo, int(SEQ_ENTITY_FIRST_INPUT_PORT + index));

		if(id)
		{
			bHasEntry = true;
			outEntity = pEntitySystem->GetEntity(id);

			// Prepare entity from pool if needed
			/*if (!outEntity && bPrepareFromPool && pEntityPoolManager->IsEntityBookmarked(id))
			{
				if (pEntityPoolManager->PrepareFromPool(id, true))
				{
					outEntity = pEntitySystem->GetEntity(id);
				}
				if (!outEntity)
				{
					CryLogAlways("Error: Test \"%s\" failed to prepare entity with id \'%u\' from the pool", Name(), id);
				}
			}*/
		}
	}

	return bHasEntry;
}
Пример #27
0
bool CGameRules::OnClientConnect(int channelId, bool isReset)
{
	const float fTerrainSize = static_cast<float>(gEnv->p3DEngine->GetTerrainSize());
	const float fTerrainElevation = gEnv->p3DEngine->GetTerrainElevation(fTerrainSize * 0.5f, fTerrainSize * 0.5f);
	const Vec3 vSpawnLocation(fTerrainSize * 0.5f, fTerrainSize * 0.5f, fTerrainElevation + 15.0f);

	IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
	IEntityClass* pPlayerClass = pEntitySystem->GetClassRegistry()->FindClass("Player");

	if (!pPlayerClass)
		return false;

	SEntitySpawnParams params;
	params.sName = "Player";
	params.vPosition = vSpawnLocation;
	params.pClass = pPlayerClass;

	if (channelId)
	{
		params.nFlags |= ENTITY_FLAG_NEVER_NETWORK_STATIC;
		if (INetChannel* pNetChannel = gEnv->pGame->GetIGameFramework()->GetNetChannel(channelId))
		{
			if (pNetChannel->IsLocal())
			{
				params.id = LOCAL_PLAYER_ENTITY_ID;
			}
		}
	}

	IEntity* pPlayerEntity = pEntitySystem->SpawnEntity(params, false);

	CGameObject* pGameObject = static_cast<CGameObject*>(pPlayerEntity->GetProxy(ENTITY_PROXY_USER));
	// always set the channel id before initializing the entity
	pGameObject->SetChannelId(channelId);

	return pEntitySystem->InitEntity(pPlayerEntity, params);
}
void CPlayerPlugin_InteractiveEntityMonitor::Update( const float dt )
{
	m_timeUntilRefresh -= dt;

#ifndef _RELEASE
	//Verify entity integrity
	InteractiveEntityDebugMap::iterator mapIter = m_debugMap.begin();
	InteractiveEntityDebugMap::iterator mapEnd = m_debugMap.end();
	while(mapIter != mapEnd)
	{
		if(!gEnv->pEntitySystem->GetEntity(mapIter->first))
		{
			CryLog("[ERROR] InteractiveEntityMonitor. About to crash. Registered entity no longer exists: '%s'. Tell Gary (Really this time).", mapIter->second.c_str());
			DesignerWarning(false, "[ERROR] InteractiveEntityMonitor. About to crash. Registered entity no longer exists: '%s'. Tell Gary (Really this time).", mapIter->second.c_str());
		}

		++mapIter;
	}
#endif //_RELEASE

	IEntitySystem* pEntitySys = gEnv->pEntitySystem;
	const Vec3& playerPos = GetOwnerPlayer()->GetEntity()->GetWorldTM().GetColumn3();
	if(m_bEnabled && (m_timeUntilRefresh < 0.f || playerPos.GetSquaredDistance2D(m_playerPrevPos) > g_pGameCVars->g_highlightingMovementDistanceToUpdateSquared))
	{
		for(InteractiveEntityList::iterator it = m_interactiveEntityList.begin(); it!=m_interactiveEntityList.end(); )
		{
			const EntityId entityId = it->first;
			IEntity* pEntity = pEntitySys->GetEntity(entityId);
			if(!pEntity)
			{
				it=m_interactiveEntityList.erase(it);
				continue;
			}

			if (IEntityRenderProxy* pRenderProxy = static_cast<IEntityRenderProxy *>(pEntity->GetProxy(ENTITY_PROXY_RENDER)))
			{
				const Vec3& entityPos = pEntity->GetWorldTM().GetColumn3();
				const float distSq = entityPos.GetSquaredDistance2D(playerPos);

				const bool withinHighlightDistance = distSq <= g_pGameCVars->g_highlightingMaxDistanceToHighlightSquared;
				if( withinHighlightDistance )
				{
					// Apply intensity fade over outer half distance
					float alpha = distSq * 2.0f - g_pGameCVars->g_highlightingMaxDistanceToHighlightSquared;
					alpha *= __fres(g_pGameCVars->g_highlightingMaxDistanceToHighlightSquared);
					alpha = 1.0f - clamp(alpha, 0.0f, 1.0f);

					if( (it->second & EIES_ShootToInteract) == 0 )
					{
						pRenderProxy->SetHUDSilhouettesParams(m_silhouetteInteractColor.r*alpha, m_silhouetteInteractColor.g*alpha, m_silhouetteInteractColor.b*alpha, m_silhouetteInteractColor.a*alpha);
					}
					else
					{
						pRenderProxy->SetHUDSilhouettesParams(m_silhouetteShootColor.r*alpha, m_silhouetteShootColor.g*alpha, m_silhouetteShootColor.b*alpha, m_silhouetteShootColor.a*alpha);
					}
					it->second |= EIES_Highlighted;
				}
				else if( it->second & EIES_Highlighted )
				{
					pRenderProxy->SetHUDSilhouettesParams(0.f, 0.f, 0.f, 0.f);
					it->second &= ~EIES_Highlighted;
				}
			}

			++it;
		}

		m_playerPrevPos = playerPos;
		m_timeUntilRefresh = g_pGameCVars->g_highlightingTimeBetweenForcedRefresh;
	}
}
		Dumper(EntityId entityId, const char *desc)
		{
			IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
			IEntity *pEntity = pEntitySystem->GetEntity(entityId);
			CryLogAlways(">> Id: %d [%s] $3%s $5%s", entityId, pEntity?pEntity->GetName():"<unknown>", pEntity?pEntity->GetClass()->GetName():"<unknown>", desc?desc:"");
		}
Пример #30
0
void CBattleDust::RecordEvent(EBattleDustEventType event, Vec3 worldPos, const IEntityClass* pClass)
{
	FUNCTION_PROFILER(GetISystem(), PROFILE_GAME);

	if(!g_pGameCVars->g_battleDust_enable)
		return;

	if(!gEnv->bServer)
		return;

	// this typically means the xml file failed to load. Turn off the dust.
	if(m_maxParticleCount == 0)
		return;

	SBattleEventParameter param;
	if(!GetEventParams(event, pClass, param))
		return;
	
	if(param.m_power == 0 || worldPos.IsEquivalent(Vec3(0,0,0)))
		return;

	if(m_pBattleEventClass == NULL)
		m_pBattleEventClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( "BattleEvent" );

	// first check if we need a new event
	bool newEvent = true;
	for(std::list<EntityId>::iterator it = m_eventIdList.begin(); it != m_eventIdList.end(); ++it)
	{
		EntityId areaId = (*it);
		CBattleEvent *pBattleArea = FindEvent(areaId);
		if(pBattleArea && CheckIntersection(pBattleArea, worldPos, param.m_power))
		{
			// don't need a new event as this one is within an existing one. Just merge them.
			MergeAreas(pBattleArea, worldPos, param.m_power);
			pBattleArea->m_lifeRemaining += param.m_lifetime;
			pBattleArea->m_lifetime = pBattleArea->m_lifeRemaining;
			pBattleArea->m_lifetime = CLAMP(pBattleArea->m_lifetime, 0.0f, m_maxLifetime);
			pBattleArea->m_lifeRemaining = CLAMP(pBattleArea->m_lifeRemaining, 0.0f, m_maxLifetime);
			newEvent = false;			
			break;
		}
	}
 
	if(newEvent)
	{
		IEntitySystem * pEntitySystem = gEnv->pEntitySystem;
 		SEntitySpawnParams esp;
 		esp.id = 0;
 		esp.nFlags = 0;
 		esp.pClass = m_pBattleEventClass;
 		if (!esp.pClass)
 			return;
 		esp.pUserData = NULL;
 		esp.sName = "BattleDust";
 		esp.vPosition	= worldPos;
	
		// when CBattleEvent is created it will add itself to the list
		IEntity * pEntity = pEntitySystem->SpawnEntity( esp );
		if(pEntity)
		{
			// find the just-added entity in the list, and set it's properties
			IGameObject* pGO = g_pGame->GetIGameFramework()->GetGameObject(pEntity->GetId());
			if(pGO)
			{
				CBattleEvent* pNewEvent = static_cast<CBattleEvent*>(pGO->QueryExtension("BattleEvent"));
				if(pNewEvent)
				{
					pNewEvent->m_radius = param.m_power;
					pNewEvent->m_peakRadius = param.m_power;
					pNewEvent->m_lifetime = param.m_lifetime;
					pNewEvent->m_lifeRemaining = param.m_lifetime;
					pNewEvent->m_worldPos = worldPos;

					pNewEvent->m_lifetime = CLAMP(pNewEvent->m_lifetime, 0.0f, m_maxLifetime);
					pNewEvent->m_lifeRemaining = CLAMP(pNewEvent->m_lifeRemaining, 0.0f, m_maxLifetime);

					pGO->ChangedNetworkState(CBattleEvent::PROPERTIES_ASPECT);
				}
			}
		}
	}
}