Beispiel #1
0
/*
================
rvGEOptions::SnapRectToGrid

Snap the rectangle to the grid
================
*/
void rvGEOptions::SnapRectToGrid ( idRectangle& rect, bool snapLeft, bool snapTop, bool snapWidth, bool snapHeight )
{
	if ( snapLeft )
	{
		float offset = (int)(rect.x + GetGridWidth() / 2) / GetGridWidth() * GetGridWidth();
		offset -= rect.x;
		rect.x += offset;
		rect.w -= offset;
	}

	if ( snapWidth )
	{					
		float offset = (int)(rect.x + rect.w + GetGridWidth() / 2) / GetGridWidth() * GetGridWidth();
		offset -= rect.x;
		offset -= rect.w;
		rect.w += offset;
	}
	
	if ( snapTop )
	{
		float offset = (int)(rect.y + GetGridHeight() / 2) / GetGridHeight() * GetGridHeight();
		offset -= rect.y;
		rect.y += offset;
		rect.h -= offset;
	}

	if ( snapHeight )
	{					
		float offset = (int)(rect.y + rect.h + GetGridHeight() / 2) / GetGridHeight() * GetGridHeight();
		offset -= rect.y;
		offset -= rect.h;
		rect.h += offset;
	}		
}
Beispiel #2
0
void CInventoryItem::Load(LPCSTR section) 
{
	CHitImmunity::LoadImmunities	(pSettings->r_string(section,"immunities_sect"),pSettings);

	ISpatial*			self				=	smart_cast<ISpatial*> (this);
	if (self)			self->spatial.type	|=	STYPE_VISIBLEFORAI;	

	m_name				= CStringTable().translate( pSettings->r_string(section, "inv_name") );
	m_nameShort			= CStringTable().translate( pSettings->r_string(section, "inv_name_short"));

//.	NameComplex			();
	m_weight			= pSettings->r_float(section, "inv_weight");
	R_ASSERT			(m_weight>=0.f);

	m_cost				= pSettings->r_u32(section, "cost");

#ifdef INV_NEW_SLOTS_SYSTEM
	const	char	*str = READ_IF_EXISTS(pSettings, r_string, section, "slot", "");
	if (*str)
	{
		char	buf[16];
		const	int		count = _GetItemCount(str);
		if (count)
			m_slots.clear(); // full override!

		for (int i = 0; i < count; ++i)
		{
			SLOT_ID slot = atoi(_GetItem(str, i, buf) ); 
			// вместо std::find(m_slots.begin(), m_slots.end(), slot) == m_slots.end() используется !IsPlaceable
			if (slot < SLOTS_TOTAL && !IsPlaceable(slot, slot))
				m_slots.push_back(slot);			
		}
		//init selected slots первым же слотом
		selected_slot = 0;
	}	
	
	// alpet: разрешение некоторым объектам попадать в слоты быстрого доступа независимо от настроек
	if ( smart_cast<CEatableItem*>(&object()) &&
		 GetGridWidth () <= SLOT_QUICK_CELLS_X && 
		 GetGridHeight() <= SLOT_QUICK_CELLS_Y) 
	{
		m_slots.push_back(SLOT_QUICK_ACCESS_0);
		m_slots.push_back(SLOT_QUICK_ACCESS_1);
		m_slots.push_back(SLOT_QUICK_ACCESS_2);
		m_slots.push_back(SLOT_QUICK_ACCESS_3);
	}
#else
	m_slot				= READ_IF_EXISTS(pSettings,r_u32,section,"slot", NO_ACTIVE_SLOT);
#endif

	// Description
	if ( pSettings->line_exist(section, "description") )
		m_Description = CStringTable().translate( pSettings->r_string(section, "description") );

	m_flags.set(Fbelt,			READ_IF_EXISTS(pSettings, r_bool, section, "belt",				FALSE));
	m_flags.set(FRuckDefault,	READ_IF_EXISTS(pSettings, r_bool, section, "default_to_ruck",	TRUE));

	m_flags.set(FCanTake,		READ_IF_EXISTS(pSettings, r_bool, section, "can_take",			TRUE));
	m_flags.set(FCanTrade,		READ_IF_EXISTS(pSettings, r_bool, section, "can_trade",			TRUE));
	m_flags.set(FIsQuestItem,	READ_IF_EXISTS(pSettings, r_bool, section, "quest_item",		FALSE));



	//время убирания объекта с уровня
	m_dwItemRemoveTime			= READ_IF_EXISTS(pSettings, r_u32, section,"item_remove_time",			ITEM_REMOVE_TIME);

	m_flags.set					(FAllowSprint,READ_IF_EXISTS	(pSettings, r_bool, section,"sprint_allowed",			TRUE));
	m_fControlInertionFactor	= READ_IF_EXISTS(pSettings, r_float,section,"control_inertion_factor",	1.0f);
	m_icon_name					= READ_IF_EXISTS(pSettings, r_string,section,"icon_name",				NULL);

}
	int CGridManager::GetGridSize() {
		return GetGridHeight()*GetGridWidth();
	}