]> git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Merge branch 'master' into divVerent/colormod
authorRudolf Polzer <divverent@alientrap.org>
Mon, 14 May 2012 18:56:23 +0000 (20:56 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 14 May 2012 18:56:23 +0000 (20:56 +0200)
Conflicts:
tools/quake3/q3map2/model.c

1  2 
tools/quake3/q3map2/map.c
tools/quake3/q3map2/model.c
tools/quake3/q3map2/q3map2.h
tools/quake3/q3map2/surface.c
tools/quake3/q3map2/surface_foliage.c

index 9e1924455b6d5614e17db270899a9a81b7172b48,d786fc541190ea692d4d7d0ffb521514d020af33..36b45e04b923375790eff27d932663e72952b7be
@@@ -55,15 -55,14 +55,14 @@@ int                                                c_structural
  
  
  /*
- PlaneEqual()
- ydnar: replaced with variable epsilon for djbob
- */
   PlaneEqual()
   ydnar: replaced with variable epsilon for djbob
 */
  
- qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist )
- {
+ qboolean PlaneEqual( plane_t *p, vec3_t normal, vec_t dist ){
 -      float ne, de;
 -
 -
 +      float   ne, de;
 +      
 +      
        /* get local copies */
        ne = normalEpsilon;
        de = distanceEpsilon;
        // (the epsilons may be zero).  We want to use '<' intead of '<=' to be
        // consistent with the true meaning of "epsilon", and also because other
        // parts of the code uses this inequality.
-       if ((p->dist == dist || fabs(p->dist - dist) < de) &&
-                       (p->normal[0] == normal[0] || fabs(p->normal[0] - normal[0]) < ne) &&
-                       (p->normal[1] == normal[1] || fabs(p->normal[1] - normal[1]) < ne) &&
-                       (p->normal[2] == normal[2] || fabs(p->normal[2] - normal[2]) < ne))
+       if ( ( p->dist == dist || fabs( p->dist - dist ) < de ) &&
+                ( p->normal[0] == normal[0] || fabs( p->normal[0] - normal[0] ) < ne ) &&
+                ( p->normal[1] == normal[1] || fabs( p->normal[1] - normal[1] ) < ne ) &&
+                ( p->normal[2] == normal[2] || fabs( p->normal[2] - normal[2] ) < ne ) ) {
                return qtrue;
 -
+       }
 +      
        /* different */
        return qfalse;
  }
  
  
  /*
- AddPlaneToHash()
- */
   AddPlaneToHash()
 */
  
- void AddPlaneToHash( plane_t *p )
- {
+ void AddPlaneToHash( plane_t *p ){
 -      int hash;
 -
 +      int             hash;
  
-       hash = (PLANE_HASHES - 1) & (int) fabs( p->dist );
 +      
+       hash = ( PLANE_HASHES - 1 ) & (int) fabs( p->dist );
  
        p->hash_chain = planehash[hash];
        planehash[hash] = p - mapplanes + 1;
  }
  
  /*
- ================
- CreateNewFloatPlane
- ================
- */
- int CreateNewFloatPlane (vec3_t normal, vec_t dist)
- {
+    ================
+    CreateNewFloatPlane
+    ================
+  */
+ int CreateNewFloatPlane( vec3_t normal, vec_t dist ){
 -      plane_t *p, temp;
 +      plane_t *p, temp;
  
-       if (VectorLength(normal) < 0.5)
-       {
-               Sys_Printf( "FloatPlane: bad normal\n");
+       if ( VectorLength( normal ) < 0.5 ) {
+               Sys_Printf( "FloatPlane: bad normal\n" );
                return -1;
        }
  
  
  
  /*
- SnapNormal()
- Snaps a near-axial normal vector.
- Returns qtrue if and only if the normal was adjusted.
- */
   SnapNormal()
   Snaps a near-axial normal vector.
   Returns qtrue if and only if the normal was adjusted.
 */
  
- qboolean SnapNormal( vec3_t normal )
- {
+ qboolean SnapNormal( vec3_t normal ){
  #if Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX
 -      int i;
 -      qboolean adjusted = qfalse;
 +      int             i;
 +      qboolean        adjusted = qfalse;
  
        // A change from the original SnapNormal() is that we snap each
        // component that's close to 0.  So for example if a normal is
        // normalized).  The original SnapNormal() didn't snap such vectors - it
        // only snapped vectors that were near a perfect axis.
  
-       for (i = 0; i < 3; i++)
-       {
-               if (normal[i] != 0.0 && -normalEpsilon < normal[i] && normal[i] < normalEpsilon)
+       for ( i = 0; i < 3; i++ )
 -      {
 +              {
+               if ( normal[i] != 0.0 && -normalEpsilon < normal[i] && normal[i] < normalEpsilon ) {
                        normal[i] = 0.0;
                        adjusted = qtrue;
                }
        // We may consider adjusting the epsilon to a larger value when we make this
        // code fix.
  
-       for( i = 0; i < 3; i++ )
-       {
-               if( fabs( normal[ i ] - 1 ) < normalEpsilon )
+       for ( i = 0; i < 3; i++ )
 -      {
 +              {
+               if ( fabs( normal[ i ] - 1 ) < normalEpsilon ) {
                        VectorClear( normal );
                        normal[ i ] = 1;
                        return qtrue;
@@@ -253,9 -242,9 +242,9 @@@ void SnapPlane( vec3_t normal, vec_t *d
  // brushes made from triangles of embedded models, and it has little effect
  // on anything else (axial planes are usually derived from snapped points)
  /*
 -   SnapPlane reenabled by namespace because of multiple reports of
 -   q3map2-crashes which were triggered by this patch.
 +  SnapPlane reenabled by namespace because of multiple reports of
 +  q3map2-crashes which were triggered by this patch.
- */
 */
        SnapNormal( normal );
  
        // TODO: Rambetter has some serious comments here as well.  First off,
  }
  
  /*
- SnapPlaneImproved()
- snaps a plane to normal/distance epsilons, improved code
- */
- void SnapPlaneImproved(vec3_t normal, vec_t *dist, int numPoints, const vec3_t *points)
- {
+    SnapPlaneImproved()
+    snaps a plane to normal/distance epsilons, improved code
+  */
+ void SnapPlaneImproved( vec3_t normal, vec_t *dist, int numPoints, const vec3_t *points ){
 -      int i;
 -      vec3_t center;
 -      vec_t distNearestInt;
 +      int     i;
 +      vec3_t  center;
 +      vec_t   distNearestInt;
  
-       if (SnapNormal(normal))
-       {
-               if (numPoints > 0)
-               {
+       if ( SnapNormal( normal ) ) {
+               if ( numPoints > 0 ) {
                        // Adjust the dist so that the provided points don't drift away.
-                       VectorClear(center);
-                       for (i = 0; i < numPoints; i++)
+                       VectorClear( center );
+                       for ( i = 0; i < numPoints; i++ )
                        {
-                               VectorAdd(center, points[i], center);
+                               VectorAdd( center, points[i], center );
                        }
-                       for (i = 0; i < 3; i++) { center[i] = center[i] / numPoints; }
-                       *dist = DotProduct(normal, center);
+                       for ( i = 0; i < 3; i++ ) { center[i] = center[i] / numPoints; }
+                       *dist = DotProduct( normal, center );
                }
        }
  
@@@ -333,38 -318,39 +318,39 @@@ int FindFloatPlane( vec3_t innormal, ve
  #ifdef USE_HASHING
  
  {
 -      int i, j, hash, h;
 +      int             i, j, hash, h;
        int pidx;
 -      plane_t *p;
 -      vec_t d;
 +      plane_t *p;
 +      vec_t   d;
        vec3_t normal;
  
-       VectorCopy(innormal, normal);
+       VectorCopy( innormal, normal );
  #if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
-       SnapPlaneImproved(normal, &dist, numPoints, (const vec3_t *) points);
+       SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
  #else
        SnapPlane( normal, &dist );
  #endif
        /* hash the plane */
-       hash = (PLANE_HASHES - 1) & (int) fabs( dist );
+       hash = ( PLANE_HASHES - 1 ) & (int) fabs( dist );
 -
 +      
        /* search the border bins as well */
-       for( i = -1; i <= 1; i++ )
+       for ( i = -1; i <= 1; i++ )
        {
-               h = (hash + i) & (PLANE_HASHES - 1);
-               for( pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 )
+               h = ( hash + i ) & ( PLANE_HASHES - 1 );
+               for ( pidx = planehash[ h ] - 1; pidx != -1; pidx = mapplanes[pidx].hash_chain - 1 )
                {
                        p = &mapplanes[pidx];
  
                        /* do standard plane compare */
-                       if( !PlaneEqual( p, normal, dist ) )
+                       if ( !PlaneEqual( p, normal, dist ) ) {
                                continue;
 -
+                       }
 +                      
                        /* ydnar: uncomment the following line for old-style plane finding */
                        //%     return p - mapplanes;
 -
 +                      
                        /* ydnar: test supplied points against this plane */
-                       for( j = 0; j < numPoints; j++ )
+                       for ( j = 0; j < numPoints; j++ )
                        {
                                // NOTE: When dist approaches 2^16, the resolution of 32 bit floating
                                // point number is greatly decreased.  The distanceEpsilon cannot be
                                // dot product here in 64 bit land will not really help the situation
                                // because the error will already be carried in dist.
                                d = DotProduct( points[ j ], p->normal ) - p->dist;
-                               d = fabs(d);
-                               if (d != 0.0 && d >= distanceEpsilon)
+                               d = fabs( d );
+                               if ( d != 0.0 && d >= distanceEpsilon ) {
                                        break; // Point is too far from plane.
 -                              }
                        }
 -
++                      }
 +                      
                        /* found a matching plane */
-                       if( j >= numPoints )
+                       if ( j >= numPoints ) {
                                return p - mapplanes;
 -                      }
                }
        }
 -
++      }
 +      
        /* none found, so create a new one */
        return CreateNewFloatPlane( normal, dist );
  }
  #else
  
  {
 -      int i;
 -      plane_t *p;
 +      int             i;
 +      plane_t *p;
        vec3_t normal;
 -
 +      
-       VectorCopy(innormal, normal);
+       VectorCopy( innormal, normal );
  #if Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX
-       SnapPlaneImproved(normal, &dist, numPoints, (const vec3_t *) points);
+       SnapPlaneImproved( normal, &dist, numPoints, (const vec3_t *) points );
  #else
 -      SnapPlane( normal, &dist );
 +      SnapPlane( normal, &dist );
  #endif
-       for( i = 0, p = mapplanes; i < nummapplanes; i++, p++ )
+       for ( i = 0, p = mapplanes; i < nummapplanes; i++, p++ )
        {
-               if( !PlaneEqual( p, normal, dist ) )
+               if ( !PlaneEqual( p, normal, dist ) ) {
                        continue;
+               }
  
                /* ydnar: uncomment the following line for old-style plane finding */
                //%     return i;
 -
 +                      
                /* ydnar: test supplied points against this plane */
-               for( j = 0; j < numPoints; j++ )
+               for ( j = 0; j < numPoints; j++ )
                {
                        d = DotProduct( points[ j ], p->normal ) - p->dist;
-                       if( fabs( d ) > distanceEpsilon )
+                       if ( fabs( d ) > distanceEpsilon ) {
                                break;
 -                      }
                }
 -
++              }
 +              
                /* found a matching plane */
-               if( j >= numPoints )
+               if ( j >= numPoints ) {
                        return i;
+               }
                // TODO: Note that the non-USE_HASHING code does not compute epsilons
                // for the provided points.  It should do that.  I think this code
                // is unmaintained because nobody sets USE_HASHING to off.
  
  
  /*
- MapPlaneFromPoints()
- takes 3 points and finds the plane they lie in
- */
   MapPlaneFromPoints()
   takes 3 points and finds the plane they lie in
 */
  
- int MapPlaneFromPoints( vec3_t *p )
- {
+ int MapPlaneFromPoints( vec3_t *p ){
  #if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES
 -      vec3_accu_t paccu[3];
 -      vec3_accu_t t1, t2, normalAccu;
 -      vec3_t normal;
 -      vec_t dist;
 +      vec3_accu_t     paccu[3];
 +      vec3_accu_t     t1, t2, normalAccu;
 +      vec3_t          normal;
 +      vec_t           dist;
  
-       VectorCopyRegularToAccu(p[0], paccu[0]);
-       VectorCopyRegularToAccu(p[1], paccu[1]);
-       VectorCopyRegularToAccu(p[2], paccu[2]);
+       VectorCopyRegularToAccu( p[0], paccu[0] );
+       VectorCopyRegularToAccu( p[1], paccu[1] );
+       VectorCopyRegularToAccu( p[2], paccu[2] );
  
-       VectorSubtractAccu(paccu[0], paccu[1], t1);
-       VectorSubtractAccu(paccu[2], paccu[1], t2);
-       CrossProductAccu(t1, t2, normalAccu);
-       VectorNormalizeAccu(normalAccu, normalAccu);
+       VectorSubtractAccu( paccu[0], paccu[1], t1 );
+       VectorSubtractAccu( paccu[2], paccu[1], t2 );
+       CrossProductAccu( t1, t2, normalAccu );
+       VectorNormalizeAccu( normalAccu, normalAccu );
        // TODO: A 32 bit float for the plane distance isn't enough resolution
        // if the plane is 2^16 units away from the origin (the "epsilon" approaches
        // 0.01 in that case).
-       dist = (vec_t) DotProductAccu(paccu[0], normalAccu);
-       VectorCopyAccuToRegular(normalAccu, normal);
+       dist = (vec_t) DotProductAccu( paccu[0], normalAccu );
+       VectorCopyAccuToRegular( normalAccu, normal );
  
-       return FindFloatPlane(normal, dist, 3, p);
+       return FindFloatPlane( normal, dist, 3, p );
  #else
 -      vec3_t t1, t2, normal;
 -      vec_t dist;
 -
 -
 +      vec3_t  t1, t2, normal;
 +      vec_t   dist;
 +      
 +      
        /* calc plane normal */
        VectorSubtract( p[ 0 ], p[ 1 ], t1 );
        VectorSubtract( p[ 2 ], p[ 1 ], t2 );
  
  
  /*
- SetBrushContents()
- the content flags and compile flags on all sides of a brush should be the same
- */
   SetBrushContents()
   the content flags and compile flags on all sides of a brush should be the same
 */
  
- void SetBrushContents( brush_t *b )
- {
+ void SetBrushContents( brush_t *b ){
 -      int contentFlags, compileFlags;
 -      side_t      *s;
 -      int i;
 +      int                     contentFlags, compileFlags;
 +      side_t          *s;
 +      int                     i;
        //%     qboolean        mixed;
 -
 -
 +      
 +      
        /* get initial compile flags from first side */
        s = &b->sides[ 0 ];
        contentFlags = s->contentFlags;
        compileFlags = s->compileFlags;
        b->contentShader = s->shaderInfo;
        //%     mixed = qfalse;
 -
 +      
        /* get the content/compile flags for every side in the brush */
-       for( i = 1; i < b->numsides; i++, s++ )
+       for ( i = 1; i < b->numsides; i++, s++ )
        {
                s = &b->sides[ i ];
-               if( s->shaderInfo == NULL )
+               if ( s->shaderInfo == NULL ) {
                        continue;
+               }
                //%     if( s->contentFlags != contentFlags || s->compileFlags != compileFlags )
                //%             mixed = qtrue;
  
                xml_Select( "Mixed detail and structural (defaulting to structural)", mapEnt->mapEntityNum, entitySourceBrushes, qfalse );
                compileFlags &= ~C_DETAIL;
        }
 -
 +      
        /* the fulldetail flag will cause detail brushes to be treated like normal brushes */
-       if( fulldetail )
+       if ( fulldetail ) {
                compileFlags &= ~C_DETAIL;
 -
+       }
 +      
        /* all translucent brushes that aren't specifically made structural will be detail */
-       if( (compileFlags & C_TRANSLUCENT) && !(compileFlags & C_STRUCTURAL) )
+       if ( ( compileFlags & C_TRANSLUCENT ) && !( compileFlags & C_STRUCTURAL ) ) {
                compileFlags |= C_DETAIL;
 -
+       }
 +      
        /* detail? */
-       if( compileFlags & C_DETAIL )
-       {
+       if ( compileFlags & C_DETAIL ) {
                c_detail++;
                b->detail = qtrue;
        }
                c_structural++;
                b->detail = qfalse;
        }
 -
 +      
        /* opaque? */
-       if( compileFlags & C_TRANSLUCENT )
+       if ( compileFlags & C_TRANSLUCENT ) {
                b->opaque = qfalse;
-       else
+       }
+       else{
                b->opaque = qtrue;
 -
+       }
 +      
        /* areaportal? */
-       if( compileFlags & C_AREAPORTAL )
+       if ( compileFlags & C_AREAPORTAL ) {
                c_areaportals++;
 -
+       }
 +      
        /* set brush flags */
        b->contentFlags = contentFlags;
        b->compileFlags = compileFlags;
  
  
  /*
- AddBrushBevels()
- adds any additional planes necessary to allow the brush being
- built to be expanded against axial bounding boxes
- ydnar 2003-01-20: added mrelusive fixes
- */
   AddBrushBevels()
   adds any additional planes necessary to allow the brush being
   built to be expanded against axial bounding boxes
   ydnar 2003-01-20: added mrelusive fixes
 */
  
- void AddBrushBevels( void )
- {
+ void AddBrushBevels( void ){
 -      int axis, dir;
 -      int i, j, k, l, order;
 -      side_t sidetemp;
 -      side_t      *s, *s2;
 -      winding_t   *w, *w2;
 -      vec3_t normal;
 -      float dist;
 -      vec3_t vec, vec2;
 -      float d, minBack;
 +      int                     axis, dir;
 +      int                     i, j, k, l, order;
 +      side_t          sidetemp;
 +      side_t          *s, *s2;
 +      winding_t       *w, *w2;
 +      vec3_t          normal;
 +      float           dist;
 +      vec3_t          vec, vec2;
 +      float           d, minBack;
  
        //
        // add the axial planes
                        {
                                /* ydnar: testing disabling of mre code */
                                #if 0
 -                              if ( dir > 0 ) {
 -                                      if ( mapplanes[s->planenum].normal[axis] >= 0.9999f ) {
 -                                              break;
 +                                      if ( dir > 0 ) {
 +                                              if ( mapplanes[s->planenum].normal[axis] >= 0.9999f ) {
 +                                                      break;
 +                                              }
                                        }
 -                              }
 -                              else {
 -                                      if ( mapplanes[s->planenum].normal[axis] <= -0.9999f ) {
 -                                              break;
 +                                      else {
 +                                              if ( mapplanes[s->planenum].normal[axis] <= -0.9999f ) {
 +                                                      break;
 +                                              }
                                        }
 -                              }
                                #else
-                                       if( (dir > 0 && mapplanes[ s->planenum ].normal[ axis ] == 1.0f ) ||
-                                               (dir < 0 && mapplanes[ s->planenum ].normal[ axis ] == -1.0f) )
+                               if ( ( dir > 0 && mapplanes[ s->planenum ].normal[ axis ] == 1.0f ) ||
+                                        ( dir < 0 && mapplanes[ s->planenum ].normal[ axis ] == -1.0f ) ) {
 -                                      break;
 +                                              break;
+                               }
                                #endif
                        }
  
                                }
                                memset( s, 0, sizeof( *s ) );
                                buildBrush->numsides++;
-                               VectorClear (normal);
+                               VectorClear( normal );
                                normal[axis] = dir;
  
-                               if( dir == 1 )
-                               {
+                               if ( dir == 1 ) {
                                        /* ydnar: adding bevel plane snapping for fewer bsp planes */
-                                       if( bevelSnap > 0 )
+                                       if ( bevelSnap > 0 ) {
                                                dist = floor( buildBrush->maxs[ axis ] / bevelSnap ) * bevelSnap;
-                                       else
+                                       }
+                                       else{
                                                dist = buildBrush->maxs[ axis ];
 -                                      }
 +                              }
+                               }
                                else
                                {
                                        /* ydnar: adding bevel plane snapping for fewer bsp planes */
-                                       if( bevelSnap > 0 )
+                                       if ( bevelSnap > 0 ) {
                                                dist = -ceil( buildBrush->mins[ axis ] / bevelSnap ) * bevelSnap;
-                                       else
+                                       }
+                                       else{
                                                dist = -buildBrush->mins[ axis ];
 -                                      }
 +                              }
+                               }
  
                                s->planenum = FindFloatPlane( normal, dist, 0, NULL );
                                s->contentFlags = buildBrush->sides[ 0 ].contentFlags;
                        }
                        SnapNormal( vec );
                        for ( k = 0; k < 3; k++ ) {
-                               if ( vec[k] == -1.0f || vec[k] == 1.0f || (vec[k] == 0.0f && vec[(k+1)%3] == 0.0f) ) {
+                               if ( vec[k] == -1.0f || vec[k] == 1.0f || ( vec[k] == 0.0f && vec[( k + 1 ) % 3] == 0.0f ) ) {
 -                                      break;  // axial
 +                                      break;  // axial
                                }
                        }
                        if ( k != 3 ) {
                                        }
  
                                        if ( k != buildBrush->numsides ) {
 -                                              continue;   // wasn't part of the outer hull
 +                                              continue;       // wasn't part of the outer hull
                                        }
 -
 +                                      
                                        /* debug code */
                                        //%     Sys_Printf( "n = %f %f %f\n", normal[ 0 ], normal[ 1 ], normal[ 2 ] );
 -
 +                                      
                                        // add this plane
-                                       if( buildBrush->numsides == MAX_BUILD_SIDES ) {
-                                               xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue);
+                                       if ( buildBrush->numsides == MAX_BUILD_SIDES ) {
+                                               xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
                                        }
                                        s2 = &buildBrush->sides[buildBrush->numsides];
                                        buildBrush->numsides++;
@@@ -771,92 -766,88 +766,88 @@@ static void MergeOrigin( entity_t *ent
        /* we have not parsed the brush completely yet... */
        GetVectorForKey( ent, "origin", ent->origin );
  
-       VectorMA(origin, -1, ent->originbrush_origin, adjustment);
-       VectorAdd(adjustment, ent->origin, ent->origin);
-       VectorCopy(origin, ent->originbrush_origin);
+       VectorMA( origin, -1, ent->originbrush_origin, adjustment );
+       VectorAdd( adjustment, ent->origin, ent->origin );
+       VectorCopy( origin, ent->originbrush_origin );
  
-       sprintf(string, "%f %f %f", ent->origin[0], ent->origin[1], ent->origin[2]);
-       SetKeyValue(ent, "origin", string);
+       sprintf( string, "%f %f %f", ent->origin[0], ent->origin[1], ent->origin[2] );
+       SetKeyValue( ent, "origin", string );
  }
  
- brush_t *FinishBrush( qboolean noCollapseGroups )
- {
+ brush_t *FinishBrush( qboolean noCollapseGroups ){
 -      brush_t     *b;
 -
 -
 +      brush_t         *b;
 +      
 +      
        /* create windings for sides and bounds for brush */
-       if ( !CreateBrushWindings( buildBrush ) )
+       if ( !CreateBrushWindings( buildBrush ) ) {
                return NULL;
+       }
  
        /* origin brushes are removed, but they set the rotation origin for the rest of the brushes in the entity.
           after the entire entity is parsed, the planenums and texinfos will be adjusted for the origin brush */
-       if( buildBrush->compileFlags & C_ORIGIN )
-       {
+       if ( buildBrush->compileFlags & C_ORIGIN ) {
 -              vec3_t origin;
 +              vec3_t  origin;
  
 -              Sys_Printf( "Entity %i, Brush %i: origin brush detected\n",
 -                                      mapEnt->mapEntityNum, entitySourceBrushes );
 +              Sys_Printf( "Entity %i, Brush %i: origin brush detected\n", 
 +                              mapEnt->mapEntityNum, entitySourceBrushes );
  
-               if( numEntities == 1 )
-               {
+               if ( numEntities == 1 ) {
 -                      Sys_Printf( "Entity %i, Brush %i: origin brushes not allowed in world\n",
 -                                              mapEnt->mapEntityNum, entitySourceBrushes );
 +                      Sys_Printf( "Entity %i, Brush %i: origin brushes not allowed in world\n", 
 +                              mapEnt->mapEntityNum, entitySourceBrushes );
                        return NULL;
                }
 -
 +              
-               VectorAdd (buildBrush->mins, buildBrush->maxs, origin);
-               VectorScale (origin, 0.5, origin);
+               VectorAdd( buildBrush->mins, buildBrush->maxs, origin );
+               VectorScale( origin, 0.5, origin );
  
-               MergeOrigin(&entities[ numEntities - 1 ], origin);
+               MergeOrigin( &entities[ numEntities - 1 ], origin );
  
                /* don't keep this brush */
                return NULL;
        }
 -
 +      
        /* determine if the brush is an area portal */
-       if( buildBrush->compileFlags & C_AREAPORTAL )
-       {
-               if( numEntities != 1 )
-               {
-                       Sys_Printf ("Entity %i, Brush %i: areaportals only allowed in world\n", numEntities - 1, entitySourceBrushes );
+       if ( buildBrush->compileFlags & C_AREAPORTAL ) {
+               if ( numEntities != 1 ) {
+                       Sys_Printf( "Entity %i, Brush %i: areaportals only allowed in world\n", numEntities - 1, entitySourceBrushes );
                        return NULL;
                }
        }
 -
 +      
        /* add bevel planes */
-       if(!noCollapseGroups)
+       if ( !noCollapseGroups ) {
                AddBrushBevels();
 -
+       }
 +      
        /* keep it */
        b = CopyBrush( buildBrush );
 -
 +      
        /* set map entity and brush numbering */
        b->entityNum = mapEnt->mapEntityNum;
        b->brushNum = entitySourceBrushes;
 -
 +      
        /* set original */
        b->original = b;
 -
 +      
        /* link opaque brushes to head of list, translucent brushes to end */
-       if( b->opaque || mapEnt->lastBrush == NULL )
-       {
+       if ( b->opaque || mapEnt->lastBrush == NULL ) {
                b->next = mapEnt->brushes;
                mapEnt->brushes = b;
-               if( mapEnt->lastBrush == NULL )
+               if ( mapEnt->lastBrush == NULL ) {
                        mapEnt->lastBrush = b;
 -              }
 +      }
+       }
        else
        {
                b->next = NULL;
                mapEnt->lastBrush->next = b;
                mapEnt->lastBrush = b;
        }
 -
 +      
        /* link colorMod volume brushes to the entity directly */
-       if( b->contentShader != NULL &&
+       if ( b->contentShader != NULL &&
 -               b->contentShader->colorMod != NULL &&
 +              b->contentShader->colorMod != NULL &&
-               b->contentShader->colorMod->type == CM_VOLUME )
-       {
+                b->contentShader->colorMod->type == CM_VOLUME ) {
                b->nextColorModBrush = mapEnt->colorModBrushes;
                mapEnt->colorModBrushes = b;
        }
  
  
  /*
- TextureAxisFromPlane()
- determines best orthagonal axis to project a texture onto a wall
- (must be identical in radiant!)
- */
   TextureAxisFromPlane()
   determines best orthagonal axis to project a texture onto a wall
   (must be identical in radiant!)
 */
  
 -vec3_t baseaxis[18] =
 +vec3_t        baseaxis[18] =
  {
 -      {0,0,1}, {1,0,0}, {0,-1,0},         // floor
 -      {0,0,-1}, {1,0,0}, {0,-1,0},        // ceiling
 -      {1,0,0}, {0,1,0}, {0,0,-1},         // west wall
 -      {-1,0,0}, {0,1,0}, {0,0,-1},        // east wall
 -      {0,1,0}, {1,0,0}, {0,0,-1},         // south wall
 -      {0,-1,0}, {1,0,0}, {0,0,-1}         // north wall
 +      {0,0,1}, {1,0,0}, {0,-1,0},                     // floor
 +      {0,0,-1}, {1,0,0}, {0,-1,0},            // ceiling
 +      {1,0,0}, {0,1,0}, {0,0,-1},                     // west wall
 +      {-1,0,0}, {0,1,0}, {0,0,-1},            // east wall
 +      {0,1,0}, {1,0,0}, {0,0,-1},                     // south wall
 +      {0,-1,0}, {1,0,0}, {0,0,-1}                     // north wall
  };
  
- void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv )
- {
+ void TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv ){
 -      int bestaxis;
 -      vec_t dot,best;
 -      int i;
 -
 +      int             bestaxis;
 +      vec_t   dot,best;
 +      int             i;
 +      
        best = 0;
        bestaxis = 0;
 -
 +      
-       for (i=0 ; i<6 ; i++)
-       {
-               dot = DotProduct (pln->normal, baseaxis[i*3]);
-               if( dot > best + 0.0001f )      /* ydnar: bug 637 fix, suggested by jmonroe */
+       for ( i = 0 ; i < 6 ; i++ )
 -      {
 +              {
+               dot = DotProduct( pln->normal, baseaxis[i * 3] );
+               if ( dot > best + 0.0001f ) { /* ydnar: bug 637 fix, suggested by jmonroe */
                        best = dot;
                        bestaxis = i;
                }
        }
 -
 +      
-       VectorCopy (baseaxis[bestaxis*3+1], xv);
-       VectorCopy (baseaxis[bestaxis*3+2], yv);
+       VectorCopy( baseaxis[bestaxis * 3 + 1], xv );
+       VectorCopy( baseaxis[bestaxis * 3 + 2], yv );
  }
  
  
  
  /*
- QuakeTextureVecs()
- creates world-to-texture mapping vecs for crappy quake plane arrangements
- */
   QuakeTextureVecs()
   creates world-to-texture mapping vecs for crappy quake plane arrangements
 */
  
- void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t scale[ 2 ], vec_t mappingVecs[ 2 ][ 4 ] )
- {
+ void QuakeTextureVecs( plane_t *plane, vec_t shift[ 2 ], vec_t rotate, vec_t scale[ 2 ], vec_t mappingVecs[ 2 ][ 4 ] ){
 -      vec3_t vecs[2];
 -      int sv, tv;
 -      vec_t ang, sinv, cosv;
 -      vec_t ns, nt;
 -      int i, j;
 -
 -
 +      vec3_t  vecs[2];
 +      int             sv, tv;
 +      vec_t   ang, sinv, cosv;
 +      vec_t   ns, nt;
 +      int             i, j;
 +      
 +      
-       TextureAxisFromPlane(plane, vecs[0], vecs[1]);
+       TextureAxisFromPlane( plane, vecs[0], vecs[1] );
 -
 +      
-       if (!scale[0])
+       if ( !scale[0] ) {
                scale[0] = 1;
-       if (!scale[1])
+       }
+       if ( !scale[1] ) {
                scale[1] = 1;
+       }
  
        // rotate axis
-       if (rotate == 0)
-               { sinv = 0 ; cosv = 1; }
-       else if (rotate == 90)
-               { sinv = 1 ; cosv = 0; }
-       else if (rotate == 180)
-               { sinv = 0 ; cosv = -1; }
-       else if (rotate == 270)
-               { sinv = -1 ; cosv = 0; }
+       if ( rotate == 0 ) {
+               sinv = 0 ; cosv = 1;
+       }
+       else if ( rotate == 90 ) {
+               sinv = 1 ; cosv = 0;
+       }
+       else if ( rotate == 180 ) {
+               sinv = 0 ; cosv = -1;
+       }
+       else if ( rotate == 270 ) {
+               sinv = -1 ; cosv = 0;
+       }
        else
 -      {
 +      {       
                ang = rotate / 180 * Q_PI;
-               sinv = sin(ang);
-               cosv = cos(ang);
+               sinv = sin( ang );
+               cosv = cos( ang );
        }
  
-       if (vecs[0][0])
+       if ( vecs[0][0] ) {
                sv = 0;
-       else if (vecs[0][1])
+       }
+       else if ( vecs[0][1] ) {
                sv = 1;
-       else
+       }
+       else{
                sv = 2;
 -
+       }
-       if (vecs[1][0])
 +                              
+       if ( vecs[1][0] ) {
                tv = 0;
-       else if (vecs[1][1])
+       }
+       else if ( vecs[1][1] ) {
                tv = 1;
-       else
+       }
+       else{
                tv = 2;
 -
+       }
-       for (i=0 ; i<2 ; i++) {
 +                                      
+       for ( i = 0 ; i < 2 ; i++ ) {
                ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
                nt = sinv * vecs[i][sv] +  cosv * vecs[i][tv];
                vecs[i][sv] = ns;
  
  
  /*
- ParseRawBrush()
- parses the sides into buildBrush->sides[], nothing else.
- no validation, back plane removal, etc.
- Timo - 08/26/99
- added brush epairs parsing ( ignoring actually )
- Timo - 08/04/99
- added exclusive brush primitive parsing
- Timo - 08/08/99
- support for old brush format back in
- NOTE: it would be "cleaner" to have seperate functions to parse between old and new brushes
- */
- static void ParseRawBrush( qboolean onlyLights )
- {
+    ParseRawBrush()
+    parses the sides into buildBrush->sides[], nothing else.
+    no validation, back plane removal, etc.
+    Timo - 08/26/99
+    added brush epairs parsing ( ignoring actually )
+    Timo - 08/04/99
+    added exclusive brush primitive parsing
+    Timo - 08/08/99
+    support for old brush format back in
+    NOTE: it would be "cleaner" to have seperate functions to parse between old and new brushes
+  */
+ static void ParseRawBrush( qboolean onlyLights ){
 -      side_t          *side;
 -      vec3_t planePoints[ 3 ];
 -      int planenum;
 -      shaderInfo_t    *si;
 -      vec_t shift[ 2 ];
 -      vec_t rotate = 0;
 -      vec_t scale[ 2 ];
 -      char name[ MAX_QPATH ];
 -      char shader[ MAX_QPATH ];
 -      int flags;
 -
 -
 +      side_t                  *side;
 +      vec3_t                  planePoints[ 3 ];
 +      int                             planenum;
 +      shaderInfo_t    *si;
 +      vec_t                   shift[ 2 ];
 +      vec_t                   rotate = 0;
 +      vec_t                   scale[ 2 ];
 +      char                    name[ MAX_QPATH ];
 +      char                    shader[ MAX_QPATH ];
 +      int                             flags;
 +      
 +      
        /* initial setup */
        buildBrush->numsides = 0;
        buildBrush->detail = qfalse;
 -
 +      
        /* bp */
-       if( g_bBrushPrimit == BPRIMIT_NEWBRUSHES )
+       if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                MatchToken( "{" );
 -
+       }
 +      
        /* parse sides */
-       while( 1 )
+       while ( 1 )
        {
-               if( !GetToken( qtrue ) )
+               if ( !GetToken( qtrue ) ) {
                        break;
-               if( !strcmp( token, "}" ) )
+               }
+               if ( !strcmp( token, "}" ) ) {
                        break;
 -
+               }
 +               
                /* ttimo : bp: here we may have to jump over brush epairs (only used in editor) */
-               if( g_bBrushPrimit == BPRIMIT_NEWBRUSHES )
-               {
-                       while( 1 )
+               if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
+                       while ( 1 )
                        {
-                               if( strcmp( token, "(" ) )
+                               if ( strcmp( token, "(" ) ) {
                                        GetToken( qfalse );
-                               else
+                               }
+                               else{
                                        break;
+                               }
                                GetToken( qtrue );
                        }
                }
                UnGetToken();
 -
 +              
                /* test side count */
-               if( buildBrush->numsides >= MAX_BUILD_SIDES )
+               if ( buildBrush->numsides >= MAX_BUILD_SIDES ) {
                        xml_Select( "MAX_BUILD_SIDES", buildBrush->entityNum, buildBrush->brushNum, qtrue );
 -
+               }
 +              
                /* add side */
                side = &buildBrush->sides[ buildBrush->numsides ];
                memset( side, 0, sizeof( *side ) );
                Parse1DMatrix( 3, planePoints[ 0 ] );
                Parse1DMatrix( 3, planePoints[ 1 ] );
                Parse1DMatrix( 3, planePoints[ 2 ] );
 -
 +              
                /* bp: read the texture matrix */
-               if( g_bBrushPrimit == BPRIMIT_NEWBRUSHES )
+               if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                        Parse2DMatrix( 2, 3, (float*) side->texMat );
 -
+               }
 +              
                /* read shader name */
                GetToken( qfalse );
                strcpy( name, token );
 -
 +              
                /* bp */
-               if( g_bBrushPrimit == BPRIMIT_OLDBRUSHES )
-               {
+               if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                        GetToken( qfalse );
                        shift[ 0 ] = atof( token );
                        GetToken( qfalse );
                        GetToken( qfalse );
                        scale[ 1 ] = atof( token );
                }
 -
 +              
                /* set default flags and values */
                sprintf( shader, "textures/%s", name );
-               if( onlyLights )
+               if ( onlyLights ) {
                        si = &shaderInfo[ 0 ];
-               else
+               }
+               else{
                        si = ShaderInfoForShader( shader );
+               }
                side->shaderInfo = si;
                side->surfaceFlags = si->surfaceFlags;
                side->contentFlags = si->contentFlags;
                side->compileFlags = si->compileFlags;
                side->value = si->value;
 -
 +              
                /* ydnar: gs mods: bias texture shift */
-               if( si->globalTexture == qfalse )
-               {
-                       shift[ 0 ] -= (floor( shift[ 0 ] / si->shaderWidth ) * si->shaderWidth);
-                       shift[ 1 ] -= (floor( shift[ 1 ] / si->shaderHeight ) * si->shaderHeight);
+               if ( si->globalTexture == qfalse ) {
+                       shift[ 0 ] -= ( floor( shift[ 0 ] / si->shaderWidth ) * si->shaderWidth );
+                       shift[ 1 ] -= ( floor( shift[ 1 ] / si->shaderHeight ) * si->shaderHeight );
                }
 -
 +              
                /*
 -                  historically, there are 3 integer values at the end of a brushside line in a .map file.
 -                  in quake 3, the only thing that mattered was the first of these three values, which
 -                  was previously the content flags. and only then did a single bit matter, the detail
 -                  bit. because every game has its own special flags for specifying detail, the
 -                  traditionally game-specified CONTENTS_DETAIL flag was overridden for Q3Map 2.3.0
 -                  by C_DETAIL, defined in q3map2.h. the value is exactly as it was before, but
 -                  is stored in compileFlags, as opposed to contentFlags, for multiple-game
 -                  portability. :sigh:
 -               */
 -
 +                      historically, there are 3 integer values at the end of a brushside line in a .map file.
 +                      in quake 3, the only thing that mattered was the first of these three values, which
 +                      was previously the content flags. and only then did a single bit matter, the detail
 +                      bit. because every game has its own special flags for specifying detail, the
 +                      traditionally game-specified CONTENTS_DETAIL flag was overridden for Q3Map 2.3.0
 +                      by C_DETAIL, defined in q3map2.h. the value is exactly as it was before, but
 +                      is stored in compileFlags, as opposed to contentFlags, for multiple-game
 +                      portability. :sigh:
 +              */
 +              
-               if( TokenAvailable() )
-               {
+               if ( TokenAvailable() ) {
                        /* get detail bit from map content flags */
                        GetToken( qfalse );
                        flags = atoi( token );
-                       if( flags & C_DETAIL )
+                       if ( flags & C_DETAIL ) {
                                side->compileFlags |= C_DETAIL;
 -
+                       }
 +                      
                        /* historical */
                        GetToken( qfalse );
                        //% td.flags = atoi( token );
                /* find the plane number */
                planenum = MapPlaneFromPoints( planePoints );
                side->planenum = planenum;
 -
 +              
                /* bp: get the texture mapping for this texturedef / plane combination */
-               if( g_bBrushPrimit == BPRIMIT_OLDBRUSHES )
+               if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                        QuakeTextureVecs( &mapplanes[ planenum ], shift, rotate, scale, side->vecs );
 -              }
        }
 -
++      }
 +      
        /* bp */
-       if( g_bBrushPrimit == BPRIMIT_NEWBRUSHES )
-       {
+       if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                UnGetToken();
                MatchToken( "}" );
                MatchToken( "}" );
  
  
  /*
- RemoveDuplicateBrushPlanes
- returns false if the brush has a mirrored set of planes,
- meaning it encloses no volume.
- also removes planes without any normal
- */
   RemoveDuplicateBrushPlanes
   returns false if the brush has a mirrored set of planes,
   meaning it encloses no volume.
   also removes planes without any normal
 */
  
- qboolean RemoveDuplicateBrushPlanes( brush_t *b )
- {
+ qboolean RemoveDuplicateBrushPlanes( brush_t *b ){
 -      int i, j, k;
 -      side_t      *sides;
 +      int                     i, j, k;
 +      side_t          *sides;
  
        sides = b->sides;
  
        for ( i = 1 ; i < b->numsides ; i++ ) {
  
                // check for a degenerate plane
-               if ( sides[i].planenum == -1) {
+               if ( sides[i].planenum == -1 ) {
 -                      xml_Select( "degenerate plane", b->entityNum, b->brushNum, qfalse );
 +                xml_Select( "degenerate plane", b->entityNum, b->brushNum, qfalse );
                        // remove it
                        for ( k = i + 1 ; k < b->numsides ; k++ ) {
-                               sides[k-1] = sides[k];
+                               sides[k - 1] = sides[k];
                        }
                        b->numsides--;
                        i--;
                // check for duplication and mirroring
                for ( j = 0 ; j < i ; j++ ) {
                        if ( sides[i].planenum == sides[j].planenum ) {
 -                              xml_Select( "duplicate plane", b->entityNum, b->brushNum, qfalse );
 +                        xml_Select( "duplicate plane", b->entityNum, b->brushNum, qfalse );
                                // remove the second duplicate
                                for ( k = i + 1 ; k < b->numsides ; k++ ) {
-                                       sides[k-1] = sides[k];
+                                       sides[k - 1] = sides[k];
                                }
                                b->numsides--;
                                i--;
                                break;
                        }
  
-                       if ( sides[i].planenum == (sides[j].planenum ^ 1) ) {
+                       if ( sides[i].planenum == ( sides[j].planenum ^ 1 ) ) {
                                // mirror plane, brush is invalid
 -                              xml_Select( "mirrored plane", b->entityNum, b->brushNum, qfalse );
 +                        xml_Select( "mirrored plane", b->entityNum, b->brushNum, qfalse );
                                return qfalse;
                        }
                }
  
  
  /*
- ParseBrush()
- parses a brush out of a map file and sets it up
- */
   ParseBrush()
   parses a brush out of a map file and sets it up
 */
  
- static void ParseBrush( qboolean onlyLights, qboolean noCollapseGroups )
- {
+ static void ParseBrush( qboolean onlyLights, qboolean noCollapseGroups ){
        /* parse the brush out of the map */
        ParseRawBrush( onlyLights );
 -
 +      
        /* only go this far? */
-       if( onlyLights )
+       if ( onlyLights ) {
                return;
 -
+       }
 +      
        /* set some defaults */
        buildBrush->portalareas[ 0 ] = -1;
        buildBrush->portalareas[ 1 ] = -1;
        buildBrush->entityNum = numMapEntities - 1;
        buildBrush->brushNum = entitySourceBrushes;
 -
 +      
        /* if there are mirrored planes, the entire brush is invalid */
-       if( !RemoveDuplicateBrushPlanes( buildBrush ) )
+       if ( !RemoveDuplicateBrushPlanes( buildBrush ) ) {
                return;
 -
+       }
 +      
        /* get the content for the entire brush */
        SetBrushContents( buildBrush );
 -
 +      
        /* allow detail brushes to be removed */
-       if( nodetail && (buildBrush->compileFlags & C_DETAIL) )
-       {
+       if ( nodetail && ( buildBrush->compileFlags & C_DETAIL ) ) {
                //%     FreeBrush( buildBrush );
                return;
        }
 -
 +      
        /* allow liquid brushes to be removed */
-       if( nowater && (buildBrush->compileFlags & C_LIQUID ) )
-       {
+       if ( nowater && ( buildBrush->compileFlags & C_LIQUID ) ) {
                //%     FreeBrush( buildBrush );
                return;
        }
 -
 +      
        /* ydnar: allow hint brushes to be removed */
-       if( noHint && (buildBrush->compileFlags & C_HINT) )
-       {
+       if ( noHint && ( buildBrush->compileFlags & C_HINT ) ) {
                //%     FreeBrush( buildBrush );
                return;
        }
 -
 +      
        /* finish the brush */
-       FinishBrush(noCollapseGroups);
+       FinishBrush( noCollapseGroups );
  }
  
  
  
  /*
- MoveBrushesToWorld()
- takes all of the brushes from the current entity and
- adds them to the world's brush list
- (used by func_group)
- */
   MoveBrushesToWorld()
   takes all of the brushes from the current entity and
   adds them to the world's brush list
   (used by func_group)
 */
  
  void AdjustBrushesForOrigin( entity_t *ent );
- void MoveBrushesToWorld( entity_t *ent )
- {
+ void MoveBrushesToWorld( entity_t *ent ){
 -      brush_t     *b, *next;
 -      parseMesh_t *pm;
 +      brush_t         *b, *next;
 +      parseMesh_t     *pm;
  
        /* we need to undo the common/origin adjustment, and instead shift them by the entity key origin */
-       VectorScale(ent->origin, -1, ent->originbrush_origin);
-       AdjustBrushesForOrigin(ent);
-       VectorClear(ent->originbrush_origin);
+       VectorScale( ent->origin, -1, ent->originbrush_origin );
+       AdjustBrushesForOrigin( ent );
+       VectorClear( ent->originbrush_origin );
 -
 +      
        /* move brushes */
-       for( b = ent->brushes; b != NULL; b = next )
+       for ( b = ent->brushes; b != NULL; b = next )
        {
                /* get next brush */
                next = b->next;
 -
 +              
                /* link opaque brushes to head of list, translucent brushes to end */
-               if( b->opaque || entities[ 0 ].lastBrush == NULL )
-               {
+               if ( b->opaque || entities[ 0 ].lastBrush == NULL ) {
                        b->next = entities[ 0 ].brushes;
                        entities[ 0 ].brushes = b;
-                       if( entities[ 0 ].lastBrush == NULL )
+                       if ( entities[ 0 ].lastBrush == NULL ) {
                                entities[ 0 ].lastBrush = b;
 -                      }
 +              }
+               }
                else
                {
                        b->next = NULL;
                }
        }
        ent->brushes = NULL;
 -
 +      
        /* ydnar: move colormod brushes */
-       if( ent->colorModBrushes != NULL )
-       {
-               for( b = ent->colorModBrushes; b->nextColorModBrush != NULL; b = b->nextColorModBrush );
+       if ( ent->colorModBrushes != NULL ) {
+               for ( b = ent->colorModBrushes; b->nextColorModBrush != NULL; b = b->nextColorModBrush ) ;
 -
 +              
                b->nextColorModBrush = entities[ 0 ].colorModBrushes;
                entities[ 0 ].colorModBrushes = ent->colorModBrushes;
 -
 +              
                ent->colorModBrushes = NULL;
        }
 -
 +      
        /* move patches */
-       if( ent->patches != NULL )
-       {
-               for( pm = ent->patches; pm->next != NULL; pm = pm->next );
+       if ( ent->patches != NULL ) {
+               for ( pm = ent->patches; pm->next != NULL; pm = pm->next ) ;
 -
 +              
                pm->next = entities[ 0 ].patches;
                entities[ 0 ].patches = ent->patches;
 -
 +              
                ent->patches = NULL;
        }
  }
  
  
  /*
- AdjustBrushesForOrigin()
- */
   AdjustBrushesForOrigin()
 */
  
- void AdjustBrushesForOrigin( entity_t *ent )
- {
+ void AdjustBrushesForOrigin( entity_t *ent ){
 -
 -      int i;
 -      side_t      *s;
 -      vec_t newdist;
 -      brush_t     *b;
 -      parseMesh_t *p;
 -
 +      
 +      int                     i;
 +      side_t          *s;
 +      vec_t           newdist;
 +      brush_t         *b;
 +      parseMesh_t     *p;
 +      
        /* walk brush list */
-       for( b = ent->brushes; b != NULL; b = b->next )
+       for ( b = ent->brushes; b != NULL; b = b->next )
        {
                /* offset brush planes */
-               for( i = 0; i < b->numsides; i++)
+               for ( i = 0; i < b->numsides; i++ )
                {
                        /* get brush side */
                        s = &b->sides[ i ];
                /* rebuild brush windings (ydnar: just offsetting the winding above should be fine) */
                CreateBrushWindings( b );
        }
 -
 +      
        /* walk patch list */
-       for( p = ent->patches; p != NULL; p = p->next )
+       for ( p = ent->patches; p != NULL; p = p->next )
        {
-               for( i = 0; i < (p->mesh.width * p->mesh.height); i++ )
+               for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
                        VectorSubtract( p->mesh.verts[ i ].xyz, ent->originbrush_origin, p->mesh.verts[ i ].xyz );
        }
  }
  
  
  /*
- SetEntityBounds() - ydnar
- finds the bounds of an entity's brushes (necessary for terrain-style generic metashaders)
- */
   SetEntityBounds() - ydnar
   finds the bounds of an entity's brushes (necessary for terrain-style generic metashaders)
 */
  
- void SetEntityBounds( entity_t *e )
- {
+ void SetEntityBounds( entity_t *e ){
 -      int i;
 -      brush_t *b;
 -      parseMesh_t *p;
 -      vec3_t mins, maxs;
 -      const char  *value;
 -
 -
 +      int                     i;
 +      brush_t *b;
 +      parseMesh_t     *p;
 +      vec3_t          mins, maxs;
 +      const char      *value;
  
 +      
 +      
  
        /* walk the entity's brushes/patches and determine bounds */
        ClearBounds( mins, maxs );
                AddPointToBounds( b->mins, mins, maxs );
                AddPointToBounds( b->maxs, mins, maxs );
        }
-       for( p = e->patches; p; p = p->next )
+       for ( p = e->patches; p; p = p->next )
        {
-               for( i = 0; i < (p->mesh.width * p->mesh.height); i++ )
+               for ( i = 0; i < ( p->mesh.width * p->mesh.height ); i++ )
                        AddPointToBounds( p->mesh.verts[ i ].xyz, mins, maxs );
        }
 -
 +      
        /* try to find explicit min/max key */
 -      value = ValueForKey( e, "min" );
 +      value = ValueForKey( e, "min" ); 
-       if( value[ 0 ] != '\0' )
+       if ( value[ 0 ] != '\0' ) {
                GetVectorForKey( e, "min", mins );
 -      value = ValueForKey( e, "max" );
+       }
-       if( value[ 0 ] != '\0' )
 +      value = ValueForKey( e, "max" ); 
+       if ( value[ 0 ] != '\0' ) {
                GetVectorForKey( e, "max", maxs );
 -
+       }
 +      
        /* store the bounds */
-       for( b = e->brushes; b; b = b->next )
+       for ( b = e->brushes; b; b = b->next )
        {
                VectorCopy( mins, b->eMins );
                VectorCopy( maxs, b->eMaxs );
  
  
  /*
- LoadEntityIndexMap() - ydnar
- based on LoadAlphaMap() from terrain.c, a little more generic
- */
   LoadEntityIndexMap() - ydnar
   based on LoadAlphaMap() from terrain.c, a little more generic
 */
  
- void LoadEntityIndexMap( entity_t *e )
- {
+ void LoadEntityIndexMap( entity_t *e ){
 -      int i, size, numLayers, w, h;
 -      const char      *value, *indexMapFilename, *shader;
 -      char ext[ MAX_QPATH ], offset[ 4096 ], *search, *space;
 -      byte            *pixels;
 -      unsigned int    *pixels32;
 -      indexMap_t      *im;
 -      brush_t         *b;
 -      parseMesh_t     *p;
 -
 -
 +      int                             i, size, numLayers, w, h;
 +      const char              *value, *indexMapFilename, *shader;
 +      char                    ext[ MAX_QPATH ], offset[ 4096 ], *search, *space;
 +      byte                    *pixels;
 +      unsigned int    *pixels32;
 +      indexMap_t              *im;
 +      brush_t                 *b;
 +      parseMesh_t             *p;
 +      
 +      
        /* this only works with bmodel ents */
-       if( e->brushes == NULL && e->patches == NULL )
+       if ( e->brushes == NULL && e->patches == NULL ) {
                return;
 -
+       }
 +      
        /* determine if there is an index map (support legacy "alphamap" key as well) */
        value = ValueForKey( e, "_indexmap" );
-       if( value[ 0 ] == '\0' )
+       if ( value[ 0 ] == '\0' ) {
                value = ValueForKey( e, "alphamap" );
-       if( value[ 0 ] == '\0' )
+       }
+       if ( value[ 0 ] == '\0' ) {
                return;
+       }
        indexMapFilename = value;
 -
 +      
        /* get number of layers (support legacy "layers" key as well) */
        value = ValueForKey( e, "_layers" );
-       if( value[ 0 ] == '\0' )
+       if ( value[ 0 ] == '\0' ) {
                value = ValueForKey( e, "layers" );
-       if( value[ 0 ] == '\0' )
-       {
+       }
+       if ( value[ 0 ] == '\0' ) {
                Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" has missing \"_layers\" or \"layers\" key\n", indexMapFilename );
                Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
                return;
                Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
                return;
        }
 -
 +      
        /* get base shader name (support legacy "shader" key as well) */
        value = ValueForKey( mapEnt, "_shader" );
-       if( value[ 0 ] == '\0' )
+       if ( value[ 0 ] == '\0' ) {
                value = ValueForKey( e, "shader" );
-       if( value[ 0 ] == '\0' )
-       {
+       }
+       if ( value[ 0 ] == '\0' ) {
                Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" has missing \"_shader\" or \"shader\" key\n", indexMapFilename );
                Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
                return;
        }
        shader = value;
 -
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "Entity %d (%s) has shader index map \"%s\"\n",  mapEnt->mapEntityNum, ValueForKey( e, "classname" ), indexMapFilename );
 -
 +      
        /* get index map file extension */
        ExtractFileExtension( indexMapFilename, ext );
 -
 +      
        /* handle tga image */
-       if( !Q_stricmp( ext, "tga" ) )
-       {
+       if ( !Q_stricmp( ext, "tga" ) ) {
                /* load it */
                Load32BitImage( indexMapFilename, &pixels32, &w, &h );
 -
 +              
                /* convert to bytes */
                size = w * h;
                pixels = safe_malloc( size );
-               for( i = 0; i < size; i++ )
+               for ( i = 0; i < size; i++ )
                {
-                       pixels[ i ] = ((pixels32[ i ] & 0xFF) * numLayers) / 256;
-                       if( pixels[ i ] >= numLayers )
+                       pixels[ i ] = ( ( pixels32[ i ] & 0xFF ) * numLayers ) / 256;
+                       if ( pixels[ i ] >= numLayers ) {
                                pixels[ i ] = numLayers - 1;
 -                      }
                }
 -
++              }
 +              
                /* free the 32 bit image */
                free( pixels32 );
        }
        {
                /* load it */
                Load256Image( indexMapFilename, &pixels, NULL, &w, &h );
 -
 +              
                /* debug code */
                //%     Sys_Printf( "-------------------------------" );
 -
 +              
                /* fix up out-of-range values */
                size = w * h;
-               for( i = 0; i < size; i++ )
+               for ( i = 0; i < size; i++ )
                {
-                       if( pixels[ i ] >= numLayers )
+                       if ( pixels[ i ] >= numLayers ) {
                                pixels[ i ] = numLayers - 1;
 -
+                       }
 +                      
                        /* debug code */
                        //%     if( (i % w) == 0 )
                        //%             Sys_Printf( "\n" );
                /* debug code */
                //%     Sys_Printf( "\n-------------------------------\n" );
        }
 -
 +      
        /* the index map must be at least 2x2 pixels */
-       if( w < 2 || h < 2 )
-       {
+       if ( w < 2 || h < 2 ) {
                Sys_Printf( "WARNING: Entity with index/alpha map \"%s\" is smaller than 2x2 pixels\n", indexMapFilename );
                Sys_Printf( "Entity will not be textured properly. Check your keys/values.\n" );
                free( pixels );
        strcpy( im->name, indexMapFilename );
        strcpy( im->shader, shader );
        im->pixels = pixels;
 -
 +      
        /* get height offsets */
        value = ValueForKey( mapEnt, "_offsets" );
-       if( value[ 0 ] == '\0' )
+       if ( value[ 0 ] == '\0' ) {
                value = ValueForKey( e, "offsets" );
-       if( value[ 0 ] != '\0' )
-       {
+       }
+       if ( value[ 0 ] != '\0' ) {
                /* value is a space-seperated set of numbers */
                strcpy( offset, value );
                search = offset;
 -
 +              
                /* get each value */
-               for( i = 0; i < 256 && *search != '\0'; i++ )
+               for ( i = 0; i < 256 && *search != '\0'; i++ )
                {
                        space = strstr( search, " " );
-                       if( space != NULL )
+                       if ( space != NULL ) {
                                *space = '\0';
+                       }
                        im->offsets[ i ] = atof( search );
-                       if( space == NULL )
+                       if ( space == NULL ) {
                                break;
+                       }
                        search = space + 1;
                }
        }
 -
 +      
        /* store the index map in every brush/patch in the entity */
-       for( b = e->brushes; b != NULL; b = b->next )
+       for ( b = e->brushes; b != NULL; b = b->next )
                b->im = im;
-       for( p = e->patches; p != NULL; p = p->next )
+       for ( p = e->patches; p != NULL; p = p->next )
                p->im = im;
  }
  
  
  
  /*
- ParseMapEntity()
- parses a single entity out of a map file
- */
   ParseMapEntity()
   parses a single entity out of a map file
 */
  
- static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups )
- {
+ static qboolean ParseMapEntity( qboolean onlyLights, qboolean noCollapseGroups ){
 -      epair_t         *ep;
 -      const char      *classname, *value;
 -      float lightmapScale, shadeAngle;
 -      int lightmapSampleSize;
 -      char shader[ MAX_QPATH ];
 -      shaderInfo_t    *celShader = NULL;
 -      brush_t         *brush;
 -      parseMesh_t     *patch;
 -      qboolean funcGroup;
 -      int castShadows, recvShadows;
 -
 -
 +      epair_t                 *ep;
 +      const char              *classname, *value;
 +      float                   lightmapScale, shadeAngle;
 +      int                             lightmapSampleSize;
 +      char                    shader[ MAX_QPATH ];
 +      shaderInfo_t    *celShader = NULL;
 +      brush_t                 *brush;
 +      parseMesh_t             *patch;
 +      qboolean                funcGroup;
 +      int                             castShadows, recvShadows;
 +      vec3_t                  colormod;
 +      
 +      
        /* eof check */
-       if( !GetToken( qtrue ) )
+       if ( !GetToken( qtrue ) ) {
                return qfalse;
 -
+       }
 +      
        /* conformance check */
-       if( strcmp( token, "{" ) )
-       {
+       if ( strcmp( token, "{" ) ) {
                Sys_Printf( "WARNING: ParseEntity: { not found, found %s on line %d - last entity was at: <%4.2f, %4.2f, %4.2f>...\n"
 -                                      "Continuing to process map, but resulting BSP may be invalid.\n",
 -                                      token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] );
 +                      "Continuing to process map, but resulting BSP may be invalid.\n",
 +                      token, scriptline, entities[ numEntities ].origin[ 0 ], entities[ numEntities ].origin[ 1 ], entities[ numEntities ].origin[ 2 ] );
                return qfalse;
        }
 -
 +      
        /* range check */
-       if( numEntities >= MAX_MAP_ENTITIES )
-               Error( "numEntities == MAX_MAP_ENTITIES" );
+       AUTOEXPAND_BY_REALLOC( entities, numEntities, allocatedEntities, 32 );
 -
 +      
        /* setup */
        entitySourceBrushes = 0;
        mapEnt = &entities[ numEntities ];
        /* ydnar: true entity numbering */
        mapEnt->mapEntityNum = numMapEntities;
        numMapEntities++;
 -
 +      
        /* loop */
-       while( 1 )
+       while ( 1 )
        {
                /* get initial token */
-               if( !GetToken( qtrue ) )
-               {
+               if ( !GetToken( qtrue ) ) {
                        Sys_Printf( "WARNING: ParseEntity: EOF without closing brace\n"
 -                                              "Continuing to process map, but resulting BSP may be invalid.\n" );
 +                              "Continuing to process map, but resulting BSP may be invalid.\n" );
                        return qfalse;
                }
 -
 +              
-               if( !strcmp( token, "}" ) )
+               if ( !strcmp( token, "}" ) ) {
                        break;
 -
+               }
-               if( !strcmp( token, "{" ) )
-               {
 +              
+               if ( !strcmp( token, "{" ) ) {
                        /* parse a brush or patch */
-                       if( !GetToken( qtrue ) )
+                       if ( !GetToken( qtrue ) ) {
                                break;
 -
+                       }
 +                      
                        /* check */
-                       if( !strcmp( token, "patchDef2" ) )
-                       {
+                       if ( !strcmp( token, "patchDef2" ) ) {
                                numMapPatches++;
                                ParsePatch( onlyLights );
                        }
-                       else if( !strcmp( token, "terrainDef" ) )
-                       {
+                       else if ( !strcmp( token, "terrainDef" ) ) {
                                //% ParseTerrain();
 -                              Sys_Printf( "WARNING: Terrain entity parsing not supported in this build.\n" ); /* ydnar */
 +                              Sys_Printf( "WARNING: Terrain entity parsing not supported in this build.\n" ); /* ydnar */
                        }
-                       else if( !strcmp( token, "brushDef" ) )
-                       {
-                               if( g_bBrushPrimit == BPRIMIT_OLDBRUSHES )
+                       else if ( !strcmp( token, "brushDef" ) ) {
+                               if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                                        Error( "Old brush format not allowed in new brush format map" );
+                               }
                                g_bBrushPrimit = BPRIMIT_NEWBRUSHES;
 -
 +                              
                                /* parse brush primitive */
                                ParseBrush( onlyLights, noCollapseGroups );
                        }
                        else
                        {
-                               if( g_bBrushPrimit == BPRIMIT_NEWBRUSHES )
+                               if ( g_bBrushPrimit == BPRIMIT_NEWBRUSHES ) {
                                        Error( "New brush format not allowed in old brush format map" );
+                               }
                                g_bBrushPrimit = BPRIMIT_OLDBRUSHES;
 -
 +                              
                                /* parse old brush format */
                                UnGetToken();
                                ParseBrush( onlyLights, noCollapseGroups );
                {
                        /* parse a key / value pair */
                        ep = ParseEPair();
 -
 +                      
                        /* ydnar: 2002-07-06 fixed wolf bug with empty epairs */
-                       if( ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' )
-                       {
+                       if ( ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' ) {
                                ep->next = mapEnt->epairs;
                                mapEnt->epairs = ep;
                        }
                }
        }
 -
 +      
        /* ydnar: get classname */
        classname = ValueForKey( mapEnt, "classname" );
 -
 +      
        /* ydnar: only lights? */
-       if( onlyLights && Q_strncasecmp( classname, "light", 5 ) )
-       {
+       if ( onlyLights && Q_strncasecmp( classname, "light", 5 ) ) {
                numEntities--;
                return qtrue;
        }
 -
 +      
        /* ydnar: determine if this is a func_group */
-       if( !Q_stricmp( "func_group", classname ) )
+       if ( !Q_stricmp( "func_group", classname ) ) {
                funcGroup = qtrue;
-       else
+       }
+       else{
                funcGroup = qfalse;
 -
+       }
 +      
        /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
-       if( funcGroup || mapEnt->mapEntityNum == 0 )
-       {
+       if ( funcGroup || mapEnt->mapEntityNum == 0 ) {
                //%     Sys_Printf( "World:  %d\n", mapEnt->mapEntityNum );
                castShadows = WORLDSPAWN_CAST_SHADOWS;
                recvShadows = WORLDSPAWN_RECV_SHADOWS;
        /* vortex: added _ls key (short name of lightmapscale) */
        /* ydnar: get lightmap scaling value for this entity */
        lightmapScale = 0.0f;
-       if( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
+       if ( strcmp( "", ValueForKey( mapEnt, "lightmapscale" ) ) ||
 -               strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) ||
 +              strcmp( "", ValueForKey( mapEnt, "_lightmapscale" ) ) || 
-               strcmp( "", ValueForKey( mapEnt, "_ls" ) ) )
-       {
+                strcmp( "", ValueForKey( mapEnt, "_ls" ) ) ) {
                /* get lightmap scale from entity */
                lightmapScale = FloatForKey( mapEnt, "lightmapscale" );
-               if( lightmapScale <= 0.0f )
+               if ( lightmapScale <= 0.0f ) {
                        lightmapScale = FloatForKey( mapEnt, "_lightmapscale" );
-               if( lightmapScale <= 0.0f )
+               }
+               if ( lightmapScale <= 0.0f ) {
                        lightmapScale = FloatForKey( mapEnt, "_ls" );
-               if( lightmapScale < 0.0f )
+               }
+               if ( lightmapScale < 0.0f ) {
                        lightmapScale = 0.0f;
-               if( lightmapScale > 0.0f )
+               }
+               if ( lightmapScale > 0.0f ) {
                        Sys_Printf( "Entity %d (%s) has lightmap scale of %.4f\n", mapEnt->mapEntityNum, classname, lightmapScale );
 -              }
 +      }
+       }
  
 +      VectorClear(colormod);
 +      if( strcmp( "", ValueForKey( mapEnt, "_color" ) ) )
 +      {
 +              GetVectorForKey( mapEnt, "_color", colormod );
 +      }
 +      
        /* ydnar: get cel shader :) for this entity */
        value = ValueForKey( mapEnt, "_celshader" );
-       if( value[ 0 ] == '\0' )        
+       if ( value[ 0 ] == '\0' ) {
                value = ValueForKey( &entities[ 0 ], "_celshader" );
-       if( value[ 0 ] != '\0' )
-       {
-               if(strcmp(value, "none"))
-               {
+       }
+       if ( value[ 0 ] != '\0' ) {
+               if ( strcmp( value, "none" ) ) {
                        sprintf( shader, "textures/%s", value );
                        celShader = ShaderInfoForShader( shader );
                        Sys_Printf( "Entity %d (%s) has cel shader %s\n", mapEnt->mapEntityNum, classname, celShader->shader );
  
        /* jal : entity based _shadeangle */
        shadeAngle = 0.0f;
-       if ( strcmp( "", ValueForKey( mapEnt, "_shadeangle" ) ) )
+       if ( strcmp( "", ValueForKey( mapEnt, "_shadeangle" ) ) ) {
                shadeAngle = FloatForKey( mapEnt, "_shadeangle" );
+       }
        /* vortex' aliases */
-       else if ( strcmp( "", ValueForKey( mapEnt, "_smoothnormals" ) ) )
+       else if ( strcmp( "", ValueForKey( mapEnt, "_smoothnormals" ) ) ) {
                shadeAngle = FloatForKey( mapEnt, "_smoothnormals" );
-       else if ( strcmp( "", ValueForKey( mapEnt, "_sn" ) ) )
+       }
+       else if ( strcmp( "", ValueForKey( mapEnt, "_sn" ) ) ) {
                shadeAngle = FloatForKey( mapEnt, "_sn" );
-       else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) )
+       }
+       else if ( strcmp( "", ValueForKey( mapEnt, "_smooth" ) ) ) {
                shadeAngle = FloatForKey( mapEnt, "_smooth" );
 -
+       }
-       if( shadeAngle < 0.0f )
 +      
+       if ( shadeAngle < 0.0f ) {
                shadeAngle = 0.0f;
+       }
  
-       if( shadeAngle > 0.0f )
+       if ( shadeAngle > 0.0f ) {
                Sys_Printf( "Entity %d (%s) has shading angle of %.4f\n", mapEnt->mapEntityNum, classname, shadeAngle );
 -
+       }
 +      
        /* jal : entity based _samplesize */
        lightmapSampleSize = 0;
-       if ( strcmp( "", ValueForKey( mapEnt, "_lightmapsamplesize" ) ) )
+       if ( strcmp( "", ValueForKey( mapEnt, "_lightmapsamplesize" ) ) ) {
                lightmapSampleSize = IntForKey( mapEnt, "_lightmapsamplesize" );
-       else if ( strcmp( "", ValueForKey( mapEnt, "_samplesize" ) ) )
+       }
+       else if ( strcmp( "", ValueForKey( mapEnt, "_samplesize" ) ) ) {
                lightmapSampleSize = IntForKey( mapEnt, "_samplesize" );
 -
+       }
-       if( lightmapSampleSize < 0 )
 +      
+       if ( lightmapSampleSize < 0 ) {
                lightmapSampleSize = 0;
+       }
  
-       if( lightmapSampleSize > 0 )
+       if ( lightmapSampleSize > 0 ) {
                Sys_Printf( "Entity %d (%s) has lightmap sample size of %d\n", mapEnt->mapEntityNum, classname, lightmapSampleSize );
 -
+       }
 +      
        /* attach stuff to everything in the entity */
-       for( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
+       for ( brush = mapEnt->brushes; brush != NULL; brush = brush->next )
        {
                brush->entityNum = mapEnt->mapEntityNum;
                brush->castShadows = castShadows;
                brush->lightmapScale = lightmapScale;
                brush->celShader = celShader;
                brush->shadeAngleDegrees = shadeAngle;
 +              brush->colormod = colormod;
        }
 -
 +      
-       for( patch = mapEnt->patches; patch != NULL; patch = patch->next )
+       for ( patch = mapEnt->patches; patch != NULL; patch = patch->next )
        {
                patch->entityNum = mapEnt->mapEntityNum;
                patch->castShadows = castShadows;
                patch->lightmapSampleSize = lightmapSampleSize;
                patch->lightmapScale = lightmapScale;
                patch->celShader = celShader;
 +              patch->colormod = colormod;
        }
 -
 +      
        /* ydnar: gs mods: set entity bounds */
        SetEntityBounds( mapEnt );
 -
 +      
        /* ydnar: gs mods: load shader index map (equivalent to old terrain alphamap) */
        LoadEntityIndexMap( mapEnt );
 -
 +      
        /* get entity origin and adjust brushes */
        GetVectorForKey( mapEnt, "origin", mapEnt->origin );
-       if( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] )
+       if ( mapEnt->originbrush_origin[ 0 ] || mapEnt->originbrush_origin[ 1 ] || mapEnt->originbrush_origin[ 2 ] ) {
                AdjustBrushesForOrigin( mapEnt );
+       }
  
        /* group_info entities are just for editor grouping (fixme: leak!) */
-       if( !noCollapseGroups && !Q_stricmp( "group_info", classname ) )
-       {
+       if ( !noCollapseGroups && !Q_stricmp( "group_info", classname ) ) {
                numEntities--;
                return qtrue;
        }
 -
 +      
        /* group entities are just for editor convenience, toss all brushes into worldspawn */
-       if( !noCollapseGroups && funcGroup )
-       {
+       if ( !noCollapseGroups && funcGroup ) {
                MoveBrushesToWorld( mapEnt );
                numEntities--;
                return qtrue;
  
  
  /*
- LoadMapFile()
- loads a map file into a list of entities
- */
   LoadMapFile()
   loads a map file into a list of entities
 */
  
- void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups )
- {             
+ void LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups ){
 -      FILE        *file;
 -      brush_t     *b;
 -      int oldNumEntities = 0, numMapBrushes;
 -
 -
 +      FILE            *file;
 +      brush_t         *b;
 +      int                     oldNumEntities = 0, numMapBrushes;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- LoadMapFile ---\n" );
        Sys_Printf( "Loading %s\n", filename );
        /* hack */
        file = SafeOpenRead( filename );
        fclose( file );
 -
 +      
        /* load the map file */
        LoadScriptFile( filename, -1 );
 -
 +      
        /* setup */
-       if( onlyLights )
+       if ( onlyLights ) {
                oldNumEntities = numEntities;
-       else
+       }
+       else{
                numEntities = 0;
 -
+       }
 +      
        /* initial setup */
        numMapDrawSurfs = 0;
        c_detail = 0;
        g_bBrushPrimit = BPRIMIT_UNDEFINED;
 -
 +      
        /* allocate a very large temporary brush for building the brushes as they are loaded */
        buildBrush = AllocBrush( MAX_BUILD_SIDES );
 -
 +      
        /* parse the map file */
-       while( ParseMapEntity( onlyLights, noCollapseGroups ) );
+       while ( ParseMapEntity( onlyLights, noCollapseGroups ) ) ;
 -
 +      
        /* light loading */
-       if( onlyLights )
-       {
+       if ( onlyLights ) {
                /* emit some statistics */
                Sys_FPrintf( SYS_VRB, "%9d light entities\n", numEntities - oldNumEntities );
        }
                        AddPointToBounds( b->mins, mapMins, mapMaxs );
                        AddPointToBounds( b->maxs, mapMins, mapMaxs );
                }
 -
 +              
                /* get brush counts */
                numMapBrushes = CountBrushList( entities[ 0 ].brushes );
-               if( (float) c_detail / (float) numMapBrushes < 0.10f && numMapBrushes > 500 )
+               if ( (float) c_detail / (float) numMapBrushes < 0.10f && numMapBrushes > 500 ) {
                        Sys_Printf( "WARNING: Over 90 percent structural map detected. Compile time may be adversely affected.\n" );
 -
+               }
 +              
                /* emit some statistics */
                Sys_FPrintf( SYS_VRB, "%9d total world brushes\n", numMapBrushes );
                Sys_FPrintf( SYS_VRB, "%9d detail brushes\n", c_detail );
-               Sys_FPrintf( SYS_VRB, "%9d patches\n", numMapPatches);
-               Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels);
-               Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels);
+               Sys_FPrintf( SYS_VRB, "%9d patches\n", numMapPatches );
+               Sys_FPrintf( SYS_VRB, "%9d boxbevels\n", c_boxbevels );
+               Sys_FPrintf( SYS_VRB, "%9d edgebevels\n", c_edgebevels );
                Sys_FPrintf( SYS_VRB, "%9d entities\n", numEntities );
-               Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes);
-               Sys_Printf( "%9d areaportals\n", c_areaportals);
+               Sys_FPrintf( SYS_VRB, "%9d planes\n", nummapplanes );
+               Sys_Printf( "%9d areaportals\n", c_areaportals );
                Sys_Printf( "Size: %5.0f, %5.0f, %5.0f to %5.0f, %5.0f, %5.0f\n",
 -                                      mapMins[ 0 ], mapMins[ 1 ], mapMins[ 2 ],
 +                      mapMins[ 0 ], mapMins[ 1 ], mapMins[ 2 ],
-                       mapMaxs[ 0 ], mapMaxs[ 1 ], mapMaxs[ 2 ]);
+                                       mapMaxs[ 0 ], mapMaxs[ 1 ], mapMaxs[ 2 ] );
 -
 +              
                /* write bogus map */
-               if( fakemap )
+               if ( fakemap ) {
                        WriteBSPBrushMap( "fakemap.map", entities[ 0 ].brushes );
 -              }
 +      }
+       }
  }
index b67fc4e35c381be51c12d62aed38d4ab854bf035,94a80487451e22086c798d2679b1c8e3c0125cb3..7489bcf07a8b882423f4628ae97b5c9b0b5d175e
  
  
  
 -/*
 +/* 
- PicoPrintFunc()
- callback for picomodel.lib
- */
   PicoPrintFunc()
   callback for picomodel.lib
 */
  
- void PicoPrintFunc( int level, const char *str )
- {
-       if( str == NULL )
+ void PicoPrintFunc( int level, const char *str ){
+       if ( str == NULL ) {
                return;
-       switch( level )
+       }
+       switch ( level )
        {
 -      case PICO_NORMAL:
 -              Sys_Printf( "%s\n", str );
 -              break;
 -
 -      case PICO_VERBOSE:
 -              Sys_FPrintf( SYS_VRB, "%s\n", str );
 -              break;
 -
 -      case PICO_WARNING:
 -              Sys_Printf( "WARNING: %s\n", str );
 -              break;
 -
 -      case PICO_ERROR:
 -              Sys_Printf( "ERROR: %s\n", str );
 -              break;
 -
 -      case PICO_FATAL:
 -              Error( "ERROR: %s\n", str );
 -              break;
 +              case PICO_NORMAL:
 +                      Sys_Printf( "%s\n", str );
 +                      break;
 +              
 +              case PICO_VERBOSE:
 +                      Sys_FPrintf( SYS_VRB, "%s\n", str );
 +                      break;
 +              
 +              case PICO_WARNING:
 +                      Sys_Printf( "WARNING: %s\n", str );
 +                      break;
 +              
 +              case PICO_ERROR:
 +                      Sys_Printf( "ERROR: %s\n", str );
 +                      break;
 +              
 +              case PICO_FATAL:
 +                      Error( "ERROR: %s\n", str );
 +                      break;
        }
  }
  
  
  
 -/*
 +/* 
- PicoLoadFileFunc()
- callback for picomodel.lib
- */
   PicoLoadFileFunc()
   callback for picomodel.lib
 */
  
- void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize )
- {
+ void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ){
        *bufSize = vfsLoadFile( name, (void**) buffer, 0 );
  }
  
  
  
  /*
- FindModel() - ydnar
- finds an existing picoModel and returns a pointer to the picoModel_t struct or NULL if not found
- */
   FindModel() - ydnar
   finds an existing picoModel and returns a pointer to the picoModel_t struct or NULL if not found
 */
  
- picoModel_t *FindModel( const char *name, int frame )
- {
+ picoModel_t *FindModel( const char *name, int frame ){
 -      int i;
 -
 -
 +      int                     i;
 +      
 +      
        /* init */
-       if( numPicoModels <= 0 )
+       if ( numPicoModels <= 0 ) {
                memset( picoModels, 0, sizeof( picoModels ) );
 -
+       }
 +      
        /* dummy check */
-       if( name == NULL || name[ 0 ] == '\0' )
+       if ( name == NULL || name[ 0 ] == '\0' ) {
                return NULL;
 -
+       }
 +      
        /* search list */
-       for( i = 0; i < MAX_MODELS; i++ )
+       for ( i = 0; i < MAX_MODELS; i++ )
        {
-               if( picoModels[ i ] != NULL &&
+               if ( picoModels[ i ] != NULL &&
 -                       !strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
 +                      !strcmp( PicoGetModelName( picoModels[ i ] ), name ) &&
-                       PicoGetModelFrameNum( picoModels[ i ] ) == frame )
+                        PicoGetModelFrameNum( picoModels[ i ] ) == frame ) {
                        return picoModels[ i ];
 -              }
        }
 -
++      }
 +      
        /* no matching picoModel found */
        return NULL;
  }
  
  
  /*
- LoadModel() - ydnar
- loads a picoModel and returns a pointer to the picoModel_t struct or NULL if not found
- */
   LoadModel() - ydnar
   loads a picoModel and returns a pointer to the picoModel_t struct or NULL if not found
 */
  
- picoModel_t *LoadModel( const char *name, int frame )
- {
+ picoModel_t *LoadModel( const char *name, int frame ){
 -      int i;
 -      picoModel_t     *model, **pm;
 -
 -
 +      int                             i;
 +      picoModel_t             *model, **pm;
 +      
 +      
        /* init */
-       if( numPicoModels <= 0 )
+       if ( numPicoModels <= 0 ) {
                memset( picoModels, 0, sizeof( picoModels ) );
 -
+       }
 +      
        /* dummy check */
-       if( name == NULL || name[ 0 ] == '\0' )
+       if ( name == NULL || name[ 0 ] == '\0' ) {
                return NULL;
 -
+       }
 +      
        /* try to find existing picoModel */
        model = FindModel( name, frame );
-       if( model != NULL )
+       if ( model != NULL ) {
                return model;
 -
+       }
 +      
        /* none found, so find first non-null picoModel */
        pm = NULL;
-       for( i = 0; i < MAX_MODELS; i++ )
-       {
-               if( picoModels[ i ] == NULL )
+       for ( i = 0; i < MAX_MODELS; i++ )
 -      {
 +              {
+               if ( picoModels[ i ] == NULL ) {
                        pm = &picoModels[ i ];
                        break;
                }
        }
 -
 +      
        /* too many picoModels? */
-       if( pm == NULL )
+       if ( pm == NULL ) {
                Error( "MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS );
 -
+       }
 +      
        /* attempt to parse model */
        *pm = PicoLoadModel( name, frame );
 -
 +      
        /* if loading failed, make a bogus model to silence the rest of the warnings */
-       if( *pm == NULL )
-       {
+       if ( *pm == NULL ) {
                /* allocate a new model */
                *pm = PicoNewModel();
-               if( *pm == NULL )
+               if ( *pm == NULL ) {
                        return NULL;
 -
+               }
 +              
                /* set data */
                PicoSetModelName( *pm, name );
                PicoSetModelFrameNum( *pm, frame );
        /* debug code */
        #if 0
        {
 -              int numSurfaces, numVertexes;
 -              picoSurface_t   *ps;
 -
 -
 +              int                             numSurfaces, numVertexes;
 +              picoSurface_t   *ps;
 +              
 +              
                Sys_Printf( "Model %s\n", name );
                numSurfaces = PicoGetModelNumSurfaces( *pm );
-               for( i = 0; i < numSurfaces; i++ )
+               for ( i = 0; i < numSurfaces; i++ )
                {
                        ps = PicoGetModelSurface( *pm, i );
                        numVertexes = PicoGetSurfaceNumVertexes( ps );
                }
        }
        #endif
 -
 +      
        /* set count */
-       if( *pm != NULL )
+       if ( *pm != NULL ) {
                numPicoModels++;
 -
+       }
 +      
        /* return the picoModel */
        return *pm;
  }
  
  
  /*
- InsertModel() - ydnar
- adds a picomodel into the bsp
- */
   InsertModel() - ydnar
   adds a picomodel into the bsp
 */
  
- void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, vec3_t colormod )
- {
 -void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle ){
 -      int i, j, s, numSurfaces;
 -      m4x4_t identity, nTransform;
 -      picoModel_t         *model;
 -      picoShader_t        *shader;
 -      picoSurface_t       *surface;
 -      shaderInfo_t        *si;
 -      mapDrawSurface_t    *ds;
 -      bspDrawVert_t       *dv;
 -      char                *picoShaderName;
 -      char shaderName[ MAX_QPATH ];
 -      picoVec_t           *xyz, *normal, *st;
 -      byte                *color;
 -      picoIndex_t         *indexes;
 -      remap_t             *rm, *glob;
 -      skinfile_t          *sf, *sf2;
 -      double normalEpsilon_save;
 -      double distanceEpsilon_save;
 -      char skinfilename[ MAX_QPATH ];
 -      char                *skinfilecontent;
 -      int skinfilesize;
 -      char                *skinfileptr, *skinfilenextptr;
 -
 -
++void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap_t *remap, shaderInfo_t *celShader, int eNum, int castShadows, int recvShadows, int spawnFlags, float lightmapScale, int lightmapSampleSize, float shadeAngle, vec3_t colormod ){
 +      int                                     i, j, s, numSurfaces;
 +      m4x4_t                          identity, nTransform;
 +      picoModel_t                     *model;
 +      picoShader_t            *shader;
 +      picoSurface_t           *surface;
 +      shaderInfo_t            *si;
 +      mapDrawSurface_t        *ds;
 +      bspDrawVert_t           *dv;
 +      char                            *picoShaderName;
 +      char                            shaderName[ MAX_QPATH ];
 +      picoVec_t                       *xyz, *normal, *st;
 +      byte                            *color;
 +      picoIndex_t                     *indexes;
 +      remap_t                         *rm, *glob;
 +      skinfile_t                      *sf, *sf2;
 +      double                          normalEpsilon_save;
 +      double                          distanceEpsilon_save;
 +      char                            skinfilename[ MAX_QPATH ];
 +      char                            *skinfilecontent;
 +      int                                     skinfilesize;
 +      char                            *skinfileptr, *skinfilenextptr;
 +      
 +      
        /* get model */
        model = LoadModel( name, frame );
-       if( model == NULL )
+       if ( model == NULL ) {
                return;
+       }
  
        /* load skin file */
-       snprintf(skinfilename, sizeof(skinfilename), "%s_%d.skin", name, skin);
-       skinfilename[sizeof(skinfilename)-1] = 0;
-       skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0);
-       if(skinfilesize < 0 && skin != 0)
-       {
+       snprintf( skinfilename, sizeof( skinfilename ), "%s_%d.skin", name, skin );
+       skinfilename[sizeof( skinfilename ) - 1] = 0;
+       skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
+       if ( skinfilesize < 0 && skin != 0 ) {
                /* fallback to skin 0 if invalid */
-               snprintf(skinfilename, sizeof(skinfilename), "%s_0.skin", name);
-               skinfilename[sizeof(skinfilename)-1] = 0;
-               skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0);
-               if(skinfilesize >= 0)
+               snprintf( skinfilename, sizeof( skinfilename ), "%s_0.skin", name );
+               skinfilename[sizeof( skinfilename ) - 1] = 0;
+               skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
+               if ( skinfilesize >= 0 ) {
                        Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
 -              }
 +      }
+       }
        sf = NULL;
-       if(skinfilesize >= 0)
-       {
+       if ( skinfilesize >= 0 ) {
                Sys_Printf( "Using skin %d of %s\n", skin, name );
                int pos;
-               for(skinfileptr = skinfilecontent; *skinfileptr; skinfileptr = skinfilenextptr)
+               for ( skinfileptr = skinfilecontent; *skinfileptr; skinfileptr = skinfilenextptr )
                {
                        // for fscanf
                        char format[64];
  
                        /* invalid input line -> discard sf struct */
                        Sys_Printf( "Discarding skin directive in %s: %s\n", skinfilename, skinfileptr );
-                       free(sf);
+                       free( sf );
                        sf = sf2;
                }
-               free(skinfilecontent);
+               free( skinfilecontent );
        }
 -
 +      
        /* handle null matrix */
-       if( transform == NULL )
-       {
+       if ( transform == NULL ) {
                m4x4_identity( identity );
                transform = identity;
        }
           this transpose is necessary with Stable-1_2
           uncomment the following line with old m4x4_t (non 1.3/spog_branch) code */
        //%     m4x4_transpose( transform );
 -
 +      
        /* create transform matrix for normals */
        memcpy( nTransform, transform, sizeof( m4x4_t ) );
-       if( m4x4_invert( nTransform ) )
+       if ( m4x4_invert( nTransform ) ) {
                Sys_FPrintf( SYS_VRB, "WARNING: Can't invert model transform matrix, using transpose instead\n" );
+       }
        m4x4_transpose( nTransform );
 -
 +      
        /* fix bogus lightmap scale */
-       if( lightmapScale <= 0.0f )
+       if ( lightmapScale <= 0.0f ) {
                lightmapScale = 1.0f;
+       }
  
        /* fix bogus shade angle */
-       if( shadeAngle <= 0.0f )
+       if ( shadeAngle <= 0.0f ) {
                shadeAngle = 0.0f;
 -
+       }
 +      
        /* each surface on the model will become a new map drawsurface */
        numSurfaces = PicoGetModelNumSurfaces( model );
        //%     Sys_FPrintf( SYS_VRB, "Model %s has %d surfaces\n", name, numSurfaces );
        {
                /* get surface */
                surface = PicoGetModelSurface( model, s );
-               if( surface == NULL )
+               if ( surface == NULL ) {
                        continue;
 -
+               }
 +              
                /* only handle triangle surfaces initially (fixme: support patches) */
-               if( PicoGetSurfaceType( surface ) != PICO_TRIANGLES )
+               if ( PicoGetSurfaceType( surface ) != PICO_TRIANGLES ) {
                        continue;
 -
+               }
 +              
                /* get shader name */
 -              shader = PicoGetSurfaceShader( surface );
 +        shader = PicoGetSurfaceShader( surface );
-               if( shader == NULL )
+               if ( shader == NULL ) {
                        picoShaderName = "";
-               else
+               }
+               else{
                        picoShaderName = PicoGetShaderName( shader );
+               }
  
                /* handle .skin file */
-               if(sf)
-               {
+               if ( sf ) {
                        picoShaderName = NULL;
-                       for(sf2 = sf; sf2 != NULL; sf2 = sf2->next)
-                       {
-                               if( !Q_stricmp( surface->name, sf2->name ) )
+                       for ( sf2 = sf; sf2 != NULL; sf2 = sf2->next )
 -                      {
 +                              {
+                               if ( !Q_stricmp( surface->name, sf2->name ) ) {
                                        Sys_FPrintf( SYS_VRB, "Skin file: mapping %s to %s\n", surface->name, sf2->to );
                                        picoShaderName = sf2->to;
                                        break;
                                break;
                        }
                }
 -
 +              
-               if( glob != NULL )
-               {
+               if ( glob != NULL ) {
                        Sys_FPrintf( SYS_VRB, "Globbing %s to %s\n", picoShaderName, glob->to );
                        picoShaderName = glob->to;
                }
 -
 +              
                /* shader renaming for sof2 */
-               if( renameModelShaders )
-               {
+               if ( renameModelShaders ) {
                        strcpy( shaderName, picoShaderName );
                        StripExtension( shaderName );
-                       if( spawnFlags & 1 )
+                       if ( spawnFlags & 1 ) {
                                strcat( shaderName, "_RMG_BSP" );
-                       else
+                       }
+                       else{
                                strcat( shaderName, "_BSP" );
+                       }
                        si = ShaderInfoForShader( shaderName );
                }
-               else
+               else{
                        si = ShaderInfoForShader( picoShaderName );
 -
+               }
 +              
                /* allocate a surface (ydnar: gs mods) */
                ds = AllocDrawSurface( SURFACE_TRIANGLES );
                ds->entityNum = eNum;
                ds->shaderInfo = si;
  
                /* force to meta? */
-               if( (si != NULL && si->forceMeta) || (spawnFlags & 4) ) /* 3rd bit */
+               if ( ( si != NULL && si->forceMeta ) || ( spawnFlags & 4 ) ) { /* 3rd bit */
                        ds->type = SURFACE_FORCED_META;
+               }
  
                /* fix the surface's normals (jal: conditioned by shader info) */
-               if( !(spawnFlags & 64) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) )
+               if ( !( spawnFlags & 64 ) && ( shadeAngle == 0.0f || ds->type != SURFACE_FORCED_META ) ) {
                        PicoFixSurfaceNormals( surface );
+               }
  
                /* set sample size */
-               if( lightmapSampleSize > 0.0f )
+               if ( lightmapSampleSize > 0.0f ) {
                        ds->sampleSize = lightmapSampleSize;
 -
+               }
 +              
                /* set lightmap scale */
-               if( lightmapScale > 0.0f )
+               if ( lightmapScale > 0.0f ) {
                        ds->lightmapScale = lightmapScale;
+               }
  
 +              /* set color mod */
 +              ds->colormod = colormod;
 +
                /* set shading angle */
-               if( shadeAngle > 0.0f )
+               if ( shadeAngle > 0.0f ) {
                        ds->shadeAngleDegrees = shadeAngle;
 -
+               }
 +              
                /* set particulars */
                ds->numVerts = PicoGetSurfaceNumVertexes( surface );
                ds->verts = safe_malloc( ds->numVerts * sizeof( ds->verts[ 0 ] ) );
                ds->numIndexes = PicoGetSurfaceNumIndexes( surface );
                ds->indexes = safe_malloc( ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
                memset( ds->indexes, 0, ds->numIndexes * sizeof( ds->indexes[ 0 ] ) );
 -
 +              
                /* copy vertexes */
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                {
                        /* get vertex */
                        dv = &ds->verts[ i ];
                                dv->st[ 0 ] = si->stFlat[ 0 ];
                                dv->st[ 1 ] = si->stFlat[ 1 ];
                        }
 -
 +                      
                        /* ydnar: gs mods: added support for explicit shader texcoord generation */
-                       else if( si->tcGen )
-                       {
+                       else if ( si->tcGen ) {
                                /* project the texture */
                                dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], dv->xyz );
                                dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], dv->xyz );
                                dv->st[ 0 ] = st[ 0 ];
                                dv->st[ 1 ] = st[ 1 ];
                        }
 -
 +                      
                        /* set lightmap/color bits */
                        color = PicoGetSurfaceColor( surface, 0, i );
-                       for( j = 0; j < MAX_LIGHTMAPS; j++ )
+                       for ( j = 0; j < MAX_LIGHTMAPS; j++ )
                        {
                                dv->lightmap[ j ][ 0 ] = 0.0f;
                                dv->lightmap[ j ][ 1 ] = 0.0f;
                                }
                        }
                }
 -
 +              
                /* copy indexes */
                indexes = PicoGetSurfaceIndexes( surface, 0 );
-               for( i = 0; i < ds->numIndexes; i++ )
+               for ( i = 0; i < ds->numIndexes; i++ )
                        ds->indexes[ i ] = indexes[ i ];
 -
 +              
                /* set cel shader */
                ds->celShader = celShader;
 -
 +              
                /* ydnar: giant hack land: generate clipping brushes for model triangles */
-               if( si->clipModel || (spawnFlags & 2) ) /* 2nd bit */
-               {
+               if ( si->clipModel || ( spawnFlags & 2 ) ) { /* 2nd bit */
 -                      vec3_t points[ 4 ], backs[ 3 ];
 -                      vec4_t plane, reverse, pa, pb, pc;
 -
 -
 +                      vec3_t          points[ 4 ], backs[ 3 ];
 +                      vec4_t          plane, reverse, pa, pb, pc;
 +                      
 +                      
                        /* temp hack */
-                       if( !si->clipModel && !(si->compileFlags & C_SOLID) )
+                       if ( !si->clipModel && !( si->compileFlags & C_SOLID ) ) {
                                continue;
 -
+                       }
 +                      
                        /* walk triangle list */
-                       for( i = 0; i < ds->numIndexes; i += 3 )
+                       for ( i = 0; i < ds->numIndexes; i += 3 )
                        {
                                /* overflow hack */
-                               AUTOEXPAND_BY_REALLOC(mapplanes, (nummapplanes+64) << 1, allocatedmapplanes, 1024);
+                               AUTOEXPAND_BY_REALLOC( mapplanes, ( nummapplanes + 64 ) << 1, allocatedmapplanes, 1024 );
 -
 +                              
                                /* make points and back points */
-                               for( j = 0; j < 3; j++ )
+                               for ( j = 0; j < 3; j++ )
                                {
                                        /* get vertex */
                                        dv = &ds->verts[ ds->indexes[ i + j ] ];
                                                buildBrush->detail = qfalse;
  
                                                // only allow EXACT matches when snapping for these (this is mostly for caulk brushes inside a model)
-                                               if(normalEpsilon > 0)
+                                               if ( normalEpsilon > 0 ) {
                                                        normalEpsilon = 0;
-                                               if(distanceEpsilon > 0)
+                                               }
+                                               if ( distanceEpsilon > 0 ) {
                                                        distanceEpsilon = 0;
 -                                              }
 +                                      }
-                                       else
+                                       }
+                                       else{
                                                buildBrush->detail = qtrue;
+                                       }
  
                                        /* regenerate back points */
-                                       for( j = 0; j < 3; j++ )
+                                       for ( j = 0; j < 3; j++ )
                                        {
                                                /* get vertex */
                                                dv = &ds->verts[ ds->indexes[ i + j ] ];
                                        /* make back plane */
                                        VectorScale( plane, -1.0f, reverse );
                                        reverse[ 3 ] = -plane[ 3 ];
-                                       if((spawnFlags & 24) != 24)
-                                               reverse[3] += DotProduct(bestNormal, plane) * backPlaneDistance;
+                                       if ( ( spawnFlags & 24 ) != 24 ) {
+                                               reverse[3] += DotProduct( bestNormal, plane ) * backPlaneDistance;
+                                       }
                                        // that's at least sqrt(1/3) backPlaneDistance, unless in DOWN mode; in DOWN mode, we are screwed anyway if we encounter a plane that's perpendicular to the xy plane)
  
-                                       if( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], backs[ 1 ] ) &&
+                                       if ( PlaneFromPoints( pa, points[ 2 ], points[ 1 ], backs[ 1 ] ) &&
 -                                               PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
 +                                                      PlaneFromPoints( pb, points[ 1 ], points[ 0 ], backs[ 0 ] ) &&
-                                                       PlaneFromPoints( pc, points[ 0 ], points[ 2 ], backs[ 2 ] ) )
-                                       {
+                                                PlaneFromPoints( pc, points[ 0 ], points[ 2 ], backs[ 2 ] ) ) {
                                                /* set up brush sides */
                                                buildBrush->numsides = 5;
                                                buildBrush->sides[ 0 ].shaderInfo = si;
-                                               for( j = 1; j < buildBrush->numsides; j++ )
+                                               for ( j = 1; j < buildBrush->numsides; j++ )
 -                                                      buildBrush->sides[ j ].shaderInfo = NULL;  // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
 +                                                      buildBrush->sides[ j ].shaderInfo = NULL; // don't emit these faces as draw surfaces, should make smaller BSPs; hope this works
  
                                                buildBrush->sides[ 0 ].planenum = FindFloatPlane( plane, plane[ 3 ], 3, points );
                                                buildBrush->sides[ 1 ].planenum = FindFloatPlane( pa, pa[ 3 ], 2, &points[ 1 ] ); // pa contains points[1] and points[2]
                                                entities[ mapEntityNum ].brushes = buildBrush;
                                                entities[ mapEntityNum ].numBrushes++;
                                        }
-                                       else
+                                       else{
                                                free( buildBrush );
 -                                      }
                                }
                        }
                }
        }
++      }
  }
  
  
  
  /*
- AddTriangleModels()
- adds misc_model surfaces to the bsp
- */
   AddTriangleModels()
   adds misc_model surfaces to the bsp
 */
  
- void AddTriangleModels( entity_t *e )
- {
+ void AddTriangleModels( entity_t *e ){
 -      int num, frame, skin, castShadows, recvShadows, spawnFlags;
 -      entity_t        *e2;
 -      const char      *targetName;
 -      const char      *target, *model, *value;
 -      char shader[ MAX_QPATH ];
 -      shaderInfo_t    *celShader;
 -      float temp, baseLightmapScale, lightmapScale;
 -      float shadeAngle;
 -      int lightmapSampleSize;
 -      vec3_t origin, scale, angles;
 -      m4x4_t transform;
 -      epair_t         *ep;
 -      remap_t         *remap, *remap2;
 -      char            *split;
 -
 -
 +      int                             num, frame, skin, castShadows, recvShadows, spawnFlags;
 +      entity_t                *e2;
 +      const char              *targetName;
 +      const char              *target, *model, *value;
 +      char                    shader[ MAX_QPATH ];
 +      shaderInfo_t    *celShader;
 +      float                   temp, baseLightmapScale, lightmapScale;
 +      float                   shadeAngle;
 +      int                             lightmapSampleSize;
 +      vec3_t                  origin, scale, angles;
 +      m4x4_t                  transform;
 +      epair_t                 *ep;
 +      remap_t                 *remap, *remap2;
 +      char                    *split;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- AddTriangleModels ---\n" );
 -
 +      
        /* get current brush entity targetname */
-       if( e == entities )
+       if ( e == entities ) {
                targetName = "";
+       }
        else
        {
                targetName = ValueForKey( e, "targetname" );
 -
 +      
                /* misc_model entities target non-worldspawn brush model entities */
-               if( targetName[ 0 ] == '\0' )
+               if ( targetName[ 0 ] == '\0' ) {
                        return;
 -              }
        }
 -
++      }
 +      
        /* get lightmap scale */
        /* vortex: added _ls key (short name of lightmapscale) */
        baseLightmapScale = 0.0f;
-       if( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
+       if ( strcmp( "", ValueForKey( e, "lightmapscale" ) ) ||
 -               strcmp( "", ValueForKey( e, "_lightmapscale" ) ) ||
 +              strcmp( "", ValueForKey( e, "_lightmapscale" ) ) || 
-               strcmp( "", ValueForKey( e, "_ls" ) ) )
-       {
+                strcmp( "", ValueForKey( e, "_ls" ) ) ) {
                baseLightmapScale = FloatForKey( e, "lightmapscale" );
-               if( baseLightmapScale <= 0.0f )
+               if ( baseLightmapScale <= 0.0f ) {
                        baseLightmapScale = FloatForKey( e, "_lightmapscale" );
-               if( baseLightmapScale <= 0.0f )
+               }
+               if ( baseLightmapScale <= 0.0f ) {
                        baseLightmapScale = FloatForKey( e, "_ls" );
-               if( baseLightmapScale < 0.0f )
+               }
+               if ( baseLightmapScale < 0.0f ) {
                        baseLightmapScale = 0.0f;
-               if( baseLightmapScale > 0.0f )
+               }
+               if ( baseLightmapScale > 0.0f ) {
                        Sys_Printf( "World Entity has lightmap scale of %.4f\n", baseLightmapScale );
 -              }
        }
 -
 -
++      }
 +      
 +      
        /* walk the entity list */
-       for( num = 1; num < numEntities; num++ )
+       for ( num = 1; num < numEntities; num++ )
        {
                /* get e2 */
                e2 = &entities[ num ];
 -
 +              
                /* convert misc_models into raw geometry */
-               if( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) )
+               if ( Q_stricmp( "misc_model", ValueForKey( e2, "classname" ) ) ) {
                        continue;
+               }
  
                /* ydnar: added support for md3 models on non-worldspawn models */
                target = ValueForKey( e2, "target" );
-               if( strcmp( target, targetName ) )
+               if ( strcmp( target, targetName ) ) {
                        continue;
 -
+               }
 +              
                /* get model name */
                model = ValueForKey( e2, "model" );
-               if( model[ 0 ] == '\0' )
-               {
+               if ( model[ 0 ] == '\0' ) {
                        Sys_Printf( "WARNING: misc_model at %i %i %i without a model key\n",
 -                                              (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
 +                              (int) origin[ 0 ], (int) origin[ 1 ], (int) origin[ 2 ] );
                        continue;
                }
 -
 +              
                /* get model frame */
                frame = 0;
-               if(strcmp("", ValueForKey( e2, "_frame")))
-                       frame = IntForKey(e2, "_frame");
-               else if(strcmp("", ValueForKey( e2, "frame")))
-                       frame = IntForKey(e2, "frame");
+               if ( strcmp( "", ValueForKey( e2, "_frame" ) ) ) {
+                       frame = IntForKey( e2, "_frame" );
+               }
+               else if ( strcmp( "", ValueForKey( e2, "frame" ) ) ) {
+                       frame = IntForKey( e2, "frame" );
+               }
 -
 +              
                /* worldspawn (and func_groups) default to cast/recv shadows in worldspawn group */
-               if( e == entities )
-               {
+               if ( e == entities ) {
                        castShadows = WORLDSPAWN_CAST_SHADOWS;
                        recvShadows = WORLDSPAWN_RECV_SHADOWS;
                }
                /* get scale */
                scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = 1.0f;
                temp = FloatForKey( e2, "modelscale" );
-               if( temp != 0.0f )
+               if ( temp != 0.0f ) {
                        scale[ 0 ] = scale[ 1 ] = scale[ 2 ] = temp;
+               }
                value = ValueForKey( e2, "modelscale_vec" );
-               if( value[ 0 ] != '\0' )
+               if ( value[ 0 ] != '\0' ) {
                        sscanf( value, "%f %f %f", &scale[ 0 ], &scale[ 1 ], &scale[ 2 ] );
 -
+               }
 +              
                /* get "angle" (yaw) or "angles" (pitch yaw roll) */
                angles[ 0 ] = angles[ 1 ] = angles[ 2 ] = 0.0f;
                angles[ 2 ] = FloatForKey( e2, "angle" );
                value = ValueForKey( e2, "angles" );
-               if( value[ 0 ] != '\0' )
+               if ( value[ 0 ] != '\0' ) {
                        sscanf( value, "%f %f %f", &angles[ 1 ], &angles[ 2 ], &angles[ 0 ] );
 -
+               }
 +              
                /* set transform matrix (thanks spog) */
                m4x4_identity( transform );
                m4x4_pivoted_transform_by_vec3( transform, origin, angles, eXYZ, scale, vec3_origin );
 -
 +              
                /* get shader remappings */
                remap = NULL;
-               for( ep = e2->epairs; ep != NULL; ep = ep->next )
+               for ( ep = e2->epairs; ep != NULL; ep = ep->next )
                {
                        /* look for keys prefixed with "_remap" */
-                       if( ep->key != NULL && ep->value != NULL &&
+                       if ( ep->key != NULL && ep->value != NULL &&
 -                               ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
 +                              ep->key[ 0 ] != '\0' && ep->value[ 0 ] != '\0' &&
-                               !Q_strncasecmp( ep->key, "_remap", 6 ) )
-                       {
+                                !Q_strncasecmp( ep->key, "_remap", 6 ) ) {
                                /* create new remapping */
                                remap2 = remap;
                                remap = safe_malloc( sizeof( *remap ) );
                                remap->next = remap2;
                                strcpy( remap->from, ep->value );
 -
 +                              
                                /* split the string */
                                split = strchr( remap->from, ';' );
-                               if( split == NULL )
-                               {
+                               if ( split == NULL ) {
                                        Sys_Printf( "WARNING: Shader _remap key found in misc_model without a ; character\n" );
                                        free( remap );
                                        remap = remap2;
                                        continue;
                                }
 -
 +                              
                                /* store the split */
                                *split = '\0';
-                               strcpy( remap->to, (split + 1) );
+                               strcpy( remap->to, ( split + 1 ) );
 -
 +                              
                                /* note it */
                                //%     Sys_FPrintf( SYS_VRB, "Remapping %s to %s\n", remap->from, remap->to );
                        }
                }
 -
 +              
                /* ydnar: cel shader support */
                value = ValueForKey( e2, "_celshader" );
-               if( value[ 0 ] == '\0' )
+               if ( value[ 0 ] == '\0' ) {
                        value = ValueForKey( &entities[ 0 ], "_celshader" );
-               if( value[ 0 ] != '\0' )
-               {
+               }
+               if ( value[ 0 ] != '\0' ) {
                        sprintf( shader, "textures/%s", value );
                        celShader = ShaderInfoForShader( shader );
                }
                /* get lightmap scale */
                /* vortex: added _ls key (short name of lightmapscale) */
                lightmapScale = 0.0f;
-               if( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
+               if ( strcmp( "", ValueForKey( e2, "lightmapscale" ) ) ||
 -                       strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) ||
 +                      strcmp( "", ValueForKey( e2, "_lightmapscale" ) ) || 
-                       strcmp( "", ValueForKey( e2, "_ls" ) ) )
-               {
+                        strcmp( "", ValueForKey( e2, "_ls" ) ) ) {
                        lightmapScale = FloatForKey( e2, "lightmapscale" );
-                       if( lightmapScale <= 0.0f )
+                       if ( lightmapScale <= 0.0f ) {
                                lightmapScale = FloatForKey( e2, "_lightmapscale" );
-                       if( lightmapScale <= 0.0f )
+                       }
+                       if ( lightmapScale <= 0.0f ) {
                                lightmapScale = FloatForKey( e2, "_ls" );
-                       if( lightmapScale < 0.0f )
+                       }
+                       if ( lightmapScale < 0.0f ) {
                                lightmapScale = 0.0f;
-                       if( lightmapScale > 0.0f )
+                       }
+                       if ( lightmapScale > 0.0f ) {
                                Sys_Printf( "misc_model has lightmap scale of %.4f\n", lightmapScale );
 -                      }
 +              }
+               }
  
                /* jal : entity based _shadeangle */
                shadeAngle = 0.0f;
-               if ( strcmp( "", ValueForKey( e2, "_shadeangle" ) ) )
+               if ( strcmp( "", ValueForKey( e2, "_shadeangle" ) ) ) {
                        shadeAngle = FloatForKey( e2, "_shadeangle" );
+               }
                /* vortex' aliases */
-               else if ( strcmp( "", ValueForKey( e2, "_smoothnormals" ) ) )
+               else if ( strcmp( "", ValueForKey( e2, "_smoothnormals" ) ) ) {
                        shadeAngle = FloatForKey( e2, "_smoothnormals" );
-               else if ( strcmp( "", ValueForKey( e2, "_sn" ) ) )
+               }
+               else if ( strcmp( "", ValueForKey( e2, "_sn" ) ) ) {
                        shadeAngle = FloatForKey( e2, "_sn" );
-               else if ( strcmp( "", ValueForKey( e2, "_smooth" ) ) )
+               }
+               else if ( strcmp( "", ValueForKey( e2, "_smooth" ) ) ) {
                        shadeAngle = FloatForKey( e2, "_smooth" );
+               }
  
-               if( shadeAngle < 0.0f )
+               if ( shadeAngle < 0.0f ) {
                        shadeAngle = 0.0f;
+               }
  
-               if( shadeAngle > 0.0f )
+               if ( shadeAngle > 0.0f ) {
                        Sys_Printf( "misc_model has shading angle of %.4f\n", shadeAngle );
+               }
  
                skin = 0;
-               if(strcmp("", ValueForKey( e2, "_skin")))
-                       skin = IntForKey(e2, "_skin");
-               else if(strcmp("", ValueForKey( e2, "skin")))
-                       skin = IntForKey(e2, "skin");
+               if ( strcmp( "", ValueForKey( e2, "_skin" ) ) ) {
+                       skin = IntForKey( e2, "_skin" );
+               }
+               else if ( strcmp( "", ValueForKey( e2, "skin" ) ) ) {
+                       skin = IntForKey( e2, "skin" );
+               }
  
                /* insert the model */
 -              InsertModel( model, skin, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle );
 -
 +              InsertModel( model, skin, frame, transform, remap, celShader, mapEntityNum, castShadows, recvShadows, spawnFlags, lightmapScale, lightmapSampleSize, shadeAngle, colormod );
 +              
                /* free shader remappings */
-               while( remap != NULL )
+               while ( remap != NULL )
                {
                        remap2 = remap->next;
                        free( remap );
index 6133243cb04e1988429f6674eff7ce8878d9039e,bbb3e76e73518d27b8bc12ef7a42ca46f51b2188..55e4b9d439fc67728ef240fccda0828397a0fe15
  
  /* -------------------------------------------------------------------------------
  
- port-related hacks
   port-related hacks
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
 -#define MAC_STATIC_HACK         0
 -#if defined( __APPLE__ ) && MAC_STATIC_HACK
 -      #define MAC_STATIC          static
 +#define MAC_STATIC_HACK                       0
 +#if defined( __APPLE__ ) && MAC_STATIC_HACK 
 +      #define MAC_STATIC                      static
  #else
 -      #define MAC_STATIC
 +      #define MAC_STATIC                      
  #endif
  
  #if 1
  
  /* temporary hacks and tests (please keep off in SVN to prevent anyone's legacy map from screwing up) */
  /* 2011-01-10 TTimo says we should turn these on in SVN, so turning on now */
 -#define Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES   1
 -#define Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX     1
 -#define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX      1
 +#define Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES 1
 +#define Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX           1
 +#define Q3MAP2_EXPERIMENTAL_SNAP_PLANE_FIX            1
  
  /* general */
 -#define MAX_QPATH               64
 +#define MAX_QPATH                             64
  
 -#define MAX_IMAGES              512
 -#define DEFAULT_IMAGE           "*default"
 +#define MAX_IMAGES                            512
 +#define DEFAULT_IMAGE                 "*default"
  
 -#define MAX_MODELS              512
 +#define MAX_MODELS                            512
  
 -#define DEF_BACKSPLASH_FRACTION 0.05f   /* 5% backsplash by default */
 -#define DEF_BACKSPLASH_DISTANCE 23
 +#define       DEF_BACKSPLASH_FRACTION 0.05f   /* 5% backsplash by default */
 +#define       DEF_BACKSPLASH_DISTANCE 23
  
 -#define DEF_RADIOSITY_BOUNCE    1.0f    /* ydnar: default to 100% re-emitted light */
 +#define DEF_RADIOSITY_BOUNCE  1.0f    /* ydnar: default to 100% re-emitted light */
  
 -#define MAX_SHADER_INFO         8192
 +#define       MAX_SHADER_INFO                 8192
- #define MAX_CUST_SURFACEPARMS 64
+ #define MAX_CUST_SURFACEPARMS   256
  
 -#define SHADER_MAX_VERTEXES     1000
 +#define       SHADER_MAX_VERTEXES             1000
- #define       SHADER_MAX_INDEXES              (6 * SHADER_MAX_VERTEXES)
+ #define SHADER_MAX_INDEXES      ( 6 * SHADER_MAX_VERTEXES )
  
 -#define MAX_JITTERS             256
 +#define MAX_JITTERS                           256
  
  
  /* epair parsing (note case-sensitivity directive) */
  
  
  /* bsp */
 -#define MAX_PATCH_SIZE          32
 -#define MAX_BRUSH_SIDES         1024
 -#define MAX_BUILD_SIDES         1024
 +#define       MAX_PATCH_SIZE                  32
 +#define       MAX_BRUSH_SIDES                 1024
 +#define MAX_BUILD_SIDES                       1024
  
 -#define MAX_EXPANDED_AXIS       128
 +#define       MAX_EXPANDED_AXIS               128
  
 -#define CLIP_EPSILON            0.1f
 -#define PLANESIDE_EPSILON       0.001f
 -#define PLANENUM_LEAF           -1
 +#define       CLIP_EPSILON                    0.1f
 +#define       PLANESIDE_EPSILON               0.001f
 +#define       PLANENUM_LEAF                   -1
  
 -#define HINT_PRIORITY           1000        /* ydnar: force hint splits first and antiportal/areaportal splits last */
 -#define ANTIPORTAL_PRIORITY     -1000
 -#define AREAPORTAL_PRIORITY     -1000
 -#define DETAIL_PRIORITY     -3000
 +#define       HINT_PRIORITY                   1000            /* ydnar: force hint splits first and antiportal/areaportal splits last */
 +#define ANTIPORTAL_PRIORITY           -1000
 +#define AREAPORTAL_PRIORITY           -1000
 +#define DETAIL_PRIORITY               -3000
  
 -#define PSIDE_FRONT             1
 -#define PSIDE_BACK              2
 +#define       PSIDE_FRONT                             1
 +#define       PSIDE_BACK                              2
- #define       PSIDE_BOTH                              (PSIDE_FRONT | PSIDE_BACK)
+ #define PSIDE_BOTH              ( PSIDE_FRONT | PSIDE_BACK )
 -#define PSIDE_FACING            4
 +#define       PSIDE_FACING                    4
  
 -#define BPRIMIT_UNDEFINED       0
 -#define BPRIMIT_OLDBRUSHES      1
 -#define BPRIMIT_NEWBRUSHES      2
 +#define BPRIMIT_UNDEFINED             0
 +#define BPRIMIT_OLDBRUSHES            1
 +#define BPRIMIT_NEWBRUSHES            2
  
  
  /* vis */
  
  
  /* light */
 -#define EMIT_POINT              0
 -#define EMIT_AREA               1
 -#define EMIT_SPOT               2
 -#define EMIT_SUN                3
 -
 -#define LIGHT_ATTEN_LINEAR      1
 -#define LIGHT_ATTEN_ANGLE       2
 -#define LIGHT_ATTEN_DISTANCE    4
 -#define LIGHT_TWOSIDED          8
 -#define LIGHT_GRID              16
 -#define LIGHT_SURFACES          32
 -#define LIGHT_DARK              64      /* probably never use this */
 -#define LIGHT_FAST              256
 -#define LIGHT_FAST_TEMP         512
 +#define EMIT_POINT                            0
 +#define EMIT_AREA                             1
 +#define EMIT_SPOT                             2
 +#define EMIT_SUN                              3
 +
 +#define LIGHT_ATTEN_LINEAR            1
 +#define LIGHT_ATTEN_ANGLE             2
 +#define LIGHT_ATTEN_DISTANCE  4
 +#define LIGHT_TWOSIDED                        8
 +#define LIGHT_GRID                            16
 +#define LIGHT_SURFACES                        32
 +#define LIGHT_DARK                            64              /* probably never use this */
 +#define LIGHT_FAST                            256
 +#define LIGHT_FAST_TEMP                       512
- #define LIGHT_FAST_ACTUAL             (LIGHT_FAST | LIGHT_FAST_TEMP)
+ #define LIGHT_FAST_ACTUAL       ( LIGHT_FAST | LIGHT_FAST_TEMP )
 -#define LIGHT_NEGATIVE          1024
 -#define LIGHT_UNNORMALIZED      2048    /* vortex: do not normalize _color */
 +#define LIGHT_NEGATIVE                        1024
 +#define LIGHT_UNNORMALIZED            2048    /* vortex: do not normalize _color */
  
- #define LIGHT_SUN_DEFAULT             (LIGHT_ATTEN_ANGLE | LIGHT_GRID | LIGHT_SURFACES)
- #define LIGHT_AREA_DEFAULT            (LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES)        /* q3a and wolf are the same */
- #define LIGHT_Q3A_DEFAULT             (LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST)
- #define LIGHT_WOLF_DEFAULT            (LIGHT_ATTEN_LINEAR | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST)
+ #define LIGHT_SUN_DEFAULT       ( LIGHT_ATTEN_ANGLE | LIGHT_GRID | LIGHT_SURFACES )
+ #define LIGHT_AREA_DEFAULT      ( LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES )    /* q3a and wolf are the same */
+ #define LIGHT_Q3A_DEFAULT       ( LIGHT_ATTEN_ANGLE | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST )
+ #define LIGHT_WOLF_DEFAULT      ( LIGHT_ATTEN_LINEAR | LIGHT_ATTEN_DISTANCE | LIGHT_GRID | LIGHT_SURFACES | LIGHT_FAST )
  
 -#define MAX_TRACE_TEST_NODES    256
 -#define DEFAULT_INHIBIT_RADIUS  1.5f
 +#define MAX_TRACE_TEST_NODES  256
 +#define DEFAULT_INHIBIT_RADIUS        1.5f
  
 -#define LUXEL_EPSILON           0.125f
 -#define VERTEX_EPSILON          -0.125f
 -#define GRID_EPSILON            0.0f
 +#define LUXEL_EPSILON                 0.125f
 +#define VERTEX_EPSILON                        -0.125f
 +#define GRID_EPSILON                  0.0f
  
 -#define DEFAULT_LIGHTMAP_SAMPLE_SIZE    16
 -#define DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE    0
 -#define DEFAULT_LIGHTMAP_SAMPLE_OFFSET  1.0f
 -#define DEFAULT_SUBDIVIDE_THRESHOLD     1.0f
 +#define DEFAULT_LIGHTMAP_SAMPLE_SIZE  16
 +#define DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE      0
 +#define DEFAULT_LIGHTMAP_SAMPLE_OFFSET        1.0f
 +#define DEFAULT_SUBDIVIDE_THRESHOLD           1.0f
  
 -#define EXTRA_SCALE             2   /* -extrawide = -super 2 */
 -#define EXTRAWIDE_SCALE         2   /* -extrawide = -super 2 -filter */
 +#define       EXTRA_SCALE                             2       /* -extrawide = -super 2 */
 +#define       EXTRAWIDE_SCALE                 2       /* -extrawide = -super 2 -filter */
  
 -#define CLUSTER_UNMAPPED        -1
 -#define CLUSTER_OCCLUDED        -2
 -#define CLUSTER_FLOODED         -3
 +#define CLUSTER_UNMAPPED              -1
 +#define CLUSTER_OCCLUDED              -2
 +#define CLUSTER_FLOODED                       -3
  
 -#define VERTEX_LUXEL_SIZE       3
 -#define BSP_LUXEL_SIZE          3
 -#define RAD_LUXEL_SIZE          3
 -#define SUPER_LUXEL_SIZE        4
 -#define SUPER_FLAG_SIZE         4
 +#define VERTEX_LUXEL_SIZE             3
 +#define BSP_LUXEL_SIZE                        3
 +#define RAD_LUXEL_SIZE                        3
 +#define SUPER_LUXEL_SIZE              4
 +#define SUPER_FLAG_SIZE                       4
  #define FLAG_FORCE_SUBSAMPLING 1
  #define FLAG_ALREADY_SUBSAMPLED 2
 -#define SUPER_ORIGIN_SIZE       3
 -#define SUPER_NORMAL_SIZE       4
 -#define SUPER_DELUXEL_SIZE      3
 -#define BSP_DELUXEL_SIZE        3
 -#define SUPER_FLOODLIGHT_SIZE   4
 +#define SUPER_ORIGIN_SIZE             3
 +#define SUPER_NORMAL_SIZE             4
 +#define SUPER_DELUXEL_SIZE            3
 +#define BSP_DELUXEL_SIZE              3
 +#define SUPER_FLOODLIGHT_SIZE 4
  
- #define VERTEX_LUXEL( s, v )  (vertexLuxels[ s ] + ((v) * VERTEX_LUXEL_SIZE))
- #define RAD_VERTEX_LUXEL( s, v )(radVertexLuxels[ s ] + ((v) * VERTEX_LUXEL_SIZE))
- #define BSP_LUXEL( s, x, y )  (lm->bspLuxels[ s ] + ((((y) * lm->w) + (x)) * BSP_LUXEL_SIZE))
- #define RAD_LUXEL( s, x, y )  (lm->radLuxels[ s ] + ((((y) * lm->w) + (x)) * RAD_LUXEL_SIZE))
- #define SUPER_LUXEL( s, x, y )        (lm->superLuxels[ s ] + ((((y) * lm->sw) + (x)) * SUPER_LUXEL_SIZE))
- #define SUPER_FLAG( x, y )    (lm->superFlags + ((((y) * lm->sw) + (x)) * SUPER_FLAG_SIZE))
- #define SUPER_DELUXEL( x, y ) (lm->superDeluxels + ((((y) * lm->sw) + (x)) * SUPER_DELUXEL_SIZE))
- #define BSP_DELUXEL( x, y )           (lm->bspDeluxels + ((((y) * lm->w) + (x)) * BSP_DELUXEL_SIZE))
- #define SUPER_CLUSTER( x, y ) (lm->superClusters + (((y) * lm->sw) + (x)))
- #define SUPER_ORIGIN( x, y )  (lm->superOrigins + ((((y) * lm->sw) + (x)) * SUPER_ORIGIN_SIZE))
- #define SUPER_NORMAL( x, y )  (lm->superNormals + ((((y) * lm->sw) + (x)) * SUPER_NORMAL_SIZE))
- #define SUPER_DIRT( x, y )            (lm->superNormals + ((((y) * lm->sw) + (x)) * SUPER_NORMAL_SIZE) + 3)   /* stash dirtyness in normal[ 3 ] */
- #define SUPER_FLOODLIGHT( x, y )      (lm->superFloodLight + ((((y) * lm->sw) + (x)) * SUPER_FLOODLIGHT_SIZE) )
+ #define VERTEX_LUXEL( s, v )    ( vertexLuxels[ s ] + ( ( v ) * VERTEX_LUXEL_SIZE ) )
+ #define RAD_VERTEX_LUXEL( s, v )( radVertexLuxels[ s ] + ( ( v ) * VERTEX_LUXEL_SIZE ) )
+ #define BSP_LUXEL( s, x, y )    ( lm->bspLuxels[ s ] + ( ( ( ( y ) * lm->w ) + ( x ) ) * BSP_LUXEL_SIZE ) )
+ #define RAD_LUXEL( s, x, y )    ( lm->radLuxels[ s ] + ( ( ( ( y ) * lm->w ) + ( x ) ) * RAD_LUXEL_SIZE ) )
+ #define SUPER_LUXEL( s, x, y )  ( lm->superLuxels[ s ] + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_LUXEL_SIZE ) )
+ #define SUPER_FLAG( x, y )  ( lm->superFlags + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_FLAG_SIZE ) )
+ #define SUPER_DELUXEL( x, y )   ( lm->superDeluxels + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_DELUXEL_SIZE ) )
+ #define BSP_DELUXEL( x, y )     ( lm->bspDeluxels + ( ( ( ( y ) * lm->w ) + ( x ) ) * BSP_DELUXEL_SIZE ) )
+ #define SUPER_CLUSTER( x, y )   ( lm->superClusters + ( ( ( y ) * lm->sw ) + ( x ) ) )
+ #define SUPER_ORIGIN( x, y )    ( lm->superOrigins + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_ORIGIN_SIZE ) )
+ #define SUPER_NORMAL( x, y )    ( lm->superNormals + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_NORMAL_SIZE ) )
+ #define SUPER_DIRT( x, y )      ( lm->superNormals + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_NORMAL_SIZE ) + 3 )   /* stash dirtyness in normal[ 3 ] */
+ #define SUPER_FLOODLIGHT( x, y )    ( lm->superFloodLight + ( ( ( ( y ) * lm->sw ) + ( x ) ) * SUPER_FLOODLIGHT_SIZE ) )
  
  
  
  /* -------------------------------------------------------------------------------
  
- abstracted bsp file
   abstracted bsp file
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
 -#define EXTERNAL_LIGHTMAP       "lm_%04d.tga"
 +#define EXTERNAL_LIGHTMAP             "lm_%04d.tga"
  
 -#define MAX_LIGHTMAPS           4           /* RBSP */
 -#define MAX_LIGHT_STYLES        64
 -#define MAX_SWITCHED_LIGHTS     32
 -#define LS_NORMAL               0x00
 -#define LS_UNUSED               0xFE
 -#define LS_NONE                 0xFF
 +#define MAX_LIGHTMAPS                 4                       /* RBSP */
 +#define MAX_LIGHT_STYLES              64
 +#define       MAX_SWITCHED_LIGHTS             32
 +#define LS_NORMAL                             0x00
 +#define LS_UNUSED                             0xFE
 +#define       LS_NONE                                 0xFF
  
 -#define MAX_LIGHTMAP_SHADERS    256
 +#define MAX_LIGHTMAP_SHADERS  256
  
  /* ok to increase these at the expense of more memory */
- #define       MAX_MAP_ENTITIES                0x1000          //%     0x800   /* ydnar */
- #define       MAX_MAP_ENTSTRING               0x80000         //%     0x40000 /* ydnar */
 -#define MAX_MAP_AREAS           0x100       /* MAX_MAP_AREA_BYTES in q_shared must match! */
 -#define MAX_MAP_FOGS            30          //& 0x100 /* RBSP (32 - world fog - goggles) */
 -#define MAX_MAP_LEAFS           0x20000
 -#define MAX_MAP_PORTALS         0x20000
 -#define MAX_MAP_LIGHTING        0x800000
 -#define MAX_MAP_LIGHTGRID       0x100000    //%       0x800000 /* ydnar: set to points, not bytes */
 +#define       MAX_MAP_AREAS                   0x100           /* MAX_MAP_AREA_BYTES in q_shared must match! */
 +#define       MAX_MAP_FOGS                    30                      //& 0x100       /* RBSP (32 - world fog - goggles) */
 +#define       MAX_MAP_LEAFS                   0x20000
 +#define       MAX_MAP_PORTALS                 0x20000
 +#define       MAX_MAP_LIGHTING                0x800000
 +#define       MAX_MAP_LIGHTGRID               0x100000        //%     0x800000 /* ydnar: set to points, not bytes */
  #define MAX_MAP_VISCLUSTERS     0x4000 // <= MAX_MAP_LEAFS
- #define       MAX_MAP_VISIBILITY              (VIS_HEADER_SIZE + MAX_MAP_VISCLUSTERS * (((MAX_MAP_VISCLUSTERS + 63) & ~63) >> 3))
+ #define MAX_MAP_VISIBILITY      ( VIS_HEADER_SIZE + MAX_MAP_VISCLUSTERS * ( ( ( MAX_MAP_VISCLUSTERS + 63 ) & ~63 ) >> 3 ) )
  
 -#define MAX_MAP_DRAW_SURFS      0x20000
 +#define       MAX_MAP_DRAW_SURFS              0x20000
- #define       MAX_MAP_DRAW_INDEXES    0x80000
  
 -#define MAX_MAP_ADVERTISEMENTS  30
 +#define MAX_MAP_ADVERTISEMENTS        30
  
  /* key / value pair sizes in the entities lump */
 -#define MAX_KEY                 32
 -#define MAX_VALUE               1024
 +#define       MAX_KEY                                 32
 +#define       MAX_VALUE                               1024
  
  /* the editor uses these predefined yaw angles to orient entities up or down */
 -#define ANGLE_UP                -1
 -#define ANGLE_DOWN              -2
 +#define       ANGLE_UP                                -1
 +#define       ANGLE_DOWN                              -2
  
 -#define LIGHTMAP_WIDTH          128
 -#define LIGHTMAP_HEIGHT         128
 +#define       LIGHTMAP_WIDTH                  128
 +#define       LIGHTMAP_HEIGHT                 128
  
- #define MIN_WORLD_COORD                       (-65536)
- #define       MAX_WORLD_COORD                 (65536)
- #define WORLD_SIZE                            (MAX_WORLD_COORD - MIN_WORLD_COORD)
+ #define MIN_WORLD_COORD         ( -65536 )
+ #define MAX_WORLD_COORD         ( 65536 )
+ #define WORLD_SIZE              ( MAX_WORLD_COORD - MIN_WORLD_COORD )
  
  
- typedef void                                  (*bspFunc)( const char * );
+ typedef void ( *bspFunc )( const char * );
  
  
  typedef struct
@@@ -523,12 -520,12 +520,12 @@@ typedef struct 
  
  /* -------------------------------------------------------------------------------
  
- general types
   general types
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
  /* ydnar: for smaller structs */
 -typedef unsigned char qb_t;
 +typedef unsigned char qb_t;
  
  
  /* ydnar: for q3map_tcMod */
@@@ -555,41 -552,44 +552,44 @@@ miniMapMode_t
  
  typedef struct game_s
  {
 -      char                *arg;                           /* -game matches this */
 -      char                *gamePath;                      /* main game data dir */
 -      char                *homeBasePath;                  /* home sub-dir on unix */
 -      char                *magic;                         /* magic word for figuring out base path */
 -      char                *shaderPath;                    /* shader directory */
 -      int maxLMSurfaceVerts;                              /* default maximum meta surface verts */
 -      int maxSurfaceVerts;                                /* default maximum surface verts */
 -      int maxSurfaceIndexes;                              /* default maximum surface indexes (tris * 3) */
 -      qboolean emitFlares;                                /* when true, emit flare surfaces */
 -      char                *flareShader;                   /* default flare shader (MUST BE SET) */
 -      qboolean wolfLight;                                 /* when true, lights work like wolf q3map  */
 -      int lightmapSize;                                   /* bsp lightmap width/height */
 -      float lightmapGamma;                                /* default lightmap gamma */
 +      char                            *arg;                                                   /* -game matches this */
 +      char                            *gamePath;                                              /* main game data dir */
 +      char                            *homeBasePath;                                  /* home sub-dir on unix */
 +      char                            *magic;                                                 /* magic word for figuring out base path */
 +      char                            *shaderPath;                                    /* shader directory */
 +      int                                     maxLMSurfaceVerts;                              /* default maximum meta surface verts */
 +      int                                     maxSurfaceVerts;                                /* default maximum surface verts */
 +      int                                     maxSurfaceIndexes;                              /* default maximum surface indexes (tris * 3) */
 +      qboolean                        emitFlares;                                             /* when true, emit flare surfaces */
 +      char                            *flareShader;                                   /* default flare shader (MUST BE SET) */
 +      qboolean                        wolfLight;                                              /* when true, lights work like wolf q3map  */
 +      int                                     lightmapSize;                                   /* bsp lightmap width/height */
 +      float                           lightmapGamma;                                  /* default lightmap gamma */
+       qboolean lightmapsRGB;                              /* default lightmap sRGB mode */
+       qboolean texturesRGB;                               /* default texture sRGB mode */
+       qboolean colorsRGB;                             /* default color sRGB mode */
 -      float lightmapExposure;                             /* default lightmap exposure */
 -      float lightmapCompensate;                           /* default lightmap compensate value */
 -      float gridScale;                                    /* vortex: default lightgrid scale (affects both directional and ambient spectres) */
 -      float gridAmbientScale;                             /* vortex: default lightgrid ambient spectre scale */
 -      qboolean lightAngleHL;                              /* jal: use half-lambert curve for light angle attenuation */
 -      qboolean noStyles;                                  /* use lightstyles hack or not */
 -      qboolean keepLights;                                /* keep light entities on bsp */
 -      int patchSubdivisions;                              /* default patch subdivisions tolerance */
 -      qboolean patchShadows;                              /* patch casting enabled */
 -      qboolean deluxeMap;                                 /* compile deluxemaps */
 -      int deluxeMode;                                     /* deluxemap mode (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
 -      int miniMapSize;                                    /* minimap size */
 -      float miniMapSharpen;                               /* minimap sharpening coefficient */
 -      float miniMapBorder;                                /* minimap border amount */
 -      qboolean miniMapKeepAspect;                         /* minimap keep aspect ratio by letterboxing */
 -      miniMapMode_t miniMapMode;                          /* minimap mode */
 +      float                           lightmapExposure;                               /* default lightmap exposure */
 +      float                           lightmapCompensate;                             /* default lightmap compensate value */
 +      float                           gridScale;                                              /* vortex: default lightgrid scale (affects both directional and ambient spectres) */
 +      float                           gridAmbientScale;                               /* vortex: default lightgrid ambient spectre scale */
 +      qboolean                        lightAngleHL;                                   /* jal: use half-lambert curve for light angle attenuation */
 +      qboolean                        noStyles;                                               /* use lightstyles hack or not */
 +      qboolean                        keepLights;                                             /* keep light entities on bsp */
 +      int                                     patchSubdivisions;                              /* default patch subdivisions tolerance */
 +      qboolean                        patchShadows;                                   /* patch casting enabled */
 +      qboolean                        deluxeMap;                                              /* compile deluxemaps */
 +      int                                     deluxeMode;                                             /* deluxemap mode (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
 +      int                 miniMapSize;                    /* minimap size */
 +      float               miniMapSharpen;                 /* minimap sharpening coefficient */
 +      float               miniMapBorder;                  /* minimap border amount */
 +      qboolean            miniMapKeepAspect;              /* minimap keep aspect ratio by letterboxing */
 +      miniMapMode_t       miniMapMode;                    /* minimap mode */
        char                *miniMapNameFormat;             /* minimap name format */
 -      char                *bspIdent;                      /* 4-letter bsp file prefix */
 -      int bspVersion;                                     /* bsp version to use */
 -      qboolean lumpSwap;                                  /* cod-style len/ofs order */
 -      bspFunc load, write;                                /* load/write function pointers */
 -      surfaceParm_t surfaceParms[ 128 ];                  /* surfaceparm array */
 +      char                            *bspIdent;                                              /* 4-letter bsp file prefix */
 +      int                                     bspVersion;                                             /* bsp version to use */
 +      qboolean                        lumpSwap;                                               /* cod-style len/ofs order */
 +      bspFunc                         load, write;                                    /* load/write function pointers */
 +      surfaceParm_t           surfaceParms[ 128 ];                    /* surfaceparm array */
  }
  game_t;
  
@@@ -894,39 -894,38 +894,39 @@@ indexMap_t
  
  typedef struct brush_s
  {
 -      struct brush_s      *next;
 -      struct brush_s      *nextColorModBrush; /* ydnar: colorMod volume brushes go here */
 -      struct brush_s      *original;          /* chopped up brushes will reference the originals */
 -
 +      struct brush_s          *next;
 +      struct brush_s          *nextColorModBrush;     /* ydnar: colorMod volume brushes go here */
 +      struct brush_s          *original;                      /* chopped up brushes will reference the originals */
 +      
-       int                                     entityNum, brushNum;/* editor numbering */
+       int entityNum, brushNum;                /* editor numbering */
 -      int outputNum;                          /* set when the brush is written to the file list */
 -
 +      int                                     outputNum;                      /* set when the brush is written to the file list */
 +      
        /* ydnar: for shadowcasting entities */
 -      int castShadows;
 -      int recvShadows;
 -
 -      shaderInfo_t        *contentShader;
 -      shaderInfo_t        *celShader;         /* :) */
 -
 +      int                                     castShadows;
 +      int                                     recvShadows;
 +      
 +      shaderInfo_t            *contentShader;
 +      shaderInfo_t            *celShader;                     /* :) */
 +      
        /* ydnar: gs mods */
 -      int lightmapSampleSize;                 /* jal : entity based _lightmapsamplesize */
 -      float lightmapScale;
 -      float shadeAngleDegrees;               /* jal : entity based _shadeangle */
 -      vec3_t eMins, eMaxs;
 -      indexMap_t          *im;
 +      int                                     lightmapSampleSize; /* jal : entity based _lightmapsamplesize */
 +      float                           lightmapScale;
 +      vec3_t                          colormod;
 +      float                           shadeAngleDegrees; /* jal : entity based _shadeangle */
 +      vec3_t                          eMins, eMaxs;
 +      indexMap_t                      *im;
  
 -      int contentFlags;
 -      int compileFlags;                       /* ydnar */
 -      qboolean detail;
 -      qboolean opaque;
 +      int                                     contentFlags;
 +      int                                     compileFlags;           /* ydnar */
 +      qboolean                        detail;
 +      qboolean                        opaque;
  
 -      int portalareas[ 2 ];
 +      int                                     portalareas[ 2 ];
  
 -      vec3_t mins, maxs;
 -      int numsides;
 +      vec3_t                          mins, maxs;
 +      int                                     numsides;
  
 -      side_t sides[ 6 ];                      /* variably sized */
 +      side_t                          sides[ 6 ];                     /* variably sized */
  }
  brush_t;
  
@@@ -978,12 -976,12 +978,12 @@@ parseMesh_t
  
  
  /*
 -    ydnar: the drawsurf struct was extended to allow for:
 -    - non-convex planar surfaces
 -    - non-planar brushface surfaces
 -    - lightmapped terrain
 -    - planar patches
 +      ydnar: the drawsurf struct was extended to allow for:
 +      - non-convex planar surfaces
 +      - non-planar brushface surfaces
 +      - lightmapped terrain
 +      - planar patches
- */
 */
  
  typedef enum
  {
  }
  surfaceType_t;
  
 -char            *surfaceTypes[ NUM_SURFACE_TYPES ]
 +char                  *surfaceTypes[ NUM_SURFACE_TYPES ]
  #ifndef MAIN_C
                              ;
+ ;
  #else
 -      =
 -      {
 -      "SURFACE_BAD",
 -      "SURFACE_FACE",
 -      "SURFACE_PATCH",
 -      "SURFACE_TRIANGLES",
 -      "SURFACE_FLARE",
 -      "SURFACE_FOLIAGE",
 -      "SURFACE_FORCED_META",
 -      "SURFACE_META",
 -      "SURFACE_FOGHULL",
 -      "SURFACE_DECAL",
 -      "SURFACE_SHADER"
 -      };
 +                              =
 +                              {
 +                                      "SURFACE_BAD",
 +                                      "SURFACE_FACE",
 +                                      "SURFACE_PATCH",
 +                                      "SURFACE_TRIANGLES",
 +                                      "SURFACE_FLARE",
 +                                      "SURFACE_FOLIAGE",
 +                                      "SURFACE_FORCED_META",
 +                                      "SURFACE_META",
 +                                      "SURFACE_FOGHULL",
 +                                      "SURFACE_DECAL",
 +                                      "SURFACE_SHADER"
 +                              };
  #endif
  
  
@@@ -1513,15 -1508,18 +1513,18 @@@ surfaceInfo_t
  
  /* -------------------------------------------------------------------------------
  
- prototypes
   prototypes
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
  /* main.c */
 -vec_t                       Random( void );
 +vec_t                                         Random( void );
+ char                        *Q_strncpyz( char *dst, const char *src, size_t len );
+ char                        *Q_strcat( char *dst, size_t dlen, const char *src );
+ char                        *Q_strncat( char *dst, size_t dlen, const char *src, size_t slen );
 -int                         BSPInfo( int count, char **fileNames );
 -int                         ScaleBSPMain( int argc, char **argv );
 -int                         ConvertMain( int argc, char **argv );
 +int                                                   BSPInfo( int count, char **fileNames );
 +int                                                   ScaleBSPMain( int argc, char **argv );
 +int                                                   ConvertMain( int argc, char **argv );
  
  
  /* path_init.c */
@@@ -1546,28 -1544,28 +1549,28 @@@ int                                                  ConvertBSPToOBJ( char *bspNam
  
  
  /* brush.c */
 -sideRef_t                   *AllocSideRef( side_t *side, sideRef_t *next );
 -int                         CountBrushList( brush_t *brushes );
 -brush_t                     *AllocBrush( int numsides );
 -void                        FreeBrush( brush_t *brushes );
 -void                        FreeBrushList( brush_t *brushes );
 -brush_t                     *CopyBrush( brush_t *brush );
 -qboolean                    BoundBrush( brush_t *brush );
 -qboolean                    CreateBrushWindings( brush_t *brush );
 -brush_t                     *BrushFromBounds( vec3_t mins, vec3_t maxs );
 -vec_t                       BrushVolume( brush_t *brush );
 -void                        WriteBSPBrushMap( char *name, brush_t *list );
 -
 -void                        FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
 -void                        FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
 -
 -int                         BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane );
 -qboolean                    WindingIsTiny( winding_t *w );
 +sideRef_t                                     *AllocSideRef( side_t *side, sideRef_t *next );
 +int                                                   CountBrushList( brush_t *brushes );
 +brush_t                                               *AllocBrush( int numsides );
 +void                                          FreeBrush( brush_t *brushes );
 +void                                          FreeBrushList( brush_t *brushes );
 +brush_t                                               *CopyBrush( brush_t *brush );
 +qboolean                                      BoundBrush( brush_t *brush );
 +qboolean                                      CreateBrushWindings( brush_t *brush );
 +brush_t                                               *BrushFromBounds( vec3_t mins, vec3_t maxs );
 +vec_t                                         BrushVolume( brush_t *brush );
 +void                                          WriteBSPBrushMap( char *name, brush_t *list );
 +
 +void                                          FilterDetailBrushesIntoTree( entity_t *e, tree_t *tree );
 +void                                          FilterStructuralBrushesIntoTree( entity_t *e, tree_t *tree );
 +
 +int                                                   BoxOnPlaneSide( vec3_t mins, vec3_t maxs, plane_t *plane );
 +qboolean                                      WindingIsTiny( winding_t *w );
  
- void                                          SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back);
+ void                        SplitBrush( brush_t *brush, int planenum, brush_t **front, brush_t **back );
  
 -tree_t                      *AllocTree( void );
 -node_t                      *AllocNode( void );
 +tree_t                                                *AllocTree( void );
 +node_t                                                *AllocNode( void );
  
  
  /* mesh.c */
@@@ -1590,27 -1588,30 +1593,30 @@@ void                                         MakeNormalVectors( vec3_t for
  
  
  /* map.c */
 -void                        LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups );
 -int                         FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points );
 -int                         PlaneTypeForNormal( vec3_t normal );
 -void                        AddBrushBevels( void );
 +void                                          LoadMapFile( char *filename, qboolean onlyLights, qboolean noCollapseGroups );
 +int                                                   FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points );
 +int                                                   PlaneTypeForNormal( vec3_t normal );
 +void                                          AddBrushBevels( void );
- brush_t                                               *FinishBrush(qboolean noCollapseGroups);
+ brush_t                     *FinishBrush( qboolean noCollapseGroups );
  
  
  /* portals.c */
 -void                        MakeHeadnodePortals( tree_t *tree );
 -void                        MakeNodePortal( node_t *node );
 -void                        SplitNodePortals( node_t *node );
 +void                                          MakeHeadnodePortals( tree_t *tree );
 +void                                          MakeNodePortal( node_t *node );
 +void                                          SplitNodePortals( node_t *node );
  
 -qboolean                    PortalPassable( portal_t *p );
 +qboolean                                      PortalPassable( portal_t *p );
  
- qboolean                                      FloodEntities( tree_t *tree );
- void                                          FillOutside( node_t *headnode);
- void                                          FloodAreas( tree_t *tree);
+ #define FLOODENTITIES_LEAKED 1
+ #define FLOODENTITIES_GOOD 0
+ #define FLOODENTITIES_EMPTY -1
+ int                     FloodEntities( tree_t *tree );
+ void                        FillOutside( node_t *headnode );
+ void                        FloodAreas( tree_t *tree );
 -face_t                      *VisibleFaces( entity_t *e, tree_t *tree );
 -void                        FreePortal( portal_t *p );
 +face_t                                                *VisibleFaces( entity_t *e, tree_t *tree );
 +void                                          FreePortal( portal_t *p );
  
 -void                        MakeTreePortals( tree_t *tree );
 +void                                          MakeTreePortals( tree_t *tree );
  
  
  /* leakfile.c */
@@@ -1645,10 -1646,10 +1651,10 @@@ void                                         FreeTreePortals_r( node_t *no
  
  
  /* patch.c */
 -void                        ParsePatch( qboolean onlyLights );
 -mesh_t                      *SubdivideMesh( mesh_t in, float maxError, float minLength );
 -void                        PatchMapDrawSurfs( entity_t *e );
 +void                                          ParsePatch( qboolean onlyLights );
 +mesh_t                                                *SubdivideMesh( mesh_t in, float maxError, float minLength );
 +void                                          PatchMapDrawSurfs( entity_t *e );
- void                                          TriangulatePatchSurface( entity_t *e , mapDrawSurface_t *ds );
+ void                        TriangulatePatchSurface( entity_t *e, mapDrawSurface_t *ds );
  
  
  /* tjunction.c */
@@@ -1746,14 -1747,14 +1752,14 @@@ void                                         LoadSurfaceExtraFile( const c
  
  
  /* decals.c */
 -void                        ProcessDecals( void );
 -void                        MakeEntityDecals( entity_t *e );
 +void                                          ProcessDecals( void );
 +void                                          MakeEntityDecals( entity_t *e );
  
  /* map.c */
 -void                        TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv );
 +void                                          TextureAxisFromPlane( plane_t *pln, vec3_t xv, vec3_t yv );
  
  /* brush_primit.c */
- void                                          ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY);
+ void                        ComputeAxisBase( vec3_t normal, vec3_t texX, vec3_t texY );
  
  
  /* vis.c */
@@@ -1773,11 -1774,11 +1779,11 @@@ void                                         PassagePortalFlow( int portal
  
  
  /* light.c  */
 -float                       PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const winding_t *w );
 -int                         LightContributionToSample( trace_t *trace );
 +float                                         PointToPolygonFormFactor( const vec3_t point, const vec3_t normal, const winding_t *w );
 +int                                                   LightContributionToSample( trace_t *trace );
- void                                          LightingAtSample( trace_t *trace, byte styles[ MAX_LIGHTMAPS ], vec3_t colors[ MAX_LIGHTMAPS ] );
+ void LightingAtSample( trace_t * trace, byte styles[ MAX_LIGHTMAPS ], vec3_t colors[ MAX_LIGHTMAPS ] );
 -int                         LightContributionToPoint( trace_t *trace );
 -int                         LightMain( int argc, char **argv );
 +int                                                   LightContributionToPoint( trace_t *trace );
 +int                                                   LightMain( int argc, char **argv );
  
  
  /* light_trace.c */
@@@ -1787,44 -1788,45 +1793,45 @@@ float                                                SetupTrace( trace_t *trace )
  
  
  /* light_bounce.c */
- qboolean                                      RadSampleImage( byte *pixels, int width, int height, float st[ 2 ], float color[ 4 ] );
+ qboolean RadSampleImage( byte * pixels, int width, int height, float st[ 2 ], float color[ 4 ] );
 -void                        RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
 -void                        RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
 -void                        RadCreateDiffuseLights( void );
 -void                        RadFreeLights();
 +void                                          RadLightForTriangles( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
 +void                                          RadLightForPatch( int num, int lightmapNum, rawLightmap_t *lm, shaderInfo_t *si, float scale, float subdivide, clipWork_t *cw );
 +void                                          RadCreateDiffuseLights( void );
 +void                                          RadFreeLights();
  
  
  /* light_ydnar.c */
 -void                        ColorToBytes( const float *color, byte *colorBytes, float scale );
 -void                        SmoothNormals( void );
 +void                                          ColorToBytes( const float *color, byte *colorBytes, float scale );
 +void                                          SmoothNormals( void );
  
 -void                        MapRawLightmap( int num );
 +void                                          MapRawLightmap( int num );
  
 -void                        SetupDirt();
 -float                       DirtForSample( trace_t *trace );
 -void                        DirtyRawLightmap( int num );
 +void                                          SetupDirt();
 +float                                         DirtForSample( trace_t *trace );
 +void                                          DirtyRawLightmap( int num );
  
 -void                        SetupFloodLight();
 -void                        FloodlightRawLightmaps();
 -void                        FloodlightIlluminateLightmap( rawLightmap_t *lm );
 +void                                          SetupFloodLight();
 +void                                          FloodlightRawLightmaps();
 +void                                          FloodlightIlluminateLightmap( rawLightmap_t *lm );
- float                                         FloodLightForSample( trace_t *trace , float floodLightDistance, qboolean floodLightLowQuality);
+ float                       FloodLightForSample( trace_t *trace, float floodLightDistance, qboolean floodLightLowQuality );
 -void                        FloodLightRawLightmap( int num );
 +void                                          FloodLightRawLightmap( int num );
  
 -void                        IlluminateRawLightmap( int num );
 -void                        IlluminateVertexes( int num );
 +void                                          IlluminateRawLightmap( int num );
 +void                                          IlluminateVertexes( int num );
  
 -void                        SetupBrushes( void );
 -void                        SetupClusters( void );
 -qboolean                    ClusterVisible( int a, int b );
 -qboolean                    ClusterVisibleToPoint( vec3_t point, int cluster );
 -int                         ClusterForPoint( vec3_t point );
 -int                         ClusterForPointExt( vec3_t point, float epsilon );
 -int                         ClusterForPointExtFilter( vec3_t point, float epsilon, int numClusters, int *clusters );
 -int                         ShaderForPointInLeaf( vec3_t point, int leafNum, float epsilon, int wantContentFlags, int wantSurfaceFlags, int *contentFlags, int *surfaceFlags );
 -void                        SetupEnvelopes( qboolean forGrid, qboolean fastFlag );
 -void                        FreeTraceLights( trace_t *trace );
 -void                        CreateTraceLightsForBounds( vec3_t mins, vec3_t maxs, vec3_t normal, int numClusters, int *clusters, int flags, trace_t *trace );
 -void                        CreateTraceLightsForSurface( int num, trace_t *trace );
+ void                        SetupBrushesFlags( int mask_any, int test_any, int mask_all, int test_all );
 +void                                          SetupBrushes( void );
 +void                                          SetupClusters( void );
 +qboolean                                      ClusterVisible( int a, int b );
 +qboolean                                      ClusterVisibleToPoint( vec3_t point, int cluster );
 +int                                                   ClusterForPoint( vec3_t point );
 +int                                                   ClusterForPointExt( vec3_t point, float epsilon );
 +int                                                   ClusterForPointExtFilter( vec3_t point, float epsilon, int numClusters, int *clusters );
 +int                                                   ShaderForPointInLeaf( vec3_t point, int leafNum, float epsilon, int wantContentFlags, int wantSurfaceFlags, int *contentFlags, int *surfaceFlags );
 +void                                          SetupEnvelopes( qboolean forGrid, qboolean fastFlag );
 +void                                          FreeTraceLights( trace_t *trace );
 +void                                          CreateTraceLightsForBounds( vec3_t mins, vec3_t maxs, vec3_t normal, int numClusters, int *clusters, int flags, trace_t *trace );
 +void                                          CreateTraceLightsForSurface( int num, trace_t *trace );
  
  
  /* lightmaps_ydnar.c */
@@@ -1845,60 -1847,61 +1852,61 @@@ image_t                                              *ImageLoad( const char *fi
  
  
  /* shaders.c */
 -void                        ColorMod( colorMod_t *am, int numVerts, bspDrawVert_t *drawVerts );
 +void                                          ColorMod( colorMod_t *am, int numVerts, bspDrawVert_t *drawVerts );
  
 -void TCMod( tcMod_t mod, float st[ 2 ] );
 -void                        TCModIdentity( tcMod_t mod );
 -void                        TCModMultiply( tcMod_t a, tcMod_t b, tcMod_t out );
 -void                        TCModTranslate( tcMod_t mod, float s, float t );
 -void                        TCModScale( tcMod_t mod, float s, float t );
 -void                        TCModRotate( tcMod_t mod, float euler );
 +void                                          TCMod( tcMod_t mod, float st[ 2 ] );
 +void                                          TCModIdentity( tcMod_t mod );
 +void                                          TCModMultiply( tcMod_t a, tcMod_t b, tcMod_t out );
 +void                                          TCModTranslate( tcMod_t mod, float s, float t );
 +void                                          TCModScale( tcMod_t mod, float s, float t );
 +void                                          TCModRotate( tcMod_t mod, float euler );
  
 -qboolean                    ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags );
 +qboolean                                      ApplySurfaceParm( char *name, int *contentFlags, int *surfaceFlags, int *compileFlags );
  
 -void                        BeginMapShaderFile( const char *mapFile );
 -void                        WriteMapShaderFile( void );
 -shaderInfo_t                *CustomShader( shaderInfo_t *si, char *find, char *replace );
 -void                        EmitVertexRemapShader( char *from, char *to );
 +void                                          BeginMapShaderFile( const char *mapFile );
 +void                                          WriteMapShaderFile( void );
 +shaderInfo_t                          *CustomShader( shaderInfo_t *si, char *find, char *replace );
 +void                                          EmitVertexRemapShader( char *from, char *to );
  
 -void                        LoadShaderInfo( void );
 -shaderInfo_t                *ShaderInfoForShader( const char *shader );
 +void                                          LoadShaderInfo( void );
 +shaderInfo_t                          *ShaderInfoForShader( const char *shader );
+ shaderInfo_t                *ShaderInfoForShaderNull( const char *shader );
  
  
  /* bspfile_abstract.c */
 -void                        SetGridPoints( int n );
 -void                        SetDrawVerts( int n );
 -void                        IncDrawVerts();
 +void                                          SetGridPoints( int n );
 +void                                          SetDrawVerts( int n );
 +void                                          IncDrawVerts();
- void                                          SetDrawSurfaces(int n);
+ void                        SetDrawSurfaces( int n );
 -void                        SetDrawSurfacesBuffer();
 -void                        BSPFilesCleanup();
 -
 -void                        SwapBlock( int *block, int size );
 -
 -int                         GetLumpElements( bspHeader_t *header, int lump, int size );
 -void                        *GetLump( bspHeader_t *header, int lump );
 -int                         CopyLump( bspHeader_t *header, int lump, void *dest, int size );
 -int                         CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable );
 -void                        AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length );
 -
 -void                        LoadBSPFile( const char *filename );
 -void                        WriteBSPFile( const char *filename );
 -void                        PrintBSPFileSizes( void );
 -
 -epair_t                     *ParseEPair( void );
 -void                        ParseEntities( void );
 -void                        UnparseEntities( void );
 -void                        PrintEntity( const entity_t *ent );
 -void                        SetKeyValue( entity_t *ent, const char *key, const char *value );
 -qboolean                    KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
 -const char                  *ValueForKey( const entity_t *ent, const char *key );
 -int                         IntForKey( const entity_t *ent, const char *key );
 -vec_t                       FloatForKey( const entity_t *ent, const char *key );
 -void                        GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec );
 -entity_t                    *FindTargetEntity( const char *target );
 -void                        GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );
 +void                                          SetDrawSurfacesBuffer();
 +void                                          BSPFilesCleanup();
 +
 +void                                          SwapBlock( int *block, int size );
 +
 +int                                                   GetLumpElements( bspHeader_t *header, int lump, int size );
 +void                                          *GetLump( bspHeader_t *header, int lump );
 +int                                                   CopyLump( bspHeader_t *header, int lump, void *dest, int size );
 +int                                                   CopyLump_Allocate( bspHeader_t *header, int lump, void **dest, int size, int *allocationVariable );
 +void                                          AddLump( FILE *file, bspHeader_t *header, int lumpNum, const void *data, int length );
 +
 +void                                          LoadBSPFile( const char *filename );
 +void                                          WriteBSPFile( const char *filename );
 +void                                          PrintBSPFileSizes( void );
 +
 +epair_t                                               *ParseEPair( void );
 +void                                          ParseEntities( void );
 +void                                          UnparseEntities( void );
 +void                                          PrintEntity( const entity_t *ent );
 +void                                          SetKeyValue( entity_t *ent, const char *key, const char *value );
 +qboolean                                      KeyExists( const entity_t *ent, const char *key ); /* VorteX: check if key exists */
 +const char                                    *ValueForKey( const entity_t *ent, const char *key );
 +int                                                   IntForKey( const entity_t *ent, const char *key );
 +vec_t                                         FloatForKey( const entity_t *ent, const char *key );
 +void                                          GetVectorForKey( const entity_t *ent, const char *key, vec3_t vec );
 +entity_t                                      *FindTargetEntity( const char *target );
 +void                                          GetEntityShadowFlags( const entity_t *ent, const entity_t *ent2, int *castShadows, int *recvShadows );
- void InjectCommandLine(char **argv, int beginArgs, int endArgs);
+ void InjectCommandLine( char **argv, int beginArgs, int endArgs );
 -
 +              
  
  
  /* bspfile_ibsp.c */
@@@ -1927,52 -1930,52 +1935,52 @@@ void                                         WriteRBSPFile( const char *fi
  #endif
  
  /* game support */
 -Q_EXTERN game_t games[]
 +Q_EXTERN game_t                               games[]
  #ifndef MAIN_C
                                                      ;
+ ;
  #else
 -      =
 -      {
 +                                                      =
 +                                                      {
                                                                #include "game_quake3.h"
 -      ,
 +                                                              ,
-                                                               #include "game_quakelive.h"/* most be after game_quake3.h as they share defines! */
+                                                               #include "game_quakelive.h" /* most be after game_quake3.h as they share defines! */
 -      ,
 +                                                              ,
-                                                               #include "game_nexuiz.h"/* most be after game_quake3.h as they share defines! */
+                                                               #include "game_nexuiz.h" /* most be after game_quake3.h as they share defines! */
 -      ,
 +                                                              ,
-                                                               #include "game_xonotic.h"/* most be after game_quake3.h as they share defines! */
+                                                               #include "game_xonotic.h" /* most be after game_quake3.h as they share defines! */
 -      ,
 +                                                              ,
                                                                #include "game_tremulous.h" /*LinuxManMikeC: must be after game_quake3.h, depends on #define's set in it */
 -      ,
 +                                                              ,
                                                                #include "game_tenebrae.h"
 -      ,
 +                                                              ,
                                                                #include "game_wolf.h"
 -      ,
 +                                                              ,
-                                                               #include "game_wolfet.h"/* most be after game_wolf.h as they share defines! */
+                                                               #include "game_wolfet.h" /* most be after game_wolf.h as they share defines! */
 -      ,
 +                                                              ,
                                                                #include "game_etut.h"
 -      ,
 +                                                              ,
                                                                #include "game_ef.h"
 -      ,
 +                                                              ,
                                                                #include "game_sof2.h"
 -      ,
 -                                                              #include "game_jk2.h"   /* most be after game_sof2.h as they share defines! */
 -      ,
 -                                                              #include "game_ja.h"    /* most be after game_jk2.h as they share defines! */
 -      ,
 -                                                              #include "game_qfusion.h"   /* qfusion game */
 -      ,
 +                                                              ,
 +                                                              #include "game_jk2.h"   /* most be after game_sof2.h as they share defines! */
 +                                                              ,
 +                                                              #include "game_ja.h"    /* most be after game_jk2.h as they share defines! */
 +                                                              ,
 +                                                              #include "game_qfusion.h"       /* qfusion game */
 +                                                              ,
                                                                #include "game_reaction.h" /* must be after game_quake3.h */
 -      ,
 -                                                              #include "game_darkplaces.h"    /* vortex: darkplaces q1 engine */
 -      ,
 -                                                              #include "game_dq.h"    /* vortex: deluxe quake game ( darkplaces q1 engine) */
 -      ,
 -                                                              #include "game_prophecy.h"  /* vortex: prophecy game ( darkplaces q1 engine) */
 -      ,
 -                                                              #include "game__null.h" /* null game (must be last item) */
 -      };
 +                                                              ,
 +                                                              #include "game_darkplaces.h"    /* vortex: darkplaces q1 engine */
 +                                                              ,
 +                                                              #include "game_dq.h"    /* vortex: deluxe quake game ( darkplaces q1 engine) */
 +                                                              ,
 +                                                              #include "game_prophecy.h"      /* vortex: prophecy game ( darkplaces q1 engine) */
 +                                                              ,
 +                                                              #include "game__null.h" /* null game (must be last item) */
 +                                                      };
  #endif
 -Q_EXTERN game_t             *game Q_ASSIGN( &games[ 0 ] );
 +Q_EXTERN game_t                               *game Q_ASSIGN( &games[ 0 ] );
  
  
  /* general */
@@@ -1998,47 -2001,50 +2006,50 @@@ Q_EXTERN float                               jitters[ MAX_JITTERS 
  
  
  /* commandline arguments */
 -Q_EXTERN qboolean verbose;
 -Q_EXTERN qboolean verboseEntities Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean force Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean infoMode Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean useCustomInfoParms Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean noprune Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean leaktest Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean nodetail Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean nosubdivide Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean notjunc Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean fulldetail Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean nowater Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean noCurveBrushes Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean fakemap Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean coplanar Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean nofog Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean noHint Q_ASSIGN( qfalse );                        /* ydnar */
 -Q_EXTERN qboolean renameModelShaders Q_ASSIGN( qfalse );            /* ydnar */
 -Q_EXTERN qboolean skyFixHack Q_ASSIGN( qfalse );                    /* ydnar */
 -Q_EXTERN qboolean bspAlternateSplitWeights Q_ASSIGN( qfalse );                      /* 27 */
 -Q_EXTERN qboolean deepBSP Q_ASSIGN( qfalse );                   /* div0 */
 -Q_EXTERN qboolean maxAreaFaceSurface Q_ASSIGN( qfalse );                    /* divVerent */
 -
 -Q_EXTERN int patchSubdivisions Q_ASSIGN( 8 );                       /* ydnar: -patchmeta subdivisions */
 -
 -Q_EXTERN int maxLMSurfaceVerts Q_ASSIGN( 64 );                      /* ydnar */
 -Q_EXTERN int maxSurfaceVerts Q_ASSIGN( 999 );                       /* ydnar */
 -Q_EXTERN int maxSurfaceIndexes Q_ASSIGN( 6000 );                    /* ydnar */
 -Q_EXTERN float npDegrees Q_ASSIGN( 0.0f );                          /* ydnar: nonplanar degrees */
 -Q_EXTERN int bevelSnap Q_ASSIGN( 0 );                               /* ydnar: bevel plane snap */
 -Q_EXTERN int texRange Q_ASSIGN( 0 );
 -Q_EXTERN qboolean flat Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean meta Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean patchMeta Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean emitFlares Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugSurfaces Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugInset Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugPortals Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     verbose;
 +Q_EXTERN qboolean                     verboseEntities Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     force Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     infoMode Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     useCustomInfoParms Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     noprune Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     leaktest Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     nodetail Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     nosubdivide Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     notjunc Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     fulldetail Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     nowater Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     noCurveBrushes Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     fakemap Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     coplanar Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     nofog Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     noHint Q_ASSIGN( qfalse );                              /* ydnar */
 +Q_EXTERN qboolean                     renameModelShaders Q_ASSIGN( qfalse );  /* ydnar */
 +Q_EXTERN qboolean                     skyFixHack Q_ASSIGN( qfalse );                  /* ydnar */
 +Q_EXTERN qboolean                     bspAlternateSplitWeights Q_ASSIGN( qfalse );                    /* 27 */
 +Q_EXTERN qboolean                     deepBSP Q_ASSIGN( qfalse );                     /* div0 */
 +Q_EXTERN qboolean                     maxAreaFaceSurface Q_ASSIGN( qfalse );                  /* divVerent */
 +
 +Q_EXTERN int                          patchSubdivisions Q_ASSIGN( 8 );                /* ydnar: -patchmeta subdivisions */
 +
 +Q_EXTERN int                          maxLMSurfaceVerts Q_ASSIGN( 64 );               /* ydnar */
 +Q_EXTERN int                          maxSurfaceVerts Q_ASSIGN( 999 );                /* ydnar */
 +Q_EXTERN int                          maxSurfaceIndexes Q_ASSIGN( 6000 );             /* ydnar */
 +Q_EXTERN float                                npDegrees Q_ASSIGN( 0.0f );                             /* ydnar: nonplanar degrees */
 +Q_EXTERN int                          bevelSnap Q_ASSIGN( 0 );                                /* ydnar: bevel plane snap */
 +Q_EXTERN int                          texRange Q_ASSIGN( 0 );
 +Q_EXTERN qboolean                     flat Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     meta Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     patchMeta Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     emitFlares Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugSurfaces Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugInset Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugPortals Q_ASSIGN( qfalse );
- Q_EXTERN qboolean           lightmapTriangleCheck Q_ASSIGN(qfalse);
- Q_EXTERN qboolean           lightmapExtraVisClusterNudge Q_ASSIGN(qfalse);
- Q_EXTERN qboolean           lightmapFill Q_ASSIGN(qfalse);
+ Q_EXTERN qboolean lightmapTriangleCheck Q_ASSIGN( qfalse );
+ Q_EXTERN qboolean lightmapExtraVisClusterNudge Q_ASSIGN( qfalse );
+ Q_EXTERN qboolean lightmapFill Q_ASSIGN( qfalse );
+ Q_EXTERN int metaAdequateScore Q_ASSIGN( -1 );
+ Q_EXTERN int metaGoodScore Q_ASSIGN( -1 );
+ Q_EXTERN float metaMaxBBoxDistance Q_ASSIGN( -1 );
  
  #if Q3MAP2_EXPERIMENTAL_SNAP_NORMAL_FIX
  // Increasing the normalEpsilon to compensate for new logic in SnapNormal(), where
  // components.  Unfortunately, normalEpsilon is also used in PlaneEqual().  So changing
  // this will affect anything that calls PlaneEqual() as well (which are, at the time
  // of this writing, FindFloatPlane() and AddBrushBevels()).
- Q_EXTERN double                               normalEpsilon Q_ASSIGN(0.00005);
+ Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00005 );
  #else
 -Q_EXTERN double normalEpsilon Q_ASSIGN( 0.00001 );
 +Q_EXTERN double                               normalEpsilon Q_ASSIGN( 0.00001 );
  #endif
  
  #if Q3MAP2_EXPERIMENTAL_HIGH_PRECISION_MATH_FIXES
  // opinion.  The real fix for this problem is to have 64 bit distances and then make
  // this epsilon even smaller, or to constrain world coordinates to plus minus 2^15
  // (or even 2^14).
- Q_EXTERN double                               distanceEpsilon Q_ASSIGN(0.005);
+ Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.005 );
  #else
 -Q_EXTERN double distanceEpsilon Q_ASSIGN( 0.01 );
 +Q_EXTERN double                               distanceEpsilon Q_ASSIGN( 0.01 );
  #endif
  
  
  /* bsp */
 -Q_EXTERN int numMapEntities Q_ASSIGN( 0 );
 +Q_EXTERN int                          numMapEntities Q_ASSIGN( 0 );
  
 -Q_EXTERN int blockSize[ 3 ]                                 /* should be the same as in radiant */
 +Q_EXTERN int                          blockSize[ 3 ]                                  /* should be the same as in radiant */
  #ifndef MAIN_C
                                                      ;
+ ;
  #else
 -      = { 1024, 1024, 1024 };
 +                                                      = { 1024, 1024, 1024 };
  #endif
  
 -Q_EXTERN char name[ 1024 ];
 -Q_EXTERN char source[ 1024 ];
 -Q_EXTERN char outbase[ 32 ];
 +Q_EXTERN char                         name[ 1024 ];
 +Q_EXTERN char                         source[ 1024 ];
 +Q_EXTERN char                         outbase[ 32 ];
  
 -Q_EXTERN int sampleSize;                                    /* lightmap sample size in units */
 -Q_EXTERN int minSampleSize;                                 /* minimum sample size to use at all */
 -Q_EXTERN int sampleScale;                                   /* vortex: lightmap sample scale (ie quality)*/
 +Q_EXTERN int                          sampleSize;                                             /* lightmap sample size in units */
 +Q_EXTERN int                          minSampleSize;                  /* minimum sample size to use at all */
 +Q_EXTERN int                          sampleScale;                                    /* vortex: lightmap sample scale (ie quality)*/
  
 -Q_EXTERN int mapEntityNum Q_ASSIGN( 0 );
 +Q_EXTERN int                          mapEntityNum Q_ASSIGN( 0 );
  
 -Q_EXTERN int entitySourceBrushes;
 +Q_EXTERN int                          entitySourceBrushes;
  
- Q_EXTERN plane_t                      *mapplanes Q_ASSIGN(NULL);      /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */
- Q_EXTERN int                          nummapplanes Q_ASSIGN(0);               /* nummapplanes will always be even */
- Q_EXTERN int                          allocatedmapplanes Q_ASSIGN(0);
+ Q_EXTERN plane_t            *mapplanes Q_ASSIGN( NULL );  /* mapplanes[ num ^ 1 ] will always be the mirror or mapplanes[ num ] */
+ Q_EXTERN int nummapplanes Q_ASSIGN( 0 );                    /* nummapplanes will always be even */
+ Q_EXTERN int allocatedmapplanes Q_ASSIGN( 0 );
 -Q_EXTERN int numMapPatches;
 -Q_EXTERN vec3_t mapMins, mapMaxs;
 +Q_EXTERN int                          numMapPatches;
 +Q_EXTERN vec3_t                               mapMins, mapMaxs;
  
 -Q_EXTERN int defaultFogNum Q_ASSIGN( -1 );                  /* ydnar: cleaner fog handling */
 -Q_EXTERN int numMapFogs Q_ASSIGN( 0 );
 -Q_EXTERN fog_t mapFogs[ MAX_MAP_FOGS ];
 +Q_EXTERN int                          defaultFogNum Q_ASSIGN( -1 );   /* ydnar: cleaner fog handling */
 +Q_EXTERN int                          numMapFogs Q_ASSIGN( 0 );
 +Q_EXTERN fog_t                                mapFogs[ MAX_MAP_FOGS ];
  
 -Q_EXTERN entity_t           *mapEnt;
 -Q_EXTERN brush_t            *buildBrush;
 -Q_EXTERN int numActiveBrushes;
 -Q_EXTERN int g_bBrushPrimit;
 +Q_EXTERN entity_t                     *mapEnt;
 +Q_EXTERN brush_t                      *buildBrush;
 +Q_EXTERN int                          numActiveBrushes;
 +Q_EXTERN int                          g_bBrushPrimit;
  
 -Q_EXTERN int numStrippedLights Q_ASSIGN( 0 );
 +Q_EXTERN int                          numStrippedLights Q_ASSIGN( 0 );
  
  
  /* surface stuff */
 -Q_EXTERN mapDrawSurface_t   *mapDrawSurfs Q_ASSIGN( NULL );
 -Q_EXTERN int numMapDrawSurfs;
 +Q_EXTERN mapDrawSurface_t     *mapDrawSurfs Q_ASSIGN( NULL );
 +Q_EXTERN int                          numMapDrawSurfs;
  
 -Q_EXTERN int numSurfacesByType[ NUM_SURFACE_TYPES ];
 -Q_EXTERN int numClearedSurfaces;
 -Q_EXTERN int numStripSurfaces;
 -Q_EXTERN int numMaxAreaSurfaces;
 -Q_EXTERN int numFanSurfaces;
 -Q_EXTERN int numMergedSurfaces;
 -Q_EXTERN int numMergedVerts;
 +Q_EXTERN int                          numSurfacesByType[ NUM_SURFACE_TYPES ];
 +Q_EXTERN int                          numClearedSurfaces;
 +Q_EXTERN int                          numStripSurfaces;
 +Q_EXTERN int                          numMaxAreaSurfaces;
 +Q_EXTERN int                          numFanSurfaces;
 +Q_EXTERN int                          numMergedSurfaces;
 +Q_EXTERN int                          numMergedVerts;
  
 -Q_EXTERN int numRedundantIndexes;
 +Q_EXTERN int                          numRedundantIndexes;
  
 -Q_EXTERN int numSurfaceModels Q_ASSIGN( 0 );
 +Q_EXTERN int                          numSurfaceModels Q_ASSIGN( 0 );
  
 -Q_EXTERN byte debugColors[ 12 ][ 3 ]
 +Q_EXTERN byte                         debugColors[ 12 ][ 3 ]
  #ifndef MAIN_C
                                                      ;
+ ;
  #else
 -      =
 -      {
 -      { 255, 0, 0 },
 -      { 192, 128, 128 },
 -      { 255, 255, 0 },
 -      { 192, 192, 128 },
 -      { 0, 255, 255 },
 -      { 128, 192, 192 },
 -      { 0, 0, 255 },
 -      { 128, 128, 192 },
 -      { 255, 0, 255 },
 -      { 192, 128, 192 },
 -      { 0, 255, 0 },
 -      { 128, 192, 128 }
 -      };
 +                                                      =
 +                                                      {
 +                                                              { 255, 0, 0 },
 +                                                              { 192, 128, 128 },
 +                                                              { 255, 255, 0 },
 +                                                              { 192, 192, 128 },
 +                                                              { 0, 255, 255 },
 +                                                              { 128, 192, 192 },
 +                                                              { 0, 0, 255 },
 +                                                              { 128, 128, 192 },
 +                                                              { 255, 0, 255 },
 +                                                              { 192, 128, 192 },
 +                                                              { 0, 255, 0 },
 +                                                              { 128, 192, 128 }
 +                                                      };
  #endif
  
 -Q_EXTERN qboolean skyboxPresent Q_ASSIGN( qfalse );
 -Q_EXTERN int skyboxArea Q_ASSIGN( -1 );
 -Q_EXTERN m4x4_t skyboxTransform;
 +Q_EXTERN qboolean                     skyboxPresent Q_ASSIGN( qfalse );
 +Q_EXTERN int                          skyboxArea Q_ASSIGN( -1 );
 +Q_EXTERN m4x4_t                               skyboxTransform;
  
  
  
  /* -------------------------------------------------------------------------------
  
- vis global variables
   vis global variables
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
  /* commandline arguments */
 -Q_EXTERN qboolean fastvis;
 -Q_EXTERN qboolean noPassageVis;
 -Q_EXTERN qboolean passageVisOnly;
 -Q_EXTERN qboolean mergevis;
 -Q_EXTERN qboolean mergevisportals;
 -Q_EXTERN qboolean nosort;
 -Q_EXTERN qboolean saveprt;
 -Q_EXTERN qboolean hint;             /* ydnar */
 -Q_EXTERN char inbase[ MAX_QPATH ];
 -Q_EXTERN char globalCelShader[ MAX_QPATH ];
 +Q_EXTERN qboolean                     fastvis;
 +Q_EXTERN qboolean                     noPassageVis;
 +Q_EXTERN qboolean                     passageVisOnly;
 +Q_EXTERN qboolean                     mergevis;
 +Q_EXTERN qboolean                     mergevisportals;
 +Q_EXTERN qboolean                     nosort;
 +Q_EXTERN qboolean                     saveprt;
 +Q_EXTERN qboolean                     hint;   /* ydnar */
 +Q_EXTERN char                         inbase[ MAX_QPATH ];
 +Q_EXTERN char                         globalCelShader[ MAX_QPATH ];
  
 -Q_EXTERN float farPlaneDist;                /* rr2do2, rf, mre, ydnar all contributed to this one... */
 +Q_EXTERN float                                farPlaneDist;   /* rr2do2, rf, mre, ydnar all contributed to this one... */
  
 -Q_EXTERN int numportals;
 -Q_EXTERN int portalclusters;
 +Q_EXTERN int                          numportals;
 +Q_EXTERN int                          portalclusters;
  
 -Q_EXTERN vportal_t          *portals;
 -Q_EXTERN leaf_t             *leafs;
 +Q_EXTERN vportal_t                    *portals;
 +Q_EXTERN leaf_t                               *leafs;
  
 -Q_EXTERN vportal_t          *faces;
 -Q_EXTERN leaf_t             *faceleafs;
 +Q_EXTERN vportal_t                    *faces;
 +Q_EXTERN leaf_t                               *faceleafs;
  
 -Q_EXTERN int numfaces;
 +Q_EXTERN int                          numfaces;
  
 -Q_EXTERN int c_portaltest, c_portalpass, c_portalcheck;
 -Q_EXTERN int c_portalskip, c_leafskip;
 -Q_EXTERN int c_vistest, c_mighttest;
 -Q_EXTERN int c_chains;
 +Q_EXTERN int                          c_portaltest, c_portalpass, c_portalcheck;
 +Q_EXTERN int                          c_portalskip, c_leafskip;
 +Q_EXTERN int                          c_vistest, c_mighttest;
 +Q_EXTERN int                          c_chains;
  
 -Q_EXTERN byte               *vismap, *vismap_p, *vismap_end;
 +Q_EXTERN byte                         *vismap, *vismap_p, *vismap_end;
  
 -Q_EXTERN int testlevel;
 +Q_EXTERN int                          testlevel;
  
 -Q_EXTERN byte               *uncompressed;
 +Q_EXTERN byte                         *uncompressed;
  
 -Q_EXTERN int leafbytes, leaflongs;
 -Q_EXTERN int portalbytes, portallongs;
 +Q_EXTERN int                          leafbytes, leaflongs;
 +Q_EXTERN int                          portalbytes, portallongs;
  
 -Q_EXTERN vportal_t          *sorted_portals[ MAX_MAP_PORTALS * 2 ];
 +Q_EXTERN vportal_t                    *sorted_portals[ MAX_MAP_PORTALS * 2 ];
  
  
  
  /* -------------------------------------------------------------------------------
  
- light global variables
   light global variables
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
  /* commandline arguments */
 -Q_EXTERN qboolean wolfLight Q_ASSIGN( qfalse );
 -Q_EXTERN float extraDist Q_ASSIGN( 0.0f );
 -Q_EXTERN qboolean loMem Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean noStyles Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean keepLights Q_ASSIGN( qfalse );
 -
 -Q_EXTERN int sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
 -Q_EXTERN int minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE );
 -Q_EXTERN qboolean noVertexLighting Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean noGridLighting Q_ASSIGN( qfalse );
 -
 -Q_EXTERN qboolean noTrace Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean noSurfaces Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean patchShadows Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean cpmaHack Q_ASSIGN( qfalse );
 -
 -Q_EXTERN qboolean deluxemap Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugDeluxemap Q_ASSIGN( qfalse );
 -Q_EXTERN int deluxemode Q_ASSIGN( 0 );                  /* deluxemap format (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
 -
 -Q_EXTERN qboolean fast Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     wolfLight Q_ASSIGN( qfalse );
 +Q_EXTERN float                                extraDist Q_ASSIGN( 0.0f );
 +Q_EXTERN qboolean                     loMem Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     noStyles Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     keepLights Q_ASSIGN( qfalse );
 +
 +Q_EXTERN int                          sampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_SAMPLE_SIZE );
 +Q_EXTERN int                          minSampleSize Q_ASSIGN( DEFAULT_LIGHTMAP_MIN_SAMPLE_SIZE );
 +Q_EXTERN qboolean                     noVertexLighting Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     noGridLighting Q_ASSIGN( qfalse );
 +
 +Q_EXTERN qboolean                     noTrace Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     noSurfaces Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     patchShadows Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     cpmaHack Q_ASSIGN( qfalse );
 +
 +Q_EXTERN qboolean                     deluxemap Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugDeluxemap Q_ASSIGN( qfalse );
 +Q_EXTERN int                          deluxemode Q_ASSIGN( 0 );       /* deluxemap format (0 - modelspace, 1 - tangentspace with renormalization, 2 - tangentspace without renormalization) */
 +
 +Q_EXTERN qboolean                     fast Q_ASSIGN( qfalse );
+ Q_EXTERN qboolean fastpoint Q_ASSIGN( qtrue );
 -Q_EXTERN qboolean faster Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean fastgrid Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean fastbounce Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean cheap Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean cheapgrid Q_ASSIGN( qfalse );
 -Q_EXTERN int bounce Q_ASSIGN( 0 );
 -Q_EXTERN qboolean bounceOnly Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean bouncing Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean bouncegrid Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean normalmap Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean trisoup Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean shade Q_ASSIGN( qfalse );
 -Q_EXTERN float shadeAngleDegrees Q_ASSIGN( 0.0f );
 -Q_EXTERN int superSample Q_ASSIGN( 0 );
 -Q_EXTERN int lightSamples Q_ASSIGN( 1 );
 -Q_EXTERN qboolean lightRandomSamples Q_ASSIGN( qfalse );
 -Q_EXTERN int lightSamplesSearchBoxSize Q_ASSIGN( 1 );
 -Q_EXTERN qboolean filter Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean dark Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean sunOnly Q_ASSIGN( qfalse );
 -Q_EXTERN int approximateTolerance Q_ASSIGN( 0 );
 -Q_EXTERN qboolean noCollapse Q_ASSIGN( qfalse );
 -Q_EXTERN int lightmapSearchBlockSize Q_ASSIGN( 0 );
 -Q_EXTERN qboolean exportLightmaps Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean externalLightmaps Q_ASSIGN( qfalse );
 -Q_EXTERN int lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH );
 -Q_EXTERN char *             lmCustomDir Q_ASSIGN( NULL );
 -Q_EXTERN int lmLimitSize Q_ASSIGN( 0 );
 -
 -Q_EXTERN qboolean dirty Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean dirtDebug Q_ASSIGN( qfalse );
 -Q_EXTERN int dirtMode Q_ASSIGN( 0 );
 -Q_EXTERN float dirtDepth Q_ASSIGN( 128.0f );
 -Q_EXTERN float dirtScale Q_ASSIGN( 1.0f );
 -Q_EXTERN float dirtGain Q_ASSIGN( 1.0f );
 +Q_EXTERN qboolean                     faster Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     fastgrid Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     fastbounce Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     cheap Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     cheapgrid Q_ASSIGN( qfalse );
 +Q_EXTERN int                          bounce Q_ASSIGN( 0 );
 +Q_EXTERN qboolean                     bounceOnly Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     bouncing Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     bouncegrid Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     normalmap Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     trisoup Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     shade Q_ASSIGN( qfalse );
 +Q_EXTERN float                                shadeAngleDegrees Q_ASSIGN( 0.0f );
 +Q_EXTERN int                          superSample Q_ASSIGN( 0 );
 +Q_EXTERN int                          lightSamples Q_ASSIGN( 1 );
 +Q_EXTERN qboolean                     lightRandomSamples Q_ASSIGN( qfalse );
 +Q_EXTERN int                          lightSamplesSearchBoxSize Q_ASSIGN( 1 );
 +Q_EXTERN qboolean                     filter Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     dark Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     sunOnly Q_ASSIGN( qfalse );
 +Q_EXTERN int                          approximateTolerance Q_ASSIGN( 0 );
 +Q_EXTERN qboolean                     noCollapse Q_ASSIGN( qfalse );
 +Q_EXTERN int                          lightmapSearchBlockSize Q_ASSIGN( 0 );
 +Q_EXTERN qboolean                     exportLightmaps Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     externalLightmaps Q_ASSIGN( qfalse );
 +Q_EXTERN int                          lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH );
 +Q_EXTERN char *                               lmCustomDir Q_ASSIGN( NULL );
 +Q_EXTERN int                          lmLimitSize Q_ASSIGN( 0 );
 +
 +Q_EXTERN qboolean                     dirty Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     dirtDebug Q_ASSIGN( qfalse );
 +Q_EXTERN int                          dirtMode Q_ASSIGN( 0 );
 +Q_EXTERN float                                dirtDepth Q_ASSIGN( 128.0f );
 +Q_EXTERN float                                dirtScale Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                dirtGain Q_ASSIGN( 1.0f );
  
  /* 27: floodlighting */
 -Q_EXTERN qboolean debugnormals Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean floodlighty Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean floodlight_lowquality Q_ASSIGN( qfalse );
 -Q_EXTERN vec3_t floodlightRGB;
 -Q_EXTERN float floodlightIntensity Q_ASSIGN( 512.0f );
 -Q_EXTERN float floodlightDistance Q_ASSIGN( 1024.0f );
 -Q_EXTERN float floodlightDirectionScale Q_ASSIGN( 1.0f );
 -
 -Q_EXTERN qboolean dump Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debug Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugUnused Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugAxis Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugCluster Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean debugOrigin Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean lightmapBorder Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                                     debugnormals Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                                     floodlighty Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                                     floodlight_lowquality Q_ASSIGN( qfalse );
 +Q_EXTERN vec3_t                                               floodlightRGB;
 +Q_EXTERN float                                                floodlightIntensity Q_ASSIGN( 512.0f );
 +Q_EXTERN float                                                floodlightDistance Q_ASSIGN( 1024.0f );
 +Q_EXTERN float                                                floodlightDirectionScale Q_ASSIGN( 1.0f );
 +
 +Q_EXTERN qboolean                     dump Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debug Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugUnused Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugAxis Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugCluster Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     debugOrigin Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     lightmapBorder Q_ASSIGN( qfalse );
  
  /* longest distance across the map */
 -Q_EXTERN float maxMapDistance Q_ASSIGN( 0 );
 +Q_EXTERN float                                maxMapDistance Q_ASSIGN( 0 );
  
  /* for run time tweaking of light sources */
 -Q_EXTERN float pointScale Q_ASSIGN( 7500.0f );
 +Q_EXTERN float                                pointScale Q_ASSIGN( 7500.0f );
+ Q_EXTERN float spotScale Q_ASSIGN( 7500.0f );
 -Q_EXTERN float areaScale Q_ASSIGN( 0.25f );
 -Q_EXTERN float skyScale Q_ASSIGN( 1.0f );
 -Q_EXTERN float bounceScale Q_ASSIGN( 0.25f );
 +Q_EXTERN float                                areaScale Q_ASSIGN( 0.25f );
 +Q_EXTERN float                                skyScale Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                bounceScale Q_ASSIGN( 0.25f );
  
  /* jal: alternative angle attenuation curve */
 -Q_EXTERN qboolean lightAngleHL Q_ASSIGN( qfalse );
 -
 +Q_EXTERN qboolean                     lightAngleHL Q_ASSIGN( qfalse );
 + 
  /* vortex: gridscale and gridambientscale */
 -Q_EXTERN float gridScale Q_ASSIGN( 1.0f );
 -Q_EXTERN float gridAmbientScale Q_ASSIGN( 1.0f );
 -Q_EXTERN float gridDirectionality Q_ASSIGN( 1.0f );
 -Q_EXTERN float gridAmbientDirectionality Q_ASSIGN( 0.0f );
 +Q_EXTERN float                                gridScale Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                gridAmbientScale Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                gridDirectionality Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                gridAmbientDirectionality Q_ASSIGN( 0.0f );
- Q_EXTERN qboolean                     inGrid Q_ASSIGN(0);
+ Q_EXTERN qboolean inGrid Q_ASSIGN( 0 );
  
  /* ydnar: lightmap gamma/compensation */
 -Q_EXTERN float lightmapGamma Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                lightmapGamma Q_ASSIGN( 1.0f );
- Q_EXTERN float                                lightmapExposure Q_ASSIGN( 1.0f );
+ Q_EXTERN float lightmapsRGB Q_ASSIGN( qfalse );
+ Q_EXTERN float texturesRGB Q_ASSIGN( qfalse );
+ Q_EXTERN float colorsRGB Q_ASSIGN( qfalse );
+ Q_EXTERN float lightmapExposure Q_ASSIGN( 0.0f );
 -Q_EXTERN float lightmapCompensate Q_ASSIGN( 1.0f );
 +Q_EXTERN float                                lightmapCompensate Q_ASSIGN( 1.0f );
  
  /* ydnar: for runtime tweaking of falloff tolerance */
 -Q_EXTERN float falloffTolerance Q_ASSIGN( 1.0f );
 -Q_EXTERN qboolean exactPointToPolygon Q_ASSIGN( qtrue );
 -Q_EXTERN float formFactorValueScale Q_ASSIGN( 3.0f );
 -Q_EXTERN float linearScale Q_ASSIGN( 1.0f / 8000.0f );
 +Q_EXTERN float                                falloffTolerance Q_ASSIGN( 1.0f );
 +Q_EXTERN qboolean                     exactPointToPolygon Q_ASSIGN( qtrue );
 +Q_EXTERN float                                formFactorValueScale Q_ASSIGN( 3.0f );
 +Q_EXTERN float                                linearScale Q_ASSIGN( 1.0f / 8000.0f );
  
  // for .ase conversion
 -Q_EXTERN qboolean shadersAsBitmap Q_ASSIGN( qfalse );
 -Q_EXTERN qboolean lightmapsAsTexcoord Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     shadersAsBitmap Q_ASSIGN( qfalse );
 +Q_EXTERN qboolean                     lightmapsAsTexcoord Q_ASSIGN( qfalse );
  
 -Q_EXTERN light_t            *lights;
 -Q_EXTERN int numPointLights;
 -Q_EXTERN int numSpotLights;
 -Q_EXTERN int numSunLights;
 -Q_EXTERN int numAreaLights;
 +Q_EXTERN light_t                      *lights;
 +Q_EXTERN int                          numPointLights;
 +Q_EXTERN int                          numSpotLights;
 +Q_EXTERN int                          numSunLights;
 +Q_EXTERN int                          numAreaLights;
  
  /* ydnar: for luxel placement */
 -Q_EXTERN int numSurfaceClusters, maxSurfaceClusters;
 -Q_EXTERN int                *surfaceClusters;
 +Q_EXTERN int                          numSurfaceClusters, maxSurfaceClusters;
 +Q_EXTERN int                          *surfaceClusters;
  
  /* ydnar: for radiosity */
 -Q_EXTERN int numDiffuseLights;
 -Q_EXTERN int numBrushDiffuseLights;
 -Q_EXTERN int numTriangleDiffuseLights;
 -Q_EXTERN int numPatchDiffuseLights;
 +Q_EXTERN int                          numDiffuseLights;
 +Q_EXTERN int                          numBrushDiffuseLights;
 +Q_EXTERN int                          numTriangleDiffuseLights;
 +Q_EXTERN int                          numPatchDiffuseLights;
  
  /* ydnar: general purpose extra copy of drawvert list */
 -Q_EXTERN bspDrawVert_t      *yDrawVerts;
 +Q_EXTERN bspDrawVert_t                *yDrawVerts;
  
  /* ydnar: for tracing statistics */
 -Q_EXTERN int minSurfacesTested;
 -Q_EXTERN int maxSurfacesTested;
 -Q_EXTERN int totalSurfacesTested;
 -Q_EXTERN int totalTraces;
 +Q_EXTERN int                          minSurfacesTested;
 +Q_EXTERN int                          maxSurfacesTested;
 +Q_EXTERN int                          totalSurfacesTested;
 +Q_EXTERN int                          totalTraces;
  
 -Q_EXTERN FILE               *dumpFile;
 +Q_EXTERN FILE                         *dumpFile;
  
 -Q_EXTERN int c_visible, c_occluded;
 -Q_EXTERN int c_subsampled;                  /* ydnar */
 +Q_EXTERN int                          c_visible, c_occluded;
 +Q_EXTERN int                          c_subsampled;   /* ydnar */
  
 -Q_EXTERN int defaultLightSubdivide Q_ASSIGN( 999 );
 +Q_EXTERN int                          defaultLightSubdivide Q_ASSIGN( 999 );
  
 -Q_EXTERN vec3_t ambientColor;
 -Q_EXTERN vec3_t minLight, minVertexLight, minGridLight;
 +Q_EXTERN vec3_t                               ambientColor;
 +Q_EXTERN vec3_t                               minLight, minVertexLight, minGridLight;
  
 -Q_EXTERN int                *entitySurface;
 -Q_EXTERN vec3_t             *surfaceOrigin;
 +Q_EXTERN int                          *entitySurface;
 +Q_EXTERN vec3_t                               *surfaceOrigin;
  
 -Q_EXTERN vec3_t sunDirection;
 -Q_EXTERN vec3_t sunLight;
 +Q_EXTERN vec3_t                               sunDirection;
 +Q_EXTERN vec3_t                               sunLight;
  
  /* tracing */
 -Q_EXTERN int c_totalTrace;
 -Q_EXTERN int c_cullTrace, c_testTrace;
 -Q_EXTERN int c_testFacets;
 +Q_EXTERN int                          c_totalTrace;
 +Q_EXTERN int                          c_cullTrace, c_testTrace;
 +Q_EXTERN int                          c_testFacets;
  
  /* ydnar: light optimization */
 -Q_EXTERN float subdivideThreshold Q_ASSIGN( DEFAULT_SUBDIVIDE_THRESHOLD );
 +Q_EXTERN float                                subdivideThreshold Q_ASSIGN( DEFAULT_SUBDIVIDE_THRESHOLD );
  
 -Q_EXTERN int numOpaqueBrushes, maxOpaqueBrush;
 -Q_EXTERN byte               *opaqueBrushes;
 +Q_EXTERN int                          numOpaqueBrushes, maxOpaqueBrush;
 +Q_EXTERN byte                         *opaqueBrushes;
  
 -Q_EXTERN int numLights;
 -Q_EXTERN int numCulledLights;
 +Q_EXTERN int                          numLights;
 +Q_EXTERN int                          numCulledLights;
  
 -Q_EXTERN int gridBoundsCulled;
 -Q_EXTERN int gridEnvelopeCulled;
 +Q_EXTERN int                          gridBoundsCulled;
 +Q_EXTERN int                          gridEnvelopeCulled;
  
 -Q_EXTERN int lightsBoundsCulled;
 -Q_EXTERN int lightsEnvelopeCulled;
 -Q_EXTERN int lightsPlaneCulled;
 -Q_EXTERN int lightsClusterCulled;
 +Q_EXTERN int                          lightsBoundsCulled;
 +Q_EXTERN int                          lightsEnvelopeCulled;
 +Q_EXTERN int                          lightsPlaneCulled;
 +Q_EXTERN int                          lightsClusterCulled;
  
  /* ydnar: radiosity */
 -Q_EXTERN float diffuseSubdivide Q_ASSIGN( 256.0f );
 -Q_EXTERN float minDiffuseSubdivide Q_ASSIGN( 64.0f );
 -Q_EXTERN int numDiffuseSurfaces Q_ASSIGN( 0 );
 +Q_EXTERN float                                diffuseSubdivide Q_ASSIGN( 256.0f );
 +Q_EXTERN float                                minDiffuseSubdivide Q_ASSIGN( 64.0f );
 +Q_EXTERN int                          numDiffuseSurfaces Q_ASSIGN( 0 );
  
  /* ydnar: list of surface information necessary for lightmap calculation */
 -Q_EXTERN surfaceInfo_t      *surfaceInfos Q_ASSIGN( NULL );
 +Q_EXTERN surfaceInfo_t                *surfaceInfos Q_ASSIGN( NULL );
  
  /* ydnar: sorted list of surfaces */
 -Q_EXTERN int                *sortSurfaces Q_ASSIGN( NULL );
 +Q_EXTERN int                          *sortSurfaces Q_ASSIGN( NULL );
  
  /* clumps of surfaces that share a raw lightmap */
 -Q_EXTERN int numLightSurfaces Q_ASSIGN( 0 );
 -Q_EXTERN int                *lightSurfaces Q_ASSIGN( NULL );
 +Q_EXTERN int                          numLightSurfaces Q_ASSIGN( 0 );
 +Q_EXTERN int                          *lightSurfaces Q_ASSIGN( NULL );
  
  /* raw lightmaps */
 -Q_EXTERN int numRawSuperLuxels Q_ASSIGN( 0 );
 -Q_EXTERN int numRawLightmaps Q_ASSIGN( 0 );
 -Q_EXTERN rawLightmap_t      *rawLightmaps Q_ASSIGN( NULL );
 -Q_EXTERN int                *sortLightmaps Q_ASSIGN( NULL );
 +Q_EXTERN int                          numRawSuperLuxels Q_ASSIGN( 0 );
 +Q_EXTERN int                          numRawLightmaps Q_ASSIGN( 0 );
 +Q_EXTERN rawLightmap_t                *rawLightmaps Q_ASSIGN( NULL );
 +Q_EXTERN int                          *sortLightmaps Q_ASSIGN( NULL );
  
  /* vertex luxels */
 -Q_EXTERN float              *vertexLuxels[ MAX_LIGHTMAPS ];
 -Q_EXTERN float              *radVertexLuxels[ MAX_LIGHTMAPS ];
 +Q_EXTERN float                                *vertexLuxels[ MAX_LIGHTMAPS ];
 +Q_EXTERN float                                *radVertexLuxels[ MAX_LIGHTMAPS ];
  
  /* bsp lightmaps */
 -Q_EXTERN int numLightmapShaders Q_ASSIGN( 0 );
 -Q_EXTERN int numSolidLightmaps Q_ASSIGN( 0 );
 -Q_EXTERN int numOutLightmaps Q_ASSIGN( 0 );
 -Q_EXTERN int numBSPLightmaps Q_ASSIGN( 0 );
 -Q_EXTERN int numExtLightmaps Q_ASSIGN( 0 );
 -Q_EXTERN outLightmap_t      *outLightmaps Q_ASSIGN( NULL );
 +Q_EXTERN int                          numLightmapShaders Q_ASSIGN( 0 );
 +Q_EXTERN int                          numSolidLightmaps Q_ASSIGN( 0 );
 +Q_EXTERN int                          numOutLightmaps Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPLightmaps Q_ASSIGN( 0 );
 +Q_EXTERN int                          numExtLightmaps Q_ASSIGN( 0 );
 +Q_EXTERN outLightmap_t                *outLightmaps Q_ASSIGN( NULL );
  
  /* vortex: per surface floodlight statictics */
 -Q_EXTERN int numSurfacesFloodlighten Q_ASSIGN( 0 );
 +Q_EXTERN int                          numSurfacesFloodlighten Q_ASSIGN( 0 );
  
  /* grid points */
 -Q_EXTERN int numRawGridPoints Q_ASSIGN( 0 );
 -Q_EXTERN rawGridPoint_t     *rawGridPoints Q_ASSIGN( NULL );
 -
 -Q_EXTERN int numSurfsVertexLit Q_ASSIGN( 0 );
 -Q_EXTERN int numSurfsVertexForced Q_ASSIGN( 0 );
 -Q_EXTERN int numSurfsVertexApproximated Q_ASSIGN( 0 );
 -Q_EXTERN int numSurfsLightmapped Q_ASSIGN( 0 );
 -Q_EXTERN int numPlanarsLightmapped Q_ASSIGN( 0 );
 -Q_EXTERN int numNonPlanarsLightmapped Q_ASSIGN( 0 );
 -Q_EXTERN int numPatchesLightmapped Q_ASSIGN( 0 );
 -Q_EXTERN int numPlanarPatchesLightmapped Q_ASSIGN( 0 );
 -
 -Q_EXTERN int numLuxels Q_ASSIGN( 0 );
 -Q_EXTERN int numLuxelsMapped Q_ASSIGN( 0 );
 -Q_EXTERN int numLuxelsOccluded Q_ASSIGN( 0 );
 -Q_EXTERN int numLuxelsIlluminated Q_ASSIGN( 0 );
 -Q_EXTERN int numVertsIlluminated Q_ASSIGN( 0 );
 +Q_EXTERN int                          numRawGridPoints Q_ASSIGN( 0 );
 +Q_EXTERN rawGridPoint_t               *rawGridPoints Q_ASSIGN( NULL );
 +
 +Q_EXTERN int                          numSurfsVertexLit Q_ASSIGN( 0 );
 +Q_EXTERN int                          numSurfsVertexForced Q_ASSIGN( 0 );
 +Q_EXTERN int                          numSurfsVertexApproximated Q_ASSIGN( 0 );
 +Q_EXTERN int                          numSurfsLightmapped Q_ASSIGN( 0 );
 +Q_EXTERN int                          numPlanarsLightmapped Q_ASSIGN( 0 );
 +Q_EXTERN int                          numNonPlanarsLightmapped Q_ASSIGN( 0 );
 +Q_EXTERN int                          numPatchesLightmapped Q_ASSIGN( 0 );
 +Q_EXTERN int                          numPlanarPatchesLightmapped Q_ASSIGN( 0 );
 +
 +Q_EXTERN int                          numLuxels Q_ASSIGN( 0 );
 +Q_EXTERN int                          numLuxelsMapped Q_ASSIGN( 0 );
 +Q_EXTERN int                          numLuxelsOccluded Q_ASSIGN( 0 );
 +Q_EXTERN int                          numLuxelsIlluminated Q_ASSIGN( 0 );
 +Q_EXTERN int                          numVertsIlluminated Q_ASSIGN( 0 );
  
  /* lightgrid */
 -Q_EXTERN vec3_t gridMins;
 -Q_EXTERN int gridBounds[ 3 ];
 -Q_EXTERN vec3_t gridSize
 +Q_EXTERN vec3_t                               gridMins;
 +Q_EXTERN int                          gridBounds[ 3 ];
 +Q_EXTERN vec3_t                               gridSize
  #ifndef MAIN_C
                                                      ;
+ ;
  #else
 -      = { 64, 64, 128 };
 +                                                      = { 64, 64, 128 };
  #endif
  
  
  
  /* -------------------------------------------------------------------------------
  
- abstracted bsp globals
   abstracted bsp globals
  
- ------------------------------------------------------------------------------- */
   ------------------------------------------------------------------------------- */
  
 -Q_EXTERN int numEntities Q_ASSIGN( 0 );
 -Q_EXTERN int numBSPEntities Q_ASSIGN( 0 );
 +Q_EXTERN int                          numEntities Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPEntities Q_ASSIGN( 0 );
- Q_EXTERN entity_t                     entities[ MAX_MAP_ENTITIES ];
+ Q_EXTERN int allocatedEntities Q_ASSIGN( 0 );
+ Q_EXTERN entity_t*          entities Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPModels Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPModels Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPModels Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPModels Q_ASSIGN( 0 );
- Q_EXTERN bspModel_t*          bspModels Q_ASSIGN(NULL);
+ Q_EXTERN bspModel_t*        bspModels Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPShaders Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPShaders Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPShaders Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPShaders Q_ASSIGN( 0 );
- Q_EXTERN bspShader_t*         bspShaders Q_ASSIGN(0);
+ Q_EXTERN bspShader_t*       bspShaders Q_ASSIGN( 0 );
  
 -Q_EXTERN int bspEntDataSize Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPEntData Q_ASSIGN( 0 );
 +Q_EXTERN int                          bspEntDataSize Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPEntData Q_ASSIGN( 0 );
- Q_EXTERN char                         *bspEntData Q_ASSIGN(0);
+ Q_EXTERN char               *bspEntData Q_ASSIGN( 0 );
  
 -Q_EXTERN int numBSPLeafs Q_ASSIGN( 0 );
 -Q_EXTERN bspLeaf_t bspLeafs[ MAX_MAP_LEAFS ];
 +Q_EXTERN int                          numBSPLeafs Q_ASSIGN( 0 );
 +Q_EXTERN bspLeaf_t                    bspLeafs[ MAX_MAP_LEAFS ];
  
 -Q_EXTERN int numBSPPlanes Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPPlanes Q_ASSIGN( 0 );
- Q_EXTERN int                          allocatedBSPPlanes Q_ASSIGN(0);
+ Q_EXTERN int allocatedBSPPlanes Q_ASSIGN( 0 );
 -Q_EXTERN bspPlane_t         *bspPlanes;
 +Q_EXTERN bspPlane_t                   *bspPlanes;
  
 -Q_EXTERN int numBSPNodes Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPNodes Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPNodes Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPNodes Q_ASSIGN( 0 );
- Q_EXTERN bspNode_t*                   bspNodes Q_ASSIGN(NULL);
+ Q_EXTERN bspNode_t*         bspNodes Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPLeafSurfaces Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPLeafSurfaces Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPLeafSurfaces Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPLeafSurfaces Q_ASSIGN( 0 );
- Q_EXTERN int*                         bspLeafSurfaces Q_ASSIGN(NULL);
+ Q_EXTERN int*               bspLeafSurfaces Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPLeafBrushes Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPLeafBrushes Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPLeafBrushes Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPLeafBrushes Q_ASSIGN( 0 );
- Q_EXTERN int*                         bspLeafBrushes Q_ASSIGN(NULL);
+ Q_EXTERN int*               bspLeafBrushes Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPBrushes Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPBrushes Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPBrushes Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPBrushes Q_ASSIGN( 0 );
- Q_EXTERN bspBrush_t*          bspBrushes Q_ASSIGN(NULL);
+ Q_EXTERN bspBrush_t*        bspBrushes Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPBrushSides Q_ASSIGN( 0 );
 -Q_EXTERN int allocatedBSPBrushSides Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPBrushSides Q_ASSIGN( 0 );
 +Q_EXTERN int                          allocatedBSPBrushSides Q_ASSIGN( 0 );
- Q_EXTERN bspBrushSide_t*      bspBrushSides Q_ASSIGN(NULL);
+ Q_EXTERN bspBrushSide_t*    bspBrushSides Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPLightBytes Q_ASSIGN( 0 );
 -Q_EXTERN byte               *bspLightBytes Q_ASSIGN( NULL );
 +Q_EXTERN int                          numBSPLightBytes Q_ASSIGN( 0 );
 +Q_EXTERN byte                         *bspLightBytes Q_ASSIGN( NULL );
  
  //%   Q_EXTERN int                            numBSPGridPoints Q_ASSIGN( 0 );
  //%   Q_EXTERN byte                           *bspGridPoints Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPGridPoints Q_ASSIGN( 0 );
 -Q_EXTERN bspGridPoint_t     *bspGridPoints Q_ASSIGN( NULL );
 +Q_EXTERN int                          numBSPGridPoints Q_ASSIGN( 0 );
 +Q_EXTERN bspGridPoint_t               *bspGridPoints Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPVisBytes Q_ASSIGN( 0 );
 -Q_EXTERN byte bspVisBytes[ MAX_MAP_VISIBILITY ];
 +Q_EXTERN int                          numBSPVisBytes Q_ASSIGN( 0 );
 +Q_EXTERN byte                         bspVisBytes[ MAX_MAP_VISIBILITY ];
  
 -Q_EXTERN int numBSPDrawVerts Q_ASSIGN( 0 );
 -Q_EXTERN bspDrawVert_t          *bspDrawVerts Q_ASSIGN( NULL );
 +Q_EXTERN int                          numBSPDrawVerts Q_ASSIGN( 0 );
 +Q_EXTERN bspDrawVert_t                *bspDrawVerts Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPDrawIndexes Q_ASSIGN( 0 );
 +Q_EXTERN int                          numBSPDrawIndexes Q_ASSIGN( 0 );
- Q_EXTERN int                          bspDrawIndexes[ MAX_MAP_DRAW_INDEXES ];
+ Q_EXTERN int allocatedBSPDrawIndexes Q_ASSIGN( 0 );
+ Q_EXTERN int                *bspDrawIndexes Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPDrawSurfaces Q_ASSIGN( 0 );
 -Q_EXTERN bspDrawSurface_t   *bspDrawSurfaces Q_ASSIGN( NULL );
 +Q_EXTERN int                          numBSPDrawSurfaces Q_ASSIGN( 0 );
 +Q_EXTERN bspDrawSurface_t     *bspDrawSurfaces Q_ASSIGN( NULL );
  
 -Q_EXTERN int numBSPFogs Q_ASSIGN( 0 );
 -Q_EXTERN bspFog_t bspFogs[ MAX_MAP_FOGS ];
 +Q_EXTERN int                          numBSPFogs Q_ASSIGN( 0 );
 +Q_EXTERN bspFog_t                     bspFogs[ MAX_MAP_FOGS ];
  
 -Q_EXTERN int numBSPAds Q_ASSIGN( 0 );
 -Q_EXTERN bspAdvertisement_t bspAds[ MAX_MAP_ADVERTISEMENTS ];
 +Q_EXTERN int                          numBSPAds Q_ASSIGN( 0 );
 +Q_EXTERN bspAdvertisement_t   bspAds[ MAX_MAP_ADVERTISEMENTS ];
  
- #define AUTOEXPAND_BY_REALLOC(ptr, reqitem, allocated, def) \
+ #define AUTOEXPAND_BY_REALLOC( ptr, reqitem, allocated, def ) \
        do \
        { \
-               if(reqitem >= allocated) \
+               if ( reqitem >= allocated )     \
                { \
-                       if(allocated == 0) \
-                               allocated = def; \
-                       while(reqitem >= allocated && allocated) \
+                       if ( allocated == 0 ) { \
+                               allocated = def; \
+                       while ( reqitem >= allocated && allocated )     \
 -                              allocated *= 2; \
 +                              allocated *= 2; \
-                       if(!allocated || allocated > 2147483647 / (int)sizeof(*ptr)) \
+                       if ( !allocated || allocated > 2147483647 / (int)sizeof( *ptr ) ) \
                        { \
-                               Error(#ptr " over 2 GB"); \
+                               Error( # ptr " over 2 GB" ); \
                        } \
-                       ptr = realloc(ptr, sizeof(*ptr) * allocated); \
-                       if(!ptr) \
-                               Error(#ptr " out of memory"); \
+                       ptr = realloc( ptr, sizeof( *ptr ) * allocated ); \
+                       if ( !ptr ) { \
+                               Error( # ptr " out of memory" ); } \
                } \
        } \
-       while(0)
+       while ( 0 )
+ #define AUTOEXPAND_BY_REALLOC_BSP( suffix, def ) AUTOEXPAND_BY_REALLOC( bsp ## suffix, numBSP ## suffix, allocatedBSP ## suffix, def )
  
- #define AUTOEXPAND_BY_REALLOC_BSP(suffix, def) AUTOEXPAND_BY_REALLOC(bsp##suffix, numBSP##suffix, allocatedBSP##suffix, def)
+ #define Image_LinearFloatFromsRGBFloat( c ) ( ( ( c ) <= 0.04045f ) ? ( c ) * ( 1.0f / 12.92f ) : (float)pow( ( ( c ) + 0.055f ) * ( 1.0f / 1.055f ), 2.4f ) )
+ #define Image_sRGBFloatFromLinearFloat( c ) ( ( ( c ) < 0.0031308f ) ? ( c ) * 12.92f : 1.055f * (float)pow( ( c ), 1.0f / 2.4f ) - 0.055f )
  
  /* end marker */
  #endif
index bc479b9386c0b3dc13dbb410caa14be07fcb4371,2aeda857975d703cff070dd3c38b39b776c77f5e..7d990bb626ce549e3824fce1404fc7ba543caf48
  
  
  /*
- AllocDrawSurface()
- ydnar: gs mods: changed to force an explicit type when allocating
- */
   AllocDrawSurface()
   ydnar: gs mods: changed to force an explicit type when allocating
 */
  
- mapDrawSurface_t *AllocDrawSurface( surfaceType_t type )
- {
+ mapDrawSurface_t *AllocDrawSurface( surfaceType_t type ){
 -      mapDrawSurface_t    *ds;
 -
 -
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* ydnar: gs mods: only allocate valid types */
-       if( type <= SURFACE_BAD || type >= NUM_SURFACE_TYPES )
+       if ( type <= SURFACE_BAD || type >= NUM_SURFACE_TYPES ) {
                Error( "AllocDrawSurface: Invalid surface type %d specified", type );
 -
+       }
 +      
        /* bounds check */
-       if( numMapDrawSurfs >= MAX_MAP_DRAW_SURFS )
+       if ( numMapDrawSurfs >= MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS (%d) exceeded", MAX_MAP_DRAW_SURFS );
+       }
        ds = &mapDrawSurfs[ numMapDrawSurfs ];
        numMapDrawSurfs++;
 -
 +      
        /* ydnar: do initial surface setup */
        memset( ds, 0, sizeof( mapDrawSurface_t ) );
        ds->type = type;
  
  
  /*
- FinishSurface()
- ydnar: general surface finish pass
- */
   FinishSurface()
   ydnar: general surface finish pass
 */
  
- void FinishSurface( mapDrawSurface_t *ds )
- {
+ void FinishSurface( mapDrawSurface_t *ds ){
 -      mapDrawSurface_t    *ds2;
 -
 -
 +      mapDrawSurface_t        *ds2;
 +      
 +      
        /* dummy check */
-       if( ds->type <= SURFACE_BAD || ds->type >= NUM_SURFACE_TYPES || ds == NULL || ds->shaderInfo == NULL )
+       if ( ds->type <= SURFACE_BAD || ds->type >= NUM_SURFACE_TYPES || ds == NULL || ds->shaderInfo == NULL ) {
                return;
 -
+       }
 +      
        /* ydnar: rocking tek-fu celshading */
-       if( ds->celShader != NULL )
+       if ( ds->celShader != NULL ) {
                MakeCelSurface( ds, ds->celShader );
 -
+       }
 +      
        /* backsides stop here */
-       if( ds->backSide )
+       if ( ds->backSide ) {
                return;
 -
+       }
 +      
        /* ydnar: rocking surface cloning (fur baby yeah!) */
-       if( ds->shaderInfo->cloneShader != NULL && ds->shaderInfo->cloneShader[ 0 ] != '\0' )
+       if ( ds->shaderInfo->cloneShader != NULL && ds->shaderInfo->cloneShader[ 0 ] != '\0' ) {
                CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->cloneShader ) );
 -
+       }
 +      
        /* ydnar: q3map_backShader support */
-       if( ds->shaderInfo->backShader != NULL && ds->shaderInfo->backShader[ 0 ] != '\0' )
-       {
+       if ( ds->shaderInfo->backShader != NULL && ds->shaderInfo->backShader[ 0 ] != '\0' ) {
                ds2 = CloneSurface( ds, ShaderInfoForShader( ds->shaderInfo->backShader ) );
                ds2->backSide = qtrue;
        }
  
  
  /*
- CloneSurface()
- clones a map drawsurface, using the specified shader
- */
   CloneSurface()
   clones a map drawsurface, using the specified shader
 */
  
- mapDrawSurface_t *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si )
- {
+ mapDrawSurface_t *CloneSurface( mapDrawSurface_t *src, shaderInfo_t *si ){
 -      mapDrawSurface_t    *ds;
 -
 -
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* dummy check */
-       if( src == NULL || si == NULL )
+       if ( src == NULL || si == NULL ) {
                return NULL;
 -
+       }
 +      
        /* allocate a new surface */
        ds = AllocDrawSurface( src->type );
-       if( ds == NULL )
+       if ( ds == NULL ) {
                return NULL;
 -
+       }
 +      
        /* copy it */
        memcpy( ds, src, sizeof( *ds ) );
 -
 +      
        /* destroy side reference */
        ds->sideRef = NULL;
 -
 +      
        /* set shader */
        ds->shaderInfo = si;
 -
 +      
        /* copy verts */
-       if( ds->numVerts > 0 )
-       {
+       if ( ds->numVerts > 0 ) {
                ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
                memcpy( ds->verts, src->verts, ds->numVerts * sizeof( *ds->verts ) );
        }
 -
 +      
        /* copy indexes */
-       if( ds->numIndexes <= 0 )
+       if ( ds->numIndexes <= 0 ) {
                return ds;
+       }
        ds->indexes = safe_malloc( ds->numIndexes * sizeof( *ds->indexes ) );
        memcpy( ds->indexes, src->indexes, ds->numIndexes * sizeof( *ds->indexes ) );
 -
 +      
        /* return the surface */
        return ds;
  }
  
  
  /*
- MakeCelSurface() - ydnar
- makes a copy of a surface, but specific to cel shading
- */
   MakeCelSurface() - ydnar
   makes a copy of a surface, but specific to cel shading
 */
  
- mapDrawSurface_t *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si )
- {
+ mapDrawSurface_t *MakeCelSurface( mapDrawSurface_t *src, shaderInfo_t *si ){
 -      mapDrawSurface_t    *ds;
 -
 -
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* dummy check */
-       if( src == NULL || si == NULL )
+       if ( src == NULL || si == NULL ) {
                return NULL;
 -
+       }
 +      
        /* don't create cel surfaces for certain types of shaders */
-       if( (src->shaderInfo->compileFlags & C_TRANSLUCENT) ||
-               (src->shaderInfo->compileFlags & C_SKY) )
+       if ( ( src->shaderInfo->compileFlags & C_TRANSLUCENT ) ||
+                ( src->shaderInfo->compileFlags & C_SKY ) ) {
                return NULL;
 -
+       }
 +      
        /* make a copy */
        ds = CloneSurface( src, si );
-       if( ds == NULL )
+       if ( ds == NULL ) {
                return NULL;
 -
+       }
 +      
        /* do some fixups for celshading */
        ds->planar = qfalse;
        ds->planeNum = -1;
  
  
  /*
- MakeSkyboxSurface() - ydnar
- generates a skybox surface, viewable from everywhere there is sky
- */
   MakeSkyboxSurface() - ydnar
   generates a skybox surface, viewable from everywhere there is sky
 */
  
- mapDrawSurface_t *MakeSkyboxSurface( mapDrawSurface_t *src )
- {
+ mapDrawSurface_t *MakeSkyboxSurface( mapDrawSurface_t *src ){
 -      int i;
 -      mapDrawSurface_t    *ds;
 -
 -
 +      int                                     i;
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* dummy check */
-       if( src == NULL )
+       if ( src == NULL ) {
                return NULL;
 -
+       }
 +      
        /* make a copy */
        ds = CloneSurface( src, src->shaderInfo );
-       if( ds == NULL )
+       if ( ds == NULL ) {
                return NULL;
 -
+       }
 +      
        /* set parent */
        ds->parent = src;
 -
 +      
        /* scale the surface vertexes */
-       for( i = 0; i < ds->numVerts; i++ )
+       for ( i = 0; i < ds->numVerts; i++ )
        {
                m4x4_transform_point( skyboxTransform, ds->verts[ i ].xyz );
 -
 +              
                /* debug code */
                //%     bspDrawVerts[ bspDrawSurfaces[ ds->outputNum ].firstVert + i ].color[ 0 ][ 1 ] = 0;
                //%     bspDrawVerts[ bspDrawSurfaces[ ds->outputNum ].firstVert + i ].color[ 0 ][ 2 ] = 0;
  
  
  /*
- IsTriangleDegenerate
- returns qtrue if all three points are colinear, backwards, or the triangle is just plain bogus
- */
   IsTriangleDegenerate
   returns qtrue if all three points are colinear, backwards, or the triangle is just plain bogus
 */
  
 -#define TINY_AREA   1.0f
 +#define       TINY_AREA       1.0f
  
- qboolean IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c )
- {
+ qboolean IsTriangleDegenerate( bspDrawVert_t *points, int a, int b, int c ){
 -      vec3_t v1, v2, v3;
 -      float d;
 -
 -
 +      vec3_t          v1, v2, v3;
 +      float           d;
 +      
 +      
        /* calcuate the area of the triangle */
        VectorSubtract( points[ b ].xyz, points[ a ].xyz, v1 );
        VectorSubtract( points[ c ].xyz, points[ a ].xyz, v2 );
        CrossProduct( v1, v2, v3 );
        d = VectorLength( v3 );
 -
 +      
        /* assume all very small or backwards triangles will cause problems */
-       if( d < TINY_AREA )
+       if ( d < TINY_AREA ) {
                return qtrue;
 -
+       }
 +      
        /* must be a good triangle */
        return qfalse;
  }
@@@ -284,50 -292,51 +292,51 @@@ void ClearSurface( mapDrawSurface_t *d
  
  
  /*
- TidyEntitySurfaces() - ydnar
- deletes all empty or bad surfaces from the surface list
- */
   TidyEntitySurfaces() - ydnar
   deletes all empty or bad surfaces from the surface list
 */
  
- void TidyEntitySurfaces( entity_t *e )
- {
+ void TidyEntitySurfaces( entity_t *e ){
 -      int i, j, deleted;
 -      mapDrawSurface_t    *out, *in = NULL;
 -
 -
 +      int                                     i, j, deleted;
 +      mapDrawSurface_t        *out, *in = NULL;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- TidyEntitySurfaces ---\n" );
 -
 +      
        /* walk the surface list */
        deleted = 0;
-       for( i = e->firstDrawSurf, j = e->firstDrawSurf; j < numMapDrawSurfs; i++, j++ )
+       for ( i = e->firstDrawSurf, j = e->firstDrawSurf; j < numMapDrawSurfs; i++, j++ )
        {
                /* get out surface */
                out = &mapDrawSurfs[ i ];
 -
 +              
                /* walk the surface list again until a proper surface is found */
-               for( ; j < numMapDrawSurfs; j++ )
+               for ( ; j < numMapDrawSurfs; j++ )
                {
                        /* get in surface */
                        in = &mapDrawSurfs[ j ];
 -
 +                      
                        /* this surface ok? */
-                       if( in->type == SURFACE_FLARE || in->type == SURFACE_SHADER ||
-                               (in->type != SURFACE_BAD && in->numVerts > 0) )
+                       if ( in->type == SURFACE_FLARE || in->type == SURFACE_SHADER ||
+                                ( in->type != SURFACE_BAD && in->numVerts > 0 ) ) {
                                break;
 -
+                       }
 +                      
                        /* nuke it */
                        ClearSurface( in );
                        deleted++;
                }
 -
 +              
                /* copy if necessary */
-               if( i != j )
+               if ( i != j ) {
                        memcpy( out, in, sizeof( mapDrawSurface_t ) );
 -              }
        }
 -
++      }
 +      
        /* set the new number of drawsurfs */
        numMapDrawSurfs = i;
 -
 +      
        /* emit some stats */
        Sys_FPrintf( SYS_VRB, "%9d empty or malformed surfaces deleted\n", deleted );
  }
  
  
  /*
- CalcSurfaceTextureRange() - ydnar
- calculates the clamped texture range for a given surface, returns qtrue if it's within [-texRange,texRange]
- */
   CalcSurfaceTextureRange() - ydnar
   calculates the clamped texture range for a given surface, returns qtrue if it's within [-texRange,texRange]
 */
  
- qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds )
- {
+ qboolean CalcSurfaceTextureRange( mapDrawSurface_t *ds ){
 -      int i, j, v, size[ 2 ];
 -      float mins[ 2 ], maxs[ 2 ];
 -
 -
 +      int             i, j, v, size[ 2 ];
 +      float   mins[ 2 ], maxs[ 2 ];
 +      
 +      
        /* try to early out */
-       if( ds->numVerts <= 0 )
+       if ( ds->numVerts <= 0 ) {
                return qtrue;
 -
+       }
 +      
        /* walk the verts and determine min/max st values */
        mins[ 0 ] = 999999;
        mins[ 1 ] = 999999;
        maxs[ 0 ] = -999999;
        maxs[ 1 ] = -999999;
-       for( i = 0; i < ds->numVerts; i++ )
+       for ( i = 0; i < ds->numVerts; i++ )
        {
-               for( j = 0; j < 2; j++ )
+               for ( j = 0; j < 2; j++ )
                {
-                       if( ds->verts[ i ].st[ j ] < mins[ j ] )
+                       if ( ds->verts[ i ].st[ j ] < mins[ j ] ) {
                                mins[ j ] = ds->verts[ i ].st[ j ];
-                       if( ds->verts[ i ].st[ j ] > maxs[ j ] )
+                       }
+                       if ( ds->verts[ i ].st[ j ] > maxs[ j ] ) {
                                maxs[ j ] = ds->verts[ i ].st[ j ];
 -                      }
                }
        }
 -
++      }
 +      
        /* clamp to integer range and calculate surface bias values */
-       for( j = 0; j < 2; j++ )
-               ds->bias[ j ] = -floor( 0.5f * (mins[ j ] + maxs[ j ]) );
+       for ( j = 0; j < 2; j++ )
+               ds->bias[ j ] = -floor( 0.5f * ( mins[ j ] + maxs[ j ] ) );
 -
 +      
        /* find biased texture coordinate mins/maxs */
        size[ 0 ] = ds->shaderInfo->shaderWidth;
        size[ 1 ] = ds->shaderInfo->shaderHeight;
        ds->texMins[ 1 ] = 999999;
        ds->texMaxs[ 0 ] = -999999;
        ds->texMaxs[ 1 ] = -999999;
-       for( i = 0; i < ds->numVerts; i++ )
+       for ( i = 0; i < ds->numVerts; i++ )
        {
-               for( j = 0; j < 2; j++ )
+               for ( j = 0; j < 2; j++ )
                {
-                       v = ((float) ds->verts[ i ].st[ j ] + ds->bias[ j ]) * size[ j ];
-                       if( v < ds->texMins[ j ] )
+                       v = ( (float) ds->verts[ i ].st[ j ] + ds->bias[ j ] ) * size[ j ];
+                       if ( v < ds->texMins[ j ] ) {
                                ds->texMins[ j ] = v;
-                       if( v > ds->texMaxs[ j ] )
+                       }
+                       if ( v > ds->texMaxs[ j ] ) {
                                ds->texMaxs[ j ] = v;
 -                      }
                }
        }
 -
++      }
 +      
        /* calc ranges */
-       for( j = 0; j < 2; j++ )
-               ds->texRange[ j ] = (ds->texMaxs[ j ] - ds->texMins[ j ]);
+       for ( j = 0; j < 2; j++ )
+               ds->texRange[ j ] = ( ds->texMaxs[ j ] - ds->texMins[ j ] );
 -
 +      
        /* if range is zero, then assume unlimited precision */
-       if( texRange == 0 )
+       if ( texRange == 0 ) {
                return qtrue;
 -
+       }
 +      
        /* within range? */
-       for( j = 0; j < 2; j++ )
+       for ( j = 0; j < 2; j++ )
        {
-               if( ds->texMins[ j ] < -texRange || ds->texMaxs[ j ] > texRange )
+               if ( ds->texMins[ j ] < -texRange || ds->texMaxs[ j ] > texRange ) {
                        return qfalse;
 -              }
        }
 -
++      }
 +      
        /* within range */
        return qtrue;
  }
  
  
  /*
- CalcLightmapAxis() - ydnar
- gives closed lightmap axis for a plane normal
- */
   CalcLightmapAxis() - ydnar
   gives closed lightmap axis for a plane normal
 */
  
- qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis )
- {
+ qboolean CalcLightmapAxis( vec3_t normal, vec3_t axis ){
 -      vec3_t absolute;
 -
 -
 +      vec3_t  absolute;
 +              
 +      
        /* test */
-       if( normal[ 0 ] == 0.0f && normal[ 1 ] == 0.0f && normal[ 2 ] == 0.0f )
-       {
+       if ( normal[ 0 ] == 0.0f && normal[ 1 ] == 0.0f && normal[ 2 ] == 0.0f ) {
                VectorClear( axis );
                return qfalse;
        }
        absolute[ 0 ] = fabs( normal[ 0 ] );
        absolute[ 1 ] = fabs( normal[ 1 ] );
        absolute[ 2 ] = fabs( normal[ 2 ] );
 -
 +      
        /* test and set */
-       if( absolute[ 2 ] > absolute[ 0 ] - 0.0001f && absolute[ 2 ] > absolute[ 1 ] - 0.0001f )
-       {
-               if( normal[ 2 ] > 0.0f )
+       if ( absolute[ 2 ] > absolute[ 0 ] - 0.0001f && absolute[ 2 ] > absolute[ 1 ] - 0.0001f ) {
+               if ( normal[ 2 ] > 0.0f ) {
                        VectorSet( axis, 0.0f, 0.0f, 1.0f );
-               else
+               }
+               else{
                        VectorSet( axis, 0.0f, 0.0f, -1.0f );
 -              }
 +      }
-       else if( absolute[ 0 ] > absolute[ 1 ] - 0.0001f && absolute[ 0 ] > absolute[ 2 ] - 0.0001f )
-       {
-               if( normal[ 0 ] > 0.0f )
+       }
+       else if ( absolute[ 0 ] > absolute[ 1 ] - 0.0001f && absolute[ 0 ] > absolute[ 2 ] - 0.0001f ) {
+               if ( normal[ 0 ] > 0.0f ) {
                        VectorSet( axis, 1.0f, 0.0f, 0.0f );
-               else
+               }
+               else{
                        VectorSet( axis, -1.0f, 0.0f, 0.0f );
 -              }
 +      }
+       }
        else
        {
-               if( normal[ 1 ] > 0.0f )
+               if ( normal[ 1 ] > 0.0f ) {
                        VectorSet( axis, 0.0f, 1.0f, 0.0f );
-               else
+               }
+               else{
                        VectorSet( axis, 0.0f, -1.0f, 0.0f );
 -              }
        }
 -
++      }
 +      
        /* return ok */
        return qtrue;
  }
  
  
  /*
- ClassifySurfaces() - ydnar
- fills out a bunch of info in the surfaces, including planar status, lightmap projection, and bounding box
- */
   ClassifySurfaces() - ydnar
   fills out a bunch of info in the surfaces, including planar status, lightmap projection, and bounding box
 */
  
 -#define PLANAR_EPSILON  0.5f    //% 0.126f 0.25f
 +#define PLANAR_EPSILON        0.5f    //% 0.126f 0.25f
  
- void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds )
- {
+ void ClassifySurfaces( int numSurfs, mapDrawSurface_t *ds ){
 -      int i, bestAxis;
 -      float dist;
 -      vec4_t plane;
 -      shaderInfo_t        *si;
 -      static vec3_t axii[ 6 ] =
 -      {
 -              { 0, 0, -1 },
 -              { 0, 0, 1 },
 -              { -1, 0, 0 },
 -              { 1, 0, 0 },
 -              { 0, -1, 0 },
 -              { 0, 1, 0 }
 -      };
 -
 -
 +      int                                     i, bestAxis;
 +      float                           dist;
 +      vec4_t                          plane;
 +      shaderInfo_t            *si;
 +      static vec3_t           axii[ 6 ] =
 +                                              {
 +                                                      { 0, 0, -1 },
 +                                                      { 0, 0, 1 },
 +                                                      { -1, 0, 0 },
 +                                                      { 1, 0, 0 },
 +                                                      { 0, -1, 0 },
 +                                                      { 0, 1, 0 }
 +                                              };
 +      
 +      
        /* walk the list of surfaces */
-       for( ; numSurfs > 0; numSurfs--, ds++ )
+       for ( ; numSurfs > 0; numSurfs--, ds++ )
        {
                /* ignore bogus (or flare) surfaces */
-               if( ds->type == SURFACE_BAD || ds->numVerts <= 0 )
+               if ( ds->type == SURFACE_BAD || ds->numVerts <= 0 ) {
                        continue;
 -
+               }
 +              
                /* get shader */
                si = ds->shaderInfo;
 -
 +              
                /* -----------------------------------------------------------------
                   force meta if vertex count is too high or shader requires it
                   ----------------------------------------------------------------- */
 -
 +              
-               if( ds->type != SURFACE_PATCH && ds->type != SURFACE_FACE )
-               {
-                       if( ds->numVerts > SHADER_MAX_VERTEXES )
+               if ( ds->type != SURFACE_PATCH && ds->type != SURFACE_FACE ) {
+                       if ( ds->numVerts > SHADER_MAX_VERTEXES ) {
                                ds->type = SURFACE_FORCED_META;
 -                      }
                }
 -
++              }
 +              
                /* -----------------------------------------------------------------
 -                 plane and bounding box classification
 +                 plane and bounding box classification 
                   ----------------------------------------------------------------- */
 -
 +              
                /* set surface bounding box */
                ClearBounds( ds->mins, ds->maxs );
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                        AddPointToBounds( ds->verts[ i ].xyz, ds->mins, ds->maxs );
 -
 +              
                /* try to get an existing plane */
-               if( ds->planeNum >= 0 )
-               {
+               if ( ds->planeNum >= 0 ) {
                        VectorCopy( mapplanes[ ds->planeNum ].normal, plane );
                        plane[ 3 ] = mapplanes[ ds->planeNum ].dist;
                }
                {
                        VectorClear( plane );
                        plane[ 3 ] = 0.0f;
-                       for( i = 0; i < ds->numVerts; i++ )
-                       {
-                               if( ds->verts[ i ].normal[ 0 ] != 0.0f && ds->verts[ i ].normal[ 1 ] != 0.0f && ds->verts[ i ].normal[ 2 ] != 0.0f )
+                       for ( i = 0; i < ds->numVerts; i++ )
 -                      {
 +                              {
+                               if ( ds->verts[ i ].normal[ 0 ] != 0.0f && ds->verts[ i ].normal[ 1 ] != 0.0f && ds->verts[ i ].normal[ 2 ] != 0.0f ) {
                                        VectorCopy( ds->verts[ i ].normal, plane );
                                        plane[ 3 ] = DotProduct( ds->verts[ i ].xyz, plane );
                                        break;
                                }
                        }
                }
 -
 +              
                /* test for bogus plane */
-               if( VectorLength( plane ) <= 0.0f )
-               {
+               if ( VectorLength( plane ) <= 0.0f ) {
                        ds->planar = qfalse;
                        ds->planeNum = -1;
                }
                {
                        /* determine if surface is planar */
                        ds->planar = qtrue;
 -
 +                      
                        /* test each vert */
-                       for( i = 0; i < ds->numVerts; i++ )
+                       for ( i = 0; i < ds->numVerts; i++ )
                        {
                                /* point-plane test */
                                dist = DotProduct( ds->verts[ i ].xyz, plane ) - plane[ 3 ];
                                }
                        }
                }
 -
 +              
                /* find map plane if necessary */
-               if( ds->planar )
-               {
-                       if( ds->planeNum < 0 )
+               if ( ds->planar ) {
+                       if ( ds->planeNum < 0 ) {
                                ds->planeNum = FindFloatPlane( plane, plane[ 3 ], 1, &ds->verts[ 0 ].xyz );
+                       }
                        VectorCopy( plane, ds->lightmapVecs[ 2 ] );
                }
                else
                /* -----------------------------------------------------------------
                   lightmap bounds and axis projection
                   ----------------------------------------------------------------- */
 -
 +              
                /* vertex lit surfaces don't need this information */
-               if( si->compileFlags & C_VERTEXLIT || ds->type == SURFACE_TRIANGLES )
-               {
+               if ( si->compileFlags & C_VERTEXLIT || ds->type == SURFACE_TRIANGLES ) {
                        VectorClear( ds->lightmapAxis );
                        //%     VectorClear( ds->lightmapVecs[ 2 ] );
                        ds->sampleSize = 0;
                        continue;
                }
 -
 +              
                /* the shader can specify an explicit lightmap axis */
-               if( si->lightmapAxis[ 0 ] || si->lightmapAxis[ 1 ] || si->lightmapAxis[ 2 ] )
+               if ( si->lightmapAxis[ 0 ] || si->lightmapAxis[ 1 ] || si->lightmapAxis[ 2 ] ) {
                        VectorCopy( si->lightmapAxis, ds->lightmapAxis );
-               else if( ds->type == SURFACE_FORCED_META )
+               }
+               else if ( ds->type == SURFACE_FORCED_META ) {
                        VectorClear( ds->lightmapAxis );
-               else if( ds->planar )
+               }
+               else if ( ds->planar ) {
                        CalcLightmapAxis( plane, ds->lightmapAxis );
+               }
                else
                {
                        /* find best lightmap axis */
-                       for( bestAxis = 0; bestAxis < 6; bestAxis++ )
+                       for ( bestAxis = 0; bestAxis < 6; bestAxis++ )
                        {
-                               for( i = 0; i < ds->numVerts && bestAxis < 6; i++ )
+                               for ( i = 0; i < ds->numVerts && bestAxis < 6; i++ )
                                {
                                        //% Sys_Printf( "Comparing %1.3f %1.3f %1.3f to %1.3f %1.3f %1.3f\n",
 -                                      //%     ds->verts[ i ].normal[ 0 ], ds->verts[ i ].normal[ 1 ], ds->verts[ i ].normal[ 2 ],
 -                                      //%     axii[ bestAxis ][ 0 ], axii[ bestAxis ][ 1 ], axii[ bestAxis ][ 2 ] );
 +                                      //%     ds->verts[ i ].normal[ 0 ], ds->verts[ i ].normal[ 1 ], ds->verts[ i ].normal[ 2 ],
 +                                      //%     axii[ bestAxis ][ 0 ], axii[ bestAxis ][ 1 ], axii[ bestAxis ][ 2 ] );
-                                       if( DotProduct( ds->verts[ i ].normal, axii[ bestAxis ] ) < 0.25f )     /* fixme: adjust this tolerance to taste */
+                                       if ( DotProduct( ds->verts[ i ].normal, axii[ bestAxis ] ) < 0.25f ) { /* fixme: adjust this tolerance to taste */
                                                break;
 -                                      }
                                }
 -
++                              }
 +                              
-                               if( i == ds->numVerts )
+                               if ( i == ds->numVerts ) {
                                        break;
 -                              }
                        }
 -
++                      }
 +                      
                        /* set axis if possible */
-                       if( bestAxis < 6 )
-                       {
+                       if ( bestAxis < 6 ) {
                                //% if( ds->type == SURFACE_PATCH )
 -                              //%     Sys_Printf( "Mapped axis %d onto patch\n", bestAxis );
 +                              //%     Sys_Printf( "Mapped axis %d onto patch\n", bestAxis );
                                VectorCopy( axii[ bestAxis ], ds->lightmapAxis );
                        }
 -
 +                      
                        /* debug code */
                        //% if( ds->type == SURFACE_PATCH )
 -                      //%     Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis );
 +                      //%     Sys_Printf( "Failed to map axis %d onto patch\n", bestAxis );
                }
 -
 +              
                /* calculate lightmap sample size */
-               if( ds->shaderInfo->lightmapSampleSize > 0 ) /* shader value overrides every other */
+               if ( ds->shaderInfo->lightmapSampleSize > 0 ) { /* shader value overrides every other */
                        ds->sampleSize = ds->shaderInfo->lightmapSampleSize;
-               else if( ds->sampleSize <= 0 ) /* may contain the entity asigned value */
+               }
+               else if ( ds->sampleSize <= 0 ) { /* may contain the entity asigned value */
                        ds->sampleSize = sampleSize; /* otherwise use global default */
  
-               if( ds->lightmapScale > 0.0f ) /* apply surface lightmap scaling factor */
-               {
+               }
+               if ( ds->lightmapScale > 0.0f ) { /* apply surface lightmap scaling factor */
                        ds->sampleSize = ds->lightmapScale * (float)ds->sampleSize;
                        ds->lightmapScale = 0; /* applied */
                }
  
-               if( ds->sampleSize < minSampleSize )
+               if ( ds->sampleSize < minSampleSize ) {
                        ds->sampleSize = minSampleSize;
+               }
  
-               if( ds->sampleSize < 1 )
+               if ( ds->sampleSize < 1 ) {
                        ds->sampleSize = 1;
+               }
  
-               if( ds->sampleSize > 16384 ) /* powers of 2 are preferred */
+               if ( ds->sampleSize > 16384 ) { /* powers of 2 are preferred */
                        ds->sampleSize = 16384;
 -              }
 +      }
+       }
  }
  
  
  
  /*
- ClassifyEntitySurfaces() - ydnar
- classifies all surfaces in an entity
- */
   ClassifyEntitySurfaces() - ydnar
   classifies all surfaces in an entity
 */
  
- void ClassifyEntitySurfaces( entity_t *e )
- {
+ void ClassifyEntitySurfaces( entity_t *e ){
 -      int i;
 -
 -
 +      int             i;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- ClassifyEntitySurfaces ---\n" );
 -
 +      
        /* walk the surface list */
-       for( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
+       for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
        {
                FinishSurface( &mapDrawSurfs[ i ] );
                ClassifySurfaces( 1, &mapDrawSurfs[ i ] );
  
  
  /*
- GetShaderIndexForPoint() - ydnar
- for shader-indexed surfaces (terrain), find a matching index from the indexmap
- */
   GetShaderIndexForPoint() - ydnar
   for shader-indexed surfaces (terrain), find a matching index from the indexmap
 */
  
- byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t point )
- {
+ byte GetShaderIndexForPoint( indexMap_t *im, vec3_t eMins, vec3_t eMaxs, vec3_t point ){
 -      int i, x, y;
 -      float s, t;
 -      vec3_t mins, maxs, size;
 -
 -
 +      int                     i, x, y;
 +      float           s, t;
 +      vec3_t          mins, maxs, size;
 +      
 +      
        /* early out if no indexmap */
-       if( im == NULL )
+       if ( im == NULL ) {
                return 0;
 -
+       }
 +      
        /* this code is really broken */
        #if 0
 -      /* legacy precision fudges for terrain */
 +              /* legacy precision fudges for terrain */
-               for( i = 0; i < 3; i++ )
+       for ( i = 0; i < 3; i++ )
 -      {
 -              mins[ i ] = floor( eMins[ i ] + 0.1 );
 -              maxs[ i ] = floor( eMaxs[ i ] + 0.1 );
 -              size[ i ] = maxs[ i ] - mins[ i ];
 -      }
 -
 -      /* find st (fixme: support more than just z-axis projection) */
 -      s = floor( point[ 0 ] + 0.1f - mins[ 0 ] ) / size[ 0 ];
 -      t = floor( maxs[ 1 ] - point[ 1 ] + 0.1f ) / size[ 1 ];
 +              {
 +                      mins[ i ] = floor( eMins[ i ] + 0.1 );
 +                      maxs[ i ] = floor( eMaxs[ i ] + 0.1 );
 +                      size[ i ] = maxs[ i ] - mins[ i ];
 +              }
 +              
 +              /* find st (fixme: support more than just z-axis projection) */
 +              s = floor( point[ 0 ] + 0.1f - mins[ 0 ] ) / size[ 0 ];
 +              t = floor( maxs[ 1 ] - point[ 1 ] + 0.1f ) / size[ 1 ];
-               if( s < 0.0f )
+       if ( s < 0.0f ) {
 -              s = 0.0f;
 +                      s = 0.0f;
-               else if( s > 1.0f )
+       }
+       else if ( s > 1.0f ) {
 -              s = 1.0f;
 +                      s = 1.0f;
-               if( t < 0.0f )
+       }
+       if ( t < 0.0f ) {
 -              t = 0.0f;
 +                      t = 0.0f;
-               else if( t > 1.0f )
+       }
+       else if ( t > 1.0f ) {
 -              t = 1.0f;
 +                      t = 1.0f;
+       }
 -
 -      /* make xy */
 +              
 +              /* make xy */
-               x = (im->w - 1) * s;
-               y = (im->h - 1) * t;
+       x = ( im->w - 1 ) * s;
+       y = ( im->h - 1 ) * t;
        #else
 -      /* get size */
 +              /* get size */
-               for( i = 0; i < 3; i++ )
+       for ( i = 0; i < 3; i++ )
 -      {
 -              mins[ i ] = eMins[ i ];
 -              maxs[ i ] = eMaxs[ i ];
 -              size[ i ] = maxs[ i ] - mins[ i ];
 -      }
 -
 -      /* calc st */
 +              {
 +                      mins[ i ] = eMins[ i ];
 +                      maxs[ i ] = eMaxs[ i ];
 +                      size[ i ] = maxs[ i ] - mins[ i ];
 +              }
 +              
 +              /* calc st */
-               s = (point[ 0 ] - mins[ 0 ]) / size[ 0 ];
-               t = (maxs[ 1 ] - point[ 1 ]) / size[ 1 ];
+       s = ( point[ 0 ] - mins[ 0 ] ) / size[ 0 ];
+       t = ( maxs[ 1 ] - point[ 1 ] ) / size[ 1 ];
 -
 -      /* calc xy */
 -      x = s * im->w;
 -      y = t * im->h;
 +              
 +              /* calc xy */
 +              x = s * im->w;
 +              y = t * im->h;
-               if( x < 0 )
+       if ( x < 0 ) {
 -              x = 0;
 +                      x = 0;
-               else if( x > (im->w - 1) )
-                       x = (im->w - 1);
-               if( y < 0 )
+       }
+       else if ( x > ( im->w - 1 ) ) {
+               x = ( im->w - 1 );
+       }
+       if ( y < 0 ) {
 -              y = 0;
 +                      y = 0;
-               else if( y > (im->h - 1) )
-                       y = (im->h - 1);
+       }
+       else if ( y > ( im->h - 1 ) ) {
+               y = ( im->h - 1 );
+       }
        #endif
 -
 +      
        /* return index */
        return im->pixels[ y * im->w + x ];
  }
  
  
  /*
- GetIndexedShader() - ydnar
- for a given set of indexes and an indexmap, get a shader and set the vertex alpha in-place
- this combines a couple different functions from terrain.c
- */
   GetIndexedShader() - ydnar
   for a given set of indexes and an indexmap, get a shader and set the vertex alpha in-place
   this combines a couple different functions from terrain.c
 */
  
- shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoints, byte *shaderIndexes )
- {
+ shaderInfo_t *GetIndexedShader( shaderInfo_t *parent, indexMap_t *im, int numPoints, byte *shaderIndexes ){
 -      int i;
 -      byte minShaderIndex, maxShaderIndex;
 -      char shader[ MAX_QPATH ];
 -      shaderInfo_t    *si;
 -
 -
 +      int                             i;
 +      byte                    minShaderIndex, maxShaderIndex;
 +      char                    shader[ MAX_QPATH ];
 +      shaderInfo_t    *si;
 +      
 +      
        /* early out if bad data */
-       if( im == NULL || numPoints <= 0 || shaderIndexes == NULL )
+       if ( im == NULL || numPoints <= 0 || shaderIndexes == NULL ) {
                return ShaderInfoForShader( "default" );
 -
+       }
 +      
        /* determine min/max index */
        minShaderIndex = 255;
        maxShaderIndex = 0;
-       for( i = 0; i < numPoints; i++ )
+       for ( i = 0; i < numPoints; i++ )
        {
-               if( shaderIndexes[ i ] < minShaderIndex )
+               if ( shaderIndexes[ i ] < minShaderIndex ) {
                        minShaderIndex = shaderIndexes[ i ];
-               if( shaderIndexes[ i ] > maxShaderIndex )
+               }
+               if ( shaderIndexes[ i ] > maxShaderIndex ) {
                        maxShaderIndex = shaderIndexes[ i ];
 -              }
        }
 -
++      }
 +      
        /* set alpha inline */
-       for( i = 0; i < numPoints; i++ )
+       for ( i = 0; i < numPoints; i++ )
        {
                /* straight rip from terrain.c */
-               if( shaderIndexes[ i ] < maxShaderIndex )
+               if ( shaderIndexes[ i ] < maxShaderIndex ) {
                        shaderIndexes[ i ] = 0;
-               else
+               }
+               else{
                        shaderIndexes[ i ] = 255;
 -              }
        }
 -
++      }
 +      
        /* make a shader name */
-       if( minShaderIndex == maxShaderIndex )
+       if ( minShaderIndex == maxShaderIndex ) {
                sprintf( shader, "textures/%s_%d", im->shader, maxShaderIndex );
-       else
+       }
+       else{
                sprintf( shader, "textures/%s_%dto%d", im->shader, minShaderIndex, maxShaderIndex );
 -
+       }
 +      
        /* get the shader */
        si = ShaderInfoForShader( shader );
 -
 +      
        /* inherit a few things from parent shader */
-       if( parent->globalTexture )
+       if ( parent->globalTexture ) {
                si->globalTexture = qtrue;
-       if( parent->forceMeta )
+       }
+       if ( parent->forceMeta ) {
                si->forceMeta = qtrue;
-       if( parent->nonplanar )
+       }
+       if ( parent->nonplanar ) {
                si->nonplanar = qtrue;
-       if( si->shadeAngleDegrees == 0.0 )
+       }
+       if ( si->shadeAngleDegrees == 0.0 ) {
                si->shadeAngleDegrees = parent->shadeAngleDegrees;
-       if( parent->tcGen && si->tcGen == qfalse )
-       {
+       }
+       if ( parent->tcGen && si->tcGen == qfalse ) {
                /* set xy texture projection */
                si->tcGen = qtrue;
                VectorCopy( parent->vecs[ 0 ], si->vecs[ 0 ] );
  
  
  /*
- DrawSurfaceForSide()
- creates a SURF_FACE drawsurface from a given brush side and winding
- */
   DrawSurfaceForSide()
   creates a SURF_FACE drawsurface from a given brush side and winding
 */
  
 -#define SNAP_FLOAT_TO_INT   8
 +#define       SNAP_FLOAT_TO_INT       8
- #define       SNAP_INT_TO_FLOAT       (1.0 / SNAP_FLOAT_TO_INT)
+ #define SNAP_INT_TO_FLOAT   ( 1.0 / SNAP_FLOAT_TO_INT )
  
- mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w )
- {
+ mapDrawSurface_t *DrawSurfaceForSide( entity_t *e, brush_t *b, side_t *s, winding_t *w ){
 -      int i, j, k;
 -      mapDrawSurface_t    *ds;
 -      shaderInfo_t        *si, *parent;
 -      bspDrawVert_t       *dv;
 -      vec3_t texX, texY;
 -      vec_t x, y;
 -      vec3_t vTranslated;
 -      qboolean indexed;
 -      byte shaderIndexes[ 256 ];
 -      float offsets[ 256 ];
 -      char tempShader[ MAX_QPATH ];
 -
 -
 +      int                                     i, j, k;
 +      mapDrawSurface_t        *ds;
 +      shaderInfo_t            *si, *parent;
 +      bspDrawVert_t           *dv;
 +      vec3_t                          texX, texY;
 +      vec_t                           x, y;
 +      vec3_t                          vTranslated;
 +      qboolean                        indexed;
 +      byte                            shaderIndexes[ 256 ];
 +      float                           offsets[ 256 ];
 +      char                            tempShader[ MAX_QPATH ];
 +
 +      
        /* ydnar: don't make a drawsurf for culled sides */
-       if( s->culled )
+       if ( s->culled ) {
                return NULL;
 -
+       }
 +      
        /* range check */
-       if( w->numpoints > MAX_POINTS_ON_WINDING )
+       if ( w->numpoints > MAX_POINTS_ON_WINDING ) {
                Error( "DrawSurfaceForSide: w->numpoints = %d (> %d)", w->numpoints, MAX_POINTS_ON_WINDING );
 -
+       }
 +      
        /* get shader */
        si = s->shaderInfo;
 -
 +      
        /* ydnar: gs mods: check for indexed shader */
-       if( si->indexed && b->im != NULL )
-       {
+       if ( si->indexed && b->im != NULL ) {
                /* indexed */
                indexed = qtrue;
 -
 +              
                /* get shader indexes for each point */
-               for( i = 0; i < w->numpoints; i++ )
+               for ( i = 0; i < w->numpoints; i++ )
                {
                        shaderIndexes[ i ] = GetShaderIndexForPoint( b->im, b->eMins, b->eMaxs, w->p[ i ] );
                        offsets[ i ] = b->im->offsets[ shaderIndexes[ i ] ];
                parent = si;
                si = GetIndexedShader( parent, b->im, w->numpoints, shaderIndexes );
        }
-       else
+       else{
                indexed = qfalse;
 -
+       }
 +      
        /* ydnar: sky hack/fix for GL_CLAMP borders on ati cards */
-       if( skyFixHack && si->skyParmsImageBase[ 0 ] != '\0' )
-       {
+       if ( skyFixHack && si->skyParmsImageBase[ 0 ] != '\0' ) {
                //%     Sys_FPrintf( SYS_VRB, "Enabling sky hack for shader %s using env %s\n", si->shader, si->skyParmsImageBase );
                sprintf( tempShader, "%s_lf", si->skyParmsImageBase );
                DrawSurfaceForShader( tempShader );
        ds->numVerts = w->numpoints;
        ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
        memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
 -
 +      
        /* compute s/t coordinates from brush primitive texture matrix (compute axis base) */
        ComputeAxisBase( mapplanes[ s->planenum ].normal, texX, texY );
 -
 +      
        /* create the vertexes */
-       for( j = 0; j < w->numpoints; j++ )
+       for ( j = 0; j < w->numpoints; j++ )
        {
                /* get the drawvert */
                dv = ds->verts + j;
 -
 +              
                /* copy xyz and do potential z offset */
                VectorCopy( w->p[ j ], dv->xyz );
-               if( indexed )
+               if ( indexed ) {
                        dv->xyz[ 2 ] += offsets[ j ];
 -
+               }
 +              
                /* round the xyz to a given precision and translate by origin */
-               for( i = 0 ; i < 3 ; i++ )
+               for ( i = 0 ; i < 3 ; i++ )
                        dv->xyz[ i ] = SNAP_INT_TO_FLOAT * floor( dv->xyz[ i ] * SNAP_FLOAT_TO_INT + 0.5f );
                VectorAdd( dv->xyz, e->origin, vTranslated );
 -
 +              
                /* ydnar: tek-fu celshading support for flat shaded shit */
-               if( flat )
-               {
+               if ( flat ) {
                        dv->st[ 0 ] = si->stFlat[ 0 ];
                        dv->st[ 1 ] = si->stFlat[ 1 ];
                }
 -
 +              
                /* ydnar: gs mods: added support for explicit shader texcoord generation */
-               else if( si->tcGen )
-               {
+               else if ( si->tcGen ) {
                        dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], vTranslated );
                        dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], vTranslated );
                }
 -
 +              
                /* old quake-style texturing */
-               else if( g_bBrushPrimit == BPRIMIT_OLDBRUSHES )
-               {
+               else if ( g_bBrushPrimit == BPRIMIT_OLDBRUSHES ) {
                        /* nearest-axial projection */
                        dv->st[ 0 ] = s->vecs[ 0 ][ 3 ] + DotProduct( s->vecs[ 0 ], vTranslated );
                        dv->st[ 1 ] = s->vecs[ 1 ][ 3 ] + DotProduct( s->vecs[ 1 ], vTranslated );
                        dv->st[ 0 ] = s->texMat[ 0 ][ 0 ] * x + s->texMat[ 0 ][ 1 ] * y + s->texMat[ 0 ][ 2 ];
                        dv->st[ 1 ] = s->texMat[ 1 ][ 0 ] * x + s->texMat[ 1 ][ 1 ] * y + s->texMat[ 1 ][ 2 ];
                }
 -
 +              
                /* copy normal */
                VectorCopy( mapplanes[ s->planenum ].normal, dv->normal );
 -
 +              
                /* ydnar: set color */
-               for( k = 0; k < MAX_LIGHTMAPS; k++ )
+               for ( k = 0; k < MAX_LIGHTMAPS; k++ )
                {
                        dv->color[ k ][ 0 ] = 255;
                        dv->color[ k ][ 1 ] = 255;
                        dv->color[ k ][ 2 ] = 255;
 -
 +                      
                        /* ydnar: gs mods: handle indexed shader blending */
-                       dv->color[ k ][ 3 ] = (indexed ? shaderIndexes[ j ] : 255);
+                       dv->color[ k ][ 3 ] = ( indexed ? shaderIndexes[ j ] : 255 );
                }
        }
 -
 +      
        /* set cel shader */
        ds->celShader = b->celShader;
  
        /* set shade angle */
-       if( b->shadeAngleDegrees > 0.0f )
+       if ( b->shadeAngleDegrees > 0.0f ) {
                ds->shadeAngleDegrees = b->shadeAngleDegrees;
 -
+       }
 +      
        /* ydnar: gs mods: moved st biasing elsewhere */
        return ds;
  }
  
  #define YDNAR_NORMAL_EPSILON 0.50f
  
- qboolean VectorCompareExt( vec3_t n1, vec3_t n2, float epsilon )
- {
+ qboolean VectorCompareExt( vec3_t n1, vec3_t n2, float epsilon ){
 -      int i;
 -
 -
 +      int             i;
 +      
 +      
        /* test */
-       for( i= 0; i < 3; i++ )
-               if( fabs( n1[ i ] - n2[ i ]) > epsilon )
+       for ( i = 0; i < 3; i++ )
+               if ( fabs( n1[ i ] - n2[ i ] ) > epsilon ) {
                        return qfalse;
+               }
        return qtrue;
  }
  
- mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh )
- {
+ mapDrawSurface_t *DrawSurfaceForMesh( entity_t *e, parseMesh_t *p, mesh_t *mesh ){
 -      int i, k, numVerts;
 -      vec4_t plane;
 -      qboolean planar;
 -      float dist;
 -      mapDrawSurface_t    *ds;
 -      shaderInfo_t        *si, *parent;
 -      bspDrawVert_t       *dv;
 -      vec3_t vTranslated;
 -      mesh_t              *copy;
 -      qboolean indexed;
 -      byte shaderIndexes[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
 -      float offsets[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
 -
 -
 +      int                                     i, k, numVerts;
 +      vec4_t                          plane;
 +      qboolean                        planar;
 +      float                           dist;
 +      mapDrawSurface_t        *ds;
 +      shaderInfo_t            *si, *parent;
 +      bspDrawVert_t           *dv;
 +      vec3_t                          vTranslated;
 +      mesh_t                          *copy;
 +      qboolean                        indexed;
 +      byte                            shaderIndexes[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
 +      float                           offsets[ MAX_EXPANDED_AXIS * MAX_EXPANDED_AXIS ];
 +      
 +      
        /* get mesh and shader shader */
-       if( mesh == NULL )
+       if ( mesh == NULL ) {
                mesh = &p->mesh;
+       }
        si = p->shaderInfo;
-       if( mesh == NULL || si == NULL )
+       if ( mesh == NULL || si == NULL ) {
                return NULL;
 -
+       }
 +      
        /* get vertex count */
        numVerts = mesh->width * mesh->height;
 -
 +      
        /* to make valid normals for patches with degenerate edges,
           we need to make a copy of the mesh and put the aproximating
           points onto the curve */
 -
 +      
        /* create a copy of the mesh */
        copy = CopyMesh( mesh );
 -
 +      
        /* store off the original (potentially bad) normals */
        MakeMeshNormals( *copy );
-       for( i = 0; i < numVerts; i++ )
+       for ( i = 0; i < numVerts; i++ )
                VectorCopy( copy->verts[ i ].normal, mesh->verts[ i ].normal );
 -
 +      
        /* put the mesh on the curve */
        PutMeshOnCurve( *copy );
  
        /* find new normals (to take into account degenerate/flipped edges */
        MakeMeshNormals( *copy );
-       for( i = 0; i < numVerts; i++ )
+       for ( i = 0; i < numVerts; i++ )
        {
                /* ydnar: only copy normals that are significantly different from the originals */
-               if( DotProduct( copy->verts[ i ].normal, mesh->verts[ i ].normal ) < 0.75f )
+               if ( DotProduct( copy->verts[ i ].normal, mesh->verts[ i ].normal ) < 0.75f ) {
                        VectorCopy( copy->verts[ i ].normal, mesh->verts[ i ].normal );
 -              }
        }
 -
++      }
 +      
        /* free the old mesh */
        FreeMesh( copy );
 -
 +      
        /* ydnar: gs mods: check for indexed shader */
-       if( si->indexed && p->im != NULL )
-       {
+       if ( si->indexed && p->im != NULL ) {
                /* indexed */
                indexed = qtrue;
  
                parent = si;
                si = GetIndexedShader( parent, p->im, numVerts, shaderIndexes );
        }
-       else
+       else{
                indexed = qfalse;
 -
 -
+       }
 +      
 +      
        /* ydnar: gs mods */
        ds = AllocDrawSurface( SURFACE_PATCH );
        ds->entityNum = p->entityNum;
        VectorCopy( mesh->verts[ 0 ].normal, plane );
        plane[ 3 ] = DotProduct( mesh->verts[ 0 ].xyz, plane );
        planar = qtrue;
 -
 +      
        /* spew forth errors */
-       if( VectorLength( plane ) < 0.001f )
+       if ( VectorLength( plane ) < 0.001f ) {
                Sys_Printf( "BOGUS " );
 -
+       }
 +      
        /* test each vert */
-       for( i = 1; i < ds->numVerts && planar; i++ )
+       for ( i = 1; i < ds->numVerts && planar; i++ )
        {
                /* normal test */
-               if( VectorCompare( plane, mesh->verts[ i ].normal ) == qfalse )
+               if ( VectorCompare( plane, mesh->verts[ i ].normal ) == qfalse ) {
                        planar = qfalse;
 -
+               }
 +              
                /* point-plane test */
                dist = DotProduct( mesh->verts[ i ].xyz, plane ) - plane[ 3 ];
-               if( fabs( dist ) > EQUAL_EPSILON )
+               if ( fabs( dist ) > EQUAL_EPSILON ) {
                        planar = qfalse;
 -              }
        }
 -
++      }
 +      
        /* add a map plane */
-       if( planar )
-       {
+       if ( planar ) {
                /* make a map plane */
                ds->planeNum = FindFloatPlane( plane, plane[ 3 ], 1, &mesh->verts[ 0 ].xyz );
                VectorCopy( plane, ds->lightmapVecs[ 2 ] );
 -
 +              
                /* push this normal to all verts (ydnar 2003-02-14: bad idea, small patches get screwed up) */
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                        VectorCopy( plane, ds->verts[ i ].normal );
        }
 -
 +      
        /* walk the verts to do special stuff */
-       for( i = 0; i < ds->numVerts; i++ )
+       for ( i = 0; i < ds->numVerts; i++ )
        {
                /* get the drawvert */
                dv = &ds->verts[ i ];
 -
 +              
                /* ydnar: tek-fu celshading support for flat shaded shit */
-               if( flat )
-               {
+               if ( flat ) {
                        dv->st[ 0 ] = si->stFlat[ 0 ];
                        dv->st[ 1 ] = si->stFlat[ 1 ];
                }
 -
 +              
                /* ydnar: gs mods: added support for explicit shader texcoord generation */
-               else if( si->tcGen )
-               {
+               else if ( si->tcGen ) {
                        /* translate by origin and project the texture */
                        VectorAdd( dv->xyz, e->origin, vTranslated );
                        dv->st[ 0 ] = DotProduct( si->vecs[ 0 ], vTranslated );
                        dv->st[ 1 ] = DotProduct( si->vecs[ 1 ], vTranslated );
                }
 -
 +              
                /* ydnar: set color */
-               for( k = 0; k < MAX_LIGHTMAPS; k++ )
+               for ( k = 0; k < MAX_LIGHTMAPS; k++ )
                {
                        dv->color[ k ][ 0 ] = 255;
                        dv->color[ k ][ 1 ] = 255;
                        dv->color[ k ][ 2 ] = 255;
 -
 +                      
                        /* ydnar: gs mods: handle indexed shader blending */
-                       dv->color[ k ][ 3 ] = (indexed ? shaderIndexes[ i ] : 255);
+                       dv->color[ k ][ 3 ] = ( indexed ? shaderIndexes[ i ] : 255 );
                }
 -
 +              
                /* ydnar: offset */
-               if( indexed )
+               if ( indexed ) {
                        dv->xyz[ 2 ] += offsets[ i ];
 -              }
        }
 -
++      }
 +      
        /* set cel shader */
        ds->celShader = p->celShader;
 -
 +      
        /* return the drawsurface */
        return ds;
  }
  
  
  /*
- DrawSurfaceForFlare() - ydnar
- creates a flare draw surface
- */
   DrawSurfaceForFlare() - ydnar
   creates a flare draw surface
 */
  
- mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle )
- {
+ mapDrawSurface_t *DrawSurfaceForFlare( int entNum, vec3_t origin, vec3_t normal, vec3_t color, const char *flareShader, int lightStyle ){
 -      mapDrawSurface_t    *ds;
 -
 -
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* emit flares? */
-       if( emitFlares == qfalse )
+       if ( emitFlares == qfalse ) {
                return NULL;
 -
+       }
 +      
        /* allocate drawsurface */
        ds = AllocDrawSurface( SURFACE_FLARE );
        ds->entityNum = entNum;
 -
 +      
        /* set it up */
-       if( flareShader != NULL && flareShader[ 0 ] != '\0' )
+       if ( flareShader != NULL && flareShader[ 0 ] != '\0' ) {
                ds->shaderInfo = ShaderInfoForShader( flareShader );
-       else
+       }
+       else{
                ds->shaderInfo = ShaderInfoForShader( game->flareShader );
-       if( origin != NULL )
+       }
+       if ( origin != NULL ) {
                VectorCopy( origin, ds->lightmapOrigin );
-       if( normal != NULL )
+       }
+       if ( normal != NULL ) {
                VectorCopy( normal, ds->lightmapVecs[ 2 ] );
-       if( color != NULL )
+       }
+       if ( color != NULL ) {
                VectorCopy( color, ds->lightmapVecs[ 0 ] );
 -
+       }
 +      
        /* store light style */
        ds->lightStyle = lightStyle;
-       if( ds->lightStyle < 0 || ds->lightStyle >= LS_NONE )
+       if ( ds->lightStyle < 0 || ds->lightStyle >= LS_NONE ) {
                ds->lightStyle = LS_NORMAL;
 -
+       }
 +      
        /* fixme: fog */
 -
 +      
        /* return to sender */
        return ds;
  }
  
  
  /*
- DrawSurfaceForShader() - ydnar
- creates a bogus surface to forcing the game to load a shader
- */
   DrawSurfaceForShader() - ydnar
   creates a bogus surface to forcing the game to load a shader
 */
  
- mapDrawSurface_t *DrawSurfaceForShader( char *shader )
- {
+ mapDrawSurface_t *DrawSurfaceForShader( char *shader ){
 -      int i;
 -      shaderInfo_t        *si;
 -      mapDrawSurface_t    *ds;
 -
 -
 +      int                                     i;
 +      shaderInfo_t            *si;
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* get shader */
        si = ShaderInfoForShader( shader );
  
        {
                /* get surface */
                ds = &mapDrawSurfs[ i ];
 -
 +              
                /* check it */
-               if( ds->shaderInfo == si )
+               if ( ds->shaderInfo == si ) {
                        return ds;
 -              }
        }
 -
++      }
 +      
        /* create a new surface */
        ds = AllocDrawSurface( SURFACE_SHADER );
        ds->entityNum = 0;
  
  
  /*
- AddSurfaceFlare() - ydnar
- creates flares (coronas) centered on surfaces
- */
   AddSurfaceFlare() - ydnar
   creates flares (coronas) centered on surfaces
 */
  
- static void AddSurfaceFlare( mapDrawSurface_t *ds, vec3_t entityOrigin )
- {
+ static void AddSurfaceFlare( mapDrawSurface_t *ds, vec3_t entityOrigin ){
 -      vec3_t origin;
 -      int i;
 -
 -
 +      vec3_t                          origin;
 +      int                                     i;
 +      
 +      
        /* find centroid */
        VectorClear( origin );
        for ( i = 0; i < ds->numVerts; i++ )
                VectorAdd( origin, ds->verts[ i ].xyz, origin );
-       VectorScale( origin, (1.0f / ds->numVerts), origin );
-       if( entityOrigin != NULL )
+       VectorScale( origin, ( 1.0f / ds->numVerts ), origin );
+       if ( entityOrigin != NULL ) {
                VectorAdd( origin, entityOrigin, origin );
 -
+       }
 +      
        /* push origin off surface a bit */
        VectorMA( origin, 2.0f,  ds->lightmapVecs[ 2 ], origin );
 -
 +      
        /* create the drawsurface */
        DrawSurfaceForFlare( ds->entityNum, origin, ds->lightmapVecs[ 2 ], ds->shaderInfo->color, ds->shaderInfo->flareShader, ds->shaderInfo->lightStyle );
  }
  
  
  /*
- SubdivideFace()
- subdivides a face surface until it is smaller than the specified size (subdivisions)
- */
   SubdivideFace()
   subdivides a face surface until it is smaller than the specified size (subdivisions)
 */
  
- static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_t *w, int fogNum, float subdivisions )
- {
+ static void SubdivideFace_r( entity_t *e, brush_t *brush, side_t *side, winding_t *w, int fogNum, float subdivisions ){
 -      int i;
 -      int axis;
 -      vec3_t bounds[ 2 ];
 -      const float epsilon = 0.1;
 -      int subFloor, subCeil;
 -      winding_t           *frontWinding, *backWinding;
 -      mapDrawSurface_t    *ds;
 -
 -
 +      int                                     i;
 +      int                                     axis;
 +      vec3_t                          bounds[ 2 ];
 +      const float                     epsilon = 0.1;
 +      int                                     subFloor, subCeil;
 +      winding_t                       *frontWinding, *backWinding;
 +      mapDrawSurface_t        *ds;
 +      
 +      
        /* dummy check */
-       if( w == NULL )
+       if ( w == NULL ) {
                return;
-       if( w->numpoints < 3 )
+       }
+       if ( w->numpoints < 3 ) {
                Error( "SubdivideFace_r: Bad w->numpoints (%d < 3)", w->numpoints );
 -
+       }
 +      
        /* determine surface bounds */
        ClearBounds( bounds[ 0 ], bounds[ 1 ] );
-       for( i = 0; i < w->numpoints; i++ )
+       for ( i = 0; i < w->numpoints; i++ )
                AddPointToBounds( w->p[ i ], bounds[ 0 ], bounds[ 1 ] );
 -
 +      
        /* split the face */
-       for( axis = 0; axis < 3; axis++ )
+       for ( axis = 0; axis < 3; axis++ )
        {
 -              vec3_t planePoint = { 0, 0, 0 };
 -              vec3_t planeNormal = { 0, 0, 0 };
 -              float d;
 -
 -
 +              vec3_t                  planePoint = { 0, 0, 0 };
 +              vec3_t                  planeNormal = { 0, 0, 0 };
 +              float                   d;
 +              
 +              
                /* create an axial clipping plane */
-               subFloor = floor( bounds[ 0 ][ axis ] / subdivisions) * subdivisions;
-               subCeil = ceil( bounds[ 1 ][ axis ] / subdivisions) * subdivisions;
+               subFloor = floor( bounds[ 0 ][ axis ] / subdivisions ) * subdivisions;
+               subCeil = ceil( bounds[ 1 ][ axis ] / subdivisions ) * subdivisions;
                planePoint[ axis ] = subFloor + subdivisions;
                planeNormal[ axis ] = -1;
                d = DotProduct( planePoint, planeNormal );
  
  
  /*
- SubdivideFaceSurfaces()
- chop up brush face surfaces that have subdivision attributes
- ydnar: and subdivide surfaces that exceed specified texture coordinate range
- */
   SubdivideFaceSurfaces()
   chop up brush face surfaces that have subdivision attributes
   ydnar: and subdivide surfaces that exceed specified texture coordinate range
 */
  
- void SubdivideFaceSurfaces( entity_t *e, tree_t *tree )
- {
+ void SubdivideFaceSurfaces( entity_t *e, tree_t *tree ){
 -      int i, j, numBaseDrawSurfs, fogNum;
 -      mapDrawSurface_t    *ds;
 -      brush_t             *brush;
 -      side_t              *side;
 -      shaderInfo_t        *si;
 -      winding_t           *w;
 -      float range, size, subdivisions, s2;
 -
 -
 +      int                                     i, j, numBaseDrawSurfs, fogNum;
 +      mapDrawSurface_t        *ds;
 +      brush_t                         *brush;
 +      side_t                          *side;
 +      shaderInfo_t            *si;
 +      winding_t                       *w;
 +      float                           range, size, subdivisions, s2;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- SubdivideFaceSurfaces ---\n" );
 -
 +      
        /* walk the list of surfaces */
        numBaseDrawSurfs = numMapDrawSurfs;
-       for( i = e->firstDrawSurf; i < numBaseDrawSurfs; i++ )
+       for ( i = e->firstDrawSurf; i < numBaseDrawSurfs; i++ )
        {
                /* get surface */
                ds = &mapDrawSurfs[ i ];
  
                /* only subdivide brush sides */
-               if( ds->type != SURFACE_FACE || ds->mapBrush == NULL || ds->sideRef == NULL || ds->sideRef->side == NULL )
+               if ( ds->type != SURFACE_FACE || ds->mapBrush == NULL || ds->sideRef == NULL || ds->sideRef->side == NULL ) {
                        continue;
 -
+               }
 +              
                /* get bits */
                brush = ds->mapBrush;
                side = ds->sideRef->side;
 -
 +              
                /* check subdivision for shader */
                si = side->shaderInfo;
-               if( si == NULL )
+               if ( si == NULL ) {
                        continue;
 -
+               }
 +              
                /* ydnar: don't subdivide sky surfaces */
-               if( si->compileFlags & C_SKY )
+               if ( si->compileFlags & C_SKY ) {
                        continue;
 -
+               }
 +              
                /* do texture coordinate range check */
                ClassifySurfaces( 1, ds );
-               if( CalcSurfaceTextureRange( ds ) == qfalse )
-               {
+               if ( CalcSurfaceTextureRange( ds ) == qfalse ) {
                        /* calculate subdivisions texture range (this code is shit) */
-                       range = (ds->texRange[ 0 ] > ds->texRange[ 1 ] ? ds->texRange[ 0 ] : ds->texRange[ 1 ]);
+                       range = ( ds->texRange[ 0 ] > ds->texRange[ 1 ] ? ds->texRange[ 0 ] : ds->texRange[ 1 ] );
                        size = ds->maxs[ 0 ] - ds->mins[ 0 ];
-                       for( j = 1; j < 3; j++ )
-                               if( (ds->maxs[ j ] - ds->mins[ j ]) > size )
+                       for ( j = 1; j < 3; j++ )
+                               if ( ( ds->maxs[ j ] - ds->mins[ j ] ) > size ) {
                                        size = ds->maxs[ j ] - ds->mins[ j ];
-                       subdivisions = (size / range) * texRange;
+                               }
+                       subdivisions = ( size / range ) * texRange;
                        subdivisions = ceil( subdivisions / 2 ) * 2;
-                       for( j = 1; j < 8; j++ )
+                       for ( j = 1; j < 8; j++ )
                        {
                                s2 = ceil( (float) texRange / j );
-                               if( fabs( subdivisions - s2 ) <= 4.0 )
-                               {
+                               if ( fabs( subdivisions - s2 ) <= 4.0 ) {
                                        subdivisions = s2;
                                        break;
                                }
                        }
                }
-               else
+               else{
                        subdivisions = si->subdivisions;
 -
+               }
 +              
                /* get subdivisions from shader */
-               if(     si->subdivisions > 0 && si->subdivisions < subdivisions )
+               if ( si->subdivisions > 0 && si->subdivisions < subdivisions ) {
                        subdivisions = si->subdivisions;
-               if( subdivisions < 1.0f )
+               }
+               if ( subdivisions < 1.0f ) {
                        continue;
 -
+               }
 +              
                /* preserve fog num */
                fogNum = ds->fogNum;
 -
 +              
                /* make a winding and free the surface */
                w = WindingFromDrawSurf( ds );
                ClearSurface( ds );
  
  
  /*
- ====================
- ClipSideIntoTree_r
   ====================
   ClipSideIntoTree_r
  
- Adds non-opaque leaf fragments to the convex hull
- ====================
- */
   Adds non-opaque leaf fragments to the convex hull
   ====================
 */
  
- void ClipSideIntoTree_r( winding_t *w, side_t *side, node_t *node )
- {
+ void ClipSideIntoTree_r( winding_t *w, side_t *side, node_t *node ){
 -      plane_t         *plane;
 -      winding_t       *front, *back;
 +      plane_t                 *plane;
 +      winding_t               *front, *back;
  
        if ( !w ) {
                return;
@@@ -1534,59 -1585,62 +1587,62 @@@ static int g_numHiddenFaces, g_numCoinF
  
  #define CULL_EPSILON 0.1f
  
- qboolean CullVectorCompare( const vec3_t v1, const vec3_t v2 )
- {
+ qboolean CullVectorCompare( const vec3_t v1, const vec3_t v2 ){
 -      int i;
 -
 -
 +      int             i;
 +      
 +      
-       for( i = 0; i < 3; i++ )
-               if( fabs( v1[ i ] - v2[ i ] ) > CULL_EPSILON )
+       for ( i = 0; i < 3; i++ )
+               if ( fabs( v1[ i ] - v2[ i ] ) > CULL_EPSILON ) {
                        return qfalse;
+               }
        return qtrue;
  }
  
  
  
  /*
- SideInBrush() - ydnar
- determines if a brushside lies inside another brush
- */
   SideInBrush() - ydnar
   determines if a brushside lies inside another brush
 */
  
- qboolean SideInBrush( side_t *side, brush_t *b )
- {
+ qboolean SideInBrush( side_t *side, brush_t *b ){
 -      int i, s;
 -      plane_t     *plane;
 -
 -
 +      int                     i, s;
 +      plane_t         *plane;
 +      
 +      
        /* ignore sides w/o windings or shaders */
-       if( side->winding == NULL || side->shaderInfo == NULL )
+       if ( side->winding == NULL || side->shaderInfo == NULL ) {
                return qtrue;
+       }
  
        /* ignore culled sides and translucent brushes */
-       if( side->culled == qtrue || (b->compileFlags & C_TRANSLUCENT) )
+       if ( side->culled == qtrue || ( b->compileFlags & C_TRANSLUCENT ) ) {
                return qfalse;
+       }
  
        /* side iterator */
-       for( i = 0; i < b->numsides; i++ )
+       for ( i = 0; i < b->numsides; i++ )
        {
                /* fail if any sides are caulk */
-               if( b->sides[ i ].compileFlags & C_NODRAW )
+               if ( b->sides[ i ].compileFlags & C_NODRAW ) {
                        return qfalse;
+               }
  
                /* check if side's winding is on or behind the plane */
                plane = &mapplanes[ b->sides[ i ].planenum ];
                s = WindingOnPlaneSide( side->winding, plane->normal, plane->dist );
-               if( s == SIDE_FRONT || s == SIDE_CROSS )
+               if ( s == SIDE_FRONT || s == SIDE_CROSS ) {
                        return qfalse;
 -              }
        }
 -
++      }
 +      
        /* don't cull autosprite or polygonoffset surfaces */
-       if( side->shaderInfo )
-       {
-               if( side->shaderInfo->autosprite || side->shaderInfo->polygonOffset )
+       if ( side->shaderInfo ) {
+               if ( side->shaderInfo->autosprite || side->shaderInfo->polygonOffset ) {
                        return qfalse;
 -              }
        }
 -
++      }
 +      
        /* inside */
        side->culled = qtrue;
        g_numHiddenFaces++;
  
  
  /*
- CullSides() - ydnar
- culls obscured or buried brushsides from the map
- */
   CullSides() - ydnar
   culls obscured or buried brushsides from the map
 */
  
- void CullSides( entity_t *e )
- {
+ void CullSides( entity_t *e ){
 -      int numPoints;
 -      int i, j, k, l, first, second, dir;
 -      winding_t   *w1, *w2;
 -      brush_t *b1, *b2;
 -      side_t      *side1, *side2;
 -
 -
 +      int                     numPoints;
 +      int                     i, j, k, l, first, second, dir;
 +      winding_t       *w1, *w2;
 +      brush_t *b1, *b2;
 +      side_t          *side1, *side2;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- CullSides ---\n" );
 -
 +      
        g_numHiddenFaces = 0;
        g_numCoinFaces = 0;
 -
 +      
        /* brush interator 1 */
-       for( b1 = e->brushes; b1; b1 = b1->next )
+       for ( b1 = e->brushes; b1; b1 = b1->next )
        {
                /* sides check */
-               if( b1->numsides < 1 )
+               if ( b1->numsides < 1 ) {
                        continue;
+               }
  
                /* brush iterator 2 */
-               for( b2 = b1->next; b2; b2 = b2->next )
+               for ( b2 = b1->next; b2; b2 = b2->next )
                {
                        /* sides check */
-                       if( b2->numsides < 1 )
+                       if ( b2->numsides < 1 ) {
                                continue;
 -
+                       }
 +                      
                        /* original check */
-                       if( b1->original == b2->original && b1->original != NULL )
+                       if ( b1->original == b2->original && b1->original != NULL ) {
                                continue;
 -
+                       }
 +                      
                        /* bbox check */
                        j = 0;
-                       for( i = 0; i < 3; i++ )
-                               if( b1->mins[ i ] > b2->maxs[ i ] || b1->maxs[ i ] < b2->mins[ i ] )
+                       for ( i = 0; i < 3; i++ )
+                               if ( b1->mins[ i ] > b2->maxs[ i ] || b1->maxs[ i ] < b2->mins[ i ] ) {
                                        j++;
-                       if( j )
+                               }
+                       if ( j ) {
                                continue;
+                       }
  
                        /* cull inside sides */
-                       for( i = 0; i < b1->numsides; i++ )
+                       for ( i = 0; i < b1->numsides; i++ )
                                SideInBrush( &b1->sides[ i ], b2 );
-                       for( i = 0; i < b2->numsides; i++ )
+                       for ( i = 0; i < b2->numsides; i++ )
                                SideInBrush( &b2->sides[ i ], b1 );
 -
 +                      
                        /* side iterator 1 */
-                       for( i = 0; i < b1->numsides; i++ )
+                       for ( i = 0; i < b1->numsides; i++ )
                        {
                                /* winding check */
                                side1 = &b1->sides[ i ];
                                w1 = side1->winding;
-                               if( w1 == NULL )
+                               if ( w1 == NULL ) {
                                        continue;
+                               }
                                numPoints = w1->numpoints;
-                               if( side1->shaderInfo == NULL )
+                               if ( side1->shaderInfo == NULL ) {
                                        continue;
 -
+                               }
 +                              
                                /* side iterator 2 */
-                               for( j = 0; j < b2->numsides; j++ )
+                               for ( j = 0; j < b2->numsides; j++ )
                                {
                                        /* winding check */
                                        side2 = &b2->sides[ j ];
                                        w2 = side2->winding;
-                                       if( w2 == NULL )
+                                       if ( w2 == NULL ) {
                                                continue;
-                                       if( side2->shaderInfo == NULL )
+                                       }
+                                       if ( side2->shaderInfo == NULL ) {
                                                continue;
-                                       if( w1->numpoints != w2->numpoints )
+                                       }
+                                       if ( w1->numpoints != w2->numpoints ) {
                                                continue;
-                                       if( side1->culled == qtrue && side2->culled == qtrue )
+                                       }
+                                       if ( side1->culled == qtrue && side2->culled == qtrue ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* compare planes */
-                                       if( (side1->planenum & ~0x00000001) != (side2->planenum & ~0x00000001) )
+                                       if ( ( side1->planenum & ~0x00000001 ) != ( side2->planenum & ~0x00000001 ) ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* get autosprite and polygonoffset status */
-                                       if( side1->shaderInfo &&
-                                               (side1->shaderInfo->autosprite || side1->shaderInfo->polygonOffset) )
+                                       if ( side1->shaderInfo &&
+                                                ( side1->shaderInfo->autosprite || side1->shaderInfo->polygonOffset ) ) {
                                                continue;
-                                       if( side2->shaderInfo &&
-                                               (side2->shaderInfo->autosprite || side2->shaderInfo->polygonOffset) )
+                                       }
+                                       if ( side2->shaderInfo &&
+                                                ( side2->shaderInfo->autosprite || side2->shaderInfo->polygonOffset ) ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* find first common point */
                                        first = -1;
-                                       for( k = 0; k < numPoints; k++ )
-                                       {
-                                               if( VectorCompare( w1->p[ 0 ], w2->p[ k ] ) )
+                                       for ( k = 0; k < numPoints; k++ )
 -                                      {
 +                                              {
+                                               if ( VectorCompare( w1->p[ 0 ], w2->p[ k ] ) ) {
                                                        first = k;
                                                        k = numPoints;
                                                }
                                        }
-                                       if( first == -1 )
+                                       if ( first == -1 ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* find second common point (regardless of winding order) */
                                        second = -1;
                                        dir = 0;
-                                       if( (first + 1) < numPoints )
+                                       if ( ( first + 1 ) < numPoints ) {
                                                second = first + 1;
-                                       else
+                                       }
+                                       else{
                                                second = 0;
-                                       if( CullVectorCompare( w1->p[ 1 ], w2->p[ second ] ) )
+                                       }
+                                       if ( CullVectorCompare( w1->p[ 1 ], w2->p[ second ] ) ) {
                                                dir = 1;
+                                       }
                                        else
                                        {
-                                               if( first > 0 )
+                                               if ( first > 0 ) {
                                                        second = first - 1;
-                                               else
+                                               }
+                                               else{
                                                        second = numPoints - 1;
-                                               if( CullVectorCompare( w1->p[ 1 ], w2->p[ second ] ) )
+                                               }
+                                               if ( CullVectorCompare( w1->p[ 1 ], w2->p[ second ] ) ) {
                                                        dir = -1;
 -                                              }
 +                                      }
-                                       if( dir == 0 )
+                                       }
+                                       if ( dir == 0 ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* compare the rest of the points */
                                        l = first;
-                                       for( k = 0; k < numPoints; k++ )
+                                       for ( k = 0; k < numPoints; k++ )
                                        {
-                                               if( !CullVectorCompare( w1->p[ k ], w2->p[ l ] ) )
+                                               if ( !CullVectorCompare( w1->p[ k ], w2->p[ l ] ) ) {
                                                        k = 100000;
 -
+                                               }
 +                                              
                                                l += dir;
-                                               if( l < 0 )
+                                               if ( l < 0 ) {
                                                        l = numPoints - 1;
-                                               else if( l >= numPoints )
+                                               }
+                                               else if ( l >= numPoints ) {
                                                        l = 0;
 -                                              }
 +                                      }
-                                       if( k >= 100000 )
+                                       }
+                                       if ( k >= 100000 ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* cull face 1 */
-                                       if( !side2->culled && !(side2->compileFlags & C_TRANSLUCENT) && !(side2->compileFlags & C_NODRAW) )
-                                       {
+                                       if ( !side2->culled && !( side2->compileFlags & C_TRANSLUCENT ) && !( side2->compileFlags & C_NODRAW ) ) {
                                                side1->culled = qtrue;
                                                g_numCoinFaces++;
                                        }
 -
 +                                      
-                                       if( side1->planenum == side2->planenum && side1->culled == qtrue )
+                                       if ( side1->planenum == side2->planenum && side1->culled == qtrue ) {
                                                continue;
 -
+                                       }
 +                                      
                                        /* cull face 2 */
-                                       if( !side1->culled && !(side1->compileFlags & C_TRANSLUCENT) && !(side1->compileFlags & C_NODRAW) )
-                                       {
+                                       if ( !side1->culled && !( side1->compileFlags & C_TRANSLUCENT ) && !( side1->compileFlags & C_NODRAW ) ) {
                                                side2->culled = qtrue;
                                                g_numCoinFaces++;
                                        }
  
  
  /*
- ClipSidesIntoTree()
   ClipSidesIntoTree()
  
- creates side->visibleHull for all visible sides
   creates side->visibleHull for all visible sides
  
- the drawsurf for a side will consist of the convex hull of
- all points in non-opaque clusters, which allows overlaps
- to be trimmed off automatically.
- */
   the drawsurf for a side will consist of the convex hull of
   all points in non-opaque clusters, which allows overlaps
   to be trimmed off automatically.
 */
  
- void ClipSidesIntoTree( entity_t *e, tree_t *tree )
- {
+ void ClipSidesIntoTree( entity_t *e, tree_t *tree ){
 -      brush_t     *b;
 -      int i;
 -      winding_t       *w;
 -      side_t          *side, *newSide;
 -      shaderInfo_t    *si;
 -
 -
 +      brush_t         *b;
 +      int                             i;
 +      winding_t               *w;
 +      side_t                  *side, *newSide;
 +      shaderInfo_t    *si;
 +  
 +      
        /* ydnar: cull brush sides */
        CullSides( e );
 -
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- ClipSidesIntoTree ---\n" );
 -
 +      
        /* walk the brush list */
-       for( b = e->brushes; b; b = b->next )
+       for ( b = e->brushes; b; b = b->next )
        {
                /* walk the brush sides */
-               for( i = 0; i < b->numsides; i++ )
+               for ( i = 0; i < b->numsides; i++ )
                {
                        /* get side */
                        side = &b->sides[ i ];
-                       if( side->winding == NULL )
+                       if ( side->winding == NULL ) {
                                continue;
 -
+                       }
 +                      
                        /* copy the winding */
                        w = CopyWinding( side->winding );
                        side->visibleHull = NULL;
                        ClipSideIntoTree_r( w, side, tree->headnode );
 -
 +                      
                        /* anything left? */
                        w = side->visibleHull;
-                       if( w == NULL )
+                       if ( w == NULL ) {
                                continue;
 -
+                       }
 +                      
                        /* shader? */
                        si = side->shaderInfo;
-                       if( si == NULL )
+                       if ( si == NULL ) {
                                continue;
 -
+                       }
 +                      
                        /* don't create faces for non-visible sides */
                        /* ydnar: except indexed shaders, like common/terrain and nodraw fog surfaces */
-                       if( (si->compileFlags & C_NODRAW) && si->indexed == qfalse && !(si->compileFlags & C_FOG) )
+                       if ( ( si->compileFlags & C_NODRAW ) && si->indexed == qfalse && !( si->compileFlags & C_FOG ) ) {
                                continue;
 -
+                       }
 +                      
                        /* always use the original winding for autosprites and noclip faces */
-                       if( si->autosprite || si->noClip )
+                       if ( si->autosprite || si->noClip ) {
                                w = side->winding;
 -
+                       }
 +                      
                        /* save this winding as a visible surface */
                        DrawSurfaceForSide( e, b, side, w );
  
                        /* make a back side for fog */
-                       if( !(si->compileFlags & C_FOG) )
+                       if ( !( si->compileFlags & C_FOG ) ) {
                                continue;
 -
+                       }
 +                      
                        /* duplicate the up-facing side */
                        w = ReverseWinding( w );
                        newSide = safe_malloc( sizeof( *side ) );
  
  /*
  
- this section deals with filtering drawsurfaces into the bsp tree,
- adding references to each leaf a surface touches
   this section deals with filtering drawsurfaces into the bsp tree,
   adding references to each leaf a surface touches
  
- */
 */
  
  /*
- AddReferenceToLeaf() - ydnar
- adds a reference to surface ds in the bsp leaf node
- */
   AddReferenceToLeaf() - ydnar
   adds a reference to surface ds in the bsp leaf node
 */
  
- int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node )
- {
+ int AddReferenceToLeaf( mapDrawSurface_t *ds, node_t *node ){
 -      drawSurfRef_t   *dsr;
 -
 -
 +      drawSurfRef_t   *dsr;
 +      
 +      
        /* dummy check */
-       if( node->planenum != PLANENUM_LEAF || node->opaque )
+       if ( node->planenum != PLANENUM_LEAF || node->opaque ) {
                return 0;
 -
+       }
 +      
        /* try to find an existing reference */
-       for( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
+       for ( dsr = node->drawSurfReferences; dsr; dsr = dsr->nextRef )
        {
-               if( dsr->outputNum == numBSPDrawSurfaces )
+               if ( dsr->outputNum == numBSPDrawSurfaces ) {
                        return 0;
 -              }
        }
 -
++      }
 +      
        /* add a new reference */
        dsr = safe_malloc( sizeof( *dsr ) );
        dsr->outputNum = numBSPDrawSurfaces;
        dsr->nextRef = node->drawSurfReferences;
        node->drawSurfReferences = dsr;
 -
 +      
        /* ydnar: sky/skybox surfaces */
-       if( node->skybox )
+       if ( node->skybox ) {
                ds->skybox = qtrue;
-       if( ds->shaderInfo->compileFlags & C_SKY )
+       }
+       if ( ds->shaderInfo->compileFlags & C_SKY ) {
                node->sky = qtrue;
 -
+       }
 +      
        /* return */
        return 1;
  }
  
  
  /*
- AddReferenceToTree_r() - ydnar
- adds a reference to the specified drawsurface to every leaf in the tree
- */
   AddReferenceToTree_r() - ydnar
   adds a reference to the specified drawsurface to every leaf in the tree
 */
  
- int AddReferenceToTree_r( mapDrawSurface_t *ds, node_t *node, qboolean skybox )
- {
+ int AddReferenceToTree_r( mapDrawSurface_t *ds, node_t *node, qboolean skybox ){
 -      int i, refs = 0;
 -
 -
 +      int             i, refs = 0;
 +      
 +      
        /* dummy check */
-       if( node == NULL )
+       if ( node == NULL ) {
                return 0;
 -
+       }
 +      
        /* is this a decision node? */
-       if( node->planenum != PLANENUM_LEAF )
-       {
+       if ( node->planenum != PLANENUM_LEAF ) {
                /* add to child nodes and return */
                refs += AddReferenceToTree_r( ds, node->children[ 0 ], skybox );
                refs += AddReferenceToTree_r( ds, node->children[ 1 ], skybox );
                return refs;
        }
 -
 +      
        /* ydnar */
-       if( skybox )
-       {
+       if ( skybox ) {
                /* skybox surfaces only get added to sky leaves */
-               if( !node->sky )
+               if ( !node->sky ) {
                        return 0;
 -
+               }
 +              
                /* increase the leaf bounds */
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                        AddPointToBounds( ds->verts[ i ].xyz, node->mins, node->maxs );
        }
 -
 +      
        /* add a reference */
        return AddReferenceToLeaf( ds, node );
  }
  
  
  /*
- FilterPointIntoTree_r() - ydnar
- filters a single point from a surface into the tree
- */
   FilterPointIntoTree_r() - ydnar
   filters a single point from a surface into the tree
 */
  
- int FilterPointIntoTree_r( vec3_t point, mapDrawSurface_t *ds, node_t *node )
- {
+ int FilterPointIntoTree_r( vec3_t point, mapDrawSurface_t *ds, node_t *node ){
 -      float d;
 -      plane_t         *plane;
 -      int refs = 0;
 -
 -
 +      float                   d;
 +      plane_t                 *plane;
 +      int                             refs = 0;
 +      
 +      
        /* is this a decision node? */
-       if( node->planenum != PLANENUM_LEAF )
-       {
+       if ( node->planenum != PLANENUM_LEAF ) {
                /* classify the point in relation to the plane */
                plane = &mapplanes[ node->planenum ];
                d = DotProduct( point, plane->normal ) - plane->dist;
 -
 +              
                /* filter by this plane */
                refs = 0;
-               if( d >= -ON_EPSILON )
+               if ( d >= -ON_EPSILON ) {
                        refs += FilterPointIntoTree_r( point, ds, node->children[ 0 ] );
-               if( d <= ON_EPSILON )
+               }
+               if ( d <= ON_EPSILON ) {
                        refs += FilterPointIntoTree_r( point, ds, node->children[ 1 ] );
 -
+               }
 +              
                /* return */
                return refs;
        }
  }
  
  /*
- FilterPointConvexHullIntoTree_r() - ydnar
- filters the convex hull of multiple points from a surface into the tree
- */
   FilterPointConvexHullIntoTree_r() - ydnar
   filters the convex hull of multiple points from a surface into the tree
 */
  
- int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurface_t *ds, node_t *node )
- {
+ int FilterPointConvexHullIntoTree_r( vec3_t **points, int npoints, mapDrawSurface_t *ds, node_t *node ){
 -      float d, dmin, dmax;
 -      plane_t         *plane;
 -      int refs = 0;
 -      int i;
 +      float                   d, dmin, dmax;
 +      plane_t                 *plane;
 +      int                             refs = 0;
 +      int                             i;
  
-       if(!points)
+       if ( !points ) {
                return 0;
 -
+       }
 +      
        /* is this a decision node? */
-       if( node->planenum != PLANENUM_LEAF )
-       {
+       if ( node->planenum != PLANENUM_LEAF ) {
                /* classify the point in relation to the plane */
                plane = &mapplanes[ node->planenum ];
  
-               dmin = dmax = DotProduct( *(points[0]), plane->normal ) - plane->dist;
-               for(i = 1; i < npoints; ++i)
+               dmin = dmax = DotProduct( *( points[0] ), plane->normal ) - plane->dist;
+               for ( i = 1; i < npoints; ++i )
                {
-                       d = DotProduct( *(points[i]), plane->normal ) - plane->dist;
-                       if(d > dmax)
+                       d = DotProduct( *( points[i] ), plane->normal ) - plane->dist;
+                       if ( d > dmax ) {
                                dmax = d;
-                       if(d < dmin)
+                       }
+                       if ( d < dmin ) {
                                dmin = d;
 -                      }
                }
 -
++              }
 +              
                /* filter by this plane */
                refs = 0;
-               if( dmax >= -ON_EPSILON )
+               if ( dmax >= -ON_EPSILON ) {
                        refs += FilterPointConvexHullIntoTree_r( points, npoints, ds, node->children[ 0 ] );
-               if( dmin <= ON_EPSILON )
+               }
+               if ( dmin <= ON_EPSILON ) {
                        refs += FilterPointConvexHullIntoTree_r( points, npoints, ds, node->children[ 1 ] );
 -
+               }
 +              
                /* return */
                return refs;
        }
  
  
  /*
- FilterWindingIntoTree_r() - ydnar
- filters a winding from a drawsurface into the tree
- */
   FilterWindingIntoTree_r() - ydnar
   filters a winding from a drawsurface into the tree
 */
  
- int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node )
- {
+ int FilterWindingIntoTree_r( winding_t *w, mapDrawSurface_t *ds, node_t *node ){
 -      int i, refs = 0;
 -      plane_t         *p1, *p2;
 +      int                             i, refs = 0;
 +      plane_t                 *p1, *p2;
-       vec4_t                  plane1, plane2, reverse;
+       vec4_t plane1, plane2;
 -      winding_t       *fat, *front, *back;
 -      shaderInfo_t    *si;
 -
 -
 +      winding_t               *fat, *front, *back;
 +      shaderInfo_t    *si;
 +      
 +      
        /* get shaderinfo */
        si = ds->shaderInfo;
 -
 +      
        /* ydnar: is this the head node? */
-       if( node->parent == NULL && si != NULL &&
-               (si->mins[ 0 ] != 0.0f || si->maxs[ 0 ] != 0.0f ||
+       if ( node->parent == NULL && si != NULL &&
+                ( si->mins[ 0 ] != 0.0f || si->maxs[ 0 ] != 0.0f ||
 -                 si->mins[ 1 ] != 0.0f || si->maxs[ 1 ] != 0.0f ||
 +              si->mins[ 1 ] != 0.0f || si->maxs[ 1 ] != 0.0f ||
-               si->mins[ 2 ] != 0.0f || si->maxs[ 2 ] != 0.0f) )
-       {
+                  si->mins[ 2 ] != 0.0f || si->maxs[ 2 ] != 0.0f ) ) {
+               static qboolean warned = qfalse;
+               if ( !warned ) {
+                       Sys_Printf( "WARNING: this map uses the deformVertexes move hack\n" );
+                       warned = qtrue;
+               }
                /* 'fatten' the winding by the shader mins/maxs (parsed from vertexDeform move) */
                /* note this winding is completely invalid (concave, nonplanar, etc) */
                fat = AllocWinding( w->numpoints * 3 + 3 );
                FreeWinding( w );
                w = fat;
        }
 -
 +      
        /* is this a decision node? */
-       if( node->planenum != PLANENUM_LEAF )
-       {       
+       if ( node->planenum != PLANENUM_LEAF ) {
                /* get node plane */
                p1 = &mapplanes[ node->planenum ];
                VectorCopy( p1->normal, plane1 );
                plane1[ 3 ] = p1->dist;
 -
 +              
                /* check if surface is planar */
-               if( ds->planeNum >= 0 )
-               {
+               if ( ds->planeNum >= 0 ) {
                        /* get surface plane */
                        p2 = &mapplanes[ ds->planeNum ];
                        VectorCopy( p2->normal, plane2 );
                        plane2[ 3 ] = p2->dist;
 -
 +                      
-                       #if 1
+                       #if 0
+                       /* div0: this is the plague (inaccurate) */
+                       vec4_t reverse;
 -                      /* invert surface plane */
 -                      VectorSubtract( vec3_origin, plane2, reverse );
 -                      reverse[ 3 ] = -plane2[ 3 ];
 -
 -                      /* compare planes */
 +                              /* invert surface plane */
 +                              VectorSubtract( vec3_origin, plane2, reverse );
 +                              reverse[ 3 ] = -plane2[ 3 ];
 +                              
 +                              /* compare planes */
-                               if( DotProduct( plane1, plane2 ) > 0.999f && fabs( plane1[ 3 ] - plane2[ 3 ] ) < 0.001f )
+                       if ( DotProduct( plane1, plane2 ) > 0.999f && fabs( plane1[ 3 ] - plane2[ 3 ] ) < 0.001f ) {
 -                              return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
 +                                      return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
-                               if( DotProduct( plane1, reverse ) > 0.999f && fabs( plane1[ 3 ] - reverse[ 3 ] ) < 0.001f )
+                       }
+                       if ( DotProduct( plane1, reverse ) > 0.999f && fabs( plane1[ 3 ] - reverse[ 3 ] ) < 0.001f ) {
 -                              return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
 +                                      return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
+                       }
                        #else
 -                      /* the drawsurf might have an associated plane, if so, force a filter here */
+                       /* div0: this is the cholera (doesn't hit enough) */
-                               if( ds->planeNum == node->planenum )
 +                              /* the drawsurf might have an associated plane, if so, force a filter here */
 -                              return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
+                       if ( ds->planeNum == node->planenum ) {
-                               if( ds->planeNum == (node->planenum ^ 1) )
 +                                      return FilterWindingIntoTree_r( w, ds, node->children[ 0 ] );
 -                              return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
+                       }
+                       if ( ds->planeNum == ( node->planenum ^ 1 ) ) {
 +                                      return FilterWindingIntoTree_r( w, ds, node->children[ 1 ] );
+                       }
                        #endif
                }
 -
 +              
                /* clip the winding by this plane */
-               ClipWindingEpsilon( w, plane1, plane1[ 3 ], ON_EPSILON, &front, &back );
+               ClipWindingEpsilonStrict( w, plane1, plane1[ 3 ], ON_EPSILON, &front, &back ); /* strict; we handle the "winding disappeared" case */
 -
 +              
                /* filter by this plane */
                refs = 0;
-               if( front != NULL )
+               if ( front == NULL && back == NULL ) {
+                       /* same plane, this is an ugly hack */
+                       /* but better too many than too few refs */
+                       refs += FilterWindingIntoTree_r( CopyWinding( w ), ds, node->children[ 0 ] );
+                       refs += FilterWindingIntoTree_r( CopyWinding( w ), ds, node->children[ 1 ] );
+               }
+               if ( front != NULL ) {
                        refs += FilterWindingIntoTree_r( front, ds, node->children[ 0 ] );
-               if( back != NULL )
+               }
+               if ( back != NULL ) {
                        refs += FilterWindingIntoTree_r( back, ds, node->children[ 1 ] );
+               }
                FreeWinding( w );
 -
 +              
                /* return */
                return refs;
        }
  
  
  /*
- FilterFaceIntoTree()
- filters a planar winding face drawsurface into the bsp tree
- */
   FilterFaceIntoTree()
   filters a planar winding face drawsurface into the bsp tree
 */
  
- int   FilterFaceIntoTree( mapDrawSurface_t *ds, tree_t *tree )
- {
+ int FilterFaceIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
 -      winding_t   *w;
 -      int refs = 0;
 -
 -
 +      winding_t       *w;
 +      int                     refs = 0;
 +      
 +      
        /* make a winding and filter it into the tree */
        w = WindingFromDrawSurf( ds );
        refs = FilterWindingIntoTree_r( w, ds, tree->headnode );
  
  
  /*
- FilterPatchIntoTree()
- subdivides a patch into an approximate curve and filters it into the tree
- */
   FilterPatchIntoTree()
   subdivides a patch into an approximate curve and filters it into the tree
 */
  
 -#define FILTER_SUBDIVISION      8
 +#define       FILTER_SUBDIVISION              8
  
- static int FilterPatchIntoTree( mapDrawSurface_t *ds, tree_t *tree )
- {
+ static int FilterPatchIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
 -      int x, y, refs = 0;
 -
 +      int                                     x, y, refs = 0;
 +      
-       for(y = 0; y + 2 < ds->patchHeight; y += 2)
-               for(x = 0; x + 2 < ds->patchWidth; x += 2)
+       for ( y = 0; y + 2 < ds->patchHeight; y += 2 )
+               for ( x = 0; x + 2 < ds->patchWidth; x += 2 )
                {
                        vec3_t *points[9];
-                       points[0] = &ds->verts[(y+0) * ds->patchWidth + (x+0)].xyz;
-                       points[1] = &ds->verts[(y+0) * ds->patchWidth + (x+1)].xyz;
-                       points[2] = &ds->verts[(y+0) * ds->patchWidth + (x+2)].xyz;
-                       points[3] = &ds->verts[(y+1) * ds->patchWidth + (x+0)].xyz;
-                       points[4] = &ds->verts[(y+1) * ds->patchWidth + (x+1)].xyz;
-                       points[5] = &ds->verts[(y+1) * ds->patchWidth + (x+2)].xyz;
-                       points[6] = &ds->verts[(y+2) * ds->patchWidth + (x+0)].xyz;
-                       points[7] = &ds->verts[(y+2) * ds->patchWidth + (x+1)].xyz;
-                       points[8] = &ds->verts[(y+2) * ds->patchWidth + (x+2)].xyz;
-                       refs += FilterPointConvexHullIntoTree_r(points, 9, ds, tree->headnode);
+                       points[0] = &ds->verts[( y + 0 ) * ds->patchWidth + ( x + 0 )].xyz;
+                       points[1] = &ds->verts[( y + 0 ) * ds->patchWidth + ( x + 1 )].xyz;
+                       points[2] = &ds->verts[( y + 0 ) * ds->patchWidth + ( x + 2 )].xyz;
+                       points[3] = &ds->verts[( y + 1 ) * ds->patchWidth + ( x + 0 )].xyz;
+                       points[4] = &ds->verts[( y + 1 ) * ds->patchWidth + ( x + 1 )].xyz;
+                       points[5] = &ds->verts[( y + 1 ) * ds->patchWidth + ( x + 2 )].xyz;
+                       points[6] = &ds->verts[( y + 2 ) * ds->patchWidth + ( x + 0 )].xyz;
+                       points[7] = &ds->verts[( y + 2 ) * ds->patchWidth + ( x + 1 )].xyz;
+                       points[8] = &ds->verts[( y + 2 ) * ds->patchWidth + ( x + 2 )].xyz;
+                       refs += FilterPointConvexHullIntoTree_r( points, 9, ds, tree->headnode );
                }
  
        return refs;
  
  
  /*
- FilterTrianglesIntoTree()
- filters a triangle surface (meta, model) into the bsp
- */
   FilterTrianglesIntoTree()
   filters a triangle surface (meta, model) into the bsp
 */
  
- static int FilterTrianglesIntoTree( mapDrawSurface_t *ds, tree_t *tree )
- {
+ static int FilterTrianglesIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
 -      int i, refs;
 -      winding_t   *w;
 -
 -
 +      int                     i, refs;
 +      winding_t       *w;
 +      
 +      
        /* ydnar: gs mods: this was creating bogus triangles before */
        refs = 0;
-       for( i = 0; i < ds->numIndexes; i += 3 )
+       for ( i = 0; i < ds->numIndexes; i += 3 )
        {
                /* error check */
-               if( ds->indexes[ i ] >= ds->numVerts ||
+               if ( ds->indexes[ i ] >= ds->numVerts ||
 -                       ds->indexes[ i + 1 ] >= ds->numVerts ||
 +                      ds->indexes[ i + 1 ] >= ds->numVerts ||
-                       ds->indexes[ i + 2 ] >= ds->numVerts )
+                        ds->indexes[ i + 2 ] >= ds->numVerts ) {
                        Error( "Index %d greater than vertex count %d", ds->indexes[ i ], ds->numVerts );
 -
+               }
 +              
                /* make a triangle winding and filter it into the tree */
                w = AllocWinding( 3 );
                w->numpoints = 3;
                VectorCopy( ds->verts[ ds->indexes[ i + 2 ] ].xyz, w->p[ 2 ] );
                refs += FilterWindingIntoTree_r( w, ds, tree->headnode );
        }
 -
 +      
        /* use point filtering as well */
-       for( i = 0; i < ds->numVerts; i++ )
+       for ( i = 0; i < ds->numVerts; i++ )
                refs += FilterPointIntoTree_r( ds->verts[ i ].xyz, ds, tree->headnode );
  
        return refs;
  
  
  /*
- FilterFoliageIntoTree()
- filters a foliage surface (wolf et/splash damage)
- */
   FilterFoliageIntoTree()
   filters a foliage surface (wolf et/splash damage)
 */
  
- static int FilterFoliageIntoTree( mapDrawSurface_t *ds, tree_t *tree )
- {
+ static int FilterFoliageIntoTree( mapDrawSurface_t *ds, tree_t *tree ){
 -      int f, i, refs;
 -      bspDrawVert_t   *instance;
 -      vec3_t xyz;
 -      winding_t       *w;
 -
 -
 +      int                             f, i, refs;
 +      bspDrawVert_t   *instance;
 +      vec3_t                  xyz;
 +      winding_t               *w;
 +      
 +      
        /* walk origin list */
        refs = 0;
-       for( f = 0; f < ds->numFoliageInstances; f++ )
+       for ( f = 0; f < ds->numFoliageInstances; f++ )
        {
                /* get instance */
                instance = ds->verts + ds->patchHeight + f;
 -
 +              
                /* walk triangle list */
-               for( i = 0; i < ds->numIndexes; i += 3 )
+               for ( i = 0; i < ds->numIndexes; i += 3 )
                {
                        /* error check */
-                       if( ds->indexes[ i ] >= ds->numVerts ||
+                       if ( ds->indexes[ i ] >= ds->numVerts ||
 -                               ds->indexes[ i + 1 ] >= ds->numVerts ||
 +                              ds->indexes[ i + 1 ] >= ds->numVerts ||
-                               ds->indexes[ i + 2 ] >= ds->numVerts )
+                                ds->indexes[ i + 2 ] >= ds->numVerts ) {
                                Error( "Index %d greater than vertex count %d", ds->indexes[ i ], ds->numVerts );
 -
+                       }
 +                      
                        /* make a triangle winding and filter it into the tree */
                        w = AllocWinding( 3 );
                        w->numpoints = 3;
                        VectorAdd( instance->xyz, ds->verts[ ds->indexes[ i + 2 ] ].xyz, w->p[ 2 ] );
                        refs += FilterWindingIntoTree_r( w, ds, tree->headnode );
                }
 -
 +              
                /* use point filtering as well */
-               for( i = 0; i < (ds->numVerts - ds->numFoliageInstances); i++ )
+               for ( i = 0; i < ( ds->numVerts - ds->numFoliageInstances ); i++ )
                {
                        VectorAdd( instance->xyz, ds->verts[ i ].xyz, xyz );
                        refs += FilterPointIntoTree_r( xyz, ds, tree->headnode );
@@@ -2274,18 -2377,17 +2379,17 @@@ static int FilterFlareSurfIntoTree( map
  
  
  /*
- EmitDrawVerts() - ydnar
- emits bsp drawverts from a map drawsurface
- */
   EmitDrawVerts() - ydnar
   emits bsp drawverts from a map drawsurface
 */
  
- void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out )
- {
+ void EmitDrawVerts( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
 -      int i, k;
 -      bspDrawVert_t   *dv;
 -      shaderInfo_t    *si;
 -      float offset;
 -
 -
 +      int                             i, k;
 +      bspDrawVert_t   *dv;
 +      shaderInfo_t    *si;
 +      float                   offset;
 +      
 +      
        /* get stuff */
        si = ds->shaderInfo;
        offset = si->offset;
                /* allocate a new vert */
                IncDrawVerts();
                dv = &bspDrawVerts[ numBSPDrawVerts - 1 ];
 -
 +              
                /* copy it */
                memcpy( dv, &ds->verts[ i ], sizeof( *dv ) );
 -
 +              
                /* offset? */
-               if( offset != 0.0f )
+               if ( offset != 0.0f ) {
                        VectorMA( dv->xyz, offset, dv->normal, dv->xyz );
 -
+               }
 +              
                /* expand model bounds
                   necessary because of misc_model surfaces on entities
                   note: does not happen on worldspawn as its bounds is only used for determining lightgrid bounds */
-               if( numBSPModels > 0 )
+               if ( numBSPModels > 0 ) {
                        AddPointToBounds( dv->xyz, bspModels[ numBSPModels ].mins, bspModels[ numBSPModels ].maxs );
 -
+               }
 +              
                /* debug color? */
-               if( debugSurfaces )
-               {
-                       for( k = 0; k < MAX_LIGHTMAPS; k++ )
-                               VectorCopy( debugColors[ (ds - mapDrawSurfs) % 12 ], dv->color[ k ] );
+               if ( debugSurfaces ) {
+                       for ( k = 0; k < MAX_LIGHTMAPS; k++ )
+                               VectorCopy( debugColors[ ( ds - mapDrawSurfs ) % 12 ], dv->color[ k ] );
                }
        }
  }
  
  
  /*
- FindDrawIndexes() - ydnar
- this attempts to find a run of indexes in the bsp that match the given indexes
- this tends to reduce the size of the bsp index pool by 1/3 or more
- returns numIndexes + 1 if the search failed
- */
- int FindDrawIndexes( int numIndexes, int *indexes )
- {
+    FindDrawIndexes() - ydnar
+    this attempts to find a run of indexes in the bsp that match the given indexes
+    this tends to reduce the size of the bsp index pool by 1/3 or more
+    returns numIndexes + 1 if the search failed
+  */
+ int FindDrawIndexes( int numIndexes, int *indexes ){
 -      int i, j, numTestIndexes;
 -
 -
 +      int             i, j, numTestIndexes;
 +      
 +      
        /* dummy check */
-       if( numIndexes < 3 || numBSPDrawIndexes < numIndexes || indexes == NULL )
+       if ( numIndexes < 3 || numBSPDrawIndexes < numIndexes || indexes == NULL ) {
                return numBSPDrawIndexes;
 -
+       }
 +      
        /* set limit */
        numTestIndexes = 1 + numBSPDrawIndexes - numIndexes;
 -
 +      
        /* handle 3 indexes as a special case for performance */
-       if( numIndexes == 3 )
-       {
+       if ( numIndexes == 3 ) {
                /* run through all indexes */
-               for( i = 0; i < numTestIndexes; i++ )
+               for ( i = 0; i < numTestIndexes; i++ )
                {
                        /* test 3 indexes */
-                       if( indexes[ 0 ] == bspDrawIndexes[ i ] &&
+                       if ( indexes[ 0 ] == bspDrawIndexes[ i ] &&
 -                               indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
 +                              indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
-                               indexes[ 2 ] == bspDrawIndexes[ i + 2 ] )
-                       {
+                                indexes[ 2 ] == bspDrawIndexes[ i + 2 ] ) {
                                numRedundantIndexes += numIndexes;
                                return i;
                        }
                /* failed */
                return numBSPDrawIndexes;
        }
 -
 +      
        /* handle 4 or more indexes */
-       for( i = 0; i < numTestIndexes; i++ )
+       for ( i = 0; i < numTestIndexes; i++ )
        {
                /* test first 4 indexes */
-               if( indexes[ 0 ] == bspDrawIndexes[ i ] &&
+               if ( indexes[ 0 ] == bspDrawIndexes[ i ] &&
 -                       indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
 -                       indexes[ 2 ] == bspDrawIndexes[ i + 2 ] &&
 +                      indexes[ 1 ] == bspDrawIndexes[ i + 1 ] &&
 +                      indexes[ 2 ] == bspDrawIndexes[ i + 2 ] &&
-                       indexes[ 3 ] == bspDrawIndexes[ i + 3 ] )
-               {
+                        indexes[ 3 ] == bspDrawIndexes[ i + 3 ] ) {
                        /* handle 4 indexes */
-                       if( numIndexes == 4 )
+                       if ( numIndexes == 4 ) {
                                return i;
 -
+                       }
 +                      
                        /* test the remainder */
-                       for( j = 4; j < numIndexes; j++ )
+                       for ( j = 4; j < numIndexes; j++ )
                        {
-                               if( indexes[ j ] != bspDrawIndexes[ i + j ] )
+                               if ( indexes[ j ] != bspDrawIndexes[ i + j ] ) {
                                        break;
-                               else if( j == (numIndexes - 1) )
-                               {
+                               }
+                               else if ( j == ( numIndexes - 1 ) ) {
                                        numRedundantIndexes += numIndexes;
                                        return i;
                                }
  
  
  /*
- EmitDrawIndexes() - ydnar
- attempts to find an existing run of drawindexes before adding new ones
- */
   EmitDrawIndexes() - ydnar
   attempts to find an existing run of drawindexes before adding new ones
 */
  
- void EmitDrawIndexes( mapDrawSurface_t *ds, bspDrawSurface_t *out )
- {
+ void EmitDrawIndexes( mapDrawSurface_t *ds, bspDrawSurface_t *out ){
 -      int i;
 -
 -
 +      int                     i;
 +      
 +      
        /* attempt to use redundant indexing */
        out->firstIndex = FindDrawIndexes( ds->numIndexes, ds->indexes );
        out->numIndexes = ds->numIndexes;
                        bspDrawIndexes[ numBSPDrawIndexes ] = ds->indexes[ i ];
  
                        /* validate the index */
-                       if( ds->type != SURFACE_PATCH )
-                       {
-                               if( bspDrawIndexes[ numBSPDrawIndexes ] < 0 || bspDrawIndexes[ numBSPDrawIndexes ] >= ds->numVerts )
-                               {
+                       if ( ds->type != SURFACE_PATCH ) {
+                               if ( bspDrawIndexes[ numBSPDrawIndexes ] < 0 || bspDrawIndexes[ numBSPDrawIndexes ] >= ds->numVerts ) {
                                        Sys_Printf( "WARNING: %d %s has invalid index %d (%d)\n",
 -                                                              numBSPDrawSurfaces,
 -                                                              ds->shaderInfo->shader,
 -                                                              bspDrawIndexes[ numBSPDrawIndexes ],
 -                                                              i );
 +                                              numBSPDrawSurfaces,
 +                                              ds->shaderInfo->shader,
 +                                              bspDrawIndexes[ numBSPDrawIndexes ],
 +                                              i );
                                        bspDrawIndexes[ numBSPDrawIndexes ] = 0;
                                }
                        }
  
  
  /*
- EmitFlareSurface()
- emits a bsp flare drawsurface
- */
   EmitFlareSurface()
   emits a bsp flare drawsurface
 */
  
- void EmitFlareSurface( mapDrawSurface_t *ds )
- {
+ void EmitFlareSurface( mapDrawSurface_t *ds ){
 -      int i;
 -      bspDrawSurface_t        *out;
 -
 -
 +      int                                             i;
 +      bspDrawSurface_t                *out;
 +      
 +      
        /* ydnar: nuking useless flare drawsurfaces */
-       if( emitFlares == qfalse && ds->type != SURFACE_SHADER )
+       if ( emitFlares == qfalse && ds->type != SURFACE_SHADER ) {
                return;
 -
+       }
 +      
        /* limit check */
-       if( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS )
+       if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS" );
 -
+       }
 +      
        /* allocate a new surface */
-       if( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS )
+       if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS" );
+       }
        out = &bspDrawSurfaces[ numBSPDrawSurfaces ];
        ds->outputNum = numBSPDrawSurfaces;
        numBSPDrawSurfaces++;
        out->surfaceType = MST_FLARE;
        out->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
        out->fogNum = ds->fogNum;
 -
 +      
        /* RBSP */
-       for( i = 0; i < MAX_LIGHTMAPS; i++ )
+       for ( i = 0; i < MAX_LIGHTMAPS; i++ )
        {
                out->lightmapNum[ i ] = -3;
                out->lightmapStyles[ i ] = LS_NONE;
  }
  
  /*
- EmitPatchSurface()
- emits a bsp patch drawsurface
- */
   EmitPatchSurface()
   emits a bsp patch drawsurface
 */
  
- void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds )
- {
+ void EmitPatchSurface( entity_t *e, mapDrawSurface_t *ds ){
 -      int i, j;
 -      bspDrawSurface_t    *out;
 -      int surfaceFlags, contentFlags;
 -      int forcePatchMeta;
 +      int                                     i, j;
 +      bspDrawSurface_t        *out;
 +      int                                     surfaceFlags, contentFlags;
 +      int                                     forcePatchMeta;
  
        /* vortex: _patchMeta support */
-       forcePatchMeta = IntForKey(e, "_patchMeta" );
-       if (!forcePatchMeta)
-               forcePatchMeta = IntForKey(e, "patchMeta" );
+       forcePatchMeta = IntForKey( e, "_patchMeta" );
+       if ( !forcePatchMeta ) {
+               forcePatchMeta = IntForKey( e, "patchMeta" );
+       }
 -
 +      
        /* invert the surface if necessary */
-       if( ds->backSide || ds->shaderInfo->invert )
-       {
+       if ( ds->backSide || ds->shaderInfo->invert ) {
 -              bspDrawVert_t   *dv1, *dv2, temp;
 +              bspDrawVert_t   *dv1, *dv2, temp;
  
                /* walk the verts, flip the normal */
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                        VectorScale( ds->verts[ i ].normal, -1.0f, ds->verts[ i ].normal );
 -
 +              
                /* walk the verts again, but this time reverse their order */
-               for( j = 0; j < ds->patchHeight; j++ )
+               for ( j = 0; j < ds->patchHeight; j++ )
                {
-                       for( i = 0; i < (ds->patchWidth / 2); i++ )
+                       for ( i = 0; i < ( ds->patchWidth / 2 ); i++ )
                        {
                                dv1 = &ds->verts[ j * ds->patchWidth + i ];
-                               dv2 = &ds->verts[ j * ds->patchWidth + (ds->patchWidth - i - 1) ];
+                               dv2 = &ds->verts[ j * ds->patchWidth + ( ds->patchWidth - i - 1 ) ];
                                memcpy( &temp, dv1, sizeof( bspDrawVert_t ) );
                                memcpy( dv1, dv2, sizeof( bspDrawVert_t ) );
                                memcpy( dv2, &temp, sizeof( bspDrawVert_t ) );
        out->patchWidth = ds->patchWidth;
        out->patchHeight = ds->patchHeight;
        out->fogNum = ds->fogNum;
 -
 +      
        /* RBSP */
-       for( i = 0; i < MAX_LIGHTMAPS; i++ )
+       for ( i = 0; i < MAX_LIGHTMAPS; i++ )
        {
                out->lightmapNum[ i ] = -3;
                out->lightmapStyles[ i ] = LS_NONE;
        VectorCopy( ds->bounds[ 0 ], out->lightmapVecs[ 0 ] );
        VectorCopy( ds->bounds[ 1 ], out->lightmapVecs[ 1 ] );
        VectorCopy( ds->lightmapVecs[ 2 ], out->lightmapVecs[ 2 ] );
 -
 +      
        /* ydnar: gs mods: clear out the plane normal */
-       if( ds->planar == qfalse )
+       if ( ds->planar == qfalse ) {
                VectorClear( out->lightmapVecs[ 2 ] );
 -
+       }
 +      
        /* emit the verts and indexes */
        EmitDrawVerts( ds, out );
        EmitDrawIndexes( ds, out );
  }
  
  /*
- OptimizeTriangleSurface() - ydnar
- optimizes the vertex/index data in a triangle surface
- */
   OptimizeTriangleSurface() - ydnar
   optimizes the vertex/index data in a triangle surface
 */
  
 -#define VERTEX_CACHE_SIZE   16
 +#define VERTEX_CACHE_SIZE     16
  
- static void OptimizeTriangleSurface( mapDrawSurface_t *ds )
- {
+ static void OptimizeTriangleSurface( mapDrawSurface_t *ds ){
 -      int i, j, k, temp, first, best, bestScore, score;
 -      int vertexCache[ VERTEX_CACHE_SIZE + 1 ];       /* one more for optimizing insert */
 -      int     *indexes;
 -
 -
 +      int             i, j, k, temp, first, best, bestScore, score;
 +      int             vertexCache[ VERTEX_CACHE_SIZE + 1 ];   /* one more for optimizing insert */
 +      int             *indexes;
 +      
 +      
        /* certain surfaces don't get optimized */
-       if( ds->numIndexes <= VERTEX_CACHE_SIZE ||
-               ds->shaderInfo->autosprite )
+       if ( ds->numIndexes <= VERTEX_CACHE_SIZE ||
+                ds->shaderInfo->autosprite ) {
                return;
 -
+       }
 +      
        /* create index scratch pad */
        indexes = safe_malloc( ds->numIndexes * sizeof( *indexes ) );
        memcpy( indexes, ds->indexes, ds->numIndexes * sizeof( *indexes ) );
 -
 +      
        /* setup */
-       for( i = 0; i <= VERTEX_CACHE_SIZE && i < ds->numIndexes; i++ )
+       for ( i = 0; i <= VERTEX_CACHE_SIZE && i < ds->numIndexes; i++ )
                vertexCache[ i ] = indexes[ i ];
 -
 +      
        /* add triangles in a vertex cache-aware order */
-       for( i = 0; i < ds->numIndexes; i += 3 )
+       for ( i = 0; i < ds->numIndexes; i += 3 )
        {
                /* find best triangle given the current vertex cache */
                first = -1;
                best = -1;
                bestScore = -1;
-               for( j = 0; j < ds->numIndexes; j += 3 )
+               for ( j = 0; j < ds->numIndexes; j += 3 )
                {
                        /* valid triangle? */
-                       if( indexes[ j ] != -1 )
-                       {
+                       if ( indexes[ j ] != -1 ) {
                                /* set first if necessary */
-                               if( first < 0 )
+                               if ( first < 0 ) {
                                        first = j;
 -
+                               }
 +                              
                                /* score the triangle */
                                score = 0;
-                               for( k = 0; k < VERTEX_CACHE_SIZE; k++ )
+                               for ( k = 0; k < VERTEX_CACHE_SIZE; k++ )
                                {
-                                       if( indexes[ j ] == vertexCache[ k ] || indexes[ j + 1 ] == vertexCache[ k ] || indexes[ j + 2 ] == vertexCache[ k ] )
+                                       if ( indexes[ j ] == vertexCache[ k ] || indexes[ j + 1 ] == vertexCache[ k ] || indexes[ j + 2 ] == vertexCache[ k ] ) {
                                                score++;
 -                                      }
                                }
 -
++                              }
 +                              
                                /* better triangle? */
-                               if( score > bestScore )
-                               {
+                               if ( score > bestScore ) {
                                        bestScore = score;
                                        best = j;
                                }
 -
 +                              
                                /* a perfect score of 3 means this triangle's verts are already present in the vertex cache */
-                               if( score == 3 )
+                               if ( score == 3 ) {
                                        break;
 -                              }
                        }
                }
 -
++              }
 +              
                /* check if no decent triangle was found, and use first available */
-               if( best < 0 )
+               if ( best < 0 ) {
                        best = first;
 -
+               }
 +              
                /* valid triangle? */
-               if( best >= 0 )
-               {
+               if ( best >= 0 ) {
                        /* add triangle to vertex cache */
-                       for( j = 0; j < 3; j++ )
+                       for ( j = 0; j < 3; j++ )
                        {
-                               for( k = 0; k < VERTEX_CACHE_SIZE; k++ )
+                               for ( k = 0; k < VERTEX_CACHE_SIZE; k++ )
                                {
-                                       if( indexes[ best + j ] == vertexCache[ k ] )
+                                       if ( indexes[ best + j ] == vertexCache[ k ] ) {
                                                break;
 -                                      }
                                }
 -
++                              }
 +                              
-                               if( k >= VERTEX_CACHE_SIZE )
-                               {
+                               if ( k >= VERTEX_CACHE_SIZE ) {
                                        /* pop off top of vertex cache */
-                                       for( k = VERTEX_CACHE_SIZE; k > 0; k-- )
+                                       for ( k = VERTEX_CACHE_SIZE; k > 0; k-- )
                                                vertexCache[ k ] = vertexCache[ k - 1 ];
 -
 +                                      
                                        /* add vertex */
                                        vertexCache[ 0 ] = indexes[ best + j ];
                                }
                        indexes[ best ] = -1;
                        indexes[ best + 1 ] = -1;
                        indexes[ best + 2 ] = -1;
 -
 +                      
                        /* sort triangle windings (312 -> 123) */
-                       while( ds->indexes[ i ] > ds->indexes[ i + 1 ] || ds->indexes[ i ] > ds->indexes[ i + 2 ] )
+                       while ( ds->indexes[ i ] > ds->indexes[ i + 1 ] || ds->indexes[ i ] > ds->indexes[ i + 2 ] )
                        {
                                temp = ds->indexes[ i ];
                                ds->indexes[ i ] = ds->indexes[ i + 1 ];
  
  
  /*
- EmitTriangleSurface()
- creates a bsp drawsurface from arbitrary triangle surfaces
- */
   EmitTriangleSurface()
   creates a bsp drawsurface from arbitrary triangle surfaces
 */
  
- void EmitTriangleSurface( mapDrawSurface_t *ds )
- {
+ void EmitTriangleSurface( mapDrawSurface_t *ds ){
 -      int i, temp;
 -      bspDrawSurface_t        *out;
 +      int                                             i, temp;
 +      bspDrawSurface_t                *out;
  
        /* invert the surface if necessary */
-       if( ds->backSide || ds->shaderInfo->invert )
-       {
+       if ( ds->backSide || ds->shaderInfo->invert ) {
                /* walk the indexes, reverse the triangle order */
-               for( i = 0; i < ds->numIndexes; i += 3 )
+               for ( i = 0; i < ds->numIndexes; i += 3 )
                {
                        temp = ds->indexes[ i ];
                        ds->indexes[ i ] = ds->indexes[ i + 1 ];
                        ds->indexes[ i + 1 ] = temp;
                }
 -
 +                      
                /* walk the verts, flip the normal */
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                        VectorScale( ds->verts[ i ].normal, -1.0f, ds->verts[ i ].normal );
 -
 +                      
                /* invert facing */
                VectorScale( ds->lightmapVecs[ 2 ], -1.0f, ds->lightmapVecs[ 2 ] );
        }
 -
 +              
        /* allocate a new surface */
-       if( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS )
+       if ( numBSPDrawSurfaces == MAX_MAP_DRAW_SURFS ) {
                Error( "MAX_MAP_DRAW_SURFS" );
+       }
        out = &bspDrawSurfaces[ numBSPDrawSurfaces ];
        ds->outputNum = numBSPDrawSurfaces;
        numBSPDrawSurfaces++;
        memset( out, 0, sizeof( *out ) );
 -
 +      
        /* ydnar/sd: handle wolf et foliage surfaces */
-       if( ds->type == SURFACE_FOLIAGE )
+       if ( ds->type == SURFACE_FOLIAGE ) {
                out->surfaceType = MST_FOLIAGE;
 -
+       }
 +      
        /* ydnar: gs mods: handle lightmapped terrain (force to planar type) */
        //%     else if( VectorLength( ds->lightmapAxis ) <= 0.0f || ds->type == SURFACE_TRIANGLES || ds->type == SURFACE_FOGHULL || debugSurfaces )
-       else if( (VectorLength( ds->lightmapAxis ) <= 0.0f && ds->planar == qfalse) ||
+       else if ( ( VectorLength( ds->lightmapAxis ) <= 0.0f && ds->planar == qfalse ) ||
 -                        ds->type == SURFACE_TRIANGLES ||
 -                        ds->type == SURFACE_FOGHULL ||
 -                        ds->numVerts > maxLMSurfaceVerts ||
 +              ds->type == SURFACE_TRIANGLES ||
 +              ds->type == SURFACE_FOGHULL ||
 +              ds->numVerts > maxLMSurfaceVerts ||
-               debugSurfaces )
+                         debugSurfaces ) {
                out->surfaceType = MST_TRIANGLE_SOUP;
 -
+       }
 +      
        /* set to a planar face */
-       else
+       else{
                out->surfaceType = MST_PLANAR;
 -
+       }
 +      
        /* set it up */
-       if( debugSurfaces )
+       if ( debugSurfaces ) {
                out->shaderNum = EmitShader( "debugsurfaces", NULL, NULL );
-       else
+       }
+       else{
                out->shaderNum = EmitShader( ds->shaderInfo->shader, &ds->shaderInfo->contentFlags, &ds->shaderInfo->surfaceFlags );
+       }
        out->patchWidth = ds->patchWidth;
        out->patchHeight = ds->patchHeight;
        out->fogNum = ds->fogNum;
 -
 +      
        /* debug inset (push each triangle vertex towards the center of each triangle it is on */
-       if( debugInset )
-       {
+       if ( debugInset ) {
 -              bspDrawVert_t   *a, *b, *c;
 -              vec3_t cent, dir;
 -
 +              bspDrawVert_t   *a, *b, *c;
 +              vec3_t                  cent, dir;
  
 +              
                /* walk triangle list */
-               for( i = 0; i < ds->numIndexes; i += 3 )
+               for ( i = 0; i < ds->numIndexes; i += 3 )
                {
                        /* get verts */
                        a = &ds->verts[ ds->indexes[ i ] ];
                        VectorAdd( c->xyz, dir, c->xyz );
                }
        }
 -
 +      
        /* RBSP */
-       for( i = 0; i < MAX_LIGHTMAPS; i++ )
+       for ( i = 0; i < MAX_LIGHTMAPS; i++ )
        {
                out->lightmapNum[ i ] = -3;
                out->lightmapStyles[ i ] = LS_NONE;
        VectorCopy( ds->lightmapVecs[ 0 ], out->lightmapVecs[ 0 ] );
        VectorCopy( ds->lightmapVecs[ 1 ], out->lightmapVecs[ 1 ] );
        VectorCopy( ds->lightmapVecs[ 2 ], out->lightmapVecs[ 2 ] );
 -
 +      
        /* ydnar: gs mods: clear out the plane normal */
-       if( ds->planar == qfalse )
+       if ( ds->planar == qfalse ) {
                VectorClear( out->lightmapVecs[ 2 ] );
 -
+       }
 +      
        /* optimize the surface's triangles */
        OptimizeTriangleSurface( ds );
 -
 +      
        /* emit the verts and indexes */
        EmitDrawVerts( ds, out );
        EmitDrawIndexes( ds, out );
@@@ -2861,49 -2967,49 +2969,49 @@@ static void EmitFaceSurface( mapDrawSur
  
  
  /*
- MakeDebugPortalSurfs_r() - ydnar
- generates drawsurfaces for passable portals in the bsp
- */
   MakeDebugPortalSurfs_r() - ydnar
   generates drawsurfaces for passable portals in the bsp
 */
  
- static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si )
- {
+ static void MakeDebugPortalSurfs_r( node_t *node, shaderInfo_t *si ){
 -      int i, k, c, s;
 -      portal_t            *p;
 -      winding_t           *w;
 -      mapDrawSurface_t    *ds;
 -      bspDrawVert_t       *dv;
 -
 -
 +      int                                     i, k, c, s;     
 +      portal_t                        *p;
 +      winding_t                       *w;
 +      mapDrawSurface_t        *ds;
 +      bspDrawVert_t           *dv;
 +      
 +      
        /* recurse if decision node */
-       if( node->planenum != PLANENUM_LEAF)
-       {
+       if ( node->planenum != PLANENUM_LEAF ) {
                MakeDebugPortalSurfs_r( node->children[ 0 ], si );
                MakeDebugPortalSurfs_r( node->children[ 1 ], si );
                return;
        }
 -
 +      
        /* don't bother with opaque leaves */
-       if( node->opaque )
+       if ( node->opaque ) {
                return;
 -
+       }
 +      
        /* walk the list of portals */
-       for( c = 0, p = node->portals; p != NULL; c++, p = p->next[ s ] )
+       for ( c = 0, p = node->portals; p != NULL; c++, p = p->next[ s ] )
        {
                /* get winding and side even/odd */
                w = p->winding;
-               s = (p->nodes[ 1 ] == node);
+               s = ( p->nodes[ 1 ] == node );
 -
 +              
                /* is this a valid portal for this leaf? */
-               if( w && p->nodes[ 0 ] == node )
-               {
+               if ( w && p->nodes[ 0 ] == node ) {
                        /* is this portal passable? */
-                       if( PortalPassable( p ) == qfalse )
+                       if ( PortalPassable( p ) == qfalse ) {
                                continue;
 -
+                       }
 +                      
                        /* check max points */
-                       if( w->numpoints > 64 )
+                       if ( w->numpoints > 64 ) {
                                Error( "MakePortalSurfs_r: w->numpoints = %d", w->numpoints );
 -
+                       }
 +                      
                        /* allocate a drawsurface */
                        ds = AllocDrawSurface( SURFACE_FACE );
                        ds->shaderInfo = si;
                        ds->numVerts = w->numpoints;
                        ds->verts = safe_malloc( ds->numVerts * sizeof( *ds->verts ) );
                        memset( ds->verts, 0, ds->numVerts * sizeof( *ds->verts ) );
 -
 +                      
                        /* walk the winding */
-                       for( i = 0; i < ds->numVerts; i++ )
+                       for ( i = 0; i < ds->numVerts; i++ )
                        {
                                /* get vert */
                                dv = ds->verts + i;
  
  
  /*
- MakeDebugPortalSurfs() - ydnar
- generates drawsurfaces for passable portals in the bsp
- */
   MakeDebugPortalSurfs() - ydnar
   generates drawsurfaces for passable portals in the bsp
 */
  
- void MakeDebugPortalSurfs( tree_t *tree )
- {
+ void MakeDebugPortalSurfs( tree_t *tree ){
 -      shaderInfo_t    *si;
 -
 -
 +      shaderInfo_t    *si;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- MakeDebugPortalSurfs ---\n" );
 -
 +      
        /* get portal debug shader */
        si = ShaderInfoForShader( "debugportals" );
 -
 +      
        /* walk the tree */
        MakeDebugPortalSurfs_r( tree->headnode, si );
  }
  
  
  /*
- MakeFogHullSurfs()
- generates drawsurfaces for a foghull (this MUST use a sky shader)
- */
   MakeFogHullSurfs()
   generates drawsurfaces for a foghull (this MUST use a sky shader)
 */
  
- void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader )
- {
+ void MakeFogHullSurfs( entity_t *e, tree_t *tree, char *shader ){
 -      shaderInfo_t        *si;
 -      mapDrawSurface_t    *ds;
 -      vec3_t fogMins, fogMaxs;
 -      int i, indexes[] =
 -      {
 -              0, 1, 2, 0, 2, 3,
 -              4, 7, 5, 5, 7, 6,
 -              1, 5, 6, 1, 6, 2,
 -              0, 4, 5, 0, 5, 1,
 -              2, 6, 7, 2, 7, 3,
 -              3, 7, 4, 3, 4, 0
 -      };
 -
 -
 +      shaderInfo_t            *si;
 +      mapDrawSurface_t        *ds;
 +      vec3_t                          fogMins, fogMaxs;
 +      int                                     i, indexes[] =
 +                                              {
 +                                                      0, 1, 2, 0, 2, 3,
 +                                                      4, 7, 5, 5, 7, 6,
 +                                                      1, 5, 6, 1, 6, 2,
 +                                                      0, 4, 5, 0, 5, 1,
 +                                                      2, 6, 7, 2, 7, 3,
 +                                                      3, 7, 4, 3, 4, 0
 +                                              };
 +
 +      
        /* dummy check */
-       if( shader == NULL || shader[ 0 ] == '\0' )
+       if ( shader == NULL || shader[ 0 ] == '\0' ) {
                return;
 -
+       }
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- MakeFogHullSurfs ---\n" );
 -
 +      
        /* get hull bounds */
        VectorCopy( mapMins, fogMins );
        VectorCopy( mapMaxs, fogMaxs );
  
  
  /*
- BiasSurfaceTextures()
- biases a surface's texcoords as close to 0 as possible
- */
   BiasSurfaceTextures()
   biases a surface's texcoords as close to 0 as possible
 */
  
- void BiasSurfaceTextures( mapDrawSurface_t *ds )
- {
+ void BiasSurfaceTextures( mapDrawSurface_t *ds ){
 -      int i;
 -
 -
 +      int             i;
 +      
 +      
        /* calculate the surface texture bias */
        CalcSurfaceTextureRange( ds );
 -
 +      
        /* don't bias globaltextured shaders */
-       if( ds->shaderInfo->globalTexture )
+       if ( ds->shaderInfo->globalTexture ) {
                return;
 -
+       }
 +      
        /* bias the texture coordinates */
-       for( i = 0; i < ds->numVerts; i++ )
+       for ( i = 0; i < ds->numVerts; i++ )
        {
                ds->verts[ i ].st[ 0 ] += ds->bias[ 0 ];
                ds->verts[ i ].st[ 1 ] += ds->bias[ 1 ];
  
  
  /*
- AddSurfaceModelsToTriangle_r()
- adds models to a specified triangle, returns the number of models added
- */
   AddSurfaceModelsToTriangle_r()
   adds models to a specified triangle, returns the number of models added
 */
  
- int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, bspDrawVert_t **tri )
- {
+ int AddSurfaceModelsToTriangle_r( mapDrawSurface_t *ds, surfaceModel_t *model, bspDrawVert_t **tri ){
 -      bspDrawVert_t mid, *tri2[ 3 ];
 -      int max, n, localNumSurfaceModels;
 -
 -
 +      bspDrawVert_t   mid, *tri2[ 3 ];
 +      int                             max, n, localNumSurfaceModels;
 +      
 +      
        /* init */
        localNumSurfaceModels = 0;
 -
 +      
        /* subdivide calc */
        {
 -              int i;
 -              float       *a, *b, dx, dy, dz, dist, maxDist;
 -
 -
 +              int                     i;
 +              float           *a, *b, dx, dy, dz, dist, maxDist;
 +              
 +              
                /* find the longest edge and split it */
                max = -1;
                maxDist = 0.0f;
                {
                        /* get verts */
                        a = tri[ i ]->xyz;
-                       b = tri[ (i + 1) % 3 ]->xyz;
+                       b = tri[ ( i + 1 ) % 3 ]->xyz;
 -
 +                      
                        /* get dists */
                        dx = a[ 0 ] - b[ 0 ];
                        dy = a[ 1 ] - b[ 1 ];
                        dz = a[ 2 ] - b[ 2 ];
-                       dist = (dx * dx) + (dy * dy) + (dz * dz);
+                       dist = ( dx * dx ) + ( dy * dy ) + ( dz * dz );
 -
 +                      
                        /* longer? */
-                       if( dist > maxDist )
-                       {
+                       if ( dist > maxDist ) {
                                maxDist = dist;
                                max = i;
                        }
                }
 -
 +              
                /* is the triangle small enough? */
-               if( max < 0 || maxDist <= (model->density * model->density) )
-               {
+               if ( max < 0 || maxDist <= ( model->density * model->density ) ) {
 -                      float odds, r, angle;
 -                      vec3_t origin, normal, scale, axis[ 3 ], angles;
 -                      m4x4_t transform, temp;
 -
 +                      float   odds, r, angle;
 +                      vec3_t  origin, normal, scale, axis[ 3 ], angles;
 +                      m4x4_t  transform, temp;
  
 +                      
                        /* roll the dice (model's odds scaled by vertex alpha) */
-                       odds = model->odds * (tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ]) / 765.0f;
+                       odds = model->odds * ( tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] + tri[ 0 ]->color[ 0 ][ 3 ] ) / 765.0f;
                        r = Random();
-                       if( r > odds )
+                       if ( r > odds ) {
                                return 0;
 -
+                       }
 +                      
                        /* calculate scale */
-                       r = model->minScale + Random() * (model->maxScale - model->minScale);
+                       r = model->minScale + Random() * ( model->maxScale - model->minScale );
                        VectorSet( scale, r, r, r );
 -
 +                      
                        /* calculate angle */
-                       angle = model->minAngle + Random() * (model->maxAngle - model->minAngle);
+                       angle = model->minAngle + Random() * ( model->maxAngle - model->minAngle );
 -
 +                      
                        /* calculate average origin */
                        VectorCopy( tri[ 0 ]->xyz, origin );
                        VectorAdd( origin, tri[ 1 ]->xyz, origin );
                        VectorAdd( origin, tri[ 2 ]->xyz, origin );
-                       VectorScale( origin, (1.0f / 3.0f), origin );
+                       VectorScale( origin, ( 1.0f / 3.0f ), origin );
 -
 +                      
                        /* clear transform matrix */
                        m4x4_identity( transform );
  
                        /* handle oriented models */
-                       if( model->oriented )
-                       {
+                       if ( model->oriented ) {
                                /* set angles */
                                VectorSet( angles, 0.0f, 0.0f, angle );
 -
 +                              
                                /* calculate average normal */
                                VectorCopy( tri[ 0 ]->normal, normal );
                                VectorAdd( normal, tri[ 1 ]->normal, normal );
                                VectorAdd( normal, tri[ 2 ]->normal, normal );
-                               if( VectorNormalize( normal, axis[ 2 ] ) == 0.0f )
+                               if ( VectorNormalize( normal, axis[ 2 ] ) == 0.0f ) {
                                        VectorCopy( tri[ 0 ]->normal, axis[ 2 ] );
 -
+                               }
 +                              
                                /* make perpendicular vectors */
                                MakeNormalVectors( axis[ 2 ], axis[ 1 ], axis[ 0 ] );
 -
 +                              
                                /* copy to matrix */
                                m4x4_identity( temp );
 -                              temp[ 0 ] = axis[ 0 ][ 0 ]; temp[ 1 ] = axis[ 0 ][ 1 ]; temp[ 2 ] = axis[ 0 ][ 2 ];
 -                              temp[ 4 ] = axis[ 1 ][ 0 ]; temp[ 5 ] = axis[ 1 ][ 1 ]; temp[ 6 ] = axis[ 1 ][ 2 ];
 -                              temp[ 8 ] = axis[ 2 ][ 0 ]; temp[ 9 ] = axis[ 2 ][ 1 ]; temp[ 10 ] = axis[ 2 ][ 2 ];
 -
 +                              temp[ 0 ] = axis[ 0 ][ 0 ];     temp[ 1 ] = axis[ 0 ][ 1 ];     temp[ 2 ] = axis[ 0 ][ 2 ];
 +                              temp[ 4 ] = axis[ 1 ][ 0 ];     temp[ 5 ] = axis[ 1 ][ 1 ];     temp[ 6 ] = axis[ 1 ][ 2 ];
 +                              temp[ 8 ] = axis[ 2 ][ 0 ];     temp[ 9 ] = axis[ 2 ][ 1 ];     temp[ 10 ] = axis[ 2 ][ 2 ];
 +                              
                                /* scale */
                                m4x4_scale_by_vec3( temp, scale );
 -
 +                              
                                /* rotate around z axis */
                                m4x4_rotate_by_vec3( temp, angles, eXYZ );
 -
 +                              
                                /* translate */
                                m4x4_translate_by_vec3( transform, origin );
 -
 +                              
                                /* tranform into axis space */
                                m4x4_multiply_by_m4x4( transform, temp );
                        }
                        return 1;
                }
        }
 -
 +      
        /* split the longest edge and map it */
-       LerpDrawVert( tri[ max ], tri[ (max + 1) % 3 ], &mid );
+       LerpDrawVert( tri[ max ], tri[ ( max + 1 ) % 3 ], &mid );
 -
 +      
        /* recurse to first triangle */
        VectorCopy( tri, tri2 );
        tri2[ max ] = &mid;
        n = AddSurfaceModelsToTriangle_r( ds, model, tri2 );
-       if( n < 0 )
+       if ( n < 0 ) {
                return n;
+       }
        localNumSurfaceModels += n;
 -
 +      
        /* recurse to second triangle */
        VectorCopy( tri, tri2 );
-       tri2[ (max + 1) % 3 ] = &mid;
+       tri2[ ( max + 1 ) % 3 ] = &mid;
        n = AddSurfaceModelsToTriangle_r( ds, model, tri2 );
-       if( n < 0 )
+       if ( n < 0 ) {
                return n;
+       }
        localNumSurfaceModels += n;
 -
 +      
        /* return count */
        return localNumSurfaceModels;
  }
  
  
  /*
- AddSurfaceModels()
- adds a surface's shader models to the surface
- */
   AddSurfaceModels()
   adds a surface's shader models to the surface
 */
  
- int AddSurfaceModels( mapDrawSurface_t *ds )
- {
+ int AddSurfaceModels( mapDrawSurface_t *ds ){
 -      surfaceModel_t  *model;
 -      int i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
 -      mesh_t src, *mesh, *subdivided;
 -      bspDrawVert_t centroid, *tri[ 3 ];
 -      float alpha;
 -
 -
 +      surfaceModel_t  *model;
 +      int                             i, x, y, n, pw[ 5 ], r, localNumSurfaceModels, iterations;
 +      mesh_t                  src, *mesh, *subdivided;
 +      bspDrawVert_t   centroid, *tri[ 3 ];
 +      float                   alpha;
 +      
 +      
        /* dummy check */
-       if( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModel == NULL )
+       if ( ds == NULL || ds->shaderInfo == NULL || ds->shaderInfo->surfaceModel == NULL ) {
                return 0;
 -
+       }
 +      
        /* init */
        localNumSurfaceModels = 0;
 -
 +      
        /* walk the model list */
-       for( model = ds->shaderInfo->surfaceModel; model != NULL; model = model->next )
+       for ( model = ds->shaderInfo->surfaceModel; model != NULL; model = model->next )
        {
                /* switch on type */
-               switch( ds->type )
+               switch ( ds->type )
                {
 -              /* handle brush faces and decals */
 -              case SURFACE_FACE:
 -              case SURFACE_DECAL:
 -                      /* calculate centroid */
 -                      memset( &centroid, 0, sizeof( centroid ) );
 -                      alpha = 0.0f;
 -
 -                      /* walk verts */
 +                      /* handle brush faces and decals */
 +                      case SURFACE_FACE:
 +                      case SURFACE_DECAL:
 +                              /* calculate centroid */
 +                              memset( &centroid, 0, sizeof( centroid ) );
 +                              alpha = 0.0f;
 +                              
 +                              /* walk verts */
-                               for( i = 0; i < ds->numVerts; i++ )
+                       for ( i = 0; i < ds->numVerts; i++ )
 -                      {
 -                              VectorAdd( centroid.xyz, ds->verts[ i ].xyz, centroid.xyz );
 -                              VectorAdd( centroid.normal, ds->verts[ i ].normal, centroid.normal );
 -                              centroid.st[ 0 ] += ds->verts[ i ].st[ 0 ];
 -                              centroid.st[ 1 ] += ds->verts[ i ].st[ 1 ];
 -                              alpha += ds->verts[ i ].color[ 0 ][ 3 ];
 -                      }
 -
 -                      /* average */
 -                      centroid.xyz[ 0 ] /= ds->numVerts;
 -                      centroid.xyz[ 1 ] /= ds->numVerts;
 -                      centroid.xyz[ 2 ] /= ds->numVerts;
 +                              {
 +                                      VectorAdd( centroid.xyz, ds->verts[ i ].xyz, centroid.xyz );
 +                                      VectorAdd( centroid.normal, ds->verts[ i ].normal, centroid.normal );
 +                                      centroid.st[ 0 ] += ds->verts[ i ].st[ 0 ];
 +                                      centroid.st[ 1 ] += ds->verts[ i ].st[ 1 ];
 +                                      alpha += ds->verts[ i ].color[ 0 ][ 3 ];
 +                              }
 +                              
 +                              /* average */
 +                              centroid.xyz[ 0 ] /= ds->numVerts;
 +                              centroid.xyz[ 1 ] /= ds->numVerts;
 +                              centroid.xyz[ 2 ] /= ds->numVerts;
-                               if( VectorNormalize( centroid.normal, centroid.normal ) == 0.0f )
+                       if ( VectorNormalize( centroid.normal, centroid.normal ) == 0.0f ) {
 -                              VectorCopy( ds->verts[ 0 ].normal, centroid.normal );
 -                      }
 -                      centroid.st[ 0 ]  /= ds->numVerts;
 -                      centroid.st[ 1 ]  /= ds->numVerts;
 -                      alpha /= ds->numVerts;
 -                      centroid.color[ 0 ][ 0 ] = 0xFF;
 -                      centroid.color[ 0 ][ 1 ] = 0xFF;
 -                      centroid.color[ 0 ][ 2 ] = 0xFF;
 +                                      VectorCopy( ds->verts[ 0 ].normal, centroid.normal );
++                      }
 +                              centroid.st[ 0 ]  /= ds->numVerts;
 +                              centroid.st[ 1 ]  /= ds->numVerts;
 +                              alpha /= ds->numVerts;
 +                              centroid.color[ 0 ][ 0 ] = 0xFF;
 +                              centroid.color[ 0 ][ 1 ] = 0xFF;
 +                              centroid.color[ 0 ][ 2 ] = 0xFF;
-                               centroid.color[ 0 ][ 2 ] = (alpha > 255.0f ? 0xFF : alpha);
+                       centroid.color[ 0 ][ 2 ] = ( alpha > 255.0f ? 0xFF : alpha );
 -
 -                      /* head vert is centroid */
 -                      tri[ 0 ] = &centroid;
 -
 -                      /* walk fanned triangles */
 +                              
 +                              /* head vert is centroid */
 +                              tri[ 0 ] = &centroid;
 +                              
 +                              /* walk fanned triangles */
-                               for( i = 0; i < ds->numVerts; i++ )
+                       for ( i = 0; i < ds->numVerts; i++ )
 -                      {
 -                              /* set triangle */
 -                              tri[ 1 ] = &ds->verts[ i ];
 +                              {
 +                                      /* set triangle */
 +                                      tri[ 1 ] = &ds->verts[ i ];
-                                       tri[ 2 ] = &ds->verts[ (i + 1) % ds->numVerts ];
+                               tri[ 2 ] = &ds->verts[ ( i + 1 ) % ds->numVerts ];
 -
 -                              /* create models */
 -                              n = AddSurfaceModelsToTriangle_r( ds, model, tri );
 +                                      
 +                                      /* create models */
 +                                      n = AddSurfaceModelsToTriangle_r( ds, model, tri );
-                                       if( n < 0 )
+                               if ( n < 0 ) {
 -                                      return n;
 +                                              return n;
+                               }
 -                              localNumSurfaceModels += n;
 -                      }
 -                      break;
 -
 -              /* handle patches */
 -              case SURFACE_PATCH:
 -                      /* subdivide the surface */
 -                      src.width = ds->patchWidth;
 -                      src.height = ds->patchHeight;
 -                      src.verts = ds->verts;
 -                      //%     subdivided = SubdivideMesh( src, 8.0f, 512 );
 -                      iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
 -                      subdivided = SubdivideMesh2( src, iterations );
 -
 -                      /* fit it to the curve and remove colinear verts on rows/columns */
 -                      PutMeshOnCurve( *subdivided );
 -                      mesh = RemoveLinearMeshColumnsRows( subdivided );
 -                      FreeMesh( subdivided );
 -
 -                      /* subdivide each quad to place the models */
 +                                      localNumSurfaceModels += n;
 +                              }
 +                              break;
 +                      
 +                      /* handle patches */
 +                      case SURFACE_PATCH:
 +                              /* subdivide the surface */
 +                              src.width = ds->patchWidth;
 +                              src.height = ds->patchHeight;
 +                              src.verts = ds->verts;
 +                              //%     subdivided = SubdivideMesh( src, 8.0f, 512 );
 +                              iterations = IterationsForCurve( ds->longestCurve, patchSubdivisions );
 +                              subdivided = SubdivideMesh2( src, iterations );
 +                              
 +                              /* fit it to the curve and remove colinear verts on rows/columns */
 +                              PutMeshOnCurve( *subdivided );
 +                              mesh = RemoveLinearMeshColumnsRows( subdivided );
 +                              FreeMesh( subdivided );
 +                              
 +                              /* subdivide each quad to place the models */
-                               for( y = 0; y < (mesh->height - 1); y++ )
+                       for ( y = 0; y < ( mesh->height - 1 ); y++ )
 -                      {
 -                              for ( x = 0; x < ( mesh->width - 1 ); x++ )
                                {
-                                       for( x = 0; x < (mesh->width - 1); x++ )
 -                                      /* set indexes */
++                              for ( x = 0; x < ( mesh->width - 1 ); x++ )
 +                                      {
 +                                              /* set indexes */
-                                               pw[ 0 ] = x + (y * mesh->width);
-                                               pw[ 1 ] = x + ((y + 1) * mesh->width);
-                                               pw[ 2 ] = x + 1 + ((y + 1) * mesh->width);
-                                               pw[ 3 ] = x + 1 + (y * mesh->width);
-                                               pw[ 4 ] = x + (y * mesh->width);        /* same as pw[ 0 ] */
+                                       pw[ 0 ] = x + ( y * mesh->width );
+                                       pw[ 1 ] = x + ( ( y + 1 ) * mesh->width );
+                                       pw[ 2 ] = x + 1 + ( ( y + 1 ) * mesh->width );
+                                       pw[ 3 ] = x + 1 + ( y * mesh->width );
+                                       pw[ 4 ] = x + ( y * mesh->width );      /* same as pw[ 0 ] */
 -
 -                                      /* set radix */
 +                                              
 +                                              /* set radix */
-                                               r = (x + y) & 1;
+                                       r = ( x + y ) & 1;
 -
 -                                      /* triangle 1 */
 -                                      tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
 -                                      tri[ 1 ] = &mesh->verts[ pw[ r + 1 ] ];
 -                                      tri[ 2 ] = &mesh->verts[ pw[ r + 2 ] ];
 -                                      n = AddSurfaceModelsToTriangle_r( ds, model, tri );
 +                                              
 +                                              /* triangle 1 */
 +                                              tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
 +                                              tri[ 1 ] = &mesh->verts[ pw[ r + 1 ] ];
 +                                              tri[ 2 ] = &mesh->verts[ pw[ r + 2 ] ];
 +                                              n = AddSurfaceModelsToTriangle_r( ds, model, tri );
-                                               if( n < 0 )
+                                       if ( n < 0 ) {
 -                                              return n;
 +                                                      return n;
+                                       }
 -                                      localNumSurfaceModels += n;
 -
 -                                      /* triangle 2 */
 -                                      tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
 -                                      tri[ 1 ] = &mesh->verts[ pw[ r + 2 ] ];
 -                                      tri[ 2 ] = &mesh->verts[ pw[ r + 3 ] ];
 -                                      n = AddSurfaceModelsToTriangle_r( ds, model, tri );
 +                                              localNumSurfaceModels += n;
 +                                              
 +                                              /* triangle 2 */
 +                                              tri[ 0 ] = &mesh->verts[ pw[ r + 0 ] ];
 +                                              tri[ 1 ] = &mesh->verts[ pw[ r + 2 ] ];
 +                                              tri[ 2 ] = &mesh->verts[ pw[ r + 3 ] ];
 +                                              n = AddSurfaceModelsToTriangle_r( ds, model, tri );
-                                               if( n < 0 )
+                                       if ( n < 0 ) {
 -                                              return n;
 +                                                      return n;
++                                      }
 +                                              localNumSurfaceModels += n;
                                        }
 -                                      localNumSurfaceModels += n;
                                }
 -                      }
 -
 -                      /* free the subdivided mesh */
 -                      FreeMesh( mesh );
 -                      break;
 -
 -              /* handle triangle surfaces */
 -              case SURFACE_TRIANGLES:
 -              case SURFACE_FORCED_META:
 -              case SURFACE_META:
 -                      /* walk the triangle list */
 +                              
 +                              /* free the subdivided mesh */
 +                              FreeMesh( mesh );
 +                              break;
 +                      
 +                      /* handle triangle surfaces */
 +                      case SURFACE_TRIANGLES:
 +                      case SURFACE_FORCED_META:
 +                      case SURFACE_META:
 +                              /* walk the triangle list */
-                               for( i = 0; i < ds->numIndexes; i += 3 )
+                       for ( i = 0; i < ds->numIndexes; i += 3 )
 -                      {
 -                              tri[ 0 ] = &ds->verts[ ds->indexes[ i ] ];
 -                              tri[ 1 ] = &ds->verts[ ds->indexes[ i + 1 ] ];
 -                              tri[ 2 ] = &ds->verts[ ds->indexes[ i + 2 ] ];
 -                              n = AddSurfaceModelsToTriangle_r( ds, model, tri );
 +                              {
 +                                      tri[ 0 ] = &ds->verts[ ds->indexes[ i ] ];
 +                                      tri[ 1 ] = &ds->verts[ ds->indexes[ i + 1 ] ];
 +                                      tri[ 2 ] = &ds->verts[ ds->indexes[ i + 2 ] ];
 +                                      n = AddSurfaceModelsToTriangle_r( ds, model, tri );
-                                       if( n < 0 )
+                               if ( n < 0 ) {
 -                                      return n;
 +                                              return n;
+                               }
 -                              localNumSurfaceModels += n;
 -                      }
 -                      break;
 -
 -              /* no support for flares, foghull, etc */
 -              default:
 -                      break;
 +                                      localNumSurfaceModels += n;
 +                              }
 +                              break;
 +                      
 +                      /* no support for flares, foghull, etc */
 +                      default:
 +                              break;
                }
        }
 -
 +      
        /* return count */
        return localNumSurfaceModels;
  }
  
  
  /*
- AddEntitySurfaceModels() - ydnar
- adds surfacemodels to an entity's surfaces
- */
   AddEntitySurfaceModels() - ydnar
   adds surfacemodels to an entity's surfaces
 */
  
- void AddEntitySurfaceModels( entity_t *e )
- {
+ void AddEntitySurfaceModels( entity_t *e ){
 -      int i;
 -
 -
 +      int             i;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- AddEntitySurfaceModels ---\n" );
 -
 +      
        /* walk the surface list */
-       for( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
+       for ( i = e->firstDrawSurf; i < numMapDrawSurfs; i++ )
                numSurfaceModels += AddSurfaceModels( &mapDrawSurfs[ i ] );
  }
  
  
  
  /*
- VolumeColorMods() - ydnar
- applies brush/volumetric color/alpha modulation to vertexes
- */
   VolumeColorMods() - ydnar
   applies brush/volumetric color/alpha modulation to vertexes
 */
  
- static void VolumeColorMods( entity_t *e, mapDrawSurface_t *ds )
- {
+ static void VolumeColorMods( entity_t *e, mapDrawSurface_t *ds ){
 -      int i, j;
 -      float d;
 -      brush_t     *b;
 -      plane_t     *plane;
 -
 -
 +      int                     i, j;
 +      float           d;
 +      brush_t         *b;
 +      plane_t         *plane;
 +      
 +      
        /* early out */
-       if( e->colorModBrushes == NULL )
+       if ( e->colorModBrushes == NULL ) {
                return;
 -
+       }
 +      
        /* iterate brushes */
-       for( b = e->colorModBrushes; b != NULL; b = b->nextColorModBrush )
+       for ( b = e->colorModBrushes; b != NULL; b = b->nextColorModBrush )
        {
                /* worldspawn alpha brushes affect all, grouped ones only affect original entity */
-               if( b->entityNum != 0 && b->entityNum != ds->entityNum )
+               if ( b->entityNum != 0 && b->entityNum != ds->entityNum ) {
                        continue;
 -
+               }
 +              
                /* test bbox */
-               if( b->mins[ 0 ] > ds->maxs[ 0 ] || b->maxs[ 0 ] < ds->mins[ 0 ] ||
+               if ( b->mins[ 0 ] > ds->maxs[ 0 ] || b->maxs[ 0 ] < ds->mins[ 0 ] ||
 -                       b->mins[ 1 ] > ds->maxs[ 1 ] || b->maxs[ 1 ] < ds->mins[ 1 ] ||
 +                      b->mins[ 1 ] > ds->maxs[ 1 ] || b->maxs[ 1 ] < ds->mins[ 1 ] ||
-                       b->mins[ 2 ] > ds->maxs[ 2 ] || b->maxs[ 2 ] < ds->mins[ 2 ] )
+                        b->mins[ 2 ] > ds->maxs[ 2 ] || b->maxs[ 2 ] < ds->mins[ 2 ] ) {
                        continue;
 -
+               }
 +              
                /* iterate verts */
-               for( i = 0; i < ds->numVerts; i++ )
+               for ( i = 0; i < ds->numVerts; i++ )
                {
                        /* iterate planes */
-                       for( j = 0; j < b->numsides; j++ )
+                       for ( j = 0; j < b->numsides; j++ )
                        {
                                /* point-plane test */
                                plane = &mapplanes[ b->sides[ j ].planenum ];
                                d = DotProduct( ds->verts[ i ].xyz, plane->normal ) - plane->dist;
-                               if( d > 1.0f )
+                               if ( d > 1.0f ) {
                                        break;
 -                              }
                        }
 -
++                      }
 +                      
                        /* apply colormods */
-                       if( j == b->numsides )
+                       if ( j == b->numsides ) {
                                ColorMod( b->contentShader->colorMod, 1, &ds->verts[ i ] );
 -                      }
                }
        }
++      }
  }
  
  
  
  /*
- FilterDrawsurfsIntoTree()
- upon completion, all drawsurfs that actually generate a reference
- will have been emited to the bspfile arrays, and the references
- will have valid final indexes
- */
- void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree )
- {
+    FilterDrawsurfsIntoTree()
+    upon completion, all drawsurfs that actually generate a reference
+    will have been emited to the bspfile arrays, and the references
+    will have valid final indexes
+  */
+ void FilterDrawsurfsIntoTree( entity_t *e, tree_t *tree ){
 -      int i, j;
 -      mapDrawSurface_t    *ds;
 -      shaderInfo_t        *si;
 -      vec3_t origin, mins, maxs;
 -      int refs;
 -      int numSurfs, numRefs, numSkyboxSurfaces;
 -      qboolean sb;
 -
 -
 +      int                                     i, j;
 +      mapDrawSurface_t        *ds;
 +      shaderInfo_t            *si;
 +      vec3_t                          origin, mins, maxs;
 +      int                                     refs;
 +      int                                     numSurfs, numRefs, numSkyboxSurfaces;
 +      qboolean        sb;
 +      
 +      
        /* note it */
        Sys_FPrintf( SYS_VRB, "--- FilterDrawsurfsIntoTree ---\n" );
 -
 +      
        /* filter surfaces into the tree */
        numSurfs = 0;
        numRefs = 0;
        {
                /* get surface and try to early out */
                ds = &mapDrawSurfs[ i ];
-               if( ds->numVerts == 0 && ds->type != SURFACE_FLARE && ds->type != SURFACE_SHADER )
+               if ( ds->numVerts == 0 && ds->type != SURFACE_FLARE && ds->type != SURFACE_SHADER ) {
                        continue;
 -
+               }
 +              
                /* get shader */
                si = ds->shaderInfo;
  
  
                        /* refs initially zero */
                        refs = 0;
 -
 +                      
                        /* apply texture coordinate mods */
-                       for( j = 0; j < ds->numVerts; j++ )
+                       for ( j = 0; j < ds->numVerts; j++ )
                                TCMod( si->mod, ds->verts[ j ].st );
 -
 +                      
                        /* ydnar: apply shader colormod */
                        ColorMod( ds->shaderInfo->colorMod, ds->numVerts, ds->verts );
 -
 +                      
                        /* ydnar: apply brush colormod */
                        VolumeColorMods( e, ds );
 -
 +                      
                        /* ydnar: make fur surfaces */
-                       if( si->furNumLayers > 0 )
+                       if ( si->furNumLayers > 0 ) {
                                Fur( ds );
 -
+                       }
 +                      
                        /* ydnar/sd: make foliage surfaces */
-                       if( si->foliage != NULL )
+                       if ( si->foliage != NULL ) {
                                Foliage( ds );
 -
+                       }
 +                      
                        /* create a flare surface if necessary */
-                       if( si->flareShader != NULL && si->flareShader[ 0 ] )
+                       if ( si->flareShader != NULL && si->flareShader[ 0 ] ) {
                                AddSurfaceFlare( ds, e->origin );
 -
+                       }
 +                      
                        /* ydnar: don't emit nodraw surfaces (like nodraw fog) */
-                       if( si != NULL && (si->compileFlags & C_NODRAW) && ds->type != SURFACE_PATCH )
+                       if ( ( si->compileFlags & C_NODRAW ) && ds->type != SURFACE_PATCH ) {
                                continue;
 -
+                       }
 +                      
                        /* ydnar: bias the surface textures */
                        BiasSurfaceTextures( ds );
 -
 +                      
                        /* ydnar: globalizing of fog volume handling (eek a hack) */
-                       if( e != entities && si->noFog == qfalse )
-                       {
+                       if ( e != entities && si->noFog == qfalse ) {
                                /* find surface origin and offset by entity origin */
                                VectorAdd( ds->mins, ds->maxs, origin );
                                VectorScale( origin, 0.5f, origin );
                                VectorAdd( origin, e->origin, origin );
 -
 +                              
                                VectorAdd( ds->mins, e->origin, mins );
                                VectorAdd( ds->maxs, e->origin, maxs );
 -
 +                              
                                /* set the fog number for this surface */
 -                              ds->fogNum = FogForBounds( mins, maxs, 1.0f );  //%     FogForPoint( origin, 0.0f );
 +                              ds->fogNum = FogForBounds( mins, maxs, 1.0f );  //%     FogForPoint( origin, 0.0f );
                        }
                }
 -
 +              
                /* ydnar: remap shader */
-               if( ds->shaderInfo->remapShader && ds->shaderInfo->remapShader[ 0 ] )
+               if ( ds->shaderInfo->remapShader && ds->shaderInfo->remapShader[ 0 ] ) {
                        ds->shaderInfo = ShaderInfoForShader( ds->shaderInfo->remapShader );
 -
+               }
 +              
                /* ydnar: gs mods: handle the various types of surfaces */
-               switch( ds->type )
+               switch ( ds->type )
                {
 -              /* handle brush faces */
 -              case SURFACE_FACE:
 -              case SURFACE_DECAL:
 +                      /* handle brush faces */
 +                      case SURFACE_FACE:
 +                      case SURFACE_DECAL:
-                               if( refs == 0 )
+                       if ( refs == 0 ) {
 -                              refs = FilterFaceIntoTree( ds, tree );
 +                                      refs = FilterFaceIntoTree( ds, tree );
-                               if( refs > 0 )
+                       }
+                       if ( refs > 0 ) {
 -                              EmitFaceSurface( ds );
 +                                      EmitFaceSurface( ds );
+                       }
 -                      break;
 -
 -              /* handle patches */
 -              case SURFACE_PATCH:
 +                              break;
 +                      
 +                      /* handle patches */
 +                      case SURFACE_PATCH:
-                               if( refs == 0 )
+                       if ( refs == 0 ) {
 -                              refs = FilterPatchIntoTree( ds, tree );
 +                                      refs = FilterPatchIntoTree( ds, tree );
-                               if( refs > 0 )
+                       }
+                       if ( refs > 0 ) {
 -                              EmitPatchSurface( e, ds );
 +                                      EmitPatchSurface( e, ds );
+                       }
 -                      break;
 -
 -              /* handle triangle surfaces */
 -              case SURFACE_TRIANGLES:
 -              case SURFACE_FORCED_META:
 -              case SURFACE_META:
 -                      //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%1d] %4d verts %s\n", numSurfs, ds->planar, ds->numVerts, si->shader );
 +                              break;
 +                      
 +                      /* handle triangle surfaces */
 +                      case SURFACE_TRIANGLES:
 +                      case SURFACE_FORCED_META:
 +                      case SURFACE_META:
 +                              //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%1d] %4d verts %s\n", numSurfs, ds->planar, ds->numVerts, si->shader );
-                               if( refs == 0 )
+                       if ( refs == 0 ) {
 -                              refs = FilterTrianglesIntoTree( ds, tree );
 +                                      refs = FilterTrianglesIntoTree( ds, tree );
-                               if( refs > 0 )
+                       }
+                       if ( refs > 0 ) {
 -                              EmitTriangleSurface( ds );
 +                                      EmitTriangleSurface( ds );
+                       }
 -                      break;
 -
 -              /* handle foliage surfaces (splash damage/wolf et) */
 -              case SURFACE_FOLIAGE:
 -                      //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%d] %4d verts %s\n", numSurfs, ds->numFoliageInstances, ds->numVerts, si->shader );
 +                              break;
 +                      
 +                      /* handle foliage surfaces (splash damage/wolf et) */
 +                      case SURFACE_FOLIAGE:
 +                              //%     Sys_FPrintf( SYS_VRB, "Surface %4d: [%d] %4d verts %s\n", numSurfs, ds->numFoliageInstances, ds->numVerts, si->shader );
-                               if( refs == 0 )
+                       if ( refs == 0 ) {
 -                              refs = FilterFoliageIntoTree( ds, tree );
 +                                      refs = FilterFoliageIntoTree( ds, tree );
-                               if( refs > 0 )
+                       }
+                       if ( refs > 0 ) {
 -                              EmitTriangleSurface( ds );
 +                                      EmitTriangleSurface( ds );
+                       }
 -                      break;
 -
 -              /* handle foghull surfaces */
 -              case SURFACE_FOGHULL:
 +                              break;
 +                      
 +                      /* handle foghull surfaces */
 +                      case SURFACE_FOGHULL:
-                               if( refs == 0 )
+                       if ( refs == 0 ) {
 -                              refs = AddReferenceToTree_r( ds, tree->headnode, qfalse );
 +                                      refs = AddReferenceToTree_r( ds, tree->headnode, qfalse );
-                               if( refs > 0 )
+                       }
+                       if ( refs > 0 ) {
 -                              EmitTriangleSurface( ds );
 +                                      EmitTriangleSurface( ds );
+                       }
 -                      break;
 -
 -              /* handle flares */
 -              case SURFACE_FLARE:
 +                              break;
 +                      
 +                      /* handle flares */
 +                      case SURFACE_FLARE:
-                               if( refs == 0 )
+                       if ( refs == 0 ) {
 -                              refs = FilterFlareSurfIntoTree( ds, tree );
 +                                      refs = FilterFlareSurfIntoTree( ds, tree );
-                               if( refs > 0 )
+                       }
+                       if ( refs > 0 ) {
 -                              EmitFlareSurface( ds );
 +                                      EmitFlareSurface( ds );
+                       }
 -                      break;
 -
 -              /* handle shader-only surfaces */
 -              case SURFACE_SHADER:
 -                      refs = 1;
 -                      EmitFlareSurface( ds );
 -                      break;
 -
 -              /* no references */
 -              default:
 -                      refs = 0;
 -                      break;
 +                              break;
 +                      
 +                      /* handle shader-only surfaces */
 +                      case SURFACE_SHADER:
 +                              refs = 1;
 +                              EmitFlareSurface( ds );
 +                              break;
 +                      
 +                      /* no references */
 +                      default:
 +                              refs = 0;
 +                              break;
                }
  
                /* maybe surface got marked as skybox again */
                /* if we keep that flag, it will get scaled up AGAIN */
-               if(sb)
+               if ( sb ) {
                        ds->skybox = qfalse;
 -
+               }
 +              
                /* tot up the references */
-               if( refs > 0 )
-               {
+               if ( refs > 0 ) {
                        /* tot up counts */
                        numSurfs++;
                        numRefs += refs;
                        /* emit extra surface data */
                        SetSurfaceExtra( ds, numBSPDrawSurfaces - 1 );
                        //%     Sys_FPrintf( SYS_VRB, "%d verts %d indexes\n", ds->numVerts, ds->numIndexes );
 -
 +                      
                        /* one last sanity check */
                        {
 -                              bspDrawSurface_t    *out;
 +                              bspDrawSurface_t        *out;
                                out = &bspDrawSurfaces[ numBSPDrawSurfaces - 1 ];
-                               if( out->numVerts == 3 && out->numIndexes > 3 )
-                               {
+                               if ( out->numVerts == 3 && out->numIndexes > 3 ) {
                                        Sys_Printf( "\nWARNING: Potentially bad %s surface (%d: %d, %d)\n     %s\n",
 -                                                              surfaceTypes[ ds->type ],
 -                                                              numBSPDrawSurfaces - 1, out->numVerts, out->numIndexes, si->shader );
 +                                              surfaceTypes[ ds->type ],
 +                                              numBSPDrawSurfaces - 1, out->numVerts, out->numIndexes, si->shader );
                                }
                        }
 -
 +                      
                        /* ydnar: handle skybox surfaces */
-                       if( ds->skybox )
-                       {
+                       if ( ds->skybox ) {
                                MakeSkyboxSurface( ds );
                                numSkyboxSurfaces++;
                        }
        Sys_FPrintf( SYS_VRB, "%9d maxarea'd face surfaces\n", numMaxAreaSurfaces );
        Sys_FPrintf( SYS_VRB, "%9d surface models generated\n", numSurfaceModels );
        Sys_FPrintf( SYS_VRB, "%9d skybox surfaces generated\n", numSkyboxSurfaces );
-       for( i = 0; i < NUM_SURFACE_TYPES; i++ )
+       for ( i = 0; i < NUM_SURFACE_TYPES; i++ )
                Sys_FPrintf( SYS_VRB, "%9d %s surfaces\n", numSurfacesByType[ i ], surfaceTypes[ i ] );
 -
 +      
-       Sys_FPrintf( SYS_VRB, "%9d redundant indexes supressed, saving %d Kbytes\n", numRedundantIndexes, (numRedundantIndexes * 4 / 1024) );
+       Sys_FPrintf( SYS_VRB, "%9d redundant indexes supressed, saving %d Kbytes\n", numRedundantIndexes, ( numRedundantIndexes * 4 / 1024 ) );
  }
index f15fdef46a1b021e58810857fe0e8f980f68463a,042c547a613eb4e22900b08810312e64b54e99d7..b4b44189edaa51b71ab13547f8daa16adf843520
@@@ -45,45 -45,47 +45,47 @@@ static foliageInstance_t           foliageInstan
  
  
  /*
- SubdivideFoliageTriangle_r()
- recursively subdivides a triangle until the triangle is smaller than
- the desired density, then pseudo-randomly sets a point
- */
   SubdivideFoliageTriangle_r()
   recursively subdivides a triangle until the triangle is smaller than
   the desired density, then pseudo-randomly sets a point
 */
  
- static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage, bspDrawVert_t **tri )
- {
+ static void SubdivideFoliageTriangle_r( mapDrawSurface_t *ds, foliage_t *foliage, bspDrawVert_t **tri ){
 -      bspDrawVert_t mid, *tri2[ 3 ];
 -      int max;
 -
 -
 +      bspDrawVert_t   mid, *tri2[ 3 ];
 +      int                             max;
 +      
 +      
        /* limit test */
-       if( numFoliageInstances >= MAX_FOLIAGE_INSTANCES )
+       if ( numFoliageInstances >= MAX_FOLIAGE_INSTANCES ) {
                return;
 -
+       }
 +      
        /* plane test */
        {
 -              vec4_t plane;
 -
 -
 +              vec4_t          plane;
 +              
 +              
                /* make a plane */
-               if( !PlaneFromPoints( plane, tri[ 0 ]->xyz, tri[ 1 ]->xyz, tri[ 2 ]->xyz ) )
+               if ( !PlaneFromPoints( plane, tri[ 0 ]->xyz, tri[ 1 ]->xyz, tri[ 2 ]->xyz ) ) {
                        return;
 -
+               }
 +              
                /* if normal is too far off vertical, then don't place an instance */
-               if( plane[ 2 ] < 0.5f )
+               if ( plane[ 2 ] < 0.5f ) {
                        return;
 -              }
        }
 -
++      }
 +      
        /* subdivide calc */
        {
 -              int i;
 -              float               *a, *b, dx, dy, dz, dist, maxDist;
 -              foliageInstance_t   *fi;
 -
 -
 +              int                                     i;
 +              float                           *a, *b, dx, dy, dz, dist, maxDist;
 +              foliageInstance_t       *fi;
 +              
 +              
                /* get instance */
                fi = &foliageInstances[ numFoliageInstances ];
 -
 +              
                /* find the longest edge and split it */
                max = -1;
                maxDist = 0.0f;
                {
                        /* get verts */
                        a = tri[ i ]->xyz;
-                       b = tri[ (i + 1) % 3 ]->xyz;
+                       b = tri[ ( i + 1 ) % 3 ]->xyz;
 -
 +                      
                        /* get dists */
                        dx = a[ 0 ] - b[ 0 ];
                        dy = a[ 1 ] - b[ 1 ];
                        dz = a[ 2 ] - b[ 2 ];
-                       dist = (dx * dx) + (dy * dy) + (dz * dz);
+                       dist = ( dx * dx ) + ( dy * dy ) + ( dz * dz );
 -
 +                      
                        /* longer? */
-                       if( dist > maxDist )
-                       {
+                       if ( dist > maxDist ) {
                                maxDist = dist;
                                max = i;
                        }
                        VectorAdd( fi->xyz, tri[ i ]->xyz, fi->xyz );
                        VectorAdd( fi->normal, tri[ i ]->normal, fi->normal );
                }
 -
 +              
                /* is the triangle small enough? */
-               if( maxDist <= (foliage->density * foliage->density) )
-               {
+               if ( maxDist <= ( foliage->density * foliage->density ) ) {
 -                      float alpha, odds, r;
 -
 -
 +                      float   alpha, odds, r;
 +                      
 +                      
                        /* get average alpha */
-                       if( foliage->inverseAlpha == 2 )
+                       if ( foliage->inverseAlpha == 2 ) {
                                alpha = 1.0f;
+                       }
                        else
                        {
-                               alpha = ((float) tri[ 0 ]->color[ 0 ][ 3 ] + (float) tri[ 1 ]->color[ 0 ][ 3 ] + (float) tri[ 2 ]->color[ 0 ][ 3 ]) / 765.0f;
-                               if( foliage->inverseAlpha == 1 )
+                               alpha = ( (float) tri[ 0 ]->color[ 0 ][ 3 ] + (float) tri[ 1 ]->color[ 0 ][ 3 ] + (float) tri[ 2 ]->color[ 0 ][ 3 ] ) / 765.0f;
+                               if ( foliage->inverseAlpha == 1 ) {
                                        alpha = 1.0f - alpha;
-                               if( alpha < 0.75f )
+                               }
+                               if ( alpha < 0.75f ) {
                                        return;
 -                              }
                        }
 -
++                      }
 +                      
                        /* roll the dice */
                        odds = foliage->odds * alpha;
                        r = Random();
-                       if( r > odds )
+                       if ( r > odds ) {
                                return;
 -
+                       }
 +                      
                        /* scale centroid */
                        VectorScale( fi->xyz, 0.33333333f, fi->xyz );
-                       if( VectorNormalize( fi->normal, fi->normal ) == 0.0f )
+                       if ( VectorNormalize( fi->normal, fi->normal ) == 0.0f ) {
                                return;
 -
+                       }
 +                      
                        /* add to count and return */
                        numFoliageInstances++;
                        return;
                }
        }
 -
 +      
        /* split the longest edge and map it */
-       LerpDrawVert( tri[ max ], tri[ (max + 1) % 3 ], &mid );
+       LerpDrawVert( tri[ max ], tri[ ( max + 1 ) % 3 ], &mid );
 -
 +      
        /* recurse to first triangle */
        VectorCopy( tri, tri2 );
        tri2[ max ] = &mid;
        SubdivideFoliageTriangle_r( ds, foliage, tri2 );
 -
 +      
        /* recurse to second triangle */
        VectorCopy( tri, tri2 );
-       tri2[ (max + 1) % 3 ] = &mid;
+       tri2[ ( max + 1 ) % 3 ] = &mid;
        SubdivideFoliageTriangle_r( ds, foliage, tri2 );
  }
  
  
  
  /*
- GenFoliage()
- generates a foliage file for a bsp
- */
   GenFoliage()
   generates a foliage file for a bsp
 */
  
- void Foliage( mapDrawSurface_t *src )
- {
+ void Foliage( mapDrawSurface_t *src ){
 -      int i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
 -      mapDrawSurface_t    *ds;
 -      shaderInfo_t        *si;
 -      foliage_t           *foliage;
 -      mesh_t srcMesh, *subdivided, *mesh;
 -      bspDrawVert_t       *verts, *dv[ 3 ], *fi;
 -      vec3_t scale;
 -      m4x4_t transform;
 -
 -
 +      int                                     i, j, k, x, y, pw[ 5 ], r, oldNumMapDrawSurfs;
 +      mapDrawSurface_t        *ds;
 +      shaderInfo_t            *si;
 +      foliage_t                       *foliage;
 +      mesh_t                          srcMesh, *subdivided, *mesh;
 +      bspDrawVert_t           *verts, *dv[ 3 ], *fi;
 +      vec3_t                          scale;
 +      m4x4_t                          transform;
 +      
 +      
        /* get shader */
        si = src->shaderInfo;
-       if( si == NULL || si->foliage == NULL )
+       if ( si == NULL || si->foliage == NULL ) {
                return;
 -
+       }
 +      
        /* do every foliage */
-       for( foliage = si->foliage; foliage != NULL; foliage = foliage->next )
+       for ( foliage = si->foliage; foliage != NULL; foliage = foliage->next )
        {
                /* zero out */
                numFoliageInstances = 0;
 -
 +              
                /* map the surface onto the lightmap origin/cluster/normal buffers */
-               switch( src->type )
+               switch ( src->type )
                {
 -              case SURFACE_META:
 -              case SURFACE_FORCED_META:
 -              case SURFACE_TRIANGLES:
 -                      /* get verts */
 -                      verts = src->verts;
 -
 -                      /* map the triangles */
 +                      case SURFACE_META:
 +                      case SURFACE_FORCED_META:
 +                      case SURFACE_TRIANGLES:
 +                              /* get verts */
 +                              verts = src->verts;
 +                              
 +                              /* map the triangles */
-                               for( i = 0; i < src->numIndexes; i += 3 )
+                       for ( i = 0; i < src->numIndexes; i += 3 )
 -                      {
 -                              dv[ 0 ] = &verts[ src->indexes[ i ] ];
 -                              dv[ 1 ] = &verts[ src->indexes[ i + 1 ] ];
 -                              dv[ 2 ] = &verts[ src->indexes[ i + 2 ] ];
 -                              SubdivideFoliageTriangle_r( src, foliage, dv );
 -                      }
 -                      break;
 -
 -              case SURFACE_PATCH:
 -                      /* make a mesh from the drawsurf */
 -                      srcMesh.width = src->patchWidth;
 -                      srcMesh.height = src->patchHeight;
 -                      srcMesh.verts = src->verts;
 -                      subdivided = SubdivideMesh( srcMesh, 8, 512 );
 -
 -                      /* fit it to the curve and remove colinear verts on rows/columns */
 -                      PutMeshOnCurve( *subdivided );
 -                      mesh = RemoveLinearMeshColumnsRows( subdivided );
 -                      FreeMesh( subdivided );
 -
 -                      /* get verts */
 -                      verts = mesh->verts;
 -
 -                      /* map the mesh quads */
 +                              {
 +                                      dv[ 0 ] = &verts[ src->indexes[ i ] ];
 +                                      dv[ 1 ] = &verts[ src->indexes[ i + 1 ] ];
 +                                      dv[ 2 ] = &verts[ src->indexes[ i + 2 ] ];
 +                                      SubdivideFoliageTriangle_r( src, foliage, dv );
 +                              }
 +                              break;
 +                      
 +                      case SURFACE_PATCH:
 +                              /* make a mesh from the drawsurf */ 
 +                              srcMesh.width = src->patchWidth;
 +                              srcMesh.height = src->patchHeight;
 +                              srcMesh.verts = src->verts;
 +                              subdivided = SubdivideMesh( srcMesh, 8, 512 );
 +                              
 +                              /* fit it to the curve and remove colinear verts on rows/columns */
 +                              PutMeshOnCurve( *subdivided );
 +                              mesh = RemoveLinearMeshColumnsRows( subdivided );
 +                              FreeMesh( subdivided );
 +                              
 +                              /* get verts */
 +                              verts = mesh->verts;
 +                              
 +                              /* map the mesh quads */
-                               for( y = 0; y < (mesh->height - 1); y++ )
+                       for ( y = 0; y < ( mesh->height - 1 ); y++ )
 -                      {
 -                              for ( x = 0; x < ( mesh->width - 1 ); x++ )
                                {
-                                       for( x = 0; x < (mesh->width - 1); x++ )
 -                                      /* set indexes */
++                              for ( x = 0; x < ( mesh->width - 1 ); x++ )
 +                                      {
 +                                              /* set indexes */
-                                               pw[ 0 ] = x + (y * mesh->width);
-                                               pw[ 1 ] = x + ((y + 1) * mesh->width);
-                                               pw[ 2 ] = x + 1 + ((y + 1) * mesh->width);
-                                               pw[ 3 ] = x + 1 + (y * mesh->width);
-                                               pw[ 4 ] = x + (y * mesh->width);        /* same as pw[ 0 ] */
+                                       pw[ 0 ] = x + ( y * mesh->width );
+                                       pw[ 1 ] = x + ( ( y + 1 ) * mesh->width );
+                                       pw[ 2 ] = x + 1 + ( ( y + 1 ) * mesh->width );
+                                       pw[ 3 ] = x + 1 + ( y * mesh->width );
+                                       pw[ 4 ] = x + ( y * mesh->width );      /* same as pw[ 0 ] */
 -
 -                                      /* set radix */
 +                                              
 +                                              /* set radix */
-                                               r = (x + y) & 1;
+                                       r = ( x + y ) & 1;
 -
 -                                      /* get drawverts and map first triangle */
 -                                      dv[ 0 ] = &verts[ pw[ r + 0 ] ];
 -                                      dv[ 1 ] = &verts[ pw[ r + 1 ] ];
 -                                      dv[ 2 ] = &verts[ pw[ r + 2 ] ];
 -                                      SubdivideFoliageTriangle_r( src, foliage, dv );
 -
 -                                      /* get drawverts and map second triangle */
 -                                      dv[ 0 ] = &verts[ pw[ r + 0 ] ];
 -                                      dv[ 1 ] = &verts[ pw[ r + 2 ] ];
 -                                      dv[ 2 ] = &verts[ pw[ r + 3 ] ];
 -                                      SubdivideFoliageTriangle_r( src, foliage, dv );
 +                                              
 +                                              /* get drawverts and map first triangle */
 +                                              dv[ 0 ] = &verts[ pw[ r + 0 ] ];
 +                                              dv[ 1 ] = &verts[ pw[ r + 1 ] ];
 +                                              dv[ 2 ] = &verts[ pw[ r + 2 ] ];
 +                                              SubdivideFoliageTriangle_r( src, foliage, dv );
 +                                              
 +                                              /* get drawverts and map second triangle */
 +                                              dv[ 0 ] = &verts[ pw[ r + 0 ] ];
 +                                              dv[ 1 ] = &verts[ pw[ r + 2 ] ];
 +                                              dv[ 2 ] = &verts[ pw[ r + 3 ] ];
 +                                              SubdivideFoliageTriangle_r( src, foliage, dv );
 +                                      }
                                }
 -                      }
 -
 -                      /* free the mesh */
 -                      FreeMesh( mesh );
 -                      break;
 -
 -              default:
 -                      break;
 +                              
 +                              /* free the mesh */
 +                              FreeMesh( mesh );
 +                              break;
 +                      
 +                      default:
 +                              break;
                }
 -
 +              
                /* any origins? */
-               if( numFoliageInstances < 1 )
+               if ( numFoliageInstances < 1 ) {
                        continue;
 -
+               }
 +              
                /* remember surface count */
                oldNumMapDrawSurfs = numMapDrawSurfs;
 -
 +              
                /* set transform matrix */
                VectorSet( scale, foliage->scale, foliage->scale, foliage->scale );
                m4x4_scale_for_vec3( transform, scale );
 -
 +              
                /* add the model to the bsp */
 -              InsertModel( foliage->model, 0, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0 );
 -
 +              InsertModel( foliage->model, 0, 0, transform, NULL, NULL, src->entityNum, src->castShadows, src->recvShadows, 0, src->lightmapScale, 0, 0, src->colormod );
 +              
                /* walk each new surface */
-               for( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )
+               for ( i = oldNumMapDrawSurfs; i < numMapDrawSurfs; i++ )
                {
                        /* get surface */
                        ds = &mapDrawSurfs[ i ];
                        /* a wee hack */
                        ds->patchWidth = ds->numFoliageInstances;
                        ds->patchHeight = ds->numVerts;
 -
 +                      
                        /* set fog to be same as source surface */
                        ds->fogNum = src->fogNum;
 -
 +                      
                        /* add a drawvert for every instance */
-                       verts = safe_malloc( (ds->numVerts + ds->numFoliageInstances) * sizeof( *verts ) );
-                       memset( verts, 0, (ds->numVerts + ds->numFoliageInstances) * sizeof( *verts ) );
+                       verts = safe_malloc( ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
+                       memset( verts, 0, ( ds->numVerts + ds->numFoliageInstances ) * sizeof( *verts ) );
                        memcpy( verts, ds->verts, ds->numVerts * sizeof( *verts ) );
                        free( ds->verts );
                        ds->verts = verts;
 -
 +                      
                        /* copy the verts */
-                       for( j = 0; j < ds->numFoliageInstances; j++ )
+                       for ( j = 0; j < ds->numFoliageInstances; j++ )
                        {
                                /* get vert (foliage instance) */
                                fi = &ds->verts[ ds->numVerts + j ];