]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3map2/convert_map.c
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / tools / quake3 / q3map2 / convert_map.c
index 1fabbc6366216bffaca73ceb8d1a62c3e7352d0b..26748c86b7a9ac39e88b6ffcb2c0f36142056ba5 100644 (file)
@@ -1,30 +1,30 @@
 /* -------------------------------------------------------------------------------
 
 /* -------------------------------------------------------------------------------
 
-Copyright (C) 1999-2007 id Software, Inc. and contributors.
-For a list of contributors, see the accompanying CONTRIBUTORS file.
+   Copyright (C) 1999-2007 id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
 
 
-This file is part of GtkRadiant.
+   This file is part of GtkRadiant.
 
 
-GtkRadiant is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   GtkRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
 
-GtkRadiant is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   GtkRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
 
-You should have received a copy of the GNU General Public License
-along with GtkRadiant; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+   You should have received a copy of the GNU General Public License
+   along with GtkRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
-----------------------------------------------------------------------------------
+   ----------------------------------------------------------------------------------
 
 
-This code has been altered significantly from its original form, to support
-several games based on the Quake III Arena engine, in the form of "Q3Map2."
+   This code has been altered significantly from its original form, to support
+   several games based on the Quake III Arena engine, in the form of "Q3Map2."
 
 
-------------------------------------------------------------------------------- */
+   ------------------------------------------------------------------------------- */
 
 
 
 
 
 
@@ -39,200 +39,211 @@ several games based on the Quake III Arena engine, in the form of "Q3Map2."
 
 
 /*
 
 
 /*
-ConvertBrush()
-exports a map brush
-*/
+   ConvertBrush()
+   exports a map brush
+ */
+
+#define SNAP_FLOAT_TO_INT   4
+#define SNAP_INT_TO_FLOAT   ( 1.0 / SNAP_FLOAT_TO_INT )
+
+static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, vec3_t origin ){
+       int i, j;
+       bspBrushSide_t  *side;
+       side_t          *buildSide;
+       bspShader_t     *shader;
+       char            *texture;
+       bspPlane_t      *plane;
+       vec3_t pts[ 3 ];
 
 
-#define        SNAP_FLOAT_TO_INT       4
-#define        SNAP_INT_TO_FLOAT       (1.0 / SNAP_FLOAT_TO_INT)
 
 
-static void ConvertBrush( FILE *f, int num, bspBrush_t *brush, vec3_t origin )
-{
-       int                             i, j;
-       bspBrushSide_t  *side;
-       side_t                  *buildSide;
-       bspShader_t             *shader;
-       char                    *texture;
-       bspPlane_t              *plane;
-       vec3_t                  pts[ 3 ];
-       
-       
        /* start brush */
        fprintf( f, "\t// brush %d\n", num );
        fprintf( f, "\t{\n" );
        /* start brush */
        fprintf( f, "\t// brush %d\n", num );
        fprintf( f, "\t{\n" );
-       
+
        /* clear out build brush */
        /* clear out build brush */
-       for( i = 0; i < buildBrush->numsides; i++ )
+       for ( i = 0; i < buildBrush->numsides; i++ )
        {
                buildSide = &buildBrush->sides[ i ];
        {
                buildSide = &buildBrush->sides[ i ];
-               if( buildSide->winding != NULL )
-               {
+               if ( buildSide->winding != NULL ) {
                        FreeWinding( buildSide->winding );
                        buildSide->winding = NULL;
                }
        }
        buildBrush->numsides = 0;
                        FreeWinding( buildSide->winding );
                        buildSide->winding = NULL;
                }
        }
        buildBrush->numsides = 0;
-       
+
        /* iterate through bsp brush sides */
        /* iterate through bsp brush sides */
-       for( i = 0; i < brush->numSides; i++ )
+       for ( i = 0; i < brush->numSides; i++ )
        {
                /* get side */
                side = &bspBrushSides[ brush->firstSide + i ];
        {
                /* get side */
                side = &bspBrushSides[ brush->firstSide + i ];
-               
+
                /* get shader */
                /* get shader */
-               if( side->shaderNum < 0 || side->shaderNum >= numBSPShaders )
+               if ( side->shaderNum < 0 || side->shaderNum >= numBSPShaders ) {
                        continue;
                        continue;
+               }
                shader = &bspShaders[ side->shaderNum ];
                shader = &bspShaders[ side->shaderNum ];
-               if( !Q_stricmp( shader->shader, "default" ) || !Q_stricmp( shader->shader, "noshader" ) )
+               if ( !Q_stricmp( shader->shader, "default" ) || !Q_stricmp( shader->shader, "noshader" ) ) {
                        continue;
                        continue;
-               
+               }
+
                /* get plane */
                plane = &bspPlanes[ side->planeNum ];
                /* get plane */
                plane = &bspPlanes[ side->planeNum ];
-               
+
                /* add build side */
                buildSide = &buildBrush->sides[ buildBrush->numsides ];
                buildBrush->numsides++;
                /* add build side */
                buildSide = &buildBrush->sides[ buildBrush->numsides ];
                buildBrush->numsides++;
-               
+
                /* tag it */
                buildSide->shaderInfo = ShaderInfoForShader( shader->shader );
                buildSide->planenum = side->planeNum;
                buildSide->winding = NULL;
        }
                /* tag it */
                buildSide->shaderInfo = ShaderInfoForShader( shader->shader );
                buildSide->planenum = side->planeNum;
                buildSide->winding = NULL;
        }
-       
+
        /* make brush windings */
        /* make brush windings */
-       if( !CreateBrushWindings( buildBrush ) )
+       if ( !CreateBrushWindings( buildBrush ) ) {
                return;
                return;
-       
+       }
+
        /* iterate through build brush sides */
        /* iterate through build brush sides */
-       for( i = 0; i < buildBrush->numsides; i++ )
+       for ( i = 0; i < buildBrush->numsides; i++ )
        {
                /* get build side */
                buildSide = &buildBrush->sides[ i ];
        {
                /* get build side */
                buildSide = &buildBrush->sides[ i ];
-               
+
                /* dummy check */
                /* dummy check */
-               if( buildSide->shaderInfo == NULL || buildSide->winding == NULL )
+               if ( buildSide->shaderInfo == NULL || buildSide->winding == NULL ) {
                        continue;
                        continue;
-               
+               }
+
                /* get texture name */
                /* get texture name */
-               if( !Q_strncasecmp( buildSide->shaderInfo->shader, "textures/", 9 ) )
+               if ( !Q_strncasecmp( buildSide->shaderInfo->shader, "textures/", 9 ) ) {
                        texture = buildSide->shaderInfo->shader + 9;
                        texture = buildSide->shaderInfo->shader + 9;
-               else
+               }
+               else{
                        texture = buildSide->shaderInfo->shader;
                        texture = buildSide->shaderInfo->shader;
-               
+               }
+
                /* get plane points and offset by origin */
                /* get plane points and offset by origin */
-               for( j = 0; j < 3; j++ )
+               for ( j = 0; j < 3; j++ )
                {
                        VectorAdd( buildSide->winding->p[ j ], origin, pts[ j ] );
                        //%     pts[ j ][ 0 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 0 ] * SNAP_FLOAT_TO_INT + 0.5f );
                        //%     pts[ j ][ 1 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 1 ] * SNAP_FLOAT_TO_INT + 0.5f );
                        //%     pts[ j ][ 2 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 2 ] * SNAP_FLOAT_TO_INT + 0.5f );
                }
                {
                        VectorAdd( buildSide->winding->p[ j ], origin, pts[ j ] );
                        //%     pts[ j ][ 0 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 0 ] * SNAP_FLOAT_TO_INT + 0.5f );
                        //%     pts[ j ][ 1 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 1 ] * SNAP_FLOAT_TO_INT + 0.5f );
                        //%     pts[ j ][ 2 ] = SNAP_INT_TO_FLOAT * floor( pts[ j ][ 2 ] * SNAP_FLOAT_TO_INT + 0.5f );
                }
-               
+
                /* print brush side */
                /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
                fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) %s 0 0 0 0.5 0.5 0 0 0\n",
                /* print brush side */
                /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
                fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) %s 0 0 0 0.5 0.5 0 0 0\n",
-                       pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
-                       pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
-                       pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
-                       texture );
+                                pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
+                                pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
+                                pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
+                                texture );
        }
        }
