예제 #1
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));
	}
예제 #2
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);
		}
	}
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
	{
		switch (event)
		{
		case eFE_Initialize:
			{
				break;
			}
		case eFE_Activate:
			{
				const string& variableName = GetPortString(pActInfo, eIn_VariableName);

				if (variableName.empty())
				{
					CryWarning(VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CAction:DRS_SetVariable: Cannot be executed without a Variable Name.");
					break;
				}

				const string& collectionName = GetPortString(pActInfo, eIn_VariableCollectionName);
				EntityId entityID = GetPortEntityId(pActInfo, eIn_EntityID);

				DRS::IVariableCollection* variableCollection = GetVariableCollection(entityID, collectionName);

				if (variableCollection)
				{					
					const string& newVariableValue = GetPortString(pActInfo, eIn_StringValue);
					variableCollection->SetVariableValue(variableName, newVariableValue.c_str(), true, GetPortFloat(pActInfo, eIn_ResetTime));
					ActivateOutput(pActInfo, eOut_VariableCollectionName, variableCollection->GetName().GetText());
				}

				break;
			}
		}
	}
//------------------------------------------------------------------------
void CFlowVehicleAttachment::Attach(SActivationInfo* pActInfo, bool attach)
{
	IVehicle* pVehicle = GetVehicle();
	if (!pVehicle)
		return;

  IVehiclePart* pPart = pVehicle->GetPart(GetPortString(pActInfo, IN_ATTACHMENT).c_str());
  if (!pPart)
    return;

  CVehiclePartEntityAttachment* pAttachment = CAST_VEHICLEOBJECT(CVehiclePartEntityAttachment, pPart);
  if (!pAttachment)
    return;

  if (!attach)
  {
    pAttachment->SetAttachmentEntity(0);
    m_attachedId = 0;
  }
  else 
  {
    EntityId entityId = GetPortEntityId(pActInfo, IN_ENTITYID);
    pAttachment->SetAttachmentEntity(entityId);
    m_attachedId = entityId;
  }
}
예제 #5
0
	virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Activate:
			const int nDrawPlayer = GetPortInt(pActInfo, EIP_DrawPlayer);
			if (IsPortActive(pActInfo, EIP_Link))
			{
				IEntity* pEntity = gEnv->pEntitySystem->GetEntity(GetPortEntityId(pActInfo, EIP_Target));
				if (pEntity)
				{
					CActor *pPlayerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor());
					if (pPlayerActor)
					{
						SActorStats* pActorStats = pPlayerActor->GetActorStats();
						if (pActorStats)
						{
							if (nDrawPlayer == -1)
								pActorStats->isHidden = true;
							else if (nDrawPlayer == 1)
								pActorStats->isHidden = false;
						}
						m_Position = pEntity->GetWorldPos();
						m_Rotation = pEntity->GetWorldRotation();

						pPlayerActor->LinkToEntity(pEntity->GetId());
						ActivateOutput(pActInfo, EOP_Linked, true);
					}
				}
			}
			if (IsPortActive(pActInfo, EIP_Unlink))
			{
				CActor *pPlayerActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetClientActor());
				if (pPlayerActor)
				{
					SActorStats* pActorStats = pPlayerActor->GetActorStats();
					if (pActorStats)
					{
						if (nDrawPlayer == -1)
							pActorStats->isHidden = true;
						else if (nDrawPlayer == 1)
							pActorStats->isHidden = false;
					}

					bool keepTransform = GetPortBool(pActInfo, EIP_KeepTransform);
					pPlayerActor->LinkToEntity(0, keepTransform);

					if(!keepTransform)
					{
						pPlayerActor->GetEntity()->SetPos(m_Position);
						pPlayerActor->GetEntity()->SetRotation(m_Rotation);
					}

					ActivateOutput(pActInfo, EOP_Unlinked, true);
				}
			}
			break;
		}
	}
	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;
		}
	}
