]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - tools/quake3/q3map2/main.c
Merge pull request #6 from bnoordhuis/cleanup
[xonotic/netradiant.git] / tools / quake3 / q3map2 / main.c
1 /* -------------------------------------------------------------------------------
2
3    Copyright (C) 1999-2007 id Software, Inc. and contributors.
4    For a list of contributors, see the accompanying CONTRIBUTORS file.
5
6    This file is part of GtkRadiant.
7
8    GtkRadiant is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    GtkRadiant is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with GtkRadiant; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21
22    -------------------------------------------------------------------------------
23
24    This code has been altered significantly from its original form, to support
25    several games based on the Quake III Arena engine, in the form of "Q3Map2."
26
27    ------------------------------------------------------------------------------- */
28
29
30
31 /* marker */
32 #define MAIN_C
33
34
35
36 /* dependencies */
37 #include "q3map2.h"
38
39 /*
40    Random()
41    returns a pseudorandom number between 0 and 1
42  */
43
44 vec_t Random( void ){
45         return (vec_t) rand() / RAND_MAX;
46 }
47
48
49 char *Q_strncpyz( char *dst, const char *src, size_t len ) {
50         if ( len == 0 ) {
51                 abort();
52         }
53
54         strncpy( dst, src, len );
55         dst[ len - 1 ] = '\0';
56         return dst;
57 }
58
59
60 char *Q_strcat( char *dst, size_t dlen, const char *src ) {
61         size_t n = strlen( dst  );
62
63         if ( n > dlen ) {
64                 abort(); /* buffer overflow */
65         }
66
67         return Q_strncpyz( dst + n, src, dlen - n );
68 }
69
70
71 char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
72         size_t n = strlen( dst );
73
74         if ( n > dlen ) {
75                 abort(); /* buffer overflow */
76         }
77
78         return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
79 }
80
81
82 /*
83    ExitQ3Map()
84    cleanup routine
85  */
86
87 static void ExitQ3Map( void ){
88         BSPFilesCleanup();
89         if ( mapDrawSurfs != NULL ) {
90                 free( mapDrawSurfs );
91         }
92 }
93
94 static int MD4BlockChecksum( void * buffer, int length ) {
95         unsigned char digest[16];
96         int checksum;
97
98         md4_get_digest( buffer, length, digest );
99         /* I suppose it has to be done that way for legacy reasons? */
100         checksum = digest[0] & ( digest[1] << 8 ) & ( digest[2] << 16 ) & ( digest[3] << 24 );
101         checksum ^= digest[4] & ( digest[5] << 8 ) & ( digest[6] << 16 ) & ( digest[7] << 24 );
102         checksum ^= digest[8] & ( digest[9] << 8 ) & ( digest[10] << 16 ) & ( digest[11] << 24 );
103         checksum ^= digest[12] & ( digest[13] << 8 ) & ( digest[14] << 16 ) & ( digest[15] << 24 );
104         return checksum;
105 }
106
107 /*
108    FixAAS()
109    resets an aas checksum to match the given BSP
110  */
111
112 int FixAAS( int argc, char **argv ){
113         int length, checksum;
114         void        *buffer;
115         FILE        *file;
116         char aas[ 1024 ], **ext;
117         char        *exts[] =
118         {
119                 ".aas",
120                 "_b0.aas",
121                 "_b1.aas",
122                 NULL
123         };
124
125
126         /* arg checking */
127         if ( argc < 2 ) {
128                 Sys_Printf( "Usage: q3map -fixaas [-v] <mapname>\n" );
129                 return 0;
130         }
131
132         /* do some path mangling */
133         strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
134         StripExtension( source );
135         DefaultExtension( source, ".bsp" );
136
137         /* note it */
138         Sys_Printf( "--- FixAAS ---\n" );
139
140         /* load the bsp */
141         Sys_Printf( "Loading %s\n", source );
142         length = LoadFile( source, &buffer );
143
144         /* create bsp checksum */
145         Sys_Printf( "Creating checksum...\n" );
146         checksum = LittleLong( MD4BlockChecksum( buffer, length ) );
147
148         /* write checksum to aas */
149         ext = exts;
150         while ( *ext )
151         {
152                 /* mangle name */
153                 strcpy( aas, source );
154                 StripExtension( aas );
155                 strcat( aas, *ext );
156                 Sys_Printf( "Trying %s\n", aas );
157                 ext++;
158
159                 /* fix it */
160                 file = fopen( aas, "r+b" );
161                 if ( !file ) {
162                         continue;
163                 }
164                 if ( fwrite( &checksum, 4, 1, file ) != 1 ) {
165                         Error( "Error writing checksum to %s", aas );
166                 }
167                 fclose( file );
168         }
169
170         /* return to sender */
171         return 0;
172 }
173
174
175
176 /*
177    AnalyzeBSP() - ydnar
178    analyzes a Quake engine BSP file
179  */
180
181 typedef struct abspHeader_s
182 {
183         char ident[ 4 ];
184         int version;
185
186         bspLump_t lumps[ 1 ];       /* unknown size */
187 }
188 abspHeader_t;
189
190 typedef struct abspLumpTest_s
191 {
192         int radix, minCount;
193         char            *name;
194 }
195 abspLumpTest_t;
196
197 int AnalyzeBSP( int argc, char **argv ){
198         abspHeader_t            *header;
199         int size, i, version, offset, length, lumpInt, count;
200         char ident[ 5 ];
201         void                    *lump;
202         float lumpFloat;
203         char lumpString[ 1024 ], source[ 1024 ];
204         qboolean lumpSwap = qfalse;
205         abspLumpTest_t          *lumpTest;
206         static abspLumpTest_t lumpTests[] =
207         {
208                 { sizeof( bspPlane_t ),         6,      "IBSP LUMP_PLANES" },
209                 { sizeof( bspBrush_t ),         1,      "IBSP LUMP_BRUSHES" },
210                 { 8,                            6,      "IBSP LUMP_BRUSHSIDES" },
211                 { sizeof( bspBrushSide_t ),     6,      "RBSP LUMP_BRUSHSIDES" },
212                 { sizeof( bspModel_t ),         1,      "IBSP LUMP_MODELS" },
213                 { sizeof( bspNode_t ),          2,      "IBSP LUMP_NODES" },
214                 { sizeof( bspLeaf_t ),          1,      "IBSP LUMP_LEAFS" },
215                 { 104,                          3,      "IBSP LUMP_DRAWSURFS" },
216                 { 44,                           3,      "IBSP LUMP_DRAWVERTS" },
217                 { 4,                            6,      "IBSP LUMP_DRAWINDEXES" },
218                 { 128 * 128 * 3,                1,      "IBSP LUMP_LIGHTMAPS" },
219                 { 256 * 256 * 3,                1,      "IBSP LUMP_LIGHTMAPS (256 x 256)" },
220                 { 512 * 512 * 3,                1,      "IBSP LUMP_LIGHTMAPS (512 x 512)" },
221                 { 0, 0, NULL }
222         };
223
224
225         /* arg checking */
226         if ( argc < 1 ) {
227                 Sys_Printf( "Usage: q3map -analyze [-lumpswap] [-v] <mapname>\n" );
228                 return 0;
229         }
230
231         /* process arguments */
232         for ( i = 1; i < ( argc - 1 ); i++ )
233         {
234                 /* -format map|ase|... */
235                 if ( !strcmp( argv[ i ],  "-lumpswap" ) ) {
236                         Sys_Printf( "Swapped lump structs enabled\n" );
237                         lumpSwap = qtrue;
238                 }
239         }
240
241         /* clean up map name */
242         strcpy( source, ExpandArg( argv[ i ] ) );
243         Sys_Printf( "Loading %s\n", source );
244
245         /* load the file */
246         size = LoadFile( source, (void**) &header );
247         if ( size == 0 || header == NULL ) {
248                 Sys_Printf( "Unable to load %s.\n", source );
249                 return -1;
250         }
251
252         /* analyze ident/version */
253         memcpy( ident, header->ident, 4 );
254         ident[ 4 ] = '\0';
255         version = LittleLong( header->version );
256
257         Sys_Printf( "Identity:      %s\n", ident );
258         Sys_Printf( "Version:       %d\n", version );
259         Sys_Printf( "---------------------------------------\n" );
260
261         /* analyze each lump */
262         for ( i = 0; i < 100; i++ )
263         {
264                 /* call of duty swapped lump pairs */
265                 if ( lumpSwap ) {
266                         offset = LittleLong( header->lumps[ i ].length );
267                         length = LittleLong( header->lumps[ i ].offset );
268                 }
269
270                 /* standard lump pairs */
271                 else
272                 {
273                         offset = LittleLong( header->lumps[ i ].offset );
274                         length = LittleLong( header->lumps[ i ].length );
275                 }
276
277                 /* extract data */
278                 lump = (byte*) header + offset;
279                 lumpInt = LittleLong( (int) *( (int*) lump ) );
280                 lumpFloat = LittleFloat( (float) *( (float*) lump ) );
281                 memcpy( lumpString, (char*) lump, ( length < 1024 ? length : 1024 ) );
282                 lumpString[ 1024 ] = '\0';
283
284                 /* print basic lump info */
285                 Sys_Printf( "Lump:          %d\n", i );
286                 Sys_Printf( "Offset:        %d bytes\n", offset );
287                 Sys_Printf( "Length:        %d bytes\n", length );
288
289                 /* only operate on valid lumps */
290                 if ( length > 0 ) {
291                         /* print data in 4 formats */
292                         Sys_Printf( "As hex:        %08X\n", lumpInt );
293                         Sys_Printf( "As int:        %d\n", lumpInt );
294                         Sys_Printf( "As float:      %f\n", lumpFloat );
295                         Sys_Printf( "As string:     %s\n", lumpString );
296
297                         /* guess lump type */
298                         if ( lumpString[ 0 ] == '{' && lumpString[ 2 ] == '"' ) {
299                                 Sys_Printf( "Type guess:    IBSP LUMP_ENTITIES\n" );
300                         }
301                         else if ( strstr( lumpString, "textures/" ) ) {
302                                 Sys_Printf( "Type guess:    IBSP LUMP_SHADERS\n" );
303                         }
304                         else
305                         {
306                                 /* guess based on size/count */
307                                 for ( lumpTest = lumpTests; lumpTest->radix > 0; lumpTest++ )
308                                 {
309                                         if ( ( length % lumpTest->radix ) != 0 ) {
310                                                 continue;
311                                         }
312                                         count = length / lumpTest->radix;
313                                         if ( count < lumpTest->minCount ) {
314                                                 continue;
315                                         }
316                                         Sys_Printf( "Type guess:    %s (%d x %d)\n", lumpTest->name, count, lumpTest->radix );
317                                 }
318                         }
319                 }
320
321                 Sys_Printf( "---------------------------------------\n" );
322
323                 /* end of file */
324                 if ( offset + length >= size ) {
325                         break;
326                 }
327         }
328
329         /* last stats */
330         Sys_Printf( "Lump count:    %d\n", i + 1 );
331         Sys_Printf( "File size:     %d bytes\n", size );
332
333         /* return to caller */
334         return 0;
335 }
336
337
338
339 /*
340    BSPInfo()
341    emits statistics about the bsp file
342  */
343
344 int BSPInfo( int count, char **fileNames ){
345         int i;
346         char source[ 1024 ], ext[ 64 ];
347         int size;
348         FILE        *f;
349
350
351         /* dummy check */
352         if ( count < 1 ) {
353                 Sys_Printf( "No files to dump info for.\n" );
354                 return -1;
355         }
356
357         /* enable info mode */
358         infoMode = qtrue;
359
360         /* walk file list */
361         for ( i = 0; i < count; i++ )
362         {
363                 Sys_Printf( "---------------------------------\n" );
364
365                 /* mangle filename and get size */
366                 strcpy( source, fileNames[ i ] );
367                 ExtractFileExtension( source, ext );
368                 if ( !Q_stricmp( ext, "map" ) ) {
369                         StripExtension( source );
370                 }
371                 DefaultExtension( source, ".bsp" );
372                 f = fopen( source, "rb" );
373                 if ( f ) {
374                         size = Q_filelength( f );
375                         fclose( f );
376                 }
377                 else{
378                         size = 0;
379                 }
380
381                 /* load the bsp file and print lump sizes */
382                 Sys_Printf( "%s\n", source );
383                 LoadBSPFile( source );
384                 PrintBSPFileSizes();
385
386                 /* print sizes */
387                 Sys_Printf( "\n" );
388                 Sys_Printf( "          total         %9d\n", size );
389                 Sys_Printf( "                        %9d KB\n", size / 1024 );
390                 Sys_Printf( "                        %9d MB\n", size / ( 1024 * 1024 ) );
391
392                 Sys_Printf( "---------------------------------\n" );
393         }
394
395         /* return count */
396         return i;
397 }
398
399
400
401 /*
402    ScaleBSPMain()
403    amaze and confuse your enemies with wierd scaled maps!
404  */
405
406 int ScaleBSPMain( int argc, char **argv ){
407         int i;
408         float f, scale;
409         vec3_t vec;
410         char str[ 1024 ];
411
412
413         /* arg checking */
414         if ( argc < 2 ) {
415                 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
416                 return 0;
417         }
418
419         /* get scale */
420         scale = atof( argv[ argc - 2 ] );
421         if ( scale == 0.0f ) {
422                 Sys_Printf( "Usage: q3map -scale <value> [-v] <mapname>\n" );
423                 Sys_Printf( "Non-zero scale value required.\n" );
424                 return 0;
425         }
426
427         /* do some path mangling */
428         strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
429         StripExtension( source );
430         DefaultExtension( source, ".bsp" );
431
432         /* load the bsp */
433         Sys_Printf( "Loading %s\n", source );
434         LoadBSPFile( source );
435         ParseEntities();
436
437         /* note it */
438         Sys_Printf( "--- ScaleBSP ---\n" );
439         Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
440
441         /* scale entity keys */
442         for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
443         {
444                 /* scale origin */
445                 GetVectorForKey( &entities[ i ], "origin", vec );
446                 if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) ) {
447                         VectorScale( vec, scale, vec );
448                         sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
449                         SetKeyValue( &entities[ i ], "origin", str );
450                 }
451
452                 /* scale door lip */
453                 f = FloatForKey( &entities[ i ], "lip" );
454                 if ( f ) {
455                         f *= scale;
456                         sprintf( str, "%f", f );
457                         SetKeyValue( &entities[ i ], "lip", str );
458                 }
459         }
460
461         /* scale models */
462         for ( i = 0; i < numBSPModels; i++ )
463         {
464                 VectorScale( bspModels[ i ].mins, scale, bspModels[ i ].mins );
465                 VectorScale( bspModels[ i ].maxs, scale, bspModels[ i ].maxs );
466         }
467
468         /* scale nodes */
469         for ( i = 0; i < numBSPNodes; i++ )
470         {
471                 VectorScale( bspNodes[ i ].mins, scale, bspNodes[ i ].mins );
472                 VectorScale( bspNodes[ i ].maxs, scale, bspNodes[ i ].maxs );
473         }
474
475         /* scale leafs */
476         for ( i = 0; i < numBSPLeafs; i++ )
477         {
478                 VectorScale( bspLeafs[ i ].mins, scale, bspLeafs[ i ].mins );
479                 VectorScale( bspLeafs[ i ].maxs, scale, bspLeafs[ i ].maxs );
480         }
481
482         /* scale drawverts */
483         for ( i = 0; i < numBSPDrawVerts; i++ )
484                 VectorScale( bspDrawVerts[ i ].xyz, scale, bspDrawVerts[ i ].xyz );
485
486         /* scale planes */
487         for ( i = 0; i < numBSPPlanes; i++ )
488                 bspPlanes[ i ].dist *= scale;
489
490         /* scale gridsize */
491         GetVectorForKey( &entities[ 0 ], "gridsize", vec );
492         if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
493                 VectorCopy( gridSize, vec );
494         }
495         VectorScale( vec, scale, vec );
496         sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
497         SetKeyValue( &entities[ 0 ], "gridsize", str );
498
499         /* write the bsp */
500         UnparseEntities();
501         StripExtension( source );
502         DefaultExtension( source, "_s.bsp" );
503         Sys_Printf( "Writing %s\n", source );
504         WriteBSPFile( source );
505
506         /* return to sender */
507         return 0;
508 }
509
510
511
512 /*
513    ConvertBSPMain()
514    main argument processing function for bsp conversion
515  */
516
517 int ConvertBSPMain( int argc, char **argv ){
518         int i;
519         int ( *convertFunc )( char * );
520         game_t  *convertGame;
521
522
523         /* set default */
524         convertFunc = ConvertBSPToASE;
525         convertGame = NULL;
526
527         /* arg checking */
528         if ( argc < 1 ) {
529                 Sys_Printf( "Usage: q3map -convert [-format <ase|map>] [-v] <mapname>\n" );
530                 return 0;
531         }
532
533         /* process arguments */
534         for ( i = 1; i < ( argc - 1 ); i++ )
535         {
536                 /* -format map|ase|... */
537                 if ( !strcmp( argv[ i ],  "-format" ) ) {
538                         i++;
539                         if ( !Q_stricmp( argv[ i ], "ase" ) ) {
540                                 convertFunc = ConvertBSPToASE;
541                         }
542                         else if ( !Q_stricmp( argv[ i ], "map" ) ) {
543                                 convertFunc = ConvertBSPToMap;
544                         }
545                         else
546                         {
547                                 convertGame = GetGame( argv[ i ] );
548                                 if ( convertGame == NULL ) {
549                                         Sys_Printf( "Unknown conversion format \"%s\". Defaulting to ASE.\n", argv[ i ] );
550                                 }
551                         }
552                 }
553         }
554
555         /* clean up map name */
556         strcpy( source, ExpandArg( argv[ i ] ) );
557         StripExtension( source );
558         DefaultExtension( source, ".bsp" );
559
560         LoadShaderInfo();
561
562         Sys_Printf( "Loading %s\n", source );
563
564         /* ydnar: load surface file */
565         //%     LoadSurfaceExtraFile( source );
566
567         LoadBSPFile( source );
568
569         /* parse bsp entities */
570         ParseEntities();
571
572         /* bsp format convert? */
573         if ( convertGame != NULL ) {
574                 /* set global game */
575                 game = convertGame;
576
577                 /* write bsp */
578                 StripExtension( source );
579                 DefaultExtension( source, "_c.bsp" );
580                 Sys_Printf( "Writing %s\n", source );
581                 WriteBSPFile( source );
582
583                 /* return to sender */
584                 return 0;
585         }
586
587         /* normal convert */
588         return convertFunc( source );
589 }
590
591
592
593 /*
594    main()
595    q3map mojo...
596  */
597
598 int main( int argc, char **argv ){
599         int i, r;
600         double start, end;
601
602
603         /* we want consistent 'randomness' */
604         srand( 0 );
605
606         /* start timer */
607         start = I_FloatTime();
608
609         /* this was changed to emit version number over the network */
610         printf( Q3MAP_VERSION "\n" );
611
612         /* set exit call */
613         atexit( ExitQ3Map );
614
615         /* read general options first */
616         for ( i = 1; i < argc; i++ )
617         {
618                 /* -connect */
619                 if ( !strcmp( argv[ i ], "-connect" ) ) {
620                         argv[ i ] = NULL;
621                         i++;
622                         Broadcast_Setup( argv[ i ] );
623                         argv[ i ] = NULL;
624                 }
625
626                 /* verbose */
627                 else if ( !strcmp( argv[ i ], "-v" ) ) {
628                         verbose = qtrue;
629                         argv[ i ] = NULL;
630                 }
631
632                 /* force */
633                 else if ( !strcmp( argv[ i ], "-force" ) ) {
634                         force = qtrue;
635                         argv[ i ] = NULL;
636                 }
637
638                 /* patch subdivisions */
639                 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
640                         argv[ i ] = NULL;
641                         i++;
642                         patchSubdivisions = atoi( argv[ i ] );
643                         argv[ i ] = NULL;
644                         if ( patchSubdivisions <= 0 ) {
645                                 patchSubdivisions = 1;
646                         }
647                 }
648
649                 /* threads */
650                 else if ( !strcmp( argv[ i ], "-threads" ) ) {
651                         argv[ i ] = NULL;
652                         i++;
653                         numthreads = atoi( argv[ i ] );
654                         argv[ i ] = NULL;
655                 }
656         }
657
658         /* init model library */
659         PicoInit();
660         PicoSetMallocFunc( safe_malloc );
661         PicoSetFreeFunc( free );
662         PicoSetPrintFunc( PicoPrintFunc );
663         PicoSetLoadFileFunc( PicoLoadFileFunc );
664         PicoSetFreeFileFunc( free );
665
666         /* set number of threads */
667         ThreadSetDefault();
668
669         /* generate sinusoid jitter table */
670         for ( i = 0; i < MAX_JITTERS; i++ )
671         {
672                 jitters[ i ] = sin( i * 139.54152147 );
673                 //%     Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
674         }
675
676         /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
677            and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
678
679         Sys_Printf( "Q3Map         - v1.0r (c) 1999 Id Software Inc.\n" );
680         Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
681         Sys_Printf( "GtkRadiant    - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
682         Sys_Printf( "%s\n", Q3MAP_MOTD );
683
684         /* ydnar: new path initialization */
685         InitPaths( &argc, argv );
686
687         /* check if we have enough options left to attempt something */
688         if ( argc < 2 ) {
689                 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
690         }
691
692         /* fixaas */
693         if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
694                 r = FixAAS( argc - 1, argv + 1 );
695         }
696
697         /* analyze */
698         else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
699                 r = AnalyzeBSP( argc - 1, argv + 1 );
700         }
701
702         /* info */
703         else if ( !strcmp( argv[ 1 ], "-info" ) ) {
704                 r = BSPInfo( argc - 2, argv + 2 );
705         }
706
707         /* vis */
708         else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
709                 r = VisMain( argc - 1, argv + 1 );
710         }
711
712         /* light */
713         else if ( !strcmp( argv[ 1 ], "-light" ) ) {
714                 r = LightMain( argc - 1, argv + 1 );
715         }
716
717         /* vlight */
718         else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
719                 Sys_Printf( "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
720                 argv[ 1 ] = "-fast";    /* eek a hack */
721                 r = LightMain( argc, argv );
722         }
723
724         /* ydnar: lightmap export */
725         else if ( !strcmp( argv[ 1 ], "-export" ) ) {
726                 r = ExportLightmapsMain( argc - 1, argv + 1 );
727         }
728
729         /* ydnar: lightmap import */
730         else if ( !strcmp( argv[ 1 ], "-import" ) ) {
731                 r = ImportLightmapsMain( argc - 1, argv + 1 );
732         }
733
734         /* ydnar: bsp scaling */
735         else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
736                 r = ScaleBSPMain( argc - 1, argv + 1 );
737         }
738
739         /* ydnar: bsp conversion */
740         else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
741                 r = ConvertBSPMain( argc - 1, argv + 1 );
742         }
743
744         /* ydnar: otherwise create a bsp */
745         else{
746                 r = BSPMain( argc, argv );
747         }
748
749         /* emit time */
750         end = I_FloatTime();
751         Sys_Printf( "%9.0f seconds elapsed\n", end - start );
752
753         /* shut down connection */
754         Broadcast_Shutdown();
755
756         /* return any error code */
757         return r;
758 }