// RMI receiver in the server to remove all items from the inventory. changes are automatically propagated to the clients
IMPLEMENT_RMI(CInventory, SvReq_RemoveAllItems)
{
  IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem();
  
  IItem* pItem = pItemSystem->GetItem( GetCurrentItem() );
  if (pItem) 
  {
    pItem->Select(false);
    pItemSystem->SetActorItem( GetActor(), (EntityId)0, false );
  }

	Destroy();

	if (gEnv->bMultiplayer)
	{
		TRMIInventory_Dummy Info;
		GetGameObject()->InvokeRMI( Cl_RemoveAllAmmo(), Info, eRMI_ToAllClients);
	}
	else
	{
		ResetAmmo();
	}

	return true;
}
//------------------------------------------------------------------------
int CInventory::GetCountOfUniqueId(uint8 uniqueId) const
{
	//Skip uniqueId 0
	if(!uniqueId)
		return 0;

	IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

	int count = 0;
	TInventoryCIt end = m_stats.slots.end();
	for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it)
	{
		IItem *pItem = pItemSystem->GetItem(*it);
		if (pItem)
		{
			uint8 id = pItemSystem->GetItemUniqueId(pItem->GetEntity()->GetClass()->GetName());
			if (id==uniqueId)
				count++;
		}

	}

	TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end();
	for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit)
	{
		uint8 id = pItemSystem->GetItemUniqueId((*cit)->GetName());
		if (id==uniqueId)
			count++;
	}

	return count;
}
//------------------------------------------------------------------------
void CInventory::Destroy()
{
  //
  //CryLog("%s::CInventory::Destroy()",GetEntity()->GetName());
  //
	if(!GetISystem()->IsSerializingFile())
	{
		IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
		IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

		TInventoryVector deleteList = m_stats.slots;
		for (TInventoryIt it = deleteList.begin(); it != deleteList.end(); ++it)
		{
			EntityId entityId = *it;

			IItem *pItem = pItemSystem->GetItem(entityId);
			if (pItem)
			{
				RemoveItemFromCategorySlot(pItem->GetEntityId());
				pItem->RemoveOwnerAttachedAccessories();
				pItem->AttachToHand(false);
				pItem->AttachToBack(false);
				pItem->SetOwnerId(0);
			}

			pEntitySystem->RemoveEntity(entityId);
		}
	}

	Clear();
}
//------------------------------------------------------------------------
int CInventory::GetCountOfCategory(const char *categoryName) const
{
	IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

	int count = 0;
	TInventoryCIt end = m_stats.slots.end();
	for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it)
	{
		IItem *pItem = pItemSystem->GetItem(*it);
		if (pItem)
		{
			const char *cat = pItemSystem->GetItemCategory(pItem->GetEntity()->GetClass()->GetName());
			if (!strcmp(cat, categoryName))
				count++;
		}

	}
	TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end();
	for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit)
	{
		const char *cat = pItemSystem->GetItemCategory((*cit)->GetName());
		if (!strcmp(cat,categoryName))
			count++;
	}

	return count;
}
IAttachmentManager* CLaserBeam::GetLaserCharacterAttachmentManager()
{
	IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
	CItem* pOwnerItem = static_cast<CItem*>(pItemSystem->GetItem(m_ownerEntityId));

	if (pOwnerItem)
	{
		IEntity* pAttachedEntity = pOwnerItem->GetEntity();

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

			if(parentId)
			{
				if(IEntity* pParentEnt = gEnv->pEntitySystem->GetEntity(parentId))
				{
					pAttachedEntity = pParentEnt;
				}
			}
		}				

		if (ICharacterInstance *pCharacter = pAttachedEntity->GetCharacter(eIGS_FirstPerson))
		{
			return pCharacter->GetIAttachmentManager();				
		}
	}

	return NULL;
}
Example #6
0
//------------------------------------------------------------------------
void CWeaponSystem::RefGun(IConsoleCmdArgs *args)
{
	IGameFramework *pGF = gEnv->pGame->GetIGameFramework();
	IItemSystem *pItemSystem = pGF->GetIItemSystem();

	IActor *pActor = pGF->GetClientActor();

	if(!pActor || !pActor->IsPlayer())
		return;

	IInventory *pInventory = pActor->GetInventory();

	if(!pInventory)
		return;

	// give & select the refgun
	EntityId itemId = pInventory->GetItemByClass(CItem::sRefWeaponClass);

	if(0 == itemId)
	{
		// if actor doesn't have it, only give it in editor
		if(!gEnv->IsEditor())
			return;

		itemId = pItemSystem->GiveItem(pActor, CItem::sRefWeaponClass->GetName(), false, true, true);
	}

	pItemSystem->SetActorItem(pActor, itemId, true);

}
Example #7
0
	void Serialize(SActivationInfo* pActInfo, TSerialize ser)
	{
		ser.Value("active", m_active);
		ser.Value("ammo", m_ammo);
		ser.Value("weaponId", m_weapId);

		if (ser.IsReading())
		{
			if (m_active && m_weapId != 0)
			{
				IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();

				IItem* pItem = pItemSys->GetItem(m_weapId);

				if (!pItem || !pItem->GetIWeapon())
				{
					GameWarning("[flow] CFlowNode_WeaponListener: Serialize no item/weapon.");
					return;
				}
				IWeapon* pWeapon = pItem->GetIWeapon();
				// set weapon listener
				pWeapon->AddEventListener(this, "CFlowNode_WeaponListener");
				// CryLog("[flow] CFlowNode_WeaponListener::Serialize() successfully created on '%s'", pItem->GetEntity()->GetName());
			}
			else
			{
				Reset();
			}
		}
	}