-       
+
        /* end brush */
        fprintf( f, "\t}\n\n" );
 }
 
 #if 0
        /* end brush */
        fprintf( f, "\t}\n\n" );
 }
 
 #if 0
-       /* iterate through the brush sides (ignore the first 6 bevel planes) */
-       for( i = 0; i < brush->numSides; i++ )
-       {
-               /* get side */
-               side = &bspBrushSides[ brush->firstSide + i ];
-               
-               /* get shader */
-               if( side->shaderNum < 0 || side->shaderNum >= numBSPShaders )
-                       continue;
-               shader = &bspShaders[ side->shaderNum ];
-               if( !Q_stricmp( shader->shader, "default" ) || !Q_stricmp( shader->shader, "noshader" ) )
-                       continue;
-               
-               /* get texture name */
-               if( !Q_strncasecmp( shader->shader, "textures/", 9 ) )
-                       texture = shader->shader + 9;
-               else
-                       texture = shader->shader;
-               
-               /* get plane */
-               plane = &bspPlanes[ side->planeNum ];
+/* iterate through the brush sides (ignore the first 6 bevel planes) */
+for ( i = 0; i < brush->numSides; i++ )
+{
+       /* get side */
+       side = &bspBrushSides[ brush->firstSide + i ];
 
 
-               /* make plane points */
-               {
-                       vec3_t  vecs[ 2 ];
+       /* get shader */
+       if ( side->shaderNum < 0 || side->shaderNum >= numBSPShaders ) {
+               continue;
+       }
+       shader = &bspShaders[ side->shaderNum ];
+       if ( !Q_stricmp( shader->shader, "default" ) || !Q_stricmp( shader->shader, "noshader" ) ) {
+               continue;
+       }
 
 
-                       
-                       MakeNormalVectors( plane->normal, vecs[ 0 ], vecs[ 1 ] );
-                       VectorMA( vec3_origin, plane->dist, plane->normal, pts[ 0 ] );
-                       VectorMA( pts[ 0 ], 256.0f, vecs[ 0 ], pts[ 1 ] );
-                       VectorMA( pts[ 0 ], 256.0f, vecs[ 1 ], pts[ 2 ] );
-               }
+       /* get texture name */
+       if ( !Q_strncasecmp( shader->shader, "textures/", 9 ) ) {
+               texture = shader->shader + 9;
+       }
+       else{
+               texture = shader->shader;
+       }
 
 
-               /* offset by origin */
-               for( j = 0; j < 3; j++ )
-                       VectorAdd( pts[ j ], origin, pts[ j ] );
-               
-               /* print brush side */
-               /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
-               fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) %s 0 0 0 0.5 0.5 0 0 0\n",
-                       pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
-                       pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
-                       pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
-                       texture );
+       /* get plane */
+       plane = &bspPlanes[ side->planeNum ];
+
+       /* make plane points */
+       {
+               vec3_t vecs[ 2 ];
+
+
+               MakeNormalVectors( plane->normal, vecs[ 0 ], vecs[ 1 ] );
+               VectorMA( vec3_origin, plane->dist, plane->normal, pts[ 0 ] );
+               VectorMA( pts[ 0 ], 256.0f, vecs[ 0 ], pts[ 1 ] );
+               VectorMA( pts[ 0 ], 256.0f, vecs[ 1 ], pts[ 2 ] );
        }
        }
