1 /* -------------------------------------------------------------------------------
3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
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.
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.
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
22 -------------------------------------------------------------------------------
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."
27 ------------------------------------------------------------------------------- */
42 returns a pseudorandom number between 0 and 1
46 return (vec_t) rand() / RAND_MAX;
50 char *Q_strncpyz( char *dst, const char *src, size_t len ) {
55 strncpy( dst, src, len );
56 dst[ len - 1 ] = '\0';
61 char *Q_strcat( char *dst, size_t dlen, const char *src ) {
62 size_t n = strlen( dst );
65 abort(); /* buffer overflow */
68 return Q_strncpyz( dst + n, src, dlen - n );
72 char *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen ) {
73 size_t n = strlen( dst );
76 abort(); /* buffer overflow */
79 return Q_strncpyz( dst + n, src, MIN( slen, dlen - n ) );
88 static void ExitQ3Map( void ){
90 if ( mapDrawSurfs != NULL ) {
98 shifts a map: for testing physics with huge coordinates
101 int ShiftBSPMain( int argc, char **argv ){
109 float *old_xyzst = NULL;
115 Sys_Printf( "Usage: q3map [-v] -shift [-tex] [-spawn_ref <value>] <value> <mapname>\n" );
120 for ( i = 1; i < argc - 2; ++i )
122 if ( !strcmp( argv[i], "-tex" ) ) {
125 else if ( !strcmp( argv[i], "-spawn_ref" ) ) {
126 spawn_ref = atof( argv[i + 1] );
135 // if(argc-2 >= i) // always true
136 scale[2] = scale[1] = scale[0] = atof( argv[ argc - 2 ] );
137 if ( argc - 3 >= i ) {
138 scale[1] = scale[0] = atof( argv[ argc - 3 ] );
140 if ( argc - 4 >= i ) {
141 scale[0] = atof( argv[ argc - 4 ] );
144 uniform = ( ( scale[0] == scale[1] ) && ( scale[1] == scale[2] ) );
147 /* do some path mangling */
148 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
149 StripExtension( source );
150 DefaultExtension( source, ".bsp" );
153 Sys_Printf( "Loading %s\n", source );
154 LoadBSPFile( source );
158 Sys_Printf( "--- ShiftBSP ---\n" );
159 Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
161 /* shift entity keys */
162 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
165 GetVectorForKey( &entities[ i ], "origin", vec );
166 if ( ( vec[ 0 ] || vec[ 1 ] || vec[ 2 ] ) ) {
167 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
173 if ( !strncmp( ValueForKey( &entities[i], "classname" ), "info_player_", 12 ) ) {
176 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
177 SetKeyValue( &entities[ i ], "origin", str );
183 for ( i = 0; i < numBSPModels; i++ )
185 bspModels[ i ].mins[0] += scale[0];
186 bspModels[ i ].mins[1] += scale[1];
187 bspModels[ i ].mins[2] += scale[2];
188 bspModels[ i ].maxs[0] += scale[0];
189 bspModels[ i ].maxs[1] += scale[1];
190 bspModels[ i ].maxs[2] += scale[2];
194 for ( i = 0; i < numBSPNodes; i++ )
196 bspNodes[ i ].mins[0] += scale[0];
197 bspNodes[ i ].mins[1] += scale[1];
198 bspNodes[ i ].mins[2] += scale[2];
199 bspNodes[ i ].maxs[0] += scale[0];
200 bspNodes[ i ].maxs[1] += scale[1];
201 bspNodes[ i ].maxs[2] += scale[2];
205 for ( i = 0; i < numBSPLeafs; i++ )
207 bspLeafs[ i ].mins[0] += scale[0];
208 bspLeafs[ i ].mins[1] += scale[1];
209 bspLeafs[ i ].mins[2] += scale[2];
210 bspLeafs[ i ].maxs[0] += scale[0];
211 bspLeafs[ i ].maxs[1] += scale[1];
212 bspLeafs[ i ].maxs[2] += scale[2];
215 /* shift drawverts */
216 for ( i = 0; i < numBSPDrawVerts; i++ )
218 bspDrawVerts[i].xyz[0] += scale[0];
219 bspDrawVerts[i].xyz[1] += scale[1];
220 bspDrawVerts[i].xyz[2] += scale[2];
227 for ( i = 0; i < numBSPPlanes; i++ )
229 //find point on plane
230 for ( j=0; j<3; j++ ){
231 if ( fabs( bspPlanes[ i ].normal[j] ) > 0.5 ){
232 point[j] = bspPlanes[ i ].dist / bspPlanes[ i ].normal[j];
233 point[(j+1)%3] = point[(j+2)%3] = 0;
238 for ( j=0; j<3; j++ ){
239 point[j] += scale[j];
241 //calc new plane dist
242 bspPlanes[ i ].dist = DotProduct( point, bspPlanes[ i ].normal );
247 GetVectorForKey( &entities[ 0 ], "gridsize", vec );
248 if ( ( vec[ 0 ] + vec[ 1 ] + vec[ 2 ] ) == 0.0f ) {
249 VectorCopy( gridSize, vec );
254 sprintf( str, "%f %f %f", vec[ 0 ], vec[ 1 ], vec[ 2 ] );
255 SetKeyValue( &entities[ 0 ], "gridsize", str );
257 /* inject command line parameters */
258 InjectCommandLine( argv, 0, argc - 1 );
262 StripExtension( source );
263 DefaultExtension( source, "_sh.bsp" );
264 Sys_Printf( "Writing %s\n", source );
265 WriteBSPFile( source );
267 /* return to sender */
272 void FixDOSName( char *src ){
279 if ( *src == '\\' ) {
287 Check if newcoming texture is unique and not excluded
289 void tex2list( char* texlist, int *texnum, char* EXtex, int *EXtexnum ){
291 if ( token[0] == '\0') return;
292 StripExtension( token );
294 for ( i = 0; i < *texnum; i++ ){
295 if ( !Q_stricmp( texlist[i], token ) ) return;
297 for ( i = 0; i < *EXtexnum; i++ ){
298 if ( !Q_stricmp( EXtex[i], token ) ) return;
300 strcpy ( texlist + (*texnum)*65, token );
307 Check if newcoming res is unique
309 void res2list( char* data, int *num ){
311 if ( *( data + (*num)*65 ) == '\0') return;
312 for ( i = 0; i < *num; i++ ){
313 if ( !Q_stricmp( data[i], data[*num] ) ) return;
319 void parseEXblock ( char* data, int *num, const char *exName ){
320 if ( !GetToken( qtrue ) || strcmp( token, "{" ) ) {
321 Error( "ReadExclusionsFile: %s, line %d: { not found", exName, scriptline );
325 if ( !GetToken( qtrue ) ) {
328 if ( !strcmp( token, "}" ) ) {
331 if ( token[0] == '{' ) {
332 Error( "ReadExclusionsFile: %s, line %d: brace, opening twice in a row.", exName, scriptline );
336 strcpy( data + (*num)*65, token );
342 char q3map2path[1024];
345 map autopackager, works for Q3 type of shaders and ents
348 int pk3BSPMain( int argc, char **argv ){
350 qboolean dbg = qfalse, png = qfalse, packFAIL = qfalse;
352 /* process arguments */
353 for ( i = 1; i < ( argc - 1 ); i++ ){
354 if ( !strcmp( argv[ i ], "-dbg" ) ) {
357 else if ( !strcmp( argv[ i ], "-png" ) ) {
362 /* do some path mangling */
363 strcpy( source, ExpandArg( argv[ argc - 1 ] ) );
364 StripExtension( source );
365 DefaultExtension( source, ".bsp" );
368 Sys_Printf( "Loading %s\n", source );
369 LoadBSPFile( source );
373 char packname[ 1024 ], packFailName[ 1024 ], base[ 1024 ], nameOFmap[ 1024 ], temp[ 1024 ];
376 strcpy( base, source );
377 StripExtension( base );
379 /* extract map name */
380 len = strlen( base ) - 1;
381 while ( len > 0 && base[ len ] != '/' && base[ len ] != '\\' )
383 strcpy( nameOFmap, &base[ len + 1 ] );
386 qboolean drawsurfSHs[1024] = { qfalse };
388 for ( i = 0; i < numBSPDrawSurfaces; i++ ){
389 /* can't exclude nodraw patches here (they want shaders :0!) */
390 //if ( !( bspDrawSurfaces[i].surfaceType == 2 && bspDrawSurfaces[i].numIndexes == 0 ) ) drawsurfSHs[bspDrawSurfaces[i].shaderNum] = qtrue;
391 drawsurfSHs[ bspDrawSurfaces[i].shaderNum ] = qtrue;
392 //Sys_Printf( "%s\n", bspShaders[bspDrawSurfaces[i].shaderNum].shader );
396 char* pk3Shaders = (char *)calloc( 1024*65, sizeof( char ) );
398 char* pk3Sounds = (char *)calloc( 1024*65, sizeof( char ) );
399 int pk3ShaderfilesN = 0;
400 char* pk3Shaderfiles = (char *)calloc( 1024*65, sizeof( char ) );
401 int pk3TexturesN = 0;
402 char* pk3Textures = (char *)calloc( 1024*65, sizeof( char ) );
404 char* pk3Videos = (char *)calloc( 1024*65, sizeof( char ) );
408 for ( i = 0; i < numBSPShaders; i++ ){
409 if ( drawsurfSHs[i] ){
410 strcpy( pk3Shaders + pk3ShadersN*65, bspShaders[i].shader );
411 res2list( pk3Shaders, &pk3ShadersN );
413 //Sys_Printf( "%s\n", bspShaders[i].shader );
419 for ( ep = entities[0].epairs; ep != NULL; ep = ep->next )
421 if ( !Q_strncasecmp( ep->key, "vertexremapshader", 17 ) ) {
422 sscanf( ep->value, "%*[^;] %*[;] %s", pk3Shaders + pk3ShadersN*65 );
423 res2list( pk3Shaders, &pk3ShadersN );
426 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[0], "music" ) );
427 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' ){
428 FixDOSName( pk3Sounds + pk3SoundsN*65 );
429 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
430 res2list( pk3Sounds, &pk3SoundsN );
433 for ( i = 0; i < numBSPEntities && i < numEntities; i++ )
435 strcpy( pk3Sounds + pk3SoundsN*65, ValueForKey( &entities[i], "noise" ) );
436 if ( *( pk3Sounds + pk3SoundsN*65 ) != '\0' && *( pk3Sounds + pk3SoundsN*65 ) != '*' ){
437 FixDOSName( pk3Sounds + pk3SoundsN*65 );
438 DefaultExtension( pk3Sounds + pk3SoundsN*65, ".wav" );
439 res2list( pk3Sounds, &pk3SoundsN );
442 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "func_plat" ) ){
443 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_strt.wav");
444 res2list( pk3Sounds, &pk3SoundsN );
445 strcpy( pk3Sounds + pk3SoundsN*65, "sound/movers/plats/pt1_end.wav");
446 res2list( pk3Sounds, &pk3SoundsN );
448 if ( !Q_stricmp( ValueForKey( &entities[i], "classname" ), "target_push" ) ){
449 if ( !(IntForKey( &entities[i], "spawnflags") & 1) ){
450 strcpy( pk3Sounds + pk3SoundsN*65, "sound/misc/windfly.wav");
451 res2list( pk3Sounds, &pk3SoundsN );
454 strcpy( pk3Shaders + pk3ShadersN*65, ValueForKey( &entities[i], "targetShaderNewName" ) );
455 res2list( pk3Shaders, &pk3ShadersN );
459 sprintf( pk3Shaders + pk3ShadersN*65, "levelshots/%s", nameOFmap );
460 res2list( pk3Shaders, &pk3ShadersN );
464 Sys_Printf( "\n\tDrawsurface+ent calls....%i\n", pk3ShadersN );
465 for ( i = 0; i < pk3ShadersN; i++ ){
466 Sys_Printf( "%s\n", pk3Shaders + i*65 );
468 Sys_Printf( "\n\tSounds....%i\n", pk3SoundsN );
469 for ( i = 0; i < pk3SoundsN; i++ ){
470 Sys_Printf( "%s\n", pk3Sounds + i*65 );
474 vfsListShaderFiles( pk3Shaderfiles, &pk3ShaderfilesN );
477 Sys_Printf( "\n\tSchroider fileses.....%i\n", pk3ShaderfilesN );
478 for ( i = 0; i < pk3ShaderfilesN; i++ ){
479 Sys_Printf( "%s\n", pk3Shaderfiles + i*65 );
484 /* load exclusions file */
486 char* ExTextures = (char *)calloc( 4096*65, sizeof( char ) );
488 char* ExShaders = (char *)calloc( 4096*65, sizeof( char ) );
490 char* ExSounds = (char *)calloc( 4096*65, sizeof( char ) );
491 int ExShaderfilesN = 0;
492 char* ExShaderfiles = (char *)calloc( 4096*65, sizeof( char ) );
494 char* ExVideos = (char *)calloc( 4096*65, sizeof( char ) );
495 int ExPureTexturesN = 0;
496 char* ExPureTextures = (char *)calloc( 4096*65, sizeof( char ) );
498 char* ExReasonShader[4096] = { NULL };
499 char* ExReasonShaderFile[4096] = { NULL };
505 strcpy( exName, q3map2path );
506 char *cut = strrchr( exName, '\\' );
507 char *cut2 = strrchr( exName, '/' );
508 if ( cut == NULL && cut2 == NULL ){
509 Sys_Printf( "WARNING: Unable to load exclusions file.\n" );
512 if ( cut2 > cut ) cut = cut2;
514 strcat( exName, game->arg );
515 strcat( exName, ".exclude" );
517 Sys_Printf( "Loading %s\n", exName );
518 size = TryLoadFile( exName, (void**) &buffer );
520 Sys_Printf( "WARNING: Unable to find exclusions file %s.\n", exName );
525 ParseFromMemory( (char *) buffer, size );
530 /* test for end of file */
531 if ( !GetToken( qtrue ) ) {
536 if ( !Q_stricmp( token, "textures" ) ){
537 parseEXblock ( ExTextures, &ExTexturesN, exName );
539 else if ( !Q_stricmp( token, "shaders" ) ){
540 parseEXblock ( ExShaders, &ExShadersN, exName );
542 else if ( !Q_stricmp( token, "shaderfiles" ) ){
543 parseEXblock ( ExShaderfiles, &ExShaderfilesN, exName );
545 else if ( !Q_stricmp( token, "sounds" ) ){
546 parseEXblock ( ExSounds, &ExSoundsN, exName );
548 else if ( !Q_stricmp( token, "videos" ) ){
549 parseEXblock ( ExVideos, &ExVideosN, exName );
552 Error( "ReadExclusionsFile: %s, line %d: unknown block name!\nValid ones are: textures, shaders, shaderfiles, sounds, videos.", exName, scriptline );
556 /* free the buffer */
559 for ( i = 0; i < ExTexturesN; i++ ){
560 for ( j = 0; j < ExShadersN; j++ ){
561 if ( !Q_stricmp( ExTextures + i*65, ExShaders + j*65 ) ){
565 if ( j == ExShadersN ){
566 strcpy ( ExPureTextures + ExPureTexturesN*65, ExTextures + i*65 );
574 Sys_Printf( "\n\tExTextures....%i\n", ExTexturesN );
575 for ( i = 0; i < ExTexturesN; i++ ) Sys_Printf( "%s\n", ExTextures + i*65 );
576 Sys_Printf( "\n\tExPureTextures....%i\n", ExPureTexturesN );
577 for ( i = 0; i < ExPureTexturesN; i++ ) Sys_Printf( "%s\n", ExPureTextures + i*65 );
578 Sys_Printf( "\n\tExShaders....%i\n", ExShadersN );
579 for ( i = 0; i < ExShadersN; i++ ) Sys_Printf( "%s\n", ExShaders + i*65 );
580 Sys_Printf( "\n\tExShaderfiles....%i\n", ExShaderfilesN );
581 for ( i = 0; i < ExShaderfilesN; i++ ) Sys_Printf( "%s\n", ExShaderfiles + i*65 );
582 Sys_Printf( "\n\tExSounds....%i\n", ExSoundsN );
583 for ( i = 0; i < ExSoundsN; i++ ) Sys_Printf( "%s\n", ExSounds + i*65 );
584 Sys_Printf( "\n\tExVideos....%i\n", ExVideosN );
585 for ( i = 0; i < ExVideosN; i++ ) Sys_Printf( "%s\n", ExVideos + i*65 );
588 /* can exclude pure textures right now, shouldn't create shaders for them anyway */
589 for ( i = 0; i < pk3ShadersN ; i++ ){
590 for ( j = 0; j < ExPureTexturesN ; j++ ){
591 if ( !Q_stricmp( pk3Shaders + i*65, ExPureTextures + j*65 ) ){
592 *( pk3Shaders + i*65 ) = '\0';
602 for ( i = 0; i < pk3ShaderfilesN; i++ ){
603 qboolean wantShader = qfalse, wantShaderFile = qfalse, ShaderFileExcluded = qfalse;
605 char* reasonShader = NULL, reasonShaderFile = NULL;
607 /* load the shader */
608 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
609 SilentLoadScriptFile( temp, 0 );
610 if( dbg ) Sys_Printf( "\n\tentering %s\n", pk3Shaderfiles + i*65 );
612 /* do wanna le shader file? */
613 for ( j = 0; j < ExShaderfilesN; j++ ){
614 if ( !Q_stricmp( ExShaderfiles + j*65, pk3Shaderfiles + i*65 ) ){
615 ShaderFileExcluded = qtrue;
616 reasonShaderFile = ExShaderfiles + j*65;
621 /* check if shader file has to be excluded */
622 while ( !ShaderFileExcluded )
624 /* test for end of file */
625 if ( !GetToken( qtrue ) ) {
629 /* does it contain restricted shaders/textures? */
630 for ( j = 0; j < ExShadersN; j++ ){
631 if ( !Q_stricmp( ExShaders + j*65, token ) ){
632 ShaderFileExcluded = qtrue;
633 reasonShader = ExShaders + j*65;
637 if ( ShaderFileExcluded )
639 for ( j = 0; j < ExPureTexturesN; j++ ){
640 if ( !Q_stricmp( ExPureTextures + j*65, token ) ){
641 ShaderFileExcluded = qtrue;
642 reasonShader = ExPureTextures + j*65;
646 if ( ShaderFileExcluded )
649 /* handle { } section */
650 if ( !GetToken( qtrue ) ) {
653 if ( strcmp( token, "{" ) ) {
654 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s",
655 temp, scriptline, token );
660 /* get the next token */
661 if ( !GetToken( qtrue ) ) {
664 if ( !strcmp( token, "}" ) ) {
667 /* parse stage directives */
668 if ( !strcmp( token, "{" ) ) {
671 if ( !GetToken( qtrue ) ) {
674 if ( !strcmp( token, "}" ) ) {
682 /* tokenize it again */
683 SilentLoadScriptFile( temp, 0 );
686 /* test for end of file */
687 if ( !GetToken( qtrue ) ) {
691 if( dbg ) Sys_Printf( "%s\n", token );
693 /* do wanna le shader? */
695 for ( j = 0; j < pk3ShadersN; j++ ){
696 if ( !Q_stricmp( pk3Shaders + j*65, token) ){
703 /* handle { } section */
704 if ( !GetToken( qtrue ) ) {
707 if ( strcmp( token, "{" ) ) {
708 Error( "ParseShaderFile: %s, line %d: { not found!\nFound instead: %s",
709 temp, scriptline, token );
714 /* get the next token */
715 if ( !GetToken( qtrue ) ) {
718 if ( !strcmp( token, "}" ) ) {
723 /* -----------------------------------------------------------------
724 shader stages (passes)
725 ----------------------------------------------------------------- */
727 /* parse stage directives */
728 if ( !strcmp( token, "{" ) ) {
731 if ( !GetToken( qtrue ) ) {
734 if ( !strcmp( token, "}" ) ) {
737 /* skip the shader */
738 if ( !wantShader ) continue;
740 /* digest any images */
741 if ( !Q_stricmp( token, "map" ) ||
742 !Q_stricmp( token, "clampMap" ) ) {
746 if ( token[ 0 ] != '*' && token[ 0 ] != '$' ) {
747 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
750 else if ( !Q_stricmp( token, "animMap" ) ||
751 !Q_stricmp( token, "clampAnimMap" ) ) {
752 GetToken( qfalse );// skip num
753 while ( TokenAvailable() ){
755 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
758 else if ( !Q_stricmp( token, "videoMap" ) ){
761 if ( strchr( token, "/" ) == NULL ){
762 sprintf( temp, "video/%s", token );
763 strcpy( token, temp );
765 for ( j = 0; j < pk3VideosN; j++ ){
766 if ( !Q_stricmp( pk3Videos + j*65, token ) ){
770 for ( j = 0; j < ExVideosN; j++ ){
771 if ( !Q_stricmp( ExVideos + j*65, token ) ){
775 strcpy ( pk3Videos + pk3VideosN*65, token );
782 /* skip the shader */
783 else if ( !wantShader ) continue;
785 /* -----------------------------------------------------------------
786 surfaceparm * directives
787 ----------------------------------------------------------------- */
789 /* match surfaceparm */
790 else if ( !Q_stricmp( token, "surfaceparm" ) ) {
792 if ( !Q_stricmp( token, "nodraw" ) ) {
794 *( pk3Shaders + shader*65 ) = '\0';
798 /* skyparms <outer image> <cloud height> <inner image> */
799 else if ( !Q_stricmp( token, "skyParms" ) ) {
803 /* ignore bogus paths */
804 if ( Q_stricmp( token, "-" ) && Q_stricmp( token, "full" ) ) {
805 strcpy ( temp, token );
806 sprintf( token, "%s_up", temp );
807 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
808 sprintf( token, "%s_dn", temp );
809 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
810 sprintf( token, "%s_lf", temp );
811 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
812 sprintf( token, "%s_rt", temp );
813 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
814 sprintf( token, "%s_bk", temp );
815 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
816 sprintf( token, "%s_ft", temp );
817 tex2list( pk3Textures, &pk3TexturesN, ExTextures, &ExTexturesN );
819 /* skip rest of line */
827 for ( j = 0; j < ExShadersN; j++ ){
828 if ( !Q_stricmp( ExShaders + j*65, pk3Shaders + shader*65 ) ){
830 *( pk3Shaders + shader*65 ) = '\0';
835 if ( ShaderFileExcluded ){
836 if ( reasonShaderFile != NULL ){
837 ExReasonShaderFile[ shader ] = reasonShaderFile;
840 ExReasonShaderFile[ shader ] = ( char* ) calloc( 65, sizeof( char ) );
841 strcpy( ExReasonShaderFile[ shader ], pk3Shaderfiles + i*65 );
843 ExReasonShader[ shader ] = reasonShader;
846 wantShaderFile = qtrue;
847 *( pk3Shaders + shader*65 ) = '\0';
852 if ( !wantShaderFile ){
853 *( pk3Shaderfiles + i*65 ) = '\0';
860 //wanted shaders from excluded .shaders
862 for ( i = 0; i < pk3ShadersN; i++ ){
863 if ( *( pk3Shaders + i*65 ) != '\0' && ( ExReasonShader[i] != NULL || ExReasonShaderFile[i] != NULL ) ){
864 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
866 if ( ExReasonShader[i] != NULL ){
867 Sys_Printf( " reason: is located in %s,\n containing restricted shader %s\n", ExReasonShaderFile[i], ExReasonShader[i] );
870 Sys_Printf( " reason: is located in restricted %s\n", ExReasonShaderFile[i] );
872 *( pk3Shaders + i*65 ) = '\0';
875 //pure textures (shader ones are done)
876 for ( i = 0; i < pk3ShadersN; i++ ){
877 if ( *( pk3Shaders + i*65 ) != '\0' ){
878 FixDOSName( pk3Shaders + i*65 );
879 for ( j = 0; j < pk3TexturesN; j++ ){
880 if ( !Q_stricmp( pk3Shaders + i*65, pk3Textures + j*65 ) ){
881 *( pk3Shaders + i*65 ) = '\0';
885 if ( *( pk3Shaders + i*65 ) == '\0' ) continue;
886 for ( j = 0; j < ExTexturesN; j++ ){
887 if ( !Q_stricmp( pk3Shaders + i*65, ExTextures + j*65 ) ){
888 *( pk3Shaders + i*65 ) = '\0';
896 for ( i = 0; i < pk3SoundsN; i++ ){
897 for ( j = 0; j < ExSoundsN; j++ ){
898 if ( !Q_stricmp( pk3Sounds + i*65, ExSounds + j*65 ) ){
899 *( pk3Sounds + i*65 ) = '\0';
906 sprintf( packname, "%s/%s_autopacked.pk3", EnginePath, nameOFmap );
908 sprintf( packFailName, "%s/%s_FAILEDpack.pk3", EnginePath, nameOFmap );
909 remove( packFailName );
911 Sys_Printf( "\n--- ZipZip ---\n" );
913 Sys_Printf( "\n\tShader referenced textures....\n" );
915 for ( i = 0; i < pk3TexturesN; i++ ){
917 sprintf( temp, "%s.png", pk3Textures + i*65 );
918 if ( vfsPackFile( temp, packname ) ){
919 Sys_Printf( "++%s\n", temp );
923 sprintf( temp, "%s.tga", pk3Textures + i*65 );
924 if ( vfsPackFile( temp, packname ) ){
925 Sys_Printf( "++%s\n", temp );
928 sprintf( temp, "%s.jpg", pk3Textures + i*65 );
929 if ( vfsPackFile( temp, packname ) ){
930 Sys_Printf( "++%s\n", temp );
933 Sys_Printf( " !FAIL! %s\n", pk3Textures + i*65 );
937 Sys_Printf( "\n\tPure textures....\n" );
939 for ( i = 0; i < pk3ShadersN; i++ ){
940 if ( *( pk3Shaders + i*65 ) != '\0' ){
942 sprintf( temp, "%s.png", pk3Shaders + i*65 );
943 if ( vfsPackFile( temp, packname ) ){
944 Sys_Printf( "++%s\n", temp );
948 sprintf( temp, "%s.tga", pk3Shaders + i*65 );
949 if ( vfsPackFile( temp, packname ) ){
950 Sys_Printf( "++%s\n", temp );
953 sprintf( temp, "%s.jpg", pk3Shaders + i*65 );
954 if ( vfsPackFile( temp, packname ) ){
955 Sys_Printf( "++%s\n", temp );
958 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
959 if ( i != pk3ShadersN - 1 ) packFAIL = qtrue; //levelshot typically
963 Sys_Printf( "\n\tShaizers....\n" );
965 for ( i = 0; i < pk3ShaderfilesN; i++ ){
966 if ( *( pk3Shaderfiles + i*65 ) != '\0' ){
967 sprintf( temp, "%s/%s", game->shaderPath, pk3Shaderfiles + i*65 );
968 if ( vfsPackFile( temp, packname ) ){
969 Sys_Printf( "++%s\n", temp );
972 Sys_Printf( " !FAIL! %s\n", pk3Shaders + i*65 );
977 Sys_Printf( "\n\tSounds....\n" );
979 for ( i = 0; i < pk3SoundsN; i++ ){
980 if ( *( pk3Sounds + i*65 ) != '\0' ){
981 if ( vfsPackFile( pk3Sounds + i*65, packname ) ){
982 Sys_Printf( "++%s\n", pk3Sounds + i*65 );
985 Sys_Printf( " !FAIL! %s\n", pk3Sounds + i*65 );
990 Sys_Printf( "\n\tVideos....\n" );
992 for ( i = 0; i < pk3VideosN; i++ ){
993 if ( vfsPackFile( pk3Videos + i*65, packname ) ){
994 Sys_Printf( "++%s\n", pk3Videos + i*65 );
997 Sys_Printf( " !FAIL! %s\n", pk3Videos + i*65 );
1001 Sys_Printf( "\n\t.bsp and stuff\n" );
1003 sprintf( temp, "maps/%s.bsp", nameOFmap );
1004 if ( vfsPackFile( temp, packname ) ){
1005 Sys_Printf( "++%s\n", temp );
1008 Sys_Printf( " !FAIL! %s\n", temp );
1012 sprintf( temp, "maps/%s.aas", nameOFmap );
1013 if ( vfsPackFile( temp, packname ) ){
1014 Sys_Printf( "++%s\n", temp );
1017 Sys_Printf( " !FAIL! %s\n", temp );
1020 sprintf( temp, "scripts/%s.arena", nameOFmap );
1021 if ( vfsPackFile( temp, packname ) ){
1022 Sys_Printf( "++%s\n", temp );
1025 Sys_Printf( " !FAIL! %s\n", temp );
1028 sprintf( temp, "scripts/%s.defi", nameOFmap );
1029 if ( vfsPackFile( temp, packname ) ){
1030 Sys_Printf( "++%s\n", temp );
1033 Sys_Printf( " !FAIL! %s\n", temp );
1037 Sys_Printf( "\nSaved to %s\n", packname );
1040 rename( packname, packFailName );
1041 Sys_Printf( "\nSaved to %s\n", packFailName );
1043 /* return to sender */
1053 int main( int argc, char **argv ){
1056 extern qboolean werror;
1059 /* we want consistent 'randomness' */
1063 start = I_FloatTime();
1065 /* this was changed to emit version number over the network */
1066 printf( Q3MAP_VERSION "\n" );
1069 atexit( ExitQ3Map );
1071 /* read general options first */
1072 for ( i = 1; i < argc; i++ )
1075 if ( !strcmp( argv[ i ], "-h" ) || !strcmp( argv[ i ], "--help" )
1076 || !strcmp( argv[ i ], "-help" ) ) {
1077 HelpMain( ( i + 1 < argc ) ? argv[ i + 1 ] : NULL );
1082 if ( !strcmp( argv[ i ], "-connect" ) ) {
1083 if ( ++i >= argc || !argv[ i ] ) {
1084 Error( "Out of arguments: No address specified after %s", argv[ i - 1 ] );
1086 argv[ i - 1 ] = NULL;
1087 Broadcast_Setup( argv[ i ] );
1092 else if ( !strcmp( argv[ i ], "-v" ) ) {
1100 else if ( !strcmp( argv[ i ], "-force" ) ) {
1105 /* make all warnings into errors */
1106 else if ( !strcmp( argv[ i ], "-werror" ) ) {
1111 /* patch subdivisions */
1112 else if ( !strcmp( argv[ i ], "-subdivisions" ) ) {
1113 if ( ++i >= argc || !argv[ i ] ) {
1114 Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
1116 argv[ i - 1 ] = NULL;
1117 patchSubdivisions = atoi( argv[ i ] );
1119 if ( patchSubdivisions <= 0 ) {
1120 patchSubdivisions = 1;
1125 else if ( !strcmp( argv[ i ], "-threads" ) ) {
1126 if ( ++i >= argc || !argv[ i ] ) {
1127 Error( "Out of arguments: No value specified after %s", argv[ i - 1 ] );
1129 argv[ i - 1 ] = NULL;
1130 numthreads = atoi( argv[ i ] );
1134 else if( !strcmp( argv[ i ], "-nocmdline" ) )
1136 Sys_Printf( "noCmdLine\n" );
1143 /* init model library */
1145 PicoSetMallocFunc( safe_malloc );
1146 PicoSetFreeFunc( free );
1147 PicoSetPrintFunc( PicoPrintFunc );
1148 PicoSetLoadFileFunc( PicoLoadFileFunc );
1149 PicoSetFreeFileFunc( free );
1151 /* set number of threads */
1154 /* generate sinusoid jitter table */
1155 for ( i = 0; i < MAX_JITTERS; i++ )
1157 jitters[ i ] = sin( i * 139.54152147 );
1158 //% Sys_Printf( "Jitter %4d: %f\n", i, jitters[ i ] );
1161 /* we print out two versions, q3map's main version (since it evolves a bit out of GtkRadiant)
1162 and we put the GtkRadiant version to make it easy to track with what version of Radiant it was built with */
1164 Sys_Printf( "Q3Map - v1.0r (c) 1999 Id Software Inc.\n" );
1165 Sys_Printf( "Q3Map (ydnar) - v" Q3MAP_VERSION "\n" );
1166 Sys_Printf( RADIANT_NAME " - v" RADIANT_VERSION " " __DATE__ " " __TIME__ "\n" );
1167 Sys_Printf( "%s\n", Q3MAP_MOTD );
1168 Sys_Printf( "%s\n", argv[0] );
1170 strcpy( q3map2path, argv[0] );//fuer autoPack func
1172 /* ydnar: new path initialization */
1173 InitPaths( &argc, argv );
1175 /* set game options */
1176 if ( !patchSubdivisions ) {
1177 patchSubdivisions = game->patchSubdivisions;
1180 /* check if we have enough options left to attempt something */
1182 Error( "Usage: %s [general options] [options] mapfile", argv[ 0 ] );
1186 if ( !strcmp( argv[ 1 ], "-fixaas" ) ) {
1187 r = FixAASMain( argc - 1, argv + 1 );
1191 else if ( !strcmp( argv[ 1 ], "-analyze" ) ) {
1192 r = AnalyzeBSPMain( argc - 1, argv + 1 );
1196 else if ( !strcmp( argv[ 1 ], "-info" ) ) {
1197 r = BSPInfoMain( argc - 2, argv + 2 );
1201 else if ( !strcmp( argv[ 1 ], "-vis" ) ) {
1202 r = VisMain( argc - 1, argv + 1 );
1206 else if ( !strcmp( argv[ 1 ], "-light" ) ) {
1207 r = LightMain( argc - 1, argv + 1 );
1211 else if ( !strcmp( argv[ 1 ], "-vlight" ) ) {
1212 Sys_FPrintf( SYS_WRN, "WARNING: VLight is no longer supported, defaulting to -light -fast instead\n\n" );
1213 argv[ 1 ] = "-fast"; /* eek a hack */
1214 r = LightMain( argc, argv );
1217 /* QBall: export entities */
1218 else if ( !strcmp( argv[ 1 ], "-exportents" ) ) {
1219 r = ExportEntitiesMain( argc - 1, argv + 1 );
1222 /* ydnar: lightmap export */
1223 else if ( !strcmp( argv[ 1 ], "-export" ) ) {
1224 r = ExportLightmapsMain( argc - 1, argv + 1 );
1227 /* ydnar: lightmap import */
1228 else if ( !strcmp( argv[ 1 ], "-import" ) ) {
1229 r = ImportLightmapsMain( argc - 1, argv + 1 );
1232 /* ydnar: bsp scaling */
1233 else if ( !strcmp( argv[ 1 ], "-scale" ) ) {
1234 r = ScaleBSPMain( argc - 1, argv + 1 );
1238 else if ( !strcmp( argv[ 1 ], "-shift" ) ) {
1239 r = ShiftBSPMain( argc - 1, argv + 1 );
1243 else if ( !strcmp( argv[ 1 ], "-pk3" ) ) {
1244 r = pk3BSPMain( argc - 1, argv + 1 );
1247 /* ydnar: bsp conversion */
1248 else if ( !strcmp( argv[ 1 ], "-convert" ) ) {
1249 r = ConvertBSPMain( argc - 1, argv + 1 );
1253 else if ( !strcmp( argv[ 1 ], "-minimap" ) ) {
1254 r = MiniMapBSPMain( argc - 1, argv + 1 );
1257 /* ydnar: otherwise create a bsp */
1259 /* used to write Smokin'Guns like tex file */
1260 compile_map = qtrue;
1262 r = BSPMain( argc, argv );
1266 end = I_FloatTime();
1267 Sys_Printf( "%9.0f seconds elapsed\n", end - start );
1269 /* shut down connection */
1270 Broadcast_Shutdown();
1272 /* return any error code */