Example #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;
		}
	}
}
Example #9
0
EEntityType GetEntityType(EntityId id)
{
	int type = eET_Unknown;

	IEntitySystem *pEntitySystem = gEnv->pEntitySystem;
	if (pEntitySystem)
	{
		IEntity *pEntity = pEntitySystem->GetEntity(id);
		if (pEntity)
		{
			type = eET_Valid;

			IEntityClass *pClass = pEntity->GetClass();
			if (pClass)
			{
				const char* className = pClass->GetName();

				// Check AI
				if (pEntity->GetAI())
				{
					type |= eET_AI;
				}
				
				// Check actor
				IActorSystem *pActorSystem = gEnv->pGame->GetIGameFramework()->GetIActorSystem();
				if (pActorSystem)
				{
					IActor *pActor = pActorSystem->GetActor(id);
					if (pActor)
					{
						type |= eET_Actor;
					}
				}

				// Check vehicle
				IVehicleSystem *pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
				if (pVehicleSystem)
				{
					if (pVehicleSystem->IsVehicleClass(className))
					{
						type |= eET_Vehicle;
					}
				}

				// Check item
				IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
				if (pItemSystem)
				{
					if (pItemSystem->IsItemClass(className))
					{
						type |= eET_Item;
					}
				}
			}
		}
	}

	return (EEntityType)type;
}
Example #10
0
//------------------------------------------------------------------------
void CEditorGame::OnCloseLevel()
{
	IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
	if (pItemSystem)
	{
		pItemSystem->ClearGeometryCache();
		pItemSystem->ClearSoundCache();
		pItemSystem->Reset();
	}
	g_pGame->GetGameSharedParametersStorage()->GetItemResourceCache().FlushCaches();
}
Example #11
0
bool CJaw::OutOfAmmo(bool allFireModes) const
{
	CActor* pOwner = GetOwnerActor();
	IInventory* pOwnerInventory = pOwner ? pOwner->GetInventory() : 0;
	if (!pOwnerInventory)
		return true;

	IEntityClass* pJawClass = GetEntity()->GetClass();
	IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
	int jawUniqueId = pItemSystem->GetItemUniqueId(pJawClass->GetName());
	int currentNumJaws = pOwnerInventory->GetCountOfUniqueId(jawUniqueId);

	return currentNumJaws == 0;
}
Example #12
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{ 
		switch (event)
		{
		case (eFE_Activate):
			{
				if (!IsPortActive(pActInfo, 0))
					return;

				IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();

				// get actor
				IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
				if (!pActor) 
					return;

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

				IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1));
				IItem* pItem = pItemSys->GetItem(pInventory->GetItemByClass(pClass));
				if (!pItem || !pItem->GetIWeapon())
				{
					pItem = pActor->GetCurrentItem();
					if (!pItem || pItem->GetEntity()->GetClass() != pClass || !pItem->GetIWeapon())
					{
						GameWarning("[flow] CFlowNode_WeaponAmmo: No item/weapon %s!", GetPortString(pActInfo,1).c_str());
						return;
					}
				}
				IWeapon *pWeapon = pItem->GetIWeapon();
				const string& ammoType = GetPortString(pActInfo,2);
				IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str());
				CRY_ASSERT(pAmmoClass);
				IFireMode* pCurrentFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode());
				if (pCurrentFireMode)
				{
					int clipSize = pCurrentFireMode->GetClipSize();
					int ammo = pWeapon->GetAmmoCount(pAmmoClass) + GetPortInt(pActInfo,3);
					ammo = CLAMP(ammo, 0, clipSize);
					pWeapon->SetAmmoCount(pAmmoClass, ammo);
				}

				ActivateOutput(pActInfo, 0, pWeapon->GetAmmoCount(pAmmoClass));
			}
			break;
		}
	}
Example #13
0
void CReplayItemList::OnActionControllerDeleted()
{
	IItemSystem* pItemSys = g_pGame->GetIGameFramework()->GetIItemSystem();
	TItemVec::const_iterator end = m_items.end();
	for(TItemVec::const_iterator it = m_items.begin(); it!=end; ++it)
	{
		if(IItem* pItem = pItemSys->GetItem(*it))
		{
			pItem->UpdateCurrentActionController();
		}
	}

	m_items.clear();

}
//------------------------------------------------------------------------
void CInventory::Clear(bool forceClear)
{
	if(m_ignoreNextClear && !forceClear)
	{
		m_ignoreNextClear = false;
		return;
	}

	if(!gEnv->bServer)
	{
		IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

		TInventoryIt end = m_stats.slots.end();
		for(TInventoryIt it = m_stats.slots.begin(); it != end; ++it)
		{
			if(IItem* pItem = pItemSystem->GetItem(*it))
			{
				pItem->RemoveOwnerAttachedAccessories();
				pItem->AttachToHand(false);
				pItem->AttachToBack(false);
				pItem->SetOwnerId(0);
				pItem->GetEntity()->Hide(true);
			}
		}
	}

	m_stats.slots.clear();
	m_stats.accessorySlots.clear();
	ResetAmmoAndUsers();
	
	for (int i = 0; i < IInventory::eInventorySlot_Last; ++i)
	{
		m_stats.slotsInfo[i].Reset();
	}

	m_stats.currentItemId = 0;
	m_stats.holsteredItemId = 0;
	m_stats.lastItemId = 0;

	TListenerVec::iterator iter = m_listeners.begin();
	m_iteratingListeners = true;
	while (iter != m_listeners.end())
	{
		(*iter)->OnClearInventory();
		++iter;
	}
	m_iteratingListeners = false;
}
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{
		if (event == eFE_Activate && IsPortActive(pActInfo,0))
		{
			IActor* pActor = GetInputActor( pActInfo );
			if (!pActor)
				return;

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

				const bool removeFromWeapons = GetPortBool(pActInfo, 1);
				if(removeFromWeapons)
				{
					IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem();
					const size_t numItems = pInventory->GetCount();
					for(size_t i=0; i<numItems; ++i)
					{
						const EntityId item = pInventory->GetItem(i);
						if(IItem* pItem = pItemSystem->GetItem(item))
						{
							if(IWeapon* pWeapon = pItem->GetIWeapon())
							{
								const size_t numFiremodes = pWeapon->GetNumOfFireModes();
								for(size_t f=0; f<numFiremodes; ++f)
								{
									if(IFireMode* pFireMode = pWeapon->GetFireMode(f))
									{
										if(IEntityClass* pAmmoType = pFireMode->GetAmmoType())
										{
											pWeapon->SetAmmoCount(pAmmoType, 0);
										}
									}
								}
							}
						}
					}
				}
				ActivateOutput(pActInfo, 0, true);
			}
			else
  			ActivateOutput(pActInfo, 0, false);
		}
	}