+
+       /* offset by origin */
+       for ( j = 0; j < 3; j++ )
+               VectorAdd( pts[ j ], origin, pts[ j ] );
+
+       /* print brush side */
+       /* ( 640 24 -224 ) ( 448 24 -224 ) ( 448 -232 -224 ) common/caulk 0 48 0 0.500000 0.500000 0 0 0 */
+       fprintf( f, "\t\t( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) ( %.3f %.3f %.3f ) %s 0 0 0 0.5 0.5 0 0 0\n",
+                        pts[ 0 ][ 0 ], pts[ 0 ][ 1 ], pts[ 0 ][ 2 ],
+                        pts[ 1 ][ 0 ], pts[ 1 ][ 1 ], pts[ 1 ][ 2 ],
+                        pts[ 2 ][ 0 ], pts[ 2 ][ 1 ], pts[ 2 ][ 2 ],
+                        texture );
+}
 #endif
 
 
 
 /*
 #endif
 
 
 
 /*
-ConvertPatch()
-converts a bsp patch to a map patch
+   ConvertPatch()
+   converts a bsp patch to a map patch
+
+    {
+        patchDef2
+        {
+            base_wall/concrete
+            ( 9 3 0 0 0 )
+            (
+                ( ( 168 168 -192 0 2 ) ( 168 168 -64 0 1 ) ( 168 168 64 0 0 ) ... )
+                ...
+            )
+        }
+    }
+
+ */
+
+static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin ){
+       int x, y;
+       bspShader_t     *shader;
+       char            *texture;
+       bspDrawVert_t   *dv;
+       vec3_t xyz;
 
 
-       {
-               patchDef2
-               {
-                       base_wall/concrete
-                       ( 9 3 0 0 0 )
-                       (
-                               ( ( 168 168 -192 0 2 ) ( 168 168 -64 0 1 ) ( 168 168 64 0 0 ) ... )
-                               ...
-                       )
-               }
-       }
 
 
-*/
-
-static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin )
-{
-       int                             x, y;
-       bspShader_t             *shader;
-       char                    *texture;
-       bspDrawVert_t   *dv;
-       vec3_t                  xyz;
-       
-       
        /* only patches */
        /* only patches */
-       if( ds->surfaceType != MST_PATCH )
+       if ( ds->surfaceType != MST_PATCH ) {
                return;
                return;
-       
+       }
+
        /* get shader */
        /* get shader */
-       if( ds->shaderNum < 0 || ds->shaderNum >= numBSPShaders )
+       if ( ds->shaderNum < 0 || ds->shaderNum >= numBSPShaders ) {
                return;
                return;
+       }
        shader = &bspShaders[ ds->shaderNum ];
        shader = &bspShaders[ ds->shaderNum ];
-       
+
        /* get texture name */
        /* get texture name */
-       if( !Q_strncasecmp( shader->shader, "textures/", 9 ) )
+       if ( !Q_strncasecmp( shader->shader, "textures/", 9 ) ) {
                texture = shader->shader + 9;
                texture = shader->shader + 9;
-       else
+       }
+       else{
                texture = shader->shader;
                texture = shader->shader;
-       
+       }
+
        /* start patch */
        fprintf( f, "\t// patch %d\n", num );
        fprintf( f, "\t{\n" );
        /* start patch */
        fprintf( f, "\t// patch %d\n", num );
        fprintf( f, "\t{\n" );
@@ -241,30 +252,30 @@ static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin
        fprintf( f, "\t\t\t%s\n", texture );
        fprintf( f, "\t\t\t( %d %d 0 0 0 )\n", ds->patchWidth, ds->patchHeight );
        fprintf( f, "\t\t\t(\n" );
        fprintf( f, "\t\t\t%s\n", texture );
        fprintf( f, "\t\t\t( %d %d 0 0 0 )\n", ds->patchWidth, ds->patchHeight );
        fprintf( f, "\t\t\t(\n" );
-       
+
        /* iterate through the verts */
        /* iterate through the verts */
-       for( x = 0; x < ds->patchWidth; x++ )
+       for ( x = 0; x < ds->patchWidth; x++ )
        {
                /* start row */
                fprintf( f, "\t\t\t\t(" );
        {
                /* start row */
                fprintf( f, "\t\t\t\t(" );
-               
+
                /* iterate through the row */
                /* iterate through the row */
-               for( y = 0; y < ds->patchHeight; y++ )
+               for ( y = 0; y < ds->patchHeight; y++ )
                {
                        /* get vert */
                {
                        /* get vert */
-                       dv = &bspDrawVerts[ ds->firstVert + (y * ds->patchWidth) + x ];
-                       
+                       dv = &bspDrawVerts[ ds->firstVert + ( y * ds->patchWidth ) + x ];
+
                        /* offset it */
                        VectorAdd( origin, dv->xyz, xyz );
                        /* offset it */
                        VectorAdd( origin, dv->xyz, xyz );
-                       
+
                        /* print vertex */
                        fprintf( f, " ( %f %f %f %f %f )", xyz[ 0 ], xyz[ 1 ], xyz[ 2 ], dv->st[ 0 ], dv->st[ 1 ] );
                }
                        /* print vertex */
                        fprintf( f, " ( %f %f %f %f %f )", xyz[ 0 ], xyz[ 1 ], xyz[ 2 ], dv->st[ 0 ], dv->st[ 1 ] );
                }
-               
+
                /* end row */
                fprintf( f, " )\n" );
        }
                /* end row */
                fprintf( f, " )\n" );
        }
-       
+
        /* end patch */
        fprintf( f, "\t\t\t)\n" );
        fprintf( f, "\t\t}\n" );
        /* end patch */
        fprintf( f, "\t\t\t)\n" );
        fprintf( f, "\t\t}\n" );
@@ -274,78 +285,79 @@ static void ConvertPatch( FILE *f, int num, bspDrawSurface_t *ds, vec3_t origin
 
 
 /*
 
 
 /*
-ConvertModel()
-exports a bsp model to a map file
-*/
+   ConvertModel()
+   exports a bsp model to a map file
+ */
+
+static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, vec3_t origin ){
+       int i, num;
+       bspBrush_t          *brush;
+       bspDrawSurface_t    *ds;
+
 
 
-static void ConvertModel( FILE *f, bspModel_t *model, int modelNum, vec3_t origin )
-{
-       int                                     i, num;
-       bspBrush_t                      *brush;
-       bspDrawSurface_t        *ds;
-       
-       
        /* convert bsp planes to map planes */
        nummapplanes = numBSPPlanes;
        /* convert bsp planes to map planes */
        nummapplanes = numBSPPlanes;
-       for( i = 0; i < numBSPPlanes; i++ )
+       for ( i = 0; i < numBSPPlanes; i++ )
        {
                VectorCopy( bspPlanes[ i ].normal, mapplanes[ i ].normal );
                mapplanes[ i ].dist = bspPlanes[ i ].dist;
                mapplanes[ i ].type = PlaneTypeForNormal( mapplanes[ i ].normal );
                mapplanes[ i ].hash_chain = NULL;
        }
        {
                VectorCopy( bspPlanes[ i ].normal, mapplanes[ i ].normal );
                mapplanes[ i ].dist = bspPlanes[ i ].dist;
                mapplanes[ i ].type = PlaneTypeForNormal( mapplanes[ i ].normal );
                mapplanes[ i ].hash_chain = NULL;
        }
-       
+
        /* allocate a build brush */
        buildBrush = AllocBrush( 512 );
        buildBrush->entityNum = 0;
        buildBrush->original = buildBrush;
        /* allocate a build brush */
        buildBrush = AllocBrush( 512 );
        buildBrush->entityNum = 0;
        buildBrush->original = buildBrush;
-       
+
        /* go through each brush in the model */
        /* go through each brush in the model */
-       for( i = 0; i < model->numBSPBrushes; i++ )
+       for ( i = 0; i < model->numBSPBrushes; i++ )
        {
                num = i + model->firstBSPBrush;
                brush = &bspBrushes[ num ];
                ConvertBrush( f, num, brush, origin );
        }
        {
                num = i + model->firstBSPBrush;
                brush = &bspBrushes[ num ];
                ConvertBrush( f, num, brush, origin );
        }
-       
+
        /* free the build brush */
        free( buildBrush );
        /* free the build brush */
        free( buildBrush );
-       
+
        /* go through each drawsurf in the model */
        /* go through each drawsurf in the model */
-       for( i = 0; i < model->numBSPSurfaces; i++ )
+       for ( i = 0; i < model->numBSPSurfaces; i++ )
        {
                num = i + model->firstBSPSurface;
                ds = &bspDrawSurfaces[ num ];
        {
                num = i + model->firstBSPSurface;
                ds = &bspDrawSurfaces[ num ];
-               
+
                /* we only love patches */
                /* we only love patches */
-               if( ds->surfaceType == MST_PATCH )
+               if ( ds->surfaceType == MST_PATCH ) {
                        ConvertPatch( f, num, ds, origin );
                        ConvertPatch( f, num, ds, origin );
+               }
        }
 }
 
 
 
 /*
        }
 }
 
 
 
 /*
-ConvertEPairs()
-exports entity key/value pairs to a map file
-*/
+   ConvertEPairs()
+   exports entity key/value pairs to a map file
+ */
+
+static void ConvertEPairs( FILE *f, entity_t *e ){
+       epair_t *ep;
+
 
 
-static void ConvertEPairs( FILE *f, entity_t *e )
-{
-       epair_t *ep;
-       
-       
        /* walk epairs */
        /* walk epairs */
-       for( ep = e->epairs; ep != NULL; ep = ep->next )
+       for ( ep = e->epairs; ep != NULL; ep = ep->next )
        {
                /* ignore empty keys/values */
        {
                /* ignore empty keys/values */
-               if( ep->key[ 0 ] == '\0' || ep->value[ 0 ] == '\0' )
+               if ( ep->key[ 0 ] == '\0' || ep->value[ 0 ] == '\0' ) {
                        continue;
                        continue;
+               }
 
                /* ignore model keys with * prefixed values */
 
                /* ignore model keys with * prefixed values */
-               if( !Q_stricmp( ep->key, "model" ) && ep->value[ 0 ] == '*' )
+               if ( !Q_stricmp( ep->key, "model" ) && ep->value[ 0 ] == '*' ) {
                        continue;
                        continue;
-               
+               }
+
                /* emit the epair */
                fprintf( f, "\t\"%s\" \"%s\"\n", ep->key, ep->value );
        }
                /* emit the epair */
                fprintf( f, "\t\"%s\" \"%s\"\n", ep->key, ep->value );
        }
@@ -354,91 +366,95 @@ static void ConvertEPairs( FILE *f, entity_t *e )
 
 
 /*
 
 
 /*
-ConvertBSPToMap()
-exports an quake map file from the bsp
-*/
+   ConvertBSPToMap()
+   exports an quake map file from the bsp
+ */
+
+int ConvertBSPToMap( char *bspName ){
+       int i, modelNum;
+       FILE            *f;
+       bspModel_t      *model;
+       entity_t        *e;
+       vec3_t origin;
+       const char      *value;
+       char name[ 1024 ], base[ 1024 ];
+
 
 
-int ConvertBSPToMap( char *bspName )
-{
-       int                             i, modelNum;
-       FILE                    *f;
-       bspModel_t              *model;
-       entity_t                *e;
-       vec3_t                  origin;
-       const char              *value;
-       char                    name[ 1024 ], base[ 1024 ];
-       
-       
        /* note it */
        Sys_Printf( "--- Convert BSP to MAP ---\n" );
        /* note it */
        Sys_Printf( "--- Convert BSP to MAP ---\n" );
-       
+
        /* create the bsp filename from the bsp name */
        strcpy( name, bspName );
        StripExtension( name );
        strcat( name, "_converted.map" );
        Sys_Printf( "writing %s\n", name );
        /* create the bsp filename from the bsp name */
        strcpy( name, bspName );
        StripExtension( name );
        strcat( name, "_converted.map" );
        Sys_Printf( "writing %s\n", name );
-       
+
        ExtractFileBase( bspName, base );
        strcat( base, ".bsp" );
        ExtractFileBase( bspName, base );
        strcat( base, ".bsp" );
-       
+
        /* open it */
        f = fopen( name, "wb" );
        /* open it */
        f = fopen( name, "wb" );
-       if( f == NULL )
+       if ( f == NULL ) {
                Error( "Open failed on %s\n", name );
                Error( "Open failed on %s\n", name );
-       
+       }
+
        /* print header */
        fprintf( f, "// Generated by Q3Map2 (ydnar) -convert -format map\n" );
        /* print header */
        fprintf( f, "// Generated by Q3Map2 (ydnar) -convert -format map\n" );
-       
+
        /* walk entity list */
        /* walk entity list */
-       for( i = 0; i < numEntities; i++ )
+       for ( i = 0; i < numEntities; i++ )
        {
                /* get entity */
                e = &entities[ i ];
        {
                /* get entity */
                e = &entities[ i ];
-               
+
                /* start entity */
                fprintf( f, "// entity %d\n", i );
                fprintf( f, "{\n" );
                /* start entity */
                fprintf( f, "// entity %d\n", i );
                fprintf( f, "{\n" );
-               
+
                /* export keys */
                ConvertEPairs( f, e );
                fprintf( f, "\n" );
                /* export keys */
                ConvertEPairs( f, e );
                fprintf( f, "\n" );
-               
+
                /* get model num */
                /* get model num */
-               if( i == 0 )
+               if ( i == 0 ) {
                        modelNum = 0;
                        modelNum = 0;
+               }
                else
                {
                        value = ValueForKey( e, "model" );
                else
                {
                        value = ValueForKey( e, "model" );
-                       if( value[ 0 ] == '*' )
+                       if ( value[ 0 ] == '*' ) {
                                modelNum = atoi( value + 1 );
                                modelNum = atoi( value + 1 );
-                       else
+                       }
+                       else{
                                modelNum = -1;
                                modelNum = -1;
+                       }
                }
                }
-               
+
                /* only handle bsp models */
                /* only handle bsp models */
-               if( modelNum >= 0 )
-               {
+               if ( modelNum >= 0 ) {
                        /* get model */
                        model = &bspModels[ modelNum ];
                        /* get model */
                        model = &bspModels[ modelNum ];
-                       
+
                        /* get entity origin */
                        value = ValueForKey( e, "origin" );
                        /* get entity origin */
                        value = ValueForKey( e, "origin" );
-                       if( value[ 0 ] == '\0' )
+                       if ( value[ 0 ] == '\0' ) {
                                VectorClear( origin );
                                VectorClear( origin );
-                       else
+                       }
+                       else{
                                GetVectorForKey( e, "origin", origin );
                                GetVectorForKey( e, "origin", origin );
-                       
+                       }
+
                        /* convert model */
                        ConvertModel( f, model, modelNum, origin );
                }
                        /* convert model */
                        ConvertModel( f, model, modelNum, origin );
                }
-               
+
                /* end entity */
                fprintf( f, "}\n\n" );
        }
                /* end entity */
                fprintf( f, "}\n\n" );
        }
-       
+
        /* close the file and return */
        fclose( f );
        /* close the file and return */
        fclose( f );
-       
+
        /* return to sender */
        return 0;
 }
        /* return to sender */
        return 0;
 }