Example #1
0
void CUIActorMenu::highlight_ammo_for_weapon( PIItem weapon_item, CUIDragDropListEx* ddlist )
{
	VERIFY( weapon_item );
	VERIFY( ddlist );
	static xr_vector<shared_str>	ammo_types;
	ammo_types.clear_not_free();

	CWeapon* weapon = smart_cast<CWeapon*>(weapon_item);
	if ( !weapon )
	{
		return;
	}
	ammo_types.assign( weapon->m_ammoTypes.begin(), weapon->m_ammoTypes.end() );

	CWeaponMagazinedWGrenade* wg = smart_cast<CWeaponMagazinedWGrenade*>(weapon_item);
	if ( wg )
	{
		if ( wg->IsGrenadeLauncherAttached() && wg->m_ammoTypes2.size() )
		{
			ammo_types.insert( ammo_types.end(), wg->m_ammoTypes2.begin(), wg->m_ammoTypes2.end() );
		}
	}
	
	if ( ammo_types.size() == 0 )
	{
		return;
	}
	xr_vector<shared_str>::iterator ite = ammo_types.end();
	
	u32 const cnt = ddlist->ItemsCount();
	for ( u32 i = 0; i < cnt; ++i )
	{
		CUICellItem* ci = ddlist->GetItemIdx(i);
		PIItem item = (PIItem)ci->m_pData;
		if ( !item )
		{
			continue;
		}
		CWeaponAmmo* ammo = smart_cast<CWeaponAmmo*>(item);
		if ( !ammo )
		{
			highlight_addons_for_weapon( weapon_item, ci );
			continue; // for i
		}
		shared_str const& ammo_name = item->object().cNameSect();

		xr_vector<shared_str>::iterator itb = ammo_types.begin();
		for ( ; itb != ite; ++itb )
		{
			if ( ammo_name._get() == (*itb)._get() )
			{
				ci->m_select_armament = true;
				break; // itb
			}
		}
	}//for i

}
Example #2
0
void transfer(const char *name, xr_vector<T> &dest, IReader& F, u32 chunk)
{
	IReader*	O	= F.open_chunk(chunk);
	u32		count	= O?(O->length()/sizeof(T)):0;
	clMsg			("* %16s: %d",name,count);
	if (count)  
	{
		dest.reserve(count);
		dest.insert	(dest.begin(), (T*)O->pointer(), (T*)O->pointer() + count);
	}
	if (O)		O->close	();
}
Example #3
0
void		sort_tlist_mat			
(
 xr_vector<mapMatrixTextures::TNode*,render_alloc<mapMatrixTextures::TNode*> >& lst,
 xr_vector<mapMatrixTextures::TNode*,render_alloc<mapMatrixTextures::TNode*> >& temp,
 mapMatrixTextures&					textures,
 BOOL	bSSA
 )
{
	int amount			= textures.begin()->key->size();
	if (bSSA)	
	{
		if (amount<=1)
		{
			// Just sort by SSA
			textures.getANY_P			(lst);
			std::sort					(lst.begin(), lst.end(), cmp_textures_ssa_mat);
		} 
		else 
		{
			// Split into 2 parts
			mapMatrixTextures::TNode* _it	= textures.begin	();
			mapMatrixTextures::TNode* _end	= textures.end		();
			for (; _it!=_end; _it++)	{
				if (_it->val.ssa > r_ssaHZBvsTEX)	lst.push_back	(_it);
				else								temp.push_back	(_it);
			}

			// 1st - part - SSA, 2nd - lexicographically
			std::sort					(lst.begin(),	lst.end(),	cmp_textures_ssa_mat);
			if (2==amount)				std::sort	(temp.begin(),	temp.end(),	cmp_textures_lex2_mat);
			else if (3==amount)			std::sort	(temp.begin(),	temp.end(),	cmp_textures_lex3_mat);
			else						std::sort	(temp.begin(),	temp.end(),	cmp_textures_lexN_mat);

			// merge lists
			lst.insert					(lst.end(),temp.begin(),temp.end());
		}
	}
	else 
	{
		textures.getANY_P			(lst);
		if (2==amount)				std::sort	(lst.begin(),	lst.end(),	cmp_textures_lex2_mat);
		else if (3==amount)			std::sort	(lst.begin(),	lst.end(),	cmp_textures_lex3_mat);
		else						std::sort	(lst.begin(),	lst.end(),	cmp_textures_lexN_mat);
	}
}
Example #4
0
IC	void CSmartCastStats::show					()
{
	if (m_stats.empty()) {
		Msg								("CONGRATULATIONS : SmartCast stats is empty!!!");
		return;
	}

	m_temp.clear						();
	m_temp.insert						(m_temp.begin(),m_stats.begin(),m_stats.end());
	std::sort							(m_temp.begin(),m_temp.end(),CStatsPredicate());
	u32									total = 0;

	xr_vector<CStats>::const_iterator	I = m_temp.begin();
	xr_vector<CStats>::const_iterator	E = m_temp.end();
	for ( ; I != E; ++I)
		total							+= (*I).m_count;

	Msg									("SmartCast stats (different %d, total %d) : ",(u32)m_stats.size(),total);

	I									= m_temp.begin();
	for ( ; I != E; ++I)
		Msg								("%8d %6.2f% : smart_cast<%s>(%s)",(*I).m_count,float((*I).m_count)*100.f/float(total),(*I).m_to,(*I).m_from);
}
Example #5
0
void ProcessOne		(u32 Base, u32 limit=8)
{
	BestQuad.clear	();
	BestQuad_Count	= 0;
	
	// ***** build horizontal line
	vecDW			BaseLine;
	BaseLine.reserve(limit*2);
	u32			BL_Left=0,BL_Right=0;
	
	// middle
	vertex&			BaseNode = g_nodes[Base];
	BaseLine.push_back(Base);
	
	// left expansion
	for (;;) {
		vertex&	B	= g_nodes[BaseLine.front()];
		u32	LP	= B.nLeft();
		
		if (BL_Left>limit)						break;
		if (LP==InvalidNode)					break;
		if (used[LP])							break;
		if (!NodeSimilar(BaseNode,g_nodes[LP]))	break;
		
		BL_Left	++;
		BaseLine.insert(BaseLine.begin(),LP);
	}
	
	// right expansion
	for (;;) {
		vertex&	B	= g_nodes[BaseLine.back()];
		u32	RP	= B.nRight();
		
		if (BL_Right>limit)						break;
		if (RP==InvalidNode)					break;
		if (used[RP])							break;
		if (!NodeSimilar(BaseNode,g_nodes[RP]))	break;
		
		BL_Right++;
		BaseLine.push_back(RP);
	}
	
	// main cycle
	//	Msg("- ---");
	u32	BasePos	= BaseLine[BL_Left];
	for (u32 left=0; left<=BL_Left; left++)
	{
		u32	limit_right	= left+limit-1;
		if (limit_right>=BaseLine.size())	limit_right=BaseLine.size()-1;
		u32	limit_left	= left;
		if (limit_left<BL_Left)				limit_left = BL_Left;
		if (limit_left>limit_right)			limit_left = limit_right;
		for (int right=int(limit_right); right>=int(limit_left); right--)
		{
			// now we have range [left,right]
			// expand it up and down
			xr_vector<vecDW>	stack_up;
			xr_vector<vecDW>	stack_down;
			
			//			Msg("[%2d,%2d], %d",	left,right,BaseLine.size());
			
			stack_up.reserve		(limit);
			stack_up.push_back		(vecDW());
			stack_up.back().assign	(BaseLine.begin()+left,BaseLine.begin()+right+1);
			stack_down.reserve		(limit);
			stack_down.push_back	(vecDW());
			stack_down.back().assign(BaseLine.begin()+left,BaseLine.begin()+right+1);
			
			// expand up
			for (;stack_up.size()<=limit;) {
				// create _new list
				stack_up.push_back	(vecDW());
				vecDW&	src			= stack_up[stack_up.size()-2];
				vecDW&	dest		= stack_up[stack_up.size()-1];
				dest.reserve		(limit);
				BOOL				bFailed = FALSE;
				
				// iterate on it
				vecDW_it I			= src.begin	();
				vecDW_it E			= src.end	();
				for (; I!=E; I++)
				{
					u32	id	= g_nodes[*I].nForward();
					if	(id==InvalidNode)					{ bFailed=TRUE; break; }
					if	(used[id])							{ bFailed=TRUE; break; }
					if	(!NodeSimilar(g_nodes[id],BaseNode)){ bFailed=TRUE; break; }
					dest.push_back	(id);
				}
				if (bFailed) {
					stack_up.pop_back();
					break;
				}
			}
			// expand down
			for (; (stack_up.size()+stack_down.size()-1) <= limit;) {
				// create _new list
				stack_down.push_back(vecDW());
				vecDW&	src			= stack_down[stack_down.size()-2];
				vecDW&	dest		= stack_down[stack_down.size()-1];
				dest.reserve		(limit);
				BOOL				bFailed = FALSE;
				
				// iterate on it
				vecDW_it I			= src.begin	();
				vecDW_it E			= src.end	();
				for (; I!=E; I++)
				{
					u32	id	= g_nodes[*I].nBack();
					if	(id==InvalidNode)					{ bFailed=TRUE; break; }
					if	(used[id])							{ bFailed=TRUE; break; }
					if	(!NodeSimilar(g_nodes[id],BaseNode)){ bFailed=TRUE; break; }
					dest.push_back	(id);
				}
				if (bFailed) {
					stack_down.pop_back();
					break;
				}
			}
			
			// calculate size
			u32 size_z	= stack_up.size()+stack_down.size()-1;
			u32 size_x	= stack_up.back().size();
			u32 size_mix	= size_z*size_x;
			if (size_mix>BestQuad_Count)	
			{
				BestQuad_Count		= size_mix;
				BestQuad.clear		();
				BestQuad.reserve	(size_z);
				
				// transfer quad
				for (u32 it=stack_up.size()-1; it>0; it--)
					BestQuad.push_back(stack_up[it]);
				BestQuad.insert(BestQuad.begin(),stack_down.begin(),stack_down.end());
			}
		}
	}
}