Pol  Revision:b38175a
poltool/poltool.cpp
Go to the documentation of this file.
00001 /*
00002 History
00003 =======
00004 
00005 Notes
00006 =======
00007 
00008 */
00009 
00010 #include "../clib/strutil.h"
00011 #include "../clib/logfacility.h"
00012 
00013 #include "../plib/mapcell.h"
00014 #include "../plib/mapserver.h"
00015 #include "../plib/filemapserver.h"
00016 #include "../plib/mapshape.h"
00017 #include "../plib/realmdescriptor.h"
00018 
00019 #include "../plib/maptile.h"
00020 #include "../plib/maptileserver.h"
00021 
00022 #include "../pol/realms/realm.h"
00023 
00024 #include <string>
00025 #include <fstream>
00026 
00027 namespace Pol {
00028   namespace Plib {
00029     void pol_walk_test();
00030     std::string flagstr( unsigned int flags );
00031     std::string flagdescs();
00032   }
00033   namespace Poltool {
00034 
00035     void usage()
00036     {
00037       ERROR_PRINT << "Usage: poltool [cmd] [options]\n"
00038         << "\t  mapdump x1 y1 [x2 y2 realm]       writes polmap info to polmap.html\n";
00039     }
00040 
00041     int mapdump( int argc, char* argv[] )
00042     {
00043       short wxl = 5485, wxh = 5500, wyl = 0, wyh = 30;
00044 
00045       char* realmname = (char*)"britannia";
00046       if ( argc >= 6 )
00047       {
00048         realmname = argv[5];
00049       }
00050       Plib::RealmDescriptor descriptor = Plib::RealmDescriptor::Load( realmname );
00051       Plib::MapServer* mapserver = Plib::MapServer::Create( descriptor );
00052       std::unique_ptr<Plib::MapServer> _owner( mapserver );
00053 
00054       std::unique_ptr<Plib::MapTileServer> mts( new Plib::MapTileServer( descriptor ) );
00055       if ( argc >= 3 )
00056       {
00057         wxl = wxh = static_cast<short>( atoi( argv[1] ) );
00058         wyl = wyh = static_cast<short>( atoi( argv[2] ) );
00059       }
00060       if ( argc >= 5 )
00061       {
00062         wxh = static_cast<short>( atoi( argv[3] ) );
00063         wyh = static_cast<short>( atoi( argv[4] ) );
00064       }
00065 
00066       std::ofstream ofs("polmap.html");
00067 
00068       ofs << Plib::flagdescs() << std::endl;
00069       ofs << "<table border=1 cellpadding=5 cellspacing=0>" << std::endl;
00070       ofs << "<tr><td>&nbsp;</td>";
00071       for ( int x = wxl; x <= wxh; ++x )
00072       {
00073         ofs << "<td align=center>" << x << "</td>";
00074       }
00075       ofs << "</tr>" << std::endl;
00076       for ( unsigned short y = wyl; y <= wyh; ++y )
00077       {
00078           ofs << "<tr><td valign=center>" << y << "</td>" << std::endl;
00079         for ( unsigned short x = wxl; x <= wxh; ++x )
00080         {
00081           ofs << "<td align=left valign=top>";
00082 
00083           Plib::MAPCELL cell = mapserver->GetMapCell( x, y );
00084           Plib::MapShapeList mlist;
00085           mapserver->GetMapShapes( mlist, x, y, static_cast<u32>(Plib::FLAG::ALL) );
00086           Plib::MAPTILE_CELL tile = mts->GetMapTile( x, y );
00087 
00088           ofs << "landtile=" << int( tile.landtile ) << "<br>";
00089           ofs << "tilez=" << int( tile.z ) << "<br>";
00090           ofs << "z=" << int( cell.z ) << "<br>";
00091           ofs << "flags=" << Plib::flagstr( cell.flags );
00092 
00093           for ( unsigned i = 1; i < mlist.size(); ++i )
00094           {
00095             ofs << "<br>"
00096               << "solid.z=" << int( mlist[i].z ) << "<br>"
00097               << "solid.height=" << int( mlist[i].height ) << "<br>"
00098               << "solid.flags=" << Plib::flagstr( mlist[i].flags );
00099           }
00100 
00101           ofs << "</td>" << std::endl;
00102         }
00103         ofs << "</tr>" << std::endl;
00104       }
00105       ofs << "</table>" << std::endl;
00106       return 0;
00107     }
00108   }
00109 
00110   int xmain( int argc, char* argv[] )
00111   {
00112     if ( argc == 1 )
00113     {
00114       Poltool::usage();
00115       return 1;
00116     }
00117 
00118     std::string cmd = argv[1];
00119     if ( cmd == "mapdump" )
00120     {
00121       return Poltool::mapdump( argc - 1, argv + 1 );
00122     }
00123     else
00124     {
00125       ERROR_PRINT << "Unknown command " << cmd << "\n";
00126       return 1;
00127     }
00128   }
00129 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines