00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <memory>
00030
00031 #include "typen.h"
00032 #include "loaders.h"
00033 #include "loadpcx.h"
00034 #include "loadbi3.h"
00035 #include "errors.h"
00036 #include "gameoptions.h"
00037 #include "mapdisplay.h"
00038 #include "dialog.h"
00039 #include "strtmesg.h"
00040 #include "itemrepository.h"
00041 #include "memorycheck.cpp"
00042 #include "graphicset.h"
00043
00044
00045 void loadcursor(void)
00046 {
00047 int w,i;
00048
00049 {
00050 tnfilestream stream ("hexfeld.raw", tnstream::reading);
00051 stream.readrlepict ( &icons.fieldshape, false, &w );
00052 }
00053
00054 {
00055 tnfilestream stream ("mapbkgrb.raw", tnstream::reading);
00056 stream.readrlepict ( &icons.mapbackground, false, &w );
00057 }
00058
00059 {
00060 tnfilestream stream ("hexfld_a.raw",tnstream::reading);
00061 stream.readrlepict( &icons.stellplatz, false, &w);
00062 }
00063
00064 {
00065 tnfilestream stream ("x.raw", tnstream::reading);
00066 stream.readrlepict( &icons.X, false, &w);
00067 }
00068
00069 {
00070 tnfilestream stream ("pfeil-a0.raw", tnstream::reading);
00071 for (i=0;i<8 ;i++ ) stream.readrlepict( &icons.pfeil2[i], false, &w);
00072 }
00073
00074 loadpalette();
00075 for (w=0;w<256 ;w++ ) {
00076 palette16[w][0] = pal[w][0];
00077 palette16[w][1] = pal[w][1];
00078 palette16[w][2] = pal[w][2];
00079 xlattables.nochange[w] = w;
00080 }
00081
00082 loadicons();
00083 loadmessages();
00084
00085 }
00086
00087
00088
00089
00090
00091 void loaddata( void )
00092 {
00093 loadcursor();
00094
00095 loadalltextfiles();
00096
00097 loadallobjecttypes();
00098
00099 loadallvehicletypes();
00100
00101 loadallbuildingtypes();
00102
00103 loadalltechnologies();
00104
00105 loadstreets();
00106
00107 loadallterraintypes();
00108
00109 readBI3translationTable();
00110
00111 loadUnitSets();
00112 }
00113
00114
00115 typedef vector<string> FilesToLoad;
00116 FilesToLoad filesToLoad;
00117
00118
00119 pfont load_font(char* name)
00120 {
00121 tnfilestream stream ( name, tnstream::reading );
00122 return loadfont ( &stream );
00123 }
00124
00125 string outputDir;
00126
00127
00128 void process_BI_map ( const ASCString& filename )
00129 {
00130 string fn;
00131 if ( filename.find ( "mis/" ) == filename.npos )
00132 fn = "mis/"+filename;
00133 else
00134 fn = filename;
00135
00136 tfindfile ff ( fn );
00137 string s = ff.getnextname();
00138 while ( !s.empty () ) {
00139 string errormsg;
00140 importbattleislemap ( outputDir.c_str(), s.c_str(), terrainTypeRepository.getObject_byPos(0)->weather[0], &errormsg, true );
00141 if ( !errormsg.empty() && 0 )
00142 fprintf(stderr, "map %s : %s \n", s.c_str(), errormsg.c_str() );
00143 string fn = outputDir+"images/pcx/"+s;
00144 fn.replace ( fn.find (".dat"), 4, ".pcx");
00145
00146 int width, height;
00147
00148 string t = outputDir+"mis/"+s;
00149 int maptime = get_filetime ( t.c_str());
00150 int pcxtime = get_filetime ( fn.c_str() );
00151 if ( maptime > pcxtime || pcxtime < 0 )
00152 writemaptopcx ( false, fn, &width, &height );
00153 else {
00154 tdisplaywholemap wm ( fn );
00155 wm.init ( actmap->xsize, actmap->ysize );
00156 width = wm.getWidth();
00157 height = wm.getHeight();
00158 }
00159
00160 int playernum = 0;
00161 int ainum = 0;
00162 for ( int i = 0; i < 8; i++ )
00163 if ( actmap->player[i].exist() ) {
00164 if ( actmap->player[i].stat == 0 )
00165 playernum++;
00166 if ( actmap->player[i].stat == 1 )
00167 ainum++;
00168 }
00169
00170
00171 printf("%sµ%sµ%dµ%dµ%dµ%dµ%dµ%d\n", s.c_str(), actmap->maptitle.c_str(), actmap->xsize*2, actmap->ysize/2, width, height, playernum, ainum );
00172
00173 s = ff.getnextname();
00174
00175 delete actmap;
00176 actmap = NULL;
00177 }
00178 }
00179
00180
00181 void process_ASC_map ( const ASCString& filename )
00182 {
00183 string fn;
00184 if ( filename.find ( "mis/" ) == filename.npos )
00185 fn = "mis/"+filename;
00186 else
00187 fn = filename;
00188
00189 tfindfile ff ( fn );
00190 string s = ff.getnextname();
00191 while ( !s.empty () ) {
00192 try {
00193 tmaploaders gl;
00194 gl.loadmap ( s.c_str() );
00195 }
00196 catch ( ASCexception ) {
00197 fprintf(stderr, "skipping map %s \n", s.c_str() );
00198 s = ff.getnextname();
00199 continue;
00200 }
00201
00202 activateGraphicSet ( actmap->graphicset );
00203 string fn = outputDir+"images/pcx/"+s;
00204 fn.replace ( fn.find (".map"), 4, ".pcx");
00205
00206 int width, height;
00207
00208 string t = outputDir+"mis/"+s;
00209 int maptime = get_filetime ( t.c_str());
00210 int pcxtime = get_filetime ( fn.c_str() );
00211 if ( maptime > pcxtime || pcxtime < 0 )
00212 writemaptopcx ( false, fn, &width, &height );
00213 else {
00214 tdisplaywholemap wm ( fn );
00215 wm.init ( actmap->xsize, actmap->ysize );
00216 width = wm.getWidth();
00217 height = wm.getHeight();
00218 }
00219
00220 int playernum = 0;
00221 int ainum = 0;
00222 for ( int i = 0; i < 8; i++ )
00223 if ( actmap->player[i].exist() ) {
00224 if ( actmap->player[i].stat == 0 )
00225 playernum++;
00226 if ( actmap->player[i].stat == 1 )
00227 ainum++;
00228 }
00229
00230 char datebuf[1000];
00231 tm* tmbuf = gmtime ( &actmap->archivalInformation.modifytime );
00232 strftime ( datebuf, 1000, "%Y-%m-%d", tmbuf );
00233
00234 printf("%sµ%sµ%dµ%dµ%dµ%dµ%dµ%dµ%sµ%sµ%sµ%sµ%dµ%s\n", s.c_str(), actmap->maptitle.c_str(), actmap->xsize, actmap->ysize, width, height, playernum, ainum, actmap->archivalInformation.author.c_str(), actmap->archivalInformation.description.c_str(),actmap->archivalInformation.requirements.c_str(),actmap->archivalInformation.tags.c_str(),actmap->_resourcemode,datebuf);
00235
00236 s = ff.getnextname();
00237
00238 delete actmap;
00239 actmap = NULL;
00240 }
00241 }
00242
00243
00244
00245 int mapeditorMainThread ( void* _mapname )
00246 {
00247 tvirtualdisplay buf ( 800, 600 );
00248 initMapDisplay( );
00249
00250 cursor.init();
00251
00252 try {
00253 loaddata();
00254
00255 for ( FilesToLoad::iterator i = filesToLoad.begin(); i != filesToLoad.end(); i++ )
00256 if ( patimat ( "*.dat", i->c_str() ))
00257 process_BI_map( *i );
00258 else
00259 process_ASC_map ( *i );
00260
00261 }
00262 catch ( tfileerror err ) {
00263 displaymessage ( " error loading file %s ",2,err.getFileName().c_str() );
00264 }
00265
00266 return 0;
00267 }
00268
00269
00270
00271 #include "clparser/map2pcx.cpp"
00272
00273 int main(int argc, char *argv[] )
00274 {
00275 Cmdline* cl = NULL;
00276 auto_ptr<Cmdline> apcl ( cl );
00277 try {
00278 cl = new Cmdline ( argc, argv );
00279 }
00280 catch ( string s ) {
00281 cerr << s.c_str();
00282 exit(1);
00283 }
00284
00285 verbosity = cl->r();
00286
00287 if ( cl->v() ) {
00288 cout << argv[0] << " " << getVersionString() << endl;
00289 exit(0);
00290 }
00291
00292 outputDir = cl->d();
00293
00294 for ( int i = cl->next_param(); i < argc; i++ )
00295 filesToLoad.push_back ( argv[i] );
00296
00297
00298 if ( filesToLoad.empty() ) {
00299 cerr << "no maps to load!\n";
00300 return 1;
00301 }
00302
00303 addSearchPath ( "./") ;
00304 initFileIO( cl->c().c_str() );
00305
00306 check_bi3_dir ();
00307
00308 setDefaultBI3ImportTranslationTable ("bi-bi.asctxt");
00309
00310 schriften.smallarial = load_font("smalaril.FNT");
00311 schriften.large = load_font("USABLACK.FNT");
00312 schriften.arial8 = load_font("ARIAL8.FNT");
00313 schriften.smallsystem = load_font("msystem.fnt");
00314 schriften.monogui = load_font("monogui.fnt");
00315
00316 virtualscreenbuf.init();
00317
00318 initializeEventHandling ( mapeditorMainThread, NULL );
00319
00320 return 0;
00321 }
00322