Ejemplo n.º 1
0
//------------------------------------------------------------------------
IParticleEmitter *CItem::GetEffectEmitter(uint32 id) const
{
	TEffectInfoMap::const_iterator it = m_effects.find(id);
	if (it == m_effects.end()) 
		return 0;

	const SEffectInfo &info = it->second;
	SEntitySlotInfo slotInfo;

	if (GetEntity()->GetSlotInfo(info.slot, slotInfo) && slotInfo.pParticleEmitter)
		return slotInfo.pParticleEmitter;

	if (GetEntity()->GetSlotInfo(info.characterSlot, slotInfo) && slotInfo.pCharacter)
	{
		ICharacterInstance *pCharacter = slotInfo.pCharacter;
		IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
		IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(info.helper.c_str());
		if (pAttachment)
		{
			CEffectAttachment *pEffectAttachment = static_cast<CEffectAttachment *>(pAttachment->GetIAttachmentObject());
			if (!pEffectAttachment)
			{
				// commenting out for silencer functionality
				//GameWarning("CItem::GetEffectEmitter: no effect attachment on %s (helper %s)", GetEntity()->GetName(), info.helper.c_str());
				return 0;
			}
			return pEffectAttachment->GetEmitter();
		}
	}

	return 0;
}
Ejemplo n.º 2
0
	void CEffectsController::DetachEffect(const TAttachedEffectId effectId)
	{
		CRY_ASSERT(m_pOwnerEntity);

		TAttachedEffects::iterator effectIt = std::find(m_attachedEffects.begin(), m_attachedEffects.end(), effectId);

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

			if (effectInfo.entityEffectSlot >= 0)
			{
				m_pOwnerEntity->FreeSlot(effectInfo.entityEffectSlot);
			}	
			else
			{
				ICharacterInstance *pCharacter = m_pOwnerEntity->GetCharacter(effectInfo.characterEffectSlot);
				if (pCharacter)
				{
					IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
					IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(effectInfo.helperName.c_str());
					if(pAttachment)
					{
						pAttachment->ClearBinding();
					}
				}
			}

			m_attachedEffects.erase(effectIt);
		}
	}
