IEntity* CLaserBeam::CreateLaserEntity()
{
	IEntity* pLaserEntity = gEnv->pEntitySystem->GetEntity(m_laserEntityId);
	if (pLaserEntity)
		return pLaserEntity;

	IEntity* pOwnerEntity = gEnv->pEntitySystem->GetEntity(m_ownerEntityId);
	if (!pOwnerEntity)
		return 0;

	SEntitySpawnParams spawnParams;
	spawnParams.pClass = gEnv->pEntitySystem->GetClassRegistry()->GetDefaultClass();
	spawnParams.sName = "LaserBeam";
	spawnParams.nFlags = (pOwnerEntity->GetFlags() | ENTITY_FLAG_NO_SAVE) & ~ENTITY_FLAG_CASTSHADOW;

	IEntity* pNewEntity = gEnv->pEntitySystem->SpawnEntity(spawnParams);

	if(pNewEntity)
	{
		m_laserEntityId = pNewEntity->GetId();


		IEntityRenderProxy *pRenderProxy = (IEntityRenderProxy*)pNewEntity->GetProxy(ENTITY_PROXY_RENDER);
		IRenderNode * pRenderNode = pRenderProxy?pRenderProxy->GetRenderNode():NULL;

		if(pRenderNode)
			pRenderNode->SetRndFlags(ERF_RENDER_ALWAYS,true);

		SetLaserEntitySlots(false);
	}

	return pNewEntity;
}
Ejemplo n.º 2
0
void CBoidsProxy::OnTrigger( bool bEnter,SEntityEvent &event )
{
	EntityId whoId = (EntityId)event.nParam[0];
	IEntity *pEntity = gEnv->pEntitySystem->GetEntity(whoId);

	if (pEntity)
	{
		if (pEntity->GetFlags() & ENTITY_FLAG_LOCAL_PLAYER)
		{
			if (bEnter)
				m_playersInCount++;
			else
				m_playersInCount--;

			if (m_playersInCount == 1)
			{
				// Activates entity when player is nearby.
				m_pEntity->Activate(true);
				if (m_pFlock)
					m_pFlock->SetEnabled(true);
			}
			if (m_playersInCount <= 0)
			{
				// Activates entity when player is nearby.
				m_playersInCount = 0;
				m_pEntity->Activate(false);
				if (m_pFlock)
					m_pFlock->SetEnabled(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);
}
Ejemplo n.º 4
0
int CScriptBind_Boids::CreateFlock( IFunctionHandler *pH, SmartScriptTable entity,int nType,SmartScriptTable paramTable )
{
	IEntity *pEntity = GetEntity(entity);
	if (!pEntity)
	{
		GameWarning( "Boids.CreateFlock called with an invalid entity" );
		return pH->EndFunction();
	}

	pEntity->SetFlags( pEntity->GetFlags() | ENTITY_FLAG_CLIENT_ONLY );

	CFlock *pFlock = 0;
	switch (nType) {
	case EFLOCK_BIRDS:
		pFlock = new CBirdsFlock(pEntity);
		break;
	case EFLOCK_CHICKENS:
		pFlock = new CChickenFlock(pEntity);
		break;
	case EFLOCK_FISH:
		pFlock = new CFishFlock(pEntity);
		break;
	case EFLOCK_FROGS:
		pFlock = new CFrogFlock(pEntity);
		break;
	case EFLOCK_TURTLES:
		pFlock = new CTurtleFlock(pEntity);
		break;
	case EFLOCK_BUGS:
		pFlock = new CBugsFlock(pEntity);
		break;
	}
	if (pFlock==NULL)
	{
		GameWarning( "Boids.CreateFlock wrong flock type %d specified",nType );
		return pH->EndFunction();
	}

	//////////////////////////////////////////////////////////////////////////
	// Creates a boids proxy for this entity, and attach flock to it.
	CBoidsProxy *pBoidsProxy = new CBoidsProxy(pEntity);
	pEntity->SetProxy( ENTITY_PROXY_BOIDS,pBoidsProxy );

	SBoidContext bc;
	pFlock->GetBoidSettings( bc );

	SBoidsCreateContext ctx;
	if (ReadParamsTable( paramTable,bc,ctx ))
	{
		bc.entity = pEntity;
		pFlock->SetBoidSettings( bc );
		pFlock->CreateBoids( ctx );
	}

	// Assign flock to boids proxy and update some settings.
	pBoidsProxy->SetFlock(pFlock);

	return pH->EndFunction();
}
Ejemplo n.º 5
0
void CScriptbind_Entity::RemoveEntity(EntityId id, bool removeNow)
{
	IEntity *pEntity = gEnv->pEntitySystem->GetEntity(id);
	if(pEntity)
	{
		if(!(pEntity->GetFlags() & ENTITY_FLAG_NO_SAVE))
		{
			GetMonoScriptSystem()->GetCryBraryAssembly()->GetException("CryEngine", "EntityRemovalException", "Attempted to remove an entity placed via Editor")->Throw();
			return;
		}

		gEnv->pEntitySystem->RemoveEntity(id, removeNow);
	}
}
Ejemplo n.º 6
0
void CJaw::OnDropped( EntityId actorId, bool ownerWasAI)
{
	CItem::OnDropped(actorId, ownerWasAI);

	IEntity* pEntity = GetEntity();

	uint32 flags = pEntity->GetFlags();	
	flags &= ~ENTITY_FLAG_NO_PROXIMITY;
	pEntity->SetFlags(flags);

	m_expended_ammo = 0;

	m_laserGuider.TurnOffLaser();
}
void CReplayActor::TransitionToCorpse(IEntity& corpse)
{
	IEntity* pEntity = GetEntity();
	if(ICharacterInstance *pCharInst = pEntity->GetCharacter(0))
	{
		corpse.SetFlags(corpse.GetFlags() | (ENTITY_FLAG_CASTSHADOW));

		Physicalize();
		pEntity->MoveSlot(&corpse, 0);
		pCharInst->SetFlags(pCharInst->GetFlags() | CS_FLAG_UPDATE);

		LoadCharacter(pCharInst->GetFilePath());

		// Make sure corpse is spawned with no glow parts
		if(CTeamVisualizationManager* pTeamVisManager = g_pGame->GetGameRules()->GetTeamVisualizationManager())
		{
			pTeamVisManager->RefreshTeamMaterial(&corpse, false, m_isFriendly); 
		}
	}
}
//------------------------------------------------------------------------
EntityId CVehicleActionDeployRope::CreateRope(IPhysicalEntity* pLinkedEntity, const Vec3& highPos, const Vec3& lowPos)
{
	IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	char pRopeName[256];
	_snprintf(pRopeName, 256, "%s_rope_%d", m_pVehicle->GetEntity()->GetName(), m_seatId);
	pRopeName[sizeof(pRopeName)-1] = '\0';

	SEntitySpawnParams params;
	params.sName = pRopeName;
	params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
	params.pClass = pEntitySystem->GetClassRegistry()->FindClass("RopeEntity");

	IEntity* pRopeEntity = pEntitySystem->SpawnEntity(params, true);
	if (!pRopeEntity)
		return 0;

	pRopeEntity->SetFlags(pRopeEntity->GetFlags() | ENTITY_FLAG_CASTSHADOW );

	pRopeEntity->CreateProxy(ENTITY_PROXY_ROPE);

	IEntityRopeProxy* pEntityRopeProxy = (IEntityRopeProxy*) pRopeEntity->GetProxy(ENTITY_PROXY_ROPE);
	if (!pEntityRopeProxy)
	{
		pEntitySystem->RemoveEntity(pRopeEntity->GetId());
		return 0;
	}

	IRopeRenderNode* pRopeNode = pEntityRopeProxy->GetRopeRendeNode();
	assert(pRopeNode);

	Vec3 ropePoints[2];
	ropePoints[0] = highPos;
	ropePoints[1] = lowPos;

	IRopeRenderNode::SRopeParams m_ropeParams;

	m_ropeParams.nFlags = IRopeRenderNode::eRope_CheckCollisinos | IRopeRenderNode::eRope_Smooth;
	m_ropeParams.fThickness = 0.05f;
	m_ropeParams.fAnchorRadius = 0.1f;
	m_ropeParams.nNumSegments = 8;
	m_ropeParams.nNumSides = 4;
	m_ropeParams.nMaxSubVtx = 3;
	m_ropeParams.nPhysSegments = 8;
	m_ropeParams.mass = 1.0f;
	m_ropeParams.friction = 2;
	m_ropeParams.frictionPull = 2;
	m_ropeParams.wind.Set(0,0,0);
	m_ropeParams.windVariance = 0;
	m_ropeParams.waterResistance = 0;
	m_ropeParams.jointLimit = 0;
	m_ropeParams.maxForce = 0;
	m_ropeParams.airResistance = 0;
	m_ropeParams.fTextureTileU = 1.0f;
	m_ropeParams.fTextureTileV = 10.0f;

	pRopeNode->SetParams(m_ropeParams);
	pRopeNode->SetPoints(ropePoints, 2);
	pRopeNode->SetEntityOwner(m_pVehicle->GetEntity()->GetId());

	pRopeNode->LinkEndEntities(m_pVehicle->GetEntity()->GetPhysics(), NULL);

	return pRopeEntity->GetId();
}
Ejemplo n.º 9
0
//------------------------------------------------------------------------
void CWeapon::OnDropped(EntityId actorId, bool ownerWasAI)
{
	BROADCAST_WEAPON_EVENT(OnDropped, (this, actorId));

	BaseClass::OnDropped(actorId, ownerWasAI);

	IEntity * pEntity = GetEntity();

	if(gEnv->bServer)
	{
		bool removeWeapon = true;

		if(gEnv->bMultiplayer && GetParams().check_clip_size_after_drop)
		{
			TFireModeVector::const_iterator firemodesEndIt = m_firemodes.end();
			for (TFireModeVector::const_iterator firemodeCit = m_firemodes.begin(); firemodeCit != firemodesEndIt && removeWeapon; ++firemodeCit)
			{
				const CFireMode* pFiremode = *firemodeCit;
				if (pFiremode)
				{
					IEntityClass* pFiremodeAmmo = pFiremode->GetAmmoType();
					if (pFiremodeAmmo)
					{
						//only check the main ammo type given with the weapon
						if(SWeaponAmmoUtils::FindAmmoConst(m_weaponsharedparams->ammoParams.ammo, pFiremodeAmmo))
						{
							int currentClipAmount = GetAmmoCount(pFiremodeAmmo);
							int clipSize = pFiremode->GetClipSize();

							if(currentClipAmount > 0 && currentClipAmount >= clipSize)
							{
								removeWeapon = false;
							}
						}
					}
				}
			}
		}
		else
		{
			const bool outOfAmmo = OutOfAmmo(true) && !ownerWasAI;
			const bool removeOnDrop = GetSharedItemParams()->params.remove_on_drop;
			removeWeapon = !gEnv->pSystem->IsSerializingFile() && (outOfAmmo && removeOnDrop);
		}

		if(removeWeapon && GetParams().check_bonus_ammo_after_drop)
		{
			for(unsigned int i = 0; i < m_bonusammo.size(); ++i)
			{
				if(m_bonusammo[i].count > 0)
				{
					removeWeapon = false;
					break;
				}
			}
		}

		if(removeWeapon)
		{
			if(gEnv->IsEditor())
			{
				pEntity->Hide(true);
			}
			else
			{
				gEnv->pEntitySystem->RemoveEntity(pEntity->GetId());
			}		
		}
	}

	uint32 flags = pEntity->GetFlags();
	
	flags &= ~ENTITY_FLAG_NO_PROXIMITY;

	pEntity->SetFlags(flags);

	m_expended_ammo = 0;

	if(gEnv->bMultiplayer && (g_pGameCVars->i_highlight_dropped_weapons == 2) || (IsHeavyWeapon() && g_pGameCVars->i_highlight_dropped_weapons == 1))
	{
		HighlightWeapon(true, true);
	}
}
Ejemplo n.º 10
-1
//------------------------------------------
bool CC4Projectile::Init(IGameObject *pGameObject)
{
	bool ok = CProjectile::Init(pGameObject);

	// C4 should always be saved (unlike other projectiles)
	IEntity* pEntity = GetEntity();
	pEntity->SetFlags(pEntity->GetFlags() & ~ENTITY_FLAG_NO_SAVE);

	if(!gEnv->bServer)
	{
		CreateLight();
	}

	if(gEnv->bMultiplayer)
	{
		CGameRules *pGameRules = g_pGame->GetGameRules();
		pGameRules->RegisterTeamChangedListener(this);
		pGameRules->RegisterClientConnectionListener(this);
	}

	return ok;
}