Пример #1
0
//--------------------------------------------------------------------------------------------------
// Name: SetMaterialOnEntity
// Desc: Sets material on entity
//--------------------------------------------------------------------------------------------------
void CGameEffect::SetMaterialOnEntity(IMaterial* pMaterial,EntityId entityId,PodArray<ItemString>*	bodyAttachmentNameArray)
{
	if(pMaterial && bodyAttachmentNameArray)
	{
		IEntity* pEntity = gEnv->pEntitySystem->GetEntity(entityId);
		if(pEntity)
		{
			SEntitySlotInfo slotInfo;
			bool gotSlotInfo = pEntity->GetSlotInfo(0, slotInfo);
			if(gotSlotInfo && slotInfo.pCharacter)
			{
				IAttachmentManager* pAttachmentManager = slotInfo.pCharacter->GetIAttachmentManager();
				if(pAttachmentManager)
				{
					int attachmentCount = bodyAttachmentNameArray->size();
					for(int i=0; i<attachmentCount; i++)
					{
						IAttachment* attachment = pAttachmentManager->GetInterfaceByName(((*bodyAttachmentNameArray)[i]).c_str());

						if(attachment)
						{
							IAttachmentObject* attachmentObj = attachment->GetIAttachmentObject();
							if(attachmentObj)
							{
								attachmentObj->SetReplacementMaterial(pMaterial);
							}
						}
					}
				}
			}
		}
	}
}//-------------------------------------------------------------------------------------------------
Пример #2
0
int PickStowSlot(IAttachmentManager *pAttachmentManager, const char *slot1, const char *slot2)
{
	int ret = -1;
	IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(slot1);
	if(pAttachment && !pAttachment->GetIAttachmentObject())
	{
		ret = 0;
	}
	else
	{
		pAttachment = pAttachmentManager->GetInterfaceByName(slot2);
		if(pAttachment && !pAttachment->GetIAttachmentObject())
		{
			ret = 1;
		}
	}

	return ret;
}
Пример #3
0
	void UnHideAttachment(SActivationInfo* pActInfo)
	{
		IAttachment* pAttachment = GetAttachment(pActInfo);
		if(pAttachment)
		{
			pAttachment->HideAttachment(0);

			IAttachmentObject* pAttachmentObject = pAttachment->GetIAttachmentObject();
			if((pAttachmentObject != NULL) && (pAttachmentObject->GetAttachmentType() == IAttachmentObject::eAttachment_Entity))
			{
				IEntity* pAttachedEntity = gEnv->pEntitySystem->GetEntity( static_cast<CEntityAttachment*>(pAttachmentObject)->GetEntityId() );
				if(pAttachedEntity)
				{
					pAttachedEntity->Hide(false);
				}
			}
		}
	}
Пример #4
0
void CVar::EnableDebugAnimText(IConsoleCmdArgs *args)
{
	if (args && args->GetArgCount() > 1)
	{
		const char* szFilterName = args->GetArg(1);
		bool enable = true;
		if (args->GetArgCount() > 2)
		{
			enable = (strcmp(args->GetArg(2), "0") != 0);
		}

		CEntitySystem* pEntitySystem = GetIEntitySystem();
		IEntity *entity = pEntitySystem->FindEntityByName(szFilterName);

		if (entity)
		{
			uint32 numSlots = entity->GetSlotCount();
			for (uint32 i=0; i<numSlots; i++)
			{
				ICharacterInstance *charInst = entity->GetCharacter(i);
				if (charInst)
				{
					charInst->GetISkeletonAnim()->SetDebugging(enable);
					IAttachmentManager* pAttachmentManager = charInst->GetIAttachmentManager();
					for(int32 attachmentIndex=0; attachmentIndex<pAttachmentManager->GetAttachmentCount(); ++attachmentIndex)
					{
						IAttachment* pAttachment = pAttachmentManager->GetInterfaceByIndex(attachmentIndex);
						assert(pAttachment);

						IAttachmentObject* pObject = pAttachment->GetIAttachmentObject();
						if (pObject)
						{
							ICharacterInstance* pObjectCharInst = pObject->GetICharacterInstance();
							if (pObjectCharInst)
							{
								pObjectCharInst->GetISkeletonAnim()->SetDebugging(enable);
							}
						}
					}
				}
			}
		}
	}
}
	ILightSource* CEffectsController::GetLightSource(const TAttachedEffectId effectId) const
	{
		CRY_ASSERT(m_pOwnerEntity);

		TAttachedEffects::const_iterator effectCit = std::find(m_attachedEffects.begin(), m_attachedEffects.end(), effectId);

		if (effectCit != m_attachedEffects.end()) 
		{
			const SEffectInfo &effectInfo = *effectCit;

			if (effectInfo.entityEffectSlot >= 0)
			{
				SEntitySlotInfo slotInfo;
				if(m_pOwnerEntity->GetSlotInfo(effectInfo.entityEffectSlot, slotInfo) && slotInfo.pLight)
				{
					return slotInfo.pLight;
				}
			}

			if (effectInfo.characterEffectSlot >= 0)
			{
				SEntitySlotInfo slotInfo;
				if (m_pOwnerEntity->GetSlotInfo(effectInfo.characterEffectSlot, slotInfo) && slotInfo.pCharacter)
				{
					IAttachmentManager *pAttachmentManager = slotInfo.pCharacter->GetIAttachmentManager();
					IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(effectInfo.helperName.c_str());
					if (pAttachment)
					{
						IAttachmentObject *pAttachmentObject = pAttachment->GetIAttachmentObject();
						if (pAttachmentObject != NULL && (pAttachmentObject->GetAttachmentType() == IAttachmentObject::eAttachment_Light))
						{
							return static_cast<CLightAttachment *>(pAttachmentObject)->GetLightSource();
						}
					}
				}
			}
		}

		return NULL;
	}