예제 #7
0
//------------------------------------------------------------------------
void CFlowVehiclePassenger::ProcessEvent(EFlowEvent flowEvent, SActivationInfo* pActivationInfo)
{
	CFlowVehicleBase::ProcessEvent(flowEvent, pActivationInfo);

	if (flowEvent == eFE_Activate)
	{
		m_actorId = GetPortEntityId(pActivationInfo, IN_ACTORID);
		m_seatId  = GetPortInt(pActivationInfo, IN_SEATID);

		if (IVehicle* pVehicle = GetVehicle())
		{
			if (IsPortActive(pActivationInfo, IN_TRIGGERPASSENGERIN))
			{
				if (m_actorId && m_seatId > 0)
				{
					IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actorId);

					if (pActor)
					{
						IVehicle* pCurrent = pActor->GetLinkedVehicle();

						if (pCurrent && pCurrent != pVehicle)
						{
							if (IVehicleSeat* pSeat = pCurrent->GetSeatForPassenger(m_actorId))
								pSeat->Exit(false, true);
						}

						if (pCurrent == pVehicle && pCurrent->GetSeatForPassenger(m_actorId))
						{
							((CVehicle*)pVehicle)->ChangeSeat(m_actorId, 0, m_seatId);
						}
						else
						{
							if (IVehicleSeat* pSeat = pVehicle->GetSeatById(m_seatId))
								pSeat->Enter(m_actorId);
						}
					}
				}
			}

			if (IsPortActive(pActivationInfo, IN_TRIGGERPASSENGEROUT))
			{
				if (m_actorId)
				{
					if (IVehicleSeat* pSeat =  pVehicle->GetSeatForPassenger(m_actorId))
						pSeat->Exit(true);
				}
			}
		}
	}
}
  virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
  {
    switch (event)
    {    
    case eFE_Activate:
      {
        IActor* pActor = GetAIActor(pActInfo);
        if (!pActor)
          break;
        
        IEntity* pEnt = pActor->GetEntity();
        if (!pEnt)
          break;
        
        HSCRIPTFUNCTION func = 0;
        int ret = 0;
        IScriptTable* pTable = pEnt->GetScriptTable();
        if (!pTable)
          break;

        if (IsPortActive(pActInfo, 1) && pTable->GetValue("GrabObject", func))
        {                   
          IEntity* pObj = gEnv->pEntitySystem->GetEntity( GetPortEntityId(pActInfo, 0) );
          if (pObj)
          {
            IScriptTable* pObjTable = pObj->GetScriptTable();
            Script::CallReturn(gEnv->pScriptSystem, func, pTable, pObjTable, ret);
          }
          ActivateOutput(pActInfo, 0, ret);
        }  
        else if (IsPortActive(pActInfo, 2) && pTable->GetValue("DropObject", func))
        {
          bool bThrow = GetPortBool(pActInfo, 3);
          Script::CallReturn(gEnv->pScriptSystem, func, pTable, bThrow, ret);
          ActivateOutput(pActInfo, 0, ret);
        }
        
        if (pTable->GetValue("GetGrabbedObject", func))
        {          
          ScriptHandle sH(0);
          Script::CallReturn(gEnv->pScriptSystem, func, pTable, sH);
          ActivateOutput(pActInfo, 1, EntityId(sH.n));
        }
        
				if(func)
					gEnv->pScriptSystem->ReleaseFunc(func);

        break;
      }
    }
  }
