//------------------------------------------------------------------------
bool CVehicleActionEntityAttachment::Init(IVehicle *pVehicle, const CVehicleParams &table)
{
	m_pVehicle = pVehicle;

	CVehicleParams entityAttachmentTable = table.findChild("EntityAttachment");

	if(!entityAttachmentTable)
		return false;

	if(entityAttachmentTable.haveAttr("helper"))
		m_pHelper = m_pVehicle->GetHelper(entityAttachmentTable.getAttr("helper"));

	if(entityAttachmentTable.haveAttr("class"))
	{
		IEntityClassRegistry *pClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
		assert(pClassRegistry);

		m_entityClassName = entityAttachmentTable.getAttr("class");

		if(IEntityClass *pEntityClass = pClassRegistry->FindClass(m_entityClassName.c_str()))
		{
			SpawnEntity();
			return true;
		}
	}

	return false;
}
//------------------------------------------------------------------------
bool CVehicleActionEntityAttachment::Init(IVehicle* pVehicle, const SmartScriptTable &table)
{
	m_pVehicle = pVehicle;

	SmartScriptTable entityAttachmentTable;
	if (!table->GetValue("EntityAttachment", entityAttachmentTable))
		return false;

	char* pHelperName;
	if (entityAttachmentTable->GetValue("helper", pHelperName))
		m_pHelper = m_pVehicle->GetHelper(pHelperName);

	char* pEntityClassName;
	if (entityAttachmentTable->GetValue("class", pEntityClassName))
	{
		IEntityClassRegistry* pClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
		assert(pClassRegistry);

		if (IEntityClass* pEntityClass = pClassRegistry->FindClass(pEntityClassName))
		{
			m_entityClassName = pEntityClassName;

			SpawnEntity();

			return true;
		}
	}

	return false;
}
//------------------------------------------------------------------------
void CVehicleActionEntityAttachment::SpawnEntity()
{
	IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
	assert(pEntitySystem);

	IEntityClassRegistry* pClassRegistry = pEntitySystem->GetClassRegistry();
	assert(pClassRegistry);

	IEntityClass* pEntityClass = pClassRegistry->FindClass(m_entityClassName.c_str());
	if (!pEntityClass)
		return;

	char pEntityName[256];
	_snprintf(pEntityName, 256, "%s_%s", m_pVehicle->GetEntity()->GetName(), m_entityClassName.c_str());
	pEntityName[sizeof(pEntityName)-1] = '\0';

	SEntitySpawnParams params;
	params.sName = pEntityName;
	params.nFlags = ENTITY_FLAG_CLIENT_ONLY;
	params.pClass = pEntityClass;

	IEntity* pEntity = pEntitySystem->SpawnEntity(params, true);
	if (!pEntity)
	{
		m_entityId = 0;
		return;
	}

	m_entityId = pEntity->GetId();

	m_pVehicle->GetEntity()->AttachChild(pEntity);
	pEntity->SetLocalTM(m_pHelper->GetVehicleTM());

	m_isAttached = true;
}
//------------------------------------------------------------------------
CGameRulesCommonDamageHandling::CGameRulesCommonDamageHandling()
: m_pGameRules(NULL)
{
	CryLog("GameRulesCommonDamageHandling::GameRulesCommonDamageHandling()");
	
	IEntityClassRegistry * pClassReg = gEnv->pEntitySystem->GetClassRegistry();
	m_pEnvironmentalWeaponClass = pClassReg->FindClass("EnvironmentalWeapon");
}
void CFlashUIInventoryNode::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		IActor* pActor = GetInputActor( pActInfo );
		if(pActor)
		{
			IInventory* pInventory = pActor->GetInventory();
			if(pInventory)
			{
				string weapons = "";
				bool first = true;
				int inv_cap = gEnv->pConsole->GetCVar("i_inventory_capacity")->GetIVal();
				for (int i = 0; i < inv_cap; i++)
				{
					const char* weaponName = pInventory->GetItemString(i);

					if(strcmp(weaponName, "") != 0)
					{
						bool selectable = false;

						//Get the weapon and check if it is a selectable item
						IEntityClassRegistry *pRegistry = gEnv->pEntitySystem->GetClassRegistry();
						EntityId item = pInventory->GetItemByClass(pRegistry->FindClass(weaponName));
						IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item);

						if(pEntity)
						{
							CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER);
							CItem* pItem = (CItem*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());
							if(pItem)
							{
								selectable = pItem->CanSelect();
							}
						}
						if(selectable)
						{
							if(!first)
								weapons.append(",");
							first = false;
							weapons.append(weaponName);
						}
					}

				}

				ActivateOutput(pActInfo, eO_OnCall, true);
				ActivateOutput(pActInfo, eO_Args, weapons);
			}
		}
	}
}
void CFlashUIGetCompatibleAccessoriesNode ::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		string accessories = "";
		IActor* pActor = GetInputActor( pActInfo );

		if(pActor)
		{
			IInventory* pInventory = pActor->GetInventory();
			if(pInventory)
			{
				//Get the item ID via the Input string
				const string weapon_name = GetPortString(pActInfo, eI_Weapon);
				IEntityClassRegistry *pRegistery = gEnv->pEntitySystem->GetClassRegistry();
				EntityId item = pInventory->GetItemByClass(pRegistery->FindClass(weapon_name));

				//Fetch the actual weapon via the ID
				IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item);
				if(pEntity)
				{

					CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER);
					const char* ext = pGameObject->GetEntity()->GetClass()->GetName();
					CWeapon* pWeapon = (CWeapon*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());

					//If the weapon exists, ask for all compatible accessories
					if(pWeapon)
					{
						//All compatible accessories for this weapon
						const DynArray<string> pCompatibleAccessoriesVec = pWeapon->GetCompatibleAccessories();

						bool first = true;
						DynArray<string>::const_iterator it;
						for (it = pCompatibleAccessoriesVec.begin(); it != pCompatibleAccessoriesVec.end(); it++)
						{
							if (!first)
								accessories.append(",");
							accessories.append((*it));
							first = false;
						}
					}
				}
			}
		}

		//return, if 'accessories' is empty, it has no compatible attachments, or the weapon/inventory was invalid
		ActivateOutput(pActInfo, eO_OnCall, true);
		ActivateOutput(pActInfo, eO_Args, accessories);
	}
}
예제 #7
0
파일: MPTutorial.cpp 프로젝트: RenEvo/dead6
void CMPTutorial::InitEntityClasses()
{
	IEntityClassRegistry* classReg = gEnv->pEntitySystem->GetClassRegistry();
	m_pHQClass = classReg->FindClass("HQ");
	m_pFactoryClass = classReg->FindClass("Factory");
	m_pAlienEnergyPointClass = classReg->FindClass("AlienEnergyPoint");
	m_pPlayerClass = classReg->FindClass("Player");
	m_pTankClass = classReg->FindClass("US_tank");
	m_pTechChargerClass = classReg->FindClass("TechCharger");
	m_pSpawnGroupClass = classReg->FindClass("SpawnGroup");
	m_pSUVClass = classReg->FindClass("Civ_car1");
}
예제 #8
0
//---------------------------------------
void CMiscAnnouncer::InitXML(XmlNodeRef root)
{
	IEntityClassRegistry *pEntityClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
	XmlNodeRef onWeaponFiringRoot = root->findChild("OnWeaponFiring");

	CryLog("CMiscAnnouncer::InitXML()");

	if(onWeaponFiringRoot)
	{
		const int numChildren = onWeaponFiringRoot->getChildCount();

		CryLog("CMiscAnnouncer::InitXML() found OnWeaponFiringRoot with %d children", numChildren);
	
		for(int i=0; i<numChildren; ++i)
		{
			XmlNodeRef child = onWeaponFiringRoot->getChild(i);
			if(child->isTag("OnWeaponFired"))
			{
				const char *pWeaponClassName = child->getAttr("weaponClass");
				CRY_ASSERT(pWeaponClassName && pWeaponClassName[0] != 0);

				CryLog("CMiscAnnouncer::InitXML() OnWeaponFired tag - pWeaponClassName=%s", pWeaponClassName ? pWeaponClassName : "NULL");

				if(IEntityClass* pWeaponEntityClass = pEntityClassRegistry->FindClass(pWeaponClassName))
				{
					const char *pAnnouncement = child->getAttr("announcement");
					CRY_ASSERT(pAnnouncement && pAnnouncement[0] != 0);

					EAnnouncementID announcementID = CAnnouncer::NameToID(pAnnouncement);
					
					CryLog("CMiscAnnouncer::InitXML() found weapon entity class for pWeaponClassName=%s; found pAnnouncement=%s announcementID=%x", pWeaponClassName, pAnnouncement ? pAnnouncement : "NULL", announcementID);

					SOnWeaponFired newWeaponFired(pWeaponEntityClass, pAnnouncement, announcementID);
					m_weaponFiredMap.insert(TWeaponFiredMap::value_type(pWeaponEntityClass, newWeaponFired));
				}
				else
				{
					CryLog("CMiscAnnouncer::InitXML() failed to find entityClass for pWeaponClassName=%s", pWeaponClassName);
					CRY_ASSERT_MESSAGE(0, string().Format("CMiscAnnouncer::InitXML() failed to find entityClass for pWeaponClassName=%s", pWeaponClassName));
				}
			}
			else
			{
				CryLog("CMiscAnnouncer::InitXML() unhandled childtag of %s found", child->getTag());
			}
		}
	}
}
void CFlashUIGetEquippedAccessoriesNode::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		string accessories = "";
		IActor* pActor = GetInputActor( pActInfo );

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

				//Get the item ID via the Input string
				const string weapon_name = GetPortString(pActInfo, eI_Weapon);
				IEntityClassRegistry *pRegistery = gEnv->pEntitySystem->GetClassRegistry();
				EntityId item = pInventory->GetItemByClass(pRegistery->FindClass(weapon_name));

				//Fetch the actual object via the ID
				CGameObject * pGameObject = (CGameObject*)gEnv->pEntitySystem->GetEntity(item)->GetProxy(ENTITY_PROXY_USER);
				const char* ext = pGameObject->GetEntity()->GetClass()->GetName();
				IItem* pWeapon = (IItem*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());

				//If the weapon exists, return all equipped attachments in a comma seperated string
				if(pWeapon)
				{
					//All equipped accessories for this weapon weapons
					accessories = static_cast<CItem*>(pWeapon)->GetAttachedAccessoriesString();
				}
			}
		}

		//return, if 'accesories' is empty, it has no attachments, or something was invalid
		ActivateOutput(pActInfo, eO_OnCall, true);
		ActivateOutput(pActInfo, eO_Args, accessories);
	}
}
void CFlashUICheckAccessoryState ::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
{
	if(event == eFE_Activate && IsPortActive(pActInfo, 0))
	{
		IActor* pActor = GetInputActor( pActInfo );
		bool is_equipped = false;
		bool is_inInventory = false;

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

			if(pInventory)
			{
				IEntityClassRegistry *pRegistry = gEnv->pEntitySystem->GetClassRegistry();

				//Find the accessory's class in the registry
				const string accessory_name = GetPortString(pActInfo, eI_Accessory);				
				IEntityClass* pClass = pRegistry->FindClass(accessory_name);

				//Check if its in inventory
				if(pInventory->HasAccessory(pClass) != 0)
				{
					is_inInventory = true;
				}	

				//if it is, check if its equipped as well
				if(is_inInventory)
				{
					//Get the weapon ID via the Input string
					const char* weapon_name = GetPortString(pActInfo, eI_Weapon).c_str();
					EntityId item = pInventory->GetItemByClass(pRegistry->FindClass(weapon_name));

					//Fetch the actual weapon via the ID
					IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item);
					if(pEntity)
					{

						CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER);
						const char* ext = pGameObject->GetEntity()->GetClass()->GetName();
						CWeapon* pWeapon = (CWeapon*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName());
						bool selectable = pWeapon->CanSelect();
						if(pWeapon)
						{
							if(pWeapon->GetAccessory(pClass->GetName()) != 0)
							{
								is_equipped = true;
							}					
						}
					}
				}
			}
		}

		if(!is_inInventory)
			ActivateOutput(pActInfo, eO_DontHave, true);
		else if(is_equipped)
			ActivateOutput(pActInfo, eO_Equipped, true);
		else
			ActivateOutput(pActInfo, eO_InInventory, true);

	}
}
예제 #11
0
void CClientHitEffectsMP::ProcessEffectInfo(SHitEffectInfoSet& hitEffectSet, XmlNodeRef xmlNode, const char* libraryName)
{
    bool foundDefault = false;
    bool foundMelee = false;
    const uint numEffects = xmlNode->getChildCount();
    IMaterialEffects* pMaterialEffects = gEnv->pMaterialEffects;
    IEntityClassRegistry* pClassRegistry = gEnv->pEntitySystem->GetClassRegistry();

    hitEffectSet.m_effectInfos.reserve(numEffects);

    for (uint i = 0; i < numEffects; i++)
        {
            if(XmlNodeRef childNode = xmlNode->getChild(i))
                {
                    if(const char* nameTag = childNode->getTag())
                        {
                            if(!foundDefault && !strcmp("default", nameTag))
                                {
                                    const char* effectName = childNode->getAttr("effect");

                                    if(effectName)
                                        {
                                            hitEffectSet.m_default = pMaterialEffects->GetEffectIdByName(libraryName, effectName);
                                        }

                                    foundDefault = true;
                                }
                            else if(!foundMelee && !strcmp("melee", nameTag))
                                {
                                    const char* effectName = childNode->getAttr("effect");

                                    if(effectName)
                                        {
                                            hitEffectSet.m_melee = pMaterialEffects->GetEffectIdByName(libraryName, effectName);
                                        }

                                    foundMelee = true;
                                }
                            else
                                {
                                    SHitEffectInfo newInfo;

                                    newInfo.pAmmoClass = pClassRegistry->FindClass(nameTag);

                                    const char* effectName = childNode->getAttr("effect");

                                    if(effectName)
                                        {
                                            newInfo.effectId = pMaterialEffects->GetEffectIdByName(libraryName, effectName);
                                        }

                                    if(newInfo.pAmmoClass && newInfo.effectId)
                                        {
                                            hitEffectSet.m_effectInfos.push_back(newInfo);
                                        }
                                    else
                                        {
                                            if(!newInfo.pAmmoClass)
                                                {
                                                    GameWarning("Class type %s does not exist", nameTag);
                                                }

                                            if(!newInfo.effectId)
                                                {
                                                    GameWarning("Material Effect %s does not exist", effectName ? effectName : "");
                                                }
                                        }
                                }
                        }
                }
        }

    if(!hitEffectSet.m_melee)
        {
            hitEffectSet.m_melee = hitEffectSet.m_default;
        }
}
void CTacticalManager::Serialize(TSerialize ser)
{
	if (ser.IsReading())
	{
		// Serialize tactical points
		ClearAllTacticalPoints();

		uint32 numTacInfoPointsGroups = 0;
		STacticalInterestPoint interestPoint;
		ser.Value("numTacInfoPointsGroups", numTacInfoPointsGroups);
		for (uint32 i = 0; i < numTacInfoPointsGroups; i++) // Reads in according to ETacticalEntityType
		{
			ser.BeginGroup("TacInfoPointsGroup");
			uint32 numTacInfoPoints = 0;
			ser.Value("numTacInfoPoints", numTacInfoPoints);
			if (numTacInfoPoints > 0)
			{
				// Go through all the tac points
				for (size_t j = 0; j < numTacInfoPoints; j++)
				{
					ser.BeginGroup("TacInfoPoint");
					interestPoint.Serialize(ser);
					ser.EndGroup();
					AddTacticalInfoPointData((ETacticalEntityType)i, interestPoint);
				}
			}

			ser.EndGroup();
		}

		// Serialize tac override entities
		m_tacEntityToOverrideEntities.clear();
		uint32 numTacOverrideData = 0;
		ser.Value("numTacOverrideData", numTacOverrideData);
		for (uint32 i = 0; i < numTacOverrideData; i++)
		{
			ser.BeginGroup("TacOverrideData");
			EntityId origEntity = 0;
			EntityId overrideEntity = 0;
			ser.Value("origEntity", origEntity);
			ser.Value("overrideEntity", overrideEntity);
			AddOverrideEntity(origEntity, overrideEntity);

			ser.EndGroup();
		}		

		// Serialize class scanned data
		m_classes.clear();
		uint32 numInterestClasses = 0;
		string interestClassName;
		ser.Value("numInterestClasses", numInterestClasses);
		for (uint32 i = 0; i < numInterestClasses; i++)
		{
			TScanningCount scanningCount;
			ser.BeginGroup("InterestClassData");
			ser.Value("name", interestClassName);
			ser.Value("scanningCount", scanningCount);

			IEntityClassRegistry* pEntityClassRegistry = gEnv->pEntitySystem->GetClassRegistry();
			CRY_ASSERT(pEntityClassRegistry != NULL);
			IEntityClass* pEntityClass = pEntityClassRegistry->FindClass(interestClassName);
			CRY_ASSERT(pEntityClass);
			if (pEntityClass)
			{
				m_classes[pEntityClass] = scanningCount;
			}

			ser.EndGroup();
		}
	}
	else
	{
		// Serialize tactical points
		uint32 numTacInfoPointsGroups = eTacticalEntity_Last;
		ser.Value("numTacInfoPointsGroups", numTacInfoPointsGroups);
		for (uint32 i = 0; i < numTacInfoPointsGroups; i++) // Writes in according to ETacticalEntityType
		{
			ser.BeginGroup("TacInfoPointsGroup");
			TInterestPoints& interestPoints = m_allTacticalPoints[i];
			uint32 numTacInfoPoints = interestPoints.size();
			ser.Value("numTacInfoPoints", numTacInfoPoints);
			if (numTacInfoPoints > 0)
			{
				// Go through all the tac points
				for (uint32 j = 0; j < numTacInfoPoints; j++)
				{
					ser.BeginGroup("TacInfoPoint");
					STacticalInterestPoint& interestPoint = interestPoints[j];
					interestPoint.Serialize(ser);
					ser.EndGroup();
				}
			}

			ser.EndGroup();
		}

		// Serialize tac override entities
		uint32 numTacOverrideData = m_tacEntityToOverrideEntities.size();
		ser.Value("numTacOverrideData", numTacOverrideData);
		TTacticalEntityToOverrideEntities::iterator tactOverrideDataIter = m_tacEntityToOverrideEntities.begin();
		const TTacticalEntityToOverrideEntities::const_iterator tactOverrideDataIterEnd = m_tacEntityToOverrideEntities.end();
		while (tactOverrideDataIter != tactOverrideDataIterEnd)
		{
			EntityId origEntity = tactOverrideDataIter->first;
			EntityId overrideEntity = tactOverrideDataIter->second;
			ser.BeginGroup("TacOverrideData");
			ser.Value("origEntity", origEntity);
			ser.Value("overrideEntity", overrideEntity);
			ser.EndGroup();
			++tactOverrideDataIter;
		}

		// Serialize class scanned data
		uint32 numInterestClasses = m_classes.size();
		ser.Value("numInterestClasses", numInterestClasses);
		TInterestClasses::iterator interestClassesIter = m_classes.begin();
		const TInterestClasses::const_iterator interestClassesIterEnd = m_classes.end();
		while (interestClassesIter != interestClassesIterEnd)
		{
			const IEntityClass* pEntityClass = interestClassesIter->first;
			CRY_ASSERT(pEntityClass);
			TScanningCount scanningCount = interestClassesIter->second;
			ser.BeginGroup("InterestClassData");
			ser.Value("name", pEntityClass->GetName());
			ser.Value("scanningCount", scanningCount);
			ser.EndGroup();
			++interestClassesIter;
		}
	}
}