Ejemplo n.º 3
0
//------------------------------------------------------------------------
bool CItem::CreateCharacterAttachment(int slot, const char *name, int type, const char *bone)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);

	if(!pCharacter)
		return false;

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

	if(pAttachment)
	{
//		GameWarning("Item '%s' trying to create attachment '%s' which already exists!", GetEntity()->GetName(), name);
		return false;
	}

	pAttachment = pAttachmentManager->CreateAttachment(name, type, bone);

	if(!pAttachment)
	{
		if(type == CA_BONE)
			GameWarning("Item '%s' failed to create attachment '%s' on bone '%s'!", GetEntity()->GetName(), name, bone);

		return false;
	}

	return true;
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------
void CItem::SetCharacterAttachment(int slot, const char *name, ICharacterInstance *pAttachedCharacter, 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 character on '%s' which does not exist!", GetEntity()->GetName(), name);
		return;
	}

	CCHRAttachment *pCharacterAttachment = new CCHRAttachment();
	pCharacterAttachment->m_pCharInstance  = pAttachedCharacter;

	// sub skin ?
	if(pAttachment->GetType() == CA_SKIN)
	{
		pAttachment->AddBinding(pCharacterAttachment);
	}
	else
	{
		pAttachment->AddBinding(pCharacterAttachment);
	}
}
//======================================================================
void CWeaponAttachmentManager::CreatePlayerBoneAttachments()
{
		
	if (ICharacterInstance* pCharInstance = m_pOwner->GetEntity()->GetCharacter(0))
	{
		IAttachmentManager* pAttachmentManager = pCharInstance->GetIAttachmentManager(); 
		IAttachment *pAttachment = NULL;
		
		for(int i=0; i<MAX_WEAPON_ATTACHMENTS; i++)
		{
			pAttachment = pAttachmentManager->GetInterfaceByName(gAttachmentTable[i]);
			if(!pAttachment)
			{
				//Attachment doesn't exist, create it
				pAttachment = pAttachmentManager->CreateAttachment(gAttachmentTable[i],CA_BONE,gBoneTable[i]);
				if(pAttachment)
				{
					m_boneAttachmentMap.insert(TBoneAttachmentMap::value_type(gAttachmentTable[i],0));
					if(pAttachment && !gOffsetTable[i].IsZero())
					{
						pAttachment->SetAttAbsoluteDefault( QuatT(gRotationTable[i],gOffsetTable[i]) );
						pAttachment->ProjectAttachment();
					}
				}
			}
		}

	}

}
//=======================================================================
void CWeaponAttachmentManager::CreatePlayerProjectedAttachments()
{

	Vec3 c4FrontPos(-0.0105f,0.2233f,1.297f),c4BackPos(0.00281f,-0.2493f,1.325f);
	Quat c4FrontRot(-0.0368f,-0.0278f,0.0783f,-0.9958f),c4BackRot(1,0,0,0);
	//Creates on init c4 face attachments
	if (ICharacterInstance* pCharInstance = m_pOwner->GetEntity()->GetCharacter(0))
	{
		IAttachmentManager* pAttachmentManager = pCharInstance->GetIAttachmentManager(); 
		IAttachment *pAttachment = NULL;
		pAttachment = pAttachmentManager->GetInterfaceByName("c4_front");
		if(!pAttachment)
		{
			//Attachment doesn't exist, create it
			pAttachment= pAttachmentManager->CreateAttachment("c4_front",CA_FACE,0);
			if(pAttachment)
			{
				pAttachment->SetAttAbsoluteDefault( QuatT(c4FrontRot,c4FrontPos) );
				pAttachment->ProjectAttachment();
			}
		}
		pAttachment = NULL;
		pAttachment = pAttachmentManager->GetInterfaceByName("c4_back");
		if(!pAttachment)
		{
			//Attachment doesn't exist, create it
			pAttachment= pAttachmentManager->CreateAttachment("c4_back",CA_FACE,0);
			if(pAttachment)
			{
				pAttachment->SetAttAbsoluteDefault( QuatT(c4BackRot,c4BackPos) );
				pAttachment->ProjectAttachment();
			}
		}
	}
}
Ejemplo n.º 7
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);
							}
						}
					}
				}
			}
		}
	}
}//-------------------------------------------------------------------------------------------------
Ejemplo n.º 8
0
void CAICorpse::AboutToBeRemoved()
{
	IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();

	ICharacterInstance* pCharacter = GetEntity()->GetCharacter(0);
	IAttachmentManager* pAttachmentManager = (pCharacter != NULL) ? pCharacter->GetIAttachmentManager() : NULL;

	for (uint32 i = 0; i < (uint32)m_attachedItemsInfo.size(); ++i)
	{
		AttachedItem& attachedItem = m_attachedItemsInfo[i];

		IItem* pItem = pItemSystem->GetItem( attachedItem.id );
		if((pItem != NULL) && ShouldDropOnCorpseRemoval( pItem->GetEntity()->GetClass() ))
		{
			IAttachment* pAttachment = (pAttachmentManager != NULL) ? pAttachmentManager->GetInterfaceByName( attachedItem.attachmentName.c_str() ) : NULL;
			if(pAttachment != NULL)
			{
				pAttachment->ClearBinding();
			}

			pItem->Drop( 1.0f, false, true );
			pItem->GetEntity()->SetFlags( pItem->GetEntity()->GetFlags() & ~ENTITY_FLAG_NO_SAVE );

			attachedItem.id = 0;
		}
	}
}
Ejemplo n.º 9
0
int CScriptBind_Actor::GetClosestAttachment(IFunctionHandler *pH, int characterSlot, Vec3 testPos, float maxDistance, const char* suffix)
{
  CActor *pActor = GetActor(pH);
	if (!pActor)
		return pH->EndFunction();

  IEntity* pEntity = pActor->GetEntity();
  ICharacterInstance* pChar = pEntity->GetCharacter(characterSlot);

  if (!pChar)  
    return pH->EndFunction();

  //fallback: use nearest attachment
  float minDiff = maxDistance*maxDistance;  
  IAttachment* pClosestAtt = 0;
  
  IAttachmentManager* pMan = pChar->GetIAttachmentManager();
  int count = pMan->GetAttachmentCount();
  
  for (int i=0; i<count; ++i)
  {
    IAttachment* pAtt = pMan->GetInterfaceByIndex(i);		
		
    if (pAtt->IsAttachmentHidden() || !pAtt->GetIAttachmentObject())
			continue;
		
		AABB bbox(AABB::CreateTransformedAABB(Matrix34(pAtt->GetAttWorldAbsolute()),pAtt->GetIAttachmentObject()->GetAABB()));
		//gEnv->pRenderer->GetIRenderAuxGeom()->DrawAABB(bbox,false,ColorB(255,0,0,100),eBBD_Faceted);
		
    //float diff = (testPos - pAtt->GetWMatrix().GetTranslation()).len2();
		float diff((testPos - bbox.GetCenter()).len2());
		
    if (diff < minDiff)
    {
      //CryLogAlways("%s distance: %.1f", pAtt->GetName(), sqrt(diff));

      if (suffix[0] && !strstr(pAtt->GetName(), suffix))
        continue;

      minDiff = diff; 
      pClosestAtt = pAtt;      
    }
  }

  if (!pClosestAtt)
    return pH->EndFunction();
  
	//FIXME FIXME: E3 workaround
	char attachmentName[64];
	strncpy(attachmentName,pClosestAtt->GetName(),63);
	attachmentName[63] = 0;
	char *pDotChar = strstr(attachmentName,".");
	if (pDotChar)
		*pDotChar = 0;

	strlwr(attachmentName);
	//

  return pH->EndFunction(attachmentName);    
}
Ejemplo n.º 10
0
//------------------------------------------------------------------------
void CItem::DestroyCharacterAttachment(int slot, const char *name)
{
    ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
    if (!pCharacter)
        return;

    IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
    pAttachmentManager->RemoveAttachmentByName(name);
}
bool CMFXParticleEffect::AttachToCharacter( IEntity& targetEntity, const SMFXParticleEntry& particleParams, const SMFXRunTimeEffectParams& params, const Vec3& dir, float scale )
{
	if (params.partID >= 0)
	{
		//Assume character is loaded in first slot 
		//We could iterate through all available slots, but first one should be good enough
		ICharacterInstance* pCharacterInstace = targetEntity.GetCharacter(0);
		ISkeletonPose* pSkeletonPose = pCharacterInstace ? pCharacterInstace->GetISkeletonPose() : NULL;
		if (pSkeletonPose)
		{
			IDefaultSkeleton& rIDefaultSkeleton	= pCharacterInstace->GetIDefaultSkeleton();
			//It hit the character, but probably in a physicalized attached part, like armor plates, etc
			if (params.partID >= rIDefaultSkeleton.GetJointCount())
			{
				return false;
			}

			//It hit some valid joint, create an attachment
			const char* boneName = rIDefaultSkeleton.GetJointNameByID(params.partID);
			TAttachmentName attachmentName;
			GetNextCharacterAttachmentName(attachmentName);

			IAttachmentManager* pAttachmentManager = pCharacterInstace->GetIAttachmentManager();
			CRY_ASSERT(pAttachmentManager);
			
			//Remove the attachment first (in case was created before)
			pAttachmentManager->RemoveAttachmentByName(attachmentName.c_str());

			//Create attachment on nearest hit bone
			IAttachment* pAttachment = pAttachmentManager->CreateAttachment(attachmentName.c_str(), CA_BONE, boneName, false);
			if (pAttachment)
			{
				//Apply relative offsets
				const QuatT boneLocation = pSkeletonPose->GetAbsJointByID(params.partID);
				Matrix34 inverseJointTM = targetEntity.GetWorldTM() * Matrix34(boneLocation);
				inverseJointTM.Invert();
				Vec3 attachmentOffsetPosition = inverseJointTM * params.pos;
				Quat attachmentOffsetRotation = Quat(inverseJointTM) * targetEntity.GetRotation();

				CRY_ASSERT(attachmentOffsetPosition.IsValid());
				//CRY_ASSERT(attachmentOffsetRotation.IsUnit());

				pAttachment->SetAttRelativeDefault(QuatT(attachmentOffsetRotation, attachmentOffsetPosition));

				//Finally attach the effect
				CEffectAttachment* pEffectAttachment = new CEffectAttachment(particleParams.name.c_str(), Vec3(0,0,0), dir, scale);
				pAttachment->AddBinding(pEffectAttachment);
				
				return true;
			}
		}
	}

	return false;
}
Ejemplo n.º 12
0
IAttachment* CKVoltEffect::GetScreenAttachment()
{
	IEntity* pEntity = m_ownerActor ? m_ownerActor->GetEntity() : NULL;
	ICharacterInstance* pCharacter = pEntity ? pEntity->GetCharacter(0) : NULL;
	IAttachmentManager* pAttachmentMan = pCharacter ? pCharacter->GetIAttachmentManager() : NULL;

	if(pAttachmentMan)
	{
		return pAttachmentMan->GetInterfaceByName("#camera");
	}

	return NULL;
}
void CLocalPlayerComponent::UpdateFPBodyPartsVisibility()
{
	if (m_rPlayer.m_stats.isThirdPerson == false)
	{
		ICharacterInstance *pMainCharacter	= m_rPlayer.GetEntity()->GetCharacter(0);
		IAttachmentManager *pAttachmentManager		= pMainCharacter ? pMainCharacter->GetIAttachmentManager() : NULL;

		if (pAttachmentManager)
		{
			CRY_ASSERT(m_rPlayer.HasBoneID(BONE_CALF_L));
			CRY_ASSERT(m_rPlayer.HasBoneID(BONE_CALF_R));

			const CCamera& camera = gEnv->p3DEngine->GetRenderingCamera();
			const Matrix34& playerWorldTM = m_rPlayer.GetEntity()->GetWorldTM();

			bool visible = true;
			if (m_rPlayer.m_linkStats.linkID == 0)
			{
				//volatile static float radius = 0.475f;
				const float radius = 0.16f;
				const Sphere calfSphereL(playerWorldTM.TransformPoint(m_rPlayer.GetBoneTransform(BONE_CALF_L).t), radius);
				const Sphere calfSpehreR(playerWorldTM.TransformPoint(m_rPlayer.GetBoneTransform(BONE_CALF_R).t), radius);

				visible = camera.IsSphereVisible_F(calfSphereL) || camera.IsSphereVisible_F(calfSpehreR);
			}

			//const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
			//gEnv->pRenderer->Draw2dLabel(50.0f, 50.0f, 2.0f, white, false, visible ? "Rendering complete FP body" : "Rendering only arms");

			//Early out if no change
			if (m_fpCompleteBodyVisible == visible)
				return;

			//Hide/Unhide certain parts depending on visibility
			const int kNumParstToToggle = 2;
			const char *tooglePartsTable[kNumParstToToggle] = {"lower_body", "upper_body"};
			for (int i=0; i<kNumParstToToggle; i++)
			{
				IAttachment* pAttachment = pAttachmentManager->GetInterfaceByName(tooglePartsTable[i]);
				if (pAttachment)
				{
					pAttachment->HideAttachment(!visible);
					pAttachment->HideInShadow(1);
				}
			}

			m_fpCompleteBodyVisible = visible;
		}
	}
}
Ejemplo n.º 14
0
//------------------------------------------------------------------------
IAttachment * CItem::GetCharacterAttachment(ICharacterInstance * pCharacter, const char *name) const
{
    if(pCharacter)
        {
            IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
            if (IAttachment * pAttachment = pAttachmentManager->GetInterfaceByName(name))
                {
                    return pAttachment;
                }

            GameWarning("Item '%s' trying to get attachment '%s' which does not exist!", GetEntity()->GetName(), name);
        }

    return NULL;
}
Ejemplo n.º 15
0
//--------------------------------------------------------------------------------------------------
// Name: InitAttachmentIndexArray
// Desc: Initialises attachment index array
//--------------------------------------------------------------------------------------------------
void CGameEffect::InitAttachmentIndexArray(PodArray<int> *attachmentIndexArray,PodArray<ItemString>* pAttachmentNameArray,EntityId entityId) const 
{
	if(attachmentIndexArray && pAttachmentNameArray && (entityId!=0))
	{
		if(attachmentIndexArray->size() == 0)
		{
			// Store attachment index array
			const int attachmentNameCount = pAttachmentNameArray->size();

			SEntitySlotInfo slotInfo;
			IEntity* pEntity = gEnv->pEntitySystem->GetEntity(entityId);
			if(pEntity)
			{
				bool gotEntitySlotInfo = pEntity->GetSlotInfo(0, slotInfo);
				if(gotEntitySlotInfo)
				{
					attachmentIndexArray->reserve(attachmentNameCount);

					if(slotInfo.pCharacter)
					{
						IAttachmentManager* attachmentManager = slotInfo.pCharacter->GetIAttachmentManager();
						if(attachmentManager)
						{
							const int attachmentCount = attachmentManager->GetAttachmentCount();

							for(int n=0; n<attachmentNameCount; n++)
							{
								for(int a=0; a<attachmentCount; a++)
								{
									IAttachment* attachment = attachmentManager->GetInterfaceByIndex(a);
									if(attachment)
									{
										const char* currentAttachmentName = attachment->GetName();
										if(strcmp(currentAttachmentName,(*pAttachmentNameArray)[n].c_str())==0)
										{
											attachmentIndexArray->push_back(a);
											break;
										}
									}
								}
							}
						}
					}
				}
			}	
		}
	}
}//-------------------------------------------------------------------------------------------------
Ejemplo n.º 16
0
	IAttachment* GetAttachment(SActivationInfo* pActInfo)
	{
		IAttachment *pAttachment = NULL;
		if (pActInfo->pEntity)
		{
			int slot = GetPortInt(pActInfo, eIP_CharacterSlot);
			ICharacterInstance *pCharacter = pActInfo->pEntity->GetCharacter(slot);
			if (pCharacter)
			{
				const string &boneName = GetPortString(pActInfo, eIP_BoneName);
				IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager();
				pAttachment = pAttachmentManager->GetInterfaceByName(boneName);
			}
		}
		return pAttachment;
	}