예제 #9
0
	virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		switch (event)
		{
		case eFE_Initialize:
			break;
		case eFE_Activate:
			IGameFramework* const pGameFramework = gEnv->pGame->GetIGameFramework();
			IGameObject* const pGameObject = pGameFramework->GetGameObject(pActInfo->pEntity->GetId());

			if(IsPortActive(pActInfo, EIP_Enslave) || IsPortActive(pActInfo, EIP_UnEnslave) )
			{
				IAnimatedCharacter* const pAnimChar = pGameObject ? (IAnimatedCharacter*) pGameObject->QueryExtension("AnimatedCharacter") : NULL;
				if(pAnimChar && pAnimChar->GetActionController())
				{
					const EntityId slaveChar = GetPortEntityId(pActInfo, EIP_Slave);
					IGameObject* pSlaveGameObject = pGameFramework->GetGameObject(slaveChar);
					IAnimatedCharacter* pSlaveAnimChar = pSlaveGameObject ? (IAnimatedCharacter*) pSlaveGameObject->QueryExtension("AnimatedCharacter") : NULL;

					if(pSlaveAnimChar && pSlaveAnimChar->GetActionController())
					{
						IAnimationDatabaseManager &dbManager = gEnv->pGame->GetIGameFramework()->GetMannequinInterface().GetAnimationDatabaseManager();
						uint32 db_crc32 = CCrc32::ComputeLowercase(GetPortString(pActInfo, EIP_DB));
						const IAnimationDatabase* db = dbManager .FindDatabase(db_crc32);

						const string& scopeContextName = GetPortString(pActInfo, EIP_ScopeContext);
						const string& requestedScopeContext = scopeContextName.empty() ? "SlaveChar" : scopeContextName;
						const TagID scopeContext = pAnimChar->GetActionController()->GetContext().controllerDef.m_scopeContexts.Find(scopeContextName.c_str());

						pAnimChar->GetActionController()->SetSlaveController(*pSlaveAnimChar->GetActionController(), scopeContext, IsPortActive(pActInfo, EIP_Enslave) ? true : false, db);
						ActivateOutput(pActInfo, EOP_Success, 1 );
					}
					else
					{
						CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or Animated character found for the slave");
						ActivateOutput(pActInfo, EOP_Fail, 1 );
					}
				}
				else
				{
					CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or AnimatedCharacter found");
					ActivateOutput(pActInfo, EOP_Fail, 1 );
				}
			}

			break;
		}
	}
예제 #10
0
void CFlowNode_AIStateGuard::ForceAIGuard()
{
	IEntity* pTarget = gEnv->pEntitySystem->GetEntity(GetPortEntityId(&m_ActInfo, INPORT_GUARDEE));

	if(m_ActInfo.pEntity && m_ActInfo.pEntity->GetAI() && pTarget)
	{
		m_ActInfo.pEntity->GetAI()->CastToIAIActor()->SetSpeed(GetPortFloat(&m_ActInfo, INPORT_WALK_SPEED));
		IAISignalExtraData* exd = gEnv->pAISystem->CreateSignalExtraData();
		exd->point = pTarget->GetPos();
		float angle = (rand() / (float)RAND_MAX) * g_PI2; //0-(2PI)
		float range = GetPortFloat(&m_ActInfo, INPORT_INSIDE_RADIUS) + (rand() / (float)RAND_MAX) * GetPortFloat(&m_ActInfo, INPORT_OUTSIDE_RADIUS); //inside_radius-outside_radius
		exd->point.x += sinf(angle) * range;
		exd->point.y += cosf(angle) * range;
		m_ActInfo.pEntity->GetAI()->CastToIAIActor()->SetSignal(AISIGNAL_DEFAULT, "ACT_GOTO", m_ActInfo.pEntity, exd);
	}
}
예제 #11
0
	void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo)
	{
		//initialization event
		switch (event)
		{
		case eFE_Initialize:
			//since we cannot send data to the flowgraph at any time, we need to wait for updates ..
			pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
			break;
		case eFE_Activate:
			if (IsPortActive(pActInfo, EIP_LoadLastCheckpoint))
			{
				CCryAction::GetCryAction()->GetICheckpointSystem()->LoadLastCheckpoint();
			}
			break;
		case eFE_Update:
			if (m_iSaveId > 0)
			{
				ActivateOutput(pActInfo, EOP_OnSave, m_iSaveId);
				m_iSaveId = 0;
			}
			if (m_iLoadId > 0)
			{
				ActivateOutput(pActInfo, EOP_OnLoad, m_iLoadId);
				m_iLoadId = 0;
			}

			for (int entityIndex = 0, portIndex = EIP_SaveLoadEntityStart; portIndex < (EIP_SaveLoadEntityStart + NUM_SAVE_LOAD_ENTITIES); ++portIndex, ++entityIndex)
			{
				m_saveLoadEntities[entityIndex] = GetPortEntityId(pActInfo, portIndex);


			}
/*
      m_saveLoadEntities[0] = GetPortEntityId(pActInfo, EIP_SaveLoadEntity1);
      m_saveLoadEntities[1] = GetPortEntityId(pActInfo, EIP_SaveLoadEntity2);
      m_saveLoadEntities[2] = GetPortEntityId(pActInfo, EIP_SaveLoadEntity3);
      m_saveLoadEntities[3] = GetPortEntityId(pActInfo, EIP_SaveLoadEntity4);
      m_saveLoadEntities[4] = GetPortEntityId(pActInfo, EIP_SaveLoadEntity5);
 */
			break;
		}
	}
