コード例 #1
0
bool CStickyProjectile::AttachToCharacter(CProjectile* pProjectile, IEntity& pEntity, ICharacterInstance& pCharacter, const char* boneName)
{
	IEntity* pProjectileEntity = pProjectile->GetEntity();

	char attachName[16] = "";		
	sprintf(attachName, "StickyProj_%d", s_attachNameID++);

	IAttachment* pCharacterAttachment = pCharacter.GetIAttachmentManager()->CreateAttachment(attachName, CA_BONE, boneName, false); 

	if(!pCharacterAttachment)
	{
		CryLogAlways("Could not create attachment for StickyProjectile[%s]. AttachmentName[%s] BoneName[%s]", pProjectileEntity->GetName(), attachName, boneName );
		CRY_ASSERT_MESSAGE(pCharacterAttachment, "Could not create attachment for StickyProjectile. This must be fixed.");
		return false;
	}

	m_characterAttachmentCrC = pCharacterAttachment->GetNameCRC();

	SetProjectilePhysics(pProjectile, ePT_None);

	pCharacterAttachment->SetAttRelativeDefault(QuatT(m_stuckRot, m_stuckPos));

	CEntityAttachment *pEntityAttachment = new CEntityAttachment();
	pEntityAttachment->SetEntityId(pProjectileEntity->GetId());

	pCharacterAttachment->AddBinding(pEntityAttachment);

	return true;
}
コード例 #2
0
ファイル: AICorpse.cpp プロジェクト: aronarts/FireNET
EntityId CAICorpse::CloneAttachedItem( const CAICorpse::AttachedItem& attachedItem, IAttachment* pAttachment  )
{
	stack_string clonedItemName;
	clonedItemName.Format("%s_%s", GetEntity()->GetName(), attachedItem.pClass->GetName() );
	SEntitySpawnParams params;
	params.sName = clonedItemName.c_str();
	params.pClass = attachedItem.pClass;

	// Flag as 'No Save' they will be recreated during serialization if needed
	params.nFlags |= (ENTITY_FLAG_NO_SAVE);				

	IEntity *pClonedItemEntity = gEnv->pEntitySystem->SpawnEntity(params);
	assert (pClonedItemEntity != NULL);

	IItem* pClonedItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(pClonedItemEntity->GetId());
	assert(pClonedItem != NULL);

	pClonedItem->Physicalize(false, false);
	pClonedItem->SetOwnerId( GetEntityId() );

	// Set properties table to null, since they'll not be used
	IScriptTable* pClonedItemEntityScript = pClonedItemEntity->GetScriptTable();
	if (pClonedItemEntityScript != NULL)
	{
		pClonedItemEntity->GetScriptTable()->SetToNull("Properties");
	}

	// Swap attachments
	CEntityAttachment* pEntityAttachement = new CEntityAttachment();
	pEntityAttachement->SetEntityId( pClonedItemEntity->GetId() );

	pAttachment->AddBinding( pEntityAttachement );

	return pClonedItemEntity->GetId();
}
コード例 #3
0
ファイル: ItemResource.cpp プロジェクト: eBunny/EmberProject
//------------------------------------------------------------------------
void CItem::SetCharacterAttachment(int slot, const char *name, IEntity *pEntity, bool owner)
{
    if(IAttachment * pAttachment = GetCharacterAttachment(GetAppropriateCharacter(slot, owner), name))
        {
            CEntityAttachment *pEntityAttachment = new CEntityAttachment();
            pEntityAttachment->SetEntityId(pEntity->GetId());

            pAttachment->AddBinding(pEntityAttachment);
            pAttachment->HideAttachment(0);
        }
}
コード例 #4
0
ファイル: ItemResource.cpp プロジェクト: kitnet/project-o
//------------------------------------------------------------------------
void CItem::SetCharacterAttachment(int slot, const char *name, IEntity *pEntity, int flags)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
	if (!pCharacter)
		return;

	IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
	IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(name);

	if (!pAttachment)
	{
		GameWarning("Item '%s' trying to attach entity on '%s' which does not exist!", GetEntity()->GetName(), name);
		return;
	}

	CEntityAttachment *pEntityAttachment = new CEntityAttachment();
	pEntityAttachment->SetEntityId(pEntity->GetId());

	pAttachment->AddBinding(pEntityAttachment);
	pAttachment->HideAttachment(0);
}
コード例 #5
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);
				}
			}
		}
	}