Пример #6
0
//------------------------------------------------------------------------
void CItem::SetLightRadius(float radius, uint32 id)
{
	TEffectInfoMap::const_iterator it = m_effects.find(id);
	if (it == m_effects.end()) 
		return;

	const SEffectInfo &info = it->second;
	SEntitySlotInfo slotInfo;
	ILightSource* pLightSource = 0;

	if (info.slot != -1)
	{
		if (GetEntity()->GetSlotInfo(info.slot, slotInfo) && slotInfo.pLight)
			pLightSource = static_cast<ILightSource*>(slotInfo.pLight);
	}
	else if (info.characterSlot != -1)
	{
		if (GetEntity()->GetSlotInfo(info.characterSlot, slotInfo) && slotInfo.pCharacter)
		{ 
			IAttachmentManager *pAttachmentManager = slotInfo.pCharacter->GetIAttachmentManager();
			IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(info.helper.c_str());
			if (pAttachment)
			{
				CLightAttachment *pLightAttachment = static_cast<CLightAttachment *>(pAttachment->GetIAttachmentObject());
				if (pLightAttachment)
					pLightSource = pLightAttachment->GetLightSource();
			}
		}
	}

	if (pLightSource)
	{
		CDLight& light = pLightSource->GetLightProperties();
		light.m_fRadius = radius;
		pLightSource->SetLightProperties(light);
	}
}
Пример #7
0
void CHandGrenades::UpdateStowedWeapons()
{
	CActor *pOwnerActor = GetOwnerActor();
	if (!pOwnerActor)
		return;

	ICharacterInstance *pOwnerCharacter = pOwnerActor->GetEntity()->GetCharacter(0);
	if (!pOwnerCharacter)
		return;

	IStatObj *pTPObj = GetEntity()->GetStatObj(eIGS_ThirdPerson);
	if (!pTPObj)
		return;


	int ammoCount = m_fm ? pOwnerActor->GetInventory()->GetAmmoCount(m_fm->GetAmmoType()) : 0;
	if (IsSelected() && (ammoCount > 0))
	{
		ammoCount--;
	}
	if (!pOwnerActor->IsThirdPerson())
	{
		ammoCount = 0;
	}

	int numGrenDiff = ammoCount - m_numStowedCopies;
	if(numGrenDiff != 0)
	{
		if (m_stowSlot < 0)
		{
			m_stowSlot = PickStowSlot(pOwnerCharacter->GetIAttachmentManager(), m_sharedparams->params.bone_attachment_01.c_str(), m_sharedparams->params.bone_attachment_02.c_str());
		}

		if (m_stowSlot >= 0)
		{
			bool attach = numGrenDiff > 0;
			int tot = abs(numGrenDiff);

			IAttachmentManager *pAttachmentManager = pOwnerCharacter->GetIAttachmentManager();
			IAttachment *pAttachment = NULL;

			for (int i=0; i<tot; i++)
			{
				//--- Generate the secondary slot from the first by adding one to the attachment name, is all we need at present...
				const char *attach1 = (m_stowSlot == 0) ? m_sharedparams->params.bone_attachment_01.c_str() : m_sharedparams->params.bone_attachment_02.c_str();
				int lenAttachName = strlen(attach1);
				stack_string attach2(attach1, lenAttachName-1);
				attach2 += (attach1[lenAttachName-1]+1);

				if (attach)
				{
					pAttachment = pAttachmentManager->GetInterfaceByName(attach1);
					if(pAttachment && pAttachment->GetIAttachmentObject())
					{
						pAttachment = pAttachmentManager->GetInterfaceByName(attach2);
					}

					if (pAttachment && !pAttachment->GetIAttachmentObject())
					{
						CCGFAttachment *pCGFAttachment = new CCGFAttachment();
						pCGFAttachment->pObj = pTPObj;
						pAttachment->AddBinding(pCGFAttachment);
						pAttachment->HideAttachment(0);
						pAttachment->HideInShadow(0);

						m_numStowedCopies++;
					}
				}
				else
				{
					pAttachment = pAttachmentManager->GetInterfaceByName(attach2);
					if(!pAttachment || !pAttachment->GetIAttachmentObject())
					{
						pAttachment = pAttachmentManager->GetInterfaceByName(attach1);
					}

					if (pAttachment && pAttachment->GetIAttachmentObject())
					{
						pAttachment->ClearBinding();
						m_numStowedCopies--;					
					}
				}
			}
		}
	}
}
Пример #8
0
//------------------------------------------------------------------------
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;

}
Пример #9
0
void CAICorpse::SetupFromSource( IEntity& sourceEntity, ICharacterInstance& characterInstance, const uint32 priority)
{
	// 1.- Move resources from source entity, into AICorpse
	GetEntity()->SetFlags(GetEntity()->GetFlags() | (ENTITY_FLAG_CASTSHADOW));

	sourceEntity.MoveSlot(GetEntity(), 0);

	// Moving everything from one slot into another will also clear the render proxies in the source.
	// Thus, we need to invalidate the model so that it will be properly reloaded when a non-pooled
	// entity is restored from a save-game.
	CActor* sourceActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(sourceEntity.GetId()));
	if (sourceActor != NULL)
	{
		sourceActor->InvalidateCurrentModelName();
	}

	// 2.- After 'MoveSlot()', characterInstance is now stored inside CAICorpse
	// It needs to be now updated from the entity system
	characterInstance.SetFlags( characterInstance.GetFlags() | CS_FLAG_UPDATE );