예제 #12
0
	Vec3 GetTargetPos( SActivationInfo* pActInfo )
	{
		EntityId targetId = GetPortEntityId(pActInfo, IN_TARGETID);

		Vec3 targetPos(0,0,0);

		if (targetId)
		{
			IEntity* pTarget = gEnv->pEntitySystem->GetEntity(targetId);
			if (pTarget)
			{
				AABB box;
				pTarget->GetWorldBounds(box);
				targetPos = box.GetCenter();
			}        
		}
		else
		{
			targetPos = GetPortVec3(pActInfo, IN_TARGETPOS);		
		}
		return targetPos;
	}
예제 #13
0
	void AttachObject(SActivationInfo *pActInfo)
	{
		if (pActInfo->pEntity)
		{
			EntityId entityId = GetPortEntityId(pActInfo, eIP_EntityId);
			IEntity *pEntity = gEnv->pEntitySystem->GetEntity(entityId);
			if (pEntity)
			{
				//Keep track of the last attachment performed in order to properly reset the state in the end
				m_pNewAttachment = GetAttachment(pActInfo);
				if(m_pNewAttachment)
				{
					CEntityAttachment *pEntityAttachment = new CEntityAttachment;
					pEntityAttachment->SetEntityId(entityId);
					m_pNewAttachment->AddBinding(pEntityAttachment);

					UpdateOffset(pActInfo);
					ActivateOutput(pActInfo, eOP_Attached, 0);
				}
			}
		}
	}
예제 #14
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;
}
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		
		switch (event)
		{
			case eFE_Initialize:
				{
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,false);
				}
			case eFE_Activate:
				{
					if(GetPortBool(pActInfo, 1)) {
						EntityId id = GetPortEntityId(pActInfo,EIP_EntityID);
						IEntity * entity = gEnv->pEntitySystem->GetEntity(id);
						if(entity)
						{
							Matrix34 trans; // = entity->GetWorldTM();
							trans.CreateIdentity();
															
							Quat quat =  entity->GetRotation();
							quat.v = GetPortVec3( pActInfo, EIP_Rotation_XYZ);
							quat.w = GetPortFloat( pActInfo, EIP_Rotation_W);
							
							//quat.NormalizeFast();
					
							Vec3 position = entity->GetPos();
							trans.Set(Vec3(1,1,1),quat.GetNormalized(),position);
							
							entity->SetPosRotScale(position,quat,Vec3(1,1,1));

							
						}
					}
				}
			}
	}
