//------------------------------------------------------------------------
bool CItem::SetGeometry(int slot, const ItemString &name, const Vec3 &poffset, const Ang3 &aoffset, float scale, bool forceReload)
{
	bool changedfp=false;

	switch(slot)
	{
	case eIGS_Arms:
	{
		if(!name || forceReload)
		{
			GetEntity()->FreeSlot(slot);
#ifndef ITEM_USE_SHAREDSTRING
			m_geometry[slot].resize(0);
#else
			m_geometry[slot].reset();
#endif
		}

		ResetCharacterAttachment(eIGS_FirstPerson, ITEM_ARMS_ATTACHMENT_NAME);

		ICharacterInstance *pCharacter=0;

		if(name && name[0])
		{
			if(name != m_geometry[slot])
				GetEntity()->LoadCharacter(slot, name);

			DrawSlot(eIGS_Arms, false);

			pCharacter = GetEntity()->GetCharacter(eIGS_Arms);
		}
		else if(m_pForcedArms)
		{
			pCharacter = m_pForcedArms;
		}
		else
		{
			int armsId=m_stats.hand==eIH_Right?0:1;
			pCharacter = GetOwnerActor()?GetOwnerActor()->GetFPArms(armsId):0;
		}

		if(pCharacter)
		{
			pCharacter->SetFlags(pCharacter->GetFlags()&(~CS_FLAG_UPDATE));
			SetCharacterAttachment(eIGS_FirstPerson, ITEM_ARMS_ATTACHMENT_NAME, pCharacter, 0);
		}
	}
	break;

	case eIGS_FirstPerson:
	case eIGS_ThirdPerson:
	default:
	{
		if(!name || forceReload)
		{
			GetEntity()->FreeSlot(slot);
#ifndef ITEM_USE_SHAREDSTRING
			m_geometry[slot].resize(0);
#else
			m_geometry[slot].reset();
#endif
		}

		DestroyAttachmentHelpers(slot);

		if(name && name[0])
		{
			if(m_geometry[slot] != name)
			{
				const char *ext = PathUtil::GetExt(name.c_str());

				if((stricmp(ext, "chr") == 0) || (stricmp(ext, "cdf") == 0) || (stricmp(ext, "cga") == 0))
					GetEntity()->LoadCharacter(slot, name, 0);
				else
					GetEntity()->LoadGeometry(slot, name, 0, 0);

				changedfp=slot==eIGS_FirstPerson;
			}

			CreateAttachmentHelpers(slot);

			SetDefaultIdleAnimation(slot, g_pItemStrings->idle);
		}

		if(slot == eIGS_FirstPerson)
		{
			ICharacterInstance *pCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson);

			if(pCharacter)
			{
				pCharacter->SetFlags(pCharacter->GetFlags()&(~CS_FLAG_UPDATE));
			}
		}
		else if(slot == eIGS_Destroyed)
			DrawSlot(eIGS_Destroyed, false);
	}
	break;
	}

	Matrix34 slotTM;
	slotTM = Matrix34::CreateRotationXYZ(aoffset);
	slotTM.Scale(Vec3(scale, scale, scale));
	slotTM.SetTranslation(poffset);
	GetEntity()->SetSlotLocalTM(slot, slotTM);

	if(changedfp && m_stats.mounted)
	{
		PlayAction(m_idleAnimation[eIGS_FirstPerson], 0, true);
		ForceSkinning(true);

		if(!m_mountparams.pivot.empty())
		{
			Matrix34 tm=GetEntity()->GetSlotLocalTM(eIGS_FirstPerson, false);
			Vec3 pivot = GetSlotHelperPos(eIGS_FirstPerson, m_mountparams.pivot.c_str(), false);
			tm.AddTranslation(pivot);

			GetEntity()->SetSlotLocalTM(eIGS_FirstPerson, tm);
		}

		GetEntity()->InvalidateTM();
	}

	m_geometry[slot] = name ? name : "";

	ReAttachAccessories();

	return true;
}
//------------------------------------------------------------------------
void CItem::FixResourceName(const ItemString &inName, TempResourceName &name, int flags, const char *hand, const char *suffix, const char *pose, const char *pov, const char *env)
{
	// the whole thing of fixing is not nice, but at least we don't allocate too often
	// StringHelper<TempResourceName::SIZE> name (inName.c_str(), inName.length());
	name.assign(inName.c_str(), inName.length());

	if(!hand)
	{
		if(m_stats.hand == eIH_Left)
			hand = "left";
		else
			hand = "right";
	}

	name.replace("%hand%", hand);

	if(m_stats.hand == eIH_Left)
		name.replace("%offhand%", "right");
	else
		name.replace("%offhand%", "left");

	if(!suffix)
		suffix = m_actionSuffix.c_str();

	name.replace("%suffix%", suffix);

	if(!pose)
	{
		if(!m_sharedparams->params.pose.empty())
			pose = m_sharedparams->params.pose.c_str();
		else
			pose = "";
	}

	name.replace("%pose%", "");

	if(!pov)
	{
		if((m_stats.fp || flags&eIPAF_ForceFirstPerson) && !(flags&eIPAF_ForceThirdPerson))
			pov = ITEM_FIRST_PERSON_TOKEN;
		else
			pov = ITEM_THIRD_PERSON_TOKEN;
	}

	name.replace("%pov%", pov);

	if(!env)
	{
		// Instead if the weapons sound proxy, the owners is used to retrieve the tail name
		IEntity *pOwner = GetOwner();

		if(GetIWeapon() && pOwner)  // restricting to weapon sounds only
		{
			if(pOwner)
			{
				IEntitySoundProxy *pSoundProxy = (IEntitySoundProxy *)pOwner->GetProxy(ENTITY_PROXY_SOUND);

				if(!pSoundProxy)
					pSoundProxy = (IEntitySoundProxy *)pOwner->CreateProxy(ENTITY_PROXY_SOUND);

				if(pSoundProxy)
				{
					// check for a roof 10m above the Owner
					// recalculate visibility when owner move more than 2 meters
					pSoundProxy->CheckVisibilityForTailName(10.0f, 2.0f);
					env = pSoundProxy->GetTailName();
				}
			}
		}


		if(!env || !env[0] || !stricmp("indoor", env))
			name.replace("%env%", "");
		else
		{
			static const size_t MAX_LEN = 256;
			char envstr[MAX_LEN];
			envstr[0] = '_';
			strncpy(envstr+1, env, MAX_LEN-1); // no 0 pad, if MAX_LEN-1 are copied
			envstr[MAX_LEN-1] = '\0'; // always zero-terminate
			name.replace("%env%", envstr);
		}
	}
	else
		name.replace("%env%", env);
}
Exemple #3
0
//------------------------------------------------------------------------
bool CItem::SetGeometry(int slot, const ItemString& name, const ItemString& material, bool useParentMaterial, const Vec3& poffset, const Ang3& aoffset, float scale, bool forceReload)
{
    assert(slot >= 0 && slot < eIGS_Last);

    bool changedfp=false;
    switch(slot)
        {
        case eIGS_Owner:
            break;
        case eIGS_FirstPerson:
        case eIGS_ThirdPerson:
        default:
        {
            if (name.empty() || forceReload)
                {
                    GetEntity()->FreeSlot(slot);
#ifndef ITEM_USE_SHAREDSTRING
                    m_geometry[slot].resize(0);
#else
                    m_geometry[slot].reset();
#endif
                }

            DestroyAttachmentHelpers(slot);

            if (!name.empty())
                {
                    if (m_geometry[slot] != name)
                        {
                            const char* ext = PathUtil::GetExt(name.c_str());
                            if ((stricmp(ext, "chr") == 0) || (stricmp(ext, "cdf") == 0) || (stricmp(ext, "cga") == 0) )
                                GetEntity()->LoadCharacter(slot, name.c_str(), 0);
                            else
                                GetEntity()->LoadGeometry(slot, name.c_str(), 0, 0);

                            changedfp=slot==eIGS_FirstPerson;
                        }

                    CreateAttachmentHelpers(slot);
                }

            /*			if (slot == eIGS_FirstPerson)
            			{
            				ICharacterInstance *pCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson);
            				if (pCharacter)
            				{
            					pCharacter->SetFlags(pCharacter->GetFlags()&(~CS_FLAG_UPDATE));
            				}
            			}
                  else */if (slot == eIGS_Destroyed)
                DrawSlot(eIGS_Destroyed, false);
        }
        break;
        }

    Matrix34 slotTM;
    slotTM = Matrix34::CreateRotationXYZ(aoffset);
    slotTM.ScaleColumn(Vec3(scale, scale, scale));
    slotTM.SetTranslation(poffset);
    GetEntity()->SetSlotLocalTM(slot, slotTM);

    if (changedfp && m_stats.mounted)
        {
            if (m_sharedparams->pMountParams && !m_sharedparams->pMountParams->pivot.empty())
                {
                    Matrix34 tm=GetEntity()->GetSlotLocalTM(eIGS_FirstPerson, false);
                    Vec3 pivot = GetSlotHelperPos(eIGS_FirstPerson, m_sharedparams->pMountParams->pivot.c_str(), false);
                    tm.AddTranslation(pivot);

                    GetEntity()->SetSlotLocalTM(eIGS_FirstPerson, tm);
                }

            GetEntity()->InvalidateTM();
        }

    m_geometry[slot] = name ? name : ItemString();

    ReAttachAccessories();

    IEntity* pParentEntity = gEnv->pEntitySystem->GetEntity(GetParentId());
    IMaterial* pOverrideMaterial = 0;
    if (!material.empty())
        {
            pOverrideMaterial = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(material.c_str());
        }
    else if (useParentMaterial && pParentEntity)
        {
            ICharacterInstance* pParentCharacter = pParentEntity->GetCharacter(slot);
            IEntityRenderProxy* pParentRenderProxy = static_cast<IEntityRenderProxy*>(pParentEntity->GetProxy(ENTITY_PROXY_RENDER));
            if (pParentCharacter)
                pOverrideMaterial = pParentCharacter->GetIMaterial();
            else if (pParentRenderProxy)
                pOverrideMaterial = pParentRenderProxy->GetSlotMaterial(slot);
        }
    if (pOverrideMaterial)
        {
            ICharacterInstance* pCharacter = GetEntity()->GetCharacter(slot);
            IEntityRenderProxy* pRenderProxy = static_cast<IEntityRenderProxy*>(GetEntity()->GetProxy(ENTITY_PROXY_RENDER));
            OverrideAttachmentMaterial(pOverrideMaterial, this, slot);
            if (pCharacter)
                pCharacter->SetIMaterial_Instance(pOverrideMaterial);
            else if (pRenderProxy)
                pRenderProxy->SetSlotMaterial(slot, pOverrideMaterial);
        }

    if(slot == eIGS_FirstPerson && IsSelected())
        {
            CActor* pOwnerActor = GetOwnerActor();
            IActionController *pActionController = GetActionController();
            if(pActionController && pOwnerActor && pOwnerActor->IsClient())
                {
                    UpdateScopeContexts(pActionController);
                }
        }

    return true;
}