Ejemplo n.º 17
0
//------------------------------------------------------------------------
int CScriptBind_Actor::AttachVulnerabilityEffect(IFunctionHandler *pH, int characterSlot, int partid, Vec3 hitPos, float radius, const char* effect, const char* attachmentIdentifier)
{
  CActor *pActor = GetActor(pH);  
	if (!pActor)
		return pH->EndFunction();

  IEntity* pEntity = pActor->GetEntity();
  ICharacterInstance* pChar = pEntity->GetCharacter(characterSlot);

  if (!pChar || !effect)  
    return pH->EndFunction();

  //fallback: use nearest attachment
  float minDiff = radius*radius;  
  IAttachment* pClosestAtt = 0;
  
  IAttachmentManager* pMan = pChar->GetIAttachmentManager();
  for (int i=0; i<pMan->GetAttachmentCount(); ++i)
  {
    IAttachment* pAtt = pMan->GetInterfaceByIndex(i);
    
    float diff = (hitPos - pAtt->GetAttWorldAbsolute().t).len2();        
    if (diff < minDiff)
    {
      // only use specified attachments 
      if (attachmentIdentifier[0] && !strstr(pAtt->GetName(), attachmentIdentifier))
        continue;

      minDiff = diff; 
      pClosestAtt = pAtt;      
    }   
    //CryLog("diff: %.2f, att: %s", diff, attName.c_str());
  }

  if (!pClosestAtt)
    return pH->EndFunction();

  //CryLog("AttachVulnerabilityEffect: closest att %s, attaching effect %s", pClosestAtt->GetName(), effect);
  
  CEffectAttachment *pEffectAttachment = new CEffectAttachment(effect, Vec3(ZERO), Vec3(0,1,0), 1.f);

  pClosestAtt->AddBinding(pEffectAttachment);
  pClosestAtt->HideAttachment(0);
  
  return pH->EndFunction(pClosestAtt->GetName());    
}
Ejemplo n.º 18
0
//------------------------------------------------------------------------
void CItem::SetCharacterAttachmentLocalTM(int slot, const char *name, const Matrix34 &tm)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
	if (!pCharacter)
		return;

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

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

	pAttachment->SetAttRelativeDefault( QuatT(tm));
}
Ejemplo n.º 19
0
//------------------------------------------------------------------------
Matrix34 CItem::GetCharacterAttachmentWorldTM(int slot, const char *name)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
	if (!pCharacter)
		return Matrix34::CreateIdentity();

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

	if (!pAttachment)
	{
		GameWarning("Item '%s' trying to get local TM on attachment '%s' which does not exist!", GetEntity()->GetName(), name);
		return Matrix34::CreateIdentity();
	}

	return Matrix34(pAttachment->GetAttWorldAbsolute());
}
Ejemplo n.º 20
0
//------------------------------------------------------------------------
void CItem::ResetCharacterAttachment(int slot, const char *name)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
	if (!pCharacter)
		return;

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

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

	pAttachment->ClearBinding();
}
Ejemplo n.º 21
0
//------------------------------------------------------------------------
const char *CItem::GetCharacterAttachmentBone(int slot, const char *name)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
	if (!pCharacter)
		return 0;

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

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

	return pCharacter->GetISkeletonPose()->GetJointNameByID(pAttachment->GetBoneID());
}
Ejemplo n.º 22
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);
							}
						}
					}
				}
			}
		}
	}
}
Ejemplo n.º 23
0
void EntityEffects::SpawnParticleWithEntity( const IEntity* pTargetEntity, const int targetSlot, IParticleEffect* pParticleEffect, const char* helperName, const EntityEffects::SEffectSpawnParams& spawnParams )
{
	SEffectSpawnParams newSpawnParams = spawnParams;

	if (pTargetEntity)
	{
		SEntitySlotInfo slotInfo;
		if (pTargetEntity->GetSlotInfo(targetSlot, slotInfo))
		{
			if (slotInfo.pStatObj)	
			{
				//Get helper position from static object
				const Vec3 localHelperPosition = slotInfo.pStatObj->GetHelperPos(helperName);
				newSpawnParams.position = pTargetEntity->GetSlotWorldTM(targetSlot).TransformPoint(localHelperPosition);
			}
			else if (slotInfo.pCharacter)	
			{
				//Get helper position from character
				IAttachmentManager *pAttachmentManager = slotInfo.pCharacter->GetIAttachmentManager();
				
				if (IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(helperName))
				{
					newSpawnParams.position = pAttachment->GetAttWorldAbsolute().t;
				}
				else
				{
					ICharacterModelSkeleton* pICharacterModelSkeleton = slotInfo.pCharacter->GetICharacterModel()->GetICharacterModelSkeleton();
					ISkeletonPose* pSkeletonPose = slotInfo.pCharacter->GetISkeletonPose();
					
					Vec3 localJointPosition = ZERO;
					const int16 jointId = pICharacterModelSkeleton->GetJointIDByName(helperName);
					if (jointId >= 0)
					{
						localJointPosition = pSkeletonPose->GetAbsJointByID(jointId).t;
					}

					newSpawnParams.position = pTargetEntity->GetSlotWorldTM(targetSlot).TransformPoint(localJointPosition);
				}
			}
		}
	}

	SpawnParticleFX(pParticleEffect, newSpawnParams);
}
void CWeaponAttachmentManager::RemoveAttachments()
{
	if (ICharacterInstance *pCharInstance = m_pOwner->GetEntity()->GetCharacter(0))
	{
		IAttachmentManager *pAttachmentManager = pCharInstance->GetIAttachmentManager();

		if(pAttachmentManager == NULL)
		{
			return;
		}

		TBoneAttachmentMap::iterator fi;

		for (fi = m_boneAttachmentMap.begin(); fi != m_boneAttachmentMap.end(); ++fi)
		{
			pAttachmentManager->RemoveAttachmentByName(fi->first);
		}
	}
}
Ejemplo n.º 25
0
void CAICorpse::PostSerialize()
{
#if AI_CORPSES_ENABLE_SERIALIZE
	ICharacterInstance* pCharacterInstance = GetEntity()->GetCharacter(0);
	if(pCharacterInstance != NULL)
	{
		IAttachmentManager* pAttachmentManager = pCharacterInstance->GetIAttachmentManager();
		for(uint32 i = 0; i < m_attachedItemsInfo.size(); ++i)
		{
			AttachedItem& weaponInfo = m_attachedItemsInfo[i];
			IAttachment* pAttachment = pAttachmentManager->GetInterfaceByName( weaponInfo.attachmentName.c_str() );
			if(pAttachment != NULL)
			{
				weaponInfo.id = CloneAttachedItem( weaponInfo, pAttachment );
			}
		}
	}
#endif //AI_CORPSES_ENABLE_SERIALIZE
}
Ejemplo n.º 26
0
//------------------------------------------------------------------------
void CItem::SetCharacterAttachment(int slot, const char *name, IStatObj *pObj, 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 static object on '%s' which does not exist!", GetEntity()->GetName(), name);
		return;
	}

	CCGFAttachment *pStatAttachment = new CCGFAttachment();
	pStatAttachment->pObj  = pObj;

	pAttachment->AddBinding(pStatAttachment);
}
void CBodyDestrutibilityInstance::ResetMaterials( IEntity& characterEntity, ICharacterInstance& characterInstance )
{
	characterEntity.SetSlotMaterial(0, NULL);

	IAttachmentManager *pAttachmentManager = characterInstance.GetIAttachmentManager();
	CRY_ASSERT(pAttachmentManager);
	
	const uint32 attachmentCount = (uint32)pAttachmentManager->GetAttachmentCount();

	for(TOriginalMaterials::iterator it = m_originalMaterials.begin(); it != m_originalMaterials.end(); ++it)
	{
		IAttachmentObject *pAttachmentObject = (it->first < attachmentCount) ? pAttachmentManager->GetInterfaceByIndex(it->first)->GetIAttachmentObject() : NULL;
		if (pAttachmentObject)
		{
			pAttachmentObject->SetReplacementMaterial(it->second);
			it->second->Release();
		}
	}

	m_originalMaterials.clear();
}
Ejemplo n.º 28
0
//------------------------------------------------------------------------
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);
}
Ejemplo n.º 29
0
//------------------------------------------------------------------------
void CItem::SetCharacterAttachment(int slot, const char *name, CDLight &light, 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 light on '%s' which does not exist!", GetEntity()->GetName(), name);
		return;
	}

	CLightAttachment *pLightAttachment = new CLightAttachment();
	pLightAttachment->LoadLight(light);

	pAttachment->AddBinding(pLightAttachment);
	pAttachment->HideAttachment(0);
}
Ejemplo n.º 30
0
//------------------------------------------------------------------------
void CItem::SetCharacterAttachmentWorldTM(int slot, const char *name, const Matrix34 &tm)
{
	ICharacterInstance *pCharacter = GetEntity()->GetCharacter(slot);
	if (!pCharacter)
		return;

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

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

//	Matrix34 boneWorldMatrix = GetEntity()->GetSlotWorldTM(slot) *	pCharacter->GetISkeleton()->GetAbsJMatrixByID(pAttachment->GetBoneID());
	Matrix34 boneWorldMatrix = GetEntity()->GetSlotWorldTM(slot) *	Matrix34(pCharacter->GetISkeletonPose()->GetAbsJointByID(pAttachment->GetBoneID()) );

	Matrix34 localAttachmentMatrix = (boneWorldMatrix.GetInverted()*tm);
	pAttachment->SetAttRelativeDefault(QuatT(localAttachmentMatrix));
}