예제 #16
0
IItem* CFlowItemAction::GetItem(SActivationInfo* pActInfo) const
{
	EntityId itemId = GetPortEntityId(pActInfo, IAI_ItemId);
	IItem* pItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(itemId);
	return pItem;
}
예제 #17
0
    virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
    {
        switch (event)
        {
        case eFE_Initialize:
            break;
        case eFE_Activate:
            IGameFramework* pGameFramework = gEnv->pGame->GetIGameFramework();

            if(IsPortActive(pActInfo, EIP_Cast))
            {
                // setup ray + optionally skip 1 entity
                ray_hit rayHit;
                static const float maxRayDist = 100.f;
                const unsigned int flags = rwi_stop_at_pierceable|rwi_colltype_any;
                IPhysicalEntity	*skipList[1];
                int skipCount = 0;
                IEntity* skipEntity = gEnv->pEntitySystem->GetEntity(GetPortEntityId(pActInfo, EIP_SkipEntity));
                if(skipEntity)
                {
                    skipList[0] = skipEntity->GetPhysics();
                    skipCount = 1;
                }

                Vec3 rayPos = GetPortVec3(pActInfo, EIP_RayPos);
                Vec3 rayDir = GetPortVec3(pActInfo, EIP_RayDir);

                // Check if the ray hits an entity
                if(gEnv->pSystem->GetIPhysicalWorld()->RayWorldIntersection(rayPos, rayDir * 100, ent_all, flags, &rayHit, 1, skipList, skipCount))
                {
                    int type = rayHit.pCollider->GetiForeignData();

                    if (type == PHYS_FOREIGN_ID_ENTITY)
                    {
                        IEntity* pEntity = (IEntity*)rayHit.pCollider->GetForeignData(PHYS_FOREIGN_ID_ENTITY);
                        IEntityRenderProxy* pRenderProxy = pEntity ? (IEntityRenderProxy*)pEntity->GetProxy(ENTITY_PROXY_RENDER) : 0;

                        // Get the renderproxy, and use it to check if the material is a DynTex, and get the UIElement if so
                        if(pRenderProxy)
                        {
                            IRenderNode *pRenderNode = pRenderProxy->GetRenderNode();
                            IMaterial* pMaterial = pRenderProxy->GetRenderMaterial();
                            SEfResTexture* texture = 0;
                            if(pMaterial && pMaterial->GetShaderItem().m_pShaderResources)
                                texture= pMaterial->GetShaderItem().m_pShaderResources->GetTexture(EFTT_DIFFUSE);
                            IUIElement* pElement = texture ? gEnv->pFlashUI->GetUIElementByInstanceStr(texture->m_Name) : 0;

                            if(pElement && pRenderNode)
                            {
                                int m_dynTexGeomSlot = 0;
                                IStatObj* pObj = pRenderNode->GetEntityStatObj(m_dynTexGeomSlot);

                                // result
                                bool hasHit = false;
                                Vec2 uv0, uv1, uv2;
                                Vec3 p0, p1, p2;
                                Vec3 hitpos;


                                // calculate ray dir
                                CCamera cam = gEnv->pRenderer->GetCamera();
                                if (pEntity->GetSlotFlags(m_dynTexGeomSlot) & ENTITY_SLOT_RENDER_NEAREST)
                                {
                                    ICVar *r_drawnearfov = gEnv->pConsole->GetCVar("r_DrawNearFoV");
                                    assert(r_drawnearfov);
                                    cam.SetFrustum(cam.GetViewSurfaceX(),cam.GetViewSurfaceZ(),DEG2RAD(r_drawnearfov->GetFVal()),cam.GetNearPlane(),cam.GetFarPlane(), cam.GetPixelAspectRatio());
                                }

                                Vec3 vPos0 = rayPos;
                                Vec3 vPos1 = rayPos + rayDir;

                                // translate into object space
                                const Matrix34 m = pEntity->GetWorldTM().GetInverted();
                                vPos0 = m * vPos0;
                                vPos1 = m * vPos1;

                                // walk through all sub objects
                                const int objCount = pObj->GetSubObjectCount();
                                for (int obj = 0; obj <= objCount && !hasHit; ++obj)
                                {
                                    Vec3 vP0, vP1;
                                    IStatObj* pSubObj = NULL;

                                    if (obj == objCount)
                                    {
                                        vP0 = vPos0;
                                        vP1 = vPos1;
                                        pSubObj = pObj;
                                    }
                                    else
                                    {
                                        IStatObj::SSubObject* pSub = pObj->GetSubObject(obj);
                                        const Matrix34 mm = pSub->tm.GetInverted();
                                        vP0 = mm * vPos0;
                                        vP1 = mm * vPos1;
                                        pSubObj = pSub->pStatObj;
                                    }

                                    IRenderMesh* pMesh = pSubObj ? pSubObj->GetRenderMesh() : NULL;
                                    if (pMesh)
                                    {
                                        const Ray ray(vP0, (vP1-vP0).GetNormalized() * maxRayDist);
                                        hasHit = RayIntersectMesh(pMesh, pMaterial, pElement, ray, hitpos, p0, p1, p2, uv0, uv1, uv2);
                                    }
                                }

                                // skip if not hit
                                if (!hasHit)
                                {
                                    ActivateOutput(pActInfo, EOP_Failed, 1);
                                    return;
                                }

                                // calculate vectors from hitpos to vertices p0, p1 and p2:
                                const Vec3 v0 = p0-hitpos;
                                const Vec3 v1 = p1-hitpos;
                                const Vec3 v2 = p2-hitpos;

                                // calculate factors
                                const float h = (p0-p1).Cross(p0-p2).GetLength();
                                const float f0 = v1.Cross(v2).GetLength() / h;
                                const float f1 = v2.Cross(v0).GetLength() / h;
                                const float f2 = v0.Cross(v1).GetLength() / h;

                                // find the uv corresponding to hitpos
                                Vec3 uv = uv0 * f0 + uv1 * f1 + uv2 * f2;

                                // translate to flash space
                                int x, y, width, height;
                                float aspect;
                                pElement->GetFlashPlayer()->GetViewport(x, y, width, height, aspect);
                                int iX = int_round(uv.x * (float)width);
                                int iY = int_round(uv.y * (float)height);

                                // call the function provided if it is present in the UIElement description
                                string funcName = GetPortString(pActInfo, EIP_CallFunction);
                                const SUIEventDesc* eventDesc = pElement->GetFunctionDesc(funcName);
                                if(eventDesc)
                                {
                                    SUIArguments arg;
                                    arg.AddArgument(iX);
                                    arg.AddArgument(iY);
                                    pElement->CallFunction(eventDesc->sName, arg);
                                }

                                ActivateOutput(pActInfo, EOP_Success, 1);
                            }
                        }
                    }
                }

                ActivateOutput(pActInfo, EOP_Failed, 1);
            }

            break;
        }
    }