void CFlowNode_AISequenceAction_WeaponDrawFromInventory::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent)
{
	switch(sequenceEvent)
	{
	case AIActionSequence::StartAction:
		{
			CRY_ASSERT_MESSAGE(m_actInfo.pEntity, "entity has magically gone");
			if (!m_actInfo.pEntity)
			{
				// the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem());
			IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId());
			if (!pActor)
			{
				CRY_ASSERT_MESSAGE(0, "Provided entity must be an IActor");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Provided entity %s must be an IActor", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIItemSystem());
			IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();

			IInventory* pInventory = pActor->GetInventory();
			if (!pInventory)
			{
				CRY_ASSERT_MESSAGE(0, "Actor has no inventory");
				CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s has no inventory", m_actInfo.pEntity->GetName());
				CancelSequenceAndActivateOutputPort(OutputPort_Done);
				return;
			}

			pInventory->SetHolsteredItem(EntityId(0));	// otherwise trying to holster the new weapon later on will not work (i. e. will do nothing)

			// draw the weapon
			const string& weaponName = GetPortString(&m_actInfo, InputPort_WeaponName);
			pItemSystem->SetActorItem(pActor, weaponName.c_str(), false);

			FinishSequenceActionAndActivateOutputPort(OutputPort_Done);
		}
		break;
	}
}
Example #17
0
//------------------------------------------------------------------------------
void CWeapon::ToggleFlashLight()
{
	static IEntityClass* pFlashLightClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Flashlight");

	IGameFramework* pGameFramework = g_pGame->GetIGameFramework();
	IItemSystem* pItemSystem = pGameFramework->GetIItemSystem();

	for (size_t i = 0; i < m_accessories.size(); ++i)
	{
		if (m_accessories[i].pClass == pFlashLightClass)
		{
			IItem* pItem = pItemSystem->GetItem(m_accessories[i].accessoryId);
			CFlashLight* pFlashLight = static_cast<CFlashLight*>(pItem);
			pFlashLight->ToggleFlashLight();
			break;
		}
	}
}
// RMI receiver in the server to remove an item from the inventory. change is automatically propagated to the clients
IMPLEMENT_RMI(CInventory, SvReq_RemoveItem)
{
	TRMIInventory_Item Info(params);
	
  IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem();
  
	IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( Info.m_ItemClass.c_str());
	if (pClass)
	{
    IItem* pItem = pItemSystem->GetItem( GetItemByClass( pClass ) );
    if (pItem && pItem->GetEntityId()==GetCurrentItem()) 
    {
      pItem->Select(false);
      pItemSystem->SetActorItem( GetActor(), (EntityId)0, false );
    }

    if (pItem)
      gEnv->pEntitySystem->RemoveEntity( pItem->GetEntityId() );
  }
	return true;
}
Example #19
0
void CJaw::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char* setup)
{
	for (TAmmoVector::iterator it = m_bonusammo.begin(); it != m_bonusammo.end(); ++it)
	{
		SWeaponAmmo& currentBonusAmmo = *it;
		currentBonusAmmo.count = 0;
	}

	IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
	IActor* pPicketActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pickerId);
	IInventory* pInventory = pPicketActor->GetInventory();
	bool giveExtraTube = GiveExtraTubeToInventory(pPicketActor, pItemSystem);

	if (pPicketActor->IsClient())
		SetAmmoCount(m_fm->GetAmmoType(), 1);

	BaseClass::PickUp(pickerId,sound,select,keepHistory, setup);

	if (giveExtraTube)
	{
		int numJaws = m_weaponsharedparams->ammoParams.extraItems;
		while(numJaws-- > 0)
		{
			pItemSystem->GiveItem(pPicketActor, GetEntity()->GetClass()->GetName(), false, false, false);
		}
		m_extraTubesAdded = true;
	}

	if(m_auxSlotUsed)
	{
		DrawSlot(eIGS_ThirdPersonAux,false);
		m_auxSlotUsed = false;
	}

	if(GetOwnerActor() && !GetOwnerActor()->IsPlayer())
		m_stats.first_selection = false;
}
void CEquipmentSystemInterface::InitItems(IGameToEditorInterface* pGTE)
{
	// Get ItemParams from ItemSystem
	// Creates the following entries
	// "item"               All Item classes
	// "item_selectable"    All Item classes which can be selected
	// "item_givable",      All Item classes which can be given
	// "weapon"             All Weapon classes (an Item of class 'Weapon' or an Item which has ammo)
	// "weapon_selectable"  All Weapon classes which can be selected
	// "weapon_givable"     All Weapon classes which can be given
	// and for any weapon which has ammo
	// "ammo_WEAPONNAME"    All Ammos for this weapon

	IItemSystem* pItemSys = m_pIItemSystem;
	int maxCountItems = pItemSys->GetItemParamsCount();
	int maxAllocItems = maxCountItems+1; // allocate one more to store empty
	const char** allItemClasses = new const char*[maxAllocItems];
	const char** givableItemClasses = new const char*[maxAllocItems];
	const char** selectableItemClasses = new const char*[maxAllocItems];
	const char** allWeaponClasses = new const char*[maxAllocItems];
	const char** givableWeaponClasses = new const char*[maxAllocItems];
	const char** selectableWeaponClasses = new const char*[maxAllocItems];

	int numAllItems = 0;
	int numAllWeapons = 0;
	int numGivableItems = 0;
	int numSelectableItems = 0;
	int numSelectableWeapons = 0;
	int numGivableWeapons = 0;
	std::set<string> allAmmosSet;

	// store default "---" -> "" value
	{
		const char* empty = "";
		selectableWeaponClasses[numSelectableWeapons++] = empty;
		givableWeaponClasses[numGivableWeapons++] = empty;
		allWeaponClasses[numAllWeapons++] = empty;
		selectableItemClasses[numSelectableItems++] = empty;
		givableItemClasses[numGivableItems++] = empty;
		allItemClasses[numAllItems++] = empty;
		allAmmosSet.insert(empty);
	}

	for (int i=0; i<maxCountItems; ++i)
	{
		const char* itemName = pItemSys->GetItemParamName(i);
		allItemClasses[numAllItems++] = itemName;

		const char* itemDescriptionFile = pItemSys->GetItemParamsDescriptionFile(itemName);
		
		CRY_ASSERT(itemDescriptionFile);
		XmlNodeRef itemRootParams = gEnv->pSystem->LoadXmlFromFile(itemDescriptionFile);

		if (!itemRootParams)
		{
			GameWarning("Item description file %s doesn't exist for item %s", itemDescriptionFile, itemName);
			continue;
		}

		CGameXmlParamReader rootReader(itemRootParams);
		const char* inheritItem = itemRootParams->getAttr("inherit");
		bool isInherited = (inheritItem && inheritItem[0] != 0);
		if (isInherited)
		{
			const char* baseItemFile = pItemSys->GetItemParamsDescriptionFile(inheritItem);
			itemRootParams = gEnv->pSystem->LoadXmlFromFile(baseItemFile);
		}

		if (itemRootParams)
		{
			bool givable = false;
			bool selectable = false;
			bool uiWeapon = false;
			XmlNodeRef childItemParams = itemRootParams->findChild("params");
			if (childItemParams) 
			{
				CGameXmlParamReader reader(childItemParams);

				//the equipeable flag is supposed to be used for weapons that are not givable
				//but that are still needed to be in the equipment weapon list.
				bool equipeable = false;
				reader.ReadParamValue<bool>("equipeable", equipeable);
				reader.ReadParamValue<bool>("giveable", givable);
				givable |= equipeable;

				reader.ReadParamValue<bool>("selectable", selectable);
				reader.ReadParamValue<bool>("ui_weapon", uiWeapon);
			}

			if (givable)
				givableItemClasses[numGivableItems++] = itemName;
			if (selectable)
				selectableItemClasses[numSelectableItems++] = itemName;

			XmlNodeRef childAccessoriesNode = itemRootParams->findChild("accessories");

			if(childAccessoriesNode)
			{
				const int numAccessories = childAccessoriesNode->getChildCount();

				for(int childIdx = 0; childIdx < numAccessories; childIdx++)
				{
					XmlNodeRef childAccessory = childAccessoriesNode->getChild(childIdx);

					if(childAccessory && stricmp(childAccessory->getTag(), "accessory") == 0)
					{
						const char* accessoryName = childAccessory->getAttr("name");
						const char* categoryName = childAccessory->getAttr("category");			

						if(categoryName && accessoryName)
						{
							m_accessoryMap[itemName][categoryName].push_back(accessoryName);
						}
					}
				}
			}

			XmlNodeRef ammosNode = itemRootParams->findChild("ammos");
			if (ammosNode)
			{
				CGameXmlParamReader reader(ammosNode);

				const int maxAmmos = reader.GetUnfilteredChildCount();
				int numAmmos = 0;
				const char** ammoNames = new const char*[maxAmmos];
				for (int j=0; j<maxAmmos; ++j)
				{
					XmlNodeRef ammoChildNode = reader.GetFilteredChildAt(j);
					if ((ammoChildNode != NULL) && stricmp(ammoChildNode->getTag(), "ammo") == 0)
					{
						const char* ammoName = ammoChildNode->getAttr("name");
						if (ammoName && ammoName[0])
						{
							ammoNames[numAmmos] = ammoName;
							++numAmmos;
							allAmmosSet.insert(ammoName);
						}
					}
				}
				if (numAmmos > 0)
				{
					// make it a weapon when there's ammo
					allWeaponClasses[numAllWeapons++] = itemName;
					if (selectable)
						selectableWeaponClasses[numSelectableWeapons++] = itemName;
					if (givable)
						givableWeaponClasses[numGivableWeapons++] = itemName;

					string ammoEntryName = "ammo_";
					ammoEntryName+=itemName;
					pGTE->SetUIEnums(ammoEntryName.c_str(), ammoNames, numAmmos);
				}
				delete[] ammoNames;
			}
			else
			{
				const char* itemClass = itemRootParams->getAttr("class");
				if (uiWeapon || (itemClass != 0 && stricmp(itemClass, "weapon") == 0))
				{
					// make it a weapon when there's ammo
					allWeaponClasses[numAllWeapons++] = itemName;
					if (selectable)
						selectableWeaponClasses[numSelectableWeapons++] = itemName;
					if (givable)
						givableWeaponClasses[numGivableWeapons++] = itemName;
				}
			}
		}
	}

	int numAllAmmos = 0;
	const char** allAmmos = new const char*[allAmmosSet.size()];
	std::set<string>::const_iterator iter (allAmmosSet.begin());
	while (iter != allAmmosSet.end())
	{
		allAmmos[numAllAmmos++] = iter->c_str();
		++iter;
	}
	pGTE->SetUIEnums("ammos", allAmmos, numAllAmmos);
	ToContainer(allAmmos+1, numAllAmmos-1, m_itemMap["Ammo"]);
	delete[] allAmmos;

	pGTE->SetUIEnums("weapon_selectable", selectableWeaponClasses, numSelectableWeapons);
	pGTE->SetUIEnums("weapon_givable", givableWeaponClasses, numGivableWeapons);
	pGTE->SetUIEnums("weapon", allWeaponClasses, numAllWeapons);
	pGTE->SetUIEnums("item_selectable", selectableItemClasses, numSelectableItems);
	pGTE->SetUIEnums("item_givable", givableItemClasses, numGivableItems);
	pGTE->SetUIEnums("item", allItemClasses, numAllItems);

	ToContainer(allItemClasses+1,numAllItems-1,m_itemMap["Item"]);
	ToContainer(givableItemClasses+1,numGivableItems-1,m_itemMap["ItemGivable"]);
	ToContainer(allWeaponClasses+1,numAllWeapons-1,m_itemMap["Weapon"]);

	delete[] selectableWeaponClasses;
	delete[] givableWeaponClasses;
	delete[] allWeaponClasses;
	delete[] selectableItemClasses;
	delete[] givableItemClasses; 
	delete[] allItemClasses;
}
Example #21
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{ 
		switch (event)
		{
		case eFE_Initialize:
			{
				m_actInfo = *pActInfo;
				Reset();
			}
			break;

		case eFE_Activate:
			{ 
				IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem();

				// create listener
				if (IsPortActive(pActInfo, IN_DISABLE))
				{ 
					Reset();
				}
				if (IsPortActive(pActInfo, IN_ENABLE))
				{ 
					Reset();
					IItem* pItem = 0;

					EntityId weaponId = GetPortEntityId(pActInfo, IN_WEAPONID);                    
					if (weaponId != 0)
					{
						pItem = pItemSys->GetItem(weaponId);
					}
					else
					{            
						IActor* pActor = CCryAction::GetCryAction()->GetClientActor();
						if (!pActor) 
							return;

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

						const string& weaponClass = GetPortString(pActInfo, IN_WEAPONCLASS);
						if (!weaponClass.empty())
						{
							// get actor weapon by class
							IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(weaponClass);
							pItem = pItemSys->GetItem( pInventory->GetItemByClass(pClass) );
						}
						else
						{
							// get current actor weapon
							pItem = pItemSys->GetItem(pInventory->GetCurrentItem());
						}
					}          

					if (!pItem || !pItem->GetIWeapon())
					{
						GameWarning("[flow] CFlowNode_WeaponListener: no item/weapon.");
						return;
					}

					m_weapId = pItem->GetEntity()->GetId();
					IWeapon* pWeapon = pItem->GetIWeapon();

					// set initial ammo
					m_ammo = GetPortInt(pActInfo, IN_AMMO);
					if (m_ammo == 0)
						m_ammo = -1; // 0 input means infinite

					// set weapon listener                            
					pWeapon->AddEventListener(this, "CFlowNode_WeaponListener");

					m_active = true;

					//CryLog("WeaponListener successfully created on %s", pItem->GetEntity()->GetName());
				}           
				break;
			}
		}
	}
