Example #1
0
void CInventory::Update() 
{
	if( OnServer() )
	{
		if(m_iActiveSlot!=m_iNextActiveSlot)
		{
			CObject* pActor_owner = smart_cast<CObject*>(m_pOwner);
			if (Level().CurrentViewEntity() == pActor_owner)
			{
				if(	(m_iNextActiveSlot!=NO_ACTIVE_SLOT) && 
					 ItemFromSlot(m_iNextActiveSlot)	&&
					 !g_player_hud->allow_activation(ItemFromSlot(m_iNextActiveSlot)->cast_hud_item())
				   )
				   return;
			}
			if( ActiveItem() )
			{
				CHudItem* hi = ActiveItem()->cast_hud_item();
				
				if(!hi->IsHidden())
				{
					if(hi->GetState()==CHUDState::eIdle && hi->GetNextState()==CHUDState::eIdle)
						hi->SendDeactivateItem();

					UpdateDropTasks	();
					return;
				}
			}
			
			if (GetNextActiveSlot() != NO_ACTIVE_SLOT)
			{
				PIItem tmp_next_active = ItemFromSlot(GetNextActiveSlot());
				if (tmp_next_active)
				{
					if (IsSlotBlocked(tmp_next_active))
					{
						Activate(m_iActiveSlot);
						return;
					} else
					{
						tmp_next_active->ActivateItem();
					}
				}
			}
			
//			if ( m_iActiveSlot != GetNextActiveSlot() ) {
//				LPCSTR const name = smart_cast<CGameObject const*>(m_pOwner)->cName().c_str();
//				if ( !xr_strcmp("jup_b43_stalker_assistant_pri6695", name) )
//					LogStackTrace	("");
//				Msg					("[%6d][%s] CInventory::Activate changing active slot from %d to next active slot %d", Device.dwTimeGlobal, name, m_iActiveSlot, GetNextActiveSlot() );
//			}
			m_iActiveSlot			= GetNextActiveSlot();
		}
		if((GetNextActiveSlot()!=NO_ACTIVE_SLOT) && ActiveItem() && ActiveItem()->cast_hud_item()->IsHidden())
				ActiveItem()->ActivateItem();
	}
	UpdateDropTasks	();
}
Example #2
0
void CInventory::Activate(u16 slot, bool bForce) 
{	
	if(!OnServer())
	{
		return;
	}

	PIItem tmp_item = NULL;
	if (slot != NO_ACTIVE_SLOT)
		tmp_item = ItemFromSlot(slot);

	if (tmp_item && IsSlotBlocked(tmp_item) && (!bForce))
	{
		//to restore after unblocking ...
		SetPrevActiveSlot(slot);
		return;
	}

	if (GetActiveSlot()==slot || (GetNextActiveSlot()==slot && !bForce))
	{
//		if (m_iNextActiveSlot != slot) {
//			LPCSTR const name = smart_cast<CGameObject const*>(m_pOwner)->cName().c_str();
//			if ( !xr_strcmp("jup_b43_stalker_assistant_pri6695", name) )
//				LogStackTrace	("");
//			Msg				( "[%6d][%s] CInventory::Activate changing next active slot to %d", Device.dwTimeGlobal, name, slot );
//		}
		m_iNextActiveSlot=slot;
#ifdef DEBUG
//		Msg("--- There's no need to activate slot [%d], next active slot is [%d]", slot, m_iNextActiveSlot);
#endif
		return;
	}

	R_ASSERT2(slot<=LastSlot(), "wrong slot number");

	if (slot != NO_ACTIVE_SLOT && !m_slots[slot].CanBeActivated()) 
		return;

#ifdef DEBUG
//	Msg("--- Activating slot [%d], inventory owner: [%s], Frame[%d]", slot, m_pOwner->Name(), Device.dwFrame);
#endif // #ifdef DEBUG
	
	//активный слот не выбран
	if (GetActiveSlot() == NO_ACTIVE_SLOT)
	{
		if (tmp_item)
		{
//			if ( m_iNextActiveSlot != slot) {
//				LPCSTR const name = smart_cast<CGameObject const*>(m_pOwner)->cName().c_str();
//				if ( !xr_strcmp("jup_b43_stalker_assistant_pri6695", name) )
//					LogStackTrace	("");
//				Msg				( "[%6d][%s] CInventory::Activate changing next active slot2 to %d", Device.dwTimeGlobal, name, slot );
//			}
			m_iNextActiveSlot		= slot;
		}
		else 
		{
			if(slot==GRENADE_SLOT)//fake for grenade
			{
				PIItem gr = SameSlot(GRENADE_SLOT, NULL, true);
				if(gr)
					Slot(GRENADE_SLOT,gr);
			}
		}
	}
	//активный слот задействован
	else if (slot==NO_ACTIVE_SLOT || tmp_item)
	{
		PIItem active_item = ActiveItem();
		if(active_item && !bForce)
		{
			CHudItem* tempItem = active_item->cast_hud_item();
			R_ASSERT2(tempItem, active_item->object().cNameSect().c_str());
			
			tempItem->SendDeactivateItem();
#ifdef DEBUG
//			Msg("--- Inventory owner [%s]: send deactivate item [%s]", m_pOwner->Name(), active_item->NameItem());
#endif // #ifdef DEBUG
		} else //in case where weapon is going to destroy
		{
			if (tmp_item)
				tmp_item->ActivateItem();
			
//!			if ( m_iActiveSlot != slot ) {
//!				LPCSTR const name = smart_cast<CGameObject const*>(m_pOwner)->cName().c_str();
//				if ( !xr_strcmp("jup_b43_stalker_assistant_pri6695", name) )
//					LogStackTrace	("");
//!				Msg				("[%6d][%s] CInventory::Activate changing active slot from %d to %d", Device.dwTimeGlobal, name, m_iActiveSlot, slot );
//!			}

			m_iActiveSlot		= slot;
		}
//		if ( m_iNextActiveSlot != slot ) {
//			LPCSTR const name = smart_cast<CGameObject const*>(m_pOwner)->cName().c_str();
//			if ( !xr_strcmp("jup_b43_stalker_assistant_pri6695", name) && !slot )
//				LogStackTrace	("");
//			Msg				( "[%6d][%s] CInventory::Activate changing next active slot3 to %d", Device.dwTimeGlobal, name, slot );
//		}
		m_iNextActiveSlot		= slot;
	}
}