예제 #18
0
	virtual void ProcessEvent(EFlowEvent event, SActivationInfo *pActInfo)
	{
		
		
		switch (event)
		{
		case eFE_Initialize:{
			pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true);
		}
		case eFE_Activate:
			{
				pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID,true);
			}
			break;
		
		case eFE_Update:
			{	
				//if (IsPortActive(pActInfo, PORT_IN_ENABLE))
				//{
					EntityId id = GetPortEntityId(pActInfo,EIP_EntityID);
					EntityId parentid = GetPortEntityId(pActInfo,EIP_ParentEntityID);
					//IGameObject *pGameObj = gEnv->pGameFramework->GetGameObject(id);
					IEntity * entity = gEnv->pEntitySystem->GetEntity(id);
					IEntity * parententity = gEnv->pEntitySystem->GetEntity(parentid);
					if(entity){
						Matrix34 trans; // = entity->GetWorldTM();
						trans.CreateIdentity();
						Matrix34 transparent;
						transparent.CreateIdentity(); 

						if (parententity){
							//quatParent = parententity->GetRotation();
							transparent = parententity->GetWorldTM();
							//CryLogAlways("Parent : [%f,%f,%f]",transparent.GetColumn0().x,transparent.GetColumn0().y,transparent.GetColumn0().z);
							//CryLogAlways("Parent : [%f,%f,%f]",transparent.GetColumn1().x,transparent.GetColumn1().y,transparent.GetColumn1().z);
							//CryLogAlways("Parent : [%f,%f,%f]",transparent.GetColumn2().x,transparent.GetColumn2().y,transparent.GetColumn2().z);
							//CryLogAlways("Parent : [%f,%f,%f]",transparent.GetColumn3().x,transparent.GetColumn3().y,transparent.GetColumn3().z);
							
						}
						
						Quat quat =  entity->GetRotation();
						quat.v = GetPortVec3( pActInfo, EIP_Rotation_XYZ);
						quat.w = GetPortFloat( pActInfo, EIP_Rotation_W);
						quat.NormalizeFast();
						

						Vec3 position = GetPortVec3(pActInfo, EIP_Position);
						
						trans.Set(Vec3(1,1,1),quat.GetNormalized(),position);
						//transparent.SetTranslation(Vec3(0,0,0));
						
						Vec3 positionlocal = transparent.TransformVector(position);

						trans = transparent * trans;

						//Matrix34 transresult ;
						//transresult.CreateIdentity();
						//transresult.Scale
						
						trans.SetTranslation(positionlocal+parententity->GetPos());

						if(trans.IsValid()){
							entity->SetWorldTM(trans);
						}
						else {
							//CryLogAlways("[%f,%f,%f]",trans.GetColumn0().x,trans.GetColumn0().y,trans.GetColumn0().z);
							//CryLogAlways("[%f,%f,%f]",trans.GetColumn1().x,trans.GetColumn1().y,trans.GetColumn1().z);
							//CryLogAlways("[%f,%f,%f]",trans.GetColumn2().x,trans.GetColumn2().y,trans.GetColumn2().z);
							//CryLogAlways("[%f,%f,%f]",trans.GetColumn3().x,trans.GetColumn3().y,trans.GetColumn3().z);
							//CryLogAlways("rot : [%f,%f,%f,%f]",trans.GetRo);
							//CryLogAlways("sca : [%f,%f,%f]",trans.GetColumn0().x,trans.GetColumn0().y,trans.GetColumn0().z);
						}
					}
					//CryLogAlways("%i",id);
				//}
			}
		}
	}