void CEquipmentSystemInterface::InitItems(IGameToEditorInterface* pGTE)
{
	// Get ItemParams from ItemSystem
	// Creates the following entries
	// "item"               All Item classes
	// "item_selectable"    All Item classes which can be selected
	// "item_givable",      All Item classes which can be given
	// "weapon"             All Weapon classes (an Item of class 'Weapon' or an Item which has ammo)
	// "weapon_selectable"  All Weapon classes which can be selected
	// "weapon_givable"     All Weapon classes which can be given
	// and for any weapon which has ammo
	// "ammo_WEAPONNAME"    All Ammos for this weapon

	IItemSystem* pItemSys = m_pIItemSystem;
	int maxCountItems = pItemSys->GetItemParamsCount();
	int maxAllocItems = maxCountItems+1; // allocate one more to store empty
	const char** allItemClasses = new const char*[maxAllocItems];
	const char** givableItemClasses = new const char*[maxAllocItems];
	const char** selectableItemClasses = new const char*[maxAllocItems];
	const char** allWeaponClasses = new const char*[maxAllocItems];
	const char** givableWeaponClasses = new const char*[maxAllocItems];
	const char** selectableWeaponClasses = new const char*[maxAllocItems];

	int numAllItems = 0;
	int numAllWeapons = 0;
	int numGivableItems = 0;
	int numSelectableItems = 0;
	int numSelectableWeapons = 0;
	int numGivableWeapons = 0;
	std::set<string> allAmmosSet;

	// store default "---" -> "" value
	{
		const char* empty = "";
		selectableWeaponClasses[numSelectableWeapons++] = empty;
		givableWeaponClasses[numGivableWeapons++] = empty;
		allWeaponClasses[numAllWeapons++] = empty;
		selectableItemClasses[numSelectableItems++] = empty;
		givableItemClasses[numGivableItems++] = empty;
		allItemClasses[numAllItems++] = empty;
		allAmmosSet.insert(empty);
	}

	for (int i=0; i<maxCountItems; ++i)
	{
		const char* itemName = pItemSys->GetItemParamName(i);
		allItemClasses[numAllItems++] = itemName;

		const IItemParamsNode* pItemRootParams = pItemSys->GetItemParams(itemName);

		if (pItemRootParams)
		{
			bool givable = false;
			bool selectable = false;
			bool uiWeapon = false;
			const IItemParamsNode *pChildItemParams = pItemRootParams->GetChild("params");
			if (pChildItemParams) 
			{
				CItemParamReader reader (pChildItemParams);

				//FIXME: the equipeable(?) flag is supposed to be used for weapons that are not givable (alien weapons)
				//but that are still needed to be in the equipment weapon list.
				bool equipeable = false;
				reader.Read("equipeable", equipeable);
				reader.Read("giveable", givable);
				givable |= equipeable;

				reader.Read("selectable", selectable);
				reader.Read("ui_weapon", uiWeapon);
			}

			if (givable)
				givableItemClasses[numGivableItems++] = itemName;
			if (selectable)
				selectableItemClasses[numSelectableItems++] = itemName;

			const IItemParamsNode* pAmmos = pItemRootParams->GetChild("ammos");
			if (pAmmos)
			{
				int maxAmmos = pAmmos->GetChildCount();
				int numAmmos = 0;
				const char** ammoNames = new const char*[maxAmmos];
				for (int j=0; j<maxAmmos; ++j)
				{
					const IItemParamsNode* pAmmoParams = pAmmos->GetChild(j);
					if (stricmp(pAmmoParams->GetName(), "ammo") == 0)
					{
						const char* ammoName = pAmmoParams->GetAttribute("name");
						if (ammoName)
						{
							ammoNames[numAmmos] = ammoName;
							++numAmmos;
							allAmmosSet.insert(ammoName);
						}
					}
				}
				if (numAmmos > 0)
				{
					// make it a weapon when there's ammo
					allWeaponClasses[numAllWeapons++] = itemName;
					if (selectable)
						selectableWeaponClasses[numSelectableWeapons++] = itemName;
					if (givable)
						givableWeaponClasses[numGivableWeapons++] = itemName;

					string ammoEntryName = "ammo_";
					ammoEntryName+=itemName;
					pGTE->SetUIEnums(ammoEntryName.c_str(), ammoNames, numAmmos);
				}
				delete[] ammoNames;
			}
			else
			{
				const char* itemClass = pItemRootParams->GetAttribute("class");
				if (uiWeapon || (itemClass != 0 && stricmp(itemClass, "weapon") == 0))
				{
					// make it a weapon when there's ammo
					allWeaponClasses[numAllWeapons++] = itemName;
					if (selectable)
						selectableWeaponClasses[numSelectableWeapons++] = itemName;
					if (givable)
						givableWeaponClasses[numGivableWeapons++] = itemName;
				}
			}
		}
	}

	int numAllAmmos = 0;
	const char** allAmmos = new const char*[allAmmosSet.size()];
	std::set<string>::const_iterator iter (allAmmosSet.begin());
	while (iter != allAmmosSet.end())
	{
		allAmmos[numAllAmmos++] = iter->c_str();
		++iter;
	}
	pGTE->SetUIEnums("ammos", allAmmos, numAllAmmos);
	ToContainer(allAmmos+1, numAllAmmos-1, m_itemMap["Ammo"]);
	delete[] allAmmos;

	pGTE->SetUIEnums("weapon_selectable", selectableWeaponClasses, numSelectableWeapons);
	pGTE->SetUIEnums("weapon_givable", givableWeaponClasses, numGivableWeapons);
	pGTE->SetUIEnums("weapon", allWeaponClasses, numAllWeapons);
	pGTE->SetUIEnums("item_selectable", selectableItemClasses, numSelectableItems);
	pGTE->SetUIEnums("item_givable", givableItemClasses, numGivableItems);
	pGTE->SetUIEnums("item", allItemClasses, numAllItems);

	ToContainer(allItemClasses+1,numAllItems-1,m_itemMap["Item"]);
	ToContainer(givableItemClasses+1,numGivableItems-1,m_itemMap["ItemGivable"]);
	ToContainer(allWeaponClasses+1,numAllWeapons-1,m_itemMap["Weapon"]);

	delete[] selectableWeaponClasses;
	delete[] givableWeaponClasses;
	delete[] allWeaponClasses;
	delete[] selectableItemClasses;
	delete[] givableItemClasses; 
	delete[] allItemClasses;
}
void CLaserBeam::UpdateLaser(const CLaserBeam::SLaserUpdateDesc& laserUpdateDesc)
{
	if(m_pLaserParams && m_laserOn)
	{
		IEntity* pLaserEntity = CreateLaserEntity();
		if (pLaserEntity)
		{
			m_lastLaserUpdatePosition = laserUpdateDesc.m_laserPos;
			m_lastLaserUpdateDirection = laserUpdateDesc.m_laserDir;

			m_laserUpdateTimer += laserUpdateDesc.m_frameTime;

			UpdateLaserGeometry(*pLaserEntity);

			if(m_laserUpdateTimer < LASER_UPDATE_TIME)
				return;

			m_laserUpdateTimer = Random(0.0f, LASER_UPDATE_TIME * 0.4f);

			if ((laserUpdateDesc.m_ownerCloaked && !laserUpdateDesc.m_weaponZoomed) || laserUpdateDesc.m_bOwnerHidden)
			{
				pLaserEntity->Hide(true);
				return;
			}
			pLaserEntity->Hide(false);

			const float range = m_pLaserParams->laser_range[GetIndexFromGeometrySlot()];

			// Use the same flags as the AI system uses for visbility.
			const int objects = ent_terrain|ent_static|ent_rigid|ent_sleeping_rigid|ent_independent; //ent_living;
			const int flags = (geom_colltype_ray << rwi_colltype_bit) | rwi_colltype_any | (10 & rwi_pierceability_mask) | (geom_colltype14 << rwi_colltype_bit);

			//If we did not get a result, just cancel it, we will queue a new one again
			RayCastRequest::Priority requestPriority = RayCastRequest::MediumPriority;
			if (m_queuedRayId != 0)
			{
				g_pGame->GetRayCaster().Cancel(m_queuedRayId);
				m_queuedRayId = 0;
				requestPriority = RayCastRequest::HighPriority;
			}

			IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
			IPhysicalEntity* pSkipEntity = NULL;
			uint8 numSkips = 0;

			CItem* pItem = static_cast<CItem*>(pItemSystem->GetItem(m_ownerEntityId));

			if(pItem)
			{
				if(pItem->IsAccessory())
				{
					CItem* pParentItem = static_cast<CItem*>(pItemSystem->GetItem(pItem->GetParentId()));
				
					if(pParentItem)
					{
						pItem = pParentItem;
					}					
				}

				IEntity* pOwnerEnt = 0;
				CWeapon* pWeapon = static_cast<CWeapon*>(pItem->GetIWeapon());
				if (pWeapon && pWeapon->GetHostId() != 0)
				{
					pOwnerEnt = gEnv->pEntitySystem->GetEntity(pWeapon->GetHostId());
				}
				else
				{
					pOwnerEnt = pItem->GetOwner();
				}

				if(pOwnerEnt)
				{
					IPhysicalEntity* pOwnerPhysics = pOwnerEnt->GetPhysics();

					if(pOwnerPhysics)
					{
						pSkipEntity = pOwnerPhysics;
						numSkips++;
					}
				}
			}

			m_queuedRayId = g_pGame->GetRayCaster().Queue(
				requestPriority,
				RayCastRequest(laserUpdateDesc.m_laserPos, laserUpdateDesc.m_laserDir*range,
				objects,
				flags,
				&pSkipEntity,
				numSkips),
				functor(*this, &CLaserBeam::OnRayCastDataReceived));
		}

	}
	else if (!m_pLaserParams)
	{
		GameWarning("LASER PARAMS: Item of type CLaser is missing it's laser params!");
	}
}
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));
		}
	}
}
Example #25
0
void CHUDCrosshair::Update(float fDeltaTime)
{
	if(m_bBroken)
		return;

	IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor();
	IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
	
	if(!pClientActor || !pItemSystem)
		return;

	IInventory *pInventory = pClientActor->GetInventory();
	if(!pInventory)
		return;

  IItem *pItem = pItemSystem->GetItem(pInventory->GetCurrentItem());      
  IWeapon *pWeapon = NULL;
	IWeapon *pSlaveWeapon = NULL;
	const float fAlternateIronSight = 0.03f;
  
  if(pItem)
	{
		pWeapon = pItem->GetIWeapon();        

		if(pItem->IsDualWieldMaster())
		{
			if(IItem *pSlave=pItem->GetDualWieldSlave())
				pSlaveWeapon = pSlave->GetIWeapon();
		}
  }
  else if(IVehicle *pVehicle=pClientActor->GetLinkedVehicle())
  {
    pItem = pItemSystem->GetItem(pVehicle->GetCurrentWeaponId(pClientActor->GetEntityId()));
    if(pItem)
      pWeapon = pItem->GetIWeapon();
  }

	if(pWeapon)
	{
		float fMinSpread = 0.0f;
		float fMaxSpread = 0.0f;

		m_spread = 0.0f;

		if(IFireMode *pFireMode=pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()))
		{
			fMinSpread = pFireMode->GetMinSpread();
			fMaxSpread = pFireMode->GetMaxSpread();

			m_spread = pFireMode->GetSpread();
		}

		if(pSlaveWeapon)
		{
			if(IFireMode *pSlaveFireMode=pSlaveWeapon->GetFireMode(pSlaveWeapon->GetCurrentFireMode()))
			{
				fMinSpread += pSlaveFireMode->GetMinSpread();
				fMaxSpread += pSlaveFireMode->GetMaxSpread();

				m_spread += pSlaveFireMode->GetSpread();
			}
		}

		CPlayer *pPlayer = static_cast<CPlayer*>(pClientActor);
		if(pPlayer && pPlayer->GetNanoSuit() && pPlayer->GetNanoSuit()->GetMode() == NANOMODE_STRENGTH)
			m_spread *=0.5;

		if(g_pGameCVars->hud_iAlternateCrosshairSpread)
		{
			if(m_spread < fMinSpread)
				m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch) / g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch;
			else
				m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral) / g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral;
		}
		else
		{
			m_spread = min((m_spread-fMinSpread),15.0f) / 15.0f;

			IZoomMode *pZoomMode = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode());
			if(pZoomMode && !pZoomMode->IsToggle() && (pZoomMode->IsZoomed() || pZoomMode->IsZooming()))
			{
				m_spread -= fAlternateIronSight;
			}
			else
			{
				m_spread = min(m_spread,1.0f);
				m_spread = max(m_spread,0.0f);
			}
		}
	}

	if(m_animCrossHair.GetVisible() && !g_pHUD->InSpectatorMode())
	{
		//also disables the damage indicator
		if(/*g_pGameCVars->hud_crosshair>0 && m_iCrosshair > 0 &&*/ (g_pGameCVars->g_difficultyLevel<4 || gEnv->bMultiplayer))
		{
			m_animCrossHair.GetFlashPlayer()->Advance(fDeltaTime);
			m_animCrossHair.GetFlashPlayer()->Render();
		}

		if(m_animInterActiveIcons.GetVisible()) //if the crosshair is invisible, the use icon should be too
		{
			if(!m_bHideUseIconTemp)	//hides the icon, when something is already grabbed/being used
			{
				m_animInterActiveIcons.GetFlashPlayer()->Advance(fDeltaTime);
				m_animInterActiveIcons.GetFlashPlayer()->Render();
			}
		}
	}

	if(m_animFriendCross.GetVisible())
	{
		m_animFriendCross.GetFlashPlayer()->Advance(fDeltaTime);
		m_animFriendCross.GetFlashPlayer()->Render();
	}

	if(!g_pGameCVars->hud_iAlternateCrosshairSpread)
	{
		m_spread = max(m_spread,-fAlternateIronSight);
		m_spread = min(m_spread,1.0f);
	}

	if (m_smoothSpread != m_spread)
	{
		Interpolate(m_smoothSpread, m_spread, 20.0f, fDeltaTime);
		m_animCrossHair.Invoke("setRecoil", m_smoothSpread);
	}

	UpdateCrosshair();
}
Example #26
0
//------------------------------------------------------------------------
bool CGameRules::OnPromoteToServer(SHostMigrationInfo& hostMigrationInfo, uint32& state)
{
	if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session))
	{
		return true;
	}

	CryLogAlways("[Host Migration]: CGameRules::OnPromoteToServer() started");

	// Server time will change after we migrate (change from old server time to new server time)
	m_gameStartedTime.SetValue(m_gameStartedTime.GetValue() - m_cachedServerTime.GetValue());
	m_gameStartTime.SetValue(m_gameStartTime.GetValue() - m_cachedServerTime.GetValue());

	// If this migration has reset (we're not the original anticipated host, remove any entities from the first attempt
	if (!m_hostMigrationCachedEntities.empty())
	{
		HostMigrationRemoveDuplicateDynamicEntities();
	}

	// Now we know we're the server, remove the actors for anyone we know isn't going to migrate
	CGameLobby *pGameLobby = g_pGame->GetGameLobby();
	CRY_ASSERT(pGameLobby);
	if (pGameLobby)
	{
		TPlayers playersToRemove;

		IActorSystem *pActorSystem = g_pGame->GetIGameFramework()->GetIActorSystem();

		playersToRemove.reserve(pActorSystem->GetActorCount());

		IActorIteratorPtr actorIt = pActorSystem->CreateActorIterator();
		IActor *pActor;
		while (pActor = actorIt->Next())
		{
			if (pActor->IsPlayer())
			{
				CRY_ASSERT(pActor->GetChannelId());
				SCryMatchMakingConnectionUID conId = pGameLobby->GetConnectionUIDFromChannelID((int) pActor->GetChannelId());
				if (pGameLobby->GetSessionNames().Find(conId) == SSessionNames::k_unableToFind)
				{
					CryLog("  player '%s' has not got a corresponding CGameLobby entry, removing actor", pActor->GetEntity()->GetName());
					playersToRemove.push_back(pActor->GetEntityId());
				}
			}
		}

		const int numPlayersToRemove = playersToRemove.size();
		for (int i = 0; i < numPlayersToRemove; ++ i)
		{
			FakeDisconnectPlayer(playersToRemove[i]);
		}
	}

	for (uint32 i = 0; i < MAX_PLAYERS; ++ i)
	{
		m_migratedPlayerChannels[i] = 0;
	}

	IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();

	IEntityItPtr it = gEnv->pEntitySystem->GetEntityIterator();
	it->MoveFirst();

	for (uint32 i = 0; i < m_hostMigrationItemMaxCount; ++ i)
	{
		m_pHostMigrationItemInfo[i].Reset();
	}
	uint32 itemIndex = 0;

	IEntity *pEntity = NULL;
	while (pEntity = it->Next())
	{
		IItem *pItem = pItemSystem->GetItem(pEntity->GetId());
		if (pItem)
		{
			if (pItem->GetOwnerId())
			{
				IEntity *pOwner = gEnv->pEntitySystem->GetEntity(pItem->GetOwnerId());
				if (pOwner)
				{
					EntityId currentItemId = 0;

					IActor *pOwnerActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pOwner->GetId());
					if (pOwnerActor)
					{
						IItem *pCurrentItem = pOwnerActor->GetCurrentItem();
						currentItemId = pCurrentItem ? pCurrentItem->GetEntityId() : 0;
					}

					CryLog("[CG] Item '%s' is owned by '%s'", pEntity->GetName(), pOwner->GetName());
					//m_pHostMigrationItemInfo[itemIndex].Set(pEntity->GetId(), pOwner->GetId(), pItem->IsUsed(), (pItem->GetEntityId() == currentItemId));
					itemIndex ++;
					if (itemIndex >= m_hostMigrationItemMaxCount)
					{
						CRY_ASSERT(itemIndex < m_hostMigrationItemMaxCount);
						break;
					}
				}
			}
		}
		// Tell entities that we're host migrating
		// - Currently only used by ForbiddenArea but may well be needed for other entities later
		// - Currently only called on the new server, add to OnDemoteToClient if we need to use this on a client
		IScriptTable *pScript = pEntity->GetScriptTable();
		if (pScript != NULL && pScript->GetValueType("OnHostMigration") == svtFunction)
		{
			m_pScriptSystem->BeginCall(pScript, "OnHostMigration");
			m_pScriptSystem->PushFuncParam(pScript);
			m_pScriptSystem->PushFuncParam(true);
			m_pScriptSystem->EndCall();
		}
	}

	// This needs initialising on the new server otherwise the respawn timer will be counting down
	// from uninitialised data.  Likewise for the pre-round timer.
	ResetReviveCycleTime();

	const int numRespawnParams = m_respawndata.size();
	for (int i = 0; i < numRespawnParams; ++ i)
	{
		SEntityRespawnData *pData = &m_respawndata[i];
		pEntity = gEnv->pEntitySystem->GetEntity(pData->m_currentEntityId);
		if (pEntity == NULL)
		{
			CryLog("  detected respawn entity (id=%u) is not present, scheduling for respawn", pData->m_currentEntityId);
			ScheduleEntityRespawn(pData->m_currentEntityId, false, g_pGameCVars->g_defaultItemRespawnTimer);
		}
	}

	CryLog("[Host Migration]: CGameRules::OnPromoteToServer() finished");

	CCCPOINT(HostMigration_OnPromoteToServer);
	return true;
}
	virtual void ProcessEvent( EFlowEvent event,SActivationInfo *pActInfo )
	{
		IVehicleSystem * pVehicleSystem = NULL;
		IVehicle * pVehicle = NULL;

		switch(event)
		{
		case eFE_Initialize:
			{
				pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false);
				break;
			}

		case eFE_Activate:
			{
				if (!pActInfo->pEntity)
					return;

				pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
				pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId());

				if (!pVehicleSystem || !pVehicle)
					return;

				string givenString = GetPortString(pActInfo, IN_PARTS);
				currentParam = givenString.substr(0,givenString.find_first_of(":"));
				currentSetting = givenString.substr(givenString.find_first_of(":")+1,(givenString.length()-givenString.find_first_of(":")));

				column1 = 10.f;
				column2 = 100.f;

				if (IsPortActive(pActInfo,IN_SHOW))
					pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true);

				break;
			}

		case eFE_Update:
			{
				IRenderer * pRenderer = gEnv->pRenderer;

				pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem();
				pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId());

				if(!pVehicleSystem || !pActInfo->pEntity || !pVehicle)
					return;

				pRenderer->Draw2dLabel(column1,10,GetPortFloat(pActInfo,IN_SIZE)+2.f,Col_Cyan,false,pActInfo->pEntity->GetName());

				if(currentParam=="Seats")
				{
					loops = 0;

					for(uint32 i=0;i<pVehicle->GetSeatCount();i++)
					{
						IVehicleSeat * currentSeat;

						if(currentSetting=="All")
						{
							currentSeat = pVehicle->GetSeatById(i+1);
						}
						else
						{
							currentSeat = pVehicle->GetSeatById(pVehicle->GetSeatId(currentSetting));
							i = pVehicle->GetSeatCount()-1;
						}

						loops += 1;

						// column 1
						string pMessage = ("%s:", currentSeat->GetSeatName());

						if (column2<pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE))
							column2=pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE);

						pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage);

						// column 2
						if(currentSeat->GetPassenger(true))
						{
							pMessage = ("- %s", gEnv->pEntitySystem->GetEntity(currentSeat->GetPassenger(true))->GetName());
							pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage);
						}
					}
				}

				else if(currentParam=="Wheels")
				{
					pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"!");
				}

				else if(currentParam=="Weapons")
				{
					loops = 0;

					for(int i=0;i<pVehicle->GetWeaponCount();i++)
					{
						IItemSystem * pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem();
						IWeapon * currentWeapon;
						EntityId currentEntityId;
						IItem * pItem;

						if(currentSetting=="All")
						{
							currentEntityId = pVehicle->GetWeaponId(i+1);
						}
						else
						{
							currentEntityId = gEnv->pEntitySystem->FindEntityByName(currentSetting)->GetId();
							i = pVehicle->GetWeaponCount()-1;
						}

						if(!pItemSystem->GetItem(currentEntityId))
							return;

						pItem = pItemSystem->GetItem(currentEntityId);
						currentWeapon = pItem->GetIWeapon();

						loops += 1;

						// column 1
						string pMessageName = string().Format("%s", gEnv->pEntitySystem->GetEntity(currentEntityId)->GetName());
						pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageName);

						if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE))
							column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE);

						// column 2
						string pMessageValue = string().Format("seat: %s firemode: %i", pVehicle->GetWeaponParentSeat(currentEntityId)->GetSeatName(), currentWeapon->GetCurrentFireMode()).c_str();
						pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageValue);
					}
				}

				else if(currentParam=="Components")
				{
					loops = 0;

					for(int i=0;i<pVehicle->GetComponentCount();i++)
					{
						IVehicleComponent * currentComponent;

						if(currentSetting=="All")
						{
							currentComponent = pVehicle->GetComponent(i);
						}
						else
						{
							currentComponent = pVehicle->GetComponent(currentSetting);
							i = pVehicle->GetComponentCount()-1;
						}

						loops += 1;

						ColorF labelColor;
						labelColor = ColorF(currentComponent->GetDamageRatio(),(1.f-currentComponent->GetDamageRatio()),0.f);

						// column 1
						string pMessageName = string().Format("%s", currentComponent->GetComponentName()).c_str();
						pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageName);

						if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE))
							column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE);

						// column 2
						string pMessageValue = string().Format("%5.2f (%3.2f)", currentComponent->GetDamageRatio()*currentComponent->GetMaxDamage(), currentComponent->GetDamageRatio()).c_str();
						pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageValue);
					}
				}

				else
				{
					pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"no component selected!");
				}
				break;
			}
		}
	};
