Esempio n. 1
0
OZF2GPXMap::OZF2GPXMap(const char *fn)
{
	kGUIString ozfn;
	DataHandle dh;
	int linenum;
	kGUIString line;
	kGUIStringSplit ss;
	int index;
	int z;
	int nf;
	unsigned char *fp;
	unsigned long filesize;
	OZ2FHEADER_DEF *oh;
	double maxlat,maxlon;
	double maxx,maxy;

	m_coords=0;

	dh.SetFilename(fn);
	if(dh.Open()==false)
		return;	/* couldn't load file */

	linenum=0;
	do
	{
		dh.ReadLine(&line);
		nf=ss.Split(&line,",");

		if(linenum==2)
		{
			int sl;
			static char dirchar[]={ DIRCHAR };

			ozfn.SetString(fn);	/* extract path from filename */
			sl=ozfn.GetLen()-1;
			/* cut off last subdir */
			while(sl>0)
			{
				if(ozfn.GetChar(sl)==dirchar[0])
				{
					++sl;
					break;
				}
				--sl;
			};
			ozfn.Clip(sl);
			ozfn.Append(line.GetString());
		}
		else if(linenum==4)
		{
			/* datum */
			if(!strcmp(ss.GetWord(0)->GetString(),"WGS 84"))
			{
				/* ok */
			}
			else
			{
				dh.Close();
				return;
			}
			//if (! FindOziDatumToWGS84 (strDatum.c_str (), m_pDatumTransformation)) {
			//	m_pDatumTransformation = NULL;
			//	ReportWarning ("Some unsupported datum is used: '%s'. No datum conversion performed.", strDatum.c_str ());
		}
		else
		{
			if(!strcmp(ss.GetWord(0)->GetString(),"Map Projection"))
			{
				/* todo */
			}
			else if(!strcmp(ss.GetWord(0)->GetString(),"MMPNUM"))
			{
				m_coords=new OZF2Corners[ss.GetWord(1)->GetInt()];
			}
			else if(!strcmp(ss.GetWord(0)->GetString(),"MMPXY"))
			{
				/* pixel position */
				index=atoi(ss.GetWord(1)->GetString())-1;
				m_coords[index].x=atoi(ss.GetWord(2)->GetString());
				m_coords[index].y=atoi(ss.GetWord(3)->GetString());
			}
			else if(!strcmp(ss.GetWord(0)->GetString(),"MMPLL"))
			{
				/* latitude/longitude position */
				index=atoi(ss.GetWord(1)->GetString())-1;
				m_coords[index].lon=atof(ss.GetWord(2)->GetString());
				m_coords[index].lat=atof(ss.GetWord(3)->GetString());
			}
		}
		++linenum;
	}while(dh.Eof()==false);
	dh.Close();

	/* calculate bounding rectanle for lat/lon */
	m_minlat=m_coords[0].lat;
	maxlat=m_coords[0].lat;
	m_minlon=m_coords[0].lon;
	maxlon=m_coords[0].lon;
	m_minx=m_coords[0].x;
	maxx=m_coords[0].x;
	m_miny=m_coords[0].y;
	maxy=m_coords[0].y;
	for(index=1;index<4;++index)
	{
		if(m_coords[index].lat<m_minlat)
		{
			m_minlat=m_coords[index].lat;
			m_miny=m_coords[index].y;
		}
		if(m_coords[index].lat>maxlat)
		{
			maxlat=m_coords[index].lat;
			maxy=m_coords[index].y;
		}

		if(m_coords[index].lon<m_minlon)
		{
			m_minlon=m_coords[index].lon;
			m_minx=m_coords[index].x;
		}
		if(m_coords[index].lon>maxlon)
		{
			maxlon=m_coords[index].lon;
			maxx=m_coords[index].x;
		}
	}

	/* assume linear for now until I figure out the projection */
	m_slx=(maxlon-m_minlon)/(maxx-m_minx);
	m_sly=(maxlat-m_minlat)/(maxy-m_miny);
	m_lsx=(maxx-m_minx)/(maxlon-m_minlon);
	m_lsy=(maxy-m_miny)/(maxlat-m_minlat);

	for(index=0;index<4;++index)
	{
		GPXCoord c;
		int sx,sy;

		c.Set(m_coords[index].lat,m_coords[index].lon);
		ToMap(&c,&sx,&sy);
		DebugPrint("Coord testing %f,%f %d,%d - %d,%d",m_coords[index].lat,m_coords[index].lon,m_coords[index].x,m_coords[index].y,sx,sy);
	}

	/* load the map file with the tiles */
	fp=kGUI::LoadFile(ozfn.GetString(),&filesize);
	if(!fp)
		return;	/* couldn't load file */

	m_filedata=fp;	/* save pointer to data so destructor will free it up upon exiting */
	oh=(OZ2FHEADER_DEF *)fp;
	
	if(oh->wSignature!=0x7778)
		return;	/* not valid format */

	assert ((oh->wPlanes==1) && (oh->wBitsPerPixel==8),"Unsupported bitmap format" );

	SetTileSize(64,64);

	/* parse the tile data */

	const int dwMasterTblOffset = * reinterpret_cast<const int *> (fp + filesize - 4);
	const int * const pdwMasterTbl = reinterpret_cast<const int *> (fp + dwMasterTblOffset);

	const int zoomlevels = (filesize - 4 - dwMasterTblOffset)/4;
	SetZoomLevels(1,zoomlevels);
	m_bitmaps.Alloc(zoomlevels);
	z=zoomlevels-1;
	for (int zoomlevel = 0; zoomlevel < zoomlevels; ++ zoomlevel)
	{
		OZ2FBITMAP_DEF *ih = (OZ2FBITMAP_DEF *) (fp + pdwMasterTbl [zoomlevel]);

		m_bitmaps.SetEntry(z,ih);
		SetSize(z,ih->dwImageWidth,ih->dwImageHeight);
		--z;
	}
}
Esempio n. 2
0
// ----------------------------------------------------------------
//	SampleData
// ----------------------------------------------------------------
void CMapInfo::SampleData()
{
	const UINT COLUMN = 24;
	const UINT ROW = 16;

	m_MapId = L"map_village";

	SetTileSize( 128, 128 );

	AddTile( L"map_village_0000_1.png" );	// 0
	AddTile( L"map_village_0000_2.png" );
	AddTile( L"map_village_0000_3.png" );
	AddTile( L"map_village_0000_4.png" );

	AddTile( L"map_village_0001_1.png" );	// 4
	AddTile( L"map_village_0001_2.png" );
	AddTile( L"map_village_0001_3.png" );
	AddTile( L"map_village_0001_4.png" );

	AddTile( L"map_village_0010_1.png" );	// 8
	AddTile( L"map_village_0010_2.png" );
	AddTile( L"map_village_0010_3.png" );
	AddTile( L"map_village_0010_4.png" );

	AddTile( L"map_village_0011_1.png" );	// 12
	AddTile( L"map_village_0011_2.png" );
	AddTile( L"map_village_0011_3.png" );
	AddTile( L"map_village_0011_4.png" );

	AddTile( L"map_village_0100_1.png" );	// 16
	AddTile( L"map_village_0100_2.png" );
	AddTile( L"map_village_0100_3.png" );
	AddTile( L"map_village_0100_4.png" );

	AddTile( L"map_village_0101_1.png" );	// 20
	AddTile( L"map_village_0101_2.png" );
	AddTile( L"map_village_0101_3.png" );
	AddTile( L"map_village_0101_4.png" );

	AddTile( L"map_village_0111_1.png" );	// 24
	AddTile( L"map_village_0111_2.png" );
	AddTile( L"map_village_0111_3.png" );
	AddTile( L"map_village_0111_4.png" );

	AddTile( L"map_village_1000_1.png" );	// 28
	AddTile( L"map_village_1000_2.png" );
	AddTile( L"map_village_1000_3.png" );
	AddTile( L"map_village_1000_4.png" );

	AddTile( L"map_village_1010_1.png" );	// 32
	AddTile( L"map_village_1010_2.png" );
	AddTile( L"map_village_1010_3.png" );
	AddTile( L"map_village_1010_4.png" );

	AddTile( L"map_village_1011_1.png" );	// 36
	AddTile( L"map_village_1011_2.png" );
	AddTile( L"map_village_1011_3.png" );
	AddTile( L"map_village_1011_4.png" );

	AddTile( L"map_village_1100_1.png" );	// 40
	AddTile( L"map_village_1100_2.png" );
	AddTile( L"map_village_1100_3.png" );
	AddTile( L"map_village_1100_4.png" );

	AddTile( L"map_village_1101_1.png" );	// 44
	AddTile( L"map_village_1101_2.png" );
	AddTile( L"map_village_1101_3.png" );
	AddTile( L"map_village_1101_4.png" );

	AddTile( L"map_village_1110_1.png" );	// 48
	AddTile( L"map_village_1110_2.png" );
	AddTile( L"map_village_1110_3.png" );
	AddTile( L"map_village_1110_4.png" );

	AddTile( L"map_village_1111_1.png" );	// 52
	AddTile( L"map_village_1111_2.png" );
	AddTile( L"map_village_1111_3.png" );
	AddTile( L"map_village_1111_4.png" );

	AddTile( L"map_tree_0011.png" );	// 56
	AddTile( L"map_tree_0101.png" );	// 57
	AddTile( L"map_tree_0111.png" );	// 58
	AddTile( L"map_tree_1010.png" );	// 59
	AddTile( L"map_tree_1011.png" );	// 60
	AddTile( L"map_tree_1100.png" );	// 61
	AddTile( L"map_tree_1101.png" );	// 62
	AddTile( L"map_tree_1110.png" );	// 63
	AddTile( L"map_tree_1111.png" );	// 64

	CreateMapData( COLUMN, ROW );

	UINT fildTileNo[ROW][COLUMN] = {
		{ 0, 0, 0, 0, 25, 37, 11, 16, 40, 28, 7, 24, 39, 12, 14, 15, 25, 33, 16, 42, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 53, 49, 28, 7, 10, 2, 22, 55, 48, 42, 42, 42, 47, 32, 7, 15, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 48, 28, 1, 23, 32, 0, 21, 50, 28, 0, 7, 8, 18, 30, 23, 55, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 38, 15, 9, 17, 28, 1, 21, 34, 0, 0, 21, 37, 10, 2, 19, 47, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 51, 41, 29, 2, 6, 15, 26, 34, 6, 11, 21, 49, 29, 1, 3, 21, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 38, 12, 14, 10, 22, 51, 43, 28, 16, 31, 18, 31, 6, 15, 9, 20, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 42, 41, 46, 35, 21, 33, 1, 2, 1, 0, 0, 5, 26, 48, 31, 19, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 4, 9, 22, 39, 24, 35, 5, 9, 0, 1, 3, 17, 45, 33, 5, 9, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 19, 28, 17, 43, 42, 28, 20, 32, 0, 5, 13, 12, 24, 36, 25, 39, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 8, 5, 10, 7, 8, 3, 22, 39, 9, 23, 51, 41, 46, 55, 53, 52, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 33, 23, 37, 26, 39, 8, 19, 43, 28, 16, 29, 0, 17, 46, 53, 55, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 39, 24, 48, 46, 50, 31, 1, 5, 13, 14, 12, 15, 12, 27, 54, 50, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 43, 42, 31, 17, 28, 4, 14, 25, 48, 46, 50, 44, 54, 51, 43, 30, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 9, 3, 3, 0, 1, 19, 41, 43, 30, 18, 31, 18, 42, 30, 3, 4, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 28, 1, 1, 3, 5, 15, 14, 14, 10, 5, 11, 2, 2, 5, 15, 27, 0, 0, 0, 0 },
		{ 0, 0, 0, 0, 11, 7, 15, 12, 27, 51, 42, 42, 31, 17, 31, 0, 4, 26, 51, 43, 0, 0, 0, 0 }
	};

	UINT treeTileNo[ROW][COLUMN] = {
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 63, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 60, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 58, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 },
		{ 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }
	};

	UINT fildMovement[ROW][COLUMN] = {
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF,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xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF },
		{ 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF, 0xF }
	};

	for ( UINT row = 0; row < ROW; ++row )
	{
		for ( UINT col = 0; col < COLUMN; ++col )
		{
			m_Maps[0]->m_Tiles[row * COLUMN + col].m_TileNo		= fildTileNo[row][col] + treeTileNo[row][col] * 128;
			m_Maps[0]->m_Tiles[row * COLUMN + col].m_Movement	= fildMovement[row][col];
		}
	}

	for ( UINT row = 0; row < ROW; ++row )
	{
		printf( "{" );
		for ( UINT col = 0; col < COLUMN; ++col )
		{
			if ( col != 0 )
				printf(",");

			printf( " %d", m_Maps[0]->m_Tiles[row * COLUMN + col].m_TileNo );
		}
		printf( " },\n" );
	}

}