コード例 #6
0
void CLaserBeam::FixAttachment(IEntity* pLaserEntity)
{
	m_usingEntityAttachment = false;

	IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
	CItem* pOwnerItem = static_cast<CItem*>(pItemSystem->GetItem(m_ownerEntityId));

	if (pOwnerItem)
	{
		IEntity* pOwnerEntity = pOwnerItem->GetEntity();
		IEntity* pAttachedEntity = pOwnerEntity;
		const char* attach_helper = "laser_term";

		Vec3 offset = pOwnerItem->GetSlotHelperPos(m_geometrySlot, attach_helper, false);

		if(m_geometrySlot == eIGS_FirstPerson)
		{
			if(pOwnerItem->IsAccessory())
			{
				EntityId parentId = pOwnerItem->GetParentId();

				if(parentId)
				{
					if(CItem* pParentItem = static_cast<CItem*>(pItemSystem->GetItem(parentId)))
					{
						const SAccessoryParams* pParams = pParentItem->GetAccessoryParams(pAttachedEntity->GetClass());

						attach_helper = pParams->attach_helper.c_str();
						pAttachedEntity = pParentItem->GetEntity();
					}
				}
			}

			if(pAttachedEntity)
			{
				ICharacterInstance *pCharacter = pAttachedEntity->GetCharacter(eIGS_FirstPerson);
				if (pCharacter)
				{
					IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();

					IAttachment *pLaserAttachment = pAttachmentManager->GetInterfaceByName(LASER_ATTACH_NAME);

					if(!pLaserAttachment)
					{
						IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(attach_helper);

						if(pAttachment)
						{
							const char* pBone = pCharacter->GetICharacterModel()->GetICharacterModelSkeleton()->GetJointNameByID(pAttachment->GetJointID());

							pLaserAttachment = pAttachmentManager->CreateAttachment(LASER_ATTACH_NAME, CA_BONE, pBone);

							if(pLaserAttachment)
							{
								QuatT relative = pAttachment->GetAttRelativeDefault();

								if(pOwnerItem->GetEntity() != pAttachedEntity)
								 {
									Matrix34 mtx(relative);
									relative.t = relative * offset;
								}

								pLaserAttachment->SetAttRelativeDefault(relative);
							}
						}
					}

					if(pLaserAttachment)
					{
						CEntityAttachment* pEntAttach = new CEntityAttachment;

						pEntAttach->SetEntityId(m_laserEntityId);
						pLaserAttachment->AddBinding(pEntAttach);
						pLaserAttachment->HideAttachment(0);

						m_usingEntityAttachment = true;
					}		
				}
			}
		}	

		if(!m_usingEntityAttachment && pOwnerEntity)
		{
			pOwnerEntity->AttachChild(pLaserEntity);
			pLaserEntity->SetLocalTM(Matrix34::CreateTranslationMat(offset));
		}
	}
}
コード例 #7
0
void CFlashLight::EnableFogVolume(CWeapon* pWeapon, int slot, bool enable)
{
	if (!g_pGameCVars->i_flashlight_has_fog_volume)
	{
		return;
	}

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

	IEntity* pFogVolume = 0;

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

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

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

		if (!pFogVolume)
		{
			return;
		}

		m_fogVolume = pFogVolume->GetId();

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

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

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

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

	if (!pFogVolume)
	{
		return;
	}

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

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

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

	pFogVolume->Hide(!enable);
}
コード例 #8
0
ファイル: C4Projectile.cpp プロジェクト: super-nova/NovaRepo
//------------------------------------------------------------------------
bool CC4Projectile::StickToCharacter(bool stick,IEntity *pActor)
{
	if(!pActor)
		return false;

	//Check for friendly AI
	if(pActor->GetAI())
	{
		if(CWeapon *pWeapon = GetWeapon())
		{
			if(CActor *pPlayer = pWeapon->GetOwnerActor())
			{
				if(IAIObject *pPlayerAI = pPlayer->GetEntity()->GetAI())
				{
					if(pActor->GetAI()->IsFriendly(pPlayerAI, false))
					{
						return false;
					}
				}
			}
		}
	}

	ICharacterInstance *pCharacter = pActor->GetCharacter(0);

	if(!pCharacter)
		return false;

	//Actors doesn't support constraints, try to stick as character attachment
	IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
	IAttachment *pAttachment = NULL;

	//Select one of the attachment points
	Vec3 charOrientation = pActor->GetRotation().GetColumn1();
	Vec3 c4ToChar = pActor->GetWorldPos() - GetEntity()->GetWorldPos();
	c4ToChar.Normalize();

	//if(c4ToChar.Dot(charOrientation)>0.0f)
	//pAttachment = pAttachmentManager->GetInterfaceByName("c4_back");
	//else
	pAttachment = pAttachmentManager->GetInterfaceByName("c4_front");

	if(!pAttachment)
	{
		GameWarning("No c4 face attachment found in actor");

		if(!pAttachment)
			return false;
	}

	if(stick)
	{
		//Check if there's already one
		if(IAttachmentObject *pAO = pAttachment->GetIAttachmentObject())
			return false;

		CEntityAttachment *pEntityAttachment = new CEntityAttachment();
		pEntityAttachment->SetEntityId(GetEntityId());

		pAttachment->AddBinding(pEntityAttachment);
		pAttachment->HideAttachment(0);

		m_stuck = true;
	}
	else
	{
		pAttachment->ClearBinding();
		m_stuck = false;
	}

	return true;

}