u32	 CLevelGraph::check_position_in_direction_slow	(u32 start_vertex_id, const Fvector2 &start_position, const Fvector2 &finish_position) const
{
	if (!valid_vertex_position(v3d(finish_position)))
		return				(u32(-1));

	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1);
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= start_position;
	dest					= finish_position;
	dir.sub					(dest,start);
	u32						dest_xz = vertex_position(v3d(dest)).xz();
	Fvector2				temp;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	for (;;) {
		const_iterator		I,E;
		begin				(cur_vertex_id,I,E);
		bool				found = false;
		for ( ; I != E; ++I) {
			u32				next_vertex_id = value(cur_vertex_id,I);
			if ((next_vertex_id == prev_vertex_id) || !valid_vertex_id(next_vertex_id))
				continue;
			CVertex			*v = vertex(next_vertex_id);
			unpack_xz		(v,temp.x,temp.y);
			box.min			= box.max = temp;
			box.grow		(identity);
			if (box.pick_exact(start,dir)) {

				if (dest_xz == v->position().xz()) {
					return	(is_accessible(next_vertex_id) ? next_vertex_id : u32(-1));
				}
				Fvector2		temp;
				temp.add		(box.min,box.max);
				temp.mul		(.5f);
				float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
				if (dist > cur_sqr)
					continue;
				
				if (!is_accessible(next_vertex_id))
					return		(u32(-1));

				cur_sqr			= dist;
				found			= true;
				prev_vertex_id	= cur_vertex_id;
				cur_vertex_id	= next_vertex_id;
				break;
			}
		}
		if (!found) {
			return			(u32(-1));
		}
	}
}
Beispiel #2
0
void CUIDragItem::Draw()
{
	Fvector2 tmp;
	tmp.sub					(GetWndPos(), GetUICursor().GetCursorPosition());
	tmp.sub					(m_pos_offset);
	tmp.mul					(-1.0f);
	MoveWndDelta			(tmp);
	inherited::Draw			();
	if(m_custom_draw) 
		m_custom_draw->OnDraw(this);
}
Beispiel #3
0
void CUIWeaponCellItem::InitAddon(CUIStatic* s, LPCSTR section, Fvector2 addon_offset, bool b_rotate)
{
	
		Frect					tex_rect;
		Fvector2				base_scale;

		if(Heading())
		{
			base_scale.x			= GetHeight()/(INV_GRID_WIDTHF*m_grid_size.x);
			base_scale.y			= GetWidth()/(INV_GRID_HEIGHTF*m_grid_size.y);
		}else
		{
			base_scale.x			= GetWidth()/(INV_GRID_WIDTHF*m_grid_size.x);
			base_scale.y			= GetHeight()/(INV_GRID_HEIGHTF*m_grid_size.y);
		}
		Fvector2				cell_size;
		cell_size.x				= pSettings->r_u32(section, "inv_grid_width")*INV_GRID_WIDTHF;
		cell_size.y				= pSettings->r_u32(section, "inv_grid_height")*INV_GRID_HEIGHTF;

		tex_rect.x1				= pSettings->r_u32(section, "inv_grid_x")*INV_GRID_WIDTHF;
		tex_rect.y1				= pSettings->r_u32(section, "inv_grid_y")*INV_GRID_HEIGHTF;

		tex_rect.rb.add			(tex_rect.lt,cell_size);

		cell_size.mul			(base_scale);

		if(b_rotate)
		{
			s->SetWndSize		(Fvector2().set(cell_size.y, cell_size.x) );
			Fvector2 new_offset;
			new_offset.x		= addon_offset.y*base_scale.x;
			new_offset.y		= GetHeight() - addon_offset.x*base_scale.x - cell_size.x;
			addon_offset		= new_offset;
		}else
		{
			s->SetWndSize		(cell_size);
			addon_offset.mul	(base_scale);
		}

		s->SetWndPos			(addon_offset);
		s->SetOriginalRect		(tex_rect);
		s->SetStretchTexture	(true);

		s->EnableHeading		(b_rotate);
		
		if(b_rotate)
		{
			s->SetHeading			(GetHeading());
			Fvector2 offs;
			offs.set				(0.0f, s->GetWndSize().y);
			s->SetHeadingPivot		(Fvector2().set(0.0f,0.0f), /*Fvector2().set(0.0f,0.0f)*/offs, true);
		}
}
Beispiel #4
0
void CUIDragItem::Draw()
{
	Fvector2 tmp;
	tmp.sub					(GetWndPos(), GetUICursor()->GetCursorPosition());
	tmp.sub					(m_pos_offset);
	tmp.mul					(-1.0f);
	MoveWndDelta			(tmp);
	UI()->PushScissor		(UI()->ScreenRect(),true);

	inherited::Draw();

	UI()->PopScissor();
}
Beispiel #5
0
void CUILevelMap::Draw()
{
	if(MapWnd()){
		for(WINDOW_LIST_it it = m_ChildWndList.begin(); m_ChildWndList.end() != it; ++it)
		{
			CMapSpot* sp			= smart_cast<CMapSpot*>((*it));
			if(sp&&sp->m_bScale){
				Fvector2 sz			= sp->m_originSize;
				sz.mul				(MapWnd()->GlobalMap()->GetCurrentZoom());
				sp->SetWndSize		(sz);
			}
		}
	}
	inherited::Draw();

}
bool CEvaluatorTargetMapShown::evaluate()
{
	if(m_storage->property(1)) return true;
	if(m_storage->property(2)) return true;
	Fvector2 pt					= m_object->m_tgtCenter; 
	pt.mul						(m_object->GlobalMap()->GetCurrentZoom());
	Fvector2 _p;
	m_object->GlobalMap()->GetAbsolutePos(_p);
	pt.add						(_p);
	Frect	rect	=	m_object->ActiveMapRect();
			rect.grow	(rect.width(),rect.height());
	if (rect.in(pt))	{
		m_storage->set_property	(2,true);
		return true;
	}
	return false;
}
bool CLevelGraph::neighbour_in_direction	(const Fvector &direction, u32 start_vertex_id) const
{
	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = u32(-1);
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= v2d(vertex_position(start_vertex_id));
	dir						= v2d(direction);
	dir.normalize_safe		();
	dest					= dir;
	dest.mul				(header().cell_size()*4.f);
	dest.add				(start);
	Fvector2				temp;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	const_iterator			I,E;
	begin					(cur_vertex_id,I,E);
	for ( ; I != E; ++I) {
		u32					next_vertex_id = value(cur_vertex_id,I);
		if ((next_vertex_id == prev_vertex_id) || !is_accessible(next_vertex_id))
			continue;
		unpack_xz			(vertex(next_vertex_id),temp.x,temp.y);
		box.min				= box.max = temp;
		box.grow			(identity);
		if (box.pick_exact(start,dir)) {
			Fvector2		temp;
			temp.add		(box.min,box.max);
			temp.mul		(.5f);
			float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
			if (dist > cur_sqr)
				continue;
			return			(true);
		}
	}
	return					(false);
}
Beispiel #8
0
void CUIZoneMap::Init()
{
	CUIXml uiXml;
	uiXml.Load						(CONFIG_PATH, UI_PATH, "zone_map.xml");

	CUIXmlInit						xml_init;
	xml_init.InitStatic				(uiXml, "minimap:background",	0, &m_background);
	xml_init.InitWindow				(uiXml, "minimap:level_frame",	0, &m_clipFrame);
	xml_init.InitStatic				(uiXml, "minimap:center",		0, &m_center);
	
	m_clock_wnd						= UIHelper::CreateStatic(uiXml, "minimap:clock_wnd", &m_background);

	m_activeMap						= xr_new<CUIMiniMap>();
	m_clipFrame.AttachChild			(m_activeMap);
	m_activeMap->SetAutoDelete		(true);

	m_activeMap->EnableHeading		(true);  
	xml_init.InitStatic				(uiXml, "minimap:compass", 0, &m_compass);
	m_background.AttachChild		(&m_compass);

	m_clipFrame.AttachChild			(&m_center);

	m_Counter_text.SetText( "" );
	visible = true;

	Fvector2 sz_k				= m_clipFrame.GetWndSize();
	Fvector2 sz					= sz_k;
	{
		float k = UI().get_current_kx();

		sz.y					*= UI_BASE_HEIGHT*k;
		sz.x					= sz.y / k;

		m_clipFrame.SetWndSize	(sz);
		
		Fvector2 p				= m_clipFrame.GetWndPos();
		p.mul					(UI_BASE_HEIGHT);
		m_clipFrame.SetWndPos	(p);
		
		m_background.SetHeight	(m_background.GetHeight() * UI_BASE_HEIGHT);
		m_background.SetWidth	(m_background.GetHeight() * k);
	}

	Fvector2				map_center;
	m_clipFrame.GetWndRect().getcenter(map_center);
	m_background.SetWndPos	(map_center);

	Fvector2 cp;
	cp.x = m_clipFrame.GetWidth()/2.0f;
	cp.y = m_clipFrame.GetHeight()/2.0f;
	m_center.SetWndPos		(cp);

	Fvector2 rel_pos		= m_compass.GetWndPos();
	rel_pos.mul				(m_background.GetWndSize());
	m_compass.SetWndPos		(rel_pos);

	rel_pos					= m_clock_wnd->GetWndPos();
	rel_pos.mul				(m_background.GetWndSize());
	m_clock_wnd->SetWndPos	(rel_pos);

	if ( IsGameTypeSingle() )
	{
		xml_init.InitStatic			(uiXml, "minimap:static_counter", 0, &m_Counter);
		m_background.AttachChild	(&m_Counter);
		xml_init.InitTextWnd		(uiXml, "minimap:static_counter:text_static", 0, &m_Counter_text);
		m_Counter.AttachChild		(&m_Counter_text);

		rel_pos						= m_Counter.GetWndPos();
		rel_pos.mul					(m_background.GetWndSize());
		m_Counter.SetWndPos			(rel_pos);
	}

}
bool CLevelGraph::create_straight_path(u32 start_vertex_id, const Fvector2 &start_point, const Fvector2 &finish_point, xr_vector<Fvector> &tpaOutputPoints, xr_vector<u32> &tpaOutputNodes, bool bAddFirstPoint, bool bClearPath) const
{
	if (!valid_vertex_position(v3d(finish_point)))
		return				(false);

	u32						cur_vertex_id = start_vertex_id, prev_vertex_id = start_vertex_id;
	Fbox2					box;
	Fvector2				identity, start, dest, dir;

	identity.x = identity.y	= header().cell_size()*.5f;
	start					= start_point;
	dest					= finish_point;
	dir.sub					(dest,start);
	u32						dest_xz = vertex_position(v3d(dest)).xz();
	Fvector2				temp;
	Fvector					pos3d;
	unpack_xz				(vertex(start_vertex_id),temp.x,temp.y);

	if (bClearPath) {
		tpaOutputPoints.clear	();
		tpaOutputNodes.clear	();
	}
	if (bAddFirstPoint) {
		pos3d				= v3d(start_point);
		pos3d.y				= vertex_plane_y(start_vertex_id,start_point.x,start_point.y);
		tpaOutputPoints.push_back(pos3d);
		tpaOutputNodes.push_back(start_vertex_id);
	}

	float					cur_sqr = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
	for (;;) {
		const_iterator		I,E;
		begin				(cur_vertex_id,I,E);
		bool				found = false;
		for ( ; I != E; ++I) {
			u32				next_vertex_id = value(cur_vertex_id,I);
			if ((next_vertex_id == prev_vertex_id) || !valid_vertex_id(next_vertex_id))
				continue;
			CVertex			*v = vertex(next_vertex_id);
			unpack_xz		(v,temp.x,temp.y);
			box.min			= box.max = temp;
			box.grow		(identity);
			if (box.pick_exact(start,dir)) {
				Fvector2		temp;
				temp.add		(box.min,box.max);
				temp.mul		(.5f);
				float			dist = _sqr(temp.x - dest.x) + _sqr(temp.y - dest.y);
				if (dist > cur_sqr)
					continue;

				Fvector2		next1, next2;
#ifdef DEBUG
				next1			= next2 = Fvector2().set(0.f,0.f);
#endif
				Fvector			tIntersectPoint;

				switch (I) {
					case 0 : {
						next1		= box.max;
						next2.set	(box.max.x,box.min.y);
						break;
					}
					case 1 : {
						next1		= box.min;
						next2.set	(box.max.x,box.min.y);
						break;
					}
					case 2 : {
						next1		= box.min;
						next2.set	(box.min.x,box.max.y);
						break;
					}
					case 3 : {
						next1		= box.max;
						next2.set	(box.min.x,box.max.y);
						break;
					}
					default : NODEFAULT;
				}
				VERIFY			(_valid(next1));
				VERIFY			(_valid(next2));
				u32				dwIntersect = intersect(start_point.x,start_point.y,finish_point.x,finish_point.y,next1.x,next1.y,next2.x,next2.y,&tIntersectPoint.x,&tIntersectPoint.z);
				if (!dwIntersect)
					continue;
				tIntersectPoint.y = vertex_plane_y(vertex(cur_vertex_id),tIntersectPoint.x,tIntersectPoint.z);

				tpaOutputPoints.push_back(tIntersectPoint);
				tpaOutputNodes.push_back(cur_vertex_id);

				if (dest_xz == v->position().xz())
					return		(true);
				
				cur_sqr			= dist;
				found			= true;
				prev_vertex_id	= cur_vertex_id;
				cur_vertex_id	= next_vertex_id;
				break;
			}
		}
		if (!found)
			return				(false);
	}
}