#if AI_CORPSES_ENABLE_SERIALIZE
	m_modelName = characterInstance.GetFilePath();
#endif

	// 3.- Search for any attached weapon and clone them
	IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();

	IAttachmentManager* pAttachmentManager = characterInstance.GetIAttachmentManager();
	const uint32 attachmentCount = (uint32)pAttachmentManager->GetAttachmentCount();
	for(uint32 i = 0; i < attachmentCount ; ++i)
	{
		IAttachment* pAttachment = pAttachmentManager->GetInterfaceByIndex(i);
		assert(pAttachment != NULL);

		IAttachmentObject* pAttachmentObject = pAttachment->GetIAttachmentObject();
		if((pAttachmentObject == NULL) || (pAttachmentObject->GetAttachmentType() != IAttachmentObject::eAttachment_Entity))
			continue;

		const EntityId attachedEntityId = static_cast<CEntityAttachment*>(pAttachmentObject)->GetEntityId();

		IItem* pItem = pItemSystem->GetItem(attachedEntityId);
		if(pItem != NULL)
		{
			if(AllowCloneAttachedItem( pItem->GetEntity()->GetClass() ))
			{
				if(m_attachedItemsInfo.size() < m_attachedItemsInfo.max_size())
				{
					AttachedItem attachedItemInfo;
					attachedItemInfo.pClass = pItem->GetEntity()->GetClass();
					attachedItemInfo.attachmentName = pAttachment->GetName();

					attachedItemInfo.id = CloneAttachedItem( attachedItemInfo, pAttachment );
					m_attachedItemsInfo.push_back(attachedItemInfo);
				}
			}
		}	
	}

	//Only accept requested priority if it has attached weapons
	m_priority = (m_attachedItemsInfo.size() > 0) ? priority : 0;

	//Force physics to sleep immediately (if not already)
	IPhysicalEntity* pCorpsePhysics = GetEntity()->GetPhysics();
	if(pCorpsePhysics != NULL)
	{
		pe_action_awake awakeAction;
		awakeAction.bAwake = 0;
		pCorpsePhysics->Action( &awakeAction );
	}
}