예제 #19
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{ 
		switch (event)
		{
		case eFE_Initialize:
			{
				m_actInfo = *pActInfo;
				Reset();
			}
			break;

		case eFE_Activate:
			{ 
				IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();

				// create listener
				if (IsPortActive(pActInfo, IN_DISABLE))
				{ 
					Reset();
				}
				if (IsPortActive(pActInfo, IN_ENABLE))
				{ 
					Reset();
					IItem* pItem = 0;

					EntityId weaponId = GetPortEntityId(pActInfo, IN_WEAPONID);                    
					if (weaponId != 0)
					{
						pItem = pItemSys->GetItem(weaponId);
					}
					else
					{            
						IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
						if (!pActor) 
							return;

						IInventory *pInventory = pActor->GetInventory();
						if (!pInventory)
							return;

						const string& weaponClass = GetPortString(pActInfo, IN_WEAPONCLASS);
						if (!weaponClass.empty())
						{
							// get actor weapon by class
							IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(weaponClass);
							pItem = pItemSys->GetItem( pInventory->GetItemByClass(pClass) );
						}
						else
						{
							// get current actor weapon
							pItem = pItemSys->GetItem(pInventory->GetCurrentItem());
						}
					}          

					if (!pItem || !pItem->GetIWeapon())
					{
						GameWarning("[flow] CFlowNode_WeaponListener: no item/weapon.");
						return;
					}

					m_weapId = pItem->GetEntity()->GetId();
					IWeapon* pWeapon = pItem->GetIWeapon();

					// set initial ammo
					m_ammo = GetPortInt(pActInfo, IN_AMMO);
					if (m_ammo == 0)
						m_ammo = -1; // 0 input means infinite

					// set weapon listener                            
					pWeapon->AddEventListener(this, "CFlowNode_WeaponListener");

					m_active = true;

					//CryLog("WeaponListener successfully created on %s", pItem->GetEntity()->GetName());
				}           
				break;
			}
		}
	}
