DWORD __stdcall draw_roads4( CDC* pDC )
{
	Emulator* emu = GLOBAL_EMU;
	if (emu->num_of_roads() == 4) {
		int corner = 360 / emu->num_of_roads();
		int road_id = 0;
		int line_index = 0;
		int v_num_of_lines = emu->num_of_lines(0)+emu->num_of_lines(2);
		int h_num_of_lines = emu->num_of_lines(1)+emu->num_of_lines(3);
		int center_to_up_road = h_num_of_lines / 2 * LINE_WIDTH;
		int center_to_left_road = v_num_of_lines / 2 * LINE_WIDTH;
		int x1 = CENTER_X - center_to_left_road;
		int y1 = CENTER_Y - center_to_up_road;

		draw_road(0,x1,y1,v_num_of_lines*LINE_WIDTH,center_to_up_road,emu->num_of_lines(0),90,pDC);
		draw_road(1,CENTER_X+center_to_left_road,CENTER_Y-center_to_up_road,h_num_of_lines*LINE_WIDTH,center_to_left_road,emu->num_of_lines(1),180,pDC);
		draw_road(2,CENTER_X+center_to_left_road,CENTER_Y+center_to_up_road,v_num_of_lines*LINE_WIDTH,center_to_up_road,emu->num_of_lines(2),270,pDC);
		draw_road(3,CENTER_X-center_to_left_road,CENTER_Y+center_to_up_road,h_num_of_lines*LINE_WIDTH,center_to_left_road,emu->num_of_lines(3),0,pDC);

	}
	return 0;
}
void BMMap::make_map( int num_loc, float spacing )
{
	int i,j;

	// init bitmaps	
	if (bmpMap) destroy_bitmap( bmpMap );


	bmpMap = load_jpeg( "gamedata/map.jpg" );
	
	BITMAP *blankMap = create_bitmap( 800, 600 );
	blit( bmpMap, blankMap, 0,0, 0,0, 800, 600 );

	nloc = num_loc;

	if (allLocs.size()==0) {
		init_map_locs( "gamedata/maplocs.xml" );
	}

	printf("allLocs size %d\n", allLocs.size() );

	// fill in the map locs
	int reject , count, ndx;
	for (i=0; i < nloc; i++) {

		reject = 1; count = 100;
		while ((reject) && (count)) {
			ndx = random( allLocs.size() );
			count--;

			reject = 0; 
			for (j=0; j < i; j++) {
				if (allLocs[ndx].name==loc[j].name) {
					reject = 1;
					break;
				}
			}

		}

		loc[i] = allLocs[ndx];
		loc[i].index = i;
		loc[i].heroVisited = 0;
	}

	// locate the locs
	for ( i=0; i < nloc; i++) {
		

		int good = 0;
		int x, y;
		float d;
		
				
		good = 0;
		while (!good) {
			x = random( 170, 678 );
			y = random( 75, 450 );			

			good = 1;
			for  ( j=0; j < i; j++) {
			
				float xx, yy;
				xx = (float)(loc[j].xpos - x);
				yy = (float)(loc[j].ypos - y);
				
				d = sqrt( xx*xx + yy*yy ) ;				
				if (d < spacing ) {
					good = 0;					
					break;
				}
			}
		}
				
		loc[i].xpos = x;
		loc[i].ypos = y;
	}


	// make the edges
	make_edges_delauney();


	// remove some edges 
	std::vector<CanRemoveEdge> cre;
	while (1) {
		cre.erase( cre.begin(), cre.end() );

		// which edges can we remove??
		for (i=0; i < nloc; i++) {
			for (j=0; j < i; j++) {

				if (adj[i][j].pass) {
					
					// can we remove i->j?
					adj[i][j].pass = 0;
					adj[j][i].pass = 0;

					if (is_connected()) {
						CanRemoveEdge foo;
						foo.a = i; foo.b = j;
						cre.push_back( foo );
					}


					// put the edge back (for now )
					adj[i][j].pass = 1;
					adj[j][i].pass = 1;

				}

			}
		}

		// no more edges to remove? (TODO: leave SOME loops)

		//printf("Cre size %d\n", cre.size() );
		if (cre.size() == 0 ) {
			break; 
		}

		// do remove the edge
		int ndx = random( cre.size() );
		i = cre[ndx].a;
		j = cre[ndx].b;

		adj[i][j].pass = 0;
		adj[j][i].pass = 0;

		// draw in the blockage
		if (adj[i][j].de) {
			DualEdge *de = adj[i][j].de;

			draw_blockers( bmpMap, bmpMtns, de->x1, de->y1, de->x2, de->y2 );

			//line( bmpMap, de->x1, de->y1, de->x2, de->y2, makecol( 255,0,0) );
		}
	}


	

	// draw the edges
	for ( i=0; i < nloc; i++) {
		for ( j=0; j < i; j++) {

			if (adj[i][j].pass) {


				draw_road( bmpMap, blankMap,
					loc[i].xpos, loc[i].ypos,
					loc[j].xpos, loc[j].ypos );

				//line( bmpMap, 
				//	loc[i].xpos, loc[i].ypos,
				//	loc[j].xpos, loc[j].ypos,
				//	makecol( 0,255,0 ) );

			}

		} 
	}


	// draw the icons on the map
	for ( i=0; i < nloc; i++) {

		BITMAP *ico = mapIcons[loc[i].bgType];

		int f=0;
		if (ico->w > 64) {
			f = random( ico->w / 64 );
		}
		masked_blit( ico, bmpMap, f*64,0, 
			  loc[i].xpos - 32, loc[i].ypos - 32,
			  64, 64 );
	}
	

	destroy_bitmap( blankMap );
}