Example #28
0
//------------------------------------------------------------------------
int CScriptBind_Item::OnUsed(IFunctionHandler *pH, ScriptHandle userId)
{
	CItem *pItem = GetItem(pH);
	if (!pItem)
		return pH->EndFunction();

	CActor *pActor = GetActor((EntityId)userId.n);
	if (!pActor)
		return pH->EndFunction();

	if (pItem->CanUse((EntityId)userId.n))
	{
		if(IEntity* pParent = pItem->GetEntity()->GetParent())
		{
			IVehicle* pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(pParent->GetId());
			if(pVehicle)
			{
				CPlayer* pPlayer = static_cast<CPlayer*>(pActor);
				IInteractor* pInteractor = pPlayer->GetInteractor();
				return pH->EndFunction( pVehicle->OnUsed((EntityId)userId.n, pInteractor->GetOverSlotIdx()) );
			}
		}

		pActor->UseItem(pItem->GetEntityId());
		return pH->EndFunction(true);
	}
	else if (pItem->CanPickUp((EntityId)userId.n))
	{
		//Should be always the client...
		if (pActor->IsClient())
		{
			CPlayer* pClientPlayer = static_cast<CPlayer*>(pActor);
			const SInteractionInfo& interactionInfo = pClientPlayer->GetCurrentInteractionInfo();
			bool expectedItem = (interactionInfo.interactiveEntityId == pItem->GetEntityId());
			bool expectedInteraction =	(interactionInfo.interactionType == eInteraction_PickupItem) || 
																	(interactionInfo.interactionType == eInteraction_ExchangeItem);
			if (!expectedItem || !expectedInteraction)
			{
				return pH->EndFunction();
			}

			if (interactionInfo.interactionType == eInteraction_ExchangeItem)
			{
				IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem();
				CItem* pCurrentItem = static_cast<CItem*>(pActor->GetCurrentItem());
				CItem* pExchangeItem = static_cast<CItem*>(pItemSystem->GetItem(interactionInfo.swapEntityId));
				if (pExchangeItem && pCurrentItem)
					pExchangeItem->ScheduleExchangeToNextItem(pActor, pItem, pCurrentItem);
			}
			else
			{
				pActor->PickUpItem(pItem->GetEntityId(), true, true);
			}
		}
		else
		{
			pActor->PickUpItem(pItem->GetEntityId(), true, true);
		}
		return pH->EndFunction(true);
	}

	return pH->EndFunction();
}
	~CFlowNode_InventoryItemSelected()
	{
		IItemSystem* pItemSys = m_pGF->GetIItemSystem();
		if (pItemSys)
			pItemSys->UnregisterListener(this);
	}
Example #30
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 );
	}
}