예제 #20
0
void CFlowNode_AISequenceAction_ApproachAndEnterVehicle::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
	switch(sequenceEvent)
	{
	case AIActionSequence::StartAction:
		{
			if (!m_actInfo.pEntity)
			{
				// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
				UnregisterFromVehicleEvent(NULL);
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			m_entityId = m_actInfo.pEntity->GetId();
			m_vehicleId = GetPortEntityId(&m_actInfo, InputPort_VehicleId);
			m_seatNumber = GetPortInt(&m_actInfo, InputPort_SeatNumber);
			m_fast = GetPortBool(&m_actInfo, InputPort_Fast);

			const bool alsoCheckForCrewHostility = true;
			IVehicle* pVehicle = GetVehicle(alsoCheckForCrewHostility);
			if (!pVehicle)
			{
				CryLog("Actor %s failed to enter vehicle (specified vehicle not found or its crew is hostile towards the actor returned true)", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			IVehicleSeat* pSeat = GetVehicleSeat(pVehicle);
			if (!pSeat)
			{
				CryLog("Actor %s failed to enter vehicle (bad seat number provided: %i)", m_actInfo.pEntity->GetName(), m_seatNumber);
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			const IVehicleHelper* pEnterHelper = static_cast<CVehicleSeat*>(pSeat)->GetEnterHelper();
			if (!pEnterHelper)
			{
				CryLog("Actor %s failed to enter vehicle (vehicle has no enter-helper)", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			m_vehicleSeatEnterPosition = pEnterHelper->GetWorldSpaceTranslation();

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
			IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());

			// if it's the player, have him enter quickly (we assume that the user moved him close enough to the vehicle)
			if (pActor && pActor->IsPlayer())
			{
				EnterVehicleSeat(true, pSeat);
			}
			else if (m_actInfo.pEntity->GetAI())
			{
				if (m_fast)
				{
					TeleportToVehicleSeat();
					EnterVehicleSeat(false, pSeat);
				}
				else
				{
					MovementRequest request;
					request.callback = functor(*this, &CFlowNode_AISequenceAction_ApproachAndEnterVehicle::MovementRequestCallback);
					request.entityID = m_actInfo.pEntity->GetId();
					request.type = MovementRequest::MoveTo;
					request.destination = m_vehicleSeatEnterPosition;
					request.style.SetSpeed((MovementStyle::Speed)GetPortInt(&m_actInfo, InputPort_Speed));
					request.style.SetStance((MovementStyle::Stance)GetPortInt(&m_actInfo, InputPort_Stance));
					m_movementRequestID = gEnv->pAISystem->GetMovementSystem()->QueueRequest(request);
				}
			}
			else if (pActor)
			{
				pActor->HolsterItem(true);
				pActor->MountedGunControllerEnabled(false);
				pActor->GetGameObject()->SetAspectProfile(eEA_Physics, eAP_Alive);
				TeleportToVehicleSeat();
				EnterVehicleSeat(GetAnimationTransitionEnabled(), pSeat);
			}
			else
			{
				CRY_ASSERT_MESSAGE(0, "no compatible entity was provided");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s failed to enter vehicle (no compatible entity was provided)", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
			}
		}
		break;

	case AIActionSequence::SequenceStopped:
		{
			if (m_movementRequestID)
			{
				gEnv->pAISystem->GetMovementSystem()->CancelRequest(m_movementRequestID);
				m_movementRequestID = MovementRequestID::Invalid();
				UnregisterFromVehicleEvent(NULL);
			}
		}
		break;
	}
}